Canoeboot Build System Audit 2

Leah Rowe

19 July 2024


Return to index

Article published by: Leah Rowe

Date of publication: 19 July 2024

Heavy amount of code reduction in this audit, and general cleanup. A new Canoeboot release is planned, for the early days of August 2024.

Introduction

Canoeboot is a free/opensource boot firmware project. It replaces your proprietary BIOS/UEFI firmware, on supported x86 and ARM computers. It does this by providing an automated build system to download, patch and compile the various upstream sources (e.g. coreboot, GRUB, SeaBIOS). Coreboot is used for hardware initialisation, configuring everything from your CPU, memory controller all way to peripherals, readying the hardware so that it can run software, e.g. GNU+Linux and BSD systems. You can essentially think of cbmk, which is Canoeboot’s build system, as a source-based package manager. It is what the Canoeboot releases are built with. The cbmk build system essentially implements a coreboot distro, the same way you might think of a GNU+Linux distribution; it systematically downloads, resets (to specific revisions) and patches various upstream project sources such as coreboot, U-Boot and GRUB, automatically building entire coreboot images. This build system is what creates Canoeboot release images and source tarballs.

Extensive auditing has been performed on cbmk, since the Canoeboot 20240612 release. These audits fix bugs, reduce code bloat and generally improve the efficiency of cbmk, adding and removing features in a careful, conservative way, with a focus on clean code.

Remember the magic words: code equals bugs. Fewer lines of code will yield fewer bugs.

This article covers changes from Canoeboot 20240612, up to revision 16f9ad55ca2ef7d19d10e78b0ff9e1c84bfc4fc1 from 19 July 2024.

You can read about the previous audit in the article for Canoeboot Build System Audit 1.

Notable code size reduction

There are 765 lines of shell script in the build system, versus 1054 in the Canoeboot 20240612 release. Canoeboot’s build system is written entirely in POSIX sh; not BASH, not KSH, not ZSH, jush sh! It is the build system of build systems; the design focuses on re-using (read: abusing) the build systems of the projects it uses, avoiding as much bloat as possible. More information is available in the cbmk build system documentation.

This is a difference of 289 lines, or a 28% reduction. The main focus has been on removing legacy bloat from the build system, vastly increasing the overall code cleanliness and efficiency. Several new safety and redundancy features were added, such as auto-rebuild when configs change(and auto-redownload) for sources, and additional redundant handling of both repositories and file downloads, cached during operation to avoid over-use of internet bandwidth.

Plan for next release

This code reduction has been the main focus; the focus now, at the next release, will be new payloads and boards, in addition to testing newer upstream revisions of projects such as coreboot, on every machine supported by Canoeboot. A release is planned for early August 2024.

A lot of work on new ports is planned. There are a number of new mainboards that will be available, in the next Canoeboot release.

Summarised list of changes

The most interesting changes are marked in bold. “Interesting” means that the change greatly improves the usefulness/reliability of Canoeboot, or that it affects the user in a profound and noticeable way.

Changes are in order per category, from newest to oldest:

Feature changes

Some unused features have been removed, and yet more added. The overall focus of Audit 2 has been to remove legacy cruft from cbmk, and in general to simplify the operation of cbmk, Canoeboot’s build system. Several new safety features were implementated for this audit, in addition to features that generally improve the redundancy of certain operations, and overall reliability in cbmk.

The changes are as follows:

Configuration changes

This pertains to anything under config/, for any changes that are of note, but it does not pertain to revisions for specific projects, nor does it cover specific patches applied to projects; the latter will be covered in other sections of this audit announcement.

The changes are as follows:

Bug fixes

There are fewer acute bug fixes in Audit 2, because bugfixes was the primary focus of Audit 1. The word acute is used, referring to triggered bugs, because many of these changes are pre-emptive bug fixes, preventing future bugs that have been foreseen, based on future modification to existing logic. The focus of Audit 2 has been general code reduction, feature simplification and improvements to safety features / error handling (many pre-emptive bugfixes implement newer safety features, but are listed as pre-emptive fixes, not features).

The changes are as follows:

General code cleanup

Extensive code cleanup has been performed, as was the main purpose of Audit 2.

The changes are as follows:

Revision updates

U-Boot

Alper Nebi Yasak is the maintainer of U-Boot, within Libreboot, and a Libreboot patch of his updated U-Boot to v2024.07, on the gru_bob and gru_kevin Chromebooks. Several improvements have been merged upstream, like Alper’s patches for Qemu, so these patches have been dropped in cbmk because they’re now included by default, in the new U-Boot revision. This patch has been imported into Canoeboot, from the Libreboot project.

