Make T440p scripts work with relative paths

Because we're using pushd/popd to make the Coreboot util invocation
cleaner, we need to use realpath so that the scripts will work with any
user input.
This commit is contained in:
Rocky Breslow 2023-02-28 11:44:48 -05:00
parent 3efec15dc7
commit 63eab714e5
No known key found for this signature in database
GPG Key ID: 5401F9FC55CD2EA4
3 changed files with 40 additions and 35 deletions

View File

@ -20,21 +20,24 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
exit 1 exit 1
fi fi
if [[ ! -f "$1/mrc.bin" ]]; then output_dir="$(realpath "${1:-./}")"
# Obtain mrc.bin from a Haswell Chromebook firmware image.
# https://doc.coreboot.org/northbridge/intel/haswell/mrc.bin.html#obtaining-mrc-bin
if [[ ! -f "${output_dir}/mrc.bin" ]]; then
pushd "${COREBOOT_DIR}" pushd "${COREBOOT_DIR}"
# https://doc.coreboot.org/northbridge/intel/haswell/mrc.bin.html#obtaining-mrc-bin
make -C util/cbfstool make -C util/cbfstool
cd util/chromeos cd util/chromeos
./crosfirmware.sh peppy ./crosfirmware.sh peppy
../cbfstool/cbfstool coreboot-*.bin extract -f mrc.bin -n mrc.bin -r RO_SECTION ../cbfstool/cbfstool coreboot-*.bin extract -f mrc.bin -n mrc.bin -r RO_SECTION
popd mv mrc.bin "${output_dir}/mrc.bin"
mv "${COREBOOT_DIR}/util/chromeos/mrc.bin" "$1/mrc.bin" popd
fi fi
if ! echo "${MRC_BIN_HASH} $1/mrc.bin" | sha256sum --check; then if ! echo "${MRC_BIN_HASH} ${output_dir}/mrc.bin" | sha256sum --check; then
echo "ERROR: SHA256 checksum for mrc.bin doesn't match." echo "ERROR: SHA256 checksum for mrc.bin doesn't match."
exit 1 exit 1
fi fi

View File

@ -20,7 +20,11 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
exit 1 exit 1
fi fi
if [[ ! -f "$1/me.bin" ]]; then output_dir="$(realpath "${1:-./}")"
if [[ ! -f "${output_dir}/me.bin" ]]; then
# Unpack Lenovo's Windows installer into a temporary directory and
# extract the Intel ME blob.
pushd "$(mktemp -d)" pushd "$(mktemp -d)"
curl -O https://download.lenovo.com/pccbbs/mobiles/glrg22ww.exe curl -O https://download.lenovo.com/pccbbs/mobiles/glrg22ww.exe
@ -30,22 +34,22 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
popd popd
pushd "${COREBOOT_DIR}/util/me_cleaner"
# Neutralize and shrink Intel ME. Note that this doesn't include # Neutralize and shrink Intel ME. Note that this doesn't include
# --soft-disable to set the "ME Disable" or "ME Disable B" (e.g., High # --soft-disable to set the "ME Disable" or "ME Disable B" (e.g.,
# Assurance Program) bits, as they are defined within the Flash # High Assurance Program) bits, as they are defined within the Flash
# Descriptor. # Descriptor.
# https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot # https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot
pushd "${COREBOOT_DIR}/util/me_cleaner"
python me_cleaner.py -r -t -O me_shrinked.bin ME9.1_5M_Production.bin python me_cleaner.py -r -t -O me_shrinked.bin ME9.1_5M_Production.bin
popd mv me_shrinked.bin "${output_dir}/me.bin"
rm ./*.bin
mv "${COREBOOT_DIR}/util/me_cleaner/me_shrinked.bin" "$1/me.bin" popd
rm "${COREBOOT_DIR}/util/me_cleaner/"*.bin
fi fi
if ! echo "${ME_BIN_HASH} $1/me.bin" | sha256sum --check; then if ! echo "${ME_BIN_HASH} ${output_dir}/me.bin" | sha256sum --check; then
echo "ERROR: SHA256 checksum for me.bin doesn't match." echo "ERROR: SHA256 checksum for me.bin doesn't match."
exit 1 exit 1
fi fi

View File

@ -18,33 +18,31 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
exit 1 exit 1
fi fi
if [[ -n "$1" ]]; then original_rom="$(realpath "$1")"
pushd "${COREBOOT_DIR}" output_dir="$(realpath "${2:-./}")"
cd util/me_cleaner # Neutralize Intel ME and resize the Intel Flash Descriptor (IFD)
# layout.
# Neutralize and shrink Intel ME.
# https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot # https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot
python me_cleaner.py -S -r -t -d -O out.bin -D ifd_shrinked.bin -M me_shrinked.bin "$1" pushd "${COREBOOT_DIR}/util/me_cleaner"
mv ifd_shrinked.bin "$2/ifd.bin" python me_cleaner.py -S -r -t -d -O out.bin -D ifd_shrinked.bin -M me_shrinked.bin "${original_rom}"
mv me_shrinked.bin "$2/me.bin"
rm ./*.bin
cd ../ifdtool mv ifd_shrinked.bin "${output_dir}/ifd.bin"
make mv me_shrinked.bin "${output_dir}/me.bin"
rm ./*.bin
# Extract the Intel Gigabit Ethernet (GbE) firmware from the
# original ROM. popd
./ifdtool -x "$1"
# Extract the Intel Gigabit Ethernet (GbE) firmware.
mv flashregion_3_gbe.bin "$2/gbe.bin" pushd "${COREBOOT_DIR}/util/ifdtool"
make
./ifdtool -x "${original_rom}"
mv flashregion_3_gbe.bin "${output_dir}/gbe.bin"
rm ./*.bin rm ./*.bin
popd popd
else
echo "ERROR: You must supply a path to the original ROM."
exit 1
fi
fi fi
fi fi