safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in the $PATH will override that program. for example, you could make a function called ls() and this would override the standand "ls". in lbmk, a part of it was first trying to run the "fail" command, deferring to "err", because some scripts call fail() which does some minor cleanup before calling err. in most cases, fail() is not defined, and it's possible that the user could have a program called "fail" in their $PATH, the behaviour of which we could not determine, and it could have disastrous effects. lbmk error handling has been re-engineered in such a way that the err function is defined in a variable, which defaults to err_ which calls err_, so defined under include/err.sh. in functions that require cleanup prior to error handling, a fail() function is still defined, and err is overridden, thus: err="fail" this change has made xx_() obsolete, so now only x_ is used. the x_ function is a wrapper that can be used to run a command and exit with non-zero status (from lbmk) if the command fails. the xx_ command did the same thing, but called fail() which would have called err(); now everything is $err example: rm -f "$filename" || err "could not delete file" this would now be: rm -f "$filename" || $err "could not delete file" overriding of err= must be done *after* including err.sh. for example: err="fail" . "include/err.sh" ^ this is wrong. instead, one must do: . "include/err.sh" err="fail" this is because err is set as a global variable under err.sh the new error handling is much cleaner, and safer. it also reduces the chance of mistakes such as: calling err when you meant to call fail. this is because the standard way is now to call $err, so you set err="fail" at the top of the script and all is well. Signed-off-by: Leah Rowe <leah@libreboot.org>9020nri
parent
6b11f1b055
commit
6ebab10caa
33
build
33
build
|
@ -14,6 +14,7 @@ export LC_ALL=C
|
||||||
. "include/option.sh"
|
. "include/option.sh"
|
||||||
|
|
||||||
eval "$(setvars "" option aur_notice tmpdir)"
|
eval "$(setvars "" option aur_notice tmpdir)"
|
||||||
|
err="fail"
|
||||||
|
|
||||||
tmpdir_was_set="y"
|
tmpdir_was_set="y"
|
||||||
set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n"
|
set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n"
|
||||||
|
@ -35,10 +36,10 @@ buildpath="./script/${linkname}"
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
xx_ id -u 1>/dev/null 2>/dev/null
|
x_ id -u 1>/dev/null 2>/dev/null
|
||||||
[ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help"
|
[ $# -lt 1 ] && $err "Too few arguments. Try: ${0} help"
|
||||||
|
|
||||||
[ "$1" = "dependencies" ] && xx_ install_packages $@ && lbmk_exit 0
|
[ "$1" = "dependencies" ] && x_ install_packages $@ && lbmk_exit 0
|
||||||
|
|
||||||
for cmd in initcmd check_git check_project git_init excmd; do
|
for cmd in initcmd check_git check_project git_init excmd; do
|
||||||
eval "${cmd} \$@"
|
eval "${cmd} \$@"
|
||||||
|
@ -48,7 +49,7 @@ main()
|
||||||
|
|
||||||
initcmd()
|
initcmd()
|
||||||
{
|
{
|
||||||
[ "$(id -u)" != "0" ] || fail "this command as root is not permitted"
|
[ "$(id -u)" != "0" ] || $err "this command as root is not permitted"
|
||||||
|
|
||||||
check_project
|
check_project
|
||||||
|
|
||||||
|
@ -69,14 +70,14 @@ install_packages()
|
||||||
printf "You must specify a distro, namely:\n" 1>&2
|
printf "You must specify a distro, namely:\n" 1>&2
|
||||||
printf "Look at files under config/dependencies/\n" 1>&2
|
printf "Look at files under config/dependencies/\n" 1>&2
|
||||||
printf "Example: ./build dependencies debian\n" 1>&2
|
printf "Example: ./build dependencies debian\n" 1>&2
|
||||||
fail "install_packages: target not specified"
|
$err "install_packages: target not specified"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -f "config/dependencies/${2}" ] || fail "Unsupported target"
|
[ -f "config/dependencies/${2}" ] || $err "Unsupported target"
|
||||||
|
|
||||||
. "config/dependencies/${2}"
|
. "config/dependencies/${2}"
|
||||||
|
|
||||||
xx_ ${pkg_add} ${pkglist}
|
x_ ${pkg_add} ${pkglist}
|
||||||
[ -z "${aur_notice}" ] && return 0
|
[ -z "${aur_notice}" ] && return 0
|
||||||
printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2
|
printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2
|
||||||
}
|
}
|
||||||
|
@ -85,24 +86,24 @@ install_packages()
|
||||||
# lbmk can be run from lbmk.git, or an archive.
|
# lbmk can be run from lbmk.git, or an archive.
|
||||||
git_init()
|
git_init()
|
||||||
{
|
{
|
||||||
[ -L ".git" ] && fail "Reference .git is a symlink"
|
[ -L ".git" ] && $err "Reference .git is a symlink"
|
||||||
[ -e ".git" ] && return 0
|
[ -e ".git" ] && return 0
|
||||||
eval "$(setvars "$(date -Rd @${versiondate})" cdate _nogit)"
|
eval "$(setvars "$(date -Rd @${versiondate})" cdate _nogit)"
|
||||||
|
|
||||||
git init || fail "${PWD}: cannot initialise Git repository"
|
git init || $err "${PWD}: cannot initialise Git repository"
|
||||||
git add -A . || fail "${PWD}: cannot add files to Git repository"
|
git add -A . || $err "${PWD}: cannot add files to Git repository"
|
||||||
git commit -m "${projectname} ${version}" --date "${cdate}" \
|
git commit -m "${projectname} ${version}" --date "${cdate}" \
|
||||||
--author="lbmk <lbmk@libreboot.org>" || \
|
--author="lbmk <lbmk@libreboot.org>" || \
|
||||||
fail "$PWD: can't commit ${projectname}/${version}, date $cdate"
|
$err "$PWD: can't commit ${projectname}/${version}, date $cdate"
|
||||||
git tag -a "${version}" -m "${projectname} ${version}" || \
|
git tag -a "${version}" -m "${projectname} ${version}" || \
|
||||||
fail "${PWD}: cannot git-tag ${projectname}/${version}"
|
$err "${PWD}: cannot git-tag ${projectname}/${version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
excmd()
|
excmd()
|
||||||
{
|
{
|
||||||
lbmkcmd="${buildpath}/${option}"
|
lbmkcmd="${buildpath}/${option}"
|
||||||
[ -f "${lbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help"
|
[ -f "${lbmkcmd}" ] || $err "Invalid command. Run: ${linkpath} help"
|
||||||
shift 1; "$lbmkcmd" $@ || fail "excmd: ${lbmkcmd} ${@}"
|
shift 1; "$lbmkcmd" $@ || $err "excmd: ${lbmkcmd} ${@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
|
@ -131,14 +132,14 @@ mkversion()
|
||||||
|
|
||||||
lbmk_exit()
|
lbmk_exit()
|
||||||
{
|
{
|
||||||
tmp_cleanup || err "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir"
|
tmp_cleanup || err_ "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir"
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
fail()
|
fail()
|
||||||
{
|
{
|
||||||
tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "$tmpdir" 1>&2
|
tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "$tmpdir" 1>&2
|
||||||
err "${1}"
|
err_ "${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_cleanup()
|
tmp_cleanup()
|
||||||
|
|
|
@ -2,19 +2,10 @@
|
||||||
# SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org>
|
# SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org>
|
||||||
|
|
||||||
version=""; versiondate=""; projectname=""; _nogit=""
|
version=""; versiondate=""; projectname=""; _nogit=""
|
||||||
|
err="err_"
|
||||||
|
|
||||||
x_() {
|
x_() {
|
||||||
[ $# -lt 1 ] || ${@} || err_exit err ${@}
|
[ $# -lt 1 ] || ${@} || $err "Unhandled non-zero exit: $@"; return 0
|
||||||
}
|
|
||||||
xx_() {
|
|
||||||
[ $# -lt 1 ] || ${@} || err_exit fail ${@}
|
|
||||||
}
|
|
||||||
|
|
||||||
err_exit()
|
|
||||||
{
|
|
||||||
_fail="${1}" && shift 1
|
|
||||||
echo "Non-zero exit: $@"
|
|
||||||
$_fail "Unhandled error"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_git()
|
check_git()
|
||||||
|
@ -30,8 +21,7 @@ check_git()
|
||||||
git_err()
|
git_err()
|
||||||
{
|
{
|
||||||
printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2
|
printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2
|
||||||
fail "Git name/email not configured" || \
|
$err "Git name/email not configured"
|
||||||
err "Git name/email not configured"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_project()
|
check_project()
|
||||||
|
@ -49,9 +39,8 @@ check_project()
|
||||||
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
|
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
|
||||||
|
|
||||||
for p in projectname version versiondate; do
|
for p in projectname version versiondate; do
|
||||||
eval "[ -n \"\$$p\" ] || fail \"$p unset\" || err \"$p unset\""
|
eval "[ -n \"\$$p\" ] || $err \"$p unset\""
|
||||||
p_="x_ printf \"%s\\n\" \"\$$p\" > $p"
|
eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
|
||||||
eval "x$p_ || $p_"
|
|
||||||
done
|
done
|
||||||
export LOCALVERSION="-${projectname}-${version%%-*}"
|
export LOCALVERSION="-${projectname}-${version%%-*}"
|
||||||
}
|
}
|
||||||
|
@ -59,7 +48,7 @@ check_project()
|
||||||
setvars()
|
setvars()
|
||||||
{
|
{
|
||||||
_setvars=""
|
_setvars=""
|
||||||
[ $# -lt 2 ] && err "setvars: too few arguments"
|
[ $# -lt 2 ] && $err "setvars: too few arguments"
|
||||||
val="${1}" && shift 1
|
val="${1}" && shift 1
|
||||||
for var in $@; do
|
for var in $@; do
|
||||||
_setvars="${var}=\"${val}\"; ${_setvars}"
|
_setvars="${var}=\"${val}\"; ${_setvars}"
|
||||||
|
@ -67,7 +56,7 @@ setvars()
|
||||||
printf "%s\n" "${_setvars% }"
|
printf "%s\n" "${_setvars% }"
|
||||||
}
|
}
|
||||||
|
|
||||||
err()
|
err_()
|
||||||
{
|
{
|
||||||
printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2
|
printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -29,7 +29,7 @@ fetch_from_upstream()
|
||||||
|
|
||||||
fetch_config()
|
fetch_config()
|
||||||
{
|
{
|
||||||
rm -f "${cfgsdir}/"*/seen || err "fetch_config ${cfgsdir}: !rm seen"
|
rm -f "${cfgsdir}/"*/seen || $err "fetch_config ${cfgsdir}: !rm seen"
|
||||||
eval "$(setvars "" xtree tree_depend)"
|
eval "$(setvars "" xtree tree_depend)"
|
||||||
while true; do
|
while true; do
|
||||||
eval "$(setvars "" rev tree)"
|
eval "$(setvars "" rev tree)"
|
||||||
|
@ -44,12 +44,12 @@ fetch_config()
|
||||||
|
|
||||||
load_target_config()
|
load_target_config()
|
||||||
{
|
{
|
||||||
[ -f "$cfgsdir/$1/target.cfg" ] || err "$1: target.cfg missing"
|
[ -f "$cfgsdir/$1/target.cfg" ] || $err "$1: target.cfg missing"
|
||||||
[ -f "${cfgsdir}/${1}/seen" ] && \
|
[ -f "${cfgsdir}/${1}/seen" ] && \
|
||||||
err "${_xm} check: infinite loop in tree definitions"
|
$err "${_xm} check: infinite loop in tree definitions"
|
||||||
|
|
||||||
. "$cfgsdir/$1/target.cfg" || err "load_target_config !$cfgsdir/$1"
|
. "$cfgsdir/$1/target.cfg" || $err "load_target_config !$cfgsdir/$1"
|
||||||
touch "$cfgsdir/$1/seen" || err "load_config $cfgsdir/$1: !mk seen"
|
touch "$cfgsdir/$1/seen" || $err "load_config $cfgsdir/$1: !mk seen"
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_new_tree()
|
prepare_new_tree()
|
||||||
|
@ -57,7 +57,7 @@ prepare_new_tree()
|
||||||
printf "Creating %s tree %s (%s)\n" "$project" "$tree" "$_target"
|
printf "Creating %s tree %s (%s)\n" "$project" "$tree" "$_target"
|
||||||
|
|
||||||
cp -R "src/${project}/${project}" "${tmpgit}" || \
|
cp -R "src/${project}/${project}" "${tmpgit}" || \
|
||||||
err "prepare_new_tree ${project}/${tree}: can't make tmpclone"
|
$err "prepare_new_tree ${project}/${tree}: can't make tmpclone"
|
||||||
git_prep "$PWD/$cfgsdir/$tree/patches" "src/$project/$tree" "update"
|
git_prep "$PWD/$cfgsdir/$tree/patches" "src/$project/$tree" "update"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,15 +65,15 @@ fetch_project_repo()
|
||||||
{
|
{
|
||||||
eval "$(setvars "" xtree tree_depend)"
|
eval "$(setvars "" xtree tree_depend)"
|
||||||
|
|
||||||
scan_config "${project}" "config/git" "err"
|
scan_config "${project}" "config/git"
|
||||||
[ -z "${loc+x}" ] && err "fetch_project_repo $project: loc not set"
|
[ -z "${loc+x}" ] && $err "fetch_project_repo $project: loc not set"
|
||||||
[ -z "${url+x}" ] && err "fetch_project_repo $project: url not set"
|
[ -z "${url+x}" ] && $err "fetch_project_repo $project: url not set"
|
||||||
|
|
||||||
clone_project
|
clone_project
|
||||||
[ -z "${depend}" ] || for d in ${depend} ; do
|
[ -z "${depend}" ] || for d in ${depend} ; do
|
||||||
x_ ./update trees -f ${d}
|
x_ ./update trees -f ${d}
|
||||||
done
|
done
|
||||||
rm -Rf "${tmpgit}" || err "fetch_repo: !rm -Rf ${tmpgit}"
|
rm -Rf "${tmpgit}" || $err "fetch_repo: !rm -Rf ${tmpgit}"
|
||||||
}
|
}
|
||||||
|
|
||||||
clone_project()
|
clone_project()
|
||||||
|
@ -86,7 +86,7 @@ clone_project()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git clone $url "$tmpgit" || git clone $bkup_url "$tmpgit" \
|
git clone $url "$tmpgit" || git clone $bkup_url "$tmpgit" \
|
||||||
|| err "clone_project: could not download ${project}"
|
|| $err "clone_project: could not download ${project}"
|
||||||
git_prep "$PWD/config/$project/patches" "$loc"
|
git_prep "$PWD/config/$project/patches" "$loc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,26 +95,26 @@ git_prep()
|
||||||
_patchdir="$1"
|
_patchdir="$1"
|
||||||
_loc="$2"
|
_loc="$2"
|
||||||
|
|
||||||
[ -z "${rev+x}" ] && err "git_prep $_loc: rev not set"
|
[ -z "${rev+x}" ] && $err "git_prep $_loc: rev not set"
|
||||||
git -C "$tmpgit" reset --hard $rev || err "git -C $_loc: !reset $rev"
|
git -C "$tmpgit" reset --hard $rev || $err "git -C $_loc: !reset $rev"
|
||||||
git_am_patches "$tmpgit" "$_patchdir" || err "!am $_loc $_patchdir"
|
git_am_patches "$tmpgit" "$_patchdir" || $err "!am $_loc $_patchdir"
|
||||||
|
|
||||||
if [ "$project" != "coreboot" ] || [ $# -gt 2 ]; then
|
if [ "$project" != "coreboot" ] || [ $# -gt 2 ]; then
|
||||||
[ ! -f "$tmpgit/.gitmodules" ] || git -C "$tmpgit" submodule \
|
[ ! -f "$tmpgit/.gitmodules" ] || git -C "$tmpgit" submodule \
|
||||||
update --init --checkout || err "git_prep $_loc: !submod"
|
update --init --checkout || $err "git_prep $_loc: !submod"
|
||||||
if [ "$project" = "coreboot" ] && [ -n "$xtree" ] && \
|
if [ "$project" = "coreboot" ] && [ -n "$xtree" ] && \
|
||||||
[ "$xtree" != "$tree" ]; then
|
[ "$xtree" != "$tree" ]; then
|
||||||
(
|
(
|
||||||
cd "$tmpgit/util" || err "prep $_loc: !cd $tmpgit/util"
|
cd "$tmpgit/util" || $err "prep $_loc: !cd $tmpgit/util"
|
||||||
rm -Rf crossgcc || err "prep $_loc: !rm xgcc"
|
rm -Rf crossgcc || $err "prep $_loc: !rm xgcc"
|
||||||
ln -s "../../$xtree/util/crossgcc" crossgcc || \
|
ln -s "../../$xtree/util/crossgcc" crossgcc || \
|
||||||
err "prep $_loc: can't create xgcc symlink"
|
$err "prep $_loc: can't create xgcc symlink"
|
||||||
) || err "prep $_loc: can't create xgcc symlink"
|
) || $err "prep $_loc: can't create xgcc symlink"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}"
|
[ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}"
|
||||||
mv "$tmpgit" "$_loc" || err "git_prep: !mv $tmpgit $_loc"
|
mv "$tmpgit" "$_loc" || $err "git_prep: !mv $tmpgit $_loc"
|
||||||
[ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \
|
[ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \
|
||||||
x_ ./update project trees -f coreboot "$xtree"; return 0
|
x_ ./update project trees -f coreboot "$xtree"; return 0
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ git_am_patches()
|
||||||
{
|
{
|
||||||
for _patch in "$2/"*; do
|
for _patch in "$2/"*; do
|
||||||
[ -L "$_patch" ] || [ ! -f "$_patch" ] || git -C "$1" am \
|
[ -L "$_patch" ] || [ ! -f "$_patch" ] || git -C "$1" am \
|
||||||
"$_patch" || err "git_am $1 $2: !git am $_patch"; continue
|
"$_patch" || $err "git_am $1 $2: !git am $_patch"; continue
|
||||||
done
|
done
|
||||||
for _patches in "$2/"*; do
|
for _patches in "$2/"*; do
|
||||||
[ ! -L "$_patches" ] && [ -d "$_patches" ] && \
|
[ ! -L "$_patches" ] && [ -d "$_patches" ] && \
|
||||||
|
|
|
@ -14,7 +14,7 @@ extract_ref()
|
||||||
# but refcode is downloaded alongside mrc. in cases where lbmk
|
# but refcode is downloaded alongside mrc. in cases where lbmk
|
||||||
# erred, downloading only mrc, we must ensure downloading refcode
|
# erred, downloading only mrc, we must ensure downloading refcode
|
||||||
[ -n "$CONFIG_MRC_FILE" ] || \
|
[ -n "$CONFIG_MRC_FILE" ] || \
|
||||||
err "extract_ref $board: CONFIG_MRC_FILE not defined"
|
$err "extract_ref $board: CONFIG_MRC_FILE not defined"
|
||||||
|
|
||||||
# the extract_mrc function actually downloads the refcode
|
# the extract_mrc function actually downloads the refcode
|
||||||
fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE"
|
fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE"
|
||||||
|
@ -22,9 +22,9 @@ extract_ref()
|
||||||
|
|
||||||
extract_mrc()
|
extract_mrc()
|
||||||
{
|
{
|
||||||
[ -z "$MRC_board" ] && err "extract_mrc $MRC_hash: MRC_board not set"
|
[ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set"
|
||||||
[ -z "${CONFIG_MRC_FILE}" ] && \
|
[ -z "${CONFIG_MRC_FILE}" ] && \
|
||||||
err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set"
|
$err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set"
|
||||||
|
|
||||||
SHELLBALL="chromeos-firmwareupdate-${MRC_board}"
|
SHELLBALL="chromeos-firmwareupdate-${MRC_board}"
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ extract_mrc()
|
||||||
x_ cd "${appdir}"
|
x_ cd "${appdir}"
|
||||||
extract_partition "${MRC_url##*/}"
|
extract_partition "${MRC_url##*/}"
|
||||||
extract_archive "${SHELLBALL}" .
|
extract_archive "${SHELLBALL}" .
|
||||||
) || err "mrc download/extract failure"
|
) || $err "mrc download/extract failure"
|
||||||
|
|
||||||
"${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \
|
"${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \
|
||||||
-f "$_dest" -r RO_SECTION || err "extract_mrc: cbfstool $_dest"
|
-f "$_dest" -r RO_SECTION || $err "extract_mrc: cbfstool $_dest"
|
||||||
|
|
||||||
[ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0
|
[ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,10 @@ extract_partition()
|
||||||
|
|
||||||
dd if="${1%.zip}" of="root-a.ext2" bs=1024 \
|
dd if="${1%.zip}" of="root-a.ext2" bs=1024 \
|
||||||
skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \
|
skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \
|
||||||
err "extract_partition, dd ${1%.zip}, root-a.ext2"
|
$err "extract_partition, dd ${1%.zip}, root-a.ext2"
|
||||||
|
|
||||||
printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \
|
printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \
|
||||||
| debugfs "root-a.ext2" || err "can't extract shellball"
|
| debugfs "root-a.ext2" || $err "can't extract shellball"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_refcode()
|
extract_refcode()
|
||||||
|
@ -66,16 +66,16 @@ extract_refcode()
|
||||||
# incompatible with older versions before coreboot 4.14,
|
# incompatible with older versions before coreboot 4.14,
|
||||||
# so we need coreboot 4.13 cbfstool for certain refcode files
|
# so we need coreboot 4.13 cbfstool for certain refcode files
|
||||||
[ -n "$cbfstoolref" ] || \
|
[ -n "$cbfstoolref" ] || \
|
||||||
err "extract_refcode $board: MRC_refcode_cbtree not set"
|
$err "extract_refcode $board: MRC_refcode_cbtree not set"
|
||||||
mkdir -p "${_refdest%/*}" || \
|
mkdir -p "${_refdest%/*}" || \
|
||||||
err "extract_refcode $board: !mkdir -p ${_refdest%/*}"
|
$err "extract_refcode $board: !mkdir -p ${_refdest%/*}"
|
||||||
|
|
||||||
"$cbfstoolref" "$appdir/bios.bin" extract \
|
"$cbfstoolref" "$appdir/bios.bin" extract \
|
||||||
-m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \
|
-m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \
|
||||||
|| err "extract_refcode $board: !cbfstoolref $_refdest"
|
|| $err "extract_refcode $board: !cbfstoolref $_refdest"
|
||||||
|
|
||||||
# enable the Intel GbE device, if told by offset MRC_refcode_gbe
|
# enable the Intel GbE device, if told by offset MRC_refcode_gbe
|
||||||
[ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \
|
[ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \
|
||||||
of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \
|
of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \
|
||||||
err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0
|
$err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,9 @@ scan_config()
|
||||||
{
|
{
|
||||||
awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
|
awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
|
||||||
confdir="${2}"
|
confdir="${2}"
|
||||||
_fail="${3}"
|
|
||||||
revfile="$(mktemp -t sources.XXXXXXXXXX)"
|
revfile="$(mktemp -t sources.XXXXXXXXXX)"
|
||||||
cat "${confdir}/"* > "${revfile}" || \
|
cat "${confdir}/"* > "${revfile}" || \
|
||||||
"${_fail}" "scan_config ${confdir}: Cannot concatenate files"
|
$err "scan_config ${confdir}: Cannot concatenate files"
|
||||||
while read -r line ; do
|
while read -r line ; do
|
||||||
set ${line} 1>/dev/null 2>/dev/null || :
|
set ${line} 1>/dev/null 2>/dev/null || :
|
||||||
if [ "${1%:}" = "depend" ]; then
|
if [ "${1%:}" = "depend" ]; then
|
||||||
|
@ -57,7 +56,7 @@ scan_config()
|
||||||
done << EOF
|
done << EOF
|
||||||
$(eval "awk '${awkstr}' \"${revfile}\"")
|
$(eval "awk '${awkstr}' \"${revfile}\"")
|
||||||
EOF
|
EOF
|
||||||
rm -f "$revfile" || "$_fail" "scan_config: Cannot remove tmpfile"
|
rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_defconfig()
|
check_defconfig()
|
||||||
|
@ -81,6 +80,6 @@ handle_coreboot_utils()
|
||||||
|
|
||||||
remkdir()
|
remkdir()
|
||||||
{
|
{
|
||||||
rm -Rf "${1}" || err "remkdir: !rm -Rf \"${1}\""
|
rm -Rf "${1}" || $err "remkdir: !rm -Rf \"${1}\""
|
||||||
mkdir -p "${1}" || err "remkdir: !mkdir -p \"${1}\""
|
mkdir -p "${1}" || $err "remkdir: !mkdir -p \"${1}\""
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ main()
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "${all}" != "y" ] || boards=$(items config/coreboot) || \
|
[ "${all}" != "y" ] || boards=$(items config/coreboot) || \
|
||||||
err "Cannot generate list of boards for building"
|
$err "Cannot generate list of boards for building"
|
||||||
|
|
||||||
for x in ${boards}; do
|
for x in ${boards}; do
|
||||||
eval "$(setvars "n" ${pv}) $(setvars "" ${v})"
|
eval "$(setvars "n" ${pv}) $(setvars "" ${v})"
|
||||||
|
@ -62,7 +62,7 @@ main()
|
||||||
targets="* bin/${board}\n${targets}"
|
targets="* bin/${board}\n${targets}"
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -z "${targets}" ] && err "No ROM images were compiled"
|
[ -z "${targets}" ] && $err "No ROM images were compiled"
|
||||||
printf "\nROM images available in these directories:\n"
|
printf "\nROM images available in these directories:\n"
|
||||||
eval "printf \"${targets}\""
|
eval "printf \"${targets}\""
|
||||||
printf "^^ ROM images available in these directories.\n\n"
|
printf "^^ ROM images available in these directories.\n\n"
|
||||||
|
@ -74,7 +74,7 @@ configure_target()
|
||||||
{
|
{
|
||||||
targetdir="${cfgsdir}/${board}"
|
targetdir="${cfgsdir}/${board}"
|
||||||
[ -f "${targetdir}/target.cfg" ] || \
|
[ -f "${targetdir}/target.cfg" ] || \
|
||||||
err "Missing target.cfg for target: ${board}"
|
$err "Missing target.cfg for target: ${board}"
|
||||||
|
|
||||||
# Override the above defaults using target.cfg
|
# Override the above defaults using target.cfg
|
||||||
. "${targetdir}/target.cfg"
|
. "${targetdir}/target.cfg"
|
||||||
|
@ -84,7 +84,7 @@ configure_target()
|
||||||
&& [ "${grub_scan_disk}" != "ahci" ] && \
|
&& [ "${grub_scan_disk}" != "ahci" ] && \
|
||||||
grub_scan_disk="both"
|
grub_scan_disk="both"
|
||||||
|
|
||||||
[ -z "$tree" ] && err "$board: tree not defined"
|
[ -z "$tree" ] && $err "$board: tree not defined"
|
||||||
|
|
||||||
[ "${payload_memtest}" != "y" ] && payload_memtest="n"
|
[ "${payload_memtest}" != "y" ] && payload_memtest="n"
|
||||||
[ "${payload_grub_withseabios}" = "y" ] && payload_grub="y"
|
[ "${payload_grub_withseabios}" = "y" ] && payload_grub="y"
|
||||||
|
@ -101,7 +101,7 @@ configure_target()
|
||||||
[ "${payload_uboot}" != "y" ] && \
|
[ "${payload_uboot}" != "y" ] && \
|
||||||
for configfile in "${targetdir}/config/"*; do
|
for configfile in "${targetdir}/config/"*; do
|
||||||
[ -e "${configfile}" ] || continue
|
[ -e "${configfile}" ] || continue
|
||||||
err "target '${board}' defines no payload"
|
$err "target '${board}' defines no payload"
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$payload_uboot" != "n" ] && [ "$payload_uboot" != "y" ] && \
|
[ "$payload_uboot" != "n" ] && [ "$payload_uboot" != "y" ] && \
|
||||||
|
@ -149,7 +149,7 @@ build_grub_payload()
|
||||||
keymaps="${keymaps} ${keymapfile}"
|
keymaps="${keymaps} ${keymapfile}"
|
||||||
done
|
done
|
||||||
[ -z "$_keyboard" ] || [ -f "$grubcfgsdir/keymap/$_keyboard.gkb" ] || \
|
[ -z "$_keyboard" ] || [ -f "$grubcfgsdir/keymap/$_keyboard.gkb" ] || \
|
||||||
err "build_grub_payload: $_keyboard layout not defined"
|
$err "build_grub_payload: $_keyboard layout not defined"
|
||||||
[ -n "$_keyboard" ] && keymaps="${grubcfgsdir}/keymap/${_keyboard}.gkb"
|
[ -n "$_keyboard" ] && keymaps="${grubcfgsdir}/keymap/${_keyboard}.gkb"
|
||||||
[ -f "$grubelf" ] && return 0
|
[ -f "$grubelf" ] && return 0
|
||||||
[ -f "src/grub/grub-mkstandalone" ] || x_ ./update trees -b grub
|
[ -f "src/grub/grub-mkstandalone" ] || x_ ./update trees -b grub
|
||||||
|
@ -164,7 +164,7 @@ build_grub_payload()
|
||||||
--install-modules="${grub_install_modules}" \
|
--install-modules="${grub_install_modules}" \
|
||||||
"/boot/grub/grub.cfg=${grubcfgsdir}/config/grub_memdisk.cfg" \
|
"/boot/grub/grub.cfg=${grubcfgsdir}/config/grub_memdisk.cfg" \
|
||||||
"/boot/grub/grub_default.cfg=${grubcfgsdir}/config/grub.cfg" || \
|
"/boot/grub/grub_default.cfg=${grubcfgsdir}/config/grub.cfg" || \
|
||||||
err "could not generate grub.elf"
|
$err "could not generate grub.elf"
|
||||||
}
|
}
|
||||||
|
|
||||||
build_uboot_payload()
|
build_uboot_payload()
|
||||||
|
@ -175,12 +175,12 @@ build_uboot_payload()
|
||||||
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot" ] && \
|
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot" ] && \
|
||||||
ubootelf="${ubdir}/u-boot"
|
ubootelf="${ubdir}/u-boot"
|
||||||
[ -f "${ubootelf}" ] && return 0
|
[ -f "${ubootelf}" ] && return 0
|
||||||
err "Can't find u-boot build for board, $board";
|
$err "Can't find u-boot build for board, $board";
|
||||||
}
|
}
|
||||||
|
|
||||||
build_target_mainboard()
|
build_target_mainboard()
|
||||||
{
|
{
|
||||||
rm -f "${romdir}/"* || err "!prepare, rm files, ${romdir}"
|
rm -f "${romdir}/"* || $err "!prepare, rm files, ${romdir}"
|
||||||
|
|
||||||
for x in "normal" "vgarom" "libgfxinit"; do
|
for x in "normal" "vgarom" "libgfxinit"; do
|
||||||
initmode="${x}"
|
initmode="${x}"
|
||||||
|
@ -237,7 +237,7 @@ build_seabios_roms()
|
||||||
x_ build_grub_roms "${t}" "seabios_withgrub"
|
x_ build_grub_roms "${t}" "seabios_withgrub"
|
||||||
else
|
else
|
||||||
t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \
|
t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \
|
||||||
err "build_seabios_roms: cannot build tmprom"
|
$err "build_seabios_roms: cannot build tmprom"
|
||||||
newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}"
|
newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}"
|
||||||
[ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
|
[ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
|
||||||
&& newrom="${newrom}_${board}_${initmode}"
|
&& newrom="${newrom}_${board}_${initmode}"
|
||||||
|
@ -256,13 +256,13 @@ build_grub_roms()
|
||||||
if [ "$payload1" = "grub" ] && [ "$payload_grub_withseabios" = "y" ]
|
if [ "$payload1" = "grub" ] && [ "$payload_grub_withseabios" = "y" ]
|
||||||
then
|
then
|
||||||
_tmpmvrom=$(mkSeabiosRom "$tmprom" "seabios.elf") || \
|
_tmpmvrom=$(mkSeabiosRom "$tmprom" "seabios.elf") || \
|
||||||
err "build_grub_roms 1 $board: can't build tmprom"
|
$err "build_grub_roms 1 $board: can't build tmprom"
|
||||||
x_ mv "$_tmpmvrom" "$tmprom"
|
x_ mv "$_tmpmvrom" "$tmprom"
|
||||||
elif [ "$payload1" != "grub" ] && [ "$payload_seabios_withgrub" = "y" ]
|
elif [ "$payload1" != "grub" ] && [ "$payload_seabios_withgrub" = "y" ]
|
||||||
then
|
then
|
||||||
grub_cbfs="img/grub2"
|
grub_cbfs="img/grub2"
|
||||||
_tmpmvrom=$(mkSeabiosRom "$tmprom" fallback/payload) || \
|
_tmpmvrom=$(mkSeabiosRom "$tmprom" fallback/payload) || \
|
||||||
err "build_grub_roms 2 $board: can't build tmprom"
|
$err "build_grub_roms 2 $board: can't build tmprom"
|
||||||
x_ mv "$_tmpmvrom" "$tmprom"
|
x_ mv "$_tmpmvrom" "$tmprom"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -276,16 +276,16 @@ build_grub_roms()
|
||||||
backgroundfile="config/grub/background/${grub_background}"
|
backgroundfile="config/grub/background/${grub_background}"
|
||||||
"${cbfstool}" "${tmprom}" add -f ${backgroundfile} \
|
"${cbfstool}" "${tmprom}" add -f ${backgroundfile} \
|
||||||
-n background.png -t raw || \
|
-n background.png -t raw || \
|
||||||
err "insert background, ${backgroundfile}"
|
$err "insert background, ${backgroundfile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
||||||
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" >"$tmpcfg" \
|
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" >"$tmpcfg" \
|
||||||
|| err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
|
|| $err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
|
||||||
[ "${grub_scan_disk}" = "both" ] || \
|
[ "${grub_scan_disk}" = "both" ] || \
|
||||||
x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
|
x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
|
||||||
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \
|
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \
|
||||||
err "set timeout, ${grub_timeout}, ${tmpcfg}"
|
$err "set timeout, ${grub_timeout}, ${tmpcfg}"
|
||||||
[ -z "${grub_timeout}" ] || x_ "${cbfstool}" "${tmprom}" add \
|
[ -z "${grub_timeout}" ] || x_ "${cbfstool}" "${tmprom}" add \
|
||||||
-f "${tmpcfg}" -n timeout.cfg -t raw
|
-f "${tmpcfg}" -n timeout.cfg -t raw
|
||||||
x_ rm -f "${tmpcfg}"
|
x_ rm -f "${tmpcfg}"
|
||||||
|
@ -344,7 +344,7 @@ mkSeabiosGrubonlyRom()
|
||||||
tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
||||||
|
|
||||||
# only load grub, by inserting a custom bootorder file
|
# only load grub, by inserting a custom bootorder file
|
||||||
printf "/rom@img/grub2\n" > "$tmpbootorder" || err "printf bootorder"
|
printf "/rom@img/grub2\n" > "$tmpbootorder" || $err "printf bootorder"
|
||||||
x_ "${cbfstool}" "${_grubrom}" \
|
x_ "${cbfstool}" "${_grubrom}" \
|
||||||
add -f "${tmpbootorder}" -n bootorder -t raw
|
add -f "${tmpbootorder}" -n bootorder -t raw
|
||||||
x_ rm -f "${tmpbootorder}"
|
x_ rm -f "${tmpbootorder}"
|
||||||
|
@ -356,7 +356,7 @@ mkSeabiosGrubonlyRom()
|
||||||
build_uboot_roms()
|
build_uboot_roms()
|
||||||
{
|
{
|
||||||
tmprom=$(mkUbootRom "${cbrom}" "fallback/payload") || \
|
tmprom=$(mkUbootRom "${cbrom}" "fallback/payload") || \
|
||||||
err "build_uboot_roms $board: could not create tmprom"
|
$err "build_uboot_roms $board: could not create tmprom"
|
||||||
newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
|
newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
|
||||||
x_ moverom "${tmprom}" "${newrom}"
|
x_ moverom "${tmprom}" "${newrom}"
|
||||||
x_ rm -f "${tmprom}"
|
x_ rm -f "${tmprom}"
|
||||||
|
@ -370,7 +370,7 @@ mkUbootRom() {
|
||||||
_ubdir="elf/u-boot/${board}/${uboot_config}"
|
_ubdir="elf/u-boot/${board}/${uboot_config}"
|
||||||
_ubootelf="${_ubdir}/u-boot.elf"
|
_ubootelf="${_ubdir}/u-boot.elf"
|
||||||
[ -f "${_ubootelf}" ] || _ubootelf="${_ubdir}/u-boot"
|
[ -f "${_ubootelf}" ] || _ubootelf="${_ubdir}/u-boot"
|
||||||
[ -f "$_ubootelf" ] || err "mkUbootRom: $board: cant find u-boot"
|
[ -f "$_ubootelf" ] || $err "mkUbootRom: $board: cant find u-boot"
|
||||||
|
|
||||||
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ usage="usage: ./build firmware serprog <rp2040|stm32> [board]"
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
[ -z "${1+x}" ] && err "${usage}"
|
[ -z "${1+x}" ] && $err "${usage}"
|
||||||
[ "$1" != "rp2040" ] && [ "$1" != "stm32" ] && err "$usage"
|
[ "$1" != "rp2040" ] && [ "$1" != "stm32" ] && $err "$usage"
|
||||||
if [ "${1}" = "rp2040" ]; then
|
if [ "${1}" = "rp2040" ]; then
|
||||||
boards_dir=${pico_sdk_dir}/src/boards/include/boards
|
boards_dir=${pico_sdk_dir}/src/boards/include/boards
|
||||||
[ -d "$pico_src_dir" ] || x_ ./update trees -f "pico-serprog"
|
[ -d "$pico_src_dir" ] || x_ ./update trees -f "pico-serprog"
|
||||||
|
@ -71,7 +71,7 @@ print_boards()
|
||||||
|
|
||||||
list_boards()
|
list_boards()
|
||||||
{
|
{
|
||||||
basename -a -s .h "${1}/"*.h || err "list_boards $1: can't list boards"
|
basename -a -s .h "${1}/"*.h || $err "list_boards $1: can't list boards"
|
||||||
}
|
}
|
||||||
|
|
||||||
main $@
|
main $@
|
||||||
|
|
|
@ -13,11 +13,11 @@ main()
|
||||||
{
|
{
|
||||||
vdir="release"
|
vdir="release"
|
||||||
while getopts d:m: option; do
|
while getopts d:m: option; do
|
||||||
[ -z "${OPTARG}" ] && err "Empty argument not allowed"
|
[ -z "${OPTARG}" ] && $err "Empty argument not allowed"
|
||||||
case "${option}" in
|
case "${option}" in
|
||||||
d) vdir="${OPTARG}" ;;
|
d) vdir="${OPTARG}" ;;
|
||||||
m) mode="${OPTARG}" ;;
|
m) mode="${OPTARG}" ;;
|
||||||
*) err "Invalid option" ;;
|
*) $err "Invalid option" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ main()
|
||||||
src_dirname="${relname}_src"
|
src_dirname="${relname}_src"
|
||||||
srcdir="${vdir}/${src_dirname}"
|
srcdir="${vdir}/${src_dirname}"
|
||||||
|
|
||||||
[ -e "${vdir}" ] && err "already exists: \"${vdir}\""
|
[ -e "${vdir}" ] && $err "already exists: \"${vdir}\""
|
||||||
|
|
||||||
mkvdir
|
mkvdir
|
||||||
build_release
|
build_release
|
||||||
|
@ -39,45 +39,45 @@ main()
|
||||||
|
|
||||||
mkvdir()
|
mkvdir()
|
||||||
{
|
{
|
||||||
mkdir -p "${vdir}" || err "mkvdir: !mkdir -p \"${vdir}\""
|
mkdir -p "${vdir}" || $err "mkvdir: !mkdir -p \"${vdir}\""
|
||||||
git clone . "${srcdir}" || err "mkdir: !gitclone \"${srcdir}\""
|
git clone . "${srcdir}" || $err "mkdir: !gitclone \"${srcdir}\""
|
||||||
insert_version_files "$srcdir" || err "mkvdir $srcdir: versionfile"
|
insert_version_files "$srcdir" || $err "mkvdir $srcdir: versionfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
build_release()
|
build_release()
|
||||||
{
|
{
|
||||||
_xm="build_release ${vdir}"
|
_xm="build_release ${vdir}"
|
||||||
(
|
(
|
||||||
cd "${srcdir}" || err "${_xm}: !cd \"${srcdir}\""
|
cd "${srcdir}" || $err "${_xm}: !cd \"${srcdir}\""
|
||||||
fetch_trees
|
fetch_trees
|
||||||
[ "${mode}" = "u-boot" ] || x_ mv src/docs docs
|
[ "${mode}" = "u-boot" ] || x_ mv src/docs docs
|
||||||
) || err "can't create release files"
|
) || $err "can't create release files"
|
||||||
|
|
||||||
git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
|
git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
|
||||||
--abbrev-commit > "${srcdir}/CHANGELOG" || \
|
--abbrev-commit > "${srcdir}/CHANGELOG" || \
|
||||||
err "build_release $srcdir: couldn't generate changelog"
|
$err "build_release $srcdir: couldn't generate changelog"
|
||||||
|
|
||||||
(
|
(
|
||||||
if [ "${mode}" = "u-boot" ]; then
|
if [ "${mode}" = "u-boot" ]; then
|
||||||
cd "${srcdir}/src/" || err "${_xm}: mktarball \"${srcdir}\""
|
cd "${srcdir}/src/" || $err "${_xm}: mktarball \"${srcdir}\""
|
||||||
mktarball u-boot "../../${srcdir##*/}.tar.xz" || \
|
mktarball u-boot "../../${srcdir##*/}.tar.xz" || \
|
||||||
err "$_xm: mksrc"
|
$err "$_xm: mksrc"
|
||||||
# make a src archive containing only u-boot
|
# make a src archive containing only u-boot
|
||||||
else
|
else
|
||||||
cd "${srcdir%/*}" || err "${_xm}: mktarball \"${srcdir}\""
|
cd "${srcdir%/*}" || $err "${_xm}: mktarball \"${srcdir}\""
|
||||||
mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || \
|
mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || \
|
||||||
err "$_xm: mksrc"
|
$err "$_xm: mksrc"
|
||||||
fi
|
fi
|
||||||
) || err "can't create src tarball"
|
) || $err "can't create src tarball"
|
||||||
[ "${mode}" = "src" ] && return 0
|
[ "${mode}" = "src" ] && return 0
|
||||||
[ "${mode}" = "u-boot" ] && return 0
|
[ "${mode}" = "u-boot" ] && return 0
|
||||||
|
|
||||||
(
|
(
|
||||||
cd "${srcdir}" || err "${_xm}: 2 !cd \"${srcdir}\""
|
cd "${srcdir}" || $err "${_xm}: 2 !cd \"${srcdir}\""
|
||||||
mkrom_images
|
mkrom_images
|
||||||
) || err "can't build rom images"
|
) || $err "can't build rom images"
|
||||||
|
|
||||||
rm -Rf "${srcdir}" || err "!rm -Rf ${srcdir}"
|
rm -Rf "${srcdir}" || $err "!rm -Rf ${srcdir}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_trees()
|
fetch_trees()
|
||||||
|
@ -85,7 +85,7 @@ fetch_trees()
|
||||||
for x in config/git/*; do
|
for x in config/git/*; do
|
||||||
[ "${mode}" = "u-boot" ] && break
|
[ "${mode}" = "u-boot" ] && break
|
||||||
[ ! -f "${x}" ] || ./update trees -f "${x#config/git/}" || \
|
[ ! -f "${x}" ] || ./update trees -f "${x#config/git/}" || \
|
||||||
err "${_xm}: fetch ${x#config/git/}"
|
$err "${_xm}: fetch ${x#config/git/}"
|
||||||
done
|
done
|
||||||
[ "${mode}" = "u-boot" ] && x_ ./update trees -f u-boot
|
[ "${mode}" = "u-boot" ] && x_ ./update trees -f u-boot
|
||||||
|
|
||||||
|
@ -93,56 +93,56 @@ fetch_trees()
|
||||||
[ -f "${x}" ] || continue
|
[ -f "${x}" ] || continue
|
||||||
xp="${x#*/}"; xp="${xp%/*}"
|
xp="${x#*/}"; xp="${xp%/*}"
|
||||||
[ -L "${xp}" ] || rm -Rf "src/${xp}/${xp}" || \
|
[ -L "${xp}" ] || rm -Rf "src/${xp}/${xp}" || \
|
||||||
err "!rm -Rf \"src/${xp}/${xp}\""
|
$err "!rm -Rf \"src/${xp}/${xp}\""
|
||||||
done
|
done
|
||||||
|
|
||||||
find . -name ".git" -exec rm -Rf {} + || err "$_xm: rm .git"
|
find . -name ".git" -exec rm -Rf {} + || $err "$_xm: rm .git"
|
||||||
find . -name ".gitmodules" -exec rm -Rf {} + || err "$_xm: rm .gitmod"
|
find . -name ".gitmodules" -exec rm -Rf {} + || $err "$_xm: rm .gitmod"
|
||||||
x_ rm -Rf tmp .git
|
x_ rm -Rf tmp .git
|
||||||
}
|
}
|
||||||
|
|
||||||
mkrom_images()
|
mkrom_images()
|
||||||
{
|
{
|
||||||
./build roms all || err "${_xm}: roms-all"
|
./build roms all || $err "${_xm}: roms-all"
|
||||||
./build serprog rp2040 || err "${_xm}: rp2040"
|
./build serprog rp2040 || $err "${_xm}: rp2040"
|
||||||
./build serprog stm32 || err "${_xm}: stm32"
|
./build serprog stm32 || $err "${_xm}: stm32"
|
||||||
|
|
||||||
for rombuild in bin/*; do
|
for rombuild in bin/*; do
|
||||||
[ -d "${rombuild}" ] || continue
|
[ -d "${rombuild}" ] || continue
|
||||||
handle_rom_archive "${rombuild}"
|
handle_rom_archive "${rombuild}"
|
||||||
done
|
done
|
||||||
|
|
||||||
mv "release/${version}/roms/" ../roms || err "${_xm}: copy roms/"
|
mv "release/${version}/roms/" ../roms || $err "${_xm}: copy roms/"
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_rom_archive()
|
handle_rom_archive()
|
||||||
{
|
{
|
||||||
builddir="${1}"
|
builddir="${1}"
|
||||||
romdir="tmp/romdir"
|
romdir="tmp/romdir"
|
||||||
rm -Rf "${romdir}" || err "!rm romdir, handle_rom_archive"
|
rm -Rf "${romdir}" || $err "!rm romdir, handle_rom_archive"
|
||||||
target="${builddir##*/}"
|
target="${builddir##*/}"
|
||||||
|
|
||||||
if [ ! -f "config/coreboot/${target}/target.cfg" ]; then
|
if [ ! -f "config/coreboot/${target}/target.cfg" ]; then
|
||||||
# No config, just make a tarball
|
# No config, just make a tarball
|
||||||
tarball="release/${version}/roms/${relname}_${target}.tar.xz"
|
tarball="release/${version}/roms/${relname}_${target}.tar.xz"
|
||||||
insert_copying_files "${builddir}" || \
|
insert_copying_files "${builddir}" || \
|
||||||
err "!insert copy, handle, ${builddir}"
|
$err "!insert copy, handle, ${builddir}"
|
||||||
mktarball "${builddir}" "${tarball}"
|
mktarball "${builddir}" "${tarball}"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
romdir="${romdir}/bin/${target}"
|
romdir="${romdir}/bin/${target}"
|
||||||
mkdir -p "${romdir}" || err "!mkdir -p romdir, handle_rom_archive"
|
mkdir -p "${romdir}" || $err "!mkdir -p romdir, handle_rom_archive"
|
||||||
cp "$builddir/"* "$romdir" || err "!cp romdir, handle_rom_archive"
|
cp "$builddir/"* "$romdir" || $err "!cp romdir, handle_rom_archive"
|
||||||
|
|
||||||
nukerom
|
nukerom
|
||||||
|
|
||||||
printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
|
printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
|
||||||
"${version}" "${projectname}" "${version}" "${target##*/}"
|
"${version}" "${projectname}" "${version}" "${target##*/}"
|
||||||
insert_version_files "${romdir}" || \
|
insert_version_files "${romdir}" || \
|
||||||
err "mkrom_tarball ${romdir}: versionfile"
|
$err "mkrom_tarball ${romdir}: versionfile"
|
||||||
|
|
||||||
insert_copying_files "$romdir" || err "!insert copy, handle 2, $romdir"
|
insert_copying_files "$romdir" || $err "!insert copy, handle 2, $romdir"
|
||||||
mkrom_tarball
|
mkrom_tarball
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,18 +152,18 @@ nukerom()
|
||||||
|
|
||||||
# Hash the images before removing vendor files
|
# Hash the images before removing vendor files
|
||||||
# which "./vendor inject" uses for verification
|
# which "./vendor inject" uses for verification
|
||||||
rm -f "${romdir}/vendorhashes" || err "!rm ${romdir}/vendorhashes"
|
rm -f "${romdir}/vendorhashes" || $err "!rm ${romdir}/vendorhashes"
|
||||||
touch "${romdir}/vendorhashes" || err "!touch ${romdir}/vendorhashes"
|
touch "${romdir}/vendorhashes" || $err "!touch ${romdir}/vendorhashes"
|
||||||
(
|
(
|
||||||
cd "${romdir}" || err "!cd romdir ${romdir}, nukerom"
|
cd "${romdir}" || $err "!cd romdir ${romdir}, nukerom"
|
||||||
sha512sum ./*.rom >> vendorhashes || \
|
sha512sum ./*.rom >> vendorhashes || \
|
||||||
err "!create vendorhashes, nukerom"
|
$err "!create vendorhashes, nukerom"
|
||||||
) || err "can't create vendor hashes"
|
) || $err "can't create vendor hashes"
|
||||||
|
|
||||||
for romfile in "${romdir}"/*.rom; do
|
for romfile in "${romdir}"/*.rom; do
|
||||||
[ -f "${romfile}" ] || continue
|
[ -f "${romfile}" ] || continue
|
||||||
./vendor inject -r "$romfile" -b "$target" -n nuke || \
|
./vendor inject -r "$romfile" -b "$target" -n nuke || \
|
||||||
err "!vendor inject (nuke) ${romfile}, nukerom"
|
$err "!vendor inject (nuke) ${romfile}, nukerom"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +188,13 @@ mkrom_tarball()
|
||||||
{
|
{
|
||||||
archivename="${relname}_${target##*/}"
|
archivename="${relname}_${target##*/}"
|
||||||
f="release/${version}/roms/${archivename}"
|
f="release/${version}/roms/${archivename}"
|
||||||
mkdir -p "${f%/*}" || err "mkrom_tarball: !mkdir -p ${f%/*}"
|
mkdir -p "${f%/*}" || $err "mkrom_tarball: !mkdir -p ${f%/*}"
|
||||||
(
|
(
|
||||||
cd "${romdir%"/bin/$target"}" || err "!cd ${romdir%"/bin/$target"}"
|
cd "${romdir%"/bin/$target"}" || $err "!cd ${romdir%"/bin/$target"}"
|
||||||
mktarball "bin/${target}" "${archivename}.tar.xz"
|
mktarball "bin/${target}" "${archivename}.tar.xz"
|
||||||
) || err "can't create rom tarball"
|
) || $err "can't create rom tarball"
|
||||||
mv "${romdir%"/bin/${target}"}/${archivename}.tar.xz"* "${f%/*}" || \
|
mv "${romdir%"/bin/${target}"}/${archivename}.tar.xz"* "${f%/*}" || \
|
||||||
err "mktar ${f%/*}/${romdir%"/bin/$target"}/$archivename.tar.xz"
|
$err "mktar ${f%/*}/${romdir%"/bin/$target"}/$archivename.tar.xz"
|
||||||
|
|
||||||
printf "Created ROM archive: %s" "${f%/*}/${archivename}.tar.xz"
|
printf "Created ROM archive: %s" "${f%/*}/${archivename}.tar.xz"
|
||||||
}
|
}
|
||||||
|
@ -212,20 +212,20 @@ mktarball()
|
||||||
tar_implementation=$(tar --version | head -n1) || :
|
tar_implementation=$(tar --version | head -n1) || :
|
||||||
|
|
||||||
[ "${2%/*}" = "${2}" ] || \
|
[ "${2%/*}" = "${2}" ] || \
|
||||||
mkdir -p "${2%/*}" || err "mk, !mkdir -p \"${2%/*}\""
|
mkdir -p "${2%/*}" || $err "mk, !mkdir -p \"${2%/*}\""
|
||||||
if [ "${tar_implementation% *}" = "tar (GNU tar)" ]; then
|
if [ "${tar_implementation% *}" = "tar (GNU tar)" ]; then
|
||||||
tar --sort=name --owner=root:0 --group=root:0 \
|
tar --sort=name --owner=root:0 --group=root:0 \
|
||||||
--mtime="UTC 2024-02-25" -c "$1" | xz -T0 -9e > "$2" || \
|
--mtime="UTC 2024-02-25" -c "$1" | xz -T0 -9e > "$2" || \
|
||||||
err "mktarball 1, ${1}"
|
$err "mktarball 1, ${1}"
|
||||||
else
|
else
|
||||||
# TODO: reproducible tarballs on non-GNU systems
|
# TODO: reproducible tarballs on non-GNU systems
|
||||||
tar -c "$1" | xz -T0 -9e > "$2" || err "mktarball 2, $1"
|
tar -c "$1" | xz -T0 -9e > "$2" || $err "mktarball 2, $1"
|
||||||
fi
|
fi
|
||||||
(
|
(
|
||||||
[ "${2%/*}" != "${2}" ] && x_ cd "${2%/*}"
|
[ "${2%/*}" != "${2}" ] && x_ cd "${2%/*}"
|
||||||
sha512sum "${2##*/}" > "${2##*/}.sha512" || \
|
sha512sum "${2##*/}" > "${2##*/}.sha512" || \
|
||||||
err "!sha512sum \"${2##*/}\" > \"${2##*/}.sha512\""
|
$err "!sha512sum \"${2##*/}\" > \"${2##*/}.sha512\""
|
||||||
) || err "failed to create tarball checksum"
|
) || $err "failed to create tarball checksum"
|
||||||
}
|
}
|
||||||
|
|
||||||
main $@
|
main $@
|
||||||
|
|
|
@ -28,12 +28,12 @@ main()
|
||||||
-s) mode="savedefconfig" ;;
|
-s) mode="savedefconfig" ;;
|
||||||
-l) mode="olddefconfig" ;;
|
-l) mode="olddefconfig" ;;
|
||||||
-n) mode="nconfig" ;;
|
-n) mode="nconfig" ;;
|
||||||
*) err "Invalid option" ;;
|
*) $err "Invalid option" ;;
|
||||||
esac
|
esac
|
||||||
shift; project="${OPTARG#src/}"; shift
|
shift; project="${OPTARG#src/}"; shift
|
||||||
done
|
done
|
||||||
[ -z "$_f" ] && err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
|
[ -z "$_f" ] && $err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
|
||||||
[ -z "$project" ] && err "project name not specified"
|
[ -z "$project" ] && $err "project name not specified"
|
||||||
elfdir="elf/${project}"
|
elfdir="elf/${project}"
|
||||||
cfgsdir="config/${project}"
|
cfgsdir="config/${project}"
|
||||||
|
|
||||||
|
@ -66,17 +66,17 @@ build_targets()
|
||||||
[ "$elfdir" = "elf/coreboot" ] && \
|
[ "$elfdir" = "elf/coreboot" ] && \
|
||||||
elfdir="elf/coreboot_nopayload_DO_NOT_FLASH"
|
elfdir="elf/coreboot_nopayload_DO_NOT_FLASH"
|
||||||
|
|
||||||
[ -d "$cfgsdir" ] || err "directory, $cfgsdir, does not exist"
|
[ -d "$cfgsdir" ] || $err "directory, $cfgsdir, does not exist"
|
||||||
|
|
||||||
listfile="${cfgsdir}/build.list"
|
listfile="${cfgsdir}/build.list"
|
||||||
[ -f "$listfile" ] || err "list file, $listfile, does not exist"
|
[ -f "$listfile" ] || $err "list file, $listfile, does not exist"
|
||||||
|
|
||||||
# Build for all targets if no argument is given
|
# Build for all targets if no argument is given
|
||||||
[ $# -gt 0 ] && target1="$1"
|
[ $# -gt 0 ] && target1="$1"
|
||||||
[ "$target1" = "utils" ] && [ "$project" = "coreboot" ] && \
|
[ "$target1" = "utils" ] && [ "$project" = "coreboot" ] && \
|
||||||
shift 1
|
shift 1
|
||||||
targets=$(items "$cfgsdir") || \
|
targets=$(items "$cfgsdir") || \
|
||||||
err "Cannot get options for $cfgsdir"
|
$err "Cannot get options for $cfgsdir"
|
||||||
[ $# -gt 0 ] && targets=$@
|
[ $# -gt 0 ] && targets=$@
|
||||||
|
|
||||||
[ -z "$mode" ] && x_ mkdir -p "$elfdir"
|
[ -z "$mode" ] && x_ mkdir -p "$elfdir"
|
||||||
|
@ -130,7 +130,7 @@ handle_src_tree()
|
||||||
|
|
||||||
x_ mkdir -p "${elfdir}/${target}"
|
x_ mkdir -p "${elfdir}/${target}"
|
||||||
|
|
||||||
[ -z "$tree" ] && err "handle_src_tree $project/$tree: tree unset"
|
[ -z "$tree" ] && $err "handle_src_tree $project/$tree: tree unset"
|
||||||
|
|
||||||
codedir="src/${project}/${tree}"
|
codedir="src/${project}/${tree}"
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ load_project_config()
|
||||||
|
|
||||||
[ -f "${1}/target.cfg" ] || return 0
|
[ -f "${1}/target.cfg" ] || return 0
|
||||||
. "${1}/target.cfg" || \
|
. "${1}/target.cfg" || \
|
||||||
err "load_project_config ${1}: cannot load target.cfg"; return 0
|
$err "load_project_config ${1}: cannot load target.cfg"; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
check_cross_compiler()
|
check_cross_compiler()
|
||||||
|
@ -178,7 +178,7 @@ check_cross_compiler()
|
||||||
|
|
||||||
check_config()
|
check_config()
|
||||||
{
|
{
|
||||||
[ -f "$config" ] || err "check_config: ${project}/${target}: no config"
|
[ -f "$config" ] || $err "check_config: ${project}/${target}: no config"
|
||||||
|
|
||||||
dest_dir="${elfdir}/${target}/${config_name}"
|
dest_dir="${elfdir}/${target}/${config_name}"
|
||||||
# TODO: very hacky check. do it properly (based on build.list)
|
# TODO: very hacky check. do it properly (based on build.list)
|
||||||
|
@ -197,7 +197,7 @@ handle_makefile()
|
||||||
[ -n "$mode" ] || make -C "$codedir" silentoldconfig || \
|
[ -n "$mode" ] || make -C "$codedir" silentoldconfig || \
|
||||||
make -C "$codedir" oldconfig || :
|
make -C "$codedir" oldconfig || :
|
||||||
|
|
||||||
run_make_command || err "handle_makefile $codedir: no makefile!"
|
run_make_command || $err "handle_makefile $codedir: no makefile!"
|
||||||
|
|
||||||
if [ -e "${codedir}/.git" ] && [ "$project" = "u-boot" ] && \
|
if [ -e "${codedir}/.git" ] && [ "$project" = "u-boot" ] && \
|
||||||
[ "$mode" = "distclean" ]; then
|
[ "$mode" = "distclean" ]; then
|
||||||
|
@ -220,7 +220,7 @@ run_make_command()
|
||||||
printf "%s\n" "${version%%-*}" > "$codedir/.coreboot-version"
|
printf "%s\n" "${version%%-*}" > "$codedir/.coreboot-version"
|
||||||
|
|
||||||
make $mode -j$(nproc) $makeargs -C "$codedir" || \
|
make $mode -j$(nproc) $makeargs -C "$codedir" || \
|
||||||
err "run_make $codedir: !make $mode"
|
$err "run_make $codedir: !make $mode"
|
||||||
|
|
||||||
[ "$mode" != "clean" ] && return 0
|
[ "$mode" != "clean" ] && return 0
|
||||||
make -C "$codedir" distclean 2>/dev/null || :
|
make -C "$codedir" distclean 2>/dev/null || :
|
||||||
|
@ -232,9 +232,9 @@ check_cmake()
|
||||||
check_makefile "${1}" || \
|
check_makefile "${1}" || \
|
||||||
cmake -B "${1}" "${1}/${cmakedir}" || \
|
cmake -B "${1}" "${1}/${cmakedir}" || \
|
||||||
check_makefile "${1}" || \
|
check_makefile "${1}" || \
|
||||||
err "check_cmake ${1}: can't cmake ${cmakedir}"
|
$err "check_cmake ${1}: can't cmake ${cmakedir}"
|
||||||
[ -z "${cmakedir}" ] || check_makefile "${1}" || \
|
[ -z "${cmakedir}" ] || check_makefile "${1}" || \
|
||||||
err "check_cmake ${1}: could not generate Makefile"
|
$err "check_cmake ${1}: could not generate Makefile"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,11 +242,11 @@ check_autoconf()
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
_cfgopt=""
|
_cfgopt=""
|
||||||
cd "${1}" || err "!cd $1"
|
cd "${1}" || $err "!cd $1"
|
||||||
[ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs
|
[ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs
|
||||||
[ -f "autogen.sh" ] && x_ ./autogen.sh ${autogenargs}
|
[ -f "autogen.sh" ] && x_ ./autogen.sh ${autogenargs}
|
||||||
[ -f "configure" ] && x_ ./configure $autoconfargs; return 0
|
[ -f "configure" ] && x_ ./configure $autoconfargs; return 0
|
||||||
) || err "can't bootstrap project: $1"
|
) || $err "can't bootstrap project: $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_makefile()
|
check_makefile()
|
||||||
|
|
|
@ -25,14 +25,14 @@ eval "$(setvars "" _b _dl EC_url EC_url_bkup EC_hash DL_hash DL_url DL_url_bkup
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
[ $# -gt 0 ] || err "No argument given"
|
[ $# -gt 0 ] || $err "No argument given"
|
||||||
board="${1}"
|
board="${1}"
|
||||||
boarddir="${cbcfgsdir}/${board}"
|
boarddir="${cbcfgsdir}/${board}"
|
||||||
_b="${board%%_*mb}" # shorthand (no duplication per rom size)
|
_b="${board%%_*mb}" # shorthand (no duplication per rom size)
|
||||||
|
|
||||||
check_defconfig "${boarddir}" && exit 0
|
check_defconfig "${boarddir}" && exit 0
|
||||||
detect_firmware && exit 0
|
detect_firmware && exit 0
|
||||||
scan_config "${_b}" "config/vendor" "err"
|
scan_config "${_b}" "config/vendor"
|
||||||
|
|
||||||
build_dependencies
|
build_dependencies
|
||||||
download_vendorfiles
|
download_vendorfiles
|
||||||
|
@ -49,7 +49,7 @@ detect_firmware()
|
||||||
set -- "${boarddir}/config/"*
|
set -- "${boarddir}/config/"*
|
||||||
. "${1}" 2>/dev/null
|
. "${1}" 2>/dev/null
|
||||||
. "${boarddir}/target.cfg" 2>/dev/null
|
. "${boarddir}/target.cfg" 2>/dev/null
|
||||||
[ -z "$tree" ] && err "detect_firmware $boarddir: tree undefined"
|
[ -z "$tree" ] && $err "detect_firmware $boarddir: tree undefined"
|
||||||
cbdir="src/coreboot/$tree"
|
cbdir="src/coreboot/$tree"
|
||||||
cbfstool="cbutils/$tree/cbfstool"
|
cbfstool="cbutils/$tree/cbfstool"
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ fetch()
|
||||||
dl_bkup="${3}"
|
dl_bkup="${3}"
|
||||||
dlsum="${4}"
|
dlsum="${4}"
|
||||||
[ "${5}" = "/dev/null" ] && return 0
|
[ "${5}" = "/dev/null" ] && return 0
|
||||||
[ "${5# }" = "$5" ] || err "fetch: space not allowed in _dest: '$5'"
|
[ "${5# }" = "$5" ] || $err "fetch: space not allowed in _dest: '$5'"
|
||||||
[ "${5#/}" = "$5" ] || err "fetch: absolute path not allowed: '$5'"
|
[ "${5#/}" = "$5" ] || $err "fetch: absolute path not allowed: '$5'"
|
||||||
_dest="${5##*../}"
|
_dest="${5##*../}"
|
||||||
_dl="${vendir}/cache/${dlsum}"
|
_dl="${vendir}/cache/${dlsum}"
|
||||||
dl_fail="n"
|
dl_fail="n"
|
||||||
|
@ -129,14 +129,14 @@ fetch()
|
||||||
vendor_checksum "${dlsum}" "${_dl}" || dl_fail="n"
|
vendor_checksum "${dlsum}" "${_dl}" || dl_fail="n"
|
||||||
done
|
done
|
||||||
[ "${dl_fail}" = "y" ] && \
|
[ "${dl_fail}" = "y" ] && \
|
||||||
err "fetch ${dlsum}: matched file unavailable"
|
$err "fetch ${dlsum}: matched file unavailable"
|
||||||
|
|
||||||
x_ rm -Rf "${_dl}_extracted"
|
x_ rm -Rf "${_dl}_extracted"
|
||||||
mkdirs "${_dest}" "extract_${dl_type}" || return 0
|
mkdirs "${_dest}" "extract_${dl_type}" || return 0
|
||||||
eval "extract_${dl_type}"
|
eval "extract_${dl_type}"
|
||||||
|
|
||||||
[ -f "${_dest}" ] && return 0
|
[ -f "${_dest}" ] && return 0
|
||||||
err "extract_${dl_type} (fetch): missing file: '${_dest}'"
|
$err "extract_${dl_type} (fetch): missing file: '${_dest}'"
|
||||||
}
|
}
|
||||||
|
|
||||||
vendor_checksum()
|
vendor_checksum()
|
||||||
|
@ -152,17 +152,17 @@ mkdirs()
|
||||||
printf "mkdirs %s %s: already downloaded\n" "$1" "$2" 1>&2
|
printf "mkdirs %s %s: already downloaded\n" "$1" "$2" 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
mkdir -p "${1%/*}" || err "mkdirs: !mkdir -p ${1%/*}"
|
mkdir -p "${1%/*}" || $err "mkdirs: !mkdir -p ${1%/*}"
|
||||||
remkdir "${appdir}"
|
remkdir "${appdir}"
|
||||||
extract_archive "${_dl}" "${appdir}" || \
|
extract_archive "${_dl}" "${appdir}" || \
|
||||||
[ "${2}" = "extract_e6400vga" ] || \
|
[ "${2}" = "extract_e6400vga" ] || \
|
||||||
err "mkdirs ${1} ${2}: !extract"
|
$err "mkdirs ${1} ${2}: !extract"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_intel_me()
|
extract_intel_me()
|
||||||
{
|
{
|
||||||
[ ! -f "$mecleaner" ] && \
|
[ ! -f "$mecleaner" ] && \
|
||||||
err "extract_intel_me $cbdir: me_cleaner missing"
|
$err "extract_intel_me $cbdir: me_cleaner missing"
|
||||||
|
|
||||||
_me="${PWD}/${_dest}" # must always be an absolute path
|
_me="${PWD}/${_dest}" # must always be an absolute path
|
||||||
cdir="${PWD}/${appdir}" # must always be an absolute path
|
cdir="${PWD}/${appdir}" # must always be an absolute path
|
||||||
|
@ -170,10 +170,10 @@ extract_intel_me()
|
||||||
[ -f "${_me}" ] && return 0
|
[ -f "${_me}" ] && return 0
|
||||||
|
|
||||||
sdir="$(mktemp -d)"
|
sdir="$(mktemp -d)"
|
||||||
mkdir -p "$sdir" || err "extract_intel_me: !mkdir -p \"$sdir\""
|
mkdir -p "$sdir" || $err "extract_intel_me: !mkdir -p \"$sdir\""
|
||||||
(
|
(
|
||||||
[ "${cdir#/a}" != "$cdir" ] && cdir="${cdir#/}"
|
[ "${cdir#/a}" != "$cdir" ] && cdir="${cdir#/}"
|
||||||
cd "$cdir" || err "extract_intel_me: !cd \"$cdir\""
|
cd "$cdir" || $err "extract_intel_me: !cd \"$cdir\""
|
||||||
for i in *; do
|
for i in *; do
|
||||||
[ -f "$_me" ] && break
|
[ -f "$_me" ] && break
|
||||||
[ -L "$i" ] && continue
|
[ -L "$i" ] && continue
|
||||||
|
@ -195,7 +195,7 @@ extract_intel_me()
|
||||||
cd "${cdir}" || :
|
cd "${cdir}" || :
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
rm -Rf "${sdir}" || err "extract_intel_me: !rm -Rf ${sdir}"
|
rm -Rf "${sdir}" || $err "extract_intel_me: !rm -Rf ${sdir}"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_archive()
|
extract_archive()
|
||||||
|
@ -207,44 +207,44 @@ extract_archive()
|
||||||
extract_kbc1126ec()
|
extract_kbc1126ec()
|
||||||
{
|
{
|
||||||
[ ! -f "$kbc1126_ec_dump" ] && \
|
[ ! -f "$kbc1126_ec_dump" ] && \
|
||||||
err "extract_kbc1126ec $cbdir: kbc1126_ec_dump missing"
|
$err "extract_kbc1126ec $cbdir: kbc1126_ec_dump missing"
|
||||||
(
|
(
|
||||||
x_ cd "${appdir}/"
|
x_ cd "${appdir}/"
|
||||||
mv Rompaq/68*.BIN ec.bin || :
|
mv Rompaq/68*.BIN ec.bin || :
|
||||||
if [ ! -f ec.bin ]; then
|
if [ ! -f ec.bin ]; then
|
||||||
unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \
|
unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \
|
||||||
unar -D 68*.CAB Rom.bin || err "can't extract Rom.bin"
|
unar -D 68*.CAB Rom.bin || $err "can't extract Rom.bin"
|
||||||
x_ mv Rom.bin ec.bin
|
x_ mv Rom.bin ec.bin
|
||||||
fi
|
fi
|
||||||
[ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract"
|
[ -f ec.bin ] || $err "extract_kbc1126_ec ${board}: can't extract"
|
||||||
"${kbc1126_ec_dump}" ec.bin || \
|
"${kbc1126_ec_dump}" ec.bin || \
|
||||||
err "extract_kbc1126_ec ${board}: can't extract ecfw1/2.bin"
|
$err "extract_kbc1126_ec ${board}: can't extract ecfw1/2.bin"
|
||||||
) || err "can't extract kbc1126 ec firmware"
|
) || $err "can't extract kbc1126 ec firmware"
|
||||||
ec_ex="y"
|
ec_ex="y"
|
||||||
for i in 1 2; do
|
for i in 1 2; do
|
||||||
[ -f "${appdir}/ec.bin.fw${i}" ] || ec_ex="n"
|
[ -f "${appdir}/ec.bin.fw${i}" ] || ec_ex="n"
|
||||||
done
|
done
|
||||||
[ "${ec_ex}" = "y" ] || \
|
[ "${ec_ex}" = "y" ] || \
|
||||||
err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin"
|
$err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin"
|
||||||
cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" || \
|
cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" || \
|
||||||
err "extract_kbc1126_ec ${board}: can't copy ec binaries"
|
$err "extract_kbc1126_ec ${board}: can't copy ec binaries"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_e6400vga()
|
extract_e6400vga()
|
||||||
{
|
{
|
||||||
for v in E6400_VGA_offset E6400_VGA_romname; do
|
for v in E6400_VGA_offset E6400_VGA_romname; do
|
||||||
eval "[ -z \"\$$v\" ] && err \"extract_e6400vga: $v undefined\""
|
eval "[ -z \"\$$v\" ] && $err \"extract_e6400vga: $v undefined\""
|
||||||
done
|
done
|
||||||
tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || :
|
tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || :
|
||||||
(
|
(
|
||||||
x_ cd "${appdir}"
|
x_ cd "${appdir}"
|
||||||
[ -f "bios.bin" ] || err "extract_e6400vga: can't extract bios.bin"
|
[ -f "bios.bin" ] || $err "extract_e6400vga: can't extract bios.bin"
|
||||||
"${e6400_unpack}" bios.bin || printf "TODO: fix dell extract util\n"
|
"${e6400_unpack}" bios.bin || printf "TODO: fix dell extract util\n"
|
||||||
[ -f "${E6400_VGA_romname}" ] || \
|
[ -f "${E6400_VGA_romname}" ] || \
|
||||||
err "extract_e6400vga: can't extract vga rom from bios.bin"
|
$err "extract_e6400vga: can't extract vga rom from bios.bin"
|
||||||
) || err "can't extract e6400 vga rom"
|
) || $err "can't extract e6400 vga rom"
|
||||||
cp "${appdir}/${E6400_VGA_romname}" "${_dest}" || \
|
cp "${appdir}/${E6400_VGA_romname}" "${_dest}" || \
|
||||||
err "extract_e6400vga ${board}: can't copy vga rom to ${_dest}"
|
$err "extract_e6400vga ${board}: can't copy vga rom to ${_dest}"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_sch5545ec()
|
extract_sch5545ec()
|
||||||
|
@ -258,9 +258,9 @@ extract_sch5545ec()
|
||||||
|
|
||||||
# this makes the file defined by _sch5545ec_fw available to copy
|
# this makes the file defined by _sch5545ec_fw available to copy
|
||||||
"${uefiextract}" "${_bios}" || \
|
"${uefiextract}" "${_bios}" || \
|
||||||
err "extract_sch5545ec: cannot extract from uefi image"
|
$err "extract_sch5545ec: cannot extract from uefi image"
|
||||||
cp "${_sch5545ec_fw}" "${_dest}" || \
|
cp "${_sch5545ec_fw}" "${_dest}" || \
|
||||||
err "extract_sch5545ec: cannot copy sch5545ec firmware file"
|
$err "extract_sch5545ec: cannot copy sch5545ec firmware file"
|
||||||
}
|
}
|
||||||
|
|
||||||
main $@
|
main $@
|
||||||
|
|
|
@ -13,7 +13,7 @@ eval "$(setvars "" archive rom modifygbe nukemode release new_mac tree)"
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
[ $# -lt 1 ] && err "No options specified."
|
[ $# -lt 1 ] && $err "No options specified."
|
||||||
[ "${1}" = "listboards" ] && eval "items config/coreboot || :; exit 0"
|
[ "${1}" = "listboards" ] && eval "items config/coreboot || :; exit 0"
|
||||||
|
|
||||||
archive="${1}"
|
archive="${1}"
|
||||||
|
@ -42,8 +42,8 @@ check_board()
|
||||||
failcheck="n"
|
failcheck="n"
|
||||||
check_release "${archive}" || failcheck="y"
|
check_release "${archive}" || failcheck="y"
|
||||||
if [ "${failcheck}" = "y" ]; then
|
if [ "${failcheck}" = "y" ]; then
|
||||||
[ -f "$rom" ] || err "check_board \"$rom\": invalid path"
|
[ -f "$rom" ] || $err "check_board \"$rom\": invalid path"
|
||||||
[ -z "${rom+x}" ] && err "check_board: no rom specified"
|
[ -z "${rom+x}" ] && $err "check_board: no rom specified"
|
||||||
[ -n "${board+x}" ] || board=$(detect_board "${rom}")
|
[ -n "${board+x}" ] || board=$(detect_board "${rom}")
|
||||||
else
|
else
|
||||||
release="y"
|
release="y"
|
||||||
|
@ -51,11 +51,11 @@ check_board()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
boarddir="${cbcfgsdir}/${board}"
|
boarddir="${cbcfgsdir}/${board}"
|
||||||
[ -d "$boarddir" ] || err "check_board: board $board missing"
|
[ -d "$boarddir" ] || $err "check_board: board $board missing"
|
||||||
[ -f "$boarddir/target.cfg" ] || \
|
[ -f "$boarddir/target.cfg" ] || \
|
||||||
err "check_board $board: target.cfg missing"
|
$err "check_board $board: target.cfg missing"
|
||||||
. "$boarddir/target.cfg" 2>/dev/null
|
. "$boarddir/target.cfg" 2>/dev/null
|
||||||
[ -z "$tree" ] && err "check_board $board: tree undefined"; return 0
|
[ -z "$tree" ] && $err "check_board $board: tree undefined"; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
check_release()
|
check_release()
|
||||||
|
@ -80,7 +80,7 @@ detect_board()
|
||||||
_stripped_prefix=${filename#*_}
|
_stripped_prefix=${filename#*_}
|
||||||
board="${_stripped_prefix%.tar.xz}" ;;
|
board="${_stripped_prefix%.tar.xz}" ;;
|
||||||
*)
|
*)
|
||||||
err "detect_board $filename: could not detect board type"
|
$err "detect_board $filename: could not detect board type"
|
||||||
esac
|
esac
|
||||||
printf "%s\n" "${board}"
|
printf "%s\n" "${board}"
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ patch_release_roms()
|
||||||
_tmpdir="tmp/romdir"
|
_tmpdir="tmp/romdir"
|
||||||
remkdir "${_tmpdir}"
|
remkdir "${_tmpdir}"
|
||||||
tar -xf "${archive}" -C "${_tmpdir}" || \
|
tar -xf "${archive}" -C "${_tmpdir}" || \
|
||||||
err "patch_release_roms: !tar -xf \"$archive\" -C \"$_tmpdir\""
|
$err "patch_release_roms: !tar -xf \"$archive\" -C \"$_tmpdir\""
|
||||||
|
|
||||||
for x in "${_tmpdir}"/bin/*/*.rom ; do
|
for x in "${_tmpdir}"/bin/*/*.rom ; do
|
||||||
printf "patching rom: %s\n" "$x"
|
printf "patching rom: %s\n" "$x"
|
||||||
|
@ -118,14 +118,14 @@ patch_release_roms()
|
||||||
|
|
||||||
(
|
(
|
||||||
cd "${_tmpdir}/bin/"* || \
|
cd "${_tmpdir}/bin/"* || \
|
||||||
err "patch_release_roms: !cd ${_tmpdir}/bin/*"
|
$err "patch_release_roms: !cd ${_tmpdir}/bin/*"
|
||||||
|
|
||||||
# NOTE: For compatibility with older rom releases, defer to sha1
|
# NOTE: For compatibility with older rom releases, defer to sha1
|
||||||
[ "${nukemode}" = "nuke" ] || sha512sum --status -c vendorhashes || \
|
[ "${nukemode}" = "nuke" ] || sha512sum --status -c vendorhashes || \
|
||||||
sha1sum --status -c vendorhashes || sha512sum --status -c \
|
sha1sum --status -c vendorhashes || sha512sum --status -c \
|
||||||
blobhashes || sha1sum --status -c blobhashes || \
|
blobhashes || sha1sum --status -c blobhashes || \
|
||||||
err "patch_release_roms: ROMs did not match expected hashes"
|
$err "patch_release_roms: ROMs did not match expected hashes"
|
||||||
) || err "can't verify vendor hashes"
|
) || $err "can't verify vendor hashes"
|
||||||
|
|
||||||
[ "${modifygbe}" = "true" ] && \
|
[ "${modifygbe}" = "true" ] && \
|
||||||
for x in "${_tmpdir}"/bin/*/*.rom ; do
|
for x in "${_tmpdir}"/bin/*/*.rom ; do
|
||||||
|
@ -143,7 +143,7 @@ patch_rom()
|
||||||
{
|
{
|
||||||
rom="${1}"
|
rom="${1}"
|
||||||
|
|
||||||
check_defconfig "$boarddir" && err "patch_rom $boarddir: no configs"
|
check_defconfig "$boarddir" && $err "patch_rom $boarddir: no configs"
|
||||||
|
|
||||||
set -- "${boarddir}/config/"*
|
set -- "${boarddir}/config/"*
|
||||||
. "${1}" 2>/dev/null
|
. "${1}" 2>/dev/null
|
||||||
|
@ -174,18 +174,18 @@ patch_rom()
|
||||||
inject()
|
inject()
|
||||||
{
|
{
|
||||||
[ $# -lt 3 ] && \
|
[ $# -lt 3 ] && \
|
||||||
err "inject $@, $rom: usage: inject name path type (offset)"
|
$err "inject $@, $rom: usage: inject name path type (offset)"
|
||||||
|
|
||||||
eval "$(setvars "" cbfsname _dest _t _offset)"
|
eval "$(setvars "" cbfsname _dest _t _offset)"
|
||||||
cbfsname="${1}"
|
cbfsname="${1}"
|
||||||
_dest="${2##*../}"
|
_dest="${2##*../}"
|
||||||
_t="${3}"
|
_t="${3}"
|
||||||
[ $# -gt 3 ] && _offset="-b ${4}" && [ -z "${4}" ] && \
|
[ $# -gt 3 ] && _offset="-b ${4}" && [ -z "${4}" ] && \
|
||||||
err "inject $@, $rom: offset passed, but empty (not defined)"
|
$err "inject $@, $rom: offset passed, but empty (not defined)"
|
||||||
|
|
||||||
[ -z "${_dest}" ] && err "inject $@, ${rom}: empty destination path"
|
[ -z "${_dest}" ] && $err "inject $@, ${rom}: empty destination path"
|
||||||
[ ! -f "${_dest}" ] && [ "${nukemode}" != "nuke" ] && \
|
[ ! -f "${_dest}" ] && [ "${nukemode}" != "nuke" ] && \
|
||||||
err "inject_${dl_type}: file missing, ${_dest}"
|
$err "inject_${dl_type}: file missing, ${_dest}"
|
||||||
|
|
||||||
[ "$nukemode" = "nuke" ] || \
|
[ "$nukemode" = "nuke" ] || \
|
||||||
printf "Inserting %s/%s in file: %s\n" "$cbfsname" "$_t" "$rom"
|
printf "Inserting %s/%s in file: %s\n" "$cbfsname" "$_t" "$rom"
|
||||||
|
@ -193,18 +193,18 @@ inject()
|
||||||
if [ "${_t}" = "GbE" ]; then
|
if [ "${_t}" = "GbE" ]; then
|
||||||
x_ mkdir -p tmp
|
x_ mkdir -p tmp
|
||||||
cp "${_dest}" "tmp/gbe.bin" || \
|
cp "${_dest}" "tmp/gbe.bin" || \
|
||||||
err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""
|
$err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""
|
||||||
_dest="tmp/gbe.bin"
|
_dest="tmp/gbe.bin"
|
||||||
"${nvmutil}" "${_dest}" setmac "${new_mac}" || \
|
"${nvmutil}" "${_dest}" setmac "${new_mac}" || \
|
||||||
err "inject ${_dest}: can't change mac address"
|
$err "inject ${_dest}: can't change mac address"
|
||||||
fi
|
fi
|
||||||
if [ "${cbfsname}" = "IFD" ]; then
|
if [ "${cbfsname}" = "IFD" ]; then
|
||||||
if [ "${nukemode}" != "nuke" ]; then
|
if [ "${nukemode}" != "nuke" ]; then
|
||||||
"$ifdtool" -i ${_t}:${_dest} "$rom" -O "$rom" || \
|
"$ifdtool" -i ${_t}:${_dest} "$rom" -O "$rom" || \
|
||||||
err "inject: can't insert $_t ($dest) into $rom"
|
$err "inject: can't insert $_t ($dest) into $rom"
|
||||||
else
|
else
|
||||||
"$ifdtool" --nuke $_t "$rom" -O "$rom" || \
|
"$ifdtool" --nuke $_t "$rom" -O "$rom" || \
|
||||||
err "inject $rom: can't nuke $_t in IFD"
|
$err "inject $rom: can't nuke $_t in IFD"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "${nukemode}" != "nuke" ]; then
|
if [ "${nukemode}" != "nuke" ]; then
|
||||||
|
@ -214,11 +214,11 @@ inject()
|
||||||
else
|
else
|
||||||
"$cbfstool" "$rom" add -f "$_dest" \
|
"$cbfstool" "$rom" add -f "$_dest" \
|
||||||
-n "$cbfsname" -t $_t $_offset || \
|
-n "$cbfsname" -t $_t $_offset || \
|
||||||
err "$rom: can't insert $_t file $_dest"
|
$err "$rom: can't insert $_t file $_dest"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
"$cbfstool" "$rom" remove -n "$cbfsname" || \
|
"$cbfstool" "$rom" remove -n "$cbfsname" || \
|
||||||
err "inject $rom: can't remove $cbfsname"
|
$err "inject $rom: can't remove $cbfsname"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue