0xbb / gpu-switch

gpu-switch is an application that allows to switch between the graphic cards of dual-GPU Macbook Pro models
MIT License
537 stars 57 forks source link

write error: Invalid argument #40

Open pipolo opened 7 years ago

pipolo commented 7 years ago

Hello there !

Trying to revive a MacBookPro 6,2, I'm having the exact same issue as described in a previous thread (I commented it but decided to open a new issue when noticing it was closed). ./gpu-switch: line 44: printf: write error: Invalid argument

I'm intending to use OS X 10.11.6, so the fix to run Ubuntu on integrated graphics will obviously not work.

Thanks for your work and thanks in advance for your kind help.

pipolo commented 7 years ago

Nobody ? Really ?

ah- commented 7 years ago

Sorry, I just don't quite know what's wrong. I suspect this is some efi variable protection introduced in recent kernels, but I might be completely wrong about that.

The script just tries to create an efi variable that tells the firmware what GPU to use, and it seems the kernel doesn't let it do that.

pipolo commented 7 years ago

Hello !

I also suspected some additional security concerning /sys/firmware/efi/efivars/, so after a few unsuccessful attempts using archlinux-2017.05.01, I downloaded archlinux-2017.03.01 but encountered the same issue (I originally followed the procedure described here).

I wonder if an older release could work, and wish I could bring more useful inputs.

bethnull commented 6 years ago

Hi pipolo,

Have you found any solution to the printf: write error: Invalid argument?

I've also followed the steps of the macrumors thread and I'm stuck trying to recreate the gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 file, surprisingly I was able to delete it but not creating the file again.

Regards and thanks in advance.

pipolo commented 6 years ago

Hello bethnull,

I found out a workaround described here.

Simply boot in single user mode, and carefully type this command : sudo nvram fa4ce28d-b62f-4c99-9cc3-6815686e30f9:gpu-power-prefs=%01%00%00%00

That should lock your MBP in integrated GPU mode. Can't guarantee it'll persist that way, as an update or a reset PRAM will probably restore your Mac to its default behavior, switching from integrated to discrete GPU and crash.

bethnull commented 6 years ago

Hi, I'm running out of luck, I can't boot in single user mode as the OS is not able to boot, well it can boot but I've to choose the startup disk as I've installed OSX sierra using the hd in another macbook air via an external usb3 sata adapter.

As the OSX was installed using another computer it isn't detected as the startup disk, also I can't boot to recovery to change it because it hangs with the same gray screen I'm having when booting choosing the OSX Sierra.

So to summarise, I've to press the option key to choose the startup disk but doing this I am not able to press cmd + s to boot in single mode. If I boot with cmd + r to boot into recovery it hangs and if I boot with option and choose the recovery partition it also hangs. Jejejeje crazy!!!

It's possible to run nvram from another OS??

pipolo commented 6 years ago

Hello again,

Resetting PRAM should force it to startup on your newly installed system. Then you be able to cmd+s to boot into single user mode (I'm pretty sure you can also do it from the boot menu, just hold the keys before clinking your boot drive).

I recommend posting to this Macrumors forum thread if you need any further help.

bethnull commented 6 years ago

Hi, I don't know what happened but yesterday I was able to execute gpu-switch without the printf: write error: Invalid argument. To be honest I was executing each of the commands manually as indicated in the MacRumors forum thread, but yesterday as a last resort I tried gpu-switch and it worked!

After that I was able to boot into recovery, remove the firmware password, set the startup disk, and now I have a working computer!

I can confirm that gpu-switch works in a 15" early 2011 macbook pro. Thanks pipolo for your help and 0xbb for the gpu-switch script.

All the best, beth.

sudo-Max2 commented 3 years ago

Subscribed to help. Had same issue. found solution here: https://askubuntu.com/questions/1004619/cannot-write-to-efivars Correct command: printf "\x07\x00\x00\x00\x01\x00\x00\x00" > /sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9

Either it was necessary to do everything fast. For some reason when you spend a time to type commands - file some-how recreated or smth like that. no idea. But when you repeat command by getting them from history - all works fine.

kambala-decapitator commented 1 year ago

facing same issue on 6,2 but none of the methods to set the NVRAM variable work for me - all of them either fail or the variable is not there after reboot (and dh 112 in EFI shell doesn't report that iGPU drives the screen). Any idea?

have various OSs installed, only one Linux though - Endeavour OS (Arch distro). I posted more details about my situation at https://forums.macrumors.com/threads/running-windows-with-fully-disabled-dgpu-on-an-old-mbp.2368512/

kambala-decapitator commented 1 year ago

I've discovered another variable that allows selecting active GPU at boot time (well, at least on 6,2):

nvram GfxMode=4

to activate iGPU at boot time and power down dGPU completely. You can also set it to 0 for iGPU, but this will not power down dGPU, i.e. both dGPU and its HD Audio device will be detectable.

see my detailed info at https://forums.macrumors.com/threads/force-2011-macbook-pro-8-2-with-failed-amd-gpu-to-always-use-intel-integrated-gpu-efi-variable-fix.2037591/post-31801562