Revert "xbmk: general code cleanup"

This reverts commit 1b65e8914c.

NOTE: cleanup of xbmk_git_init was retained

this "cleanup" actually made the code harder to read.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-09-10 12:29:39 +01:00
parent 123639e3db
commit afdf8c7733
11 changed files with 130 additions and 938 deletions
+2 -10
View File
@@ -32,13 +32,11 @@ mr_edk2tree="chromebook" # tree name in xbmk
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
@@ -66,7 +64,6 @@ 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"
}
@@ -84,7 +81,6 @@ prep_mr()
x_ prep_mr_clone "$@"
x_ prep_mr_patch "$@"
x_ prep_mr_file "config/$1/$6/target.cfg" \
"$spdx" \
"" \
@@ -108,13 +104,10 @@ prep_mr_patch()
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 || :
}
@@ -126,11 +119,10 @@ prep_mr_file()
x_ rm -f "$mr_filename"
while [ $# -gt 0 ]; do
while [ $# -gt 0 ]
do
printf "%s\n" "$1" >> "$mr_filename" || \
err "Can't write '$1' to '$mr_filename'" prep_mr_file "$@"
shift 1
done
+15 -94
View File
@@ -20,7 +20,6 @@ tmpgitcache="$xbtmp/tmpgit"
fetch_targets()
{
if [ -d "src/$project/$tree" ]; then
return 0
fi
@@ -36,22 +35,16 @@ fetch_project()
err "Can't read config 'config/git/$project/pkg.cfg'" \
"fetch_project" "@"
if [ -z "$url" ] || \
[ -z "$bkup_url" ]; then
if [ -z "$url" ] || [ -z "$bkup_url" ]; then
err "url/bkup_url not both set 'config/git/$project/pkg.cfg'" \
"fetch_project" "$@"
fi
if [ -n "$xgcctree" ]; then
x_ ./mk -f coreboot "$xgcctree"
fi
if [ -n "$depend" ]; then
for d in $depend ; do
x_ ./mk -f $d
done
fi
@@ -62,14 +55,12 @@ fetch_project()
clone_project()
{
if ! singletree "$project"; then
return 0
fi
loc="src/$project"
if [ -d "$loc" ]; then
return 0
fi
@@ -85,20 +76,15 @@ git_prep()
_loc="$4" # $1 and $2 are gitrepo and gitrepo_backup
if [ -z "$rev" ]; then
err "$project/$tree: rev not set" "git_prep" "$@"
fi
xbget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
if singletree "$project" || \
[ $# -gt 4 ]; then
if singletree "$project" || [ $# -gt 4 ]; then
dx_ fetch_submodule "$mdir/module.list"
fi
if [ "$_loc" != "${_loc%/*}" ]; then
x_ xbmkdir "${_loc%/*}"
fi
@@ -119,59 +105,41 @@ fetch_submodule()
if e "$mcfgdir/module.cfg" f missing; then
return 0
fi
. "$mcfgdir/module.cfg" || \
err "Can't read '$mcfgdir/module.cfg'" "fetch_submodules" "$@"
if [ -n "$subgit" ] || \
[ -n "$subgit_bkup" ]; then
if [ -n "$subgit" ] || [ -n "$subgit_bkup" ]; then
st="$st git"
fi
if [ -n "$subcurl" ] || \
[ -n "$subcurl_bkup" ]; then
if [ -n "$subcurl" ] || [ -n "$subcurl_bkup" ]; then
st="$st curl"
fi
st="${st# }"
if [ "$st" = "git curl" ]; then
err "$mdir: git+curl defined" "fetch_submodule" "$@"
fi
if [ -z "$st" ]; then
return 0
fi
if [ "$st" = "curl" ]; then
if [ -z "$subcurl" ] || [ -z "$subcurl_bkup" ]; then
err "subcurl/subcurl_bkup not both set" \
"fetch_submodule" "$@"
fi
elif [ -z "$subgit" ] || \
[ -z "$subgit_bkup" ]; then
elif [ -z "$subgit" ] || [ -z "$subgit_bkup" ]; then
err "subgit/subgit_bkup not both set" "fetch_submodule" "$@"
elif [ -z "$subhash" ]; then
err "subhash not set" "fetch_submodule" "$@"
fi
if [ "$st" = "git" ]; then
x_ rm -Rf "$tmpgit/$1"
xbget "$st" "$subgit" "$subgit_bkup" "$tmpgit/$1" \
"$subhash" "$mdir/${1##*/}/patches"
else
xbget "$st" "$subcurl" "$subcurl_bkup" "$tmpgit/$1" \
"$subhash" "$mdir/${1##*/}/patches"
fi
@@ -183,41 +151,30 @@ fetch_submodule()
xbget()
{
if [ "$1" != "curl" ] && \
[ "$1" != "copy" ] && \
[ "$1" != "git" ]; then
if [ "$1" != "curl" ] && [ "$1" != "copy" ] && [ "$1" != "git" ]; then
err "Bad dlop (arg 1)" "xbget" "$@"
fi
for url in "$2" "$3"; do
for url in "$2" "$3"
do
if [ -z "$url" ]; then
err "empty URL given in" "xbget" "$@"
elif ! try_fetch "$url" "$@"; then
continue
fi
case "$1" in
git)
if [ ! -d "$4" ]; then
continue
fi
;;
*)
if [ ! -f "$4" ]; then
continue
fi
;;
esac
return 0 # successful download/copy
done
@@ -227,15 +184,11 @@ xbget()
try_fetch()
{
if [ "$2" = "git" ]; then
if ! try_fetch_git "$@"; then
return 1
fi
else
if ! try_fetch_file "$@"; then
return 1
fi
fi
@@ -248,34 +201,27 @@ try_fetch_git()
# directories becomes cache/mirror/foo.example.com/repo
if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
cached="mirror"
else
cached="clone"
fi
cached="$cached/${1#*://}"
cached="$XBMK_CACHE/$cached"
x_ xbmkdir "${5%/*}" "${cached%/*}"
if ! try_$2 "$cached" "$@"; then
return 1
elif [ ! -d "$cached" ]; then
return 1
fi
if [ ! -d "$5" ]; then
tmpclone "$cached" "$5" "$6" "$7" || \
err "Can't clone final repo" "try_fetch" "$@"; :
fi
if [ ! -d "$5" ]; then
return 1
fi
}
@@ -288,14 +234,11 @@ try_fetch_file()
x_ xbmkdir "${5%/*}" "${cached%/*}"
if bad_checksum "$6" "$cached" 2>/dev/null; then
x_ rm -f "$cached"
fi
if [ ! -f "$cached" ]; then
if ! try_$2 "$cached" "$@"; then
return 1
fi
fi
@@ -307,50 +250,39 @@ try_fetch_file()
fi
if [ ! -f "$cached" ]; then
return 1
elif bad_checksum "$6" "$cached"; then
x_ rm -f "$cached"
return 1
fi
if [ "$cached" != "$5" ]; then
x_ cp "$cached" "$5"
fi
if bad_checksum "$6" "$5"; then
x_ rm -f "$5"
return 1
elif [ ! -f "$5" ]; then
return 1
fi
}
try_curl()
{
ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
_ua=""
case "$2" in
https://www.supermicro.com/*)
ua="curl/8.6.0"
;;
_ua="curl/8.6.0";;
*)
:
;;
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";;
esac
( x_ curl --location --retry 3 -A "$ua" "$2" -o "$1" ) \
|| ( x_ wget --tries 3 -U "$ua" "$2" -O "$1" ) \
( x_ curl --location --retry 3 -A "$_ua" "$2" -o "$1" ) \
|| ( x_ wget --tries 3 -U "$_ua" "$2" -O "$1" ) \
|| return 1; :
}
@@ -367,13 +299,10 @@ try_git()
x_ rm -Rf "$tmpgitcache"
if [ ! -d "$gitdest" ]; then
if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
( x_ git clone --mirror "$2" "$tmpgitcache" ) || \
return 1
else
( x_ git clone "$2" "$tmpgitcache" ) || return 1
fi
@@ -383,7 +312,6 @@ try_git()
if git -C "$gitdest" show "$7" 1>/dev/null 2>/dev/null && \
[ "$forcepull" != "y" ]; then
# don't try to pull the latest changes if the given target
# revision already exists locally. this saves a lot of time
# during release builds, and reduces the chance that we will
@@ -393,11 +321,9 @@ try_git()
fi
if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
( x_ git -C "$gitdest" fetch ) || :; :
( x_ git -C "$gitdest" update-server-info ) || :; :
else
( x_ git -C "$gitdest" pull --all ) || :; :
fi
}
@@ -405,22 +331,17 @@ try_git()
bad_checksum()
{
if e "$2" f missing; then
return 0
fi
build_sbase
csum="$(x_ "$sha512sum" "$2" | awk '{print $1}')" || \
err "!sha512 '$2' $1" bad_checksum "$@"
if [ "$csum" = "$1" ]; then
return 1
else
x_ rm -f "$2"
printf "BAD SHA512 %s, '%s'; need %s\n" "$csum" "$2" "$1" 1>&2
fi
}
+20 -129
View File
@@ -47,8 +47,8 @@ xbmk_init()
sha512sum="$xbmkpwd/util/sbase/sha512sum"
if [ $# -gt 0 ] && [ "$1" = "dependencies" ]; then
x_ xbmkpkg "$@"
exit 0
fi
@@ -56,7 +56,6 @@ xbmk_init()
err "suid check failed" "xbmk_init" "$@"
if [ "$(id -u)" = "0" ]; then
err "this command as root is not permitted" "xbmk_init" "$@"
fi
@@ -64,14 +63,11 @@ xbmk_init()
x_ xbmkdir "$basetmp"
if [ ! -e "cache" ]; then
x_ xbmkdir "cache"
fi
for init_cmd in get_version set_env set_threads git_init child_exec; do
if ! xbmk_$init_cmd "$@"; then
break
fi
done
@@ -82,24 +78,19 @@ xbmkpkg()
xchk xbmkpkg "$@"
if [ $# -gt 2 ]; then
reinstall="$3"
fi
. "config/dependencies/$2" || \
err "Can't read 'config/dependencies/$2'" "xbmkpkg" "$@"
if [ -z "$pkg_add" ] || \
[ -z "$pkglist" ]; then
if [ -z "$pkg_add" ] || [ -z "$pkglist" ]; then
err "pkg_add/pkglist not both set" "xbmkpkg" "$@"
fi
if [ "$2" == "gentoo" ]; then
if [ -z "$pkg_use" ] || \
[ -z "$pkg_use_file" ]; then
if [ -z "$pkg_use" ] || [ -z "$pkg_use_file" ]; then
err "pkg_use/pkg_use_file not both set" "xbmkpkg" "$@"
fi
@@ -107,7 +98,6 @@ xbmkpkg()
printf "Writing into %s" "$pkg_use_file..."
if [ ! -d "`dirname $pkg_use_file`" ]; then
x_ mkdir -p "`dirname $pkg_use_file`"
fi
@@ -117,7 +107,6 @@ xbmkpkg()
x_ $pkg_add $pkglist
if [ -n "$aur_notice" ]; then
printf "You need AUR packages: %s\n" "$aur_notice" 1>&2
fi
}
@@ -125,45 +114,31 @@ xbmkpkg()
xbmk_get_version()
{
if [ -f ".version" ]; then
read -r version < ".version" || \
err "can't read version file" "xbmk_get_version" "$@"
fi
if [ -f ".versiondate" ]; then
read -r versiondate < ".versiondate" || \
err "can't read versiondate" xbmk_get_version "$@"
fi
if [ -f ".version" ] && \
[ -z "$version" ]; then
if [ -f ".version" ] && [ -z "$version" ]; then
err "version not set" "xbmk_get_version" "$@"
fi
if [ -f ".versiondate" ] && \
[ -z "$versiondate" ]; then
if [ -f ".versiondate" ] && [ -z "$versiondate" ]; then
err "versiondate not set" "xbmk_get_version" "$@"
fi
if [ ! -e ".git" ] && \
[ ! -f ".version" ]; then
if [ ! -e ".git" ] && [ ! -f ".version" ]; then
version="unknown"
fi
if [ ! -e ".git" ] && \
[ ! -f ".versiondate" ]; then
if [ ! -e ".git" ] && [ ! -f ".versiondate" ]; then
versiondate="1716415872"
fi
xbmk_sanitize_version
if [ -n "$version" ]; then
relname="$projectname-$version"
fi
}
@@ -178,26 +153,19 @@ xbmk_set_env()
xbmkpath="$PATH"
# unify all temporary files/directories in a single TMPDIR
if [ -n "${TMPDIR+x}" ] && \
[ "${TMPDIR%_*}" != "$basetmp/xbmk" ]; then
if [ -n "${TMPDIR+x}" ] && [ "${TMPDIR%_*}" != "$basetmp/xbmk" ]; then
unset TMPDIR
fi
if [ -n "${TMPDIR+x}" ]; then
export TMPDIR="$TMPDIR"
xbtmp="$TMPDIR"
fi
if [ -n "${TMPDIR+x}" ]; then
is_child="y"
fi
if [ "$is_child" = "y" ]; then
if [ "$is_child" = "y" ]
then
# child instance of xbmk, so we stop init after this point
# and execute the given user command upon return:
@@ -205,7 +173,6 @@ xbmk_set_env()
return 1
else
# parent instance of xbmk, so we continue initialising.
# a parent instance of xbmk never processes its own
# command directly; instead, it calls a child instance
@@ -222,17 +189,12 @@ xbmk_child_set_env()
xbmk_child_set_tmp
if [ -z "${XBMK_CACHE+x}" ]; then
err "XBMK_CACHE unset on child" "xbmk_set_env" "$@"
fi
if [ -z "${XBMK_THREADS+x}" ]; then
xbmk_set_threads; :
fi
if [ -z "${XBMK_CACHE_MIRROR+x}" ]; then
xbmk_set_mirror
fi
}
@@ -250,7 +212,6 @@ xbmk_child_set_tmp()
err "can't read '$xbmklock'" "xbmk_child_set_tmp" "$@"
if [ "$locktmp" != "$xbtmpchk" ]; then
badtmp="TMPDIR '$xbtmpchk' changed; was '$locktmp'"
printf "bad TMPDIR init, '%s': %s\n" "$TMPDIR" "$badtmp" 1>&2
@@ -258,7 +219,6 @@ xbmk_child_set_tmp()
fi
xbtmp="$xbtmpchk"
export TMPDIR="$xbtmpchk"
}
@@ -276,13 +236,11 @@ xbmk_parent_set_env()
x_ chmod -w "$xbmklock"
xbmk_parent_set_export
xbmk_set_version
remkdir "$xbtmp" "$xbtmp/gnupath" "$xbtmp/xbmkpath"
xbmk_set_pyver
xbmk_set_mirror
}
@@ -297,9 +255,7 @@ xbmk_parent_check_tmp()
x_ touch "$xbmklist"
for xtmpdir in "$basetmp"/xbmk_*; do
if [ -e "$xtmpdir" ]; then
printf "%s\n" "$xtmpdir" >> "$xbmklist" || \
err "can't write '$xtmpdir' to '$xbmklist'" \
"xbmk_parent_check_tmp" "$@"; :
@@ -307,19 +263,14 @@ xbmk_parent_check_tmp()
done
# set up a unified temporary directory, for common deletion later:
export TMPDIR="`x_ mktemp -d -t xbmk_XXXXXXXX`" || \
err "can't export TMPDIR" "xbmk_parent_check_tmp" "$@"
xbtmp="$TMPDIR"
while read -r xtmpdir; do
if [ "$xtmpdir" = "$xbtmp" ]; then
err "pre-existing '$xbtmp'" "xbmk_parent_check_tmp" "$@"
fi
done < "$xbmklist" || \
err "Can't read xbmklist: '$xbmklist'" "xbmk_parent_check_tmp" "$@"
@@ -330,9 +281,7 @@ xbmk_parent_set_export()
{
export XBMK_CACHE="$xbmkpwd/cache"
if [ -e "$XBMK_CACHE" ] && \
[ ! -d "$XBMK_CACHE" ]; then
if [ -e "$XBMK_CACHE" ] && [ ! -d "$XBMK_CACHE" ]; then
err "cachedir '$XBMK_CACHE' is a file" \
"xbmk_parent_set_export" "$@"
fi
@@ -344,17 +293,12 @@ xbmk_parent_set_export()
# (this is used to exclude certain build targets from releases)
if [ -z "${XBMK_RELEASE+x}" ]; then
export XBMK_RELEASE="n"
fi
if [ "$XBMK_RELEASE" = "Y" ]; then
export XBMK_RELEASE="y"
fi
if [ "$XBMK_RELEASE" != "y" ]; then
export XBMK_RELEASE="n"
fi
}
@@ -362,13 +306,10 @@ xbmk_parent_set_export()
xbmk_set_threads()
{
if [ -z "${XBMK_THREADS+x}" ]; then
export XBMK_THREADS=1
fi
if ! expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \
1>/dev/null 2>/dev/null; then
export XBMK_THREADS=1
fi
}
@@ -376,74 +317,54 @@ xbmk_set_threads()
xbmk_set_version()
{
version_="$version"
if [ -e ".git" ]; then
version="$(git describe --tags HEAD 2>&1)" || \
version="git-$(git rev-parse HEAD 2>&1)" || \
version="$version_"
fi
versiondate_="$versiondate"
if [ -e ".git" ]; then
versiondate="$(git show --no-patch --no-notes \
--pretty='%ct' HEAD)" || versiondate="$versiondate_"
fi
if [ -z "$version" ] || \
[ -z "$versiondate" ]; then
if [ -z "$version" ] || [ -z "$versiondate" ]; then
err "version and/or versiondate unset" "xbmk_set_version" "$@"
fi
update_xbmkver "."
relname="$projectname-$version"
export LOCALVERSION="-$projectname-${version%%-*}"
}
xbmk_set_pyver()
{
pyver="2"
python="python3"
pyver="2"
pyv="import sys; print(sys.version_info[:])"
if ! pybin python3 1>/dev/null; then
python="python"
fi
if [ "$python" = "python3" ]; then
pyver="3"
fi
if ! pybin "$python" 1>/dev/null; then
pyver=""
fi
if [ -n "$pyver" ]; then
"`x_ pybin "$python"`" -c "$pyv" 1>/dev/null \
2>/dev/null || \
err "Can't detect Python version." "xbmk_set_pyver" "$@"
fi
if [ -n "$pyver" ]; then
pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')"
pyver="${pyver#(}"
pyver="${pyver%,}"
fi
if [ "${pyver%%.*}" != "3" ]; then
err "Bad python version (must by 3.x)" "xbmk_set_pyver" "$@"
fi
@@ -467,16 +388,11 @@ pybin()
py="import sys; quit(1) if sys.prefix == sys.base_prefix else quit(0)"
venv=1
if ! command -v "$1" 1>/dev/null 2>/dev/null; then
venv=0
fi
if [ $venv -gt 0 ]; then
if ! "$1" -c "$py" 1>/dev/null 2>/dev/null; then
venv=0
fi
fi
@@ -484,14 +400,11 @@ pybin()
# ideally, don't rely on PATH or hardcoded paths if python venv.
# use the *real*, direct executable linked to by the venv symlink:
if [ $venv -gt 0 ] && \
[ -L "`command -v "$1" 2>/dev/null`" ]; then
if [ $venv -gt 0 ] && [ -L "`command -v "$1" 2>/dev/null`" ]; then
pypath="$(findpath \
"$(command -v "$1" 2>/dev/null)" 2>/dev/null || :)"
if [ -e "$pypath" ] && \
[ ! -d "$pypath" ] && \
if [ -e "$pypath" ] && [ ! -d "$pypath" ] && \
[ -x "$pypath" ]; then
printf "%s\n" "$pypath"
@@ -503,22 +416,17 @@ pybin()
# if python venv: fall back to common PATH directories for checking:
[ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do
if [ -e "$pypath/$1" ] && \
! -d "$pypath/$1" ] && \
if [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \
[ -x "$pypath/$1" ]; then
printf "%s/%s\n" "$pypath" "$1"
return 0
fi
done && return 1
# Defer to normal command -v if not a venv:
# Defer to normal command -v if not a venv
if ! command -v "$1" 2>/dev/null; then
return 1
fi
}
@@ -534,12 +442,9 @@ xbmk_set_mirror()
# appreciate it, so it should only be used for development or archival
if [ -z "${XBMK_CACHE_MIRROR+x}" ]; then
export XBMK_CACHE_MIRROR="n"
fi
if [ "$XBMK_CACHE_MIRROR" != "y" ]; then
export XBMK_CACHE_MIRROR="n"
fi
}
@@ -547,26 +452,19 @@ xbmk_set_mirror()
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" "$@"
fi
if [ -e ".git" ]; then
return 0
fi
@@ -580,13 +478,10 @@ xbmk_git_init()
err "can't get date" "xbmk_git_init" "$@"
x_ git init 1>/dev/null 2>/dev/null
x_ git add -A . 1>/dev/null 2>/dev/null
x_ git -c user.name="xbmk" -c user.email="xbmk@example.com" \
commit -m "$projectname $version" --date "$cdate" \
--author="xbmk <xbmk@example.com>" 1>/dev/null 2>/dev/null
x_ git -c user.name="xbmk" -c user.email="xbmk@example.com" \
tag -a "$version" -m "$projectname $version" \
1>/dev/null 2>/dev/null; :
@@ -596,14 +491,10 @@ xbmk_child_exec()
{
xbmk_rval=0
( x_ ./mk "$@" ) \
|| xbmk_rval=1
( x_ ./mk "$@" ) || xbmk_rval=1
( x_ rm -Rf "$xbtmp" ) \
|| xbmk_rval=1
( x_ rm -f "$xbmklock" ) \
|| xbmk_rval=1
( x_ rm -Rf "$xbtmp" ) || xbmk_rval=1
( x_ rm -f "$xbmklock" ) || xbmk_rval=1
exit $xbmk_rval
}
+2 -59
View File
@@ -10,14 +10,10 @@ 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
@@ -38,7 +34,6 @@ inject()
remkdir "$tmpromdel"
if [ $# -lt 1 ]; then
err "No options specified" "inject" "$@"
fi
@@ -49,57 +44,39 @@ inject()
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
@@ -109,12 +86,9 @@ inject()
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
@@ -122,39 +96,28 @@ check_release()
|| 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
@@ -164,7 +127,6 @@ check_target()
err "Can't read '$boarddir/target.cfg'" "check_target" "$@"
if [ -z "$tree" ]; then
err "tree unset in '$boarddir/target.cfg'" "check_target" "$@"
fi
@@ -173,7 +135,6 @@ check_target()
ifdtool="elf/coreboot/$tree/ifdtool"
if [ -n "$IFD_platform" ]; then
ifdprefix="-p $IFD_platform"
fi
}
@@ -181,7 +142,6 @@ check_target()
patch_release()
{
if [ "$nuke" != "nuke" ]; then
x_ ./mk download "$board"
fi
@@ -189,13 +149,10 @@ patch_release()
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"
@@ -204,12 +161,8 @@ patch_release()
done
if ! readkconfig; then
return 1
elif [ -n "$new_mac" ] && \
[ -n "$CONFIG_GBE_BIN_PATH" ]; then
elif [ -n "$new_mac" ] && [ -n "$CONFIG_GBE_BIN_PATH" ]; then
modify_mac
fi
}
@@ -221,7 +174,6 @@ readkconfig()
fx_ scankconfig x_ find "$boarddir/config" -type f
if e "$xbtmp/cbcfg" f missing; then
return 1
fi
@@ -229,7 +181,6 @@ readkconfig()
err "Can't read '$xbtmp/cbcfg'" "readkconfig" "$@"
if ! setvfile "$@"; then
return 1
fi
}
@@ -237,7 +188,6 @@ readkconfig()
scankconfig()
{
for cbc in $checkvars; do
grep "$cbc" "$1" 2>/dev/null 1>>"$xbtmp/cbcfg" || :
done
}
@@ -246,11 +196,8 @@ modify_mac()
{
x_ cp "${CONFIG_GBE_BIN_PATH##*../}" "$xbtmp/gbe"
if [ -n "$new_mac" ] && \
[ "$new_mac" != "restore" ]; then
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"
@@ -259,16 +206,13 @@ modify_mac()
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
}
@@ -279,7 +223,6 @@ 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" "$@"
+6 -53
View File
@@ -11,7 +11,6 @@ rmodtool="elf/coreboot/default/rmodtool"
mkrom_tarball()
{
update_xbmkver "$1"
mktarball "$1" "${1%/*}/${relname}_${1##*/}.tar.xz"
x_ rm -Rf "$1"
@@ -31,7 +30,6 @@ update_xbmkver()
xbmk_sanitize_version()
{
if [ -z "$version" ]; then
return 0
fi
@@ -44,7 +42,6 @@ xbmk_sanitize_version()
version="${version#-}"
if [ -z "$version" ]; then
err "'version' empty after sanitization" \
"xbmk_sanitize_version" "$@"
fi
@@ -55,7 +52,6 @@ mktarball()
printf "Creating tar archive '%s' from directory '%s'\n" "$2" "$1"
if [ "${2%/*}" != "$2" ]; then
x_ xbmkdir "${2%/*}"
fi
@@ -68,7 +64,6 @@ e()
es_t="e"
if [ $# -gt 1 ]; then
es_t="$2"
fi
@@ -76,7 +71,6 @@ e()
estr="[ -$es_t \"\$1\" ] || return 1"
if [ $# -gt 2 ]; then
estr="[ -$es_t \"\$1\" ] && return 1"
es2="missing"
fi
@@ -91,18 +85,14 @@ setvars()
_setvars=""
if [ $# -lt 2 ]; then
return 0
fi
val="$1"
shift 1
while [ $# -gt 0 ]; do
printf "%s=\"%s\"\n" "$1" "$val"
shift 1
done
}
@@ -118,16 +108,14 @@ singletree()
findpath()
{
if [ $# -lt 1 ]; then
err "findpath: No arguments provided" "findpath" "$@"
fi
while [ $# -gt 0 ]; do
while [ $# -gt 0 ]
do
found="`readlink -f "$1" 2>/dev/null`" || return 1; :
if [ -z "$found" ]; then
found="`realpath "$1" 2>/dev/null`" || \
return 1
fi
@@ -155,7 +143,6 @@ unpad_one_byte()
err "can't increment file size" "unpad_one_byte" "$@"
if [ $xromsize -lt 524288 ]; then
err "too small, $xromsize: $1" "unpad_one_byte" "$@"
fi
@@ -163,14 +150,12 @@ 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
x_ make -C "$xbmkpwd/util/sbase"
fi
}
@@ -178,16 +163,14 @@ build_sbase()
remkdir()
{
x_ rm -Rf "$@"
x_ xbmkdir "$@"
}
xbmkdir()
{
while [ $# -gt 0 ]; do
while [ $# -gt 0 ]
do
if [ ! -d "$1" ]; then
x_ mkdir -p "$1"
fi
@@ -198,14 +181,12 @@ xbmkdir()
fx_()
{
xchk fx_ "$@"
xcmd="$1"
xfile="`mktemp || err "can't create tmpfile"`" || \
err "can't make tmpfile" "fx_" "$@"
x_ rm -f "$xfile"
x_ touch "$xfile"
shift 1
@@ -214,7 +195,6 @@ fx_()
err "can't sort to '$xfile'" "fx_" "$xcmd" "$@"
dx_ "$xcmd" "$xfile" || :
x_ rm -f "$xfile"
}
@@ -223,30 +203,21 @@ dx_()
xchk dx_ "$@"
if [ ! -f "$2" ]; then
return 0
fi
while read -r fx; do
$1 "$fx" || return 1; :
done < "$2" \
|| err "cannot read '$2'" "dx_" "$@"; :
done < "$2" || err "cannot read '$2'" "dx_" "$@"; :
}
x_()
{
if [ $# -lt 1 ]; then
return 0
elif [ -z "$1" ]; then
err "Empty first arg" "x_" "$@"
else
"$@" || err "Unhandled error" "x_" "$@"
fi
}
@@ -254,12 +225,8 @@ x_()
xchk()
{
if [ $# -lt 3 ]; then
err "$1 needs at least two arguments" "xchk" "$@"
elif [ -z "$2" ] || \
[ -z "$3" ]; then
elif [ -z "$2" ] || [ -z "$3" ]; then
err "arguments must not be empty" "xchk" "$@"
fi
}
@@ -267,19 +234,12 @@ xchk()
err()
{
if [ $# -eq 1 ]; then
printf "ERROR %s: %s\n" "$0" "$1" 1>&2 || :
elif [ $# -gt 1 ]; then
printf "ERROR %s: %s: in command with args: " "$0" "$1" 1>&2
shift 1
xprintf "$@" 1>&2
else
printf "ERROR, but no arguments provided to err\n" 1>&2
fi
@@ -289,23 +249,16 @@ err()
xprintf()
{
xprintfargs=0
while [ $# -gt 0 ]; do
printf "\"%s\"" "$1"
if [ $# -gt 1 ]; then
printf " "
fi
xprintfargs=1
shift 1
done
if [ $xprintfargs -gt 0 ]; then
printf "\n"
fi
}
+1 -8
View File
@@ -19,7 +19,6 @@ extract_refcode()
# cbfstool from coreboot 4.11_branch, the tree used by ASUS KGPE-D16:
if [ -z "$cbfstoolref" ]; then
err "cbfstoolref not set" "extract_refcode" "$@"
fi
@@ -28,10 +27,8 @@ extract_refcode()
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:
# 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
@@ -42,11 +39,8 @@ extract_refcode()
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
@@ -54,7 +48,6 @@ extract_mrc()
(
x_ cd "$appdir"
extract_partition "${MRC_url##*/}"
extract_archive "$SHELLBALL" .
+3 -26
View File
@@ -14,58 +14,45 @@ release()
reldir="release"
while getopts m: option; do
while getopts m: option
do
if [ -z "$OPTARG" ]; then
err "empty argument not allowed" "release" "$@"
fi
case "$option" in
m)
relmode="$OPTARG"
;;
*)
err "invalid option '-$option'" "release" "$@"
;;
esac
done
reldest="$reldir/$version"
if [ -e "$reldest" ]; then
err "already exists: \"$reldest\"" "release" "$@"
fi
vdir="`mktemp -d || err "can't make vdir"`" || \
err "can't make tmp vdir" "release" "$@"
vdir="$vdir/$version"
rsrc="$vdir/${relname}_src"
remkdir "$vdir"
x_ git clone . "$rsrc"
update_xbmkver "$rsrc"
prep_release src
prep_release tarball
if [ "$relmode" != "src" ]; then
prep_release bin
fi
x_ rm -Rf "$rsrc"
x_ xbmkdir "$reldir"
x_ mv "$vdir" "$reldir"
x_ rm -Rf "${vdir%"/$version"}"
@@ -76,11 +63,8 @@ prep_release()
{
(
if [ "$1" != "tarball" ]; then
x_ cd "$rsrc"
if [ ! -e "cache" ]; then
x_ ln -s "$XBMK_CACHE" "cache"
fi
fi
@@ -99,18 +83,15 @@ prep_release_src()
fx_ "x_ rm -Rf" x_ find . -name ".git"
fx_ "x_ rm -Rf" x_ find . -name ".gitmodules"
# delete unwanted files from the release
( fx_ nuke x_ find config -type f -name "nuke.list" ) || \
err "can't prune project files" "prep_release_src" "$@"; :
}
# delete unwanted files from the release
nuke()
{
r="$rsrc/src/${1#config/}"
if [ -d "${r%/*}" ]; then
x_ cd "${r%/*}"
dx_ "x_ rm -Rf" "$rsrc/$1"
@@ -124,9 +105,7 @@ prep_release_tarball()
err "can't create '$rsrc/CHANGELOG'" "prep_release_tarball" "$@"
x_ rm -f "$rsrc/lock" "$rsrc/cache"
x_ rm -Rf "$rsrc/xbmkwd" "$rsrc/util/sbase"
x_ mv "$rsrc/util/sbase2" "$rsrc/util/sbase"
(
@@ -139,12 +118,10 @@ 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
fx_ mkrom_tarball x_ find bin -maxdepth 1 -type d -name "serprog_*"
+25 -156
View File
@@ -11,21 +11,15 @@ 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##*.}"
}
@@ -69,9 +63,7 @@ mkpayload_grub()
corebootpremake()
{
if [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" = "n" ]; then
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 0
fi
@@ -83,18 +75,14 @@ corebootpremake()
printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
err "!mk $srcdir .coreboot-version" "corebootpremake" "$@"
if [ -z "$mode" ] && \
[ "$target" != "$tree" ]; then
if [ -z "$mode" ] && [ "$target" != "$tree" ]; then
x_ ./mk download "$target"
fi
}
cook_coreboot_config()
{
if [ -z "$mode" ] && \
[ -f "$srcdir/.config" ]; then
if [ -z "$mode" ] && [ -f "$srcdir/.config" ]; then
printf "CONFIG_CCACHE=y\n" >> "$srcdir/.config" || \
err "can't cook '$srcdir'" "cook_coreboot_config" "$@"
fi
@@ -103,12 +91,9 @@ cook_coreboot_config()
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
@@ -116,33 +101,26 @@ check_coreboot_util()
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
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
}
@@ -159,9 +137,7 @@ coreboot_pad_one_byte()
mkcorebootbin()
{
if [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" = "n" ]; then
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 0
fi
@@ -172,9 +148,7 @@ mkcorebootbin()
check_coreboot_util ifdtool
for y in "$target_dir/config"/*; do
defconfig="$y"
mkcorebootbin_real
done
@@ -184,7 +158,6 @@ mkcorebootbin()
mkcorebootbin_real()
{
if [ "$target" = "$tree" ]; then
return 0
fi
@@ -192,28 +165,21 @@ mkcorebootbin_real()
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 \
@@ -222,69 +188,48 @@ mkcorebootbin_real()
$if_not_dry_build \
unpad_one_byte "$tmprom"
if [ -n "$payload_uboot" ] && \
[ "$payload_uboot" != "amd64" ] && \
[ "$payload_uboot" != "i386" ] && \
[ "$payload_uboot" != "arm64" ]; then
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
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 [ "$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
if [ "$payload_grubsea" = "y" ] && [ "$initmode" = "normal" ]; then
payload_grubsea="n"
fi
if [ "$payload_grub" != "y" ]; then
payload_grubsea="n"
fi
@@ -292,29 +237,20 @@ mkcorebootbin_real()
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; :
}
@@ -326,12 +262,9 @@ 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
if [ -z "$op_name" ] || [ -z "$op_arg" ]; then
return 0
fi
@@ -350,9 +283,7 @@ add_cbfs_option()
add_seabios()
{
if [ -n "$payload_uboot" ] && \
[ "$payload_uboot" != "arm64" ]; then
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
@@ -361,16 +292,11 @@ add_seabios()
fi
_seabioself="elf/seabios/default/default/$initmode/bios.bin.elf"
if [ "$initmode" = "fspgop" ]; then
[ "$initmode" = "fspgop" ] && \
_seabioself="elf/seabios/default/default/libgfxinit/bios.bin.elf"
fi
_seaname="fallback/payload"
if [ "$payload_grubsea" = "y" ]; then
_seaname="seabios.elf"
fi
@@ -379,39 +305,27 @@ add_seabios()
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
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
@@ -424,18 +338,13 @@ add_seabios()
if [ "$payload_uboot" = "amd64" ] && \
[ "$displaymode" != "txtmode" ] && \
[ "$initmode" != "normal" ] && \
[ "$payload_grubsea" != "y" ]; then
[ "$initmode" != "normal" ] && [ "$payload_grubsea" != "y" ]; then
pname="seauboot"
cprom "seauboot"
fi
if [ "$payload_grub" = "y" ]; then
pname="seagrub"
mkseagrub
fi
}
@@ -444,9 +353,7 @@ add_grub()
{
# path in CBFS for the GRUB payload
_grubname="img/grub2"
if [ "$payload_grubsea" = "y" ]; then
_grubname="fallback/payload"
fi
@@ -458,9 +365,7 @@ add_grub()
cbfs "$tmprom" "$xbtmp/tmpcfg" scan.cfg raw
if [ "$initmode" != "normal" ] && \
[ "$displaymode" != "txtmode" ]; then
if [ "$initmode" != "normal" ] && [ "$displaymode" != "txtmode" ]; then
cbfs "$tmprom" "$grubdata/background/background1280x800.png" \
"background.png" raw
fi
@@ -469,10 +374,8 @@ add_grub()
mkseagrub()
{
if [ "$payload_grubsea" = "y" ]; then
pname="grub"
else
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
fi
@@ -482,13 +385,10 @@ mkseagrub()
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
@@ -506,22 +406,17 @@ add_uboot()
# 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"
if [ "$payload_uboot" = "i386" ]
then
ubpath="u-boot" # 32-bit
ubtree="x86"
ubtarget="i386coreboot"; :
fi
@@ -530,29 +425,20 @@ add_uboot()
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
}
@@ -567,13 +453,9 @@ cprom()
newrom="bin/$target/${pname}_${target}_$initmode.rom"
if [ -n "$displaymode" ]; then
newrom="${newrom%.rom}_$displaymode.rom"
fi
if [ $# -gt 0 ] && \
[ "${1%.gkb}" != "$1" ]; then
if [ $# -gt 0 ] && [ "${1%.gkb}" != "$1" ]; then
tmpnew="${1##*/}"
newrom="${newrom%.rom}_${tmpnew%.gkb}.rom"
fi
@@ -581,18 +463,14 @@ cprom()
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
@@ -600,7 +478,6 @@ cprom()
printf "Creating new %s image: '%s'\n" "$projectname" "$newrom"
x_ xbmkdir "bin/$target"
x_ $cpcmd "$irom" "$newrom"
}
@@ -609,15 +486,10 @@ cbfs()
ccmd="add-payload"
lzma="-c lzma"
if [ $# -gt 3 ] && \
[ $# -lt 5 ]; then
if [ $# -gt 3 ] && [ $# -lt 5 ]; then
ccmd="add"
lzma="-t $4"
elif [ $# -gt 4 ] && \
[ "$5" = "0x1110000" ]; then
elif [ $# -gt 4 ] && [ "$5" = "0x1110000" ]; then
ccmd="add-flat-binary" && \
lzma="-c lzma -l 0x1110000 -e 0x1110000"
fi
@@ -632,14 +504,11 @@ mkcoreboottar()
$if_dry_build \
return 0
if [ "$target" = "$tree" ] || \
[ "$XBMK_RELEASE" != "y" ] || \
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
}
+33 -190
View File
@@ -57,10 +57,9 @@ trees()
{
flags="f:F:b:m:u:c:x:s:l:n:d:"
while getopts $flags option; do
while getopts $flags option
do
if [ -n "$flag" ]; then
err "only one flag is permitted" "trees" "$@"
fi
@@ -70,7 +69,6 @@ trees()
# ./mk -m coreboot does: make menuconfig -C src/coreboot/tree
case "$flag" in
-d)
# -d is similar to -b, except that
# a large number of operations will be
@@ -81,20 +79,13 @@ trees()
if_dry_build=""
if_not_dry_build=":"
;;
-b) : ;;
-u) mode="oldconfig" ;;
-m) mode="menuconfig" ;;
-c) mode="distclean" ;;
-x) mode="crossgcc-clean" ;;
-f|-F) # download source code for a project
# macros. colon means false.
if_do_make=":"
if_dry_build=""
if_not_do_make=""
@@ -105,19 +96,13 @@ trees()
forcepull="y"
fi
;;
-s) mode="savedefconfig" ;;
-l) mode="olddefconfig" ;;
-n) mode="nconfig" ;;
*) err "invalid option '-$option'" "trees" "$@" ;;
esac
if [ -z "${OPTARG+x}" ]; then
shift 1
break
@@ -130,17 +115,13 @@ trees()
done
if [ -z "$flag" ]; then
err "missing flag ($flags)" "trees" "$@"
elif [ -z "$project" ]; then
fx_ "x_ ./mk $flag" x_ ls -1 config/git
return 1
elif [ ! -f "config/git/$project/pkg.cfg" ]; then
err "config/git/$project/pkg.cfg missing" "trees" "$@"
fi
@@ -151,26 +132,19 @@ trees()
dest_dir="$elfdir"
listfile="$datadir/build.list"
if [ ! -f "$listfile" ]; then
listfile="" # build.list is optional on all projects
fi
mkhelpercfg="$datadir/mkhelper.cfg"
if e "$mkhelpercfg" f missing; then
mkhelpercfg="$xbtmp/mkhelper.cfg"
x_ touch "$mkhelpercfg"
fi
targets="$*"
cmd="build_targets $targets"
if singletree "$project"; then
cmd="build_project"
fi
@@ -180,29 +154,22 @@ trees()
build_project()
{
if ! configure_project "$configdir"; then
return 0
elif [ -f "$listfile" ]; then
if ! $if_not_dry_build elfcheck; then
return 0
fi
fi
if [ "$mode" = "distclean" ]; then
mode="clean"
fi
if ! run_make_command; then
return 0
fi
if [ -z "$mode" ]; then
$if_not_dry_build \
copy_elf; :
fi
@@ -211,22 +178,18 @@ build_project()
build_targets()
{
if [ ! -d "$configdir" ]; then
err "directory '$configdir' doesn't exist" "build_targets" "$@"
elif [ $# -lt 1 ]; then
targets="$(ls -1 "$configdir")" || \
err "'$configdir': can't list targets" "build_targets" "$@"
fi
for x in $targets; do
for x in $targets
do
unset CROSS_COMPILE
export PATH="$xbmkpath"
if [ "$x" = "list" ]; then
x_ ls -1 "config/$project"
listfile=""
@@ -241,7 +204,6 @@ build_targets()
x_ handle_defconfig
if [ -z "$mode" ]; then
x_ $postmake
fi
done; :
@@ -252,54 +214,39 @@ handle_defconfig()
target_dir="$configdir/$target"
if [ ! -f "CHANGELOG" ]; then
fetch_project "$project"
fi
if ! configure_project "$target_dir"; then
return 0
fi
if [ -z "$tree" ]; then
err "$configdir: 'tree' not set" "handle_defconfig" "$@"
fi
srcdir="src/$project/$tree"
if [ "$mode" = "${mode%clean}" ] && \
[ ! -d "$srcdir" ]; then
if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]; then
return 0
fi
for y in "$target_dir/config"/*; do
if [ "$flag" != "-d" ] && \
[ ! -f "$y" ]; then
for y in "$target_dir/config"/*
do
if [ "$flag" != "-d" ] && [ ! -f "$y" ]; then
continue
elif [ "$flag" != "-d" ]; then
defconfig="$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; :
@@ -308,7 +255,6 @@ handle_defconfig()
handle_makefile
if [ -z "$mode" ]; then
$if_not_dry_build \
copy_elf
fi
@@ -317,7 +263,7 @@ handle_defconfig()
configure_project()
{
tcfg="$1/target.cfg"
_tcfg="$1/target.cfg"
autoconfargs=""
badhash=""
@@ -335,15 +281,13 @@ configure_project()
xgcctree=""
xlang=""
if [ ! -f "$tcfg" ]; then
if [ ! -f "$_tcfg" ]; then
buildtype="auto"
fi
# globally initialise all variables for a source tree / target:
if e "$datadir/mkhelper.cfg" f; then
. "$datadir/mkhelper.cfg" || \
err "Can't read '$datadir/mkhelper.cfg'" \
"configure_project" "$@"
@@ -351,9 +295,8 @@ configure_project()
# override target/tree specific variables from per-target config:
while e "$tcfg" f || \
[ "$cmd" != "build_project" ]; do
while e "$_tcfg" f || [ "$cmd" != "build_project" ]
do
# TODO: implement infinite loop detection here, caused
# by project targets pointing to other targets/trees
# when then ultimate point back repeatedly; this is
@@ -361,78 +304,59 @@ configure_project()
# temporary files per tree/target name could be created
# per iteration, and then checked the next time
printf "Loading %s config: %s\n" "$project" "$tcfg"
printf "Loading %s config: %s\n" "$project" "$_tcfg"
rev=""
tree=""
. "$tcfg" || \
err "Can't read '$tcfg'" "configure_project" "$@"
. "$_tcfg" || \
err "Can't read '$_tcfg'" "configure_project" "$@"
if [ "$flag" = "-d" ]; then
build_depend="" # dry run
fi
if [ "$cmd" = "build_project" ]; then
# single-tree, so it can't be a target pointing
# to a main source tree
break
fi
$if_do_make \
break
if [ "${tcfg%/*/target.cfg}" = "${tcfg%"/$tree/target.cfg"}" ]
if [ "${_tcfg%/*/target.cfg}" = "${_tcfg%"/$tree/target.cfg"}" ]
then
# we have found the main source tree that
# a given target uses; no need to continue
break
else
tcfg="${tcfg%/*/target.cfg}/$tree/target.cfg"
_tcfg="${_tcfg%/*/target.cfg}/$tree/target.cfg"
fi
done
if [ "$XBMK_RELEASE" = "y" ] && \
[ "$release" = "n" ]; then
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 1
fi
if [ -n "$buildtype" ] && \
[ "${mode%config}" != "$mode" ]; then
if [ -n "$buildtype" ] && [ "${mode%config}" != "$mode" ]; then
return 1
fi
if [ -z "$mode" ]; then
$if_not_dry_build \
build_dependencies
fi
mdir="$xbmkpwd/config/submodule/$project"
if [ -n "$tree" ]; then
mdir="$mdir/$tree"
fi
if [ ! -f "CHANGELOG" ]; then
delete_old_project_files
$if_not_do_make \
fetch_${cmd#build_}
fi
$if_not_do_make \
return 1
@@ -444,25 +368,20 @@ configure_project()
build_dependencies()
{
for bd in $build_depend; do
for bd in $build_depend
do
bd_project="${bd%%/*}"
bd_tree="${bd##*/}"
if [ -z "$bd_project" ]; then
$if_not_dry_build \
err "$project/$tree: !bd '$bd'" \
"build_dependencies" "$@"
fi
if [ "${bd##*/}" = "$bd" ]; then
bd_tree=""
fi
if [ -n "$bd_project" ]; then
$if_not_dry_build \
x_ ./mk -b $bd_project $bd_tree; :
fi
@@ -482,16 +401,13 @@ delete_old_project_files()
# delete an entire source tree along with its builds:
if ! project_up_to_date hash "$tree" badhash "$datadir" \
"$configdir/$tree" "$mdir"; then
x_ rm -Rf "src/$project/$tree" "elf/$project/$tree"
fi
x_ cp "$xbtmp/new.hash" "$XBMK_CACHE/hash/$project$tree"
if singletree "$project" || \
[ -z "$target" ] || \
[ "$target" = "$tree" ]; then
if singletree "$project" || [ -z "$target" ] || [ "$target" = "$tree" ]
then
return 0
fi
@@ -501,7 +417,6 @@ delete_old_project_files()
if ! project_up_to_date tghash "$target" badtghash "$configdir/$target"
then
x_ rm -Rf "elf/$project/$tree/$target"
fi
@@ -522,7 +437,6 @@ project_up_to_date()
x_ xbmkdir "$XBMK_CACHE/$hashdir"
if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
read -r old_hash < "$XBMK_CACHE/$hashdir/$project$hashname" \
|| err \
"$hashdir: err '$XBMK_CACHE/$hashdir/$project$hashname'" \
@@ -531,7 +445,6 @@ project_up_to_date()
fi
build_sbase
fx_ "x_ util/sbase/sha512sum" find "$@" -type f -not -path \
"*/.git*/*" | awk '{print $1}' > "$xbtmp/tmp.hash" || \
err "!h $project $hashdir" \
@@ -543,7 +456,6 @@ project_up_to_date()
if [ "$hash" != "$old_hash" ] || \
[ ! -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
eval "$badhashvar=\"y\""
fi
@@ -559,19 +471,15 @@ check_cross_compiler()
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
@@ -579,55 +487,39 @@ check_cross_compiler()
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
@@ -639,11 +531,8 @@ check_gnu_path()
gnatver=""
if host_gcc_gnat_match "$@"; then
return 0
elif ! match_gcc_gnat_versions "$@"; then
return 1
fi
}
@@ -653,47 +542,39 @@ check_gnu_path()
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
# non-matching gcc/gnat versions
return 1
fi
}
# find all host gcc/gnat versions, matching them up in PATH:
# find all 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
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
@@ -712,12 +593,10 @@ link_gcc_gnat_versions()
x_ cd "$xbtmp/gnupath"
for _gnubin in "$_gnudir/$2"*"-$_gnuver"; do
for _gnubin in "$_gnudir/$2"*"-$_gnuver"
do
_gnuutil="${_gnubin##*/}"
if [ -e "$_gnubin" ]; then
x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
fi
done
@@ -738,7 +617,6 @@ gnu_setver()
check_defconfig()
{
if [ ! -f "$defconfig" ]; then
$if_not_dry_build \
err "$project/$target: no config" "check_defconfig" "$@"
fi
@@ -749,9 +627,7 @@ check_defconfig()
$if_dry_build \
return 0
if ! elfcheck; then
return 1
fi
}
@@ -760,23 +636,17 @@ elfcheck()
{
# TODO: *STILL* very hacky check. do it properly (based on build.list)
# extremely hacky check that glues the entire universe together
# beware demons
( fx_ "eval exit 1 && err" find "$dest_dir" -type f ) || return 1; :
}
handle_makefile()
{
if $if_not_dry_build check_makefile "$srcdir"; then
$if_not_dry_build \
x_ make -C "$srcdir" $cleanargs clean
fi
if [ -f "$defconfig" ]; then
x_ cp "$defconfig" "$srcdir/.config"
fi
@@ -786,20 +656,16 @@ 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" ] && \
if [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ]; then
$if_not_dry_build \
x_ git -C "$srcdir" $cleanargs clean -fdx; :
fi
@@ -812,16 +678,12 @@ run_make_command()
fi
if $if_not_dry_build check_cmake "$srcdir"; then
if [ -z "$mode" ]; then
$if_not_dry_build \
check_autoconf "$srcdir"
fi
fi
if ! $if_not_dry_build check_makefile "$srcdir"; then
return 1
fi
@@ -829,22 +691,17 @@ run_make_command()
x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs
if [ -z "$mode" ]; then
x_ $mkhelper
fi
if ! check_makefile "$srcdir"; then
return 0
fi
if [ "$mode" = "clean" ]; then
$if_dry_build \
return 0
if ! make -C "$srcdir" $cleanargs distclean; then
x_ make -C "$srcdir" $cleanargs clean
fi
fi
@@ -854,18 +711,13 @@ check_cmake()
{
$if_dry_build \
return 0
if [ ! -n "$cmakedir" ]; then
return 0
elif ! check_makefile "$1"; then
if ! cmake -B "$1" "$1/$cmakedir"; then
x_ check_makefile "$1"
fi
fi
x_ check_makefile "$1"; :
}
@@ -875,17 +727,12 @@ check_autoconf()
x_ cd "$1"
if [ -f "bootstrap" ]; then
x_ ./bootstrap $bootstrapargs
fi
if [ -f "autogen.sh" ]; then
x_ ./autogen.sh $autogenargs
fi
if [ -f "configure" ]; then
x_ ./configure $autoconfargs; :
fi
@@ -894,8 +741,7 @@ check_autoconf()
check_makefile()
{
if [ ! -f "$1/Makefile" ] && \
[ ! -f "$1/makefile" ] && \
if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \
[ ! -f "$1/GNUmakefile" ]; then
return 1
@@ -905,16 +751,13 @@ check_makefile()
copy_elf()
{
if [ -f "$listfile" ]; then
x_ xbmkdir "$dest_dir"
fi
if [ -f "$listfile" ]; then
while read -r f; do
while read -r f
do
if [ -f "$srcdir/$f" ]; then
x_ cp "$srcdir/$f" "$dest_dir"
fi
+22 -202
View File
@@ -101,7 +101,6 @@ XBMKmecleaner=""
download()
{
if [ $# -lt 1 ]; then
err "No argument given" "download" "$@"
fi
@@ -109,7 +108,6 @@ download()
board="$1"
if check_target; then
readkconfig download
fi
}
@@ -117,63 +115,44 @@ download()
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
@@ -191,7 +170,6 @@ fetch()
binsum="$7"
if [ -z "$binsum" ]; then
err "binsum is empty (no checksum)" "fetch" "$@"
fi
@@ -199,29 +177,23 @@ fetch()
_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:
# 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
# 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
@@ -229,12 +201,9 @@ fetch()
_cdp="$dl_bkup"
if [ ! -f "$_cdp" ]; then
_cdp="$cbdir/$_cdp"
fi
if [ -f "$_cdp" ]; then
dl_bkup="$_cdp"; :
fi
fi
@@ -247,50 +216,39 @@ fetch()
# 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
@@ -300,11 +258,8 @@ 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"
@@ -315,12 +270,10 @@ mkdst()
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"
@@ -328,26 +281,17 @@ extract_intel_me()
x_ rm -Rf "$_7ztest"
# maintain compatibility with older configs
# because in the past, shrink was assumed:
# because in the past, shrink was assumed
if [ -z "$MEshrink" ]; then
MEshrink="y"
fi
if [ "$MEshrink" != "y" ] && \
[ "$MEshrink" != "n" ]; then
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
if [ -z "$ME11delta" ] || [ -z "$ME11version" ] || \
[ -z "$ME11sku" ] || [ -z "$ME11pch" ]; then
err "$board: ME11delta/ME11version/ME11sku/ME11pch" \
"extract_intel_me" "$@"
fi
@@ -362,11 +306,8 @@ extract_intel_me()
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
@@ -377,13 +318,10 @@ 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
fi
@@ -395,21 +333,15 @@ find_me()
_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
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
@@ -418,57 +350,38 @@ find_me()
_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
-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" \
|| \
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
}
@@ -485,32 +398,20 @@ apply_deguard_hack()
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
}
@@ -532,33 +433,22 @@ 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
}
@@ -567,9 +457,7 @@ extract_e6400vga()
{
set +u +e
if [ -z "$E6400_VGA_offset" ] || \
[ -z "$E6400_VGA_romname" ]; then
if [ -z "$E6400_VGA_offset" ] || [ -z "$E6400_VGA_romname" ]; then
err "$board: E6400_VGA_romname/E6400_VGA_offset unset" \
"extract_e6400vga" "$@"
fi
@@ -577,12 +465,9 @@ extract_e6400vga()
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"
@@ -599,7 +484,6 @@ extract_sch5545ec()
_sch5545ec_fw="$_sch5545ec_fw/0 Raw section/body.bin" # <-- this!
x_ "$uefiextract" "$_bios"
x_ cp "$_sch5545ec_fw" "$_pre_dest"
}
@@ -608,7 +492,6 @@ extract_sch5545ec()
extract_tbfw()
{
if [ -z "$TBFW_size" ]; then
err "$board: TBFW_size unset" "extract_tbfw" "$@"
fi
@@ -617,9 +500,7 @@ extract_tbfw()
copytb()
{
if [ -f "$1" ] && \
[ ! -L "$1" ]; then
if [ -f "$1" ] && [ ! -L "$1" ]; then
x_ dd if=/dev/null of="$1" bs=1 seek=$TBFW_size
x_ mv "$1" "$_pre_dest"
@@ -635,29 +516,24 @@ extract_fsp()
setvfile()
{
[ -n "$vcfg" ] && for c in $checkvarschk; do
[ -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
@@ -667,16 +543,13 @@ 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
@@ -691,9 +564,7 @@ bootstrap()
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
@@ -706,12 +577,10 @@ bootstrap()
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
@@ -724,23 +593,20 @@ prep()
_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
if [ "${_xromname#"$vfix"}" != "$_xromname" ] \
&& [ "$nuke" != "nuke" ]; then
unpad_one_byte "$_xrom"
x_ mv "$_xrom" "$_xromnew"
@@ -749,12 +615,10 @@ prep()
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
@@ -762,9 +626,7 @@ prep()
fi
if [ "$nuke" = "nuke" ]; then
pad_one_byte "$_xrom"
x_ mv "$_xrom" "$_xromnew"
fi
}
@@ -774,7 +636,6 @@ mksha512()
build_sbase
if [ "${1%/*}" != "$1" ]; then
x_ cd "${1%/*}"
fi
@@ -787,68 +648,46 @@ 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" ] && \
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" ] && \
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
@@ -860,7 +699,6 @@ add_vfiles()
vfile()
{
if [ "$2" = "/dev/null" ]; then
return 0
fi
@@ -870,50 +708,34 @@ vfile()
_offset=""
if [ "$blobtype" = "fsp" ] && \
[ $# -gt 3 ]; then
if [ "$blobtype" = "fsp" ] && [ $# -gt 3 ]; then
_offset="$4"
elif [ $# -gt 3 ] && \
_offset="-b $4" && [ -z "$4" ]; then
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
@@ -928,9 +750,7 @@ check_vendor_hashes()
x_ cd "$tmpromdir"
if [ "$has_hashes" != "n" ] && \
[ "$nuke" != "nuke" ]; then
if [ "$has_hashes" != "n" ] && [ "$nuke" != "nuke" ]; then
( x_ "$sha512sum" -c "$hashfile" ) || \
x_ sha1sum -c "$hashfile"
fi
+1 -11
View File
@@ -10,15 +10,12 @@ set -u -e
ispwd="true"
if [ "$0" != "./mk" ]; then
ispwd="false"
fi
if [ "$ispwd" = "true" ] && [ -L "mk" ]; then
ispwd="false"
fi
if [ "$ispwd" = "false" ]; then
printf "You must run this in the proper work directory.\n" 1>&2
exit 1
fi
@@ -37,29 +34,22 @@ main()
{
cmd=""
if [ $# -gt 0 ]; then
cmd="$1"
shift 1
fi
case "$cmd" in
version)
printf "%s\nWebsite: %s\n" "$relname" "$projectsite"
;;
release|download|inject|prep_mr_import)
$cmd "$@"
;;
-*)
return 0
;;
*)
err "bad command" main "$@"
;;
esac