Greatly simplify error handling in shell scripts

Instead of having detailed error messages, run most
commands through a function that calls err() under
fault conditions.

Where detail is still required, err() is still called
manually. Where it isn't, the error message is simply
whatever command was executed to cause the error.

This results in a massive sloccount reduction for lbmk;
specifically, 178 sloc reduction, or a 8.1% reduction.
The total sloccount is now 2022, for shell scripts.

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-01 06:33:43 +01:00
parent 5f914a4d00
commit 8c03b886c4
19 changed files with 278 additions and 461 deletions

View File

@ -52,14 +52,14 @@ fetch()
_dest="${5##*../}" _dest="${5##*../}"
_dl="${blobdir}/cache/${dlsum}" _dl="${blobdir}/cache/${dlsum}"
mkdir -p "${_dl%/*}" || err "fetch: !mkdir ${_dl%/*}" x_ mkdir -p "${_dl%/*}"
dl_fail="y" dl_fail="y"
vendor_checksum "${dlsum}" "${_dl}" && dl_fail="n" vendor_checksum "${dlsum}" "${_dl}" && dl_fail="n"
for url in "${dl}" "${dl_bkup}"; do for url in "${dl}" "${dl_bkup}"; do
[ "${dl_fail}" = "n" ] && break [ "${dl_fail}" = "n" ] && break
[ -z "${url}" ] && continue [ -z "${url}" ] && continue
rm -f "${_dl}" || err "fetch: !rm -f ${_dl}" x_ rm -f "${_dl}"
curl --location --retry 3 -A "${_ua}" "${url}" -o "${_dl}" || \ curl --location --retry 3 -A "${_ua}" "${url}" -o "${_dl}" || \
wget --tries 3 -U "${_ua}" "${url}" -O "${_dl}" || \ wget --tries 3 -U "${_ua}" "${url}" -O "${_dl}" || \
continue continue
@ -68,7 +68,7 @@ fetch()
[ "${dl_fail}" = "y" ] && \ [ "${dl_fail}" = "y" ] && \
err "fetch ${dlsum}: matched file unavailable" err "fetch ${dlsum}: matched file unavailable"
rm -Rf "${_dl}_extracted" || err "!rm ${_dl}_extracted" x_ rm -Rf "${_dl}_extracted"
mkdirs "${_dest}" "extract_${dl_type}" || return 0 mkdirs "${_dest}" "extract_${dl_type}" || return 0
eval "extract_${dl_type}" eval "extract_${dl_type}"
@ -89,9 +89,9 @@ mkdirs()
{ {
[ -f "${1}" ] && \ [ -f "${1}" ] && \
printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1 printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1
mkdir -p "${1%/*}" || err "mkdirs ${1} ${2}: !mkdir ${1%/*}" x_ mkdir -p "${1%/*}"
rm -Rf "${appdir}" || err "mkdirs ${1} ${2}: can't remove ${appdir}" x_ rm -Rf "${appdir}"
mkdir -p "${appdir}/" || err "mkdirs ${1} ${2}: !mkdir ${appdir}" x_ mkdir -p "${appdir}/"
extract_archive "${_dl}" "${appdir}" || \ extract_archive "${_dl}" "${appdir}" || \
[ "${2}" = "extract_e6400vga" ] || err "mkdirs ${1} ${2}: !extract" [ "${2}" = "extract_e6400vga" ] || err "mkdirs ${1} ${2}: !extract"
} }

View File

@ -1,6 +1,15 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org> # SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org>
xfail=""
x_() {
[ $# -lt 1 ] || ${@} || err "${@}"
}
xx_() {
[ $# -lt 1 ] || ${@} || fail "${@}"
}
setvars() setvars()
{ {
_setvars="" _setvars=""

View File

@ -14,15 +14,14 @@ extract_mrc()
_file="${_file%.zip}" _file="${_file%.zip}"
( (
cd "${appdir}" || err "extract_mrc: !cd ${appdir}" x_ cd "${appdir}"
extract_partition ROOT-A "${_file}" root-a.ext2 extract_partition ROOT-A "${_file}" root-a.ext2
extract_shellball root-a.ext2 chromeos-firmwareupdate-${MRC_board} extract_shellball root-a.ext2 chromeos-firmwareupdate-${MRC_board}
extract_coreboot chromeos-firmwareupdate-${MRC_board} extract_coreboot chromeos-firmwareupdate-${MRC_board}
) )
"${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \ x_ "${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \
-f "${_dest}" -r RO_SECTION || \ -f "${_dest}" -r RO_SECTION
err "extract_mrc: could not fetch mrc.bin"
} }
extract_partition() extract_partition()
@ -39,9 +38,8 @@ extract_partition()
START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) )) START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) ))
SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) )) SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) ))
dd if="${FILE}" of="${ROOTFS}" bs=${_bs} skip=$(( ${START} / ${_bs} )) \ x_ dd if="${FILE}" of="${ROOTFS}" bs=${_bs} \
count=$(( ${SIZE} / ${_bs} )) || \ skip=$(( ${START} / ${_bs} )) count=$(( ${SIZE} / ${_bs} ))
err "extract_partition: can't extract root file system"
} }
extract_shellball() extract_shellball()
@ -62,8 +60,7 @@ extract_coreboot()
printf "Extracting coreboot image\n" printf "Extracting coreboot image\n"
[ -f "${_shellball}" ] || \ [ -f "${_shellball}" ] || \
err "extract_coreboot: shellball missing in google cros image" err "extract_coreboot: shellball missing in google cros image"
sh "${_shellball}" --unpack "${_unpacked}" || \ x_ sh "${_shellball}" --unpack "${_unpacked}"
err "extract_coreboot: shellball exits with non-zero status"
# TODO: audit the f* out of that shellball, for each mrc version. # TODO: audit the f* out of that shellball, for each mrc version.
# it has to be updated for each mrc update. we should ideally # it has to be updated for each mrc update. we should ideally
@ -75,6 +72,5 @@ extract_coreboot()
_version=$( cat "${_unpacked}/VERSION" | grep BIOS\ version: | \ _version=$( cat "${_unpacked}/VERSION" | grep BIOS\ version: | \
cut -f2 -d: | tr -d \ ) cut -f2 -d: | tr -d \ )
cp "${_unpacked}/bios.bin" "coreboot-${_version}.bin" || \ x_ cp "${_unpacked}/bios.bin" "coreboot-${_version}.bin"
err "extract_coreboot: cannot copy google cros rom"
} }

View File

@ -38,6 +38,5 @@ scan_config()
done << EOF done << EOF
$(eval "awk '${awkstr}' \"${revfile}\"") $(eval "awk '${awkstr}' \"${revfile}\"")
EOF EOF
rm -f "${revfile}" || \ rm -f "${revfile}" || "${_fail}" "scan_config: Cannot remove tmpfile"
"${_fail}" "scan_config: Cannot remove tmpfile"
} }

13
lbmk
View File

