From 01db6a0a234919bdb91e196d1e205450e2bced79 Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Sun, 26 Feb 2023 02:20:20 +0000 Subject: [PATCH] EnableGop: Update vBIOS insertion script - Add AMD support - Add GOP offset auto-detection - Support back to 10.11 El Capitan --- Changelog.md | 1 + Staging/EnableGop/NvInsertEfi.sh | 117 -------------- Staging/EnableGop/README.md | 69 ++++---- Staging/EnableGop/vBiosInsert.sh | 268 +++++++++++++++++++++++++++++++ build_oc.tool | 2 +- 5 files changed, 302 insertions(+), 155 deletions(-) delete mode 100755 Staging/EnableGop/NvInsertEfi.sh create mode 100755 Staging/EnableGop/vBiosInsert.sh diff --git a/Changelog.md b/Changelog.md index 6991f24c..0b6670bb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ OpenCore Changelog - Resolved issues with verbose boot log appearing over picker graphics - Added version number to EnableGop UI section, so tool builders can track it - Added `ProvideCurrentCpuInfo` support for macOS 13.3 DP +- Added AMD support, GOP offset auto-detection and macOS 10.11+ support to EnableGop vBIOS insertion script #### v0.8.9 - Improved debug logging when applying ACPI patches diff --git a/Staging/EnableGop/NvInsertEfi.sh b/Staging/EnableGop/NvInsertEfi.sh deleted file mode 100755 index 633fe579..00000000 --- a/Staging/EnableGop/NvInsertEfi.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -# -# Copyright © 2023 Mike Beaton. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause -# -# Insert EFI into Nvidia VBIOS. -# -# TODO: Check that original GOP is present, and locate it in the original file automatically. -# - -usage() { - echo "Usage: ./${SELFNAME} {rom-file} {efi-file} {GOP offset} {out-file}" - echo "E.g.:" - echo " ./${SELFNAME} nv.rom GOP.efi 0xFC00 mod.rom" - echo " ./${SELFNAME} nv.rom GOP.efi 64512 mod.rom" - echo "" -} - -SELFNAME="$(/usr/bin/basename "${0}")" - -if [ "$#" -ne 4 ] ; then - usage - exit 0 -fi - -commands=( - "EfiRom" - "UEFIRomExtract" -) -FOUND=1 -for command in "${commands[@]}"; do - if ! command -v "$command" 1>/dev/null ; then - echo "${command} not available!" - FOUND=0 - fi -done - -if [ "$FOUND" -eq 0 ] ; then - exit 1 -fi - -ROM_FILE="$1" -EFI_FILE="$2" -GOP_OFFSET="$3" -OUT_FILE="$4" - -# https://unix.stackexchange.com/a/84980/340732 -tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'vbios') || exit 1 - -echo "Splitting original ROM..." - -dd bs=1 if="$ROM_FILE" of="$tmpdir/original_first_part.rom" count=$(($GOP_OFFSET)) status=none || exit 1 -dd bs=1 if="$ROM_FILE" of="$tmpdir/original_last_part.rom" skip=$(($GOP_OFFSET)) status=none || exit 1 - -echo "Compressing ${EFI_FILE} using EfiRom..." -EfiRom -o "$tmpdir/insert.rom" -ec "$EFI_FILE" -f 0xAAAA -i 0xBBBB -l 0x30000 || exit 1 - -echo "Adding Nvidia header..." -dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_first_part" count=$((0x38)) status=none || exit 1 -dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_last_part" skip=$((0x38)) status=none || exit 1 - -INSERT_SIZE=$(stat -f%z "$tmpdir/insert.rom") || exit 1 - -# add NPDE from original GOP -dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_first_part" skip=$((0x38)) seek=$((0x38)) count=$((0x18)) status=none || exit 1 -cat "$tmpdir/insert_first_part" "$tmpdir/insert_last_part" > "$tmpdir/insert_oversize.rom" || exit 1 -# `truncate` not present by default on macOS -dd bs=1 if="$tmpdir/insert_oversize.rom" of="$tmpdir/insert_fixed.rom" count="$INSERT_SIZE" status=none || exit 1 - -# patch size in NPDE -dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x2)) seek=$((0x48)) count=1 conv=notrunc status=none || exit 1 - -# patch with vendor and device id from original GOP -dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x20)) seek=$((0x20)) count=4 conv=notrunc status=none || exit 1 - -# patch size in PCIR -dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x16)) seek=$((0x16)) count=1 conv=notrunc status=none || exit 1 - -# patch end marker in NPDE in fixed ROM (leave PCIR correct and EFI extractable from fixed ROM) -echo -n -e '\x00' | dd bs=1 of="$tmpdir/insert_fixed.rom" seek=$((0x4A)) conv=notrunc status=none || exit 1 - -echo "Writing ${OUT_FILE}..." -cat "$tmpdir/original_first_part.rom" "$tmpdir/insert_fixed.rom" "$tmpdir/original_last_part.rom" > "$OUT_FILE" || exit 1 - -# patch end marker in PCIR in out file -echo -n -e '\x00' | dd bs=1 of="$OUT_FILE" seek=$(($GOP_OFFSET + 0x31)) conv=notrunc status=none || exit 1 - -echo "Verifying ${OUT_FILE}..." -dd bs=1 if="$OUT_FILE" of="$tmpdir/out_efi_part.rom" skip=$(($GOP_OFFSET)) status=none || exit 1 -UEFIRomExtract "$tmpdir/out_efi_part.rom" "$tmpdir/extracted.efi" 1>/dev/null || exit 1 -ERROR=0 -diff "$tmpdir/extracted.efi" "$EFI_FILE" 1>/dev/null || ERROR=1 - -if [ "$ERROR" -ne 0 ] ; then - echo " - Failure comparing extracted EFI to original!" -fi - -OLD_EFI_COUNT=$(EfiRom -d "$tmpdir/original_last_part.rom" | grep "0x0EF1" | wc -l) || exit 1 -OLD_EFI_COUNT=$(($OLD_EFI_COUNT)) || exit 1 - -NEW_EFI_COUNT=$(EfiRom -d "$tmpdir/out_efi_part.rom" | grep "0x0EF1" | wc -l) || exit 1 -NEW_EFI_COUNT=$(($NEW_EFI_COUNT)) || exit 1 - -if [ "$NEW_EFI_COUNT" -ne $(($OLD_EFI_COUNT + 1)) ] ; then - echo " - Found ${NEW_EFI_COUNT} EFI parts, expected $(($OLD_EFI_COUNT + 1))!" -fi - -if [ "$ERROR" -eq 0 ] ; then - echo "SUCCESS." -else - echo "*** WARNING - FAIL ***" -fi - -rm -rf "$tmpdir" || exit 1 - -echo "Done." diff --git a/Staging/EnableGop/README.md b/Staging/EnableGop/README.md index b4322af1..981ef91d 100644 --- a/Staging/EnableGop/README.md +++ b/Staging/EnableGop/README.md @@ -18,7 +18,7 @@ with several different GPUs, and on several MacPro4,1/5,1 machines with several case (and still possible) scenario, an incompatible or incorrectly installed driver in firmware may brick your hardware. -*In all cases take a backup of the main firmware or VBIOS firmware which you are modifying, and confirm that +*In all cases take a backup of the main firmware or vBIOS firmware which you are modifying, and confirm that you can successfully restore from this, before starting.* ## Recovery from bricked hardware @@ -27,10 +27,10 @@ need a Matt card (which may breach intellectual property laws in some jurisdicti desolder and reprogram your own NVRAM chip. - If testing via firmware insertion on an iMac, you will need the ability to disassemble your iMac and reprogram its NVRAM chip using a SOIC clip attached to a CH341A controller running on another computer. - - If testing via VBIOS insertion (iMac or Mac Pro), you will need the ability to disassemble your system, + - If testing via vBIOS insertion (iMac or Mac Pro), you will need the ability to disassemble your system, likely remove the heat sink from the graphics card, and then reprogram its NVRAM chip using a SOIC clip attached to a CH341A controller running on another computer. - - If testing via VBIOS insertion, in some cases it may also be possible + - If testing via vBIOS insertion, in some cases it may also be possible to use physical electrical connection to your GPU NVRAM chip in order to boot with no graphics, then connect to your machine with `ssh` (which must have been enabled beforehand) and reprogram the GPU NVRAM. Advice on this is not provided here, but may be found for instance on the iMac GPU related forum threads listed below. @@ -51,9 +51,9 @@ The requirements for using this driver are: picker when started via the latest version of OpenCore tool `BootKicker.efi`) (otherwise, the driver will not work). - *Note*: If your OpenCore installation includes a required GOP driver for your graphics card (this is added automatically on some systems by recent versions of OpenCore Legacy Patcher, as a way to enable OpenCore menu - in cards such as ex-mining GPUs), then you would also need to burn that driver to the VBIOS of your graphics + in cards such as ex-mining GPUs), then you would also need to burn that driver to the vBIOS of your graphics card in order to obtain pre-OpenCore graphics; instructions for this are outside the scope of this tutorial, - although the procedures required for modifying VBIOS are similar to what is covered here. + although the procedures required for modifying vBIOS are similar to what is covered here. When installed, the driver should enable: @@ -69,9 +69,9 @@ directory of the OpenCore release package. For GPUs needing `DirectGopRendering` in OpenCore configuration, use `EnableGopDirect.efi`, otherwise use `EnableGop.efi` as it renders faster on most other systems. -The driver may be installed to VBIOS or to main firmware. It is expected that most Mac Pro users will use firmware insertion -and most iMac users will chose VBIOS insertion, however both techniques work on both systems (but it is harder to modify the -iMac firmware). +The driver may be installed to vBIOS or to main firmware. It is expected that most Mac Pro users will use firmware insertion +and most iMac users will chose vBIOS insertion, however both techniques work on both systems (but it is harder to modify the +iMac firmware, since there is no simple way to enable writing to it). Further discussion and community support for this driver is available at: @@ -86,7 +86,7 @@ well. Alternatively the kexts and executables which this uses can be sourced ind run from the command line. The firmware on the iMac cannot be updated without an initial hardware flash (SOIC clip plus CH341A controller), therefore -the recommended approach on iMac systems is [VBIOS injection](#install-to-vbios). However, the below instructions for firmware +the recommended approach on iMac systems is [vBIOS injection](#install-to-vBIOS). However, the below instructions for firmware injection do work, if you are willing to do a hardware flash of the resulting firmware file, or if you have already [unprotected your iMac firmware](https://forums.macrumors.com/threads/imac-2011-see-more-uefi-firmware-mod.2257435/page-3?post=31087001#post-31087001) - which reduces security, and is only recommended for those actively developing firmware modifications. @@ -124,40 +124,35 @@ The end result, after saving and re-loading, should look like this: -## Install to VBIOS +## Install to vBIOS -Instructions and a script for inserting the driver into NVidia VBIOS are provided. -Similar techniques are appropriate for AMD GPUs. +Instructions and a script for inserting the driver into Nvidia or AMD vBIOS are provided. -For further information on VBIOS modification, see: +Please note all the cautions already given above about the difficulty of recovering, unless you are familiar with +the procedures necessary, if this process fails. - - https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/ - - https://forums.macrumors.com/threads/imac-2011-maxwell-and-pascal-gpu-upgrade.2300989/ - - https://github.com/Ausdauersportler/IMAC-EFI-BOOT-SCREEN/wiki - - https://winraid.level1techs.com/t/amd-and-nvidia-gop-update-no-requests-diy/30917 - -### Nvidia +To use the provided `vBiosInsert.sh` script: -To use the provided `NvInsertEfi.sh` script: + - Locate an appropriate version of the `nvflash` tool (Nvidia) or `amdvbflash` tool (AMD) (both are available for + Linux and Windows), which can be used to read from and write to the GPU vBIOS. + - Use that tool to read a copy of the vBIOS. + - Run `./vBiosInsertEfi.sh [-a|-n] {original}.rom EnableGop.efi {modified}.rom`, with `-a` for AMD and `-n` for Nvidia. + - The new file `{modified}.rom` may be burnt to the vBIOS firmware. - - Locate an appropriate version of the `nvflash` tool (available for Linux and Windows), which can be used to read - from and write to your Nvidia GPU VBIOS. - - Use `nvflash` to read a copy of your VBIOS. - - Using a hex editor, search in the VBIOS for the byte sequence `F1 0E 00 00` with the byte sequence `55 AA` coming - close before it; the start address of the `55 AA` is the value needed for the insertion offset in the next step. - - Run `./NvInsertEfi.sh {original}.rom EnableGop.efi {offset} {modified}/.rom`. - - Run `./NvInsertEfi.sh` with no arguments to see allowed formats for offset parameter. - - Only if you modified a rom file obtained via `flashrom` rather than `nvflash`, you should manually truncate - the modified file's size to the original file's size at this point. (`nvflash` files only contain the used section - of the VBIOS, and therefore must not be truncated.) - - The new file `{modified}.rom` may be burnt to the VBIOS firmware. - - Please note all the cautions already given above about the difficulty of recovering, unless you are familiar with - the procedures necessary, if this process fails. +In the case of AMD, considerably less space is normally available, due to a strict limit of 128k for legacy and EFI +parts of the larger ROM image. If there is not enough space (i.e. script reports +data would be truncated) then it is necessary to [strip some legacy VGA parts of the +vBIOS](https://github.com/Ausdauersportler/IMAC-EFI-BOOT-SCREEN/wiki/Deleting-the-VGA). This is beyond the scope +of these instructions. -### AMD +If required to manually detect the GOP offset (this should normally be autodetected): -Similar procedures as for Nvidia apply. +> Using a hex editor, search in the vBIOS for the byte sequence `F1 0E 00 00` with the byte sequence `55 AA` coming + close before it; the start address of the `55 AA` is the GOP offset value needed. - - Further assistance and information may be available in the forums and pages listed above. +For further information on vBIOS modification, see: + - https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/ + - https://forums.macrumors.com/threads/imac-2011-maxwell-and-pascal-gpu-upgrade.2300989/ + - https://github.com/Ausdauersportler/IMAC-EFI-BOOT-SCREEN/wiki + - https://winraid.level1techs.com/t/amd-and-nvidia-gop-update-no-requests-diy/30917 diff --git a/Staging/EnableGop/vBiosInsert.sh b/Staging/EnableGop/vBiosInsert.sh new file mode 100755 index 00000000..a405dcae --- /dev/null +++ b/Staging/EnableGop/vBiosInsert.sh @@ -0,0 +1,268 @@ +#!/bin/bash + +# +# Copyright © 2023 Mike Beaton. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# +# Insert EFI into AMD or Nvidia VBIOS. +# Tested back to Mac OS X 10.11 El Capitan. +# + +usage() { + echo "Usage: ./${SELFNAME} [args] {rom-file} {efi-file} {out-file}" + echo "Args:" + echo " -a : AMD" + echo " -n : Nvidia" + echo " -o {GOP offset} : GOP offset (auto-detected if Homebrew grep is installed)" + echo " Can specify 0x{hex} or {decimal}" + echo " -t {temp dir} : Specify temporary directory, and keep temp files" + echo "Examples:" + echo " ./${SELFNAME} -n -o 0xFC00 nv.rom EnableGop.efi nv_mod.rom" + echo " ./${SELFNAME} -n nv.rom EnableGop.efi nv_mod.rom" + echo " ./${SELFNAME} -a amd.rom EnableGop.efi amd_mod.rom" + echo "" +} + +SELFNAME="$(/usr/bin/basename "${0}")" + +commands=( + "EfiRom" + "UEFIRomExtract" + "hexdump" + "grep" +) + +FOUND=1 +for command in "${commands[@]}"; do + if ! command -v "$command" 1>/dev/null ; then + echo "${command} not available!" + FOUND=0 + fi +done + +if [ "$FOUND" -eq 0 ] ; then + exit 1 +fi + +AMD=0 +AMD_SAFE_SIZE="0x20000" +GOP_OFFSET="-" +NVIDIA=0 +POS=0 + +while true; do + if [ "$1" = "-a" ] ; then + AMD=1 + NVIDIA=0 + shift + elif [ "$1" = "-n" ] ; then + AMD=0 + NVIDIA=1 + shift + elif [ "$1" = "-o" ] ; then + shift + if [ "$1" != "" ] && ! [ "${1:0:1}" = "-" ] ; then + GOP_OFFSET=$1 + shift + else + echo "No GOP offset specified" && exit 1 + fi + elif [ "$1" = "-s" ] ; then # semi-secret option to modify AMD safe size + shift + if [ "$1" != "" ] && ! [ "${1:0:1}" = "-" ] ; then + AMD_SAFE_SIZE=$1 + shift + else + echo "No AMD safe size specified" && exit 1 + fi + elif [ "$1" = "-t" ] ; then + shift + if [ "$1" != "" ] && ! [ "${1:0:1}" = "-" ] ; then + TEMP_DIR=$1 + shift + else + echo "No temp dir specified" && exit 1 + fi + elif [ "${1:0:1}" = "-" ] ; then + echo "Unknown option: ${1}" && exit 1 + elif [ "$1" != "" ] ; then + case "$POS" in + 0 ) + ROM_FILE="$1" + ;; + 1 ) + EFI_FILE="$1" + ;; + 2 ) + OUT_FILE="$1" + ;; + * ) + echo "Too many filenames specified" && exit 1 + ;; + esac + POS=$(($POS+1)) + shift + else + break + fi +done + +if [ "$ROM_FILE" = "" ] || + [ "$EFI_FILE" = "" ] || + [ "$OUT_FILE" = "" ] ; then + usage + exit 0 +fi + +if [ "$AMD" -eq 0 ] && [ "$NVIDIA" -eq 0 ] ; then + echo "Must specify -a or -n" && exit 1 +fi + +if [ "$TEMP_DIR" != "" ] ; then + mkdir -p "$TEMP_DIR" || exit 1 + tmpdir="$TEMP_DIR" +else + # https://unix.stackexchange.com/a/84980/340732 + tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'vbios') || exit 1 +fi + +ORIGINAL_SIZE=$(stat -f%z "$ROM_FILE") || exit 1 + +if [ "$AMD" -eq 1 ] ; then + if [ "$ORIGINAL_SIZE" -lt "$((AMD_SAFE_SIZE))" ] ; then + echo " - File size of ${ORIGINAL_SIZE} bytes must be at least safe size of $((AMD_SAFE_SIZE)) bytes; use -s or check file" && exit 1 + fi + + dd bs=1 if="$ROM_FILE" of="$tmpdir/modify_part.rom" count=$(($AMD_SAFE_SIZE)) 2>/dev/null || exit 1 + dd bs=1 if="$ROM_FILE" of="$tmpdir/keep_part.rom" skip=$(($AMD_SAFE_SIZE)) 2>/dev/null || exit 1 +else + cp "$ROM_FILE" "$tmpdir/modify_part.rom" || exit 1 +fi + +if [ "$GOP_OFFSET" = "-" ] ; then + echo "Auto-detecting GOP offset..." + + # nicer techniques which do not assume nice alignment of what is being searched for do not work on older Mac OS X + OUTPUT=$(hexdump -C "$tmpdir/modify_part.rom" | grep '55 aa .. .. f1 0e 00 00' | head -1) + # Make macOS bash to split as expected: + # shellcheck disable=SC2206 + GOP_ARRAY=($OUTPUT) + GOP_OFFSET=${GOP_ARRAY[0]} + if [ "$GOP_OFFSET" != "" ] ; then + GOP_OFFSET="0x${GOP_OFFSET}" + GOP_OFFSET=$(($GOP_OFFSET)) + else + GOP_OFFSET=-1 + fi + + if [ "$GOP_OFFSET" -eq -1 ] ; then + echo " - No GOP found in ROM!" && exit 1 + fi +fi + +dd bs=1 if="$tmpdir/modify_part.rom" of="$tmpdir/original_first_part.rom" count=$(($GOP_OFFSET)) 2>/dev/null || exit 1 +dd bs=1 if="$tmpdir/modify_part.rom" of="$tmpdir/original_last_part.rom" skip=$(($GOP_OFFSET)) 2>/dev/null || exit 1 + +echo "Compressing EFI using EfiRom..." +if [ "$AMD" -eq 1 ] ; then + EfiRom -o "$tmpdir/insert.rom" -ec "$EFI_FILE" -f 0xAAAA -i 0xBBBB -l 0x30000 -p || exit 1 +else + EfiRom -o "$tmpdir/insert.rom" -ec "$EFI_FILE" -f 0xAAAA -i 0xBBBB -l 0x30000 || exit 1 +fi + +if [ "$NVIDIA" -eq 1 ] ; then + echo "Adding Nvidia header..." + dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_first_part" count=$((0x38)) 2>/dev/null || exit 1 + dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_last_part" skip=$((0x38)) 2>/dev/null || exit 1 + + # TODO: truncation logic must be fixed for when there is not enough spare padding in output of EfiRom + INSERT_SIZE=$(stat -f%z "$tmpdir/insert.rom") || exit 1 + + # add NPDE from original GOP + dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_first_part" skip=$((0x38)) seek=$((0x38)) count=$((0x18)) 2>/dev/null || exit 1 + cat "$tmpdir/insert_first_part" "$tmpdir/insert_last_part" > "$tmpdir/insert_oversize.rom" || exit 1 + # Note: `truncate` command is not present by default on macOS + dd bs=1 if="$tmpdir/insert_oversize.rom" of="$tmpdir/insert_fixed.rom" count="$INSERT_SIZE" 2>/dev/null || exit 1 + + # patch size in NPDE + dd bs=1 if="$tmpdir/insert.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x2)) seek=$((0x48)) count=1 conv=notrunc 2>/dev/null || exit 1 +else + cp "$tmpdir/insert.rom" "$tmpdir/insert_fixed.rom" || exit 1 +fi + +# patch with vendor and device id from original GOP +dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x20)) seek=$((0x20)) count=4 conv=notrunc 2>/dev/null || exit 1 + +if [ "$NVIDIA" -eq 1 ] ; then + # patch size in PCIR + dd bs=1 if="$tmpdir/original_last_part.rom" of="$tmpdir/insert_fixed.rom" skip=$((0x16)) seek=$((0x16)) count=1 conv=notrunc 2>/dev/null || exit 1 + + # patch end marker in NPDE in fixed ROM (leave PCIR correct and EFI extractable from fixed ROM) + echo -n -e '\x00' | dd bs=1 of="$tmpdir/insert_fixed.rom" seek=$((0x4A)) conv=notrunc 2>/dev/null || exit 1 +fi + +echo "Combining..." +cat "$tmpdir/original_first_part.rom" "$tmpdir/insert_fixed.rom" "$tmpdir/original_last_part.rom" > "$tmpdir/combined.rom" || exit 1 + +TRUNCATE=0 +if [ "$AMD" -eq 1 ] ; then + TRUNCATE=1 + TRUNCATE_SIZE="$AMD_SAFE_SIZE" +else + printf '%x' "$ORIGINAL_SIZE" | grep -q "000$" && TRUNCATE=1 + if [ "$TRUNCATE" -eq 1 ] ; then + echo "Detected standard ROM size, truncating to original size..." + TRUNCATE_SIZE="$ORIGINAL_SIZE" + fi +fi +if [ "$TRUNCATE" -eq 1 ] ; then + dd bs=1 if="$tmpdir/combined.rom" of="$tmpdir/truncated.rom" count="$TRUNCATE_SIZE" 2>/dev/null || exit 1 + + ERROR=0 + hexdump -v -e '1/8 " %016X\n"' "$tmpdir/truncated.rom" | tail | grep -q "FFFFFFFFFFFFFFFF" || ERROR=1 + + if [ "$ERROR" -eq 1 ] ; then + echo " - Not enough space within AMD $((TRUNCATE_SIZE / 1024))k limit - aborting!" && exit 1 + fi + + cat "$tmpdir/truncated.rom" "$tmpdir/keep_part.rom" > "$OUT_FILE" || exit 1 +else + cp "$tmpdir/combined.rom" "$OUT_FILE" || exit 1 +fi + +# patch end marker in PCIR in out file +echo -n -e '\x00' | dd bs=1 of="$OUT_FILE" seek=$(($GOP_OFFSET + 0x31)) conv=notrunc 2>/dev/null || exit 1 + +printf "Verifying (starting at 0x%X)...\n" "$GOP_OFFSET" +dd bs=1 if="$OUT_FILE" of="$tmpdir/out_efi_part.rom" skip=$(($GOP_OFFSET)) 2>/dev/null || exit 1 +# UEFIRomExtract error messages are on stdout, so we cannot suppress unwanted normal output here +UEFIRomExtract "$tmpdir/out_efi_part.rom" "$tmpdir/extracted.efi" || exit 1 +ERROR=0 +diff "$tmpdir/extracted.efi" "$EFI_FILE" 1>/dev/null || ERROR=1 + +if [ "$ERROR" -ne 0 ] ; then + echo " - Failure comparing extracted EFI to original!" +fi + +OLD_EFI_COUNT=$(EfiRom -d "$tmpdir/original_last_part.rom" | grep "0x0EF1" | wc -l) || exit 1 +OLD_EFI_COUNT=$(($OLD_EFI_COUNT)) || exit 1 + +NEW_EFI_COUNT=$(EfiRom -d "$tmpdir/out_efi_part.rom" | grep "0x0EF1" | wc -l) || exit 1 +NEW_EFI_COUNT=$(($NEW_EFI_COUNT)) || exit 1 + +if [ "$NEW_EFI_COUNT" -ne $(($OLD_EFI_COUNT + 1)) ] ; then + echo " - ${OLD_EFI_COUNT} EFI parts in original ROM, and detected ${NEW_EFI_COUNT} EFI parts in modified ROM, expected $(($OLD_EFI_COUNT + 1))!" + ERROR=1 +fi + +if [ "$ERROR" -eq 0 ] ; then + echo "SUCCESS." +else + echo "*** WARNING - FAIL ***" +fi + +if [ "$TEMP_DIR" = "" ] ; then + rm -rf "$tmpdir" || exit 1 +fi + +echo "Done." diff --git a/build_oc.tool b/build_oc.tool index 9301dbf6..9385e490 100755 --- a/build_oc.tool +++ b/build_oc.tool @@ -269,7 +269,7 @@ package() { helpFiles=( "README.md" "UEFITool_Inserted_Screenshot.png" - "NvInsertEfi.sh" + "vBiosInsert.sh" ) for file in "${helpFiles[@]}"; do cp "${selfdir}/Staging/EnableGop/${file}" "${dstdir}/Utilities/EnableGop"/ || exit 1 -- GitLab