Long-time refind user here! Thanks for the absolutely awesome bootloader.
I recently got a MacBook Pro 2016 (MBP 13,3) with 2 GPUs (the integrated Intel Iris Pro and the discrete AMD RX 460). I'm currently working on getting Linux running smoothly on this model, and I ran into a couple of issues.
Specifically, I'm trying to get Linux to use the integrated intel graphics card (very interesting details here https://github.com/Dunedan/mbp-2016-linux/issues/6). Now I have the thing working using a utility called gpu-switch (https://github.com/0xbb/gpu-switch/) which is doing some EFI magic to switch cards. Refind's "spoof_osx_version 10.12" is used to power on the card.
Now the problem is, if I run the utilty from Linux and set it to integrated graphics and reboot, I can get Linux running perfectly on the Intel GPU. However, when I reboot into macOS, boot hangs. This seems to be connected to gpu-switch, since if I go back into Linux and switch it to the discrete graphics, macOS boots fine. I therefore can't seamlessly reboot into macOS or Linux simultaneously. This leads me to think that we can streamline things a lot if we can get refind to do some automatic stuff here :
1. If we are booting into macOS, set the dGPU option.
2. If we are booting into Linux, set the iGPU option.
Do you think this is possible to do? The gpu-switch source should be able to give you implementation details on what's needed.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It looks like the script you reference is just writing one value to the gpu-power-prefs EFI NVRAM variable to enable one device, and another value to enable another device. That part would be easy enough to implement in rEFInd; it already modifies the csr-active-config variable, the PreviousBoot variable, and one or two others under certain circumstances, so the code for writing to gpu-power-prefs would be similar.
The tricky part is in figuring out what to write and under what circumstances. That detail is likely to be very hardware- and OS-specific -- that is, you might need to write 1 for Windows and Linux but 0 for macOS on Machine A, but 1 for Windows and MacOS and 0 for Linux on Machine B. Then there's the question of what to do with more obscure OSes, BIOS-mode boots, etc. Because all of this would likely vary from one machine to another, you'd probably need a configuration file option to tell rEFInd what to write for particular OSes. That task could be complex enough to require some new option parsing code. Alternatively, a new configuration file in the same directory as the boot loader (akin to refind_linux.conf) could be used to set the option on a per-OS basis, but that adds its own complexity.
In any event, a crude proof-of-concept version that sets the values in a hard-coded way for your own computer would be the best first step. I may be able to get to that in a few days, but if you want to give it a try yourself, you'd need to use the EfivarSetRaw() function in refind/lib.c to write the variable. You'd need to set the 0 or 1 values you're doing via your Bash script, perhaps from StartEFIImage() or StartEFIImageList() in refind/main.c, keying off of the OSType variable to set the appropriate value. If the desired behavior can be created in a hard-coded way, then we can start to consider the user interface details; but if it doesn't work from rEFInd for some reason, it's probably best to leave the user interface issues until the hard-coded switching can be made to work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Rod,
Long-time refind user here! Thanks for the absolutely awesome bootloader.
I recently got a MacBook Pro 2016 (MBP 13,3) with 2 GPUs (the integrated Intel Iris Pro and the discrete AMD RX 460). I'm currently working on getting Linux running smoothly on this model, and I ran into a couple of issues.
We are tracking the general progress on Linux here : https://github.com/Dunedan/mbp-2016-linux
Specifically, I'm trying to get Linux to use the integrated intel graphics card (very interesting details here https://github.com/Dunedan/mbp-2016-linux/issues/6). Now I have the thing working using a utility called gpu-switch (https://github.com/0xbb/gpu-switch/) which is doing some EFI magic to switch cards. Refind's "spoof_osx_version 10.12" is used to power on the card.
Now the problem is, if I run the utilty from Linux and set it to integrated graphics and reboot, I can get Linux running perfectly on the Intel GPU. However, when I reboot into macOS, boot hangs. This seems to be connected to gpu-switch, since if I go back into Linux and switch it to the discrete graphics, macOS boots fine. I therefore can't seamlessly reboot into macOS or Linux simultaneously. This leads me to think that we can streamline things a lot if we can get refind to do some automatic stuff here :
1. If we are booting into macOS, set the dGPU option.
2. If we are booting into Linux, set the iGPU option.
Do you think this is possible to do? The gpu-switch source should be able to give you implementation details on what's needed.
Thanks!
It looks like the script you reference is just writing one value to the
gpu-power-prefs
EFI NVRAM variable to enable one device, and another value to enable another device. That part would be easy enough to implement in rEFInd; it already modifies thecsr-active-config
variable, thePreviousBoot
variable, and one or two others under certain circumstances, so the code for writing togpu-power-prefs
would be similar.The tricky part is in figuring out what to write and under what circumstances. That detail is likely to be very hardware- and OS-specific -- that is, you might need to write
1
for Windows and Linux but0
for macOS on Machine A, but1
for Windows and MacOS and0
for Linux on Machine B. Then there's the question of what to do with more obscure OSes, BIOS-mode boots, etc. Because all of this would likely vary from one machine to another, you'd probably need a configuration file option to tell rEFInd what to write for particular OSes. That task could be complex enough to require some new option parsing code. Alternatively, a new configuration file in the same directory as the boot loader (akin torefind_linux.conf
) could be used to set the option on a per-OS basis, but that adds its own complexity.In any event, a crude proof-of-concept version that sets the values in a hard-coded way for your own computer would be the best first step. I may be able to get to that in a few days, but if you want to give it a try yourself, you'd need to use the
EfivarSetRaw()
function inrefind/lib.c
to write the variable. You'd need to set the0
or1
values you're doing via your Bash script, perhaps fromStartEFIImage()
orStartEFIImageList()
inrefind/main.c
, keying off of theOSType
variable to set the appropriate value. If the desired behavior can be created in a hard-coded way, then we can start to consider the user interface details; but if it doesn't work from rEFInd for some reason, it's probably best to leave the user interface issues until the hard-coded switching can be made to work.