lib.sh: more unified config handling

replace it with logic that simply uses "." to load
files directly.

config/git files are now directories, also containing
pkg.cfg files each with the same variables as before,
such as repository link and commit hash

this change results in a noticeable reduction in code
complexity within the build system.

unified reading of config files: new function setcfg()
added to lib.sh

setcfg checks if a config exists. if a 2nd argument is
passed, it is used as a return value for eval, otherwise
a string calling err is passed. setcfg output is passed
through eval, to set strings based on config; eval must
be used, so that the variables are set within the same
scope, otherwise they'd be set within setcfg which could
lead to some whacky results.

there's still a bit more more to do, but this single change
results in a substantial reduction in code complexity.

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2
Leah Rowe 2024-06-22 02:35:25 +01:00 committed by Leah Rowe
parent c72904b6d1
commit dec9ae9b43
28 changed files with 67 additions and 105 deletions

View File

@ -4,3 +4,4 @@ payload_seabios="y"
payload_seabios_withgrub="y"
payload_memtest="y"
grub_scan_disk="ahci"
vcfg="e6400"

View File

@ -0,0 +1,3 @@
rev="0a7bc1d71735ef97b00dfec0fd54a02fcc5d1bb0"
url="https://review.coreboot.org/bios_extract"
bkup_url="https://github.com/coreboot/bios_extract/"

View File

@ -0,0 +1,3 @@
rev="03ae0cf0706ede5a2a15da0986c19c776d0e6b26"
url="https://codeberg.org/libreboot/BIOSUtilities"
bkup_url="https://github.com/platomav/BIOSUtilities"

View File

@ -1,6 +0,0 @@
{coreboot}{
rev: HEAD
loc: coreboot/coreboot
url: https://review.coreboot.org/coreboot
bkup_url: https://github.com/coreboot/coreboot.git
}

View File

@ -0,0 +1,3 @@
rev="HEAD"
url="https://review.coreboot.org/coreboot"
bkup_url="https://github.com/coreboot/coreboot.git"

View File

@ -1,6 +0,0 @@
{docs}{
rev: e72d055915c3a9ffe739982946e101b146b2483c
loc: docs
url: https://codeberg.org/vimuser/untitled
bkup_url: https://notabug.org/untitled/untitled
}

3
config/git/docs/pkg.cfg Normal file
View File

@ -0,0 +1,3 @@
rev="e72d055915c3a9ffe739982946e101b146b2483c"
url="https://codeberg.org/vimuser/untitled"
bkup_url="https://notabug.org/untitled/untitled"

View File

@ -1,6 +0,0 @@
{flashprog}{
rev: 5b4fdd11dd74c7f018cb04f7a27a2badc02fe182
loc: flashprog
url: https://review.sourcearcade.org/flashprog
bkup_url: https://github.com/SourceArcade/flashprog.git
}

View File

@ -0,0 +1,3 @@
rev="5b4fdd11dd74c7f018cb04f7a27a2badc02fe182"
url="https://review.sourcearcade.org/flashprog"
bkup_url="https://github.com/SourceArcade/flashprog.git"

View File

@ -1,6 +0,0 @@
{grub}{
rev: HEAD
loc: grub/grub
url: git://git.savannah.gnu.org/grub.git
bkup_url: https://codeberg.org/libreboot/grub
}

3
config/git/grub/pkg.cfg Normal file
View File

@ -0,0 +1,3 @@
rev="HEAD"
url="git://git.savannah.gnu.org/grub.git"
bkup_url="https://codeberg.org/libreboot/grub"

View File

@ -1,6 +0,0 @@
{memtest86plus}{
rev: 5dcd424ea7afb857c1171e747ef064d98d26afeb
loc: memtest86plus
url: https://codeberg.org/libreboot/memtest86plus
bkup_url: https://github.com/memtest86plus/memtest86plus.git
}

View File

@ -0,0 +1,3 @@
rev="5dcd424ea7afb857c1171e747ef064d98d26afeb"
url="https://codeberg.org/libreboot/memtest86plus"
bkup_url="https://github.com/memtest86plus/memtest86plus.git"

