11#! /usr/bin/env bash
2+ source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /../lib.sh"
23
3- function printusage {
4+ function usage {
45 echo " Usage: $0 -m <me_cleaner>(optional)"
56}
67
78ME_BIN_HASH=" c140d04d792bed555e616065d48bdc327bb78f0213ccc54c0ae95f12b28896a4"
89
9- if [ -e " ${output_dir} /me.bin" ]; then
10- echo " me.bin already exists"
11- if echo " ${ME_BIN_HASH} ${output_dir} /me.bin" | sha256sum --check; then
12- echo " SKIPPING: SHA256 checksum for me.bin matches."
13- exit 0
14- fi
15- echo " me.bin exists but checksum doesn't match. Continuing..."
16- fi
17-
1810if [[ " ${BASH_SOURCE[0]} " == " $0 " ]]; then
1911 if [[ " ${1:- } " == " --help" ]]; then
2012 usage
@@ -26,34 +18,29 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
2618
2719 output_dir=" $( realpath " ${1:- ./ } " ) "
2820
29- if [[ ! -f " ${output_dir} /me.bin" ]]; then
30- # Unpack Lenovo's Windows installer into a temporary directory and
31- # extract the Intel ME blob.
32- pushd " $( mktemp -d) " || exit
33-
34- curl -O https://download.lenovo.com/pccbbs/mobiles/g1rg24ww.exe
35- innoextract g1rg24ww.exe
36-
37- mv app/ME8_5M_Production.bin " ${COREBOOT_DIR} /util/me_cleaner"
38- rm -rf ./*
39- popd || exit
40-
41- # Neutralize and shrink Intel ME. Note that this doesn't include
42- # --soft-disable to set the "ME Disable" or "ME Disable B" (e.g.,
43- # High Assurance Program) bits, as they are defined within the Flash
44- # Descriptor.
45- # https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot
46- pushd " ${COREBOOT_DIR} /util/me_cleaner" || exit
47-
48- python me_cleaner.py -r -t -O me_shrinked.bin ME8_5M_Production.bin
49- rm -f ME8_5M_Production.bin
50- mv me_shrinked.bin " ${output_dir} /me.bin"
51- popd || exit
52- fi
21+ check_outputs " ${ME_BIN_HASH} ${output_dir} /me.bin" && { echo " All outputs match. Nothing to do." ; exit 0; }
5322
54- if ! echo " ${ME_BIN_HASH} ${output_dir} /me.bin" | sha256sum --check; then
55- echo " ERROR: SHA256 checksum for me.bin doesn't match."
56- exit 1
57- fi
23+ pushd " $( mktemp -d) " || exit
24+
25+ curl -O https://download.lenovo.com/pccbbs/mobiles/g1rg24ww.exe
26+ innoextract g1rg24ww.exe
27+
28+ mv app/ME8_5M_Production.bin " ${COREBOOT_DIR} /util/me_cleaner"
29+ rm -rf ./*
30+ popd || exit
31+
32+ # Neutralize and shrink Intel ME. Note that this doesn't include
33+ # --soft-disable to set the "ME Disable" or "ME Disable B" (e.g.,
34+ # High Assurance Program) bits, as they are defined within the Flash
35+ # Descriptor.
36+ # https://github.com/corna/me_cleaner/wiki/External-flashing#neutralize-and-shrink-intel-me-useful-only-for-coreboot
37+ pushd " ${COREBOOT_DIR} /util/me_cleaner" || exit
38+
39+ python me_cleaner.py -r -t -O me_shrinked.bin ME8_5M_Production.bin
40+ rm -f ME8_5M_Production.bin
41+ mv me_shrinked.bin " ${output_dir} /me.bin"
42+ popd || exit
43+
44+ check_outputs " ${ME_BIN_HASH} ${output_dir} /me.bin" || exit 1
5845 fi
5946fi
0 commit comments