From 355eb765ff47b0855a6f5655312608d3264e70bf Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sun, 27 Aug 2023 17:19:36 +0100
Subject: move resources/scripts/ to script/

Signed-off-by: Leah Rowe <leah@libreboot.org>
---
 script/build/boot/roms         | 112 ++++++++
 script/build/boot/roms_helper  | 613 +++++++++++++++++++++++++++++++++++++++++
 script/build/clean/cbutils     |  59 ++++
 script/build/clean/crossgcc    |  45 +++
 script/build/clean/seabios     |  48 ++++
 script/build/clean/u-boot      |  51 ++++
 script/build/command/options   |  31 +++
 script/build/coreboot/utils    |  78 ++++++
 script/build/descriptors/ich9m |  42 +++
 script/build/grub/payload      | 104 +++++++
 script/build/grub/utils        |  52 ++++
 script/build/release/roms      | 195 +++++++++++++
 script/build/release/src       | 193 +++++++++++++
 13 files changed, 1623 insertions(+)
 create mode 100755 script/build/boot/roms
 create mode 100755 script/build/boot/roms_helper
 create mode 100755 script/build/clean/cbutils
 create mode 100755 script/build/clean/crossgcc
 create mode 100755 script/build/clean/seabios
 create mode 100755 script/build/clean/u-boot
 create mode 100755 script/build/command/options
 create mode 100755 script/build/coreboot/utils
 create mode 100755 script/build/descriptors/ich9m
 create mode 100755 script/build/grub/payload
 create mode 100755 script/build/grub/utils
 create mode 100755 script/build/release/roms
 create mode 100755 script/build/release/src

(limited to 'script/build')

