Dash:
[t2.git] / package / boot / grub2 / applesetos.patch
blob0a7f356713168254f62690a941801ebd2f08dbbe
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../grub2/applesetos.patch
5 # Copyright (C) 2017 - 2019 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 The EFI on current macbooks configures hardware differently depending
18 on wether it is booting Mac OS X or a different os, for example
19 disabling the internal GPU completely on some models.
21 Mac OS X identifies itself using a custom EFI protocol.
23 This adds a command that fakes the os identification, making all
24 hardware accessible.
26 ---
27 grub-core/Makefile.core.def | 6 +++
28 grub-core/commands/efi/applesetos.c | 82 +++++++++++++++++++++++++++++++++++++
29 2 files changed, 88 insertions(+)
30 create mode 100644 grub-core/commands/efi/applesetos.c
32 diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
33 index 42443bc..dc9c4de 100644
34 --- a/grub-core/Makefile.core.def
35 +++ b/grub-core/Makefile.core.def
36 @@ -742,6 +742,12 @@ module = {
39 module = {
40 + name = applesetos;
41 + common = commands/efi/applesetos.c;
42 + enable = efi;
43 +};
45 +module = {
46 name = blocklist;
47 common = commands/blocklist.c;
49 diff --git a/grub-core/commands/efi/applesetos.c
50 b/grub-core/commands/efi/applesetos.c
51 new file mode 100644
52 index 0000000..9464307
53 --- /dev/null
54 +++ b/grub-core/commands/efi/applesetos.c
55 @@ -0,0 +1,82 @@
56 +/* applesetos.c - Pretend to be Mac OS X. */
57 +/*
58 + * GRUB -- GRand Unified Bootloader
59 + * Copyright (C) 2013 Free Software Foundation, Inc.
60 + *
61 + * GRUB is free software: you can redistribute it and/or modify
62 + * it under the terms of the GNU General Public License as published by
63 + * the Free Software Foundation, either version 3 of the License, or
64 + * (at your option) any later version.
65 + *
66 + * GRUB is distributed in the hope that it will be useful,
67 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
68 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 + * GNU General Public License for more details.
70 + *
71 + * You should have received a copy of the GNU General Public License
72 + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
73 + */
74 +#include <grub/efi/api.h>
75 +#include <grub/efi/efi.h>
76 +#include <grub/command.h>
77 +/* For NULL. */
78 +#include <grub/mm.h>
80 +GRUB_MOD_LICENSE ("GPLv3+");
82 +#define GRUB_EFI_APPLE_SET_OS_PROTOCOL_GUID \
83 + { 0xc5c5da95, 0x7d5c, 0x45e6, \
84 + { 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77 } \
85 + }
87 +struct grub_efi_apple_set_os_interface
89 + grub_efi_uint64_t version;
90 + void (*set_os_version) (const grub_efi_char8_t *os_version);
91 + void (*set_os_vendor) (const grub_efi_char8_t *os_vendor);
92 +};
93 +typedef struct grub_efi_apple_set_os_interface grub_efi_apple_set_os_interface_t;
95 +static const grub_efi_char8_t apple_os_version[] = "macOS-ish";
96 +static const grub_efi_char8_t apple_os_vendor[] = "Apple Inc.";
98 +static grub_err_t
99 +grub_cmd_apple_set_os (grub_command_t cmd __attribute__ ((unused)),
100 + int argc __attribute__ ((unused)),
101 + char **args __attribute__ ((unused)))
103 + grub_efi_guid_t apple_set_os_guid = GRUB_EFI_APPLE_SET_OS_PROTOCOL_GUID;
104 + grub_efi_apple_set_os_interface_t *set_os;
105 + set_os = grub_efi_locate_protocol (&apple_set_os_guid, 0);
106 + if (!set_os) {
107 + return grub_error (GRUB_ERR_FILE_NOT_FOUND,
108 + "Could not locate the apple set os protocol.");
111 + if (set_os->version != 0)
113 + grub_efi_char8_t* os_version = argc > 0 ? args[0] : apple_os_version;
114 + grub_efi_char8_t* os_vendor = argc > 1 ? args[1] : apple_os_vendor;
116 + efi_call_1 (set_os->set_os_version, os_version);
117 + grub_printf("Set os version to %s\n", os_version);
119 + efi_call_1 (set_os->set_os_vendor, os_vendor);
120 + grub_printf("Set os vendor to %s\n", os_vendor);
123 + return 0;
126 +static grub_command_t cmd;
128 +GRUB_MOD_INIT(applesetos)
130 + cmd = grub_register_command ("apple_set_os", grub_cmd_apple_set_os, NULL,
131 + "Register as Apple Inc. Mac OS X 10.9.");
134 +GRUB_MOD_FINI(applesetos)
136 + grub_unregister_command (cmd);
139 1.8.5.2