summaryrefslogtreecommitdiff
path: root/include/inject.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/inject.sh')
-rw-r--r--include/inject.sh146
1 files changed, 54 insertions, 92 deletions
diff --git a/include/inject.sh b/include/inject.sh
index 6b316729..9bfda2db 100644
--- a/include/inject.sh
+++ b/include/inject.sh
@@ -14,7 +14,7 @@ hashfiles="vendorhashes blobhashes" # blobhashes for backwards compatibility
dontflash="!!! AN ERROR OCCURED! Please DO NOT flash if injection failed. !!!"
vfix="DO_NOT_FLASH_YET._FIRST,_INJECT_FILES_VIA_INSTRUCTIONS_ON_LIBREBOOT.ORG_"
vguide="https://libreboot.org/docs/install/ivy_has_common.html"
-tmpromdel="$xbmkpwd/tmp/DO_NOT_FLASH"
+tmpromdel="$xbmklocal/DO_NOT_FLASH"
nvm="util/nvmutil/nvm"
ifdtool="elf/ifdtool/default/ifdtool"
@@ -86,6 +86,8 @@ getfiles()
"$E6400_VGA_DL_url_bkup" "$E6400_VGA_DL_hash" "$CONFIG_VGA_BIOS_FILE"
[ -z "$CONFIG_HAVE_MRC" ] || fetch "mrc" "$MRC_url" "$MRC_url_bkup" \
"$MRC_hash" "$CONFIG_MRC_FILE"
+ [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && fetch "refcode" "$MRC_url" \
+ "$MRC_url_bkup" "$MRC_hash" "$CONFIG_REFCODE_BLOB_FILE"
[ -z "$CONFIG_LENOVO_TBFW_BIN" ] || fetch "tbfw" "$TBFW_url" \
"$TBFW_url_bkup" "$TBFW_hash" "$CONFIG_LENOVO_TBFW_BIN"
#
@@ -93,9 +95,9 @@ getfiles()
# therefore, handle them separately, in case one of them is libre; if
# one of them was, the path wouldn't be set.
#
- [ -z "$CONFIG_FSP_M_FILE" ] || fetch "fspm" "$CONFIG_FSP_FD_PATH" \
+ [ -z "$CONFIG_FSP_M_FILE" ] || fetch "fsp" "$CONFIG_FSP_FD_PATH" \
"$CONFIG_FSP_FD_PATH" "$FSPFD_hash" "$CONFIG_FSP_M_FILE" copy
- [ -z "$CONFIG_FSP_S_FILE" ] || fetch "fsps" "$CONFIG_FSP_FD_PATH" \
+ [ -z "$CONFIG_FSP_S_FILE" ] || fetch "fsp" "$CONFIG_FSP_FD_PATH" \
"$CONFIG_FSP_FD_PATH" "$FSPFD_hash" "$CONFIG_FSP_S_FILE" copy; :
}
@@ -109,14 +111,12 @@ fetch()
[ "$5" = "/dev/null" ] && return 0
_dl="$XBMK_CACHE/file/$dlsum"
- if [ "$dl_type" = "fspm" ] || [ "$dl_type" = "fsps" ]; then
- # HACK: if grabbing fsp from coreboot, fix the path for lbmk
- for _cdl in dl dl_bkup; do
- eval "$_cdl=\"\${$_cdl##*../}\"; _cdp=\"\$$_cdl\""
- [ -f "$_cdp" ] || _cdp="$cbdir/$_cdp"
- [ -f "$_cdp" ] && eval "$_cdl=\"$_cdp\""
- done
- fi
+ # 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; :
dlop="curl" && [ $# -gt 5 ] && dlop="$6"
xbmkget "$dl" "$dl_bkup" "$_dl" "$dlsum" "$dlop"
@@ -140,14 +140,12 @@ extract_intel_me()
cdir="$xbmkpwd/$appdir"
_me="$xbmkpwd/$_dest"
- _metmp="$xbmkpwd/tmp/me.bin"
+ _metmp="$xbmklocal/me.bin"
mfs="" && [ "$ME11bootguard" = "y" ] && mfs="--whitelist MFS" && \
chkvars ME11delta ME11version ME11sku ME11pch
[ "$ME11bootguard" = "y" ] && x_ ./mk -f deguard
- x_ mkdir -p tmp
-
extract_intel_me_bruteforce
if [ "$ME11bootguard" = "y" ]; then
apply_me11_deguard_mod
@@ -205,27 +203,14 @@ apply_me11_deguard_mod()
extract_archive()
{
- if [ $# -gt 2 ]; then
- if [ "$3" = "fspm" ] || [ "$3" = "fsps" ]; then
- decat_fspfd "$1" "$2"
- return 0
- fi
- fi
+ [ $# -gt 2 ] && [ "$3" = "fsp" ] && x_ python \
+ "$cbdir/3rdparty/fsp/Tools/SplitFspBin.py" split -f "$1" -o "$2" \
+ -n "Fsp.fd" && return 0
innoextract "$1" -d "$2" || python "$pfs_extract" "$1" -e || 7z x \
"$1" -o"$2" || unar "$1" -o "$2" || unzip "$1" -d "$2" || return 1
- [ ! -d "${_dl}_extracted" ] || cp -R "${_dl}_extracted" "$2" || \
- $err "!mv '${_dl}_extracted' '$2' - $dontflash"; :
-}
-
-decat_fspfd()
-{
- _fspfd="$1"
- _fspdir="$2"
- _fspsplit="$cbdir/3rdparty/fsp/Tools/SplitFspBin.py"
-
- x_ $python "$_fspsplit" split -f "$_fspfd" -o "$_fspdir" -n "Fsp.fd"
+ [ ! -d "${_dl}_extracted" ] || x_ cp -R "${_dl}_extracted" "$2"; :
}
extract_kbc1126ec()
@@ -243,9 +228,7 @@ extract_kbc1126ec()
) || $err "$board: can't extract kbc1126 ec firmware - $dontflash"
x_ e "$appdir/ec.bin.fw1" f && x_ e "$appdir/ec.bin.fw2" f
-
- cp "$appdir/"ec.bin.fw* "${_dest%/*}/" || \
- $err "!cp 1126ec $_dest - $dontflash"; :
+ x_ cp "$appdir/"ec.bin.fw* "${_dest%/*}/"
}
extract_e6400vga()
@@ -278,35 +261,25 @@ 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 # size in bytes, matching TBFW's flash IC
- x_ mkdir -p tmp
- x_ rm -f tmp/tb.bin
- find "$appdir" -type f -name "TBT.bin" > "tmp/tb.txt" || \
- $err "extract_tbfw $_dest: Can't extract TBT.bin - $dontflash"
- while read -r f; do
- [ -f "$f" ] || continue
- [ -L "$f" ] && continue
- x_ cp "$f" "tmp/tb.bin"
- break
- done < "tmp/tb.txt"
- x_ dd if=/dev/null of=tmp/tb.bin bs=1 seek=$TBFW_size
- x_ cp "tmp/tb.bin" "$_dest"
+ chkvars TBFW_size
+ fe_ copy_tbfw "$appdir" -type f -name "TBT.bin"
+ [ -f "$_dest" ] || $err "$board: Could not extract tbfw"; :
}
-extract_fspm()
+copy_tbfw()
{
- copy_fsp M; :
-}
+ [ -f "$1" ] || return 0
+ [ -L "$1" ] && return 0
-extract_fsps()
-{
- copy_fsp S; :
+ x_ dd if=/dev/null of="$1" bs=1 seek=$TBFW_size
+ x_ mv "$1" "$_dest"
+
+ return 1
}
-# this copies the fsp s/m; re-base is handled by ./mk inject
-copy_fsp()
+extract_fsp()
{
- x_ cp "$appdir/Fsp_$1.fd" "$_dest"
+ x_ cp "$appdir/"Fsp_*.fd "${_dest%/*}"
}
fail_inject()
@@ -330,7 +303,7 @@ inject()
eval "`setvars "" nukemode new_mac xchanged`"
archive="$1";
- new_mac="??:??:??:??:??:??"
+ new_mac="xx:xx:xx:xx:xx:xx"
[ $# -gt 1 ] && case "$2" in
nuke)
@@ -343,6 +316,9 @@ inject()
esac
[ "$new_mac" = "keep" ] && new_mac=""
+ [ -n "$new_mac" ] && [ "$new_mac" != "restore" ] && \
+ x_ make -C util/nvmutil clean && x_ make -C util/nvmutil
+
check_release "$archive" || $err "'$archive' is not a release archive"
readcfg && need_files="y"
@@ -406,7 +382,7 @@ readcfg()
patch_release_roms()
{
has_hashes="n"
- tmpromdir="tmp/DO_NOT_FLASH/bin/$board"
+ tmpromdir="$xbmklocal/DO_NOT_FLASH/bin/$board"
remkdir "${tmpromdir%"/bin/$board"}"
x_ tar -xf "$archive" -C "${tmpromdir%"/bin/$board"}"
@@ -417,16 +393,8 @@ patch_release_roms()
hashfile="$_hashes" && break; :
done
- x_ mkdir -p "tmp" && [ -L "tmp/rom.list" ] && \
- $err "'$archive' -> tmp/rom.list is a symlink - $dontflash"
-
- find "$tmpromdir" -maxdepth 1 -type f -name "*.rom" > "tmp/rom.list" \
- || $err "'$archive' -> Can't make tmp/rom.list - $dontflash"
-
if readkconfig; then
- while read -r _xrom ; do
- process_release_rom "$_xrom" || break
- done < "tmp/rom.list"
+ fe_ prep_rom "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
[ "$nukemode" != "nuke" ] || \
printf "Make sure you inserted vendor files: %s\n" \
"$vguide" > "$tmpromdir/README.md" || :
@@ -460,7 +428,7 @@ patch_release_roms()
"$archive" || $err "'$archive' -> Can't overwrite - $dontflash"; :
}
-process_release_rom()
+prep_rom()
{
_xrom="$1"
_xromname="${1##*/}"
@@ -538,11 +506,10 @@ insert()
_offset=""
- if [ "$_t" = "fsp" ]; then
- [ $# -gt 3 ] && _offset="$4"
- else
- [ $# -gt 3 ] && _offset="-b $4" && [ -z "$4" ] && \
- $err "insert $*, $rom: offset given but empty (undefined)"
+ if [ "$_t" = "fsp" ] && [ $# -gt 3 ]; then
+ _offset="$4"
+ elif [ $# -gt 3 ] && _offset="-b $4" && [ -z "$4" ]; then
+ $err "insert $*, $rom: offset given but empty (undefined)"
fi
[ "$nukemode" = "nuke" ] || x_ e "$_dest" f
@@ -556,11 +523,10 @@ insert()
elif [ "$nukemode" = "nuke" ]; then
x_ "$cbfstool" "$rom" remove -n "$cbfsname"
elif [ "$_t" = "stage" ]; then # the only stage we handle is refcode
- x_ mkdir -p tmp
- x_ rm -f "tmp/refcode"
- "$rmodtool" -i "$_dest" -o "tmp/refcode" || "!reloc refcode"
- "$cbfstool" "$rom" add-stage -f "tmp/refcode" -n "$cbfsname" \
- -t stage || $err "$rom: !add ref"
+ x_ rm -f "$xbmklocal/refcode"
+ "$rmodtool" -i "$_dest" -o "$xbmklocal/refcode" || "!reloc ref"
+ "$cbfstool" "$rom" add-stage -f "$xbmklocal/refcode" \
+ -n "$cbfsname" -t stage || $err "$rom: !add ref"
else
"$cbfstool" "$rom" add -f "$_dest" -n "$cbfsname" \
-t $_t $_offset || $err "$rom !add $_t ($_dest)"
@@ -572,22 +538,18 @@ modify_mac()
{
[ -n "$CONFIG_GBE_BIN_PATH" ] || return 1
- x_ mkdir -p tmp && x_ cp "${CONFIG_GBE_BIN_PATH##*../}" tmp/gbe
- [ "$new_mac" != "restore" ] && x_ make -C util/nvmutil && \
- x_ "$nvm" tmp/gbe setmac "$new_mac"
-
- find "$tmpromdir" -maxdepth 1 -type f -name "*.rom" > "tmp/rom.list" \
- || $err "'$archive' -> Can't make tmp/rom.list - $dontflash"
+ x_ cp "${CONFIG_GBE_BIN_PATH##*../}" "$xbmklocal/gbe"
+ [ -n "$new_mac" ] && [ "$new_mac" != "restore" ] && \
+ x_ "$nvm" "$xbmklocal/gbe" setmac "$new_mac"
- while read -r _xrom; do
- e "$_xrom" f && xchanged="y" && x_ \
- "$ifdtool" $ifdprefix -i GbE:tmp/gbe "$_xrom" -O "$_xrom"
- done < "tmp/rom.list"
+ fe_ newmac "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
printf "\nGbE NVM written to '%s':\n" "$archive"
- x_ "$nvm" tmp/gbe dump | grep -v "bytes read from file" || :
+ x_ "$nvm" "$xbmklocal/gbe" dump | grep -v "bytes read from file" || :
+}
- [ "$new_mac" = "restore" ] && \
- printf "\nDefault GbE file '%s' written, unmodified.\n" \
- "${CONFIG_GBE_BIN_PATH##*../}"; :
+newmac()
+{
+ e "$1" f && xchanged="y" && x_ \
+ "$ifdtool" $ifdprefix -i GbE:"$xbmklocal/gbe" "$1" -O "$1"; :
}