diff options
Diffstat (limited to 'include/vendor.sh')
-rw-r--r-- | include/vendor.sh | 202 |
1 files changed, 156 insertions, 46 deletions
diff --git a/include/vendor.sh b/include/vendor.sh index 9e0eb731..a0806dd8 100644 --- a/include/vendor.sh +++ b/include/vendor.sh @@ -23,29 +23,77 @@ vendir="vendorfiles" appdir="$vendir/app" vfix="DO_NOT_FLASH_YET._FIRST,_INJECT_FILES_VIA_INSTRUCTIONS_ON_LIBREBOOT.ORG_" -# lbmk-specific extension to the "cv" variable (not suitable for cbmk) -cvchk="CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \ +# lbmk-specific extension to the "checkvars" variable (not suitable for cbmk) +checkvarschk="CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \ CONFIG_LENOVO_TBFW_BIN CONFIG_VGA_BIOS_FILE CONFIG_FSP_M_FILE \ CONFIG_FSP_S_FILE CONFIG_KBC1126_FW1 CONFIG_KBC1126_FW2" -# lbmk-specific extensions to the "cv" variable (not suitable for cbmk) -cvxbmk="CONFIG_ME_BIN_PATH CONFIG_SMSC_SCH5545_EC_FW_FILE CONFIG_FSP_FULL_FD \ +# lbmk-specific extensions to the "checkvars" variable (not suitable for cbmk) +checkvarsxbmk="CONFIG_ME_BIN_PATH CONFIG_SMSC_SCH5545_EC_FW_FILE CONFIG_FSP_FULL_FD \ CONFIG_KBC1126_FW1_OFFSET CONFIG_KBC1126_FW2_OFFSET CONFIG_FSP_USE_REPO \ CONFIG_VGA_BIOS_ID CONFIG_BOARD_DELL_E6400 CONFIG_FSP_S_CBFS \ CONFIG_HAVE_REFCODE_BLOB CONFIG_REFCODE_BLOB_FILE CONFIG_FSP_FD_PATH \ CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE CONFIG_FSP_M_CBFS" -# lbmk-specific extensions; mostly used for downloading vendor files -eval "`setvars "" has_hashes EC_hash DL_hash DL_url_bkup MRC_refcode_gbe vcfg \ - E6400_VGA_DL_hash E6400_VGA_DL_url E6400_VGA_DL_url_bkup E6400_VGA_offset \ - E6400_VGA_romname SCH5545EC_DL_url_bkup SCH5545EC_DL_hash _dest mecleaner \ - kbc1126_ec_dump MRC_refcode_cbtree _dl SCH5545EC_DL_url EC_url rom DL_url \ - nuke cbfstoolref FSPFD_hash _7ztest ME11bootguard ME11delta xromsize \ - ME11version ME11sku ME11pch _me _metmp mfs TBFW_url_bkup TBFW_url cbdir \ - TBFW_hash TBFW_size hashfile EC_url_bkup FSPM_bin_hash FSPS_bin_hash \ - EC_FW1_hash EC_FW2_hash ME_bin_hash MRC_bin_hash REF_bin_hash _dl_bin \ - SCH5545EC_bin_hash TBFW_bin_hash E6400_VGA_bin_hash _pre_dest \ - XBMKmecleaner MEclean`" +# lbmk-specific extensions; general variables +_dest="" +has_hashes="" +vcfg="" +mecleaner="" +kbc1126_ec_dump="" +_dl="" +rom="" +nuke="" +_7ztest="" +cbfstoolref="" +_me="" +_metmp="" +mfs="" +cbdir="" +hashfile="" +_dl_bin="" +_pre_dest="" +xromsize="" + +# lbmk-specific extensions; declared in pkg.cfg files in config/vendor/ +EC_hash="" +DL_hash="" +DL_url_bkup="" +MRC_refcode_gbe="" +E6400_VGA_DL_hash="" +E6400_VGA_DL_url="" +E6400_VGA_DL_url_bkup="" +E6400_VGA_offset="" +E6400_VGA_romname="" +SCH5545EC_DL_url_bkup="" +SCH5545EC_DL_hash="" +MRC_refcode_cbtree="" +SCH5545EC_DL_url="" +EC_url="" +DL_url="" +FSPFD_hash="" +ME11bootguard="" +ME11delta="" +ME11version="" +ME11sku="" +ME11pch="" +TBFW_url_bkup="" +TBFW_url="" +TBFW_hash="" +TBFW_size="" +EC_url_bkup="" +FSPM_bin_hash="" +FSPS_bin_hash="" +EC_FW1_hash="" +EC_FW2_hash="" +ME_bin_hash="" +MRC_bin_hash="" +REF_bin_hash="" +SCH5545EC_bin_hash="" +TBFW_bin_hash="" +E6400_VGA_bin_hash="" +XBMKmecleaner="" +MEclean="" download() { @@ -118,6 +166,10 @@ fetch() dlop="$6" binsum="$7" + if [ -z "$binsum" ]; then + err "binsum is empty (no checksum)" "fetch" "$@" + fi + _dl="$XBMK_CACHE/file/$dlsum" # internet file to extract from e.g. .exe _dl_bin="$XBMK_CACHE/file/$binsum" # extracted file e.g. me.bin @@ -130,17 +182,36 @@ fetch() remkdir "${_pre_dest%/*}" "$appdir" # HACK: if grabbing fsp from coreboot, fix the path for lbmk - [ "$dl_type" = "fsp" ] && for _cdl in dl dl_bkup; do - eval "$_cdl=\"\${$_cdl##*../}\"; _cdp=\"\$$_cdl\"" - [ -f "$_cdp" ] || _cdp="$cbdir/$_cdp" - [ -f "$_cdp" ] && eval "$_cdl=\"$_cdp\""; : - done; : + if [ "$dl_type" = "fsp" ] + then + dl="${dl##*../}" + _cdp="$dl" + + if [ ! -f "$_cdp" ]; then + _cdp="$cbdir/$_cdp" + fi + if [ -f "$_cdp" ]; then + dl="$_cdp" + fi + + dl_bkup="${dl_bkup##*../}" + _cdp="$dl_bkup" + + if [ ! -f "$_cdp" ]; then + _cdp="$cbdir/$_cdp" + fi + if [ -f "$_cdp" ]; then + dl_bkup="$_cdp"; : + fi + fi + + # download the file (from the internet) to extract from: - # download the file (from the internet) to extract from xbget "$dlop" "$dl" "$dl_bkup" "$_dl" "$dlsum" x_ rm -Rf "${_dl}_extracted" - # skip extraction if a cached extracted file exists + # skip extraction if a cached extracted file exists: + ( xbget copy "$_dl_bin" "$_dl_bin" "$_dest" "$binsum" 2>/dev/null ) || : if [ -f "$_dest" ]; then return 0 @@ -160,7 +231,7 @@ fetch() # some functions don't output directly to the given file, _pre_dest. # instead, they put multiple files there, but we need the one matching # the given hashsum. So, search for a matching file via bruteforce: - ( fx_ "eval mkdst \"$binsum\"" x_ find "${_pre_dest%/*}" -type f ) || : + ( fx_ "mkdst $binsum" x_ find "${_pre_dest%/*}" -type f ) || : if ! bad_checksum "$binsum" "$_dest"; then if [ -f "$_dest" ]; then @@ -178,8 +249,7 @@ fetch() x_ rm -f "$_dest" fi - err "Could not safely extract '$_dest', for board '$board'" \ - "fetch" "$@" + err "Can't safely extract '$_dest', for board '$board'" "fetch" "$@" } mkdst() @@ -208,8 +278,14 @@ extract_intel_me() x_ rm -Rf "$_7ztest" if [ "$ME11bootguard" = "y" ]; then - mfs="--whitelist MFS" && \ - chkvars ME11delta ME11version ME11sku ME11pch + mfs="--whitelist MFS" + + if [ -z "$ME11delta" ] || [ -z "$ME11version" ] || \ + [ -z "$ME11sku" ] || [ -z "$ME11pch" ]; then + err "$board: ME11delta/ME11version/ME11sku/ME11pch" \ + "extract_intel_me" "$@" + fi + x_ ./mk -f deguard fi @@ -232,6 +308,8 @@ extract_intel_me() find_me() { if [ -f "$_metmp" ]; then + # we found me.bin, so we stop searching + exit 1 elif [ -L "$1" ]; then return 0 @@ -273,7 +351,8 @@ find_me() fi if [ -f "$_metmp" ]; then - # we found me.bin + # we found me.bin, so we stop searching + exit 1 else # if the subshell does exit 1, we found me.bin, so exit 1 @@ -351,7 +430,11 @@ extract_kbc1126ec_dump() extract_e6400vga() { set +u +e - chkvars E6400_VGA_offset E6400_VGA_romname + + if [ -z "$E6400_VGA_offset" ] || [ -z "$E6400_VGA_romname" ]; then + err "$board: E6400_VGA_romname/E6400_VGA_offset unset" \ + "extract_e6400vga" "$@" + fi tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || : @@ -382,7 +465,10 @@ extract_sch5545ec() # https://pcsupport.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-t-series-laptops/thinkpad-t480-type-20l5-20l6/20l5/solutions/ht508988 extract_tbfw() { - chkvars TBFW_size + if [ -z "$TBFW_size" ]; then + err "$board: TBFW_size unset" "extract_tbfw" "$@" + fi + fx_ copytb x_ find "$appdir" -type f -name "TBT.bin" } @@ -391,6 +477,7 @@ copytb() if [ -f "$1" ] && [ ! -L "$1" ]; then x_ dd if=/dev/null of="$1" bs=1 seek=$TBFW_size x_ mv "$1" "$_pre_dest" + return 1 fi } @@ -403,15 +490,24 @@ extract_fsp() setvfile() { - [ -n "$vcfg" ] && for c in $cvchk; do - vcmd="[ \"\${$c}\" != \"/dev/null\" ] && [ -n \"\${$c}\" ]" - eval "$vcmd && getvfile \"\$@\" && return 0" + [ -n "$vcfg" ] && for c in $checkvarschk; do + vcmd="[ \"\${$c}\" = \"/dev/null\" ] || [ -z \"\${$c}\" ]" + eval "$vcmd || return 0" + + if getvfile "$@"; then + return 0 + fi done && return 1; : } getvfile() { - eval "`setcfg "config/vendor/$vcfg/pkg.cfg" 1`" + if e "config/vendor/$vcfg/pkg.cfg" f missing; then + return 1 + fi + + . "config/vendor/$vcfg/pkg.cfg" || \ + err "Can't read 'config/vendor/$vcfg/pkg.cfg'" "getvfile" "$@" bootstrap @@ -480,6 +576,7 @@ prep() # Remove the prefix and 1-byte pad if [ "${_xromname#"$vfix"}" != "$_xromname" ] \ && [ "$nuke" != "nuke" ]; then + unpad_one_byte "$_xrom" x_ mv "$_xrom" "$_xromnew" @@ -490,20 +587,28 @@ prep() ( mksha512 "$_xrom" "vendorhashes" ) || err; : fi - add_vfiles "$_xrom" || return 1 # we still change the MAC if needed + if ! add_vfiles "$_xrom"; then + # no need to insert files. we will later + # still process MAC addresses as required + + return 1 + fi if [ "$nuke" = "nuke" ]; then - pad_one_byte "$_xrom" && x_ mv "$_xrom" "$_xromnew" + pad_one_byte "$_xrom" + x_ mv "$_xrom" "$_xromnew" fi } mksha512() { + build_sbase + if [ "${1%/*}" != "$1" ]; then x_ cd "${1%/*}" fi - x_ sha512sum ./"${1##*/}" >> "$2" || \ + x_ "$sha512sum" ./"${1##*/}" >> "$2" || \ err "!sha512sum \"$1\" > \"$2\"" "mksha512" "$@" } @@ -513,9 +618,11 @@ add_vfiles() if [ "$has_hashes" != "y" ] && [ "$nuke" != "nuke" ]; then printf "'%s' has no hash file. Skipping.\n" "$archive" 1>&2 + return 1 elif [ "$has_hashes" = "y" ] && [ "$nuke" = "nuke" ]; then printf "'%s' has a hash file. Skipping nuke.\n" "$archive" 1>&2 + return 1 fi @@ -566,11 +673,11 @@ vfile() cbfsname="$1" _dest="${2##*../}" - _t="$3" + blobtype="$3" _offset="" - if [ "$_t" = "fsp" ] && [ $# -gt 3 ]; then + if [ "$blobtype" = "fsp" ] && [ $# -gt 3 ]; then _offset="$4" elif [ $# -gt 3 ] && _offset="-b $4" && [ -z "$4" ]; then err "$rom: offset given but empty (undefined)" "vfile" "$@" @@ -582,34 +689,37 @@ vfile() if [ "$cbfsname" = "IFD" ]; then if [ "$nuke" = "nuke" ]; then - x_ "$ifdtool" $ifdprefix --nuke $_t "$rom" -O "$rom" + x_ "$ifdtool" $ifdprefix --nuke $blobtype "$rom" \ + -O "$rom" else - x_ "$ifdtool" $ifdprefix -i $_t:$_dest "$rom" -O "$rom" + x_ "$ifdtool" $ifdprefix -i $blobtype:$_dest "$rom" \ + -O "$rom" fi elif [ "$nuke" = "nuke" ]; then x_ "$cbfstool" "$rom" remove -n "$cbfsname" - elif [ "$_t" = "stage" ]; then # the only stage we handle is refcode + elif [ "$blobtype" = "stage" ]; then # the only stage we handle is refcode x_ rm -f "$xbtmp/refcode" x_ "$rmodtool" -i "$_dest" -o "$xbtmp/refcode" x_ "$cbfstool" "$rom" add-stage -f "$xbtmp/refcode" \ -n "$cbfsname" -t stage else x_ "$cbfstool" "$rom" add -f "$_dest" -n "$cbfsname" \ - -t $_t $_offset + -t $blobtype $_offset fi xchanged="y" - : } # must be called from a subshell check_vendor_hashes() { + build_sbase + x_ cd "$tmpromdir" if [ "$has_hashes" != "n" ] && [ "$nuke" != "nuke" ]; then - sha512sum --status -c "$hashfile" || x_ sha1sum --status \ - -c "$hashfile" + ( x_ "$sha512sum" -c "$hashfile" ) || \ + x_ sha1sum -c "$hashfile" fi x_ rm -f "$hashfile" |