@ -21,9 +21,7 @@ option=""
main() main()
{ {
id -u 1>/dev/null 2>/dev/null || \ xx_ id -u 1>/dev/null 2>/dev/null
fail "cannot ascertain user id"
initialise_command $@ initialise_command $@
shift 2 shift 2
@ -40,8 +38,7 @@ initialise_command()
[ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help" [ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help"
mode="${1}" mode="${1}"
[ "${mode}" != "dependencies" ] || \ [ "${mode}" != "dependencies" ] || xx_ install_packages $@
install_packages $@ || fail "Can't install dependencies"
[ "$(id -u)" != "0" ] || \ [ "$(id -u)" != "0" ] || \
fail "running this command as root is not permitted" fail "running this command as root is not permitted"
@ -68,8 +65,7 @@ install_packages()
aur_notice="" aur_notice=""
. "config/dependencies/${2}" . "config/dependencies/${2}"
${pkg_add} ${pkglist} || \ xx_ ${pkg_add} ${pkglist}
fail "install_packages: Error installing dependencies"
[ "${aur_notice}" = "" ] || \ [ "${aur_notice}" = "" ] || \
printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2 printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2
@ -79,8 +75,7 @@ install_packages()
execute_command() execute_command()
{ {
if [ "${option}" = "list" ]; then if [ "${option}" = "list" ]; then
listitems "${buildpath}/${mode}" || \ xx_ listitems "${buildpath}/${mode}"
fail "execute_command: cannot list command options"
lbmk_exit 0 lbmk_exit 0
fi fi
[ -f "${buildpath}/${mode}/${option}" ] || \ [ -f "${buildpath}/${mode}/${option}" ] || \

View File

@ -41,8 +41,7 @@ build_bootroms()
{ {
opts="${_displaymode} ${_payload} ${_keyboard}" opts="${_displaymode} ${_payload} ${_keyboard}"
for x in ${boards}; do for x in ${boards}; do
./build boot roms_helper ${opts} ${x} || \ x_ ./build boot roms_helper ${opts} ${x}
err "handle_targets ${opts} ${x}: build error"
[ -d "bin/${x}" ] && targets="${x} ${targets}" [ -d "bin/${x}" ] && targets="${x} ${targets}"
done done
} }

View File

@ -110,16 +110,15 @@ build_dependencies()
cbfstool="cbutils/${tree}/cbfstool" cbfstool="cbutils/${tree}/cbfstool"
cbrom="${cbdir}/build/coreboot.rom" cbrom="${cbdir}/build/coreboot.rom"
./build coreboot utils ${tree} || err "cannot build cbutils/${tree}" x_ ./build coreboot utils ${tree}
build_dependency_seabios build_dependency_seabios
memtest_bin="memtest86plus/build${arch#*_}/memtest.bin" memtest_bin="memtest86plus/build${arch#*_}/memtest.bin"
[ "${payload_memtest}" != "y" ] || [ -f "${memtest_bin}" ] || \ [ "${payload_memtest}" != "y" ] || [ -f "${memtest_bin}" ] || \
./handle make file -b ${memtest_bin%/*} || \ x_ ./handle make file -b ${memtest_bin%/*}
err "cannot build memtest86+"
rm -f "${romdir}"/* || err "cannot: rm -f \"${romdir}\"/*" x_ rm -f "${romdir}/"*
build_dependency_grub build_dependency_grub
build_dependency_uboot build_dependency_uboot
@ -133,8 +132,7 @@ build_dependency_seabios()
|| [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \ || [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \ || [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then || [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then
./handle make config -b seabios || \ x_ ./handle make config -b seabios
err "cannot build seabios"
fi fi
} }
@ -155,16 +153,14 @@ build_dependency_grub()
rebuild_grub="y" && break rebuild_grub="y" && break
done done
[ "${rebuild_grub}" = "y" ] || return 0 [ "${rebuild_grub}" = "y" ] || return 0
./build grub payload || \ x_ ./build grub payload
err "build_dependency_grub: cannot build grub payload"
} }
build_dependency_uboot() build_dependency_uboot()
{ {
[ "${payload_uboot}" = "y" ] || return 0 [ "${payload_uboot}" = "y" ] || return 0
./handle make config -b u-boot ${board} || \ x_ ./handle make config -b u-boot ${board}
err "cannot build u-boot target: ${board}"
ubdir="elf/u-boot/${board}/${uboot_config}" ubdir="elf/u-boot/${board}/${uboot_config}"
ubootelf="${ubdir}/u-boot.elf" ubootelf="${ubdir}/u-boot.elf"
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot.bin" ] && \ [ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot.bin" ] && \
@ -201,26 +197,22 @@ build_roms()
"${cbcfg}" "${board}" "${displaymode}" "${initmode}" \ "${cbcfg}" "${board}" "${displaymode}" "${initmode}" \
1>&2 && return 0 1>&2 && return 0
./handle make config -b coreboot ${board} || \ x_ ./handle make config -b coreboot ${board}
err "build_roms: cannot build coreboot for target: ${board}"
_cbrom="elf/coreboot/${board}/${initmode}_${displaymode}" _cbrom="elf/coreboot/${board}/${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && \ [ "${initmode}" = "normal" ] && \
_cbrom="${_cbrom%_${displaymode}}" _cbrom="${_cbrom%_${displaymode}}"
_cbrom="${_cbrom}/coreboot.rom" _cbrom="${_cbrom}/coreboot.rom"
cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)" cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
cp "${_cbrom}" "${cbrom}" || \ x_ cp "${_cbrom}" "${cbrom}"
err "build_roms: cannot copy rom"
[ "${payload_memtest}" != "y" ] || \ [ "${payload_memtest}" != "y" ] || \
"${cbfstool}" "${cbrom}" add-payload \ x_ "${cbfstool}" "${cbrom}" add-payload \
-f "${memtest_bin}" -n img/memtest -c lzma || \ -f "${memtest_bin}" -n img/memtest -c lzma
err "build_roms: cannot add img/memtest to coreboot rom"
[ "${payload_seabios}" = "y" ] && \ [ "${payload_seabios}" = "y" ] && \
build_seabios_roms build_seabios_roms
[ "${payload_grub}" != "y" ] || \ [ "${payload_grub}" != "y" ] || \
build_grub_roms "${cbrom}" "grub" || \ x_ build_grub_roms "${cbrom}" "grub"
err "build_roms: build_grub_roms failed"
[ "${payload_uboot}" = "y" ] || return 0 [ "${payload_uboot}" = "y" ] || return 0
build_uboot_roms build_uboot_roms
} }
@ -229,68 +221,57 @@ build_seabios_roms()
{ {
if [ "${payload_seabios_withgrub}" = "y" ]; then if [ "${payload_seabios_withgrub}" = "y" ]; then
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
cp "${cbrom}" "${tmprom}" || \ x_ cp "${cbrom}" "${tmprom}"
err "build_seabios_roms: cannot copy to tmprom" x_ build_grub_roms "${tmprom}" "seabios_withgrub"
build_grub_roms "${tmprom}" "seabios_withgrub" || \ x_ rm -f "${tmprom}"
err "build_roms: cannot build grub roms, seabios w/grub"
rm -f "${tmprom}" || err "build_roms: can't remove tmprom"
else else
t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \ t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \
err "build_seabios_roms: cannot build tmprom" err "build_seabios_roms: cannot build tmprom"
newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}" newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \ [ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
&& newrom="${newrom}_${board}_${initmode}" && newrom="${newrom}_${board}_${initmode}"
moverom "${t}" "${newrom}.rom" || \ x_ moverom "${t}" "${newrom}.rom"
err "build_roms: cannot copy rom" x_ rm -f "${t}"
rm -f "${t}" || err "cannot rm ${t}"
fi fi
} }
# Make separate ROM images with GRUB payload, for each supported keymap # Make separate ROM images with GRUB payload, for each supported keymap
build_grub_roms() { build_grub_roms()
{
tmprom="${1}" tmprom="${1}"
payload1="${2}" # allow values: grub, seabios, seabios_withgrub payload1="${2}" # allow values: grub, seabios, seabios_withgrub
grub_cbfs="fallback/payload" grub_cbfs="fallback/payload"
if [ "${payload_grub_withseabios}" = "y" ] && \ if [ "${payload_grub_withseabios}" = "y" ] && \
[ "${payload1}" = "grub" ]; then [ "${payload1}" = "grub" ]; then
mv "$(mkSeabiosRom "${tmprom}" "seabios.elf")" "${tmprom}" || \ x_ mv "$(mkSeabiosRom "${tmprom}" "seabios.elf")" "${tmprom}"
err "build_grub_roms: cannot move tmp rom (seabios.elf)"
elif [ "${payload_seabios_withgrub}" = "y" ] && \ elif [ "${payload_seabios_withgrub}" = "y" ] && \
[ "${payload1}" != "grub" ]; then [ "${payload1}" != "grub" ]; then
mv "$(mkSeabiosRom "${tmprom}" fallback/payload)" "${tmprom}" \ x_ mv "$(mkSeabiosRom "${tmprom}" fallback/payload)" "${tmprom}"
|| err "build_grub_roms: cannot move SeaBIOS ROM to tmprom"
grub_cbfs="img/grub2" grub_cbfs="img/grub2"
fi fi
# we only need insert grub.elf once, for each coreboot config: # we only need insert grub.elf once, for each coreboot config:
"${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" -n ${grub_cbfs} \ x_ "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" \
-c lzma || err "build_grub_roms: cannot add grub payload to tmprom" -n ${grub_cbfs} -c lzma
# we only need insert background.png once, for each coreboot config: # we only need insert background.png once, for each coreboot config:
if [ "${displaymode}" = "vesafb" ] || \ if [ "${displaymode}" = "vesafb" ] || \
[ "${displaymode}" = "corebootfb" ]; then [ "${displaymode}" = "corebootfb" ]; then
backgroundfile="config/grub/background/${grub_background}" backgroundfile="config/grub/background/${grub_background}"
"${cbfstool}" "${tmprom}" add -f ${backgroundfile} \ x_ "${cbfstool}" "${tmprom}" add -f ${backgroundfile} \
-n background.png -t raw || \ -n background.png -t raw
err "build_grub_roms: cannot add background.png to tmprom"
fi fi
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX) || tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX) ||
err "build_grub_roms: cannot create temporary scan.cfg" err "build_grub_roms: cannot create temporary scan.cfg"
printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" > \ x_ printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" >"${tmpcfg}"
"${tmpcfg}" || err "build_grub_roms: cannot create scan.cfg"
[ "${grub_scan_disk}" = "both" ] || \ [ "${grub_scan_disk}" = "both" ] || \
"${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n scan.cfg -t \ x_ "${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n scan.cfg -t raw
raw || err "build_grub_roms: can't insert scan.cfg" x_ printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}"
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \ [ -z "${grub_timeout}" ] || x_ "${cbfstool}" "${tmprom}" add \
err "build_grub_roms: can't create timeout.cfg" -f "${tmpcfg}" -n timeout.cfg -t raw
[ -z "${grub_timeout}" ] || \ x_ rm -f "${tmpcfg}"
"${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n timeout.cfg \
-t raw || err "build_grub_roms: can't insert timeout.cfg"
rm -f "${tmpcfg}" || err "build_grub_roms: can't delete tmpcfg"
keymaps="" keymaps=""
for kmapfile in "${kmapdir}"/*; do for kmapfile in "${kmapdir}"/*; do
@ -309,9 +290,8 @@ build_grub_roms() {
[ "${initmode}" = "normal" ] && \ [ "${initmode}" = "normal" ] && \
newrom="${romdir}/${payload1}_${board}_" && \ newrom="${romdir}/${payload1}_${board}_" && \
newrom="${newrom}${initmode}_${keymap}.rom" newrom="${newrom}${initmode}_${keymap}.rom"
moverom "${tmpgrubrom}" "${newrom}" || \ x_ moverom "${tmpgrubrom}" "${newrom}"
err "build_grub_roms, moverom" x_ rm -f "${tmpgrubrom}"
rm -f "${tmpgrubrom}" || err "rm tmpgrubrom, build_grub_roms"
done done
} }
@ -324,9 +304,8 @@ mkGrubRom() {
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || \ tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || \
err "mkGrubRom: cannot create tmprom" err "mkGrubRom: cannot create tmprom"
cp "${_cbrom}" "${tmprom}" || err "mkGrubRom: cannot copy to tmprom" x_ cp "${_cbrom}" "${tmprom}"
"${cbfstool}" "${tmprom}" add -f "${keymapcfg}" -n keymap.cfg -t raw \ x_ "${cbfstool}" "${tmprom}" add -f "${keymapcfg}" -n keymap.cfg -t raw
|| err "mkGrubRom: cannot add keymap.cfg to tmprom"
printf "%s\n" "${tmprom}" printf "%s\n" "${tmprom}"
} }
@ -339,23 +318,17 @@ mkSeabiosRom() {
_seabioself="elf/seabios/default/${initmode}/bios.bin.elf" _seabioself="elf/seabios/default/${initmode}/bios.bin.elf"
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
cp "${_cbrom}" "${tmprom}" || \ x_ cp "${_cbrom}" "${tmprom}"
err "mkSeabiosRom: cannot copy to tmprom" x_ "${cbfstool}" "${tmprom}" add-payload -f "${_seabioself}" \
"${cbfstool}" "${tmprom}" add-payload -f "${_seabioself}" \ -n ${_seabios_cbfs_path} -c lzma
-n ${_seabios_cbfs_path} -c lzma || \ x_ "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup
err "mkSeabiosRom: can't add payload, ${_seabioself}, to rom"
"${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup \
|| err "mkSeabiosRom: cbfs add-int etc/ps2-keyboard-spinup 3000"
z="2"; [ "${initmode}" = "vgarom" ] && z="0" z="2"; [ "${initmode}" = "vgarom" ] && z="0"
"${cbfstool}" "${tmprom}" add-int -i $z -n etc/pci-optionrom-exec || \ x_ "${cbfstool}" "${tmprom}" add-int -i $z -n etc/pci-optionrom-exec
err "mkSeabiosRom: cbfs add-int etc/pci-optionrom-exec 0" x_ "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum
"${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum || \
err "mkSeabiosRom: cbfs add-int etc/optionroms-checksum 0"
[ "${initmode}" != "libgfxinit" ] || \ [ "${initmode}" != "libgfxinit" ] || \
"${cbfstool}" "${tmprom}" add -f "${seavgabiosrom}" \ x_ "${cbfstool}" "${tmprom}" add -f "${seavgabiosrom}" \
-n vgaroms/seavgabios.bin -t raw || \ -n vgaroms/seavgabios.bin -t raw
err "mkSeabiosRom: cbfs add-raw vgaroms/seavgabios.bin"
printf "%s\n" "${tmprom}" printf "%s\n" "${tmprom}"
} }
@ -366,9 +339,8 @@ build_uboot_roms()
newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom" newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
[ "${initmode}" = "normal" ] && \ [ "${initmode}" = "normal" ] && \
newrom="${romdir}/uboot_payload_${board}_${initmode}.rom" newrom="${romdir}/uboot_payload_${board}_${initmode}.rom"
moverom "${tmprom}" "${newrom}" || \ x_ moverom "${tmprom}" "${newrom}"
err "build_roms: moverom fail (u-boot)" x_ rm -f "${tmprom}"
rm -f "${tmprom}" || err "build_roms: cannot rm u-boot rom"
} }
# make a rom in /tmp/ and then print the path of that ROM # make a rom in /tmp/ and then print the path of that ROM
@ -384,11 +356,9 @@ mkUbootRom() {
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
cp "${_cbrom}" "${tmprom}" || \ x_ cp "${_cbrom}" "${tmprom}"
err "mkUbootRom: cannot copy to tmprom" x_ "${cbfstool}" "${tmprom}" add-payload -f "${_ubootelf}" \
"${cbfstool}" "${tmprom}" add-payload -f "${_ubootelf}" \ -n ${_uboot_cbfs_path} -c lzma
-n ${_uboot_cbfs_path} -c lzma || \
err "mkUbootRom: cannot add u-boot to tmprom"
printf "%s\n" "${tmprom}" printf "%s\n" "${tmprom}"
} }
@ -401,10 +371,9 @@ moverom() {
printf "Creating target image: %s\n" "${newrom}" printf "Creating target image: %s\n" "${newrom}"
[ -d "${newrom%/*}" ] || mkdir -p "${newrom%/*}/" || \ [ -d "${newrom%/*}" ] || x_ mkdir -p "${newrom%/*}/"
err "moverom: cannot create rom directory: \"${newrom%/*}\""
[ "${blobs_required}" = "n" ] && newrom="${newrom%.rom}_noblobs.rom" [ "${blobs_required}" = "n" ] && newrom="${newrom%.rom}_noblobs.rom"
cp "${rompath}" "${newrom}" || err "moverom: can't copy rom" x_ cp "${rompath}" "${newrom}"
} }
main $@ main $@

View File

@ -13,14 +13,12 @@ main()
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
for board in "${@}"; do for board in "${@}"; do
build_for_mainboard ${board} || \ x_ build_for_mainboard ${board}
err "cannot build cbutils for target, ${board}"
done done
else else
for boarddir in config/coreboot/*; do for boarddir in config/coreboot/*; do
[ ! -d "${boarddir}" ] && continue [ ! -d "${boarddir}" ] && continue
build_for_mainboard ${boarddir##*/} || \ x_ build_for_mainboard ${boarddir##*/}
err "cannot build cbutils for target, ${board}"
done done
fi fi
} }
@ -28,36 +26,29 @@ main()
build_for_mainboard() { build_for_mainboard() {
board="${1}" board="${1}"
[ -d "config/coreboot/${board}" ] || \ [ -d "config/coreboot/${board}" ] || \
err "build_for_mainboard ${board}: boarddir does not exist" err "build_for_mainboard ${board}: boarddir does not exist"
[ -f "config/coreboot/${board}/target.cfg" ] || \ [ -f "config/coreboot/${board}/target.cfg" ] || \
err "build_for_mainboard ${board}: target.cfg does not exist" err "build_for_mainboard ${board}: target.cfg does not exist"
tree="undefined" tree="undefined"
. "config/coreboot/${board}/target.cfg" # source . "config/coreboot/${board}/target.cfg" # source
[ "${tree}" = "undefined" ] && \ [ "${tree}" = "undefined" ] && \
err "build_for_mainboard: improper tree definition for '${board}'" err "build_for_mainboard ${board}: improper tree definition"
buildutils "${tree}" buildutils "${tree}"
} }
buildutils() { buildutils() {
tree="${1}" tree="${1}"
[ -d "coreboot/${tree}/" ] || \ [ -d "coreboot/${tree}/" ] || \
./update project trees coreboot $tree || \ x_ ./update project trees coreboot ${tree}
err "buildutils: cannot fetch ${tree}"
for util in cbfstool ifdtool; do for util in cbfstool ifdtool; do
[ -f "cbutils/${tree}/${util}" ] && continue [ -f "cbutils/${tree}/${util}" ] && continue
[ -d "cbutils/${tree}" ] || \ [ -d "cbutils/${tree}" ] || x_ mkdir -p "cbutils/${tree}"
mkdir -p "cbutils/${tree}" || \
err "buildutils: can't mkdir cbutils/${tree}"
utildir="coreboot/${tree}/util/${util}" utildir="coreboot/${tree}/util/${util}"
make distclean -C "${utildir}" || \ x_ make distclean -C "${utildir}"
err "buildutils: cannot clean ${utildir}" x_ make -j$(nproc) -C "${utildir}"
make -j$(nproc) -C "${utildir}" || \ x_ cp "${utildir}/${util}" "cbutils/${tree}"
err "buildutils: cannot build ${utildir}" x_ make distclean -C "${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 done
} }

View File

@ -28,8 +28,7 @@ main()
else else
err "${usage}" err "${usage}"
fi fi
mkdir -p "bin/serprog_${platform}" || \ x_ mkdir -p "bin/serprog_${platform}"
err "can't create dir: bin/serprog_${platform}"
if [ $# -gt 1 ] ; then if [ $# -gt 1 ] ; then
if [ "${2}" = "list" ] ; then if [ "${2}" = "list" ] ; then
@ -47,20 +46,18 @@ main()
fetch_repo() fetch_repo()
{ {
./update project repo "${1}" || err "fetch ${1} failed!\n" x_ ./update project repo "${1}"
} }
build_rp2040_rom() build_rp2040_rom()
{ {
board=${1} board=${1}
printf "Building pico-serprog for ${board}\n" printf "Building pico-serprog for ${board}\n"
cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \ x_ cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \
-B "${pico_src_dir}/build" "${pico_src_dir}" \ -B "${pico_src_dir}/build" "${pico_src_dir}"
|| err "can't cmake ${pico_src_dir}" x_ cmake --build "${pico_src_dir}/build"
cmake --build "${pico_src_dir}/build" x_ mv ${pico_src_dir}/build/pico_serprog.uf2 \
mv ${pico_src_dir}/build/pico_serprog.uf2 \ bin/serprog_rp2040/serprog_${board}.uf2
bin/serprog_rp2040/serprog_${board}.uf2 \
|| err "${board} serprog build failed!"
printf "output to bin/serprog_rp2040/serprog_${board}.uf2\n" printf "output to bin/serprog_rp2040/serprog_${board}.uf2\n"
} }
@ -68,11 +65,10 @@ build_stm32_rom()
{ {
board=${1} board=${1}
printf "Building stm32-vserprog for ${board}\n" printf "Building stm32-vserprog for ${board}\n"
make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board} x_ make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board}
make -C ${stm32_src_dir} BOARD=${board} x_ make -C ${stm32_src_dir} BOARD=${board}
mv ${stm32_src_dir}/stm32-vserprog.hex \ x_ mv ${stm32_src_dir}/stm32-vserprog.hex \
bin/serprog_stm32/serprog_${board}.hex \ bin/serprog_stm32/serprog_${board}.hex
|| err "${board} serprog build failed!"
printf "output to bin/serprog_stm32/serprog_${board}.hex\n" printf "output to bin/serprog_stm32/serprog_${board}.hex\n"
} }

View File

@ -22,16 +22,12 @@ main()
handle_dependencies() handle_dependencies()
{ {
[ -d "grub/" ] || \ [ -d "grub/" ] || \
./update project repo grub || \ x_ ./update project repo grub
err "handle_dependencies: cannot fetch grub"
[ -f "grub/grub-mkstandalone" ] || \ [ -f "grub/grub-mkstandalone" ] || \
./build grub utils || \ x_ ./build grub utils
err "handle_dependencies: cannot build grub utils"
[ -d "${elfdir}" ] || \ [ -d "${elfdir}" ] || \
mkdir -p "${elfdir}" || \ x_ mkdir -p "${elfdir}"
err "handle_dependencies: cannot mkdir ${elfdir}" x_ rm -f "${elfdir}/"*
rm -f "${elfdir}/"* || \
err "handle_dependencies: cannot rm inside: ${elfdir}/"
} }
build_keymap_configs() build_keymap_configs()
@ -40,9 +36,8 @@ build_keymap_configs()
[ -f "${keylayoutfile}" ] || continue [ -f "${keylayoutfile}" ] || continue
keymap="${keylayoutfile##${grubcfgsdir}/keymap/}" keymap="${keylayoutfile##${grubcfgsdir}/keymap/}"
keymap="${keymap%.gkb}" keymap="${keymap%.gkb}"
printf "keymap %s\n" "${keymap}" > \ x_ printf "keymap %s\n" "${keymap}" > \
"${elfdir}/keymap_${keymap}.cfg" || \ "${elfdir}/keymap_${keymap}.cfg"
err "mk_keymap: can't make ${elfdir}/keymap_${keymap}.cfg"
done done
} }

View File

@ -10,25 +10,19 @@ set -u -e
main() main()
{ {
[ -d "grub/" ] || ./update project repo grub || err "cannot fetch grub" [ -d "grub/" ] || x_ ./update project repo grub
build_grub build_grub
} }
build_grub() build_grub()
{ {
( (
cd grub/ || \ x_ cd grub/
err "build_grub: cd" [ ! -d Makefile ] || x_ make distclean
[ ! -d Makefile ] || make distclean || \ x_ ./bootstrap --gnulib-srcdir=gnulib/ --no-git
err "build_grub: make-distclean" x_ ./autogen.sh
./bootstrap --gnulib-srcdir=gnulib/ --no-git || \ x_ ./configure --with-platform=coreboot
err "build_grub: gnulib bootstrap" x_ make -j$(nproc) FS_PAYLOAD_MODULES=""
./autogen.sh || \
err "build_grub: autogen.sh"
./configure --with-platform=coreboot || \
err "build_grub: autoconf"
make -j$(nproc) FS_PAYLOAD_MODULES="" || \
err "build_grub: make"
) )
} }

View File

@ -38,41 +38,33 @@ init_check()
[ ! -d "bin/" ] && \ [ ! -d "bin/" ] && \
err "init_check: no ROMs built yet (error)" err "init_check: no ROMs built yet (error)"
[ -d "release/" ] || \ [ -d "release/" ] || \
mkdir -p release/ || \ x_ mkdir -p release/
err "init_check: !mkdir -p release/"
[ -d "release/${version}/" ] || \ [ -d "release/${version}/" ] || \
mkdir -p "release/${version}/" || \ x_ mkdir -p "release/${version}/"
err "init_check: !mkdir -p release/${version}/"
[ ! -d "release/${version}/roms/" ] || \ [ ! -d "release/${version}/roms/" ] || \
rm -Rf "release/${version}/roms/" || \ x_ rm -Rf "release/${version}/roms/"
err "init_check: !rm -Rf release/${version}/roms/"
[ -d "release/${version}/roms/" ] && return 0 [ -d "release/${version}/roms/" ] && return 0
mkdir -p "release/${version}/roms/" || \ x_ mkdir -p "release/${version}/roms/"
err "init_check: !mkdir -p release/${version}/roms/"
} }
make_archive() make_archive()
{ {
builddir="${1}" builddir="${1}"
romdir="tmp/romdir" || \ romdir="tmp/romdir"
err "make_archive: cannot create tmpdir" x_ rm -Rf "${romdir}"
rm -Rf "${romdir}" || err "make_archive: can't remove tmpdir"
target="${builddir##*/}" target="${builddir##*/}"
if [ ! -f "config/coreboot/${target}/target.cfg" ]; then if [ ! -f "config/coreboot/${target}/target.cfg" ]; then
# No config, just make a tarball # No config, just make a tarball
tarball=release/${version}/roms/${target}_${version}.tar.xz tarball=release/${version}/roms/${target}_${version}.tar.xz
tar -c "${builddir}" | xz -T0 -6 > ${tarball} || \ x_ tar -c "${builddir}" | xz -T0 -6 > ${tarball} || \
(rm ${tarball} x_ rm -f ${tarball}
err "make_archive: cannot make \"${tarball}\"")
return 0 return 0
fi fi
romdir="${romdir}/bin/${target}" romdir="${romdir}/bin/${target}"
mkdir -p "${romdir}" || \ x_ mkdir -p "${romdir}"
err "make_archive: can't mkdir tmpdir" x_ cp "${builddir}"/* "${romdir}"
cp "${builddir}"/* "${romdir}" || \
err "make_archive: cannot copy ROM images directory -> ${romdir}"
printf "%s\n" "${target}" printf "%s\n" "${target}"
@ -97,24 +89,18 @@ make_archive()
printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \ printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
"${version}" "${projectname}" "${version}" "${target##*/}" "${version}" "${projectname}" "${version}" "${target##*/}"
printf "%s\n" "${version}" > "${romdir}/version" || \ x_ printf "%s\n" "${version}" > "${romdir}/version"
err "make_archive: can't create ${romdir}/version" x_ printf "%s\n" "${versiondate}" > "${romdir}/versiondate"
printf "%s\n" "${versiondate}" > "${romdir}/versiondate" || \ x_ printf "%s\n" "${projectname}" > "${romdir}/projectname"
err "make_archive: can't create ${romdir}/versiondate"
printf "%s\n" "${projectname}" > "${romdir}/projectname" || \
err "make_archive: can't create ${romdir}/projectname"
archivename="${projectname}-${version}_${target##*/}" archivename="${projectname}-${version}_${target##*/}"
f="release/${version}/roms/${archivename}" f="release/${version}/roms/${archivename}"
( (
cd "${romdir%/bin/${target}}" || err "make_archive: can't cd to tmpdir" x_ cd "${romdir%/bin/${target}}"
tar -c "bin/${target}/" | xz -T0 -9e > "${archivename}.tar.xz" || \ x_ tar -c "bin/${target}/" | xz -T0 -9e > "${archivename}.tar.xz"
err "make_archive:cant make ${projectname}-${version}_${target##*/}"
) )
mv "${romdir%/bin/${target}}/${archivename}.tar.xz" "${f}.tar.xz" || \ x_ mv "${romdir%/bin/${target}}/${archivename}.tar.xz" "${f}.tar.xz"
err "make_archive: can't copy tarball" x_ rm -Rf "${romdir%/bin/${target}}"
rm -Rf "${romdir%/bin/${target}}" || \
err "make_archive: can't delete tmpdir"
} }
strip_archive() strip_archive()
@ -122,10 +108,8 @@ strip_archive()
romdir=${1} romdir=${1}
[ -d "coreboot/${tree}" ] || \ [ -d "coreboot/${tree}" ] || \
./update project trees coreboot ${tree} || \ x_ ./update project trees coreboot ${tree}
err "strip_archive: coreboot/${tree}: can't fetch source" x_ ./build coreboot utils ${tree}
./build coreboot utils ${tree} || \
err "strip_archive: coreboot/${tree}: can't build utils"
if [ "${microcode_required}" = "n" ]; then if [ "${microcode_required}" = "n" ]; then
for romfile in "${romdir}"/*.rom; do for romfile in "${romdir}"/*.rom; do
@ -134,21 +118,17 @@ strip_archive()
done done
for romfile in "${romdir}"/*.tmprom; do for romfile in "${romdir}"/*.tmprom; do
[ -f "${romfile}" ] || continue [ -f "${romfile}" ] || continue
mv "${romfile}" "${romfile%.tmprom}.rom" || \ x_ mv "${romfile}" "${romfile%.tmprom}.rom"
err "can't make no-u rom: ${romfile%.tmprom}.rom"
done done
fi fi
# Hash the rom before removing blobs # Hash the rom before removing blobs
rm -f "${romdir}/blobhashes" || \ x_ rm -f "${romdir}/blobhashes"
err "strip_archive: !rm -f ${blobdir}/blobhashes" x_ touch "${romdir}/blobhashes"
touch "${romdir}/blobhashes" || \
err "strip_archive: !touch ${blobdir}/blobhashes"
( (
cd "${romdir}" || err "strip_archive: !cd ${romdir}" x_ cd "${romdir}"
sha512sum *.rom >> blobhashes || \ x_ sha512sum *.rom >> blobhashes
err "strip_archive: ${romdir}: !sha512sum *.rom >> blobhashes"
) )
for romfile in "${romdir}"/*.rom; do for romfile in "${romdir}"/*.rom; do
@ -161,40 +141,32 @@ strip_ucode()
{ {
romfile=${1} romfile=${1}
_newrom_b="${romfile%.rom}_nomicrocode.tmprom" _newrom_b="${romfile%.rom}_nomicrocode.tmprom"
cp "${romfile}" "${_newrom_b}" || \ x_ cp "${romfile}" "${_newrom_b}"
err "strip_rom_image: cp \"${romfile}\" \"${_newrom_b}\""
microcode_present="y" microcode_present="y"
"${cbfstool}" "${_newrom_b}" remove -n \ "${cbfstool}" "${_newrom_b}" remove -n \
cpu_microcode_blob.bin 2>/dev/null || microcode_present="n" cpu_microcode_blob.bin 2>/dev/null || microcode_present="n"
[ "${microcode_present}" = "n" ] || return 0 [ "${microcode_present}" = "n" ] || return 0
printf "REMARK: '%s' already lacks microcode\n" "${romfile}" 1>&2 printf "REMARK: '%s' already lacks microcode\n" "${romfile}" 1>&2
printf "Renaming default ROM file instead.\n" 1>&2 printf "Renaming default ROM file instead.\n" 1>&2
mv "${romfile}" "${_newrom_b}" || \ x_ mv "${romfile}" "${_newrom_b}"
err "strip_rom_image: can't rename no-u ${romfile}"
} }
strip_rom_image() strip_rom_image()
{ {
[ -f "${1}" ] || return 0 [ -f "${1}" ] || return 0
[ "${CONFIG_HAVE_ME_BIN}" != "y" ] || \ [ "${CONFIG_HAVE_ME_BIN}" != "y" ] || \
"${ifdtool}" --nuke me "${1}" -O "${1}" || \ x_ "${ifdtool}" --nuke me "${1}" -O "${1}"
err "strip_rom_images: ${1}: cannot nuke Intel ME"
[ "${CONFIG_HAVE_MRC}" != "y" ] || \ [ "${CONFIG_HAVE_MRC}" != "y" ] || \
"${cbfstool}" "${1}" remove -n mrc.bin || \ x_ "${cbfstool}" "${1}" remove -n mrc.bin
err "strip_rom_images: ${1}: cannot nuke mrc.bin"
[ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" != "y" ] || \ [ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" != "y" ] || \
"${cbfstool}" "${1}" remove -n sch5545_ecfw.bin || \ x_ "${cbfstool}" "${1}" remove -n sch5545_ecfw.bin
err "strip_rom_images: ${1}: can't nuke sch5545ec fw"
if [ "${CONFIG_KBC1126_FIRMWARE}" = "y" ]; then if [ "${CONFIG_KBC1126_FIRMWARE}" = "y" ]; then
"${cbfstool}" "${1}" remove -n ecfw1.bin || \ x_ "${cbfstool}" "${1}" remove -n ecfw1.bin
err "strip_rom_images: ${1}: can't nuke ecfw1.bin" x_ "${cbfstool}" "${1}" remove -n ecfw2.bin
"${cbfstool}" "${1}" remove -n ecfw2.bin || \
err "strip_rom_images: ${1}: can't nuke ecfw2.bin"
fi fi
# TODO: replace this board-specific hack # TODO: replace this board-specific hack
[ "${target}" = "e6400_4mb" ] || return 0 [ "${target}" = "e6400_4mb" ] || return 0
"${cbfstool}" "${1}" remove -n "pci10de,06eb.rom" || \ x_ "${cbfstool}" "${1}" remove -n "pci10de,06eb.rom"
err "strip_rom_images: ${1}: can't nuke e6400 vga rom"
} }
main $@ main $@

View File

@ -45,31 +45,23 @@ create_release_directory()
dirname="${projectname}-${version}_src" dirname="${projectname}-${version}_src"
srcdir="${reldir}/${dirname}" srcdir="${reldir}/${dirname}"
[ -d "release/" ] || mkdir -p release/ || \ [ -d "release/" ] || x_ mkdir -p release/
err "create_release_directory: !mkdir -p release/" [ -d "${reldir}/" ] || x_ mkdir -p "${reldir}/"
[ -d "${reldir}/" ] || mkdir -p "${reldir}/" || \ [ ! -d "${srcdir}/" ] || x_ rm -Rf "${srcdir}/"
err "create_release_directory: !mkdir -p ${reldir}/"
[ ! -d "${srcdir}/" ] || rm -Rf "${srcdir}/" || \
err "create_release_directory: !rm -Rf ${srcdir}/"
[ ! -f "${srcdir}.tar.xz" ] || \ [ ! -f "${srcdir}.tar.xz" ] || \
rm -f "${srcdir}.tar.xz/" || \ x_ rm -f "${srcdir}.tar.xz/"
err "create_release_directory: !rm -f ${srcdir}.tar.xz/"
mkdir -p "${srcdir}/" || \ x_ mkdir -p "${srcdir}/"
err "create_release_directory: !mkdir -p ${srcdir}/" x_ printf "%s" "${version}" > "${srcdir}"/version
printf "%s" "${version}" > "${srcdir}"/version || \
err "create_release_directory: ${srcdir}/version: can't create file"
} }
download_modules() download_modules()
{ {
for modname in ${trees_fetch_list}; do for modname in ${trees_fetch_list}; do
[ -d "${modname}" ] || ./update project trees ${modname} || \ [ -d "${modname}" ] || x_ ./update project trees ${modname}
err "download_modules: couldn't download ${modname} trees"
done done
for modname in ${simple_fetch_list} ${download_only_list}; do for modname in ${simple_fetch_list} ${download_only_list}; do
[ -d "${modname}/" ] || ./update project repo ${modname} || \ [ -d "${modname}/" ] || x_ ./update project repo ${modname}
err "download_modules: couldn't download ${modname} repo"
done done
} }
@ -80,34 +72,27 @@ copy_files()
for subdir in "${dir}"/*; do for subdir in "${dir}"/*; do
[ -d "${subdir}" ] || continue [ -d "${subdir}" ] || continue
[ "${subdir##*/}" = "${dir}" ] && continue [ "${subdir##*/}" = "${dir}" ] && continue
mkdir -p "${srcdir}/${dir}" || \ x_ mkdir -p "${srcdir}/${dir}"
err "copy_files: !mkdir -p ${srcdir}/${dir}"
[ ! -d "${srcdir}/${dir}/${subdir##*/}" ] || \ [ ! -d "${srcdir}/${dir}/${subdir##*/}" ] || \
rm -Rf "${srcdir}/${dir}/${subdir##*/}" || \ x_ rm -Rf "${srcdir}/${dir}/${subdir##*/}"
err "copy_f:can't rm ${srcdir}/${dir}/${subdir##*/}" x_ cp -R "${subdir}" "${srcdir}/${dir}/${subdir##*/}"
cp -R "${subdir}" "${srcdir}/${dir}/${subdir##*/}" || \
err "copy_f:can't cp ${srcdir}/${dir}/${subdir##*/}"
done done
done done
for dir in ${simple_fetch_list} ${dirlist}; do for dir in ${simple_fetch_list} ${dirlist}; do
cp -R "${dir}/" "${srcdir}/" || \ x_ cp -R "${dir}/" "${srcdir}/"
err "copy_files: !cp -R ${dir}/ ${srcdir}/"
done done
for i in ${filelist}; do for i in ${filelist}; do
if [ ! -f "${i}" ]; then if [ ! -f "${i}" ]; then
rm -Rf "${srcdir}" || \ x_ rm -Rf "${srcdir}"
err "copy_files: !rm -Rf ${srcdir}"
err "copy_files: file '${i}' does not exist" err "copy_files: file '${i}' does not exist"
fi fi
cp "${i}" "${srcdir}/" || \ x_ cp "${i}" "${srcdir}/"
err "copy_files: !cp ${i} ${srcdir}/"
done done
( (
cd "${srcdir}/" || err "copy_files: can't enter dir: ${srcdir}/" x_ cd "${srcdir}/"
for i in ${linklist}; do for i in ${linklist}; do
ln -s lbmk "${i}" || \ x_ ln -s lbmk "${i}"
err "copy_files: cannot create symlink: ${i} -> lbmk"
done done
) )
} }
@ -115,55 +100,40 @@ copy_files()
purge_files() purge_files()
{ {
( (
cd "${srcdir}/" || err "purge_files 3: !cd ${srcdir}/" x_ cd "${srcdir}/"
[ ! -d "coreboot/default/util/kbc1126" ] || \ [ ! -d "coreboot/default/util/kbc1126" ] || \
./handle make file -c "coreboot/default/util/kbc1126" || \ x_ ./handle make file -c "coreboot/default/util/kbc1126"
err "purge_files 1: default/util/kbc1126: ! make clean" x_ ./handle make config -x coreboot
./handle make config -x coreboot || \
err "purge_files: coreboot: cannot clean crossgcc files"
for p in u-boot seabios coreboot; do for p in u-boot seabios coreboot; do
./handle make config -c "${p}" || \ x_ ./handle make config -c "${p}"
err "purge_files: ${p}: cannot clean the source trees"
done done
for p in bios_extract flashrom grub uefitool; do for p in bios_extract flashrom grub uefitool; do
./handle make file -c "${p}" || \ x_ ./handle make file -c "${p}"
err "purge_files: !./handle make file -c ${p}"
done done
for p in "stm32-vserprog" "stm32-vserprog/libopencm3"; do for p in "stm32-vserprog" "stm32-vserprog/libopencm3"; do
./handle make file -c "util-fw/${p}" || \ x_ ./handle make file -c "util-fw/${p}"
err "purge_files !./handle make file util-fw/${p}"
done done
for p in 32 64; do for p in 32 64; do
./handle make file -c "memtest86plus/build${p}" || \ x_ ./handle make file -c "memtest86plus/build${p}"
err "purge_files: cannot clean memtest86+ build${p}"
done done
for p in "nvmutil" "spkmodem_recv" "e6400-flash-unlock"; do for p in "nvmutil" "spkmodem_recv" "e6400-flash-unlock"; do
make clean -C "util/${p}" || \ x_ make clean -C "util/${p}"
err "purge_files 2: !make clean -C ${util}/p"
done done
for p in ${trees_fetch_list}; do for p in ${trees_fetch_list}; do
rm -Rf "${p}/${p}" "${p}"/*/.git* || \ x_ rm -Rf "${p}/${p}" "${p}"/*/.git*
err "purge_files 1: cannot clean ${p} project files"
done done
rm -Rf .git* */.git* */*/.git* */*/*/.git* */*/*/*/.git* \ x_ rm -Rf .git* */.git* */*/.git* */*/*/.git* */*/*/*/.git* \
*/*/*/*/*/.git* */*/*/*/*/*/.git* */*/*/*/*/*/*/.git* || \ */*/*/*/*/.git* */*/*/*/*/*/.git* */*/*/*/*/*/*/.git*
err "purge_files rm-rf2: can't purge .git files/directories" x_ rm -Rf cbutils elf util-fw/rp2040/pico-serprog/build
rm -Rf cbutils || err "purge_files: can't remove ${srcdir}/cbutils/"
rm -Rf elf || err "purge_files: can't remove ${srcdir}/elf/"
rm -Rf util-fw/rp2040/pico-serprog/build || \
err "purge_files: can't remove pico-serprog/build"
) )
} }
create_release_archive() create_release_archive()
{ {
( (
cd "${reldir}/" || \ x_ cd "${reldir}/"
err "create_release_archive 4: !cd ${reldir}/" x_ tar -c "${dirname}/" | xz -T0 -9e >"${dirname}.tar.xz"
tar -c "${dirname}/" | xz -T0 -9e >"${dirname}.tar.xz" || \ x_ rm -Rf "${dirname}/"
err "create_release_archive: can't create ${dirname}.tar.xz"
rm -Rf "${dirname}/" || \
err "create_release_archive 5: !rm -Rf ${dirname}/"
) )
} }