diff --git a/script/build/boot/roms b/script/build/boot/roms
new file mode 100755
index 00000000..a19d9445
--- /dev/null
+++ b/script/build/boot/roms
@@ -0,0 +1,112 @@
+#!/usr/bin/env sh
+
+#
+#  helper script: build coreboot images with various payloads
+#
+#	Copyright (C) 2014,2015,2016,2020,2021,2023 Leah Rowe
+#							<info@minifree.org>
+#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
+#	Copyright (C) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
+#	Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# This script assumes that the working directory is the root
+# of git or release archive
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+projectname="$(cat projectname)"
+opts=""
+boards=
+firstoption=""
+
+main()
+{
+	[ $# -lt 1 ] && usage && err "target not specified"
+
+	firstoption="${1}"
+	[ "${firstoption}" = "help" ] && usage && exit 0
+	[ "${firstoption}" = "list" ] && \
+	    ./build command options resources/coreboot && exit 0
+
+	while [ $# -gt 0 ]; do
+		case ${1} in
+		-d)
+			opts="${opts} -d ${2}"
+			shift ;;
+		-p)
+			opts="${opts} -p ${2}"
+			shift ;;
+		-k)
+			opts="${opts} -k ${2}"
+			shift ;;
+		*)
+			boards="${boards} ${1} " ;;
+		esac
+		shift
+	done
+
+	[ -z ${opts+x} ] && opts=""
+	printf "Building %s ROM images\n" "${projectname}"
+
+	if [ "${firstoption}" = "all" ]; then
+		for target in $(./build command options resources/coreboot); do
+			buildrom "${target}" || err "build/roms (1): error"
+		done
+	else
+		for board in ${boards}; do
+			buildrom "${board}" || err "build/roms (2): error"
+		done
+	fi
+
+	printf "\n\nDone! Your ROMs are in bin/\n\n"
+}
+
+usage()
+{
+	cat <<- EOF
+	USAGE:	./build boot roms target
+	To build *all* boards, do this: ./build boot roms all
+	To list *all* boards, do this: ./build boot roms list
+	
+	Optional Flags:
+	-d: displaymode
+	-p: payload
+	-k: keyboard layout
+
+	Example commands:
+		./build boot roms x60
+		./build boot roms x200_8mb x60
+		./build boot roms x60 -p grub -d corebootfb -k usqwerty
+
+	possible values for 'target':
+	$(./build command options "resources/coreboot")
+
+	Refer to the ${projectname} documentation for more information.
+	EOF
+}
+
+# Build ROM images for supported boards
+buildrom() {
+	[ -d "resources/coreboot/${1}/" ] || \
+		err "build/roms: target not defined: ${1}"
+	./build boot roms_helper ${1}${opts} || return 1
+}
+
+main $@
diff --git a/script/build/boot/roms_helper b/script/build/boot/roms_helper
new file mode 100755
index 00000000..79e86ad4
--- /dev/null
+++ b/script/build/boot/roms_helper
@@ -0,0 +1,613 @@
+#!/usr/bin/env sh
+
+#  helper script: create ROM images for a given mainboard
+#
+#	Copyright (C) 2020,2021,2023 Leah Rowe <info@minifree.org>
+#	Copyright (C) 2021,2022 Ferass El Hafidi
+#				<vitali64pmemail@protonmail.com>
+#	Copyright (C) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
+#	Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
+#	Copyright (C) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# This script assumes that the working directory is the root
+# of git or release archive
+
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+projectname="$(cat projectname)"
+
+blobs_required=""
+microcode_required=""
+
+board=""
+ubdir=""
+kmapdir="resources/grub/keymap"
+displaymodes=""
+payloads=""
+keyboard_layouts=""
+while [ $# -gt 0 ]; do
+	case ${1} in
+	-d)
+		displaymodes="${displaymodes}${2}" 
+		shift ;;
+	-p)
+		payloads="${payloads}${2}"
+		shift ;;
+	-k)
+		keyboard_layouts="${keyboard_layouts}${2}"
+		shift ;;
+	*)
+		board=${1} ;;
+	esac
+	shift
+done
+
+printf "\n\nboard is %s , kb is %s , displaymode is %s , payloads is %s\n" \
+		${board} ${keyboard_layouts} ${displaymodes} ${payloads} 1>&2
+
+[ -d "resources/coreboot/${board}" ] || \
+	err "Target not defined: ${board}"
+
+[ -f "resources/coreboot/${board}/target.cfg" ] || \
+	err "Missing target.cfg for target: ${board}"
+
+grub_scan_disk="undefined"
+tree="undefined"
+romtype="normal" # optional parameter in target.cfg. "normal" is default
+arch="undefined"
+
+# Disable all payloads by default.
+# target.cfg files have to specifically enable [a] payload(s)
+payload_grub="n"
+payload_grub_withseabios="n" # seabios chainloaded from grub
+payload_seabios="n"
+payload_seabios_withgrub="n" # i386-coreboot grub from SeaBIOS boot menu
+payload_memtest="n"
+payload_uboot="n"
+uboot_config="undefined"
+# Override the above defaults using target.cfg
+. "resources/coreboot/${board}/target.cfg"
+
+[ "${grub_scan_disk}" = "undefined" ] && \
+	grub_scan_disk="both"
+[ "${grub_scan_disk}" != "both" ] && [ "${grub_scan_disk}" != "ata" ] && \
+    [ "${grub_scan_disk}" != "ahci" ] && \
+	grub_scan_disk="both"
+
+[ "${tree}" = "undefined" ] && \
+	err "Target '${board}' does not define a coreboot tree. Skipping build."
+[ "${arch}" = "undefined" ] && \
+	err "Target '${board}' does not define a CPU type. Skipping build."
+
+[ "${payload_memtest}" != "y" ] && \
+	payload_memtest="n"
+[ "${payload_grub_withseabios}" = "y" ] && \
+	payload_grub="y"
+if [ "${payload_grub_withseabios}" = "y" ]; then
+	payload_seabios="y"
+	payload_seabios_withgrub="y"
+fi
+[ "${payload_seabios_withgrub}" = "y" ] && \
+	payload_seabios="y"
+
+# NOTE: reverse logic must NOT be applied. If SeaBIOS-with-GRUB works, that
+# doesn't necessarily mean GRUb-with-SeaBIOS will. For example, the board
+# might have an external GPU, where it's recommended to boot SeaBIOS first
+if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] && \
+    [ "${payload_uboot}" != "y" ]; then
+	for configfile in "resources/coreboot/${board}/config/"*; do
+		[ -e "${configfile}" ] || continue
+		err "target '${board}' defines no payload"
+	done
+fi
+
+[ "${payload_uboot}" != "n" ] && [ "${payload_uboot}" != "y" ] && \
+	payload_uboot="n"
+[ "${payload_uboot}" = "y" ] && [ "${uboot_config}" = "undefined" ] && \
+	uboot_config="default"
+
+[ "${microcode_required}" != "n" ] && [ "${microcode_required}" != "y" ] && \
+	microcode_required="y"
+[ "${blobs_required}" != "n" ] && [ "${blobs_required}" != "y" ] && \
+	blobs_required="y"
+
+# Override all payload directives with cmdline args
+if [ ! -z ${payloads} ]; then	
+	echo "setting payloads $payloads"
+	payload_grub="n"
+	payload_grub_withseabios="n" # seabios chainloaded from grub
+	payload_seabios="n"
+	payload_seabios_withgrub="n" # i386-coreboot grub from SeaBIOS menu
+	payload_uboot="n"
+	payload_memtest="n"
+
+	for payload in ${payloads} ; do
+		eval "payload_${payload}=y"
+	done
+fi 
+
+romdir="bin/${board}"
+cbdir="coreboot/${board}"
+[ "${board}" = "${tree}" ] || \
+	cbdir="coreboot/${tree}"
+cbfstool="cbutils/${tree}/cbfstool"
+corebootrom="${cbdir}/build/coreboot.rom"
+seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
+
+./build coreboot utils ${tree} || err "cannot build cbutils/${tree}"
+
+if [ ! -f "${seavgabiosrom}" ] \
+    || [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \
+    || [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \
+    || [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then
+	[ "${payload_seabios}" != "y" ] || \
+		./handle make config -b seabios || \
+		    err "cannot build seabios"
+fi
+
+memtest_bin="memtest86plus/build${arch#*_}/memtest.bin"
+[ "${payload_memtest}" != "y" ] || [ -f "${memtest_bin}" ] || \
+	./handle make file -b ${memtest_bin%/*} || \
+	    err "cannot build memtest86+"
+
+[ -d "${romdir}/" ] || mkdir -p "${romdir}/" || \
+    err "cannot create rom directory: \"${romdir}\""
+rm -f "${romdir}"/* || err "cannot: rm -f \"${romdir}\"/*"
+
+if [ "${payload_grub}" = "y" ] || \
+    [ "${payload_seabios_withgrub}" = "y" ]; then
+	if [ -f "elf/grub/grub_usqwerty.cfg" ]; then
+		sha1sumcmd="sha1sum resources/grub/config/grub.cfg"
+		grubrefchecksum="$(${sha1sumcmd} | awk '{print $1}')"
+
+		sha1sumcmd="sha1sum elf/grub/grub_usqwerty.cfg"
+		grubbuildchecksum="$(${sha1sumcmd} | awk '{print $1}')"
+
+		if [ "${grubrefchecksum}" != "${grubbuildchecksum}" ]; then
+			printf "Changes detected to GRUB. Re-building now.\n" \
+			    1>&2
+		fi
+	else
+		printf "Required GRUB payloads not yet built. Building now.\n" \
+		    1>&2
+	fi
+	for keymapfile in "${kmapdir}"/*; do
+		[ -f "${keymapfile}" ] || continue
+
+		keymap="${keymapfile##*/}"
+		keymap="${keymap%.gkb}"
+
+		grubelf="elf/grub/grub_${keymap}.elf"
+		grubcfg="elf/grub/grub_${keymap}.cfg"
+		grubtestcfg="elf/grub/grub_${keymap}_test.cfg"
+
+		if [ ! -f "${grubelf}" ] || [ ! -f "${grubcfg}" ] || \
+		    [ ! -f "${grubtestcfg}" ]; then
+			./build grub payload || err "cannot build grub payload"
+		fi
+	done
+fi
+
+if [ "${payload_uboot}" = "y" ]; then
+	./handle make config -b u-boot ${board} || \
+	    err "cannot build u-boot target: ${board}"
+	ubdir="elf/u-boot/${board}/${uboot_config}"
+	ubootelf="${ubdir}/u-boot.elf"
+	[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot.bin" ] && \
+		ubootelf="${ubdir}/u-boot.bin"
+	[ -f "${ubootelf}" ] || \
+		err "Could not find u-boot build for board, ${board}"
+fi
+
+# it is assumed that no other work will be done on the ROM
+# after calling this function. therefore this function is "final"
+moverom() {
+	rompath="$1"
+	newrompath="$2"
+	cuttype="$3"
+
+	[ "${blobs_required}" = "n" ] && \
+		newrompath="${newrompath%.rom}_noblobs.rom"
+
+	printf "\nCreating new ROM image: %s\n" "${newrompath}"
+
+	if [ "${cuttype}" = "4MiB IFD BIOS region" ]; then
+		dd if="${rompath}" of="${newrompath}" bs=1 \
+		    skip=$(($(stat -c %s "${rompath}") - 0x400000)) \
+		    count=4194304 || err "moverom: cannot cut 4MB section"
+	else
+		cp "${rompath}" "${newrompath}" || err "moverom: can't copy rom"
+	fi
+
+	# pike2008 cards cause a system hang when loading option roms in seabios
+	# if there is an empty option rom in cbfs, no option rom will be loaded
+	if [ "${cuttype}" = "d8d16sas" ]; then
+		emptyrom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+		rm -f "${emptyrom}" || err "cannot remove fake oprom"
+		touch "${emptyrom}" || err "cannot create fake oprom"
+		for deviceID in "0072" "3050"; do
+			"${cbfstool}" "${newrompath}" add -f "${emptyrom}" \
+			    -n "pci1000,${deviceID}.rom" -t raw || \
+			    err "moverom: cannot insert fake pike2008 rom"
+		done
+		rm -f "${emptyrom}" || err "moverom: cannot remove pike2008 rom"
+	fi
+
+	for romsize in 4 8 16; do
+		ifdgbe="descriptors/ich9m/ich9fdgbe_${romsize}m.bin"
+		if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOR flash" ]; then
+			[ -f "${ifdgbe}" ] || \
+				./build descriptors ich9m || \
+				    err "moverom: cannot create ich9m ifd"
+			dd if="${ifdgbe}" of="${newrompath}" bs=1 count=12k \
+			    conv=notrunc || err "moverom: cant insert ich9m ifd"
+		fi
+		cmpstr="${romsize}MiB ICH9 IFD NOGBE NOR flash"
+		ifdgbe="descriptors/ich9m/ich9fdnogbe_${romsize}m.bin"
+		if [ "${cuttype}" = "${cmpstr}" ]; then
+			[ -f "${ifdgbe}" ] || \
+				./build descriptors ich9m || \
+				    err "moverom: cannot create ich9m ifd"
+			dd if="${ifdgbe}" of="${newrompath}" bs=1 count=4k \
+			    conv=notrunc || err "moverom: cant insert ich9m ifd"
+		fi
+	done
+
+	if [ "${cuttype}" = "i945 laptop" ]; then
+		dd if="${newrompath}" of=top64k.bin bs=1 \
+		    skip=$(($(stat -c %s "${newrompath}") - 0x10000)) \
+		    count=64k || \
+		    err "moverom: cannot copy boot block from i945 rom"
+		dd if=top64k.bin of="${newrompath}" bs=1 \
+		    seek=$(($(stat -c %s "${newrompath}") - 0x20000)) \
+		    count=64k conv=notrunc || \
+		    err "moverom: cannot copy boot block into i945 rom"
+		rm -f top64k.bin || err "moverom: can't remove top64k.bin"
+	fi
+
+	if [ "${microcode_required}" = "n" ]; then
+		_newrom_b="${newrompath%.rom}_nomicrocode.rom"
+		cp "${newrompath}" "${_newrom_b}" || \
+		    err "moverom: cp \"${newrompath}\" \"${_newrom_b}\""
+		microcode_present="y"
+		"${cbfstool}" "${_newrom_b}" remove -n \
+		    cpu_microcode_blob.bin || microcode_present="n"
+		if [ "${microcode_present}" = "n" ]; then
+			rm -f "${_newrom_b}" || err "cannot remove ${_newrom_b}"
+			printf "REMARK: '%s' already lacks microcode\n" \
+			    "${newrompath}"
+			printf "Renaming default ROM file instead.\n"
+			mv "${newrompath}" "${_newrom_b}" || \
+			    err "moverom: mv \"${newrompath}\" \"${_newrom_b}\""
+		fi
+	fi
+}
+
+# make a rom in /tmp/ and then print the path of that ROM
+mkSeabiosRom() {
+	target_cbrom="${1}" # rom to insert seabios in. will not be touched
+		# (a tmpfile will be made instead)
+	target_seabios_cbfs_path="${2}" # e.g. fallback/payload
+	target_initmode="${3}" # e.g. libgfxinit
+
+	target_seabioself="elf/seabios/default/${target_initmode}/bios.bin.elf"
+
+	tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+
+	cp "${target_cbrom}" "${tmprom}" || \
+	    err "mkSeabiosRom: cannot copy to tmprom"
+
+	"${cbfstool}" "${tmprom}" add-payload -f "${target_seabioself}" \
+	    -n ${target_seabios_cbfs_path} -c lzma || \
+	    err "mkSeabiosRom: can't add payload, ${target_seabioself}, to rom"
+
+	"${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup \
+	    || err "mkSeabiosRom: cbfs add-int etc/ps2-keyboard-spinup 3000"
+
+	if [ "${target_initmode}" = "normal" ] || \
+	    [ "${target_initmode}" = "libgfxinit" ]; then
+		"${cbfstool}" "${tmprom}" add-int -i 2 \
+		    -n etc/pci-optionrom-exec || \
+		    err "mkSeabiosRom: cbfs add-int etc/pci-optionrom-exec 2"
+	elif [ "${target_initmode}" = "vgarom" ]; then # coreboot executes it
+		"${cbfstool}" "${tmprom}" add-int -i 0 \
+		    -n etc/pci-optionrom-exec || \
+		    err "mkSeabiosRom: cbfs add-int etc/pci-optionrom-exec 0"
+	fi # for undefined modes, don't add this integer. use SeaBIOS defaults
+
+	"${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum || \
+	    err "mkSeabiosRom: cbfs add-int etc/optionroms-checksum 0"
+
+	[ "${target_initmode}" != "libgfxinit" ] || \
+		"${cbfstool}" "${tmprom}" add -f "${seavgabiosrom}" \
+		    -n vgaroms/seavgabios.bin -t raw || \
+		    err "mkSeabiosRom: cbfs add-raw vgaroms/seavgabios.bin"
+
+	printf "%s\n" "${tmprom}"
+}
+
+# make a rom in /tmp/ and then print the path of that ROM
+mkUbootRom() {
+	target_cbrom="${1}" # rom to insert u-boot in. it won't be touched
+		# (a tmpfile will be made instead)
+	target_uboot_cbfs_path="${2}" # e.g. fallback/payload
+	target_uboot_config="${3}"
+	cbfstool_path="${4}"
+
+	target_ubdir="elf/u-boot/${board}/${target_uboot_config}"
+	target_ubootelf="${target_ubdir}/u-boot.elf"
+	[ -f "${target_ubootelf}" ] || \
+		target_ubootelf="${target_ubdir}/u-boot.bin"
+	[ -f "${target_ubootelf}" ] || \
+		err "mkUbootRom: cant find u-boot build for board, ${board}"
+
+	tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+
+	cp "${target_cbrom}" "${tmprom}" || \
+	    err "mkUbootRom: cannot copy to tmprom"
+	"${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" \
+	    -n ${target_uboot_cbfs_path} -c lzma || \
+	    err "mkUbootRom: cannot add u-boot to tmprom"
+
+	printf "%s\n" "${tmprom}"
+}
+
+# make a rom in /tmp/ and then print the path of that ROM
+mkGrubRom() {
+	target_keymap="${1}"
+	target_cbrom="${2}"
+	target_grubelf_cbfs_path="${3}" # e.g. fallback/payload
+
+	grubelf="elf/grub/grub_${target_keymap}.elf"
+	grubcfg="elf/grub/grub_${target_keymap}.cfg"
+	grubtestcfg="elf/grub/grub_${target_keymap}_test.cfg"
+
+	tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || \
+	    err "mkGrubRom: cannot create tmprom"
+	cp "${target_cbrom}" "${tmprom}" || \
+	    err "mkGrubRom: cannot copy to tmprom"
+
+	"${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" \
+	    -n ${target_grubelf_cbfs_path} -c lzma || \
+	    err "mkGrubRom: cannot add grub payload to tmprom"
+
+	tmpgrubcfg=$(mktemp -t grub.cfg.XXXXXXXXXX)
+	tmpgrubtestcfg=$(mktemp -t grubtest.cfg.XXXXXXXXXX)
+	if [ "${grub_scan_disk}" = "ahci" ]; then
+		sed \
+		's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' \
+		    "${grubcfg}" > "${tmpgrubcfg}" || err "mkGrubRom: sed1"
+		sed \
+		's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' \
+		    "${grubtestcfg}" > "${tmpgrubtestcfg}" || \
+		    err "mkGrubRom: sed2"
+	elif [ "${grub_scan_disk}" = "ata" ]; then
+		sed \
+		's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' \
+		    "${grubcfg}" > "${tmpgrubcfg}" || err "mkGrubRom: sed3"
+		sed \
+		's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' \
+		    "${grubtestcfg}" > "${tmpgrubtestcfg}" || \
+		    err "mkGrubRom: sed4"
+	else
+		cp "${grubcfg}" "${tmpgrubcfg}" || err "mkGrubRom: grub.cfg cp"
+		cp "${grubtestcfg}" "${tmpgrubtestcfg}" || \
+		    err "mkGrubRom: grubtest.cfg cp"
+	fi
+
+	"${cbfstool}" "${tmprom}" add -f "${tmpgrubcfg}" -n grub.cfg -t raw || \
+	    err "mkGrubRom: cannot add grub.cfg to tmprom"
+
+	"${cbfstool}" "${tmprom}" add -f "${tmpgrubtestcfg}" -n grubtest.cfg \
+	    -t raw || err "mkGrubRom: cannot add grubtest.cfg to tmprom"
+	rm -f "${tmpgrubcfg}" "${tmpgrubtestcfg}" || \
+	    err "mkGrubRom: cannot remove tmp grub.cfg / grubtest.cfg"
+
+	backgroundfile="background1280x800.png"
+	if [ "${board}" = "x60" ] || [ "${board}" = "t60_intelgpu" ]; then
+		# TODO: don't hardcode this. do it in target.cfg per board
+		backgroundfile="background1024x768.png"
+	fi
+	backgroundfile="resources/grub/background/${backgroundfile}"
+	"${cbfstool}" "${tmprom}" add -f ${backgroundfile} -n background.png \
+	    -t raw || err "mkGrubRom: cannot add background.png to tmprom"
+
+	printf "%s\n" "${tmprom}"
+}
+
+# Make separate ROM images with GRUB payload, for each supported keymap
+mkRomsWithGrub() {
+	tmprompath="${1}"
+	initmode="${2}"
+	displaymode="${3}"
+	firstpayloadname="${4}" # allow values: grub, seabios, seabios_withgrub
+
+	x=${tmprompath}
+	y=${initmode}
+	if [ "${payload_grub_withseabios}" = "y" ] && \
+	    [ "${firstpayloadname}" = "grub" ]; then
+		mv "$(mkSeabiosRom "${x}" "seabios.elf" "${y}")" "${tmprompath}"
+	elif [ "${payload_seabios_withgrub}" ] && \
+	    [ "${firstpayloadname}" != "grub" ]; then
+		mv "$(mkSeabiosRom "${x}" "fallback/payload" "$y")" \
+		    "${tmprompath}" || \
+		    err "mkRomsWithGrub: cannot move SeaBIOS ROM to tmprom"
+	fi	
+
+	keymaps=""
+	if [ -z ${keyboard_layouts} ]; then
+		for kmapfile in "${kmapdir}"/*; do
+			keymaps="${keymaps} ${kmapfile}"
+		done
+	else
+		for keymapname in ${keyboard_layouts}; do
+			keymaps="${keymaps} ${kmapdir}/${keymapname}.gkb"
+		done
+	fi
+	for keymapfile in ${keymaps}; do
+		echo "keymaps is $keymaps, keymapfile is $keymapfile"
+
+		[ -f "${keymapfile}" ] || continue
+
+		keymap="${keymapfile##*/}"
+		keymap="${keymap%.gkb}"
+
+		grub_path_in_cbfs="fallback/payload"
+		[ "${firstpayloadname}" = "grub" ] || \
+			grub_path_in_cbfs="img/grub2"
+
+		# evil bofh rfc 2646 compliance hack
+		x=${keymap}
+		y=${tmprompath}
+		z=${grub_path_in_cbfs}
+
+		tmpgrubrom="$(mkGrubRom "${x}" "${y}" "${z}")"
+
+		if [ "${initmode}" = "normal" ]; then
+			newrompath="${romdir}/${firstpayloadname}_${board}_"
+			newrompath="${newrompath}${initmode}_${keymap}.rom"
+		else
+			newrompath="${romdir}/${firstpayloadname}_${board}_"
+			newrompath="${newrompath}${initmode}_${displaymode}_"
+			newrompath="${newrompath}${keymap}.rom"
+		fi
+		moverom "${tmpgrubrom}" "${newrompath}" "${romtype}" || \
+		    err "mkRomsWithGrub, moverom"
+		rm -f "${tmpgrubrom}" || err "rm tmpgrubrom, mkRomsWithGrub"
+	done
+}
+
+# Main ROM building function. This calls all other functions
+mkRoms()
+{
+	cbcfgpath="${1}"
+	displaymode="${2}"
+	initmode="${3}"
+
+	if [ ! -f "${cbcfgpath}" ]; then
+		printf "'%s' does not exist. Skipping build for %s %s %s\n" \
+		    "${cbcfgpath}" "${board}" "${displaymode}" "${initmode}" \
+		    1>&2
+		return 0
+	fi
+
+	./handle make config -b coreboot ${board} || \
+	    err "mkRoms: cannot build coreboot for target: ${board}"
+
+	_corebootrom="elf/coreboot/${board}/${initmode}_${displaymode}"
+	[ "${initmode}" = "normal" ] && \
+		_corebootrom="${_corebootrom%_${displaymode}}"
+	_corebootrom="${_corebootrom}/coreboot.rom"
+	corebootrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
+	cp "${_corebootrom}" "${corebootrom}" || err "mkRoms: cannot copy rom"
+
+	if [ "${payload_memtest}" = "y" ]; then
+		"${cbfstool}" "${corebootrom}" add-payload \
+		    -f "${memtest_bin}" -n img/memtest -c lzma || \
+		    err "mkRoms: cannot add img/memtest to coreboot rom"
+	fi
+
+	if [ "${payload_seabios}" = "y" ]; then
+		if [ "${payload_seabios_withgrub}" = "n" ]; then
+			x=${corebootrom}
+			y=${initmode}
+			t=$(mkSeabiosRom "$x" "fallback/payload" "$y")
+			if [ "${initmode}" = "normal" ]; then
+				newrompath="${romdir}/seabios_${board}_"
+				newrompath="${newrompath}${initmode}.rom"
+			else
+				newrompath="${romdir}/seabios_${board}_"
+				newrompath="${newrompath}${initmode}_"
+				newrompath="${newrompath}${displaymode}.rom"
+			fi
+
+			moverom "${t}" "${newrompath}" "${romtype}" || \
+			    err "mkRoms: cannot copy rom"
+			rm -f "${t}" || err "cannot rm ${t}"
+		else
+			tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+			cp "${corebootrom}" "${tmprom}"
+			mkRomsWithGrub "${tmprom}" "${initmode}" \
+			    "${displaymode}" "seabios_withgrub" || \
+			    err "mkRoms: cannot build grub roms, seabios w/grub"
+			rm -f "${tmprom}" || err "mkRoms: can't remove tmprom"
+		fi
+	fi
+
+	[ "${payload_grub}" != "y" ] || \
+		mkRomsWithGrub "${corebootrom}" "${initmode}" \
+		    "${displaymode}" "grub" || \
+		    err "mkRoms: mkRomsWithGrub failed"
+
+	if [ "${payload_uboot}" = "y" ]; then
+		x=${corebootrom}
+		y=${uboot_config}
+		z=${cbfstool}
+		tmpubootrom="$(mkUbootRom "$x" "fallback/payload" "$y" "$z")"
+		if [ "${initmode}" = "normal" ]; then
+			newrompath="${romdir}/uboot_payload_${board}_"
+			newrompath="${newrompath}${initmode}.rom"
+		else
+			newrompath="${romdir}/uboot_payload_${board}_"
+			newrompath="${newrompath}${initmode}_${displaymode}.rom"
+		fi
+		moverom "${tmpubootrom}" "${newrompath}" "${romtype}" || \
+		    err "mkRoms: moverom fail (u-boot)"
+		rm -f "${tmpubootrom}" || err "mkRoms: cannot rm u-boot rom"
+	fi
+}
+
+if [ -z ${displaymodes} ]; then
+	initmode="libgfxinit"
+	for displaymode in corebootfb txtmode; do
+		cbcfgpath="resources/coreboot/${board}/config/${initmode}_"
+		cbcfgpath="${cbcfgpath}${displaymode}"
+		mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
+	done
+	
+	initmode="vgarom"
+	for displaymode in vesafb txtmode; do	
+		cbcfgpath="resources/coreboot/${board}/config/${initmode}_"
+		cbcfgpath="${cbcfgpath}${displaymode}"
+		mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
+	done
+	
+	initmode="normal"
+	displaymode="txtmode"
+	cbcfgpath="resources/coreboot/${board}/config/${initmode}"
+	mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
+
+else
+	echo "special displaymode defined as $displaymodes"
+	initmode="libgfxinit"
+	for displaymode in ${displaymodes}; do
+		cbcfgpath="resources/coreboot/${board}/config/${initmode}_"
+		cbcfgpath="${cbcfgpath}${displaymode}"
+		mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
+	done
+
+	initmode="vgarom"
+	for displaymode in ${displaymodes}; do
+		cbcfgpath="resources/coreboot/${board}/config/${initmode}_"
+		cbcfgpath="${cbcfgpath}${displaymode}"
+		mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
+	done
+fi
diff --git a/script/build/clean/cbutils b/script/build/clean/cbutils
new file mode 100755
index 00000000..bdacc45a
--- /dev/null
+++ b/script/build/clean/cbutils
@@ -0,0 +1,59 @@
+#!/usr/bin/env sh
+
+#  helper script: clean the dependencies that were built in coreboot
+#
+#	Copyright (C) 2014-2016, 2020, 2023 Leah Rowe <info@minifree.org>
+#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# This script assumes that the current working directory is the root
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+main()
+{
+	printf "Cleaning the previous build of coreboot and its utilities\n"
+
+	rm -Rf cbutils || err "cannot remove cbutils/"
+	[ ! -d "coreboot/" ] && exit 0
+
+	clean_cbutils
+}
+
+clean_cbutils()
+{
+	for tree in coreboot/*; do
+		[ "${tree##*/}" = "coreboot" ] && continue
+		[ -d "${tree}" ] || continue
+
+		# Clean coreboot, of course
+		make -C "${tree}/" distclean || \
+		    err "clean_cbutils: ${tree}: cannot distclean"
+
+		# Clean its utilities as well
+		for util in cbfstool ifdtool nvramtool cbmem; do
+			make distclean -C "${tree}/util/${util}/" || \
+			    err "clean_cbutils: ${cbtree} ${util}: can't clean"
+		done
+		make distclean -C "${tree}/payloads/libpayload/" || \
+		    err "clean_cbutils: ${tree}: can't distclean libpayload"
+	done
+}
+
+main $@
diff --git a/script/build/clean/crossgcc b/script/build/clean/crossgcc
new file mode 100755
index 00000000..c76d1849
--- /dev/null
+++ b/script/build/clean/crossgcc
@@ -0,0 +1,45 @@
+#!/usr/bin/env sh
+
+#  helper script: clean the crossgcc builds
+#
+#	Copyright (C) 2014-2016, 2020, 2023 Leah Rowe <info@minifree.org>
+#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+main()
+{
+	printf "Cleaning crossgcc builds in all coreboot archives\n"
+	[ ! -d "coreboot/" ] && exit 0
+
+	clean_crossgcc
+}
+
+clean_crossgcc()
+{
+	for board in coreboot/*; do
+		[ -d "${board}" ] || continue
+		[ "${board##*/}" = "coreboot" ] && continue
+		make -C "${board}/" crossgcc-clean || \
+		    err "clean_crossgcc: ${board}: !make crossgcc-clean"
+	done
+}
+
+main $@
diff --git a/script/build/clean/seabios b/script/build/clean/seabios
new file mode 100755
index 00000000..0178a729
--- /dev/null
+++ b/script/build/clean/seabios
@@ -0,0 +1,48 @@
+#!/usr/bin/env sh
+
+#  helper script: clean the dependencies that were built in seabios
+#
+#	Copyright (C) 2015,2020,2021,2023 Leah Rowe <info@minifree.org>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+# clean bucts
+# --------------------------------------------------------
+
+main()
+{
+	[ ! -d "elf/seabios" ] || rm -Rf elf/seabios || \
+	    err "cannot remove elf/seabios"
+	[ ! -d "seabios/" ] && exit 0
+
+	clean_seabios
+}
+
+clean_seabios()
+{
+	for x in seabios/*; do
+		[ ! -d "${x}" ] && continue
+		[ "${x}" = "seabios/seabios" ] && continue
+		make -C "${x}" distclean || \
+		    err "clean_seabios: cannot distclean tree, ${x}"
+	done
+}
+
+main $@
diff --git a/script/build/clean/u-boot b/script/build/clean/u-boot
new file mode 100755
index 00000000..5deff216
--- /dev/null
+++ b/script/build/clean/u-boot
@@ -0,0 +1,51 @@
+#!/usr/bin/env sh
+
+#  helper script: clean the u-boot builds
+#
+#	   Copyright (C) 2014-2016, 2020, 2023 Leah Rowe <info@minifree.org>
+#	   Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
+#	   Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+main()
+{
+	printf "Cleaning u-boot builds for all boards\n"
+	clean_uboot
+}
+
+clean_uboot()
+{
+	for board in u-boot/*; do
+		if [ "${board##*/}" = "u-boot" ] || [ ! -d "${board}" ]; then
+			continue
+		fi
+
+		make -C "${board}/" distclean || \
+		    err "clean_uboot: cannot distclean ${board}"
+
+		if [ -e "${board}/.git" ]; then
+			git -C "${board}" clean -fdx || \
+			    err "clean_uboot: ${board}: cannot clean git files"
+		fi
+	done
+}
+
+main $@
diff --git a/script/build/command/options b/script/build/command/options
new file mode 100755
index 00000000..84a9a3fb
--- /dev/null
+++ b/script/build/command/options
@@ -0,0 +1,31 @@
+#!/usr/bin/env sh
+
+# Copyright (c) 2023 Leah Rowe <info@minifree.org>
+# SPDX-License-Identifier: MIT
+
+. "include/err.sh"
+
+items=1
+
+main()
+{
+	[ $# -gt 0 ] || \
+		err "No argument given"
+	listitems "${1}" || err "No items present under: ${1}"
+}
+
+listitems()
+{
+	[ -d "${1}" ] || \
+		err "Directory not does exist: ${1}"
+	for x in "${1}/"*; do
+		# -e used because this is for files *or* directories
+		[ -e "${x}" ] || continue
+		[ "${x##*/}" = "build.list" ] && continue
+		printf "%s\n" "${x##*/}"
+		items=0
+	done
+	return ${items}
+}
+
+main $@
diff --git a/script/build/coreboot/utils b/script/build/coreboot/utils
new file mode 100755
index 00000000..bf0c47a7
--- /dev/null
+++ b/script/build/coreboot/utils
@@ -0,0 +1,78 @@
+#!/usr/bin/env sh
+
+#  helper script: build various coreboot utilities
+#
+#	Copyright (C) 2014-2016,2020,2021,2023 Leah Rowe <info@minifree.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+main()
+{
+	printf "Building coreboot utils\n"
+
+	if [ $# -gt 0 ]; then
+		for board in "${@}"; do
+			build_for_mainboard ${board} || \
+			    err "cannot build cbutils for target, ${board}"
+		done
+	else
+		for boarddir in resources/coreboot/*; do
+			[ ! -d "${boarddir}" ] && continue
+			build_for_mainboard ${boarddir##*/} || \
+			    err "cannot build cbutils for target, ${board}"
+		done
+	fi
+}
+
+build_for_mainboard() {
+	board="${1}"
+	[ -d "resources/coreboot/${board}" ] || continue
+	[ -f "resources/coreboot/${board}/target.cfg" ] || continue
+	tree="undefined"
+	. "resources/coreboot/${board}/target.cfg" # source
+	[ "${tree}" = "undefined" ] && \
+	    err "build_for_mainboard: improper tree definition for '${board}'"
+	buildutils "${tree}"
+}
+
+buildutils() {
+	tree="${1}"
+	[ -d "coreboot/${tree}/" ] || \
+		./fetch_trees coreboot $tree || \
+		    err "buildutils: cannot fetch ${tree}"
+	for util in cbfstool ifdtool; do
+		[ -f "cbutils/${tree}/${util}" ] && continue
+		[ -d "cbutils/${tree}" ] || \
+			mkdir -p "cbutils/${tree}" || \
+			    err "buildutils: can't mkdir cbutils/${tree}"
+
+		utildir="coreboot/${tree}/util/${util}"
+		make distclean -C "${utildir}" || \
+		    err "buildutils: cannot clean ${utildir}"
+		make -j$(nproc) -C "${utildir}" || \
+		    err "buildutils: cannot build ${utildir}"
+		cp "${utildir}/${util}" "cbutils/${tree}" || \
+		    err "buildutils: can't cp ${util} cbutils/${tree}/"
+		make distclean -C "${utildir}" || \
+		    err "buildutils: can't clean ${utildir}"
+	done
+}
+
+main $@
diff --git a/script/build/descriptors/ich9m b/script/build/descriptors/ich9m
new file mode 100755
index 00000000..d965aef8
--- /dev/null
+++ b/script/build/descriptors/ich9m
@@ -0,0 +1,42 @@
+#!/usr/bin/env sh
+
+#	 Copyright (C) 2020, 2023 Leah Rowe <info@minifree.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+ich9gen="util/ich9utils/ich9gen"
+
+main()
+{
+	[ -f "${ich9gen}" ] || ./handle make file -b ich9utils || \
+	    err "ich9utils make"
+	[ ! -f "${ich9gen}" ] && err "ich9gen doesn't exist"
+
+	[ -d "descriptors/ich9m/" ] || mkdir -p "descriptors/ich9m/" || \
+	    err "can't create directory: descriptors/ich9m"
+	rm -f descriptors/ich9m/* || err "rm-rf"
+
+	(
+	cd descriptors/ich9m/ || err "cd2"
+	../../"${ich9gen}" || err "ich9gen"
+	)
+}
+
+main $@
diff --git a/script/build/grub/payload b/script/build/grub/payload
new file mode 100755
index 00000000..63849bac
--- /dev/null
+++ b/script/build/grub/payload
@@ -0,0 +1,104 @@
+#!/usr/bin/env sh
+
+#   generate GRUB ELF files (coreboot payload) and configuration files
+#
+#	Copyright (C) 2014,2015,2020,2021,2023 Leah Rowe <info@minifree.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+grubcfgsdir="resources/grub"
+keymap=""
+
+. "${grubcfgsdir}/modules.list"
+
+main()
+{
+	printf "Creating GRUB payloads and configuration files\n"
+
+	handle_dependencies
+
+	# Separate GRUB payload per keymap to save space in ROM.
+	for keylayoutfile in ${grubcfgsdir}/keymap/*.gkb; do
+		[ -f "${keylayoutfile}" ] || continue
+		build_grub_payloads "${keylayoutfile}"
+	done
+
+	printf "Done! Check elf/grub/ to see the files.\n\n"
+}
+
+handle_dependencies()
+{
+	[ -d "grub/" ] || \
+		./fetch grub || \
+		    err "handle_dependencies: cannot fetch grub"
+	[ -f "grub/grub-mkstandalone" ] || \
+		./build grub utils || \
+		    err "handle_dependencies: cannot build grub utils"
+	[ -d "elf/grub" ] || \
+		mkdir -p elf/grub || \
+		    err "handle_dependencies: cannot mkdir elf/grub"
+	rm -f elf/grub/* || \
+	    err "handle_dependencies: cannot rm inside: elf/grub/"
+}
+
+build_grub_payloads()
+{
+	keylayoutfile=${1}
+	[ -f "${keylayoutfile}" ] || continue
+
+	keymap="${keylayoutfile##${grubcfgsdir}/keymap/}"
+	keymap="${keymap%.gkb}"
+
+	build_grub_elf "${keylayoutfile}"
+	create_grub_config
+
+	printf "Created 'elf/grub/grub_%s.elf' and configs.'\n" "${keymap}"
+}
+
+build_grub_elf()
+{
+	keylayoutfile=${1}
+
+	gcfg="/boot/grub/grub.cfg=${grubcfgsdir}"
+	gcfg="${gcfg}/config/grub_memdisk.cfg"
+	grubk="/boot/grub/layouts/${keymap}.gkb=${keylayoutfile}"
+	grub/grub-mkstandalone \
+	    --grub-mkimage="grub/grub-mkimage" \
+	    -O i386-coreboot \
+	    -o "elf/grub/grub_${keymap}.elf" \
+	    -d grub/grub-core/ \
+	    --fonts= --themes= --locales=  \
+	    --modules="${grub_modules}" \
+	    --install-modules="${grub_install_modules}" \
+	    "${gcfg}" "${grubk}" || \
+	    err "build_grub_elf: cannot build grub payload (grub-mkstandalone)"
+}
+
+create_grub_config()
+{
+	sed "s/usqwerty/${keymap}/" < "${grubcfgsdir}/config/grub.cfg" \
+	    > "elf/grub/grub_${keymap}.cfg" || \
+	    err "create_grub_config: sed failed: grub.cfg"
+	sed "s/grubtest.cfg/grub.cfg/" < "elf/grub/grub_${keymap}.cfg" \
+	    > "elf/grub/grub_${keymap}_test.cfg" || \
+	    err "create_grub_config: sed failed: grubtest.cfg"
+}
+
+main $@
diff --git a/script/build/grub/utils b/script/build/grub/utils
new file mode 100755
index 00000000..f0449ed7
--- /dev/null
+++ b/script/build/grub/utils
@@ -0,0 +1,52 @@
+#!/usr/bin/env sh
+
+#  helper script: builds GRUB2 source code
+#
+#	Copyright (C) 2014, 2015, 2020, 2023 Leah Rowe <info@minifree.org>
+#	Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+main()
+{
+	printf "Building GRUB\n"
+	[ -d "grub/" ] || ./fetch grub || err "cannot fetch grub"
+	build_grub
+}
+
+build_grub()
+{
+	(
+	cd grub/ || \
+	    err "build_grub: cd"
+	[ ! -d Makefile ] || make distclean || \
+	    err "build_grub: make-distclean"
+	./bootstrap --gnulib-srcdir=gnulib/ --no-git || \
+	    err "build_grub: gnulib bootstrap"
+	./autogen.sh || \
+	    err "build_grub: autogen.sh"
+	./configure --with-platform=coreboot || \
+	    err "build_grub: autoconf"
+	make -j$(nproc) || \
+	    err "build_grub: make"
+	)
+}
+
+main $@
diff --git a/script/build/release/roms b/script/build/release/roms
new file mode 100755
index 00000000..395fb8d7
--- /dev/null
+++ b/script/build/release/roms
@@ -0,0 +1,195 @@
+#!/usr/bin/env sh
+
+#  helper script: generate release archive (ROM images)
+#
+#	Copyright (C) 2020,2021,2022,2023 Leah Rowe <info@minifree.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+projectname="$(cat projectname)"
+version="version-unknown"
+versiondate="version-date-unknown"
+tree="default"
+target=""
+CONFIG_HAVE_MRC=""
+CONFIG_HAVE_ME_BIN=""
+CONFIG_KBC1126_FIRMWARE=""
+CONFIG_INCLUDE_SMSC_SCH5545_EC_FW=""
+ifdtool="cbutils/${tree}/ifdtool"
+cbfstool="cbutils/${tree}/cbfstool"
+
+main()
+{
+	printf "Building ROM image archives for version %s\n" "${version}"
+
+	init_check
+
+	for romdir in bin/*; do
+		make_archive "${romdir}"
+	done
+
+	printf "\nROM archives available at release/%s/roms/\n\n" "${version}"
+}
+
+init_check()
+{
+	if [ -f version ]; then
+		version="$(cat version)"
+	[ -f versiondate ] && \
+		versiondate="$(cat versiondate)"
+	[ ! -d "bin/" ] && \
+		err "init_check: no ROMs built yet (error)"
+	[ -d "release/" ] || \
+		mkdir -p release/ || \
+		    err "init_check: !mkdir -p release/"
+	[ -d "release/${version}/" ] || \
+		mkdir -p "release/${version}/" || \
+		    err "init_check: !mkdir -p release/${version}/"
+	[ ! -d "release/${version}/roms/" ] || \
+		rm -Rf "release/${version}/roms/" || \
+		    err "init_check: !rm -Rf release/${version}/roms/"
+
+	if [ ! -d "release/${version}/roms/" ]; then
+		mkdir -p "release/${version}/roms/" || \
+		    err "init_check: !mkdir -p release/${version}/roms/"
+	fi
+}
+
+make_archive()
+{
+	romdir=${1}
+	target="${romdir##*/}"
+
+	echo ${target}
+	[ -d "${romdir}/" ] || continue
+
+	CONFIG_HAVE_MRC="y"
+	CONFIG_HAVE_ME_BIN="y"
+	CONFIG_KBC1126_FIRMWARE="y"
+	CONFIG_INCLUDE_SMSC_SCH5545_EC_FW="y"
+	grep "CONFIG_HAVE_ME_BIN=y" "resources/coreboot/${target}/config/"* || \
+	    CONFIG_HAVE_ME_BIN="n"
+	grep "CONFIG_HAVE_MRC=y" "resources/coreboot/${target}/config/"* || \
+	    CONFIG_HAVE_MRC="n"
+	grep "CONFIG_KBC1126_FIRMWARE=y" \
+	    "resources/coreboot/${target}/config"/* || \
+	    CONFIG_KBC1126_FIRMWARE="n"
+	grep "CONFIG_INCLUDE_SMSC_SCH5545_EC_FW=y" \
+	    "resources/coreboot/${target}/config"/* || \
+	    CONFIG_INCLUDE_SMSC_SCH5545_EC_FW="n"
+
+	# remove ME/MRC/EC firmware from ROM images
+	if [ "${CONFIG_HAVE_ME_BIN}" = "y" ] || \
+	    [ "${target}" = "e6400nvidia_4mb" ]; then
+		strip_archive "${romdir}"
+	fi
+
+	printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
+	    "${version}" "${projectname}" "${version}" "${target##*/}"
+	printf "%s\n" "${version}" > "${romdir}/version" || \
+	    err "make_archive: can't create ${romdir}/version"
+	printf "%s\n" "${versiondate}" > "${romdir}/versiondate" || \
+	    err "make_archive: can't create ${romdir}/versiondate"
+	printf "%s\n" "${projectname}" > "${romdir}/projectname" || \
+	    err "make_archive: can't create ${romdir}/projectname"
+
+	f="release/${version}/roms/${projectname}-${version}_${target##*/}"
+	tar -c "${romdir}/" | xz -9e > "${f}.tar.xz" || \
+	    err "make_archive: can't create ${f}.tar.xz"
+
+	if [ -d "${romdir}_tmp" ]; then
+		rm -Rf "${romdir}" || err "make_archive: !rm -Rf ${romdir}"
+		mv "${romdir}_tmp" "${romdir}" || \
+		    err "make_archive: !mv \"${romdir}_tmp\" \"${romdir}\""
+	fi
+}
+
+strip_archive()
+{
+	romdir=${1}
+
+	[ -d "coreboot/${tree}" ] || \
+		./fetch_trees coreboot ${tree} || \
+		    err "strip_archive: coreboot/${tree}: can't fetch source"
+	./build coreboot utils ${tree} || \
+	    err "strip_archive: coreboot/${tree}: can't build utils"
+
+	# dirty hack, to reduce disk io later
+	# rather than using /tmp, which might not be tmpfs
+	rm -Rf "${romdir}_tmp" || err "strip_archive: !rm -Rf ${romdir}_tmp"
+	mkdir "${romdir}_tmp" || err "strip_archive: !mkdir ${romdir}_tmp"
+
+	# Hash the rom before removing blobs
+	rm -f "${romdir}/blobhashes" || \
+	    err "strip_archive: !rm -f ${blobdir}/blobhashes"
+	touch "${romdir}/blobhashes" || \
+	    err "strip_archive: !touch ${blobdir}/blobhashes"
+
+	(
+	cd "${romdir}" || err "strip_archive: !cd ${romdir}"
+	sha1sum *.rom >> blobhashes || \
+	    err "strip_archive: ${romdir}: !sha1sum *.rom >> blobhashes"
+	)
+
+	for romfile in "${romdir}"/*.rom; do
+		strip_rom_image "${romfile}"
+	done
+}
+
+strip_rom_image()
+{
+	romfile=${1}
+
+	[ -f "${romfile}" ] || return 0
+
+	if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then
+		"${ifdtool}" --nuke me "${romfile}" || \
+		    err "strip_rom_images: ${romfile}: cannot nuke Intel ME"
+		mv "${romfile}" "${romdir}_tmp" || \
+		    err "strip_rom_images: !mv ${romfile} ${romdir}_tmp"
+		mv "${romfile}.new" "${romfile}" || \
+		    err "strip_rom_images: !mv ${romfile}.new ${romfile}"
+	fi
+
+	if [ "${CONFIG_HAVE_MRC}" = "y" ]; then
+		"${cbfstool}" "${romfile}" remove -n mrc.bin || \
+		    err "strip_rom_images: ${romfile}: cannot nuke mrc.bin"
+		"${cbfstool}" "${romfile}" print || :
+	fi
+
+	if [ "${CONFIG_KBC1126_FIRMWARE}" = "y" ]; then
+		"${cbfstool}" "${romfile}" remove -n ecfw1.bin || \
+		    err "strip_rom_images: ${romfile}: can't nuke ecfw1.bin"
+		"${cbfstool}" "${romfile}" remove -n ecfw2.bin || \
+		    err "strip_rom_images: ${romfile}: can't nuke ecfw2.bin"
+	fi
+
+	[ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" != "y" ] || \
+		"${cbfstool}" "${romfile}" remove -n sch5545_ecfw.bin || \
+		    err "strip_rom_images: ${romfile}: can't nuke sch5545ec fw"
+
+	# TODO: replace this board-specific hack
+	if [ "${target}" = "e6400nvidia_4mb" ]; then
+		"${cbfstool}" "${romfile}" remove -n "pci10de,06eb.rom" || \
+		    err "strip_rom_images: ${romfile}: can't nuke e6400 vga rom"
+	fi
+}
+
+main $@
diff --git a/script/build/release/src b/script/build/release/src
new file mode 100755
index 00000000..0db9d721
--- /dev/null
+++ b/script/build/release/src
@@ -0,0 +1,193 @@
+#!/usr/bin/env sh
+
+#  helper script: generate release archive (source code)
+#
+#	Copyright (C) 2020,2021,2023 Leah Rowe <info@minifree.org>
+#
+#	This program is free software: you can redistribute it and/or modify
+#	it under the terms of the GNU General Public License as published by
+#	the Free Software Foundation, either version 3 of the License, or
+#	(at your option) any later version.
+#
+#	This program is distributed in the hope that it will be useful,
+#	but WITHOUT ANY WARRANTY; without even the implied warranty of
+#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#	GNU General Public License for more details.
+#
+#	You should have received a copy of the GNU General Public License
+#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+. "include/err.sh"
+
+projectname="$(cat projectname)"
+
+trees_fetch_list="coreboot u-boot seabios"
+simple_fetch_list="flashrom grub memtest86plus me_cleaner uefitool"
+simple_fetch_list="${simple_fetch_list} bios_extract biosutilities"
+
+# do not add blobs directory here. it's handled below
+dirlist="resources util script"
+
+filelist="lbmk modify build README.md COPYING Makefile update version"
+filelist="${filelist} versiondate projectname .gitcheck fetch fetch_trees"
+
+version="version-unknown"
+versiondate="version-date-unknown"
+reldir=""
+dirname=""
+srcdir=""
+
+printf "Building source code archive, version %s\n" "${version}"
+
+main()
+{
+	[ -f version ] && \
+		version="$(cat version)"
+	[ -f versiondate ] && \
+		versiondate="$(cat versiondate)"
+
+	create_release_directory
+	download_modules
+	copy_files
+	purge_files
+
+	create_release_archive
+
+	printf "Source code archive available at %s.tar.xz\n\n" "${srcdir}"
+}
+
+create_release_directory()
+{
+	reldir="release/${version}"
+	dirname="${projectname}-${version}_src"
+	srcdir="${reldir}/${dirname}"
+
+	[ -d "release/" ] || mkdir -p release/ || \
+	    err "create_release_directory: !mkdir -p release/"
+	[ -d "${reldir}/" ] || mkdir -p "${reldir}/" || \
+	    err "create_release_directory: !mkdir -p ${reldir}/"
+	[ ! -d "${srcdir}/" ] || rm -Rf "${srcdir}/" || \
+	    err "create_release_directory: !rm -Rf ${srcdir}/"
+	[ ! -f "${srcdir}.tar.xz" ] || \
+		rm -f "${srcdir}.tar.xz/" || \
+		    err "create_release_directory: !rm -f ${srcdir}.tar.xz/"
+
+	mkdir -p "${srcdir}/" || \
+	    err "create_release_directory: !mkdir -p ${srcdir}/"
+	printf "%s" "${version}" > "${srcdir}"/version || \
+	    err "create_release_directory: ${srcdir}/version: can't create file"
+}
+
+download_modules()
+{
+	for modname in ${trees_fetch_list}; do
+		[ -d "${modname}" ] || ./fetch_trees ${modname} || \
+		    err "download_modules: couldn't download ${modname} trees"
+	done
+	for modname in ${simple_fetch_list}; do
+		[ -d "${modname}/" ] || ./fetch ${modname} || \
+		    err "download_modules: couldn't download ${modname} repo"
+	done
+}
+
+copy_files()
+{
+	for dir in ${simple_fetch_list} ${dirlist}; do
+		cp -R "${dir}/" "${srcdir}/" || \
+		    err "copy_files: !cp -R ${dir}/ ${srcdir}/"
+	done
+
+	copy_blobs
+
+	for i in ${filelist}; do
+		if [ ! -f "${i}" ]; then
+			rm -Rf "${srcdir}" || \
+			    err "copy_files: !rm -Rf ${srcdir}"
+			err "copy_files: file '${1}' does not exist"
+		fi
+		cp "${i}" "${srcdir}/" || \
+		    err "copy_files: !cp ${i} ${srcdir}/"
+	done
+}
+
+copy_blobs()
+{
+	mkdir -p "${srcdir}"/blobs || \
+	    err "copy_blobs: !mkdir -p ${srcdir}/blobs"
+	# do not copy intel ME etc, but do copy ifd/gbe files
+	for i in t440p xx20 xx30 hp8200sff hp_ivybridge hp_sandybridge \
+	    hp8300usdt t1650; do
+		for j in ifd gbe 4_ifd 8_ifd 12_ifd 16_ifd; do
+			[ -f "blobs/${i}/${j}.bin" ] || continue
+			[ -e "${srcdir}/blobs/${i}" ] || \
+				mkdir -p "${srcdir}/blobs/${i}" || \
+				    err "copy_blobs: ! -d ${srcdir}/blobs/${i}"
+			cp "blobs/${i}/${j}.bin" "${srcdir}/blobs/${i}" || \
+			    err "copy_blobs: ! -f ${srcdir}/blobs/${i}"
+		done
+	done
+}
+
+purge_files()
+{
+	(
+	cd "${srcdir}/" || \
+	    err "purge_files 3: !cd ${srcdir}/"
+
+	for p in coreboot/*; do
+		[ -d "${p}" ] || continue
+		./handle make file -c "${p}" || \
+		    err "purge_files 1: ${p}: !make distclean"
+	done
+
+	./handle make file -c coreboot/default/util/kbc1126 || \
+	    err "purge_files 1: default/util/kbc1126: ! make clean"
+	./build clean all || \
+	    err "purge_files 1: ! ./build clean all"
+
+	for p in bios_extract flashrom grub ich9utils uefitool; do
+		./handle make file -c "${p}" || \
+		    err "purge_files: !./handle make file -c ${p}"
+	done
+	for p in 32 64; do
+		./handle make file -c "memtest86plus/build${p}" || \
+		    err "purge_files: cannot clean memtest86+ build${p}"
+	done
+	for p in "nvmutil" "ich9utils" "spkmodem_recv" "e6400-flash-unlock"; do
+		make clean -C "util/${p}" || \
+		
+		    err "purge_files 2: !make clean -C ${util}/p"
+	done
+	for p in ${trees_fetch_list}; do
+		rm -Rf "${p}/${p}" "${p}"/*/.git* || \
+		    err "purge_files 1: cannot clean ${p} project files"
+	done
+	rm -Rf .git .gitignore */.git* coreboot/*/3rdparty/*/.git* \
+	    coreboot/*/util/nvidia/cbootimage/.git* || \
+	    err "purge_files rm-rf2: can't purge .git files/directories"
+	)
+}
+
+create_release_archive()
+{
+	(
+	cd "${reldir}/" || \
+	    err "create_release_archive 4: !cd ${reldir}/"
+	printf "%s\n" "${version}" > "${dirname}/version" || \
+	    err "create_release_archive: can't create ${dirname}/version"
+	printf "%s\n" "${versiondate}" > "${dirname}/versiondate" || \
+	    err "create_release_archive: can't create ${dirname}/versiondate"
+	printf "%s\n" "${projectname}" > "${dirname}/projectname" || \
+	    err "create_release_archive: can't create ${dirname}/projectname"
+	tar -c "${dirname}/" | xz -9e >"${dirname}.tar.xz" || \
+	    err "create_release_archive: can't create ${dirname}.tar.xz"
+	rm -Rf "${dirname}/" || \
+	    err "create_release_archive 5: !rm -Rf ${dirname}/"
+	)
+}
+
+main $@
-- 
cgit v1.2.1