Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC: NVRAM emulation, EFI_GLOBAL_VARIABLE_GUID, and Default Boot Entry with Startup Disk #580

Closed
williambj1 opened this issue Nov 17, 2019 · 14 comments

Comments

@williambj1
Copy link

williambj1 commented Nov 17, 2019

Feature Request

Add support for NVRAM write fix (or emulation) for EFI_GLOBAL_VARIABLE_GUID in OpenCore/FwRuntimeServices for devices that don't have working hardware NVRAM in macOS to make boot entry setting fully functional.

Background

After discussing in a Chinese chat group community for nearly 1 month, we figured out how this is related to NVRAM emulation and the setting of OpenCore's default boot option.


We experimented 3 different motherboards (Z390, C621 & HM370) and got the same results

Both tests are under these conditions:

  • DisableVariableWrite = Yes
  • LegacyEnable = YES
  • RequestBootVarRouting = YES
  • ScanPolicy = 0
  • ExposeSensitiveData = 0x03
  • FwRuntimeServices included
  • Hardware NVRAM reseted before each test (without VariableRuntimeDxe)
  • OpenCore's default boot item is BootCamp Windows
  • VariableRuntimeDxe compiled with emulation enabled

Boot0080 and BootOrder is NOT present under NVRAM/Block

Test 1: (Booted without VariableRuntimeDxe)

  1. Set Startup disk to Macintosh HD

  2. In Terminal:

    $ sudo nvram -x '8BE4DF61-93CA-11D2-AA0D-00E098032B8C:Boot0080' | /usr/bin/sed '/\<data\>/,/\<\/data\>/!d;//d' | /usr/bin/base64 --decode`
    nvram: Error getting variable - '8BE4DF61-93CA-11D2-AA0D-00E098032B8C:Boot0080': (iokit/common) data was not found
    
    $ sudo nvram boot-args
    boot-args    <Empty>
    
    $ sudo nvram boot-args="-v"
    
    $ sudo nvram boot-args
    boot-args    -v
  3. Entry 8BE4DF61-93CA-11D2-AA0D-00E098032B8C is not present in nvram.plist dumped by LogoutHook

  4. Restart and OpenCore's default boot option is still BootCamp Windows

Test 2: (Booted with VariableRuntimeDxe)

  1. Set Startup disk to Macintosh HD

  2. In Terminal:

    $ sudo nvram -x '8BE4DF61-93CA-11D2-AA0D-00E098032B8C:Boot0080' | /usr/bin/sed '/\<data\>/,/\<\/data\>/!d;//d' | /usr/bin/base64 --decode`
    Mac OS X
            �A
    %8W��2��a�e�V�Q�x�I�7OJ
    ��D$��t�|
             �I�G�.hB5�|̏�@��I����
    \(Whatever UUID)\System\Library\CoreServices\boot.efi�%
    
    $ sudo nvram boot-args
    boot-args    <Empty>
    
    $ sudo nvram boot-args="-v"
    
    $ sudo nvram boot-args
    boot-args    -v
  3. Entry 8BE4DF61-93CA-11D2-AA0D-00E098032B8C this time is present in nvram.plist dumped by LogoutHook

  4. Restart and OpenCore's default boot option is still BootCamp Windows

    • HOWEVER, if VariableRuntimeDxe is removed before restart at this moment, OpenCore's default boot option will successfully change into Macintosh HD

Conclusion

  • It seems that macOS can read and write variables into APPLE_NVRAM_VARIABLE_GUID but fails to write into EFI_GLOBAL_VARIABLE_GUID
  • To get correct values from EFI_GLOBAL_VARIABLE_GUID (Boot0080, BootOrder, etc.), an Emulated NVRAM layer must be used
  • OpenCore fails to read the default boot order from nvram.plist when VaribleRuntimeDxe is present
  • The default boot order is unchangeable unless a new nvram.plist is generated with VariableRuntimeDxe, which is quite inconvenient