View File

@ -56,8 +56,7 @@ handle_dependencies()
fail "Cannot get options for ${cfgsdir}" fail "Cannot get options for ${cfgsdir}"
[ $# -gt 0 ] && targets=$@ [ $# -gt 0 ] && targets=$@
[ -d "${elfdir}" ] || [ "${mode}" != "all" ] || \ [ "${mode}" = "all" ] && xx_ mkdir -p "${elfdir}/"
mkdir -p "${elfdir}/" || fail "can't create directory ${elfdir}"
} }
handle_targets() handle_targets()
@ -67,8 +66,8 @@ handle_targets()
printf "Running 'make %s' for project '%s, target '%s''\n" \ printf "Running 'make %s' for project '%s, target '%s''\n" \
"${mode}" "${project}" "${target}" "${mode}" "${project}" "${target}"
[ "${project}" != "coreboot" ] || [ "${mode}" != "all" ] || \ [ "${project}" != "coreboot" ] || [ "${mode}" != "all" ] || \
./update blobs download ${target} || fail "blobutil" xx_ ./update blobs download ${target}
handle_defconfig || fail "error handling config file" xx_ handle_defconfig
done done
[ "${mode}" = "all" ] || return 0 [ "${mode}" = "all" ] || return 0
@ -96,8 +95,7 @@ handle_defconfig()
handle_src_tree() handle_src_tree()
{ {
target_dir="${cfgsdir}/${target}" target_dir="${cfgsdir}/${target}"
mkdir -p "${elfdir}/${target}" || \ xx_ mkdir -p "${elfdir}/${target}"
fail "handle_src_tree: !mkdir -p ${elfdir}/${target}"
eval "$(setvars "undefined" arch tree)" eval "$(setvars "undefined" arch tree)"
romtype="normal" romtype="normal"
@ -121,8 +119,7 @@ handle_src_tree()
"${codedir}" 1>&2 "${codedir}" 1>&2
return 1 return 1
fi fi
./update project trees "${project}" "${target}" || \ xx_ ./update project trees "${project}" "${target}"
fail "handle_src_tree: can't fetch ${project}/${target}"
elif [ "${mode}" = "distclean" ] || \ elif [ "${mode}" = "distclean" ] || \
[ "${mode}" = "crossgcc-clean" ]; then [ "${mode}" = "crossgcc-clean" ]; then
[ -f "${tmpclean}/${tree}" ] && return 1 [ -f "${tmpclean}/${tree}" ] && return 1
@ -134,8 +131,7 @@ handle_src_tree()
[ "${mode}" != "all" ] || check_cross_compiler || \ [ "${mode}" != "all" ] || check_cross_compiler || \
fail "handle_src_tree ${project}/${target}: crossgcc" fail "handle_src_tree ${project}/${target}: crossgcc"
cbfstool="cbutils/${tree}/cbfstool" cbfstool="cbutils/${tree}/cbfstool"
[ -f "${cbfstool}" ] || ./build coreboot utils "${tree}" || \ [ -f "${cbfstool}" ] || xx_ ./build coreboot utils "${tree}"
fail "handle_src_tree: cannot build cbfstool"
fi fi
} }
@ -156,8 +152,7 @@ check_cross_compiler()
# only true if not building coreboot: # only true if not building coreboot:
ctarget="${cbdir#coreboot/}" ctarget="${cbdir#coreboot/}"
[ -d "${cbdir}" ] || \ [ -d "${cbdir}" ] || \
./update project trees coreboot ${ctarget} || \ xx_ ./update project trees coreboot ${ctarget}
fail "check_cross_compiler: can't fetch coreboot/${ctarget}"
if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
[ -d "${cbdir}/util/crossgcc/xgcc/i386-elf/" ] || \ [ -d "${cbdir}/util/crossgcc/xgcc/i386-elf/" ] || \
@ -205,17 +200,13 @@ check_config()
printf "Build already exists, so skipping build\n" 1>&2 printf "Build already exists, so skipping build\n" 1>&2
return 1 return 1
done done
mkdir -p "${dest_dir}" || \ xx_ mkdir -p "${dest_dir}"
fail "check_config: cannot mkdir: ${dest_dir}"
} }
run_make_command() run_make_command()
{ {
./handle make file -c "${codedir}" || \ xx_ ./handle make file -c "${codedir}"
fail "run_make_command: make distclean/clean failed" xx_ cp "${config}" "${codedir}/.config"
cp "${config}" "${codedir}/.config" || \
fail "run_make_command: can't copy config for: ${project}/${target}"
[ "${mode}" != "all" ] || make -C "${codedir}" silentoldconfig || \ [ "${mode}" != "all" ] || make -C "${codedir}" silentoldconfig || \
make -C "${codedir}" oldconfig || : # don't error on oldconfig make -C "${codedir}" oldconfig || : # don't error on oldconfig
@ -223,30 +214,26 @@ run_make_command()
printf "%s\n" "${our_version}" >"${codedir}/.coreboot-version" \ printf "%s\n" "${our_version}" >"${codedir}/.coreboot-version" \
|| fail "run_make_command: ${codedir}: can't set version" || fail "run_make_command: ${codedir}: can't set version"
fi fi
make -C "${codedir}" -j$(nproc) ${mode} || \ xx_ make -C "${codedir}" -j$(nproc) ${mode}
fail "run_make: !make-${mode}: ${codedir} (${project}/${target})"
if [ -e "${codedir}/.git" ] && [ "${project}" = "u-boot" ] && \ if [ -e "${codedir}/.git" ] && [ "${project}" = "u-boot" ] && \
[ "${mode}" = "distclean" ]; then [ "${mode}" = "distclean" ]; then
git -C "${codedir}" clean -fdx || \ xx_ git -C "${codedir}" clean -fdx
fail "run_make_command: ${codedir}: cannot clean u-boot git"
elif [ "${mode}" = "oldconfig" ] || [ "${mode}" = "menuconfig" ]; then elif [ "${mode}" = "oldconfig" ] || [ "${mode}" = "menuconfig" ]; then
cp "${codedir}/.config" "${config}" || \ xx_ cp "${codedir}/.config" "${config}"
fail "run_make: can't edit config: ${project}/${target}"
fi fi
} }
copy_elf() copy_elf()
{ {
[ "${project}" != "coreboot" ] || modify_coreboot_rom || \ [ "${project}" != "coreboot" ] || xx_ modify_coreboot_rom
fail "copy_elf: cannot prepare coreboot image"
while read f; do while read f; do
[ ! -f "${codedir}/$f" ] || cp "${codedir}/${f}" \ [ ! -f "${codedir}/$f" ] || \
"${dest_dir}/" || fail "copy_elf: cannot copy elf file" xx_ cp "${codedir}/${f}" "${dest_dir}/"
done < ${listfile} done < ${listfile}
./handle make file -c "${codedir}" || \ xx_ ./handle make file -c "${codedir}"
fail "copy_elf: clean: ${codedir} (${project}/${target})"
} }
modify_coreboot_rom() modify_coreboot_rom()
@ -255,32 +242,26 @@ modify_coreboot_rom()
[ -f "${rompath}" ] || \ [ -f "${rompath}" ] || \
fail "modify_coreboot_rom: does not exist: ${rompath}" fail "modify_coreboot_rom: does not exist: ${rompath}"
tmprom="$(mktemp -t rom.XXXXXXXXXX)" tmprom="$(mktemp -t rom.XXXXXXXXXX)"
rm -f "${tmprom}" || \ xx_ rm -f "${tmprom}"
fail "modify_coreboot_rom prep: cannot remove tmprom"
if [ "${romtype}" = "d8d16sas" ]; then if [ "${romtype}" = "d8d16sas" ]; then
# pike2008 roms hang seabios. an empty rom will override # pike2008 roms hang seabios. an empty rom will override
# the built-in one, thus disabling all execution of it # the built-in one, thus disabling all execution of it
touch "${tmprom}" || \ xx_ touch "${tmprom}"
fail "modify_coreboot_rom: cannot create fake oprom"
for deviceID in "0072" "3050"; do for deviceID in "0072" "3050"; do
"${cbfstool}" "${rompath}" add -f "${tmprom}" \ xx_ "${cbfstool}" "${rompath}" add -f "${tmprom}" \
-n "pci1000,${deviceID}.rom" -t raw || \ -n "pci1000,${deviceID}.rom" -t raw
fail "modify_coreboot_rom: can't insert fake rom"
done done
elif [ "${romtype}" = "i945 laptop" ]; then elif [ "${romtype}" = "i945 laptop" ]; then
# for bucts-based installation method from factory bios # for bucts-based installation method from factory bios
dd if="${rompath}" of="${tmprom}" bs=1 \ xx_ dd if="${rompath}" of="${tmprom}" bs=1 \
skip=$(($(stat -c %s "${rompath}") - 0x10000)) \ skip=$(($(stat -c %s "${rompath}") - 0x10000)) \
count=64k || \ count=64k
fail "modify_coreboot_rom: can't read i945 bootblock" xx_ dd if="${tmprom}" of="${rompath}" bs=1 \
dd if="${tmprom}" of="${rompath}" bs=1 \
seek=$(($(stat -c %s "${rompath}") - 0x20000)) \ seek=$(($(stat -c %s "${rompath}") - 0x20000)) \
count=64k conv=notrunc || \ count=64k conv=notrunc
fail "modify_coreboot_rom: can't write i945 bootblock"
fi fi
rm -f "${tmprom}" || \ xx_ rm -f "${tmprom}"
fail "modify_coreboot_rom: cannot remove tmprom"
} }
fail() fail()

