roms: simplify main()

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2-merge1
Leah Rowe 2024-06-14 09:11:07 +01:00 committed by Leah Rowe
parent 250f59bfb1
commit 4ed6e41221
1 changed files with 28 additions and 33 deletions

View File

@ -23,38 +23,33 @@ pv="payload_uboot payload_grub_withseabios payload_seabios payload_memtest t"
pv="$pv payload_seabios_withgrub payload_seabios_grubonly payload_grub mt86bin" pv="$pv payload_seabios_withgrub payload_seabios_grubonly payload_grub mt86bin"
v="romdir cbrom initmode displaymode cbcfg targetdir tree keymaps release" v="romdir cbrom initmode displaymode cbcfg targetdir tree keymaps release"
v="$v grub_timeout ubdir board grub_scan_disk uboot_config grubtree grubelf" v="$v grub_timeout ubdir board grub_scan_disk uboot_config grubtree grubelf"
eval "$(setvars "n" $pv serprog)" eval "$(setvars "n" $pv)"
eval "$(setvars "" $v boards _displaymode _payload _keyboard all targets \ eval "$(setvars "" $v boards opt_d opt_p opt_k targets serprog_boards_dir opt_s)"
serprog_boards_dir _scandisk)"
main() main()
{ {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in if [ "$1" = "-d" ] || [ "$1" = "-p" ] || [ "$1" = "-k" ] || \
list) x_ items config/coreboot; return 0 ;; [ "$1" = "-s" ]; then
serprog) serprog="y"; shift 1; break ;; [ $# -lt 2 ] && $err "$1: option not specified"
-d) _displaymode="$2" ;; eval "opt_$1=\"$2\""; shift 2
-p) _payload="$2" ;; elif [ "$1" = "serprog" ]; then
-k) _keyboard="$2" ;; shift 1; handle_serprog $@; return 0
-s) _scandisk="$2" ;; elif [ "$1" = "list" ]; then
*) x_ items config/coreboot; return 0
[ "$1" = "all" ] && all="y" else
[ "$1" = "all" ] && shift && continue
boards="$1 $boards" boards="$1 $boards"
shift && continue ;; shift && continue
esac fi
shift 2
done done
if [ "$serprog" = "y" ]; then [ -n "$boards" ] || boards="$(items config/coreboot)" || \
handle_serprog $@; return 0 $err "Cannot generate list of boards for building"
else for x in $boards; do
[ "$all" != "y" ] || boards="$(items config/coreboot)" || \ [ -d "config/coreboot/$x/config" ] && \
$err "Cannot generate list of boards for building" handle_coreboot_target "$x"; continue
for x in $boards; do done
[ -d "config/coreboot/$x/config" ] && \
handle_coreboot_target "$x"; continue
done
fi
x="directories" x="directories"
[ "$xbmk_release" = "y" ] && x="archives" [ "$xbmk_release" = "y" ] && x="archives"
@ -150,7 +145,7 @@ configure_target()
# Override the above defaults using target.cfg # Override the above defaults using target.cfg
. "$targetdir/target.cfg" . "$targetdir/target.cfg"
[ -n "$_scandisk" ] && grub_scan_disk="$_scandisk" [ -n "$opt_s" ] && grub_scan_disk="$opt_s"
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata" [ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
eval "$(setvars "" _ata _ahci _nvme _grub_scan_disk)" eval "$(setvars "" _ata _ahci _nvme _grub_scan_disk)"
@ -196,11 +191,11 @@ configure_target()
uboot_config="default" uboot_config="default"
# Override all payload directives with cmdline args # Override all payload directives with cmdline args
[ -z "$_payload" ] && return 0 [ -z "$opt_p" ] && return 0
eval "$(setvars "n" payload_grub payload_memtest payload_seabios \ eval "$(setvars "n" payload_grub payload_memtest payload_seabios \
payload_seabios_withgrub payload_uboot payload_grub_withseabios \ payload_seabios_withgrub payload_uboot payload_grub_withseabios \
payload_seabios_grubonly)" payload_seabios_grubonly)"
eval "payload_$_payload=y" eval "payload_$opt_p=y"
} }
build_payloads() build_payloads()
@ -229,9 +224,9 @@ build_grub_payload()
for keymapfile in "$grubdata/keymap/"*.gkb; do for keymapfile in "$grubdata/keymap/"*.gkb; do
[ -f "$keymapfile" ] && keymaps="$keymaps $keymapfile" [ -f "$keymapfile" ] && keymaps="$keymaps $keymapfile"
done done
[ -z "$_keyboard" ] || [ -f "$grubdata/keymap/$_keyboard.gkb" ] || \ [ -z "$opt_k" ] || [ -f "$grubdata/keymap/${opt_k}.gkb" ] || \
$err "build_grub_payload: $_keyboard layout not defined" $err "build_grub_payload: ${opt_k} layout not defined"
[ -n "$_keyboard" ] && keymaps="$grubdata/keymap/$_keyboard.gkb" [ -n "$opt_k" ] && keymaps="$grubdata/keymap/$opt_k.gkb"
[ -f "$grubelf" ] || x_ ./update trees -b grub $grubtree; return 0 [ -f "$grubelf" ] || x_ ./update trees -b grub $grubtree; return 0
} }
@ -255,7 +250,7 @@ build_target_mainboard()
hmode="vesafb" hmode="vesafb"
[ "$initmode" = "vgarom" ] || hmode="corebootfb" [ "$initmode" = "vgarom" ] || hmode="corebootfb"
modes="$hmode txtmode" modes="$hmode txtmode"
[ -z "$_displaymode" ] || modes="$_displaymode" [ -z "$opt_d" ] || modes="$opt_d"
for y in $modes; do for y in $modes; do
displaymode="$y" displaymode="$y"
[ "$initmode" = "normal" ] && \ [ "$initmode" = "normal" ] && \
@ -341,7 +336,7 @@ build_grub_roms()
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 grubopt_s, $grub_scan_disk, $tmpcfg"
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"