2023-08-23 17:56:31 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2024-05-03 06:13:54 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022, 2024 Leah Rowe <leah@libreboot.org>
|
2023-08-23 17:56:31 +00:00
|
|
|
|
2024-04-26 07:20:19 +00:00
|
|
|
export LC_COLLATE=C
|
|
|
|
export LC_ALL=C
|
|
|
|
|
2023-12-24 06:32:19 +00:00
|
|
|
version=""; versiondate=""; projectname=""; _nogit=""
|
2024-04-28 19:33:38 +00:00
|
|
|
err="err_"; tmpdir=""; lbmk_status=""
|
2023-10-07 01:36:46 +00:00
|
|
|
|
haswell: only provide NRI-based ROMs in releases
release="n" is set in target.cfg on haswell build targets
that use mrc.bin
script/update/release exports LBMK_RELEASE="y"
script/build/roms skips building a given target if release="n"
in target.cfg *and* LBMK_RELEASE="y"
you could also do the export yourself before running ./build roms,
for example:
export LBMK_RELEASE="y"
./build roms all
This would skip these ROM images. The native haswell raminit is
now stable enough in my testing, that I wish to delete the MRC-based
targets. This is in line with Libreboot's Binary Blob Reduction Policy,
which states: if a blob can be avoided, it should be avoided.
The problem is that users often run the inject script in *lbmk* from
Git, instead of from the src release archive. I forsee some users
running this on modern lbmk with older release images. If the mrc-based
target isn't there, the user may use an NRI-based target name, and
think it works; they will insert without MRC. I foresaw this ages
ago, which is why Caleb and I ensured that the script checks hashes,
and hashes are included in releases.
Therefore: for the time being, keep the MRC-based configs in lbmk
but do not include images for them in releases. This can be done
indefinitely, but I'll probably remove those configs entirely at
some point.
On the following boards, Libreboot now will *only* provide NRI-based
ROM images for the following machines:
* Dell OptiPlex 9020 SFF
* Dell OptiPlex 9020 MT
* Lenovo ThinkPad T440p
* Lenovo ThinkPad W541/W540
I now recommend exclusive use of NRI-based images, on Haswell
hardware. It's stable enough in my testing, and now supports S3.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-04-24 04:27:27 +00:00
|
|
|
# if "y": a coreboot target won't be built if target.cfg says release="n"
|
|
|
|
# (this is used to exclude certain build targets from releases)
|
|
|
|
lbmk_release=
|
|
|
|
set | grep LBMK_RELEASE 1>/dev/null 2>/dev/null || lbmk_release="n" || :
|
|
|
|
[ -z "$lbmk_release" ] && lbmk_release="$LBMK_RELEASE"
|
|
|
|
[ "$lbmk_release" = "n" ] || [ "$lbmk_release" = "y" ] || lbmk_release="n"
|
2024-04-26 07:20:19 +00:00
|
|
|
export LBMK_RELEASE="$lbmk_release"
|
haswell: only provide NRI-based ROMs in releases
release="n" is set in target.cfg on haswell build targets
that use mrc.bin
script/update/release exports LBMK_RELEASE="y"
script/build/roms skips building a given target if release="n"
in target.cfg *and* LBMK_RELEASE="y"
you could also do the export yourself before running ./build roms,
for example:
export LBMK_RELEASE="y"
./build roms all
This would skip these ROM images. The native haswell raminit is
now stable enough in my testing, that I wish to delete the MRC-based
targets. This is in line with Libreboot's Binary Blob Reduction Policy,
which states: if a blob can be avoided, it should be avoided.
The problem is that users often run the inject script in *lbmk* from
Git, instead of from the src release archive. I forsee some users
running this on modern lbmk with older release images. If the mrc-based
target isn't there, the user may use an NRI-based target name, and
think it works; they will insert without MRC. I foresaw this ages
ago, which is why Caleb and I ensured that the script checks hashes,
and hashes are included in releases.
Therefore: for the time being, keep the MRC-based configs in lbmk
but do not include images for them in releases. This can be done
indefinitely, but I'll probably remove those configs entirely at
some point.
On the following boards, Libreboot now will *only* provide NRI-based
ROM images for the following machines:
* Dell OptiPlex 9020 SFF
* Dell OptiPlex 9020 MT
* Lenovo ThinkPad T440p
* Lenovo ThinkPad W541/W540
I now recommend exclusive use of NRI-based images, on Haswell
hardware. It's stable enough in my testing, and now supports S3.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-04-24 04:27:27 +00:00
|
|
|
|
2024-04-27 15:46:31 +00:00
|
|
|
# if set to n via export, status checks will be skipped during
|
|
|
|
# all builds, and all targets will be built regardless of status.
|
|
|
|
# this replicates the old behaviour of lbmk, prior to the checks.
|
|
|
|
set | grep LBMK_STATUS 1>/dev/null 2>/dev/null && lbmk_status="$LBMK_STATUS"
|
|
|
|
[ "$lbmk_status" = "y" ] || [ "$lbmk_status" = "n" ] || lbmk_status="y"
|
|
|
|
export LBMK_STATUS="$lbmk_status"
|
|
|
|
|
lbmk: export TMPDIR from err.sh, not build
lbmk sets TMPDIR to /tmp, and then creates a tmpdir, then
exports *that* as the value of TMPDIR. this unified TMPDIR
location then contains all subsequent files and directories,
when any script or program makes use of /tmp, via mktemp. at
least, that's the theory!
in practise, because it was only being properly exported from
the main build scripts, subscripts that are then called were
not exporting it, at least that is my assumption because in
some cases, i found that the coreboot build system was leaving
errant files behind outside of our own TMPDIR, and that build
system did not seem to be setting TMPDIR itself; more debugging
is needed.
anyway: use the exact same logic, but do it from err.sh. since
err.sh is included from every lbmk script, that means it will
always be exported when running every single part of lbmk. this
should reduce the chance that mktemp creates files and directories
outside of our custom TMPDIR location.
this is because in lbmk, we mitigate unhandled tmpdirs/files by
unifying it in the manner described, then deleting the entire
TMPDIR on exit from the main lbmk parent process (the main
script that the user called from, which is always the "build"
file).
in lbmk, effort is made to clean up temporary files properly,
without relying on this catch-all, but we can't rely on that.
the catch-all should also be as robust as possible.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-04-25 18:08:53 +00:00
|
|
|
tmpdir_was_set="y"
|
|
|
|
set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n"
|
|
|
|
if [ "${tmpdir_was_set}" = "y" ]; then
|
|
|
|
[ "${TMPDIR%_*}" = "/tmp/lbmk" ] || tmpdir_was_set="n"
|
|
|
|
fi
|
|
|
|
if [ "${tmpdir_was_set}" = "n" ]; then
|
|
|
|
export TMPDIR="/tmp"
|
|
|
|
tmpdir="$(mktemp -d -t lbmk_XXXXXXXX)"
|
|
|
|
export TMPDIR="${tmpdir}"
|
|
|
|
else
|
|
|
|
export TMPDIR="${TMPDIR}"
|
|
|
|
tmpdir="${TMPDIR}"
|
|
|
|
fi
|
|
|
|
|
2023-10-01 05:33:43 +00:00
|
|
|
x_() {
|
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>
2024-03-27 01:19:39 +00:00
|
|
|
[ $# -lt 1 ] || ${@} || $err "Unhandled non-zero exit: $@"; return 0
|
2023-10-01 05:33:43 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 07:06:10 +00:00
|
|
|
check_git()
|
|
|
|
{
|
|
|
|
which git 1>/dev/null 2>/dev/null || \
|
2023-10-04 09:02:59 +00:00
|
|
|
git_err "git not installed. please install git-scm."
|
2023-10-04 07:06:10 +00:00
|
|
|
git config --global user.name 1>/dev/null 2>/dev/null || \
|
2023-10-04 08:57:42 +00:00
|
|
|
git_err "git config --global user.name \"John Doe\""
|
2023-10-04 07:06:10 +00:00
|
|
|
git config --global user.email 1>/dev/null 2>/dev/null || \
|
2023-10-04 08:57:42 +00:00
|
|
|
git_err "git config --global user.email \"john.doe@example.com\""
|
|
|
|
}
|
|
|
|
|
|
|
|
git_err()
|
|
|
|
{
|
2023-12-24 09:04:36 +00:00
|
|
|
printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2
|
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>
2024-03-27 01:19:39 +00:00
|
|
|
$err "Git name/email not configured"
|
2023-10-04 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_project()
|
|
|
|
{
|
2023-12-16 07:56:26 +00:00
|
|
|
read -r projectname < projectname || :
|
2023-10-04 07:06:10 +00:00
|
|
|
|
2023-12-16 07:56:26 +00:00
|
|
|
[ ! -f version ] || read -r version < version || :
|
2023-10-04 07:06:10 +00:00
|
|
|
version_="${version}"
|
|
|
|
[ ! -e ".git" ] || version="$(git describe --tags HEAD 2>&1)" || \
|
|
|
|
version="git-$(git rev-parse HEAD 2>&1)" || version="${version_}"
|
|
|
|
|
2023-12-16 07:56:26 +00:00
|
|
|
[ ! -f versiondate ] || read -r versiondate < versiondate || :
|
2023-10-04 07:06:10 +00:00
|
|
|
versiondate_="${versiondate}"
|
|
|
|
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
|
|
|
|
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
|
|
|
|
|
2023-12-23 16:16:26 +00:00
|
|
|
for p in projectname version versiondate; do
|
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>
2024-03-27 01:19:39 +00:00
|
|
|
eval "[ -n \"\$$p\" ] || $err \"$p unset\""
|
|
|
|
eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
|
2023-12-23 16:16:26 +00:00
|
|
|
done
|
2023-12-23 08:43:42 +00:00
|
|
|
export LOCALVERSION="-${projectname}-${version%%-*}"
|
2023-10-04 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
2023-09-30 17:41:57 +00:00
|
|
|
setvars()
|
|
|
|
{
|
|
|
|
_setvars=""
|
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>
2024-03-27 01:19:39 +00:00
|
|
|
[ $# -lt 2 ] && $err "setvars: too few arguments"
|
2023-12-23 16:16:26 +00:00
|
|
|
val="${1}" && shift 1
|
2023-09-30 17:41:57 +00:00
|
|
|
for var in $@; do
|
|
|
|
_setvars="${var}=\"${val}\"; ${_setvars}"
|
|
|
|
done
|
|
|
|
printf "%s\n" "${_setvars% }"
|
|
|
|
}
|
|
|
|
|
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>
2024-03-27 01:19:39 +00:00
|
|
|
err_()
|
2023-08-23 17:56:31 +00:00
|
|
|
{
|
|
|
|
printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|