View File

@ -29,14 +29,13 @@ main()
handle_dependencies() handle_dependencies()
{ {
[ -d "${project}" ] || ./update project repo "${project%/*}" || \ [ -d "${project}" ] || x_ ./update project repo "${project%/*}"
err "handle_dependencies: can't fetch ${project%/*}"
[ -d "${project}" ] || \ [ -d "${project}" ] || \
err "handle_dependencies: ${project%/*} not downloaded" err "handle_dependencies: ${project%/*} not downloaded"
[ "${project}" = "uefitool" ] || return 0 # TODO: remove hardcoding [ "${project}" = "uefitool" ] || return 0 # TODO: remove hardcoding
( (
cd uefitool || err "handle_dependencies: !cd uefitool" x_ cd uefitool
cmake UEFIExtract/ || [ -f Makefile ] || \ cmake UEFIExtract/ || [ -f Makefile ] || \
err "handle_dependencies: !cmake UEFIExtract/" err "handle_dependencies: !cmake UEFIExtract/"
) )
@ -45,11 +44,9 @@ handle_dependencies()
run_make_command() run_make_command()
{ {
if [ -z "${mode}" ]; then if [ -z "${mode}" ]; then
make -C "${project}" -j$(nproc) || \ x_ make -C "${project}" -j$(nproc)
err "run_make_command: !make -C ${project}"
else else
make -C "${project}" clean || \ x_ make -C "${project}" clean
err "run_make_command: ${project}: make-clean failed"
make -C "${project}" distclean || : make -C "${project}" distclean || :
fi fi
} }

View File

@ -41,21 +41,16 @@ detect_firmware()
build_dependencies() build_dependencies()
{ {
[ -d ${cbdir} ] || \ [ -d ${cbdir} ] || \
./update project trees coreboot ${cbdir##*/} || \ x_ ./update project trees coreboot ${cbdir##*/}
err "build_dependencies: can't fetch ${cbdir}"
for d in uefitool biosutilities bios_extract me_cleaner; do for d in uefitool biosutilities bios_extract me_cleaner; do
[ -d "${d}" ] && continue [ -d "${d}" ] && continue
./update project repo "${d}" || \ x_ ./update project repo "${d}"
err "build_dependencies: can't fetch ${d}"
done done
[ -f uefitool/uefiextract ] || \ [ -f uefitool/uefiextract ] || \
./handle make file -b uefitool || \ x_ ./handle make file -b uefitool
err "build_dependencies: can't build uefitool"
[ -f "${cbdir}/util/kbc1126/kbc1126_ec_dump" ] || \ [ -f "${cbdir}/util/kbc1126/kbc1126_ec_dump" ] || \
make -C "${cbdir}/util/kbc1126" || \ x_ make -C "${cbdir}/util/kbc1126"
err "build_dependencies: can't build kbc1126_ec_dump" x_ ./build coreboot utils default
./build coreboot utils default || \
err "build_dependencies: cannot build utils in cbutils/default/"
} }
download_blobs() download_blobs()
@ -117,13 +112,12 @@ extract_intel_me()
extract_kbc1126ec() extract_kbc1126ec()
{ {
( (
cd "${appdir}/" || \ x_ cd "${appdir}/"
err "extract_kbc1126_ec: !cd \"${appdir}/\""
mv Rompaq/68*.BIN ec.bin || : mv Rompaq/68*.BIN ec.bin || :
if [ ! -f ec.bin ]; then if [ ! -f ec.bin ]; then
unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \ unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \
unar -D 68*.CAB Rom.bin || err "extract_kbc1126_ec !extract" x_ unar -D 68*.CAB Rom.bin
mv Rom.bin ec.bin || err "extract_kbc1126_ec: *didn't* extract" x_ mv Rom.bin ec.bin
fi fi
[ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract" [ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract"
"${kbc1126_ec_dump}" ec.bin || \ "${kbc1126_ec_dump}" ec.bin || \
@ -135,8 +129,7 @@ extract_kbc1126ec()
done done
[ "${ec_ex}" = "y" ] || \ [ "${ec_ex}" = "y" ] || \
err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin" err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin"
cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" || \ x_ cp "${appdir}/"ec.bin.fw* "${_dest%/*}/"
err "extract_kbc1126_ec: cant mv ecfw1/2 ${_dest%/*}"
} }
extract_e6400vga() extract_e6400vga()
@ -148,14 +141,13 @@ extract_e6400vga()
tail -c +${E6400_VGA_offset} "${_dl}" | \ tail -c +${E6400_VGA_offset} "${_dl}" | \
gunzip >"${appdir}/bios.bin" || : gunzip >"${appdir}/bios.bin" || :
( (
cd "${appdir}" || err "extract_e6400vga: can't cd ${appdir}" x_ cd "${appdir}"
[ -f "bios.bin" ] || err "extract_e6400vga: can't extract bios.bin" [ -f "bios.bin" ] || err "extract_e6400vga: can't extract bios.bin"
"${e6400_unpack}" bios.bin || printf "TODO: fix dell extract util\n" "${e6400_unpack}" bios.bin || printf "TODO: fix dell extract util\n"
[ -f "${E6400_VGA_romname}" ] || \ [ -f "${E6400_VGA_romname}" ] || \
err "extract_e6400vga: can't extract vga rom from bios.bin" err "extract_e6400vga: can't extract vga rom from bios.bin"
) )
cp "${appdir}"/"${E6400_VGA_romname}" "${_dest}" || \ x_ cp "${appdir}"/"${E6400_VGA_romname}" "${_dest}"
err "extract_e6400vga: can't copy vga rom to ${_dest}"
} }
# TODO: this code is cancer. hardcoded is bad, and stupid. # TODO: this code is cancer. hardcoded is bad, and stupid.

View File

@ -82,18 +82,15 @@ detect_board()
err "detect_board: could not detect board type" err "detect_board: could not detect board type"
esac esac
[ -d "${boarddir}/" ] || \ [ -d "${boarddir}/" ] || \
err "detect_board: dir, ${boarddir}, doesn't exist" err "detect_board: dir, ${boarddir}, doesn't exist"
printf "%s\n" "${board}" printf "%s\n" "${board}"
} }
build_dependencies() build_dependencies()
{ {
[ -d "${cbdir}" ] || ./update project trees coreboot default || \ [ -d "${cbdir}" ] || x_ ./update project trees coreboot default
err "build_dependencies: could not download coreboot/default" x_ ./build coreboot utils default
./build coreboot utils default || \ x_ ./update blobs download ${board}
err "build_dependencies: could not build cbutils"
./update blobs download ${board} || \
err "build_dependencies: Could not download blobs for ${board}"
} }
inject_blobs() inject_blobs()
@ -104,35 +101,31 @@ inject_blobs()
release_archive="y" release_archive="y"
patch_release_roms patch_release_roms
else else
patch_rom "${rom}" || \ x_ patch_rom "${rom}"
err "inject_blobs: could not patch ${x}"
fi fi
} }
patch_release_roms() patch_release_roms()
{ {
_tmpdir="tmp/romdir" _tmpdir="tmp/romdir"
rm -Rf "${_tmpdir}" || err "patch_release_roms 1: can't prepare tmpdir" x_ rm -Rf "${_tmpdir}"
mkdir -p "${_tmpdir}" || err "patch_release_roms: can't make tmpdir" x_ mkdir -p "${_tmpdir}"
tar -xf "${releasearchive}" -C "${_tmpdir}" || \ x_ tar -xf "${releasearchive}" -C "${_tmpdir}"
err "patch_release_roms: could not extract release archive"
for x in "${_tmpdir}"/bin/*/*.rom ; do for x in "${_tmpdir}"/bin/*/*.rom ; do
printf "patching rom: %s\n" "$x" printf "patching rom: %s\n" "$x"
patch_rom "${x}" || err "patch_release_roms: could not patch ${x}" x_ patch_rom "${x}"
done done
for x in "${_tmpdir}"/bin/*/*_nomicrocode.rom ; do for x in "${_tmpdir}"/bin/*/*_nomicrocode.rom ; do
[ -f "${x}" ] || continue [ -f "${x}" ] || continue
[ -f "${x%_nomicrocode.rom}.rom" ] || continue [ -f "${x%_nomicrocode.rom}.rom" ] || continue
cp "${x%_nomicrocode.rom}.rom" "${x}" || \ x_ cp "${x%_nomicrocode.rom}.rom" "${x}"
err "patch_release_roms: ${x}: can't overwrite no-ucode rom" x_ "${cbfstool}" "${x}" remove -n cpu_microcode_blob.bin
"${cbfstool}" "${x}" remove -n cpu_microcode_blob.bin || \
err "patch_release_roms: ${x}: cannot remove u-code"
done done
( (
cd "${_tmpdir}"/bin/* x_ cd "${_tmpdir}/bin/"*
# NOTE: For compatibility with older rom releases, defer to sha1 # NOTE: For compatibility with older rom releases, defer to sha1
sha512sum --status -c blobhashes || \ sha512sum --status -c blobhashes || \
@ -146,14 +139,12 @@ patch_release_roms()
done done
fi fi
[ -d bin/release ] || mkdir -p bin/release || \ [ -d bin/release ] || x_ mkdir -p bin/release
err "patch_release_roms: !mkdir -p bin/release" x_ mv "${_tmpdir}"/bin/* bin/release/
mv "${_tmpdir}"/bin/* bin/release/ || \
err "patch_release_roms: !mv ${_tmpdir}/bin/* bin/release/"
printf "Success! Your ROMs are in bin/release\n" printf "Success! Your ROMs are in bin/release\n"
rm -Rf "${_tmpdir}" || err "patch_release_roms: !rm -Rf ${_tmpdir}" x_ rm -Rf "${_tmpdir}"
} }
patch_rom() patch_rom()
@ -170,7 +161,7 @@ patch_rom()
[ -f "${rom%_nomicrocode.rom}.rom" ] && \ [ -f "${rom%_nomicrocode.rom}.rom" ] && \
[ "${release_archive}" = "y" ] && return 0 [ "${release_archive}" = "y" ] && return 0
check_defconfig "${boarddir}" || err "patch_rom ${rom}: no defconfig" x_ check_defconfig "${boarddir}"
set -- "${boarddir}/config/"* set -- "${boarddir}/config/"*
. "${1}" 2>/dev/null . "${1}" 2>/dev/null
@ -217,8 +208,8 @@ inject_blob_intel_mrc()
# source code, and it is *always* correct for haswell platform. # source code, and it is *always* correct for haswell platform.
# TODO: this logic should be tweaked to handle more platforms # TODO: this logic should be tweaked to handle more platforms
"${cbfstool}" "${rom}" add -f mrc/haswell/mrc.bin -n mrc.bin -t mrc \ x_ "${cbfstool}" "${rom}" add -f mrc/haswell/mrc.bin -n mrc.bin \
-b 0xfffa0000 || err "inject_blob_intel_mrc: cannot insert mrc.bin" -t mrc -b 0xfffa0000
} }
inject_blob_intel_me() inject_blob_intel_me()
@ -233,8 +224,7 @@ inject_blob_intel_me()
[ ! -f "${_me_location}" ] && \ [ ! -f "${_me_location}" ] && \
err "inject_blob_intel_me: per CONFIG_ME_BIN_PATH: file missing" err "inject_blob_intel_me: per CONFIG_ME_BIN_PATH: file missing"
"${ifdtool}" -i me:"${_me_location}" "${rom}" -O "${rom}" || \ x_ "${ifdtool}" -i me:"${_me_location}" "${rom}" -O "${rom}"
err "inject_blob_intel_me: cannot insert me.bin"
} }
inject_blob_hp_kbc1126_ec() inject_blob_hp_kbc1126_ec()
@ -258,12 +248,10 @@ inject_blob_hp_kbc1126_ec()
err "inject_blob_hp_kbc1126_ec: ${board}: ecfw not downloaded" err "inject_blob_hp_kbc1126_ec: ${board}: ecfw not downloaded"
fi fi
"${cbfstool}" "${rom}" add -f "${_ec1_location}" -n ecfw1.bin \ x_ "${cbfstool}" "${rom}" add -f "${_ec1_location}" -n ecfw1.bin \
-b ${_ec1_offset} -t raw || \ -b ${_ec1_offset} -t raw
err "inject_blob_hp_kbc1126_ec: cannot insert ecfw1.bin" x_ "${cbfstool}" "${rom}" add -f "${_ec2_location}" -n ecfw2.bin \
"${cbfstool}" "${rom}" add -f "${_ec2_location}" -n ecfw2.bin \ -b ${_ec2_offset} -t raw
-b ${_ec2_offset} -t raw || \
err "inject_blob_hp_kbc1126_ec: cannot insert ecfw2.bin"
} }
inject_blob_dell_e6400_vgarom_nvidia() inject_blob_dell_e6400_vgarom_nvidia()
@ -276,29 +264,24 @@ inject_blob_dell_e6400_vgarom_nvidia()
printf "adding pci option rom\n" printf "adding pci option rom\n"
if [ "${_vga_dir}" != "${pciromsdir}" ]; then [ "${_vga_dir}" = "${pciromsdir}" ] || \
err "inject_blob_dell_e6400vga: invalid pcirom dir: ${_vga_dir}" err "inject_blob_dell_e6400vga: invalid pcirom dir: ${_vga_dir}"
fi [ -f "${_vga_location}" ] || \
if [ ! -f "${_vga_location}" ]; then
err "inject_blob_dell_e6400vga: ${_vga_location} doesn't exist" err "inject_blob_dell_e6400vga: ${_vga_location} doesn't exist"
fi
"${cbfstool}" "${rom}" add -f "${_vga_location}" \ x_ "${cbfstool}" "${rom}" add -f "${_vga_location}" \
-n "pci${CONFIG_VGA_BIOS_ID}.rom" -t optionrom || \ -n "pci${CONFIG_VGA_BIOS_ID}.rom" -t optionrom
err "inject_blob_dell_e6400vga: cannot insert vga oprom"
} }
inject_blob_smsc_sch5545_ec() inject_blob_smsc_sch5545_ec()
{ {
rom="${1}" rom="${1}"
_sch5545ec_location="${CONFIG_SMSC_SCH5545_EC_FW_FILE#../../}" _sch5545ec_location="${CONFIG_SMSC_SCH5545_EC_FW_FILE#../../}"
[ -f "${_sch5545ec_location}" ] || \ [ -f "${_sch5545ec_location}" ] || \
err "inject_blob_smsc_sch5545_ec: SCH5545 fw missing" err "inject_blob_smsc_sch5545_ec: SCH5545 fw missing"
"${cbfstool}" "${rom}" add -f "${_sch5545ec_location}" \ x_ "${cbfstool}" "${rom}" add -f "${_sch5545ec_location}" \
-n sch5545_ecfw.bin -t raw || \ -n sch5545_ecfw.bin -t raw
err "inject_blob_smsc_sch5545_ec: can't insert sch5545_ecfw.bin"
} }
modify_gbe() modify_gbe()
@ -309,21 +292,17 @@ modify_gbe()
rom="${1}" rom="${1}"
_gbe_location=${CONFIG_GBE_BIN_PATH#../../} _gbe_location=${CONFIG_GBE_BIN_PATH#../../}
[ -f "${_gbe_location}" ] || \ [ -f "${_gbe_location}" ] || \
err "modify_gbe: CONFIG_GBE_BIN_PATH points to missing file" err "modify_gbe: CONFIG_GBE_BIN_PATH points to missing file"
[ -f "${nvmutil}" ] || \ [ -f "${nvmutil}" ] || \
make -C util/nvmutil || err "modify_gbe: couldn't build nvmutil" x_ make -C util/nvmutil
_gbe_tmp=$(mktemp -t gbeXXXX.bin) _gbe_tmp=$(mktemp -t gbeXXXX.bin)
cp "${_gbe_location}" "${_gbe_tmp}" x_ cp "${_gbe_location}" "${_gbe_tmp}"
"${nvmutil}" "${_gbe_tmp}" setmac "${new_mac}" || \ x_ "${nvmutil}" "${_gbe_tmp}" setmac "${new_mac}"
err "modify_gbe: ${board}: failed to modify mac address" x_ "${ifdtool}" -i GbE:"${_gbe_tmp}" "${rom}" -O "${rom}"
"${ifdtool}" -i GbE:"${_gbe_tmp}" "${rom}" -O "${rom}" || \ x_ rm -f "${_gbe_tmp}"
err "modify_gbe: ${board}: cannot insert modified gbe.bin"
rm -f "${_gbe_tmp}" || err "modify_gbe: can't remove ${_gbe_tmp}"
} }
usage() usage()

View File

@ -23,11 +23,9 @@ main()
clone_project clone_project
[ "${depend}" = "" ] || for d in ${depend} ; do [ "${depend}" = "" ] || for d in ${depend} ; do
./update project repo ${d} || \ xx_ ./update project repo ${d}
fail "Cannot fetch dependency, ${d}, for project, ${name}"
done done
xx_ rm -Rf "${tmp_dir}"
rm -Rf "${tmp_dir}" || fail "cannot remove tmpdir, ${tmp_dir}"
} }
verify_config() verify_config()
@ -39,8 +37,8 @@ verify_config()
clone_project() clone_project()
{ {
rm -Rf "${tmp_dir}" || fail "clone_project: cannot remove old tmpdir" xx_ rm -Rf "${tmp_dir}"
mkdir -p "${tmp_dir%/*}" || fail "clone_project: can't mkdir" xx_ mkdir -p "${tmp_dir%/*}"
git clone ${url} "${tmp_dir}" || git clone ${bkup_url} "${tmp_dir}" || \ git clone ${url} "${tmp_dir}" || git clone ${bkup_url} "${tmp_dir}" || \
fail "clone_project: could not download ${name}" fail "clone_project: could not download ${name}"
@ -50,12 +48,9 @@ clone_project()
fail "clone_project ${loc}/: cannot apply patches" fail "clone_project ${loc}/: cannot apply patches"
[ ! -d "${loc}" ] || \ [ ! -d "${loc}" ] || \
rm -Rf "${loc}" || \ xx_ rm -Rf "${loc}"
fail "clone_project: Can't remove directory '${loc}'" [ "${loc}" = "${loc%/*}" ] || xx_ mkdir -p ${loc%/*}
[ "${loc}" = "${loc%/*}" ] || mkdir -p ${loc%/*} || \ xx_ mv "${tmp_dir}" "${loc}"
fail "clone_project: cannot make directory for ${name}"
mv "${tmp_dir}" "${loc}" || \
fail "clone_project: could not copy temp file to destination"
} }
fail() fail()

View File

@ -15,7 +15,7 @@ eval "$(setvars "" _target tree rev project cfgsdir)"
main() main()
{ {
rm -f "${cfgsdir}"/*/seen || err_rm_seen "main 1" x_ rm -f "${cfgsdir}"/*/seen
printf "Downloading %s and (if available) applying patches\n" \ printf "Downloading %s and (if available) applying patches\n" \
${project} ${project}
@ -32,11 +32,10 @@ main()
err "No targets available for project: ${project}" err "No targets available for project: ${project}"
for x in ${targets}; do for x in ${targets}; do
rm -f "${cfgsdir}"/*/seen || err_rm_seen "main 2" x_ rm -f "${cfgsdir}"/*/seen
download_for_target "${x}" || \ x_ download_for_target "${x}"
err "${project}/${target}: cannot download source tree"
done done
rm -f "${cfgsdir}"/*/seen || err_rm_seen "main 3" x_ rm -f "${cfgsdir}"/*/seen
} }
download_for_target() download_for_target()
@ -45,10 +44,8 @@ download_for_target()
tree="undefined" tree="undefined"
rev="undefined" rev="undefined"
fetch_config "${_target}" || \ x_ fetch_config "${_target}"
err "download_for_target: ${project}/${_target}: bad target.cfg" x_ rm -f "${cfgsdir}"/*/seen
rm -f "${cfgsdir}"/*/seen || err_rm_seen "download_for_target"
if [ -d "${project}/${tree}" ]; then if [ -d "${project}/${tree}" ]; then
printf "REMARK: download/%s %s: exists. Skipping.\n" \ printf "REMARK: download/%s %s: exists. Skipping.\n" \
@ -60,8 +57,7 @@ download_for_target()
fetch_from_upstream || \ fetch_from_upstream || \
err "download_for_target: cannot fetch: ${project}" err "download_for_target: cannot fetch: ${project}"
prepare_new_tree "${_target}" "${tree}" "${rev}" || \ x_ prepare_new_tree "${_target}" "${tree}" "${rev}"
err "download_for_target: cannot create tree: ${project}/${tree}"
} }
fetch_config() fetch_config()
@ -82,14 +78,16 @@ fetch_config()
_target="${tree}" _target="${tree}"
continue continue
elif [ "${tree}" = "undefined" ]; then elif [ "${tree}" = "undefined" ]; then
printf "ERROR (fetch_config): download/%s:" 1>&2 printf "ERROR (fetch_config): download/%s:" \
"${project}" 1>&2
printf " tree name undefined for '%s\n'" \ printf " tree name undefined for '%s\n'" \
"${project}" "${_target}" 1>&2 "${_target}" 1>&2
return 1 return 1
elif [ "${rev}" = "undefined" ]; then elif [ "${rev}" = "undefined" ]; then
printf "ERROR (fetch_config): download/%s:" 1>&2 printf "ERROR (fetch_config): download/%s:" \
"${project}" 1>&2
printf " commit ID undefined for '%s'\n" \ printf " commit ID undefined for '%s'\n" \
"${project}" "${_target}" 1>&2 "${_target}" 1>&2
return 1 return 1
else else
break break
@ -114,8 +112,7 @@ check_config_for_target()
1>&2 1>&2
return 1 return 1
fi fi
touch "${cfgsdir}/${_target}/seen" || \ x_ touch "${cfgsdir}/${_target}/seen"
err "${project}/${_target}: touch \"${cfgsdir}/${_target}/seen\""
} }
fetch_from_upstream() fetch_from_upstream()
@ -137,26 +134,17 @@ prepare_new_tree()
[ "${tree}" != "${target}" ] && \ [ "${tree}" != "${target}" ] && \
printf "(for target, %s)\n" "${target}" printf "(for target, %s)\n" "${target}"
cp -R "${project}/${project}" "${project}/${tree}" || \ x_ cp -R "${project}/${project}" "${project}/${tree}"
err "${project}/${tree}: cannot copy source tree" x_ git_reset_rev "${project}/${tree}" "${rev}" "err"
git_reset_rev "${project}/${tree}" "${rev}" "err" || \
err "prepare_new_trees ${project}/${tree}: cannot reset <- ${rev}"
( (
cd "${project}/${tree}" || \ x_ cd "${project}/${tree}"
err "prepare_new_tree: !cd \"${project}/${tree}\""
git submodule update --init --checkout || \ git submodule update --init --checkout || \
err "prepare_new_tree ${project}/${tree}: can't update git modules" err "prepare_new_tree ${project}/${tree}: can't update git modules"
) )
git_am_patches "${PWD}/${project}/${tree}" \ x_ git_am_patches "${PWD}/${project}/${tree}" \
"${PWD}/${cfgsdir}/${tree}/patches" "err" || \ "${PWD}/${cfgsdir}/${tree}/patches" "err"
err "prepare_new_trees ${project}/${tree}: cannot apply patches"
}
err_rm_seen()
{
err "${1}: ${project}/${target}: cannot rm: \"${cfgsdir}/*/seen\""
} }
main $@ main $@