Questions

  1. Is VariableRuntimeDxe completely replaced by OpenCore + FwRuntimeServices? (ref:https://github.com/cattyhouse/oc-guide/blame/33f657e44a1c372a7d1bcb1553b0947c3f2a28cf/README.md#L8) CC @cattyhouse
  2. What's the behavior of NVRAM resetting and Boot order setting in OpenCore when VariableRuntimeDxe is present?

Related issues comments:

#459 (comment)
#495 (comment)
#575 (comment)

Thanks for your patience for reading these words, we highly admire your hard work and respect your time. If this is non-sense, feel free to close this.

Edit[1]: Change links, add more details
Edit[2]: Terminal Copy-Paste error
Edit[3]: Clearity

@williambj1 williambj1 changed the title OC: Add support for NVRAM write fix (or emulation) for EFI_GLOBAL_VARIABLE_GUID in OpenCore/FwRuntimeServices OC: NVRAM emulation, EFI_GLOBAL_VARIABLE_GUID, and Default Boot Entry with Startup Disk Nov 17, 2019
@vit9696
Copy link
Contributor

vit9696 commented Nov 17, 2019

I think the issue is that DisableVariableWrite simply error-exits SetVariable interface in FwRuntimeServices.efi. Unlike APPLE_BOOT_VARIABLE_GUID, other GUIDs are not cached and are written immediately, thus saving and retrieving them with the script does not work.

  if (gCurrentConfig->WriteProtection) {
    return EFI_SECURITY_VIOLATION;
  }

To resolute this FwRuntimeServices will need setting/getting NVRAM variables to/from some memory structure. Feel free to contribute.

@williambj1
Copy link
Author

@vit9696 Thanks for your reply!

I'd really want to contribute but unfortunately, I have very limited knowledge in C and no experience in EDK2 at all. The only related code I could understand is the LogoutHook script. I apologize that I can't handle this.

@meaganmargaret
Copy link

Any progress on this? Because it is, at least for me and my system, a major failing. I cannot reliably set the boot order with OpenCore.

I also am not a programmer, but I would offer my Asus Sage system up for testing and experimentation, if that's of any value.

@errorexists
Copy link

errorexists commented Jan 26, 2020

Any progress on this? Because it is, at least for me and my system, a major failing. I cannot reliably set the boot order with OpenCore.

I also am not a programmer, but I would offer my Asus Sage system up for testing and experimentation, if that's of any value.

read here for NVRAM
acidanthera/OpenCorePkg@a825da4
https://www.hackintosh-forum.de/forum/thread/46154-natives-nvram-auf-dem-z390-durchbruch/

@meaganmargaret
Copy link

Errorexists:

Please don't assume I haven't read those references.
A Z390 system does NOT equal an Asus Sage X299 system! Not the same and they don't work on X299 systems.

I want OC to respect and USE the proper boot order on my system (an X299 Asus Sage), and these changes don't work! The may work for a Z390 system, but that is NOT my system!

@errorexists
Copy link

errorexists commented Jan 26, 2020

Errorexists:

Please don't assume I haven't read those references.
A Z390 system does NOT equal an Asus Sage X299 system! Not the same and they don't work on X299 systems.

I want OC to respect and USE the proper boot order on my system (an X299 Asus Sage), and these changes don't work! The may work for a Z390 system, but that is NOT my system!

Any progress on this? Because it is, at least for me and my system, a major failing. I cannot reliably set the boot order with OpenCore.

I also am not a programmer, but I would offer my Asus Sage system up for testing and experimentation, if that's of any value.

hold your horses their you did not "specify" that it was a x299 system now did you
if you also read this has nothing to do with a x299

@ghost
Copy link

ghost commented Jan 26, 2020

Specifying the Chipset would be helpful :)

@meaganmargaret
Copy link

meaganmargaret commented Jan 26, 2020 via email

@errorexists
Copy link

well you need NVRAM to bless the drive an that is accomplished from selecting the boot drive from the startup in the system pref

@meaganmargaret
Copy link

Okay, I'll try one more time.

Here's the original request: "......OpenCore/FwRuntimeServices for devices that don't have working hardware NVRAM in macOS to make boot entry setting fully functional...."

And also: the originator of this request, williambj1, posted that he would offer three different motherboards for testing, and one of them was: C621, which is an X299 motherboard. So the purpose of this feature request was to deal with the C621 (on mostly Asus boards) NVRAM and OC's failure to respect boot order. That was the purpose of the request.

Well, maybe they now have NVRAM, but it doesn't matter. On an X299 C621 system, nvram or not, the "...make boot entry setting fully functional...." does NOT work.

I've set the boot order any number of times (like over a hundred - and yes that means rebooting that many times), and it doesn't work.

@errorexists
Copy link

NVRAM is not supported for the x299 an x99 as read here
https://khronokernel-2.gitbook.io/opencore-vanilla-desktop-guide/post-install/nvram

@meaganmargaret
Copy link

I've also read that. I'm looking for work-arounds.

This is pointless.

@cattyhouse
Copy link
Contributor

Errorexists:

Please don't assume I haven't read those references.
A Z390 system does NOT equal an Asus Sage X299 system! Not the same and they don't work on X299 systems.

I want OC to respect and USE the proper boot order on my system (an X299 Asus Sage), and these changes don't work! The may work for a Z390 system, but that is NOT my system!

Stay hungry, stay foolish.

@vit9696
Copy link
Contributor

vit9696 commented Jan 27, 2020

We do not plan to work on this issue, but we can consider contributed patches.

@acidanthera acidanthera locked and limited conversation to collaborators Jan 27, 2020
@vit9696 vit9696 closed this as completed May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

6 participants