roms: general code cleanup

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2
Leah Rowe 2024-06-23 00:15:19 +01:00 committed by Leah Rowe
parent 852eb1db4f
commit b72dfe11f9
1 changed files with 54 additions and 107 deletions

View File

@ -10,6 +10,8 @@ set -u -e
. "include/lib.sh" . "include/lib.sh"
tmprom="$tmpdir/rom"
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin" seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
cfgsdir="config/coreboot" cfgsdir="config/coreboot"
rp2040src="src/pico-serprog" rp2040src="src/pico-serprog"
@ -23,7 +25,7 @@ stm32dir="$stm32src/boards"
# Disable all payloads by default. # Disable all payloads by default.
# target.cfg files have to specifically enable [a] payload(s) # target.cfg files have to specifically enable [a] payload(s)
pv="payload_uboot payload_seabios payload_memtest t payload_grub" pv="payload_uboot payload_seabios payload_memtest t payload_grub"
v="romdir cbrom initmode displaymode cbcfg targetdir tree release ubootelf" v="romdir initmode displaymode cbcfg targetdir tree release ubootelf"
v="$v board grub_scan_disk uboot_config grubtree grubelf tmpmv" v="$v board grub_scan_disk uboot_config grubtree grubelf tmpmv"
eval `setvars "n" $pv` eval `setvars "n" $pv`
eval `setvars "" $v boards targets serdir ser` eval `setvars "" $v boards targets serdir ser`
@ -53,7 +55,7 @@ main()
for x in $boards; do for x in $boards; do
[ -n "$ser" ] && mkserprogfw "$ser" "$x" [ -n "$ser" ] && mkserprogfw "$ser" "$x"
[ -z "$ser" ] && [ -d "config/coreboot/$x/config" ] && \ [ -z "$ser" ] && [ -d "config/coreboot/$x/config" ] && \
configure_target "$x" && build_payloads && build_board && \ configure_target "$x" && build_board && \
[ -d "bin/$board" ] && targets="$targets, $x"; continue [ -d "bin/$board" ] && targets="$targets, $x"; continue
done done
@ -61,23 +63,18 @@ main()
mkrom_tarball "bin/serprog_$ser" && return 0 mkrom_tarball "bin/serprog_$ser" && return 0
[ -z "$ser" ] && [ -z "$targets" ] && $err "No images were compiled" [ -z "$ser" ] && [ -z "$targets" ] && $err "No images were compiled"
printf "DO NOT flash images from elf/ - use bin/ instead. ALSO:\n" printf "DO NOT flash from elf/ - use bin/ - ALSO:\n%s\n" "$kbnotice"
printf "%s\n" "$kbnotice"
} }
mkserprogfw() mkserprogfw()
{ {
x_ mkdir -p "bin/serprog_$1" x_ mkdir -p "bin/serprog_$1"
if [ "$1" = "rp2040" ]; then [ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$2" \
x_ cmake -DPICO_BOARD="$2" -DPICO_SDK_PATH="$picosdk" \ -DPICO_SDK_PATH="$picosdk" -B "$rp2040src/build" "$rp2040src" && \
-B "$rp2040src/build" "$rp2040src" x_ cmake --build "$rp2040src/build"
x_ cmake --build "$rp2040src/build" [ "$1" = "stm32" ] && x_ make -C "$stm32src" libopencm3-just-make \
else BOARD=$2 && x_ make -C "$stm32src" BOARD=$2
x_ make -C "$stm32src" libopencm3-just-make BOARD=$2
x_ make -C "$stm32src" BOARD=$2
fi
eval "x_ mv \"\$${1}x\" \"bin/serprog_$1/serprog_$2.\${${1}x##*.}\"" eval "x_ mv \"\$${1}x\" \"bin/serprog_$1/serprog_$2.\${${1}x##*.}\""
printf "Look in bin/serprog_%s/ for images\n" "$1"
} }
serlist() serlist()
@ -89,9 +86,8 @@ configure_target()
{ {
eval `setvars "n" $pv` eval `setvars "n" $pv`
eval `setvars "" $v` eval `setvars "" $v`
board="$1"
targetdir="$cfgsdir/$board" board="$1"; targetdir="$cfgsdir/$board"; romdir="bin/$board"
# Override the above defaults using target.cfg # Override the above defaults using target.cfg
eval `setcfg "$targetdir/target.cfg"` eval `setcfg "$targetdir/target.cfg"`
@ -100,6 +96,10 @@ configure_target()
[ "$xbmk_release" = "y" ] && [ "$release" = "n" ] && return 1 [ "$xbmk_release" = "y" ] && [ "$release" = "n" ] && return 1
[ "$board" = "$tree" ] && return 1 [ "$board" = "$tree" ] && return 1
cbdir="src/coreboot/$tree"
cbfstool="elf/cbfstool/$tree/cbfstool"
[ -f "$cbfstool" ] || x_ ./update trees -b coreboot utils $tree
[ -n "$uboot_config" ] || uboot_config="default" [ -n "$uboot_config" ] || uboot_config="default"
[ "$payload_uboot" = "y" ] || payload_seabios="y" [ "$payload_uboot" = "y" ] || payload_seabios="y"
[ "$payload_grub" = "y" ] && payload_seabios="y" [ "$payload_grub" = "y" ] && payload_seabios="y"
@ -112,29 +112,7 @@ configure_target()
grubelf="elf/grub/$grubtree/payload/grub.elf" grubelf="elf/grub/$grubtree/payload/grub.elf"
[ "$payload_memtest" = "y" ] || payload_memtest="n" [ "$payload_memtest" = "y" ] || payload_memtest="n"
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n" [ "$(uname -m)" = "x86_64" ] || payload_memtest="n"; return 0
[ "$payload_uboot" = "y" ] && payload_memtest="n"; return 0
}
build_payloads()
{
romdir="bin/$board"
cbdir="src/coreboot/$board"
[ "$board" = "$tree" ] || cbdir="src/coreboot/$tree"
cbfstool="elf/cbfstool/$tree/cbfstool"
cbrom="$cbdir/build/coreboot.rom"
[ -f "$cbfstool" ] || x_ ./update trees -b coreboot utils $tree
[ "$payload_memtest" = "y" ] && x_ ./update trees -b memtest86plus
[ "$payload_seabios" = "y" ] && x_ ./update trees -b seabios
[ "$payload_grub" = "y" ] && x_ ./update trees -b grub $grubtree
[ "$payload_uboot" = "y" ] || return 0
x_ ./update trees -b u-boot $board
ubdir="elf/u-boot/$board/$uboot_config"
ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
ubootelf="$ubdir/u-boot"
[ -f "$ubootelf" ] || $err "$board: Can't find u-boot"; return 0
} }
build_board() build_board()
@ -142,17 +120,15 @@ build_board()
x_ rm -Rf "$romdir" x_ rm -Rf "$romdir"
for it in "normal" "vgarom" "libgfxinit"; do for it in "normal" "vgarom" "libgfxinit"; do
initmode="$it" initmode="$it"; hmode="vesafb"
hmode="vesafb"
[ "$initmode" = "vgarom" ] || hmode="corebootfb" [ "$initmode" = "vgarom" ] || hmode="corebootfb"
modes="$hmode txtmode" modes="$hmode txtmode"
for y in $modes; do for dt in $modes; do
displaymode="$y" displaymode="$dt"; [ "$initmode" = "normal" ] && \
[ "$initmode" = "normal" ] && \
[ "$displaymode" != "txtmode" ] && continue [ "$displaymode" != "txtmode" ] && continue
cbcfg="$targetdir/config/${initmode}_$displaymode" cbcfg="$targetdir/config/${initmode}_$displaymode"
[ "$initmode" = "normal" ] && cbcfg="${cbcfg%_*}" [ "$initmode" = "normal" ] && cbcfg="${cbcfg%_*}"
e "$cbcfg" f not || build_roms; x_ rm -f "$cbrom" e "$cbcfg" f not || build_roms; x_ rm -f "$tmprom"
done done
done done
} }
@ -161,90 +137,61 @@ build_roms()
{ {
x_ ./update trees -b coreboot $board x_ ./update trees -b coreboot $board
_cbrom="$cbelfdir/$board/${initmode}_$displaymode" cbuild="$cbelfdir/$board/${initmode}_$displaymode"
[ "$initmode" = "normal" ] && _cbrom="${_cbrom%"_$displaymode"}" [ "$initmode" = "normal" ] && cbuild="${cbuild%"_$displaymode"}"
_cbrom="$_cbrom/coreboot.rom" x_ cp "$cbuild/coreboot.rom" "$tmprom"
cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
x_ cp "$_cbrom" "$cbrom"
[ "$payload_memtest" != "y" ] || cbfs "$cbrom" \
"elf/memtest86plus/memtest.bin" img/memtest
[ "$payload_seabios" = "y" ] && build_seabios_roms [ "$payload_seabios" = "y" ] && build_seabios_roms
[ "$payload_uboot" = "y" ] && x_ cp "$_cbrom" "$cbrom" && \ [ "$payload_uboot" = "y" ] || return 0
build_uboot_roms; return 0
x_ ./update trees -b u-boot $board
ubdir="elf/u-boot/$board/$uboot_config"
ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
ubootelf="$ubdir/u-boot"
[ -f "$ubootelf" ] || $err "$board: Can't find u-boot"
cbfs "$tmprom" "$ubootelf" "fallback/payload"
cprom "$romdir/uboot_payload_${board}_${initmode}_$displaymode.rom"
} }
build_seabios_roms() build_seabios_roms()
{ {
if [ "$payload_grub" = "y" ]; then # SeaBIOS with GRUB
t="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
x_ cp "$cbrom" "$t"
build_seagrub_roms "$t" "seabios_withgrub"
else # SeaBIOS only
t="$(mkSeabiosRom "$cbrom")" || \
$err "build_seabios_roms: cannot build tmprom"
newrom="$romdir/seabios_${board}_${initmode}_$displaymode"
[ "$initmode" = "normal" ] && newrom="$romdir/seabios" \
&& newrom="${newrom}_${board}_$initmode"
cprom cp "$t" "$newrom.rom"
fi
x_ rm -f "$t"
}
build_seagrub_roms()
{
tmpmv="$(mkSeabiosRom "$1")" || $err "$board: !mk grub tmprom"
x_ mv "$tmpmv" "$1"
# we only need insert grub.elf once, for each coreboot config:
cbfs "$1" "$grubelf" "img/grub2"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$tmpdir/tmpcfg" || $err "set grub_scan_disk, $grub_scan_disk"
cbfs "$1" "$tmpdir/tmpcfg" scan.cfg raw
newrom="$romdir/seabios_withgrub_${board}_${initmode}_$displaymode.rom"
[ "$initmode" = "normal" ] && newrom="$romdir/seabios_withgrub_" \
&& newrom="$newrom${board}_$initmode.rom"
cprom cp "$1" "$newrom"
cbfs "$1" "$grubdata/bootorder" bootorder raw # SeaGRUB
cprom cp "$1" "${newrom%.rom}_grubfirst.rom"
}
# make a rom in /tmp/ and then print the path of that ROM
mkSeabiosRom() {
tmprom="$(mktemp -t coreboot_rom.XXXXXXXXXX)" # 1=cbrom, 2=cbfs path
_seabioself="elf/seabios/default/$initmode/bios.bin.elf" _seabioself="elf/seabios/default/$initmode/bios.bin.elf"
x_ ./update trees -b seabios
pstr="seabios" && [ "$payload_grub" = "y" ] && pstr="seabios_withgrub"
newrom="$romdir/${pstr}_${board}_$initmode.rom"
[ "$initmode" = "normal" ] || newrom="${newrom%.rom}_$displaymode.rom"
x_ cp "$1" "$tmprom"
cbfs "$tmprom" "$_seabioself" "fallback/payload" cbfs "$tmprom" "$_seabioself" "fallback/payload"
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
z="2"; [ "$initmode" = "vgarom" ] && z="0" z="2"; [ "$initmode" = "vgarom" ] && z="0"
x_ "$cbfstool" "$tmprom" add-int -i $z -n etc/pci-optionrom-exec x_ "$cbfstool" "$tmprom" add-int -i $z -n etc/pci-optionrom-exec
x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
[ "$initmode" != "libgfxinit" ] || cbfs "$tmprom" "$seavgabiosrom" \ [ "$initmode" = "libgfxinit" ] && cbfs "$tmprom" "$seavgabiosrom" \
vgaroms/seavgabios.bin raw vgaroms/seavgabios.bin raw
printf "%s\n" "$tmprom" if [ "$payload_grub" = "y" ]; then
} x_ ./update trees -b grub $grubtree
cbfs "$tmprom" "$grubelf" "img/grub2"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$tmpdir/tmpcfg" || $err "$board: !insert scandisk"
cbfs "$tmprom" "$tmpdir/tmpcfg" scan.cfg raw
fi
build_uboot_roms() [ "$payload_memtest" = "y" ] && x_ ./update trees -b memtest86plus && \
{ cbfs "$tmprom" "elf/memtest86plus/memtest.bin" img/memtest
tmprom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
newrom="$romdir/uboot_payload_${board}_${initmode}_$displaymode.rom" cprom "$newrom" && [ "$payload_grub" = "y" ] && \
x_ cp "$cbrom" "$tmprom" cbfs "$tmprom" "$grubdata/bootorder" bootorder raw && \
cbfs "$tmprom" "$ubootelf" "fallback/payload" cprom "${newrom%.rom}_grubfirst.rom"; return 0
cprom mv "$tmprom" "$newrom"
} }
cprom() cprom()
{ {
printf "Creating target image: %s\n" "$3" printf "Creating target image: %s\n" "$1"
x_ mkdir -p "${1%/*}"; x_ cp "$tmprom" "$1"
x_ mkdir -p "${3%/*}"
x_ $1 "$2" "$3"
} }
main $@ main $@