WIP: convert to lwmk

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-09-07 13:41:59 +01:00
parent 8d0ad21112
commit 2b34aeea5d
909 changed files with 6807 additions and 186660 deletions
-138
View File
@@ -1,138 +0,0 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2025 Leah Rowe <leah@libreboot.org>
# Import MrChromebox project into xbmk
# NOTE: variable naming scheme:
# mr_ for variables/functions dealing with MrChromebox
# mx_ for variables/functions pertaining to Libreboot setup
# because i am a non-binary blob
spdx="# SPDX-License-Identifier: GPL-3.0-or-later"
# temporary work variables
mr_tmpdir="" # dir to clone tmp repos in
# NOTE: upstream for our purposes: https://review.coreboot.org/coreboot
mr_cbrepo="https://github.com/mrchromebox/coreboot"
mr_cbbranch="MrChromebox-2503" # branch in mrchromebox
mr_cbrev="ecd9fa6a177e00132ec214252a2b9cebbb01e25f" # relative to base
mr_cbrevbase="38f5f7c48024d9fca4b6bbd88914423c34da709c" # 25.03 upstream base
mr_cbtree="chromebook" # tree name in xbmk
# NOTE: upstream for our purposes: https://github.com/tianocore/edk2.git
mr_edk2repo="https://github.com/mrchromebox/edk2"
mr_edk2branch="uefipayload_2502" # branch in mrchromebox
mr_edk2rev="feaf6b976b7cc72a18ed364f273751c943a9e7d0" # relative to base
mr_edk2revbase="fbe0805b2091393406952e84724188f8c1941837" # 2025.02 upstream
mr_edk2tree="chromebook" # tree name in xbmk
# mxlibreboot was here
prep_mr_import()
{
if [ -f "$xbmkpwd/CHANGELOG" ]; then
err "Project import disabled on releases" "prep_mr_import" "$@"
fi
mr_tmpdir="`mktemp -d || err "can't make mrtmpdir"`" || \
err "can't make mrtmpdir" "prep_mr_coreboot" "$@"
x_ remkdir "$mr_tmpdir"
x_ prep_mx_edk2conf
x_ prep_mr_projects
x_ rm -Rf "$mr_tmpdir"
}
# create config/git/edk2/pkg.cfg
prep_mx_edk2conf()
{
x_ remkdir "config/git/edk2"
x_ prep_mr_file "config/git/edk2/pkg.cfg" \
"$spdx" \
"" \
"rev=\"HEAD\"" \
"url=\"https://codeberg.org/libreboot/edk2\"" \
"bkup_url=\"https://git.disroot.org/libreboot/edk2\""
}
# prep config/PROJECT/TREE/ for various projects
prep_mr_projects()
{
x_ prep_mr "coreboot" "$mr_cbrepo" "$mr_cbbranch" "$mr_cbrev" \
"$mr_cbrevbase" "$mr_cbtree"
x_ prep_mr "edk2" "$mr_edk2repo" "$mr_edk2branch" "$mr_edk2rev" \
"$mr_edk2revbase" "$mr_edk2tree"
}
# create config/PROJECT/TREE/target.cfg
# and config/PROJECT/TREE/patches/
prep_mr()
{
mr_projectname="$1"
mr_repo="$2"
mr_branch="$3"
mr_rev="$4"
mr_revbase="$5"
mr_tree="$6"
x_ prep_mr_clone "$@"
x_ prep_mr_patch "$@"
x_ prep_mr_file "config/$1/$6/target.cfg" \
"$spdx" \
"" \
"tree=\"$6\"" \
"rev=\"$5\""
}
prep_mr_clone()
{
mr_tmpclone="$mr_tmpdir/$1"
x_ git clone "$2" "$mr_tmpclone"
x_ git -C "$mr_tmpclone" checkout "$3"
# we don't reset, because we format-patch between revbase..rev
}
prep_mr_patch()
{
mr_tmpclone="$mr_tmpdir/$1"
mx_patchdir="config/$1/$6/patches"
x_ remkdir "$mx_patchdir"
if [ "$4" != "$5" ]; then
x_ git -C "$mr_tmpclone" format-patch $5..$4
x_ mv "$mr_tmpclone"/*.patch "$mx_patchdir"
fi
# if no patches were created, rmdir will succeed
rmdir "$mx_patchdir" 1>/dev/null 2>/dev/null || :
}
prep_mr_file()
{
mr_filename="$1"
shift 1
x_ rm -f "$mr_filename"
while [ $# -gt 0 ]; do
printf "%s\n" "$1" >> "$mr_filename" || \
err "Can't write '$1' to '$mr_filename'" prep_mr_file "$@"
shift 1
done
printf "Created '%s'\n" "$mr_filename"
}
+1 -8
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2020-2021,2023-2025 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2020-2021,2023-2026 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
url=""
@@ -30,8 +30,6 @@ fetch_targets()
fetch_project()
{
xgcctree=""
. "config/git/$project/pkg.cfg" || \
err "Can't read config 'config/git/$project/pkg.cfg'" \
"fetch_project" "@"
@@ -43,11 +41,6 @@ fetch_project()
"fetch_project" "$@"
fi
if [ -n "$xgcctree" ]; then
x_ ./mk -f coreboot "$xgcctree"
fi
if [ -n "$depend" ]; then
for d in $depend ; do
+26 -18
View File
@@ -340,7 +340,7 @@ xbmk_parent_set_export()
export PATH="$xbtmp/xbmkpath:$xbtmp/gnupath:$PATH"
xbmkpath="$PATH"
# if "y": a coreboot target won't be built if target.cfg says release=n
# if "y": a target won't be built if target.cfg says release=n
# (this is used to exclude certain build targets from releases)
if [ -z "${XBMK_RELEASE+x}" ]; then
@@ -533,33 +533,41 @@ xbmk_set_mirror()
# it's slower, and uses more disk space, and some upstreams might not
# appreciate it, so it should only be used for development or archival
# NOTE: unlike the lbmk design, which defaults to "n", the lwmk
# design defaults to "y". This is due to the sheer size of the firefox
# repository, and the complications caused by build artifacts in
# its build system. We want to make sure that we always have a reliable
# cache of the repository, so we default to mirror mode unless
# configured otherwise by the user.
# the lbmk design defaults to "n" because the coreboot repository
# contains every pull request as a new branch, so the decision was
# made accordingly there (to further reduce the risk of overly
# burdening them, that build system also defaults to a github
# backup instead of the main coreboot mirror)
# mozilla hosts firefox on github, and github has plenty of bandwidth.
# mirror mode is always preferred, in both build systems, at least
# for development purposes. end users who don't want to download as
# much (only the branch they're checkout out) might want to turn off
# mirror mode. by default, the lwmk build system assumes that the user
# is a developer, because most people who compile librewolf will use
# the tarball, probably in a linux distro or (hint hint) openbsd ports
if [ -z "${XBMK_CACHE_MIRROR+x}" ]; then
export XBMK_CACHE_MIRROR="n"
export XBMK_CACHE_MIRROR="y"
fi
if [ "$XBMK_CACHE_MIRROR" != "y" ]; then
if [ "$XBMK_CACHE_MIRROR" != "y" ] && \
[ "$XBMK_CACHE_MIRROR" != "n" ]; then
export XBMK_CACHE_MIRROR="n"
export XBMK_CACHE_MIRROR="y"
fi
}
xbmk_git_init()
{
# the git identity check is only needed for: ./mk -b coreboot [args]
[ "${2-}" = "-b" ] && [ "${3-}" = "coreboot" ] && \
for gitarg in "user.name" "user.email"; do
gitcmd="git config --includes $gitarg"
if ! $gitcmd 1>/dev/null 2>/dev/null; then
err "Run this first: $gitcmd \"your ${gitcmd##*.}\"" \
"xbmk_git_init" "$@"
fi
done
if [ -L ".git" ]; then
err "'$xbmkpwd/.git' is a symlink" "xbmk_git_init" "$@"
-290
View File
@@ -1,290 +0,0 @@
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org>
cbcfgsdir="config/coreboot"
tmpromdel="$XBMK_CACHE/DO_NOT_FLASH"
nvmutil="util/nvmutil/nvmutil"
ifdtool="elf/coreboot/default/ifdtool"
checkvars="CONFIG_GBE_BIN_PATH"
if [ -n "$checkvarsxbmk" ]; then
checkvars="$checkvars $checkvarsxbmk"
fi
if [ -n "$checkvarschk" ]; then
checkvars="$checkvars $checkvarschk"
fi
archive=""
board=""
boarddir=""
IFD_platform=""
ifdprefix=""
new_mac=""
tmpromdir=""
tree=""
xchanged=""
eval "`setvars "" $checkvars`"
inject()
{
remkdir "$tmpromdel"
if [ $# -lt 1 ]; then
err "No options specified" "inject" "$@"
fi
archive="$1";
new_mac="xx:xx:xx:xx:xx:xx"
nuke=""
xchanged=""
[ $# -gt 1 ] && case "$2" in
nuke)
new_mac=""
nuke="nuke"
;;
setmac)
if [ $# -gt 2 ]; then
new_mac="$3" && \
if [ -z "$new_mac" ]; then
err "Empty MAC address specified" "inject" "$@"
fi
fi
;;
*)
err "Unrecognised inject mode: '$2'" "inject" "$@" ;;
esac
if [ "$new_mac" = "keep" ]; then
new_mac=""
fi
check_release
if check_target; then
if ! patch_release; then
return 0
fi
fi
if [ "$xchanged" = "y" ]; then
remktar
fi
if [ "$xchanged" = "y" ]; then
printf "\n'%s' was modified\n" "$archive" 1>&2
else
printf "\n'%s' was NOT modified\n" "$archive" 1>&2
fi
x_ rm -Rf "$tmpromdel"
}
check_release()
{
if [ -L "$archive" ]; then
err "'$archive' is a symlink" "check_release" "$@"
fi
if e "$archive" f missing; then
err "'$archive' missing" "check_release" "$@"
fi
archivename="`basename "$archive" || err "Can't get '$archive' name"`" \
|| err "can't get '$archive' name" "check_release" "$@"
if [ -z "$archivename" ]; then
err "Can't determine archive name" "check_release" "$@"
fi
case "$archivename" in
*_src.tar.xz)
err "'$archive' is a src archive!" "check_release" "$@"
;;
grub_*|seagrub_*|custom_*|seauboot_*|seabios_withgrub_*)
err "'$archive' is a ROM image" "check_release" "$@"
;;
*.tar.xz) _stripped_prefix="${archivename#*_}"
board="${_stripped_prefix%.tar.xz}"
;;
*)
err "'$archive': cannot detect board" "check_release" "$@"
;;
esac; :
}
check_target()
{
if [ "$board" != "${board#serprog_}" ]; then
return 1
fi
boarddir="$cbcfgsdir/$board"
. "$boarddir/target.cfg" || \
err "Can't read '$boarddir/target.cfg'" "check_target" "$@"
if [ -z "$tree" ]; then
err "tree unset in '$boarddir/target.cfg'" "check_target" "$@"
fi
x_ ./mk -d coreboot "$tree"
ifdtool="elf/coreboot/$tree/ifdtool"
if [ -n "$IFD_platform" ]; then
ifdprefix="-p $IFD_platform"
fi
}
patch_release()
{
if [ "$nuke" != "nuke" ]; then
x_ ./mk download "$board"
fi
has_hashes="n"
tmpromdir="$tmpromdel/bin/$board"
remkdir "${tmpromdir%"/bin/$board"}"
x_ tar -xf "$archive" -C "${tmpromdir%"/bin/$board"}"
for _hashes in "vendorhashes" "blobhashes"; do
if e "$tmpromdir/$_hashes" f; then
has_hashes="y"
hashfile="$_hashes"
break
fi
done
if ! readkconfig; then
return 1
elif [ -n "$new_mac" ] && \
[ -n "$CONFIG_GBE_BIN_PATH" ]; then
modify_mac
fi
}
readkconfig()
{
x_ rm -f "$xbtmp/cbcfg"
fx_ scankconfig x_ find "$boarddir/config" -type f
if e "$xbtmp/cbcfg" f missing; then
return 1
fi
. "$xbtmp/cbcfg" || \
err "Can't read '$xbtmp/cbcfg'" "readkconfig" "$@"
if ! setvfile "$@"; then
return 1
fi
}
scankconfig()
{
for cbc in $checkvars; do
grep "$cbc" "$1" 2>/dev/null 1>>"$xbtmp/cbcfg" || :
done
}
modify_mac()
{
x_ cp "${CONFIG_GBE_BIN_PATH##*../}" "$xbtmp/gbe"
if [ -n "$new_mac" ] && \
[ "$new_mac" != "restore" ]; then
x_ make -C util/nvmutil clean
x_ make -C util/nvmutil
x_ "$nvmutil" "$xbtmp/gbe" setmac "$new_mac"
fi
fx_ newmac x_ find "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
printf "\nThe following GbE NVM data will be written:\n"
x_ "$nvmutil" "$xbtmp/gbe" dump | grep -v "bytes read from file" || :
}
newmac()
{
if e "$1" f; then
xchanged="y"
x_ "$ifdtool" $ifdprefix -i GbE:"$xbtmp/gbe" "$1" -O "$1"
fi
}
remktar()
{
(
x_ cd "${tmpromdir%"/bin/$board"}"
printf "Re-building tar archive (please wait)\n"
mkrom_tarball "bin/$board" 1>/dev/null
) || err "Cannot re-generate '$archive'" "remktar" "$@"
mv "${tmpromdir%"/bin/$board"}/bin/${relname}_${board}.tar.xz" \
"$archive" || \
err "'$archive' -> Can't overwrite" "remktar" "$@"; :
}
+1 -33
View File
@@ -5,9 +5,6 @@
# Copyright (c) 2020-2025 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2025 Alper Nebi Yasak <alpernebiyasak@gmail.com>
cbfstool="elf/coreboot/default/cbfstool"
rmodtool="elf/coreboot/default/rmodtool"
mkrom_tarball()
{
update_xbmkver "$1"
@@ -108,7 +105,7 @@ setvars()
}
# return 0 if project is single-tree, otherwise 1
# e.g. coreboot is multi-tree, so 1
# e.g. firefox is multi-tree, so 1
singletree()
{
( fx_ "eval exit 1 && err" find "config/$1/"*/ -type f \
@@ -138,35 +135,6 @@ findpath()
done
}
pad_one_byte()
{
paddedfile="`mktemp || err "mktemp pad_one_byte"`" || \
err "can't make tmp file" "pad_one_byte" "$@"
x_ cat "$1" config/data/coreboot/0 > "$paddedfile" || \
err "could not pad file '$paddedfile'" "pad_one_byte" "$1"; :
x_ mv "$paddedfile" "$1"
}
unpad_one_byte()
{
xromsize="$(expr $(stat -c '%s' "$1") - 1)" || \
err "can't increment file size" "unpad_one_byte" "$@"
if [ $xromsize -lt 524288 ]; then
err "too small, $xromsize: $1" "unpad_one_byte" "$@"
fi
unpaddedfile="`mktemp || err "mktemp unpad_one_byte"`" || \
err "can't make tmp file" "unpad_one_byte" "$@"
x_ dd if="$1" of="$unpaddedfile" bs=$xromsize count=1
x_ mv "$unpaddedfile" "$1"
}
build_sbase()
{
if [ ! -f "$sha512sum" ]; then
-84
View File
@@ -1,84 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-only
# Logic based on util/chromeos/crosfirmware.sh in coreboot cfc26ce278.
# Modifications in this version are Copyright 2021,2023-2025 Leah Rowe.
# Original copyright detailed in repo: https://review.coreboot.org/coreboot/
MRC_board=""
MRC_hash=""
MRC_url=""
MRC_url_bkup=""
SHELLBALL=""
extract_refcode()
{
extract_mrc
# cbfstool after coreboot 4.13 changed the stage file attribute scheme,
# and refcode is extracted from an image using the old scheme. we use
# cbfstool from coreboot 4.11_branch, the tree used by ASUS KGPE-D16:
if [ -z "$cbfstoolref" ]; then
err "cbfstoolref not set" "extract_refcode" "$@"
fi
x_ xbmkdir "${_pre_dest%/*}"
x_ "$cbfstoolref" "$appdir/bios.bin" extract \
-m x86 -n fallback/refcode -f "$appdir/ref" -r RO_SECTION
# enable the Intel GbE device, if told by offset MRC_refcode_gbe:
if [ -n "$MRC_refcode_gbe" ]; then
x_ dd if="config/ifd/hp820g2/1.bin" of="$appdir/ref" bs=1 \
seek=$MRC_refcode_gbe count=1 conv=notrunc; :
fi
x_ mv "$appdir/ref" "$_pre_dest"
}
extract_mrc()
{
if [ -z "$MRC_board" ]; then
err "MRC_board unset" "extract_mrc" "$@"
elif [ -z "$CONFIG_MRC_FILE" ]; then
err "CONFIG_MRC_FILE unset" "extract_mrc" "$@"
fi
SHELLBALL="chromeos-firmwareupdate-$MRC_board"
(
x_ cd "$appdir"
extract_partition "${MRC_url##*/}"
extract_archive "$SHELLBALL" .
) || err "mrc download/extract failure" "extract_mrc" "$@"
x_ "$cbfstool" "$appdir/"bios.bin extract -n mrc.bin \
-f "${_pre_dest%/*}/mrc.bin" -r RO_SECTION
}
extract_partition()
{
printf "Extracting ROOT-A partition\n"
ROOTP=$( printf "unit\nB\nprint\nquit\n" | \
parted "${1%.zip}" 2>/dev/null | grep "ROOT-A" )
START=$(( $( echo $ROOTP | cut -f2 -d\ | tr -d "B" ) ))
SIZE=$(( $( echo $ROOTP | cut -f4 -d\ | tr -d "B" ) ))
x_ dd if="${1%.zip}" of="root-a.ext2" bs=1024 \
skip=$(( $START / 1024 )) count=$(( $SIZE / 1024 ))
printf "cd /usr/sbin\ndump chromeos-firmwareupdate %s\nquit" \
"$SHELLBALL" | debugfs "root-a.ext2" || \
err "!extract shellball" "extract_partition" "$@"
}
+1 -8
View File
@@ -138,14 +138,7 @@ prep_release_tarball()
prep_release_bin()
{
x_ ./mk -d coreboot
x_ ./mk -b coreboot
x_ ./mk -b pico-serprog
x_ ./mk -b stm32-vserprog
x_ ./mk -b pcsx-redux
x_ ./mk -b firefox
fx_ mkrom_tarball x_ find bin -maxdepth 1 -type d -name "serprog_*"
-645
View File
@@ -1,645 +0,0 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2014-2016,2020-2021,2023-2025 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2021-2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (c) 2023-2024 Riku Viitanen <riku.viitanen@protonmail.com>
grubdata="config/data/grub"
buildser()
{
if [ "$1" = "pico" ]; then
x_ cmake -DPICO_BOARD="$2" \
-DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc"
x_ cmake --build "$sersrc/build"
elif [ "$1" = "stm32" ]; then
x_ make -C "$sersrc" libopencm3-just-make BOARD=$2
x_ make -C "$sersrc" BOARD=$2
fi
x_ xbmkdir "bin/serprog_$1"
x_ mv "$serx" "bin/serprog_$1/serprog_$2.${serx##*.}"
}
copyps1bios()
{
$if_dry_build \
return 0
remkdir "bin/playstation"
x_ cp src/pcsx-redux/src/mips/openbios/openbios.bin bin/playstation
printf "MIT License\n\nCopyright (c) 2019-2025 PCSX-Redux authors\n\n" \
> bin/playstation/COPYING.txt || \
err "can't write PCSX Redux copyright info" "copyps1bios" "$@"
x_ cat config/snippet/mit >>bin/playstation/COPYING.txt || \
err "can't copy MIT license snippet" "copyps1bios" "$@"
}
mkpayload_grub()
{
grub_modules=""
grub_install_modules=""
$if_dry_build \
return 0
. "$grubdata/module/$tree" || \
err "Can't read '$grubdata/module/$tree'" "mkpayload_grub" "$@"
x_ rm -f "$srcdir/grub.elf"
x_ "$srcdir/grub-mkstandalone" \
--grub-mkimage="$srcdir/grub-mkimage" \
-O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \
--fonts= --themes= --locales= --modules="$grub_modules" \
--install-modules="$grub_install_modules" \
"/boot/grub/grub_default.cfg=${srcdir}/.config" \
"/boot/grub/grub.cfg=$grubdata/memdisk.cfg"; :
}
corebootpremake()
{
if [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" = "n" ]; then
return 0
fi
$if_not_dry_build \
cook_coreboot_config
fx_ check_coreboot_util printf "cbfstool\nifdtool\n"
printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
err "!mk $srcdir .coreboot-version" "corebootpremake" "$@"
if [ -z "$mode" ] && \
[ "$target" != "$tree" ]; then
x_ ./mk download "$target"
fi
}
cook_coreboot_config()
{
if [ -z "$mode" ] && \
[ -f "$srcdir/.config" ]; then
printf "CONFIG_CCACHE=y\n" >> "$srcdir/.config" || \
err "can't cook '$srcdir'" "cook_coreboot_config" "$@"
fi
}
check_coreboot_util()
{
if [ "$badhash" = "y" ]; then
x_ rm -f "elf/coreboot/$tree/$1"
fi
if e "elf/coreboot/$tree/$1" f; then
return 0
fi
utilelfdir="elf/coreboot/$tree"
utilsrcdir="src/coreboot/$tree/util/$1"
utilmode=""
if [ -n "$mode" ]; then
utilmode="clean"
fi
x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
if [ -n "$mode" ]; then
# TODO: is this rm command needed?
x_ rm -Rf "$utilelfdir"
return 0
elif [ -n "$mode" ] || \
[ -f "$utilelfdir/$1" ]; then
return 0
fi
x_ xbmkdir "$utilelfdir"
x_ cp "$utilsrcdir/$1" "$utilelfdir"
if [ "$1" = "cbfstool" ]; then
x_ cp "$utilsrcdir/rmodtool" "$utilelfdir"
fi
}
coreboot_pad_one_byte()
{
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 0
fi
$if_not_dry_build \
pad_one_byte "$srcdir/build/coreboot.rom"
}
mkcorebootbin()
{
if [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" = "n" ]; then
return 0
fi
$if_not_dry_build \
check_coreboot_util cbfstool
$if_not_dry_build \
check_coreboot_util ifdtool
for y in "$target_dir/config"/*; do
defconfig="$y"
mkcorebootbin_real
done
mkcoreboottar
}
mkcorebootbin_real()
{
if [ "$target" = "$tree" ]; then
return 0
fi
tmprom="$xbtmp/coreboot.rom"
initmode="${defconfig##*/}"
displaymode="${initmode##*_}"
if [ "$displaymode" = "$initmode" ]; then
# blank it for "normal" or "fspgop" configs:
displaymode=""
fi
initmode="${initmode%%_*}"
cbfstool="elf/coreboot/$tree/cbfstool"
# cbfstool option backends, if they exist
cbfscfg="config/coreboot/$target/cbfs.cfg"
elfrom="elf/coreboot/$tree/$target/$initmode"
if [ -n "$displaymode" ]; then
elfrom="${elfrom}_$displaymode"
fi
elfrom="$elfrom/coreboot.rom"
$if_not_dry_build \
x_ cp "$elfrom" "$tmprom"
$if_not_dry_build \
unpad_one_byte "$tmprom"
if [ -n "$payload_uboot" ] && \
[ "$payload_uboot" != "amd64" ] && \
[ "$payload_uboot" != "i386" ] && \
[ "$payload_uboot" != "arm64" ]; then
err "'$target' defines bad u-boot type '$payload_uboot'" \
"mkcorebootbin_real" "$@"
fi
if [ -n "$payload_uboot" ] && \
[ "$payload_uboot" != "arm64" ]; then
payload_seabios="y"
fi
if [ -z "$uboot_config" ]; then
uboot_config="default"
fi
if [ "$payload_grub" = "y" ]; then
payload_seabios="y"
fi
if [ "$payload_seabios" = "y" ] && \
[ "$payload_uboot" = "arm64" ]; then
$if_not_dry_build \
err "$target: U-Boot arm / SeaBIOS/GRUB both enabled" \
"mkcorebootbin_real" "$@"
fi
if [ -z "$grub_scan_disk" ]; then
grub_scan_disk="nvme ahci ata"
fi
if [ -z "$grubtree" ]; then
grubtree="default"
fi
grubelf="elf/grub/$grubtree/$grubtree/payload/grub.elf"
if [ "$payload_memtest" != "y" ]; then
payload_memtest="n"
fi
if [ "$(uname -m)" != "x86_64" ]; then
payload_memtest="n"
fi
if [ "$payload_grubsea" = "y" ] && \
[ "$initmode" = "normal" ]; then
payload_grubsea="n"
fi
if [ "$payload_grub" != "y" ]; then
payload_grubsea="n"
fi
$if_dry_build \
return 0
if [ -f "$cbfscfg" ]; then
dx_ add_cbfs_option "$cbfscfg"
fi
if grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then
if [ "$payload_seabios" = "y" ]; then
pname="seabios"
add_seabios
fi
if [ "$payload_uboot" = "arm64" ]; then
pname="uboot"
add_uboot
fi
else
pname="custom"
cprom
fi; :
}
# options for cbfs backend (as opposed to nvram/smmstore):
add_cbfs_option()
{
# TODO: input sanitization (currently mitigated by careful config)
op_name="`printf "%s\n" "$1" | awk '{print $1}'`"
op_arg="`printf "%s\n" "$1" | awk '{print $2}'`"
if [ -z "$op_name" ] || \
[ -z "$op_arg" ]; then
return 0
fi
( x_ "$cbfstool" "$tmprom" remove -n "option/$op_name" 1>/dev/null \
2>/dev/null ) || :
x_ "$cbfstool" "$tmprom" add-int -i "$op_arg" -n "option/$op_name"
}
# in our design, SeaBIOS is also responsible for starting either
# a GRUB or U-Boot payload. this is because SeaBIOS is generally
# a more reliable codebase, so it's less likely to cause a brick
# during testing and development, or user configuration. if one
# of the u-boot or grub payloads fails, the user still has a
# functional SeaBIOS setup to fall back on. watch:
add_seabios()
{
if [ -n "$payload_uboot" ] && \
[ "$payload_uboot" != "arm64" ]; then
# we must add u-boot first, because it's added as a flat
# binary at a specific offset for secondary program loader
$if_not_dry_build \
add_uboot
fi
_seabioself="elf/seabios/default/default/$initmode/bios.bin.elf"
if [ "$initmode" = "fspgop" ]; then
_seabioself="elf/seabios/default/default/libgfxinit/bios.bin.elf"
fi
_seaname="fallback/payload"
if [ "$payload_grubsea" = "y" ]; then
_seaname="seabios.elf"
fi
cbfs "$tmprom" "$_seabioself" "$_seaname"
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
opexec="2"
if [ "$initmode" = "vgarom" ]; then
opexec="0"
fi
x_ "$cbfstool" "$tmprom" add-int -i $opexec -n etc/pci-optionrom-exec
x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
if [ "$initmode" = "libgfxinit" ] || \
[ "$initmode" = "fspgop" ]; then
cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw
fi
if [ "$payload_memtest" = "y" ]; then
# because why not have memtest?
# we can have it. we are entitled to it.
# so we shall have it, yes. having memtest86+
# in your boot flash makes you a better person.
cbfs "$tmprom" "elf/memtest86plus/memtest.bin" img/memtest
fi
if [ "$payload_grub" = "y" ]; then
add_grub
fi
if [ "$payload_grubsea" != "y" ]; then
# ROM image where SeaBIOS doesn't load grub/u-boot first.
# U-Boot/GRUB available in ESC menu if enabled for the board
cprom
fi
# now make "SeaUBoot" and "SeaGRUB" images, where SeaBIOS auto-loads
# SeaBIOS or U-Boot first; users can bypass this by pressing ESC
# in the SeaBIOS menu, to boot devices using SeaBIOS itself instead
if [ "$payload_uboot" = "amd64" ] && \
[ "$displaymode" != "txtmode" ] && \
[ "$initmode" != "normal" ] && \
[ "$payload_grubsea" != "y" ]; then
pname="seauboot"
cprom "seauboot"
fi
if [ "$payload_grub" = "y" ]; then
pname="seagrub"
mkseagrub
fi
}
add_grub()
{
# path in CBFS for the GRUB payload
_grubname="img/grub2"
if [ "$payload_grubsea" = "y" ]; then
_grubname="fallback/payload"
fi
cbfs "$tmprom" "$grubelf" "$_grubname"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$xbtmp/tmpcfg" || \
err "$target: !insert scandisk" "add_grub" "$@"
cbfs "$tmprom" "$xbtmp/tmpcfg" scan.cfg raw
if [ "$initmode" != "normal" ] && \
[ "$displaymode" != "txtmode" ]; then
cbfs "$tmprom" "$grubdata/background/background1280x800.png" \
"background.png" raw
fi
}
mkseagrub()
{
if [ "$payload_grubsea" = "y" ]; then
pname="grub"
else
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
fi
fx_ cprom x_ find "$grubdata/keymap" -type f -name "*.gkb"
}
add_uboot()
{
if [ "$displaymode" = "txtmode" ]; then
printf "cb/%s: Can't use U-Boot in text mode\n" "$target" 1>&2
return 0
elif [ "$initmode" = "normal" ]; then
printf "cb/%s: Can't use U-Boot in normal initmode\n" \
"$target" 1>&2
return 0
fi
# TODO: re-work to allow each coreboot target to say which ub tree
# instead of hardcoding as in the current logic below:
# aarch64 targets:
ubcbfsargs=""
ubpath="fallback/payload"
ubtree="default"
ubtarget="$target"
# override for x86/x86_64 targets:
if [ -n "$payload_uboot" ] && [ "$payload_uboot" != "arm64" ]; then
ubcbfsargs="-l 0x1110000 -e 0x1110000" # 64-bit and 32-bit
# on 64-bit, 0x1120000 is the SPL, with a stub that
# loads it, located at 0x1110000
ubpath="img/u-boot" # 64-bit
ubtree="x86_64"
ubtarget="amd64coreboot"
if [ "$payload_uboot" = "i386" ]; then
# override for 32-bit
ubpath="u-boot"
ubtree="x86"
ubtarget="i386coreboot"; :
fi
fi
ubdir="elf/u-boot/$ubtree/$ubtarget/$uboot_config"
# aarch64 targets:
ubootelf="$ubdir/u-boot.elf"
if [ ! -f "$ubootelf" ]; then
ubootelf="$ubdir/u-boot"
fi
# override for x86/x86_64 targets:
if [ "$payload_uboot" = "i386" ]; then
ubootelf="$ubdir/u-boot-dtb.bin"
elif [ "$payload_uboot" = "amd64" ]; then
ubootelf="$ubdir/u-boot-x86-with-spl.bin" # EFI-compatible
fi
cbfs "$tmprom" "$ubootelf" "$ubpath" $ubcbfsargs
if [ "$payload_seabios" != "y" ]; then
cprom
fi
}
# prepare the final image in bin/ for user installation:
cprom()
{
cpcmd="cp"
tmpnew=""
newrom="bin/$target/${pname}_${target}_$initmode.rom"
if [ -n "$displaymode" ]; then
newrom="${newrom%.rom}_$displaymode.rom"
fi
if [ $# -gt 0 ] && \
[ "${1%.gkb}" != "$1" ]; then
tmpnew="${1##*/}"
newrom="${newrom%.rom}_${tmpnew%.gkb}.rom"
fi
irom="$tmprom"
if [ $# -gt 0 ]; then
irom="$(mktemp || err "!mk irom, $(echo "$@")")" || \
err "can't copy rom" "cprom" "$@"
x_ cp "$tmprom" "$irom" && cpcmd="mv"
if [ "${1%.gkb}" != "$1" ]; then
cbfs "$irom" "$grubdata/keymap/$tmpnew" keymap.gkb raw
elif [ "$1" = "seauboot" ]; then
cbfs "$irom" "$grubdata/bootorder_uboot" bootorder raw
fi
fi
printf "Creating new %s image: '%s'\n" "$projectname" "$newrom"
x_ xbmkdir "bin/$target"
x_ $cpcmd "$irom" "$newrom"
}
cbfs()
{
ccmd="add-payload"
lzma="-c lzma"
if [ $# -gt 3 ] && \
[ $# -lt 5 ]; then
ccmd="add"
lzma="-t $4"
elif [ $# -gt 4 ] && \
[ "$5" = "0x1110000" ]; then
ccmd="add-flat-binary" && \
lzma="-c lzma -l 0x1110000 -e 0x1110000"
fi
x_ "$cbfstool" "$1" $ccmd -f "$2" -n "$3" $lzma
}
# for release files:
mkcoreboottar()
{
$if_dry_build \
return 0
if [ "$target" = "$tree" ] || \
[ "$XBMK_RELEASE" != "y" ] || \
[ "$release" = "n" ]; then
return 0
fi
mkrom_tarball "bin/$target"
x_ ./mk inject "bin/${relname}_${target}.tar.xz" nuke
}
+14 -261
View File
@@ -23,16 +23,10 @@ buildtype=""
cleanargs=""
cmakedir=""
cmd=""
defconfig=""
mozconfig=""
dest_dir=""
elfdir=""
forcepull=""
gccdir=""
gccfull=""
gccver=""
gnatdir=""
gnatfull=""
gnatver=""
listfile=""
makeargs=""
mdir=""
@@ -49,13 +43,10 @@ target=""
target_dir=""
targets=""
tree=""
xarch=""
xgcctree=""
xlang=""
trees()
{
flags="f:F:b:m:u:c:x:s:l:n:d:"
flags="f:F:b:c:x:d:"
while getopts $flags option; do
@@ -66,9 +57,6 @@ trees()
flag="$1"
# the "mode" variable is affixed to a make command, example:
# ./mk -m coreboot does: make menuconfig -C src/coreboot/tree
case "$flag" in
-d)
@@ -84,10 +72,6 @@ trees()
-b) : ;;
-u) mode="oldconfig" ;;
-m) mode="menuconfig" ;;
-c) mode="distclean" ;;
-x) mode="crossgcc-clean" ;;
@@ -106,12 +90,6 @@ trees()
fi
;;
-s) mode="savedefconfig" ;;
-l) mode="olddefconfig" ;;
-n) mode="nconfig" ;;
*) err "invalid option '-$option'" "trees" "$@" ;;
esac
@@ -238,7 +216,7 @@ build_targets()
target="$x"
x_ handle_defconfig
x_ handle_mozconfig
if [ -z "$mode" ]; then
@@ -247,7 +225,7 @@ build_targets()
done; :
}
handle_defconfig()
handle_mozconfig()
{
target_dir="$configdir/$target"
@@ -263,7 +241,7 @@ handle_defconfig()
if [ -z "$tree" ]; then
err "$configdir: 'tree' not set" "handle_defconfig" "$@"
err "$configdir: 'tree' not set" "handle_mozconfig" "$@"
fi
srcdir="src/$project/$tree"
@@ -283,26 +261,12 @@ handle_defconfig()
elif [ "$flag" != "-d" ]; then
defconfig="$y"
mozconfig="$y"
fi
if [ -z "$mode" ]; then
check_defconfig || continue; :
fi
if [ -z "$mode" ]; then
for _xarch in $xarch; do
$if_dry_build \
break
if [ -n "$_xarch" ]; then
check_cross_compiler "$_xarch"
fi
done; :
check_mozconfig || continue; :
fi
handle_makefile
@@ -331,9 +295,6 @@ configure_project()
postmake=""
premake=""
release=""
xarch=""
xgcctree=""
xlang=""
if [ ! -f "$tcfg" ]; then
@@ -406,12 +367,6 @@ configure_project()
return 1
fi
if [ -n "$buildtype" ] && \
[ "${mode%config}" != "$mode" ]; then
return 1
fi
if [ -z "$mode" ]; then
$if_not_dry_build \
@@ -554,196 +509,15 @@ project_up_to_date()
eval "[ \"\$$badhashvar\" = \"y\" ] && return 1"; :
}
check_cross_compiler()
check_mozconfig()
{
cbdir="src/coreboot/$tree"
if [ "$project" != "coreboot" ]; then
cbdir="src/coreboot/default"
fi
if [ -n "$xgcctree" ]; then
cbdir="src/coreboot/$xgcctree"
fi
xfix="${1%-*}"
if [ "$xfix" = "x86_64" ]; then
xfix="x64"
fi
xgccfile="elf/coreboot/$tree/xgcc_${xfix}_was_compiled"
xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
x_ ./mk -f coreboot "${cbdir#src/coreboot/}"
x_ xbmkdir "elf/coreboot/$tree" # TODO: is this needed?
export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH"
export CROSS_COMPILE="${xarch% *}-"
if [ -n "$xlang" ]; then
export BUILD_LANGUAGES="$xlang"
fi
if [ -f "$xgccfile" ]; then
# skip the build, because a build already exists:
return 0
fi
check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc
# try twice because xgcc sometimes fails for, like, no reason
#
make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs
# this tells subsequent runs that the build was already done:
#
x_ touch "$xgccfile"
# reset hostcc in PATH:
#
remkdir "$xbtmp/gnupath"
}
# host toolchain version correction:
# fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024,
# trixie/sid had gnat-13 as gnat and gcc-14 as gcc, but has gnat-14 in apt. in
# some cases, gcc 13+14 and gnat-13 are present; or gnat-14 and gcc-14, but
# gnat in PATH never resolves to gnat-14, because gnat-14 was "experimental"
# note that this was implemented for debian trixie-testing, but this same
# issue will likely occur in future distros, including newer debian testing
# releases. this just matches up the versions of each toolchain component.
check_gnu_path()
{
if ! command -v "$1" 1>/dev/null; then
err "Host '$1' unavailable" "check_gnu_path" "$@"
fi
gccdir=""
gccfull=""
gccver=""
gnatdir=""
gnatfull=""
gnatver=""
if host_gcc_gnat_match "$@"; then
return 0
elif ! match_gcc_gnat_versions "$@"; then
return 1
fi
}
# check if gcc/gnat versions already match:
host_gcc_gnat_match()
{
if ! gnu_setver "$1" "$1"; then
err "Command '$1' unavailable." "check_gnu_path" "$@"
fi
gnu_setver "$2" "$2" || :
eval "[ -z \"\$$1ver\" ] && err \"Cannot detect host '$1' version\""
if [ "$gnatfull" != "$gccfull" ]; then
# non-matching host gcc/gnat versions
return 1
fi
}
# find all host gcc/gnat versions, matching them up in PATH:
match_gcc_gnat_versions()
{
eval "$1dir=\"$(dirname "$(command -v "$1")")\""
eval "_gnudir=\"\$$1dir\""
eval "_gnuver=\"\$$1ver\""
for _bin in "$_gnudir/$2-"*; do
if [ "${_bin#"$_gnudir/$2-"}" = "$_gnuver" ] && [ -x "$_bin" ]
then
_gnuver="${_bin#"$_gnudir/$2-"}"
break
fi
done
if ! gnu_setver "$2" "$_gnudir/$2-$_gnuver"; then
return 1
elif [ "$gnatfull" != "$gccfull" ]; then
return 1
fi
( link_gcc_gnat_versions "$@" "$_gnudir" "$_gnuver" ) || \
err "Can't link '$2-$_gnuver' '$_gnudir'" "check_gnu_path" "$@"; :
}
# create symlinks in PATH, so that the GCC/GNAT versions match:
link_gcc_gnat_versions()
{
_gnudir="$3"
_gnuver="$4"
remkdir "$xbtmp/gnupath"
x_ cd "$xbtmp/gnupath"
for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do
_gnuutil="${_gnubin##*/}"
if [ -e "$_gnubin" ]; then
x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
fi
done
}
# get the gcc/gnat version
# fail: return 1 if util not found
gnu_setver()
{
eval "$2 --version 1>/dev/null 2>/dev/null || return 1"
eval "$1ver=\"`"$2" --version 2>/dev/null | head -n1`\""
eval "$1ver=\"\${$1ver##* }\""
eval "$1full=\"\$$1ver\""
eval "$1ver=\"\${$1ver%%.*}\""; :
}
check_defconfig()
{
if [ ! -f "$defconfig" ]; then
if [ ! -f "$mozconfig" ]; then
$if_not_dry_build \
err "$project/$target: no config" "check_defconfig" "$@"
err "$project/$target: no config" "check_mozconfig" "$@"
fi
dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}"
dest_dir="$elfdir/$tree/$target/${mozconfig#"$target_dir/config/"}"
# skip build if a previous one exists:
@@ -775,34 +549,13 @@ handle_makefile()
x_ make -C "$srcdir" $cleanargs clean
fi
if [ -f "$defconfig" ]; then
if [ -f "$mozconfig" ]; then
x_ cp "$defconfig" "$srcdir/.config"
x_ cp "$mozconfig" "$srcdir/mozconfig"
fi
run_make_command || \
err "no makefile!" "handle_makefile" "$@"
_copy=".config"
if [ "$mode" = "savedefconfig" ]; then
_copy="defconfig"
fi
if [ "${mode%config}" != "$mode" ]; then
$if_not_dry_build \
x_ cp "$srcdir/$_copy" "$defconfig"; :
fi
if [ -e "$srcdir/.git" ] && \
[ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ]; then
$if_not_dry_build \
x_ git -C "$srcdir" $cleanargs clean -fdx; :
fi
err "no makefile!" "handle_makefile" "$@"; :
}
run_make_command()
-939
View File
@@ -1,939 +0,0 @@
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org>
# These are variables and functions, extending the functionality of
# inject.sh, to be used with lbmk; they are kept separate here, so that
# the main inject.sh can be as similar as possible between lbmk and cbmk,
# so that cherry-picking lbmk patches into cbmk yields fewer merge conflicts.
# When reading this file, you should imagine that it is part of inject.sh,
# with inject.sh concatenated onto vendor.sh; they are inexorably intertwined.
# The main "mk" script sources vendor.sh first, and then inject.sh, in lbmk.
e6400_unpack="$xbmkpwd/src/bios_extract/dell_inspiron_1100_unpacker.py"
me7updateparser="$xbmkpwd/util/me7_update_parser/me7_update_parser.py"
pfs_extract="$xbmkpwd/src/biosutilities/Dell_PFS_Extract.py"
uefiextract="$xbmkpwd/elf/uefitool/uefiextract"
bsdtar="$xbmkpwd/elf/libarchive/bsdtar"
bsdunzip="$xbmkpwd/elf/libarchive/bsdunzip"
vendir="vendorfiles"
appdir="$vendir/app"
vfix="DO_NOT_FLASH_YET._FIRST,_INJECT_FILES_VIA_INSTRUCTIONS_ON_LIBREBOOT.ORG_"
# 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 "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; general variables
cbdir=""
cbfstoolref=""
has_hashes=""
hashfile=""
kbc1126_ec_dump=""
mecleaner=""
mfs=""
nuke=""
rom=""
vcfg=""
xromsize=""
_7ztest=""
_dest=""
_dl=""
_dl_bin=""
_me=""
_metmp=""
_pre_dest=""
# lbmk-specific extensions; declared in pkg.cfg files in config/vendor/
DL_hash=""
DL_url=""
DL_url_bkup=""
E6400_VGA_bin_hash=""
E6400_VGA_DL_hash=""
E6400_VGA_DL_url=""
E6400_VGA_DL_url_bkup=""
E6400_VGA_offset=""
E6400_VGA_romname=""
EC_FW1_hash=""
EC_FW2_hash=""
EC_hash=""
EC_url=""
EC_url_bkup=""
FSPFD_hash=""
FSPM_bin_hash=""
FSPS_bin_hash=""
ME11bootguard=""
ME11delta=""
ME11pch=""
ME11sku=""
ME11version=""
ME_bin_hash=""
MEcheck=""
MEclean=""
MEshrink=""
MRC_bin_hash=""
MRC_refcode_cbtree=""
MRC_refcode_gbe=""
REF_bin_hash=""
SCH5545EC_bin_hash=""
SCH5545EC_DL_hash=""
SCH5545EC_DL_url=""
SCH5545EC_DL_url_bkup=""
TBFW_bin_hash=""
TBFW_hash=""
TBFW_size=""
TBFW_url=""
TBFW_url_bkup=""
XBMKmecleaner=""
download()
{
if [ $# -lt 1 ]; then
err "No argument given" "download" "$@"
fi
export PATH="$PATH:/sbin"
board="$1"
if check_target; then
readkconfig download
fi
}
getfiles()
{
if [ -n "$CONFIG_HAVE_ME_BIN" ];then
fetch intel_me "$DL_url" "$DL_url_bkup" "$DL_hash" \
"$CONFIG_ME_BIN_PATH" curl "$ME_bin_hash"
fi
if [ -n "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" ]; then
fetch sch5545ec "$SCH5545EC_DL_url" "$SCH5545EC_DL_url_bkup" \
"$SCH5545EC_DL_hash" "$CONFIG_SMSC_SCH5545_EC_FW_FILE" \
"curl" "$SCH5545EC_bin_hash"
fi
if [ -n "$CONFIG_KBC1126_FW1" ]; then
fetch kbc1126ec "$EC_url" "$EC_url_bkup" "$EC_hash" \
"$CONFIG_KBC1126_FW1" curl "$EC_FW1_hash"
fi
if [ -n "$CONFIG_KBC1126_FW2" ]; then
fetch kbc1126ec "$EC_url" "$EC_url_bkup" "$EC_hash" \
"$CONFIG_KBC1126_FW2" curl "$EC_FW2_hash"
fi
if [ -n "$CONFIG_VGA_BIOS_FILE" ]; then
fetch e6400vga "$E6400_VGA_DL_url" "$E6400_VGA_DL_url_bkup" \
"$E6400_VGA_DL_hash" "$CONFIG_VGA_BIOS_FILE" "curl" \
"$E6400_VGA_bin_hash"
fi
if [ -n "$CONFIG_HAVE_MRC" ]; then
fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" \
"$CONFIG_MRC_FILE" "curl" "$MRC_bin_hash"
fi
if [ -n "$CONFIG_REFCODE_BLOB_FILE" ]; then
fetch "refcode" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" \
"$CONFIG_REFCODE_BLOB_FILE" "curl" "$REF_bin_hash"
fi
if [ -n "$CONFIG_LENOVO_TBFW_BIN" ]; then
fetch "tbfw" "$TBFW_url" "$TBFW_url_bkup" "$TBFW_hash" \
"$CONFIG_LENOVO_TBFW_BIN" "curl" "$TBFW_bin_hash"
fi
if [ -n "$CONFIG_FSP_M_FILE" ]; then
fetch "fsp" "$CONFIG_FSP_FD_PATH" "$CONFIG_FSP_FD_PATH" \
"$FSPFD_hash" "$CONFIG_FSP_M_FILE" "copy" "$FSPM_bin_hash"
fi
if [ -n "$CONFIG_FSP_S_FILE" ]; then
fetch "fsp" "$CONFIG_FSP_FD_PATH" "$CONFIG_FSP_FD_PATH" \
"$FSPFD_hash" "$CONFIG_FSP_S_FILE" "copy" "$FSPS_bin_hash"
fi
}
fetch()
{
dl_type="$1"
dl="$2"
dl_bkup="$3"
dlsum="$4"
_dest="${5##*../}"
_pre_dest="$XBMK_CACHE/tmpdl/check"
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
if [ "$5" = "/dev/null" ]; then
return 0
fi
# an extracted vendor file will be placed in pre_dest first, for
# verifying its checksum. if it matches, it is later moved to _dest:
remkdir "${_pre_dest%/*}" "$appdir"
# HACK: if grabbing fsp from coreboot, fix the path for lbmk:
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:
xbget "$dlop" "$dl" "$dl_bkup" "$_dl" "$dlsum"
x_ rm -Rf "${_dl}_extracted"
# 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
fi
x_ xbmkdir "${_dest%/*}"
if [ "$dl_type" != "fsp" ]; then
extract_archive "$_dl" "$appdir" || \
[ "$dl_type" = "e6400vga" ] || \
err "$_dest $dl_type: !extract" "fetch" "$@"
fi
x_ extract_$dl_type "$_dl" "$appdir"
set -u -e
# 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_ "mkdst $binsum" x_ find "${_pre_dest%/*}" -type f ) || :
if ! bad_checksum "$binsum" "$_dest"; then
if [ -f "$_dest" ]; then
return 0
fi
fi
if [ -z "$binsum" ]; then
printf "'%s': checksum undefined\n" "$_dest" 1>&2
fi
if [ -L "$_dest" ]; then
printf "WARNING: '%s' is a link!\n" "$_dest" 1>&2
else
x_ rm -f "$_dest"
fi
err "Can't safely extract '$_dest', for board '$board'" "fetch" "$@"
}
mkdst()
{
if bad_checksum "$1" "$2" 2>/dev/null; then
x_ rm -f "$2"
else
x_ mv "$2" "$_dl_bin"
x_ cp "$_dl_bin" "$_dest"
exit 1
fi
}
extract_intel_me()
{
if e "$mecleaner" f missing; then
err "$cbdir: me_cleaner missing" "extract_intel_me" "$@"
fi
mfs=""
_7ztest="$xbtmp/metmp/a"
_metmp="$xbtmp/me.bin"
x_ rm -f "$_metmp" "$xbtmp/a"
x_ rm -Rf "$_7ztest"
# maintain compatibility with older configs
# because in the past, shrink was assumed:
if [ -z "$MEshrink" ]; then
MEshrink="y"
fi
if [ "$MEshrink" != "y" ] && \
[ "$MEshrink" != "n" ]; then
err "MEshrink set badly on '$board' vendor config"
fi
if [ "$ME11bootguard" = "y" ]; then
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
set +u +e
( fx_ find_me x_ find "$xbmkpwd/$appdir" -type f ) || :; :
set -u -e
if [ "$ME11bootguard" != "y" ]; then
x_ mv "$_metmp" "$_pre_dest"
else
( apply_deguard_hack ) || \
err "deguard error on '$_dest'" "extract_intel_me" "$@"; :
fi
}
# bruteforce Intel ME extraction.
# must be called inside a subshell.
find_me()
{
if [ -f "$_metmp" ]; then
# we found me.bin, so we stop searching
exit 1
elif [ -L "$1" ]; then
return 0
fi
_7ztest="${_7ztest}a"
_keep="" # -k: keep fptr modules even if they can be removed
_pass="" # -p: skip fptr check
_r="-r" # re-locate modules
_trunc="-t" # -t: truncate the ME size
if [ "$ME11bootguard" = "y" ]; then
mfs="--whitelist MFS"
fi
if [ "$MEclean" = "n" ]; then
MEshrink="n"
_keep="-k" # keep ME modules, don't delete anything
mfs="" # no MFS whitelist needed, due to -r:
fi
if [ "$MEclean" = "n" ] || \
[ "$MEshrink" != "y" ]; then
# MEclean can still be y, this just means don't shrink,
# so deleted modules would become padded space. this
# could also be used alongside --whitelist, if
# MEclean is otherwise enabled.
_r="" # don't re-locate ME modules
_trunc="" # don't shrink the me.bin file size
fi
if [ "$MEcheck" = "n" ]; then
_pass="-p" # skip fptr check
fi
if [ -n "$mfs" ]; then
_r="" # cannot re-locate modules if using --whitelist MFS
fi
if "$mecleaner" $mfs $_r $_keep $_pass $_trunc -O "$xbtmp/a" \
-M "$_metmp" "$1" \
|| \
[ -f "$_metmp" ]; then
# me.bin extracted from a full image with ifd, then shrunk
:
elif "$mecleaner" $mfs $_r $_pass $_keep $_trunc -O "$_metmp" "$1" \
|| \
[ -f "$_metmp" ]; then
# me.bin image already present, and we shrunk it
:
elif "$me7updateparser" $_keep -O "$_metmp" "$1"; then
# thinkpad sandybridge me.bin image e.g. x220/t420
:
elif extract_archive "$1" "$_7ztest"; then
# scan newly extracted archive within extracted archive
:
else
# could not extract anything, so we'll try the next file
return 0
fi
if [ -f "$_metmp" ]; then
# we found me.bin, so we stop searching
exit 1
else
# if the subshell does exit 1, we found me.bin, so exit 1
( fx_ find_me x_ find "$_7ztest" -type f ) || exit 1; :
fi
}
apply_deguard_hack()
{
x_ cd src/deguard
x_ ./finalimage.py --delta "data/delta/$ME11delta" \
--version "$ME11version" --pch "$ME11pch" --sku "$ME11sku" \
--fake-fpfs data/fpfs/zero --input "$_metmp" --output "$_pre_dest"
}
extract_archive()
{
if innoextract "$1" -d "$2"; then
:
elif python "$pfs_extract" "$1" -e; then
:
elif 7z x "$1" -o"$2"; then
:
elif "$bsdtar" -C "$2" -xf "$1"; then
:
elif "$bsdunzip" "$1" -d "$2"; then
:
else
return 1
fi
if [ -d "${_dl}_extracted" ]; then
x_ cp -R "${_dl}_extracted" "$2"
fi
}
extract_kbc1126ec()
{
( extract_kbc1126ec_dump ) || \
err "$board: can't extract kbc1126 fw" "extract_kbc1126ec" "$@"
# throw error if either file is missing
x_ e "$appdir/ec.bin.fw1" f
x_ e "$appdir/ec.bin.fw2" f
x_ cp "$appdir/"ec.bin.fw* "${_pre_dest%/*}/"
}
extract_kbc1126ec_dump()
{
x_ cd "$appdir/"
if mv Rompaq/68*.BIN ec.bin; then
:
elif unar -D ROM.CAB Rom.bin; then
:
elif unar -D Rom.CAB Rom.bin; then
:
elif unar -D 68*.CAB Rom.bin; then
:
else
err "!kbc1126 unar" "extract_kbc1126ec" "$@"
fi
if [ ! -f "ec.bin" ]; then
x_ mv Rom.bin ec.bin
fi
if x_ e ec.bin f; then
x_ "$kbc1126_ec_dump" ec.bin
fi
}
extract_e6400vga()
{
set +u +e
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" || :
(
x_ cd "$appdir"
x_ e "bios.bin" f
"$e6400_unpack" bios.bin || printf "TODO: fix dell extract util\n"
) || err "can't extract e6400 vga rom" "extract_e6400vga" "$@"
x_ cp "$appdir/$E6400_VGA_romname" "$_pre_dest"
}
extract_sch5545ec()
{
# full system ROM (UEFI), to extract with UEFIExtract:
_bios="${_dl}_extracted/Firmware/1 $dlsum -- 1 System BIOS vA.28.bin"
# this is the SCH5545 firmware, inside of the extracted UEFI ROM:
_sch5545ec_fw="$_bios.dump/4 7A9354D9-0468-444A-81CE-0BF617D890DF"
_sch5545ec_fw="$_sch5545ec_fw/54 D386BEB8-4B54-4E69-94F5-06091F67E0D3"
_sch5545ec_fw="$_sch5545ec_fw/0 Raw section/body.bin" # <-- this!
x_ "$uefiextract" "$_bios"
x_ cp "$_sch5545ec_fw" "$_pre_dest"
}
# Lenovo ThunderBolt firmware updates:
# https://pcsupport.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-t-series-laptops/thinkpad-t480-type-20l5-20l6/20l5/solutions/ht508988
extract_tbfw()
{
if [ -z "$TBFW_size" ]; then
err "$board: TBFW_size unset" "extract_tbfw" "$@"
fi
fx_ copytb x_ find "$appdir" -type f -name "TBT.bin"
}
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
}
extract_fsp()
{
x_ python "$cbdir/3rdparty/fsp/Tools/SplitFspBin.py" split -f "$1" \
-o "${_pre_dest%/*}" -n "Fsp.fd"
}
setvfile()
{
[ -n "$vcfg" ] && for c in $checkvarschk; do
do_getvfile="n"
vcmd="[ \"\${$c}\" != \"/dev/null\" ] && [ -n \"\${$c}\" ]"
eval "$vcmd && do_getvfile=\"y\""
if [ "$do_getvfile" = "y" ]; then
if getvfile "$@"; then
return 0
fi
fi
done && return 1; :
}
getvfile()
{
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
if [ $# -gt 0 ]; then
# download vendor files
getfiles
else
# inject vendor files
fx_ prep x_ find "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
( check_vendor_hashes ) || \
err "$archive: Can't verify hashes" "getvfile" "$@"; :
fi
}
bootstrap()
{
cbdir="src/coreboot/$tree"
kbc1126_ec_dump="$xbmkpwd/$cbdir/util/kbc1126/kbc1126_ec_dump"
cbfstool="elf/coreboot/$tree/cbfstool"
rmodtool="elf/coreboot/$tree/rmodtool"
mecleaner="$xbmkpwd/$cbdir/util/me_cleaner/me_cleaner.py"
if [ "$XBMKmecleaner" = "y" ]; then
mecleaner="$xbmkpwd/src/me_cleaner/me_cleaner.py"
fi
x_ ./mk -f coreboot "${cbdir##*/}"
x_ ./mk -f me_cleaner
x_ ./mk -b bios_extract
x_ ./mk -b biosutilities
x_ ./mk -b uefitool
x_ ./mk -b libarchive # for bsdtar and bsdunzip
if [ -d "${kbc1126_ec_dump%/*}" ]; then
x_ make -C "$cbdir/util/kbc1126"
fi
if [ -n "$MRC_refcode_cbtree" ]; then
cbfstoolref="elf/coreboot/$MRC_refcode_cbtree/cbfstool"
x_ ./mk -d coreboot "$MRC_refcode_cbtree"; :
fi
}
prep()
{
_xrom="$1"
_xromname="${1##*/}"
_xromnew="${_xrom%/*}/${_xromname#"$vfix"}"
if [ "$nuke" = "nuke" ]; then
_xromnew="${_xrom%/*}/$vfix${_xrom##*/}"
fi
if e "$_xrom" f missing; then
return 0
fi
if [ -z "${_xromname#"$vfix"}" ]; then
err "$_xromname / $vfix: name match" "prep" "$@"
fi
# Remove the prefix and 1-byte pad
if [ "${_xromname#"$vfix"}" != "$_xromname" ] && \
[ "$nuke" != "nuke" ]; then
unpad_one_byte "$_xrom"
x_ mv "$_xrom" "$_xromnew"
_xrom="$_xromnew"
fi
if [ "$nuke" = "nuke" ]; then
( mksha512 "$_xrom" "vendorhashes" ) || err; :
fi
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"
fi
}
mksha512()
{
build_sbase
if [ "${1%/*}" != "$1" ]; then
x_ cd "${1%/*}"
fi
x_ "$sha512sum" ./"${1##*/}" >> "$2" || \
err "!sha512sum \"$1\" > \"$2\"" "mksha512" "$@"
}
add_vfiles()
{
rom="$1"
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
if [ -n "$CONFIG_HAVE_REFCODE_BLOB" ]; then
vfile "fallback/refcode" "$CONFIG_REFCODE_BLOB_FILE" "stage"
fi
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
vfile "mrc.bin" "$CONFIG_MRC_FILE" "mrc" "0xfffa0000"
fi
if [ "$CONFIG_HAVE_ME_BIN" = "y" ]; then
vfile IFD "$CONFIG_ME_BIN_PATH" me
fi
if [ -n "$CONFIG_KBC1126_FW1" ]; then
vfile ecfw1.bin "$CONFIG_KBC1126_FW1" raw \
"$CONFIG_KBC1126_FW1_OFFSET"
fi
if [ -n "$CONFIG_KBC1126_FW2" ]; then
vfile ecfw2.bin "$CONFIG_KBC1126_FW2" raw \
"$CONFIG_KBC1126_FW2_OFFSET"
fi
if [ -n "$CONFIG_VGA_BIOS_FILE" ] && [ -n "$CONFIG_VGA_BIOS_ID" ]; then
vfile "pci$CONFIG_VGA_BIOS_ID.rom" "$CONFIG_VGA_BIOS_FILE" \
optionrom
fi
if [ "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" = "y" ] && \
[ -n "$CONFIG_SMSC_SCH5545_EC_FW_FILE" ]; then
vfile sch5545_ecfw.bin "$CONFIG_SMSC_SCH5545_EC_FW_FILE" raw
fi
if [ -z "$CONFIG_FSP_USE_REPO" ] && \
[ -z "$CONFIG_FSP_FULL_FD" ] && \
[ -n "$CONFIG_FSP_M_FILE" ]; then
vfile "$CONFIG_FSP_M_CBFS" "$CONFIG_FSP_M_FILE" fsp --xip
fi
if [ -z "$CONFIG_FSP_USE_REPO" ] && \
[ -z "$CONFIG_FSP_FULL_FD" ] && \
[ -n "$CONFIG_FSP_S_FILE" ]; then
vfile "$CONFIG_FSP_S_CBFS" "$CONFIG_FSP_S_FILE" fsp
fi
xchanged="y"
printf "ROM image successfully patched: %s\n" "$rom"
}
vfile()
{
if [ "$2" = "/dev/null" ]; then
return 0
fi
cbfsname="$1"
_dest="${2##*../}"
blobtype="$3"
_offset=""
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" "$@"
fi
if [ "$nuke" != "nuke" ]; then
x_ e "$_dest" f
fi
if [ "$cbfsname" = "IFD" ]; then
if [ "$nuke" = "nuke" ]; then
x_ "$ifdtool" $ifdprefix --nuke $blobtype "$rom" \
-O "$rom"
else
x_ "$ifdtool" $ifdprefix -i $blobtype:$_dest "$rom" \
-O "$rom"
fi
elif [ "$nuke" = "nuke" ]; then
x_ "$cbfstool" "$rom" remove -n "$cbfsname"
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 $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
( x_ "$sha512sum" -c "$hashfile" ) || \
x_ sha1sum -c "$hashfile"
fi
x_ rm -f "$hashfile"
}