* [PATCH] Add apple_set_os command
@ 2013-12-30 16:04 Andreas Heider
2013-12-30 23:11 ` SevenBits
2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 2 replies; 13+ messages in thread
From: Andreas Heider @ 2013-12-30 16:04 UTC (permalink / raw)
To: grub-devel; +Cc: Andreas Heider
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
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2013-12-30 16:04 [PATCH] Add apple_set_os command Andreas Heider
@ 2013-12-30 23:11 ` SevenBits
2013-12-31 5:19 ` Andreas Heider
2014-01-03 6:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
1 sibling, 2 replies; 13+ messages in thread
From: SevenBits @ 2013-12-30 23:11 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 5114 bytes --]
On Monday, December 30, 2013, Andreas Heider wrote:
> 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.
Just a question: I do a lot of booting Linux on MacBooks, and I frequently
suffer from this issue. How do we know that this code actually works? I'm
not criticizing your code or anything, but how can you verify that
identifying as Apple fixes these issues, or even that this patch works
correctly. I'm only asking because I'm very interested in this if it works.
> ---
> 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;
Out of curiosity: how did you find these?
> +
> +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.";
Why are you making OS X 10.9 the default? Not every Mac can run 10.9.
Ideally it would be very cool if you could figure out which version the
user is running and identify as that.
Secondly, you should include fallbacks in case this is run on a machine
that isn't a Mac, as then that GUID and protocol won't be defined. It
should exit gracefully, perhaps with an error message.
> +
> +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
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org <javascript:;>
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
[-- Attachment #2: Type: text/html, Size: 6440 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2013-12-30 23:11 ` SevenBits
@ 2013-12-31 5:19 ` Andreas Heider
2014-01-03 6:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
1 sibling, 0 replies; 13+ messages in thread
From: Andreas Heider @ 2013-12-31 5:19 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 6530 bytes --]
Am 31.12.2013 um 00:11 schrieb SevenBits <sevenbitstech@gmail.com>:
> On Monday, December 30, 2013, Andreas Heider wrote:
> 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.
>
> Just a question: I do a lot of booting Linux on MacBooks, and I frequently suffer from this issue. How do we know that this code actually works? I'm not criticizing your code or anything, but how can you verify that identifying as Apple fixes these issues, or even that this patch works correctly. I'm only asking because I'm very interested in this if it works.
This depends, it just notifies all interested EFI drivers that they’re booting Mac OS X, so there’s no general answer. On my laptop this stops the integrated gnu from being disabled, so you could see it in lspci. But I guess you should see some difference in dmesg before and after.
There might be side effects of other things breaking in osx-mode due to the different configuration, so I implemented this as a optional command and not the default.
Also, this is just one of the ways Apple detects osx vs other operating systems, for example this does not help with acpi_osi=Darwin.
If you want to test it I’m interested if apple_set_os changes anything noteworthy on older models. They only started to support bootcamp via EFI this year, so I suspect that the hardware disabling took place in the BIOS/CSM before.
>
> ---
> 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;
>
> Out of curiosity: how did you find these?
>
> +
> +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.";
>
> Why are you making OS X 10.9 the default? Not every Mac can run 10.9. Ideally it would be very cool if you could figure out which version the user is running and identify as that.
AFAIK the os_version is never even read by the Apple EFI, so I just kept it as simple as possible. We could also just put GRUB as the version.
>
> Secondly, you should include fallbacks in case this is run on a machine that isn't a Mac, as then that GUID and protocol won't be defined. It should exit gracefully, perhaps with an error message.
It should fail with "Could not locate the apple set os protocol.“.
>
> +
> +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
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
[-- Attachment #2: Type: text/html, Size: 10253 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2013-12-30 23:11 ` 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
1 sibling, 2 replies; 13+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2014-01-03 6:46 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 873 bytes --]
On 31.12.2013 00:11, SevenBits wrote:
> On Monday, December 30, 2013, Andreas Heider wrote:
>
> 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.
>
>
> Just a question: I do a lot of booting Linux on MacBooks, and I
> frequently suffer from this issue. How do we know that this code
> actually works?
Run on a mac with this code and without and compare results. The ship of
"works by sane design" has long since sailed away. For most
manufacturers it's somewhere in Moon orbit but for apple it has long
since left solar system.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2014-01-03 6:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2014-01-03 17:26 ` SevenBits
2014-01-03 18:38 ` SevenBits
1 sibling, 0 replies; 13+ messages in thread
From: SevenBits @ 2014-01-03 17:26 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 1760 bytes --]
On Friday, January 3, 2014, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 31.12.2013 00:11, SevenBits wrote:
> > On Monday, December 30, 2013, Andreas Heider wrote:
> >
> > 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.
> >
> >
> > Just a question: I do a lot of booting Linux on MacBooks, and I
> > frequently suffer from this issue. How do we know that this code
> > actually works?
> Run on a mac with this code and without and compare results. The ship of
> "works by sane design" has long since sailed away. For most
> manufacturers it's somewhere in Moon orbit but for apple it has long
> since left solar system.
Believe me, I'm done quite a bit of work with Apple's EFI and it is
certainly a pain in the neck once you start digging underneath the surface
and doing anything more than really basic stuff. Some MacBooks for instance
are still running EFI 1.x while some newer ones implement 2.x... It's quite
a disaster considering those older machines are still in use.
I'll give the patch a try. Hopefully it will work. I'm personally fearful
that it won't make any difference, but you never know. I love Apple
products, I think they're great stuff, but the EFI implementation can drive
you crazy and OS X boots in a roundabout way, which gives Linux fans like
myself headaches when we try to boot Linux on the machines.
Anyway, I'll give it a go and report what I find.
[-- Attachment #2: Type: text/html, Size: 2074 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
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
1 sibling, 1 reply; 13+ messages in thread
From: SevenBits @ 2014-01-03 18:38 UTC (permalink / raw)
To: grub-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 01/03/2014 01:46 AM, Vladimir '?-coder/phcoder' Serbinenko wrote:
> On 31.12.2013 00:11, SevenBits wrote:
>> On Monday, December 30, 2013, Andreas Heider wrote:
>>
>> 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.
>>
>>
>> Just a question: I do a lot of booting Linux on MacBooks, and I
>> frequently suffer from this issue. How do we know that this code
>> actually works?
> Run on a mac with this code and without and compare results. The
> ship of "works by sane design" has long since sailed away. For
> most manufacturers it's somewhere in Moon orbit but for apple it
> has long since left solar system.
So, Andreas, I tried your patch, and... no dice. The Mac behaves
exactly as before. I'm afraid it didn't appear to do anything for me.
Furthermore, your patch didn't print any output. There wasn't any
error message returned (i.e your "Could not locate the apple set os
protocol." message on line 52-53). When I invoked your command from
the GRUB normal prompt, it DID print the message however. Perhaps it
doesn't fail if called from within a grub.cfg, or maybe it simply
doesn't print.
The Mac that I tested on was a MacBook Pro from early 2008. Clearly,
this function isn't present on all models. I can try it on others and
seeing if it works on them, however.
Also, why the if statements on lines 59 and 65, which indicate whether
the OS version and/or vendor was set. What is the point of them? Why
not just call the functions directly?
>
>
>
> _______________________________________________ Grub-devel mailing
> list Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSxwOMAAoJEFbRvtGxmFPELWoH+QGu7aLuDam0vY+xW8h4TdFw
ckY51K8vgEGlpUNvK2fwQnnAt57W3jH14HBIRY1IaC+c9XA3mooqp748xh0jfoV/
D95lZJuYu3XP4iFYtCehcCVOiz+x4DNXMnT6WA6hd5FjPT9xqbBqf/9RxSpN9O+i
ZGbSe/ZQkOvTyLXJ11L3SeTlNi9jqA03mLaMrMi7Ehb7AU3hBkiSMpiiIcUjnP3o
ZskQrSkguqt9Kt+FlHheTJkpAitqqJR/GpHkegg3bNGLrflacVGITMFFw0EsJP4R
h0fsEocfYnvSVPrw07SJVFvt2TzPGB69p5QXy11cU1ZBYUhILcG7rDTAmVctZig=
=wKye
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2013-12-30 16:04 [PATCH] Add apple_set_os command Andreas Heider
2013-12-30 23:11 ` SevenBits
@ 2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-01-07 14:46 ` Andrey Borzenkov
2014-01-07 14:58 ` andreas
1 sibling, 2 replies; 13+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2014-01-07 13:38 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 803 bytes --]
On 30.12.2013 17:04, Andreas Heider wrote:
> +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.";
> +
Can those be optionally supplied on command line?
E.g.
apple_set_os [[VENDOR] VERSION]
On the other hand we should probably start collecting whitelist of macs
who need this and do it on them automatically. Idk if there is EFI
variable to identify mac model from EFI but it's possible from SMBIOS.
> +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;
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2014-01-07 14:46 ` Andrey Borzenkov
2014-01-07 14:58 ` andreas
1 sibling, 0 replies; 13+ messages in thread
From: Andrey Borzenkov @ 2014-01-07 14:46 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 693 bytes --]
В Вт, 07/01/2014 в 14:38 +0100, Vladimir 'φ-coder/phcoder' Serbinenko
пишет:
> On 30.12.2013 17:04, Andreas Heider wrote:
> > +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.";
> > +
> Can those be optionally supplied on command line?
> E.g.
> apple_set_os [[VENDOR] VERSION]
> On the other hand we should probably start collecting whitelist of macs
> who need this and do it on them automatically. Idk if there is EFI
> variable to identify mac model from EFI but it's possible from SMBIOS.
I wonder what became of smbios command. Would be good to have generic
way to fetch it.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2014-01-07 13:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
2014-01-07 14:46 ` Andrey Borzenkov
@ 2014-01-07 14:58 ` andreas
1 sibling, 0 replies; 13+ messages in thread
From: andreas @ 2014-01-07 14:58 UTC (permalink / raw)
To: grub-devel
Am 2014-01-07 14:38, schrieb Vladimir 'φ-coder/phcoder' Serbinenko:
> On 30.12.2013 17:04, Andreas Heider wrote:
>> +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.";
>> +
> Can those be optionally supplied on command line?
> E.g.
> apple_set_os [[VENDOR] VERSION]
> On the other hand we should probably start collecting whitelist of macs
> who need this and do it on them automatically. Idk if there is EFI
> variable to identify mac model from EFI but it's possible from SMBIOS.
I'll try to find the time to implement the command line arguments
tonight, and I am pretty sure that there is a way to get the model from
EFI. I just hope that Apple implemented this correctly.
One thing I'm still wondering about is how this could integrate better
with EFISTUB. Do you know how for example the broadcom fix is applied in
that scenario? Is the same fix just duplicated in the Linux kernel?
Because if we implement a whitelist in grub and then suddenly Linux boot
properly with grub but not directly with EFISTUB things become quite
ugly.
>> +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-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2014-01-03 18:38 ` SevenBits
@ 2014-01-07 15:19 ` andreas
2014-01-07 23:04 ` SevenBits
0 siblings, 1 reply; 13+ messages in thread
From: andreas @ 2014-01-07 15:19 UTC (permalink / raw)
To: grub-devel
Am 2014-01-03 19:38, schrieb SevenBits:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 01/03/2014 01:46 AM, Vladimir '?-coder/phcoder' Serbinenko wrote:
>> On 31.12.2013 00:11, SevenBits wrote:
>>> On Monday, December 30, 2013, Andreas Heider wrote:
>>>
>>> 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.
>>>
>>>
>>> Just a question: I do a lot of booting Linux on MacBooks, and I
>>> frequently suffer from this issue. How do we know that this code
>>> actually works?
>> Run on a mac with this code and without and compare results. The
>> ship of "works by sane design" has long since sailed away. For
>> most manufacturers it's somewhere in Moon orbit but for apple it
>> has long since left solar system.
> So, Andreas, I tried your patch, and... no dice. The Mac behaves
> exactly as before. I'm afraid it didn't appear to do anything for me.
Hi,
thanks for testing! I suspect that your MacBook Pro is simply too old. I
don't know exactly when this protocol was introduced, I found references
to it on Hackintosh-Forums from a while ago and in the Mac OS X
internals book which is also a bit older.
What effect exactly were you looking for? Your MBP doesn't have a second
GPU to disable.
Also, AFAIK the older models disable less hardware when you boot via EFI
than the newer ones, since Bootcamp with EFI wasn't supported.
> Furthermore, your patch didn't print any output. There wasn't any
> error message returned (i.e your "Could not locate the apple set os
> protocol." message on line 52-53). When I invoked your command from
> the GRUB normal prompt, it DID print the message however. Perhaps it
> doesn't fail if called from within a grub.cfg, or maybe it simply
> doesn't print.
If it prints something on the promt I'd say it's working as intended,
although I'm pretty sure that I see output from it when I boot a
grub.cfg entry.
> The Mac that I tested on was a MacBook Pro from early 2008. Clearly,
> this function isn't present on all models. I can try it on others and
> seeing if it works on them, however.
If you have the time, please do. I'd be interested in what exactly
changes.
> Also, why the if statements on lines 59 and 65, which indicate whether
> the OS version and/or vendor was set. What is the point of them? Why
> not just call the functions directly?
It's just some output so you know that the command did something.
>>
>>
>>
>> _______________________________________________ Grub-devel mailing
>> list Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.14 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQEcBAEBAgAGBQJSxwOMAAoJEFbRvtGxmFPELWoH+QGu7aLuDam0vY+xW8h4TdFw
> ckY51K8vgEGlpUNvK2fwQnnAt57W3jH14HBIRY1IaC+c9XA3mooqp748xh0jfoV/
> D95lZJuYu3XP4iFYtCehcCVOiz+x4DNXMnT6WA6hd5FjPT9xqbBqf/9RxSpN9O+i
> ZGbSe/ZQkOvTyLXJ11L3SeTlNi9jqA03mLaMrMi7Ehb7AU3hBkiSMpiiIcUjnP3o
> ZskQrSkguqt9Kt+FlHheTJkpAitqqJR/GpHkegg3bNGLrflacVGITMFFw0EsJP4R
> h0fsEocfYnvSVPrw07SJVFvt2TzPGB69p5QXy11cU1ZBYUhILcG7rDTAmVctZig=
> =wKye
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
2014-01-07 15:19 ` andreas
@ 2014-01-07 23:04 ` SevenBits
0 siblings, 0 replies; 13+ messages in thread
From: SevenBits @ 2014-01-07 23:04 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 4253 bytes --]
On Jan 7, 2014, at 10:19 AM, andreas@heider.io wrote:
> Am 2014-01-03 19:38, schrieb SevenBits:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> On 01/03/2014 01:46 AM, Vladimir '?-coder/phcoder' Serbinenko wrote:
>>> On 31.12.2013 00:11, SevenBits wrote:
>>>> On Monday, December 30, 2013, Andreas Heider wrote:
>>>> 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.
>>>> Just a question: I do a lot of booting Linux on MacBooks, and I
>>>> frequently suffer from this issue. How do we know that this code
>>>> actually works?
>>> Run on a mac with this code and without and compare results. The
>>> ship of "works by sane design" has long since sailed away. For
>>> most manufacturers it's somewhere in Moon orbit but for apple it
>>> has long since left solar system.
>> So, Andreas, I tried your patch, and... no dice. The Mac behaves
>> exactly as before. I'm afraid it didn't appear to do anything for me.
>
> Hi,
> thanks for testing! I suspect that your MacBook Pro is simply too old. I don't know exactly when this protocol was introduced, I found references to it on Hackintosh-Forums from a while ago and in the Mac OS X internals book which is also a bit older.
>
> What effect exactly were you looking for? Your MBP doesn't have a second GPU to disable.
> Also, AFAIK the older models disable less hardware when you boot via EFI than the newer ones, since Bootcamp with EFI wasn't supported.
I was looking for any change in the video behavior. You are correct that my MBP does not have a second GPU, but I was looking for any change at all that might indicate the patch worked.
Anyway, the patch didn’t work on my machine, so I guess the point is moot.
>
>> Furthermore, your patch didn't print any output. There wasn't any
>> error message returned (i.e your "Could not locate the apple set os
>> protocol." message on line 52-53). When I invoked your command from
>> the GRUB normal prompt, it DID print the message however. Perhaps it
>> doesn't fail if called from within a grub.cfg, or maybe it simply
>> doesn't print.
>
> If it prints something on the promt I'd say it's working as intended, although I'm pretty sure that I see output from it when I boot a grub.cfg entry.
>
>> The Mac that I tested on was a MacBook Pro from early 2008. Clearly,
>> this function isn't present on all models. I can try it on others and
>> seeing if it works on them, however.
>
> If you have the time, please do. I'd be interested in what exactly changes.
Perhaps it would be a good way to see which MBPs have this protocol as well.
>
>> Also, why the if statements on lines 59 and 65, which indicate whether
>> the OS version and/or vendor was set. What is the point of them? Why
>> not just call the functions directly?
>
> It's just some output so you know that the command did something.
>
>>> _______________________________________________ Grub-devel mailing
>>> list Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.14 (GNU/Linux)
>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>> iQEcBAEBAgAGBQJSxwOMAAoJEFbRvtGxmFPELWoH+QGu7aLuDam0vY+xW8h4TdFw
>> ckY51K8vgEGlpUNvK2fwQnnAt57W3jH14HBIRY1IaC+c9XA3mooqp748xh0jfoV/
>> D95lZJuYu3XP4iFYtCehcCVOiz+x4DNXMnT6WA6hd5FjPT9xqbBqf/9RxSpN9O+i
>> ZGbSe/ZQkOvTyLXJ11L3SeTlNi9jqA03mLaMrMi7Ehb7AU3hBkiSMpiiIcUjnP3o
>> ZskQrSkguqt9Kt+FlHheTJkpAitqqJR/GpHkegg3bNGLrflacVGITMFFw0EsJP4R
>> h0fsEocfYnvSVPrw07SJVFvt2TzPGB69p5QXy11cU1ZBYUhILcG7rDTAmVctZig=
>> =wKye
>> -----END PGP SIGNATURE-----
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 535 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add apple_set_os command
@ 2014-11-13 6:57 Michael Marineau
0 siblings, 0 replies; 13+ messages in thread
From: Michael Marineau @ 2014-11-13 6:57 UTC (permalink / raw)
To: andreas; +Cc: grub-devel
[-- Attachment #1: Type: text/plain, Size: 898 bytes --]
This is a long belated reply to an old thread:
https://lists.gnu.org/archive/html/grub-devel/2014-01/msg00017.html
I just wanted to note that I made a quick implementation of this a
while back for Linux's EFI-stub which may be useful to folks
interested in this issue. Revisiting it now since the current 3.18-rc
development tree has enough other fixes that using this trick with my
particular laptop (MacBookPro11,3) is nearly practical. My current
patch is certainly not suitable for upstream but my hunch is that
handling quirks like this makes a lot more sense in Linux than GRUB.
That would require GRUB to adopt launching Linux via the 'chainloader'
command (admittedly I haven't tried this) or the currently unmerged
'linuxefi' command from Fedora:
http://lists.gnu.org/archive/html/grub-devel/2014-01/msg00120.html
The attached patch for Linux is against 3.18-rc4+
--
Michael Marineau
[-- Attachment #2: 0001-efi-Identify-as-OS-X-to-EFI-drivers-before-booting.patch --]
[-- Type: text/x-patch, Size: 2727 bytes --]
From 1f2fcbbca18176e2e6c862774428dad878bbac51 Mon Sep 17 00:00:00 2001
From: Michael Marineau <mike@marineau.org>
Date: Sun, 30 Mar 2014 13:01:35 -0700
Subject: [PATCH] efi: Identify as OS X to EFI drivers before booting.
This prevents the firmware from powering down the integrated graphics
card on some recent 2013 Macbook Pro laptops. The trick was originally
posted as a command for GRUB2 by Andreas Heider.
http://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html
---
arch/x86/boot/compressed/eboot.c | 62 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 1acf605..419b368 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -1374,6 +1374,66 @@ free_mem_map:
return status;
}
+#define APPLE_SET_OS_PROTOCOL_GUID \
+ EFI_GUID(0xc5c5da95, 0x7d5c, 0x45e6, 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77)
+
+typedef struct {
+ u64 version;
+ void (*set_os_version) (const char *os_version);
+ void (*set_os_vendor) (const char *os_vendor);
+} apple_set_os_interface_t;
+
+static efi_status_t apple_set_os()
+{
+ apple_set_os_interface_t *set_os;
+ efi_guid_t set_os_guid = APPLE_SET_OS_PROTOCOL_GUID;
+ efi_status_t status;
+ void **handles;
+ unsigned long i, nr_handles, size = 0;
+
+ status = efi_call_early(locate_handle, EFI_LOCATE_BY_PROTOCOL,
+ &set_os_guid, NULL, &size, handles);
+
+ if (status == EFI_BUFFER_TOO_SMALL) {
+ status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
+ size, &handles);
+
+ if (status != EFI_SUCCESS)
+ return status;
+
+ status = efi_call_early(locate_handle, EFI_LOCATE_BY_PROTOCOL,
+ &set_os_guid, NULL, &size, handles);
+ }
+
+ if (status != EFI_SUCCESS)
+ goto free_handle;
+
+ nr_handles = size / sizeof(void *);
+ for (i = 0; i < nr_handles; i++) {
+ void *h = handles[i];
+
+ status = efi_call_early(handle_protocol, h,
+ &set_os_guid, &set_os);
+
+ if (status != EFI_SUCCESS || !set_os)
+ continue;
+
+ if (set_os->version > 0) {
+ efi_early->call((unsigned long)set_os->set_os_version,
+ "Mac OS X 10.9");
+ }
+
+ if (set_os->version >= 2) {
+ efi_early->call((unsigned long)set_os->set_os_vendor,
+ "Apple Inc.");
+ }
+ }
+
+free_handle:
+ efi_call_early(free_pool, handles);
+ return status;
+}
+
/*
* On success we return a pointer to a boot_params structure, and NULL
* on failure.
@@ -1445,6 +1505,8 @@ struct boot_params *efi_main(struct efi_config *c,
hdr->code32_start = bzimage_addr;
}
+ apple_set_os();
+
status = exit_boot(boot_params, handle, is64);
if (status != EFI_SUCCESS) {
efi_printk(sys_table, "exit_boot() failed!\n");
--
2.0.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH] Add apple_set_os command
@ 2015-04-09 10:50 Bruno Bierbaumer
0 siblings, 0 replies; 13+ messages in thread
From: Bruno Bierbaumer @ 2015-04-09 10:50 UTC (permalink / raw)
To: grub-devel
Hello!
I wanted to bring some attention to this patch:
https://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html
I haven been using this patch for months and it works well.
The current generation of dual GPU Macbook Pros turn off the integrated
Intel GPU when any other OS than Mac OS X is booted.
This works by MAC OS X identifying itself as a custom EFI protocol.
The mentioned patch adds a command (apple_set_os) that fakes this OS
identification to make all the hardware accessible.
It would be great if that patch could be merged so that distributions
will contain the command without manually patching grub.
I think the command is side-effect free as it just gets registered and
then can be run by users who need this quirk for their hardware.
References:
https://github.com/0xbb/gpu-switch#requirements
https://wiki.archlinux.org/index.php/MacBookPro11,x#Getting_the_integrated_intel_card_to_work_on_11.2C3
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1367109
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=781843
Greetings,
Bruno
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2015-04-09 10:50 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-30 16:04 [PATCH] Add apple_set_os command Andreas Heider
2013-12-30 23:11 ` 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
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).