Alper also tested the latest coreboot revision and it worked fine, on these boards, but revision updates will be done immediately after Audit 2 is announced, as a priority for further work that is to be completed for the next Canoeboot release, ETA August 2024.

Git log

This git log covers all changes in this audit, relative to Canoeboot 20240612.

* 16f9ad55ca put cachedir in environmental variable 
* 6b2653f8cd git.sh: warn when a cached clone fails 
* 1458e1108e git.sh: fix typo in git command 
* 20b076714c git.sh: fix lack of error exits on fault 
* a7f9a7bb6f build: remove tmp/ on release archives 
* 71091e03a7 trees: hardcode makeargs for xgcc 
* 1bc484dbf6 allow using coreboot's build system to add payload 
* 93a476b4fc trees: remove unnecessary command 
* ae3966a02f build: remove cache/ on making releases 
* 0cf0fdcfc3 unify caching of files into cache/ 
* 8bb3730e7b cache downloaded files(module) to cache/file/HASH 
* 0d55d7b23a git.sh: remove previous tmprepo if args>5 
* 3e2e5ecf5a git.sh: try direct clone if cached git fails 
* 03c9670fef git.sh: re-try git pull three times 
* 055c9be15b trees: auto-delete+auto-rebuild if project changes 
* 2d794a8385 trees: also remove single-tree repo/p/ 
* b564f5b848 trees: remove repo/p, not src/p/p 
* c44ff5ac47 git.sh: don't download to src/project/project/ 
* 3590a53ed1 git.sh: cache git downloads to repo/ 
* 2823ccc438 remove util/autoport 
* a29453023c trees: move dependency building to new function 
* a9997082d7 u-boot: Fix display initialization on gru boards 
* 5b170de055 u-boot: Avoid breaking build for U-Boot-only binman images 
* d442d61f84 u-boot: Update to v2024.07 
* 215764cfbd trees: fix bad comparison in configure_project() 
* 60d491e2bd trees: don't continue if no argument given 
* 3365fca06a trees: general code cleanup 
* a721e927b0 trees: merge build_targets() with handle_targets() 
* 1a95c0cf30 trees: use wrapper for dry-running make commands 
* a258eb231a trees: remove project-specific hacks 
* 3681c29e77 remove executable permission on include/ 
* 378c09a25c rom.sh: actually say if a cbutil exists 
* 87681db12c rom.sh: avoid re-building cbutils if built 
* fdf7864905 rom.sh: only before cbutils before coreboot 
* 21306dd5b8 trees: fix bad comparison 
* 9a3beea79c minor cleanup 
* 4dbce8aef0 trees: support -d (dry run) for custom build logic 
* 2dad7b0b6f rom.sh: only make rom tarball if release=y 
* e01995d491 rom.sh: new file, to replace script/roms 
* a50c789b1d roms: remove unnecessary trees checks 
* e5262da7ca coreboot: set build_depend on target.cfg files 
* a8a42ebb0b trees: rename load_target_config() 
* 07769f3341 trees: support build dependencies, not just fetch 
* 1b75d738bf GRUB: only load xhci from grub.cfg 
* bfeab80a8d trees: just do makeargs on coreboot, not cbmakearg 
* 05b59f39d6 trees: fix bad rm -Rf command (-Rf, not Rf) 
* 5d179fe3e0 roms: fix bad comparison in configure_target() 
* 1fe126501a GRUB: use mkhelper.cfg for common variables 
* c76e6b0527 trees: allow global config on multi-tree projects 
* bdf43e07cf trees: handle all projects if project undefined 
* ff00073666 git.sh: simpler for loop in git_am_patches() 
* de26bb9997 git.sh: merge for loops in git_am_patches() 
* cc090de51e trees and git.sh: tidy up global variables 
* 5b24c812a0 git.sh: simplified initialisation of "loc" 
* a62ad20730 trees: simplified distclean directory check 
* 63ae4ad746 git.sh: condense fetch_targets() a bit 
* 7aad37199c git.sh: short git_prep command in fetch_targets() 
* 4a152d53c3 trees: only do bare multi-tree clone on git 
* be4c655008 trees: simplified multi-tree bare repo clone 
* 51fe371931 git.sh: merge prepare_new_tree with fetch_targets 
* ca77d3a3d7 trees run_make_command: simpler distclean handling 
* aad9c8d0de trees: condense copy_elf() a bit 
* fdd67e5935 trees: add return to handle_defconfig() 
* be01e56609 trees: rename check_config to check_defconfig 
* 2740db84b7 trees: remove variable "config_name" 
* c77c09bac2 trees: rename variable "config" to defconfig 
* 675b24e83d git.sh: remove duplicate "xtree" variable 
* e332937241 trees: remove unnecessary commonts 
* 516b399eb1 trees: condense run_make_command() a bit 
* 0ab9afc7af trees: condense handle_makefile() a bit 
* 605b099e04 trees: mv load_project_config load_target_config 
* ef3ff3dfe4 trees, multi: download bare project *before* trees 
* e377404406 trees: unified multi-tree configuration handling 
* 211f4f0b82 trees: unified handling of source downloads 
* 0f7a5c27dc git.sh: rename Fetch_project_trees fetch_targets 
* 626fd9f245 git.sh: rename fetch_project_repo to fetch_project 
* 6a91dc02dc trees: better skip-clean string in handle_src_tree 
* de8dc508f9 trees: add return to check_coreboot_utils() 
* cc61bd1239 trees: simplify "utilmode" variable initialisation 
* cbe40044b4 trees mkpayload_grub: remove unnecessary check 
* 7322a2b53d lib.sh: stricter check in chkvars() 
* 203fdb8007 tidy up some setvars lists 
* d3ccb4d8a7 roms: explicitly shift by 1 on the "all" target 
* bd8f0e0bbb roms: add return value for the list command 
* 5907022703 roms: build u-boot *before* checking ubootelf 
* 57b68302c7 remove more unnecessary checks on trees commands 
* 0dcd8852dd lib.sh: keep versiondate check to 80 characters 
* 2ebdd184b7 lib.sh: condense for loop 
* 5dc30167de lib.sh: condense err_() a bit 
* a9882cfa00 lib.sh: add a return to the end of chkvars() 
* 511423a85a lib.sh: remove unused variable "boarddir" 
* 1fbfc7303d remove use of _xm variable in the build system 
* 7451fa629c trees: don't hardcode use of mkpayload_grub 
* 623ad90ef0 trees: simplify single/multi handling in main() 
* 7b178f5fad trees: rename build_projects to build_project 
* 7ee147ed49 trees: err if target.cfg not given if multi-tree 
* f8d1abf18d trees: set btype if target.cfg doesn't exist 
* 2827917b0a lib.sh: remove unused cbdir variable 
* dd28339f38 roms: remove unnecessary assignment to cbdir 
* cf4f828dbe trees: avoid kconfig make commands generically 
* ce9b2f0a1c git.sh: remove unnecessary check 
* f3baebe7e1 lib.sh: move git_err() to build 
* 43238fa0c5 lib.sh: condense singletree() a bit 
* de331e5da0 lib.sh: add a return to the end of check_defconfig 
* 94d9d313cc trees: condense elfcheck() a bit 
* 35c516c2f4 lib.sh: condense e() a bit 
* 2ac6db2b91 trees: shorten the final confirmation message 
* 9ba28a0b86 lib.sh: make elf/coreboot* a dot directory 
* 32e1b13416 build: don't rm TMPDIR if it's /tmp 
* 6daea94df8 lib.sh: simplified TMPDIR handling 
* 0c0b8124c1 lib.sh: condense setcfg() if/else logic 
* 0a2ed1a7bd trees: remove redundant space in printf 
* e3179f435e trees: explicitly err if OPTARG is not set 
* 8dcfb8a585 trees: only permit one single-tree project 
* c56531af40 trees: call err if multiple flags are provided 
* ebebb5a57e trees: explicitly set mode for -b 
* 0662b22297 roms: re-add compression of coreboot images 
* e8b7e74db5 roms: build coreboot *after* checking variables 
* aac8720382 lib.sh: introduce mandatory check of projectname 
* ae28debf21 lib.sh: condense setvars() a bit 
* 8c06c62e06 simplified lock message 
* 2965d526fd lib.sh: simplify reading of version files 
* 3319147306 lib.sh: simplify use of environment variables 
* aa89f69b34 roms main(): confirm what serprog images are built 
* ba228ac228 roms: remove unused variable name 
* e48183a52e roms: remove redundant printf 
* e73f1b1c9b roms: optimise u-boot elf check 
* 14c3a328f1 roms: simplify build_roms() 
* 0355a80408 roms: make the bin/elf message more polite 
* 537efc148d roms: re-add final confirmation of targets 
* 01986beda3 roms: rename functions for extra clarity 
* d0a949d00b roms: build coreboot early to avoid duplicate work 
* df66dbd72d trees: try xgcc build twice if first attempt fails 
* bd59d01ea2 trees: don't check if xgcc is already built 
* fc408f5554 lib.sh: fix error running ./build dependencies 
* 8a02aef1d8 remove unused git modules 
* b72dfe11f9 roms: general code cleanup 
* 852eb1db4f roms: only support SeaBIOS/SeaGRUB on x86 
* 107072b189 roms: remove support for "grubonly" seabios 
* ad1d0cb58c use backticks on eval commands, not subshells 
* e7fcfac14e lib.sh: remove badcmd() 
* dec9ae9b43 lib.sh: more unified config handling 
* c72904b6d1 trees: more robust check to avoid "make fetch" 
* a59ebb1b7c roms: fix lack of backslash on multi-line command 
* 253015f6a9 Revert "roms: remove build_payloads() and split it up" 
* 448d02babb git.sh: revert modification to for loop 
* 381ed442d9 minor code cleanup in the build system 
* 295471644a git.sh: general code cleanup in fetch_submodule() 
* 3ba876932d git.sh: reduced indentation on repo/file check 
* 109db65932 git.sh: simplified repo/backup check 
* acbefc558e roms: merge mkserprog() into main() 
* c2ca92a169 roms: don't insert timeout.cfg 
* 98fc84b0ed correction 
* 3ef9925b56 roms: reduce indentation in build_grub_roms() 
* faddd02ef5 roms: re-introduce accidentally disabled check 
* 14a05f72fb roms: remove build_payloads() and split it up 
* da3d7c7101 roms: group some commands that are similar 
* 99a13a32d9 roms: remove mt86bin variable 
* 3097a9e97a roms: merge build_uboot_payload to build_payloads 
* ccb330ec09 roms: simplify payload_uboot y/n check 
* 49c41411bd roms: simplify the check for serprog srcdir 
* 8136b640b9 roms: simplify the loop for building serprog roms 
* 6976a4edb2 roms: shorten variable serprog_boards_dir 
* 4a3ab3ad1c roms: simplified serprog image copy 
* 64ce81d2b6 roms: rename picosrc variable to rp2040src 
* e3471b22e7 roms: remove useless confirmation in mkserprogfw 
* a8fb99a750 roms: merge serprog build into one function 
* b1ec5ad719 roms: remind the user about gkb files 
* a93f519799 roms: rename x variable to it in for loop 
* faff6f0348 roms: don't use x_ to call cproms() 
* f43525d14f roms build_uboot_roms(): move rom, don't copy 
* dd2854b3e8 roms cproms(): allow other commands besides cp 
* a8f44ab80a unify coreboot elfdir (DO_NOT_FLASH) 
* be04f59602 roms: merge mkUbootRom() into build_uboot_roms() 
* a9819d7385 roms: simplify mkSeabiosRom() 
* 19baf8d1a7 roms: simplify mkUbootRom() 
* 935958e6a4 roms: simplify build_roms() 
* acd5d16961 roms: remove unnecessary check 
* 6094542663 build: remove unused variables 
* 94b9bd44e4 roms: further clean up build_grub_roms() 
* 167f81a993 roms: simplify timeout/scandisk insertion 
* d958b16369 roms: simplify seagrub check in build_grub_roms 
* 726b56b2f1 roms: simplify mkserprog() 
* dd59f2daba roms: simplify the serprog build functions 
* 9897bc748d script/roms: fix serprog build commands 
* 3269e0c097 roms: simplified ubootelf check 
* 7265b9f112 roms: simplify grubonly check in configure_target 
* c29b3ec3fc roms: simplify seagrub check in configure_target 
* f07aa84d49 roms: don't use x_ to call build_grub_roms 
* ed921d7890 trees: simplify copy_elf() 
* 293777fb99 trees: remove unnecessary check in copy_elf 
* b50a588cba grub: insert background in memdisk instead 
* 7f5adffc02 roms: unify all add-payload commands 
* 82c6a352df roms: don't add grub keymaps at all 
* f1aea87141 roms: merge handle_coreboot_target into main() 
* ae9dce889b roms: simplify target check (whether roms built) 
* bb4f0995d1 roms: simplify main() again 
* 59392ea0bb roms: remove redundant check on grub_scan_disk 
* e96d85dc76 roms: remove dangerous runtime p/s/d options 
* bb7b04cb59 unified checks for variable initialisation 
* 1399f2137f lib.sh: remove the items() function 
* 4ed6e41221 roms: simplify main() 

This is 202 changes in total, between 12 June 2024 and 19 July 2024.

Markdown file for this page: https://canoeboot.org/news/audit2.md

Subscribe to RSS for this site

Site map

This HTML page was generated by the Untitled Static Site Generator.