Skip to content

Using UEFIPatch

Curi0 edited this page Mar 6, 2024 · 53 revisions

Many consumer motherboards have issues handling 64-bit BARs which are required for Resizable BAR to work at its full size. Here you can find out how to use UEFIPatch (part of UEFITool) to patch UEFI to make it compatible with 64-bit BARs and solve various issues.

Working patches

  • <4GB BAR size limit removal
  • <16GB BAR size limit removal
  • <64GB BAR size limit removal
  • Prevent 64-bit BARs from being downgraded to 32-bit
  • Increase MMIO space to 64GB (Haswell/Broadwell). Full 512GB/39-bit isn't possible yet.
  • Increase MMIO space from 16GB to full usage of 64GB/36-bit range (Sandy/Ivy Bridge). Requires DSDT modification on certain motherboards. See wiki page DSDT Patching for more information.
  • Remove NVRAM whitelist to solve ReBarState GetLastError: 5 / Access Denied
  • X79 Above 4G Decoding fix

Using UEFIPatch

  1. Download UEFIPatch from here. As of writing this the latest version is 0.28.0 released in March 2020.
  2. Download patches.txt and place it into a folder along with UEFIPatch and your BIOS file. It should look something like this image

You don't have to select individual patches in patches.txt, just use the file as is.

X79 systems will need to uncomment (remove # on second line with hex codes) the patch Extend MMIOH limit to fix Above 4G Decoding (X79), it's commented because of its possible incompatibility with multi CPU systems. Do not use this patch if your X79 already has working 4G decoding such as on a few AliExpress boards.

  1. Run UEFIPatch on the BIOS file in command prompt/Powershell/terminal. It should look something like below the patches will differ depending on your BIOS image
  • Intel 7 Series Chipset (B75/Z75/H77/Z77/Q75/Q77/C216) will additionally need to apply IvyUSB3.txt for functioning USB 3 ports in BIOS with 4G Decoding enabled. Use .\UEFIPatch YOURBIOS.bin.patched .\IvyUSB3.txt -o YOURBIOS.bin.patched after downloading and placing it in the same folder as UEFIPatch.

  • Intel 8 Series Chipset (H81/B85/Q85/Q87/H87/Z87/C222/C224/C226) will additionally need to apply HswUSB3.txt for functioning USB 3 ports in BIOS with 4G Decoding enabled. Use .\UEFIPatch YOURBIOS.bin.patched .\HswUSB3.txt -o YOURBIOS.bin.patched after downloading and placing it in the same folder as UEFIPatch.

  • Intel 9 Series Chipset (H97/Z97) will additionally need to apply BdwUSB3.txt for functioning USB 3 ports in BIOS with 4G Decoding enabled. Use .\UEFIPatch YOURBIOS.bin.patched .\BdwUSB3.txt -o YOURBIOS.bin.patched after downloading and placing it in the same folder as UEFIPatch.

If you get No patches can be applied to input file you can skip this and continue to DSDT Patching using the unpatched BIOS file.

Any errors reported by UEFIPatch are safe to ignore.

  1. You'll get a new file created with .patched as the extension. This file will be used for the next steps if there isn't pad file issue. If you used the USB 3 patch make sure there is no file with extension .patched.patched.

Checking for pad file issue

UEFITool/UEFIPatch have a bug which results in pad file corruption that affects mostly ASUS motherboards. Pad file corruption will cause boot failure which can only be fixed by flashing a proper BIOS. You can check for this issue by comparing pad files of the modified volume in UEFITool.

Good (both pad files being same, if you can't find pad file in DXE volume it's also ok)

image

Bad (pad file gets changed)

image

Pad file issue workaround

Until bug #231 is fixed in UEFITool/UEFIPatch this will be required. Note that this requires MMTool which internal AMI software linking it here will probably result in this repo being DMCAed. You can easily find it online though. Make sure to use MMTool version 4.50.0.23

  1. Open the .patched BIOS in UEFITool and Extract as is the .ffs files of the modules that were patched. You can find these by looking at the patches.txt file and seeing which ones were patched. In this case it is PciBus and PciHostBridge.

    image

  2. Open your unpatched BIOS in MMTool (click Load Image). Select the module you want to replace and click the Replace tab. Click Browse and select the patched .ffs file. image

  3. Click Replace. Repeat this for the other patched .ffs module(s) and be careful not be mix them up.

  4. Click Save Image As to save the modified BIOS. This file will be used for the next steps.

Verify that the pad files are proper before continuing.

When replacing a TE Image (used only for the X79 4G decoding fix) you may find that even MMTool still causes pad file issue, in that case you will need to manually do the patch using a hex editor. @ZOXZX explained it in the comment here. Also if you have any issues applying the Runtime patch it's completely optional (used for EFI applications accessing PCIe BAR like OpenCore boot audio) and you can skip it.

Continue to DSDT Patching

Thanks @romulus2k4 for discovering this workaround for the pad file issues.

If you're interested in creating your own patches, these were all reverse engineered using Ghidra with efiSeek plugin.