From: Andreas Heider <andreas@heider.io>
To: grub-devel@gnu.org
Cc: Andreas Heider <andreas@heider.io>
Subject: [PATCH] Add apple_set_os command
Date: Mon, 30 Dec 2013 17:04:26 +0100 [thread overview]
Message-ID: <1388419466-2023-1-git-send-email-andreas@heider.io> (raw)
The EFI on current macbooks configures hardware differently depending
on wether it is booting Mac OS X or a different os, for example
disabling the internal GPU completely on some models.
Mac OS X identifies itself using a custom EFI protocol.
This adds a command that fakes the os identification, making all
hardware accessible.
---
grub-core/Makefile.core.def | 6 +++
grub-core/commands/efi/applesetos.c | 82 +++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+)
create mode 100644 grub-core/commands/efi/applesetos.c
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 42443bc..dc9c4de 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -742,6 +742,12 @@ module = {
};
module = {
+ name = applesetos;
+ common = commands/efi/applesetos.c;
+ enable = efi;
+};
+
+module = {
name = blocklist;
common = commands/blocklist.c;
};
diff --git a/grub-core/commands/efi/applesetos.c b/grub-core/commands/efi/applesetos.c
new file mode 100644
index 0000000..9464307
--- /dev/null
+++ b/grub-core/commands/efi/applesetos.c
@@ -0,0 +1,82 @@
+/* applesetos.c - Pretend to be Mac OS X. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <grub/efi/api.h>
+#include <grub/efi/efi.h>
+#include <grub/command.h>
+/* For NULL. */
+#include <grub/mm.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define GRUB_EFI_APPLE_SET_OS_PROTOCOL_GUID \
+ { 0xc5c5da95, 0x7d5c, 0x45e6, \
+ { 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77 } \
+ }
+
+struct grub_efi_apple_set_os_interface
+{
+ grub_efi_uint64_t version;
+ void (*set_os_version) (const grub_efi_char8_t *os_version);
+ void (*set_os_vendor) (const grub_efi_char8_t *os_vendor);
+};
+typedef struct grub_efi_apple_set_os_interface grub_efi_apple_set_os_interface_t;
+
+static const grub_efi_char8_t apple_os_version[] = "Mac OS X 10.9";
+static const grub_efi_char8_t apple_os_vendor[] = "Apple Inc.";
+
+static grub_err_t
+grub_cmd_apple_set_os (grub_command_t cmd __attribute__ ((unused)),
+ int argc __attribute__ ((unused)),
+ char **args __attribute__ ((unused)))
+{
+ grub_efi_guid_t apple_set_os_guid = GRUB_EFI_APPLE_SET_OS_PROTOCOL_GUID;
+ grub_efi_apple_set_os_interface_t *set_os;
+ set_os = grub_efi_locate_protocol (&apple_set_os_guid, 0);
+ if (!set_os) {
+ return grub_error (GRUB_ERR_FILE_NOT_FOUND,
+ "Could not locate the apple set os protocol.");
+ }
+
+ if (set_os->version != 0)
+ {
+ efi_call_1 (set_os->set_os_version, apple_os_version);
+ grub_printf("Set os version to %s\n", apple_os_version);
+ }
+
+ if (set_os->version == 2)
+ {
+ efi_call_1 (set_os->set_os_vendor, apple_os_vendor);
+ grub_printf("Set os vendor to %s\n", apple_os_vendor);
+ }
+
+ return 0;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT(applesetos)
+{
+ cmd = grub_register_command ("apple_set_os", grub_cmd_apple_set_os, NULL,
+ "Register as Apple Inc. Mac OS X 10.9.");
+}
+
+GRUB_MOD_FINI(applesetos)
+{
+ grub_unregister_command (cmd);
+}
--
1.8.5.2
next reply other threads:[~2013-12-30 16:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-30 16:04 Andreas Heider [this message]
2013-12-30 23:11 ` [PATCH] Add apple_set_os command SevenBits
2013-12-31 5:19 ` Andreas Heider
2014-01-03 6:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-01-03 17:26 ` SevenBits
2014-01-03 18:38 ` SevenBits
2014-01-07 15:19 ` andreas
2014-01-07 23:04 ` SevenBits
2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-01-07 14:46 ` Andrey Borzenkov
2014-01-07 14:58 ` andreas
-- strict thread matches above, loose matches on Subject: below --
2014-11-13 6:57 Michael Marineau
2015-04-09 10:50 Bruno Bierbaumer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1388419466-2023-1-git-send-email-andreas@heider.io \
--to=andreas@heider.io \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).