View File

@ -1,6 +0,0 @@
{pico-sdk}{
rev: 6a7db34ff63345a7badec79ebea3aaef1712f374
loc: pico-sdk
url: https://codeberg.org/libreboot/pico-sdk
bkup_url: https://github.com/raspberrypi/pico-sdk
}

View File

@ -0,0 +1,3 @@
rev="6a7db34ff63345a7badec79ebea3aaef1712f374"
url="https://codeberg.org/libreboot/pico-sdk"
bkup_url="https://github.com/raspberrypi/pico-sdk"

View File

@ -1,7 +0,0 @@
{pico-serprog}{
rev: e75e3a20e63269a5e3189bc2e49a6a81d45a636a
loc: pico-serprog
url: https://codeberg.org/libreboot/pico-serprog
bkup_url: https://git.disroot.org/libreboot/pico-serprog
depend: pico-sdk
}

View File

@ -0,0 +1,4 @@
rev="e75e3a20e63269a5e3189bc2e49a6a81d45a636a"
url="https://codeberg.org/libreboot/pico-serprog"
bkup_url="https://git.disroot.org/libreboot/pico-serprog"
depend="pico-sdk"

View File

@ -1,6 +0,0 @@
{seabios}{
rev: HEAD
loc: seabios/seabios
url: https://review.coreboot.org/seabios
bkup_url: https://github.com/coreboot/seabios
}

View File

@ -0,0 +1,3 @@
rev="HEAD"
url="https://review.coreboot.org/seabios"
bkup_url="https://github.com/coreboot/seabios"

View File

@ -1,6 +0,0 @@
{stm32-vserprog}{
rev: 8fcf0a4d41800631b571fa7bbd1d8b251f0a2111
loc: stm32-vserprog
url: https://codeberg.org/libreboot/stm32-vserprog
bkup_url: https://git.disroot.org/libreboot/stm32-vserprog
}

View File

@ -0,0 +1,3 @@
rev="8fcf0a4d41800631b571fa7bbd1d8b251f0a2111"
url="https://codeberg.org/libreboot/stm32-vserprog"
bkup_url="https://git.disroot.org/libreboot/stm32-vserprog"

View File

@ -1,6 +0,0 @@
{u-boot}{
rev: HEAD
loc: u-boot/u-boot
url: https://source.denx.de/u-boot/u-boot.git
bkup_url: https://github.com/u-boot/u-boot.git
}

View File

@ -0,0 +1,3 @@
rev="HEAD"
url="https://source.denx.de/u-boot/u-boot.git"
bkup_url="https://github.com/u-boot/u-boot.git"

View File

@ -0,0 +1,3 @@
rev="4a41c33596e9bc3ae812e763965d91ac57553e02"
url="https://codeberg.org/libreboot/UEFITool"
bkup_url="https://github.com/LongSoft/UEFITool"

View File

@ -31,10 +31,8 @@ fetch_config()
load_target_config()
{
[ -f "$cfgsdir/$1/target.cfg" ] || $err "$1: target.cfg missing"
[ -f "$cfgsdir/$1/seen" ] && $err "$_xm cfg: infinite loop in trees"
. "$cfgsdir/$1/target.cfg" || $err "load_target_config !$cfgsdir/$1"
eval `setcfg "$cfgsdir/$1/target.cfg"`
touch "$cfgsdir/$1/seen" || $err "load_config $cfgsdir/$1: !mk seen"
}
@ -50,9 +48,9 @@ prepare_new_tree()
fetch_project_repo()
{
eval "$(setvars "" xtree tree_depend)"
eval `setcfg "config/git/$project/pkg.cfg"`
scan_config "$project" "config/git"
chkvars loc url
chkvars url
[ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \
x_ ./update trees -f coreboot "$xtree"
@ -63,14 +61,14 @@ fetch_project_repo()
clone_project
for x in config/git/*; do
[ -f "$x" ] && nuke "${x##*/}" "src/${x##*/}" 2>/dev/null
done
[ -d "$x" ] && nuke "${x##*/}" "src/${x##*/}" 2>/dev/null
done; return 0
}
clone_project()
{
loc="${loc#src/}"
loc="src/$loc"
loc="src/$project"
singletree "$project" || loc="src/$project/$project"
printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
e "$loc" d && return 0

View File

@ -60,9 +60,7 @@ read -r projectsite < projectsite || :
install_packages()
{
[ $# -lt 2 ] && badcmd "fewer than two arguments"
[ -f "config/dependencies/$2" ] || badcmd "unsupported target"
. "config/dependencies/$2" || $err "! . config/dependencies/$2"
eval `setcfg "config/dependencies/$2"`
$pkg_add $pkglist || $err "Cannot install packages"
@ -127,25 +125,6 @@ done
relname="$projectname-$version"
export LOCALVERSION="-$projectname-${version%%-*}"
scan_config()
{
awkstr=" /\{.*$1.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
confdir="$2"
revfile="$(mktemp -t sources.XXXXXXXXXX)"
cat "$confdir/"* > "$revfile" || $err "$confdir: can't cat files"
while read -r line ; do
set $line 1>/dev/null 2>/dev/null || :
if [ "${1%:}" = "depend" ]; then
depend="$depend $2"
else
eval "${1%:}=\"$2\""
fi
done << EOF
$(eval "awk '$awkstr' \"$revfile\"")
EOF
rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile"
}
check_defconfig()
{
[ -d "$1" ] || $err "Target '$1' not defined."
@ -253,3 +232,14 @@ cbfs()
lzma="-c lzma" && [ $# -gt 3 ] && lzma="-t raw"
x_ "$cbfstool" "$1" $ccmd -f "$2" -n "$3" $lzma
}
setcfg()
{
if [ $# -gt 1 ]; then
printf "e \"%s\" f missing && return %s;\n" "$1" "$2"
else
printf "e \"%s\" f missing && %s \"Missing config\";\n" "$1" \
"$err"
fi
printf ". \"%s\" || %s \"Could not read config\";\n" "$1" "$err"
}

View File

@ -91,10 +91,9 @@ configure_target()
board="$1"
targetdir="$cfgsdir/$board"
[ -f "$targetdir/target.cfg" ] || $err "$board: target.cfg missing"
# Override the above defaults using target.cfg
. "$targetdir/target.cfg"
eval `setcfg "$targetdir/target.cfg"`
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"

View File

@ -35,7 +35,7 @@ main()
[ -z "$_f" ] && $err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
[ -z "$project" ] && $err "project name not specified"
[ -f "config/git/$project" ] || $err "project '$project' not defined"
[ -f "config/git/$project/pkg.cfg" ] || $err "'$project' not defined"
elfdir="elf/$project"
datadir="config/data/$project"
@ -152,9 +152,7 @@ load_project_config()
{
eval "$(setvars "" xarch xlang tree bootstrapargs autoconfargs xtree \
tree_depend makeargs)"
[ -f "$1/target.cfg" ] || return 0
. "$1/target.cfg" || $err "loadp $1: can't load target.cfg"; return 0
eval `setcfg "$1/target.cfg" 0`; return 0
}
check_cross_compiler()
@ -272,15 +270,12 @@ check_makefile()
mkpayload_grub()
{
[ -f "$grubdata/module/$tree" ] || $err "$tree: grub modules missing"
x_ rm -f "$cdir/grub.elf"
eval "$(setvars "" grub_modules grub_install_modules)"
. "$grubdata/module/$tree" || $err "$tree: !source grub modules"
eval `setcfg "$grubdata/module/$tree"`
chkvars "grub_install_modules" "grub_modules"
x_ rm -f "$cdir/grub.elf"
"${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \
--fonts= --themes= --locales= --modules="$grub_modules" \
@ -288,7 +283,7 @@ mkpayload_grub()
"/boot/grub/grub_default.cfg=${cdir}/.config" \
"/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
"/background.png=$grubdata/background/background1280x800.png" || \
$err "$tree: cannot build grub.elf"
$err "$tree: cannot build grub.elf"; return 0
}
copy_elf()