The bootflow feature provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation. This is called 'standard boot' since it provides a standard way for U-Boot to boot a distro, without scripting.
It introduces the following concepts: - bootdev - a device which can hold a distro - bootmeth - a method to scan a bootdev to find bootflows (owned by U-Boot) - bootflow - a description of how to boot (owned by the distro) This series provides an implementation of these, enabled to scan for bootflows from MMC, USB and Ethernet. It supports the existing distro boot as well as the EFI loader flow (bootefi/bootmgr). It works similiarly to the existing script-based approach, but is native to U-Boot. With this we can boot on a Raspberry Pi 3 with just one command: bootflow scan -lb which means to scan, listing (-l) each bootflow and trying to boot each one (-b). The final patch shows this. With a standard way to identify boot devices, booting become easier. It also should be possible to support U-Boot scripts, for backwards compatibility only. This series relies on the PXE clean-up series, posted here: https://patchwork.ozlabs.org/project/uboot/list/?series=267078 For documentation, see the 'doc' patch. For version 2, a new naming scheme is used as above: - bootdev is used instead of bootdevice, because 'device' is overused, is everywhere in U-Boot, can be confused with udevice - bootmeth - because 'method' is too vanilla, appears 1300 times in U-Boot Also in version 2, drivers are introduced for the boot methods, to make it more extensible. Booting a custom OS is simply a matter of creating a bootmeth for it and implementing the read_file() and boot() methods. The design is described in these two documents: https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing https://drive.google.com/file/d/1kTrflO9vvGlKp-ZH_jlgb9TY3WYG6FF9/view?usp=sharing Overall size increment on rpi_3_32b is 6.75KB. The series is available at u-boot-dm/bme-working Sample log on rpi_3_32b: U-Boot 2021.10-rc2-00043-gccd453aa918-dirty (Aug 28 2021 - 13:58:46 -0600) DRAM: 992 MiB RPI 3 Model B (0xa22082) MMC: mmc@7e202000: 0, sdhci@7e300000: 1 Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1... In: serial Out: vidconsole Err: vidconsole Net: No ethernet found. starting USB... Bus usb@7e980000: USB DWC2 scanning bus usb@7e980000 for devices... usb_kbd usb_kbd: Timeout poll on interrupt endpoint Failed to get keyboard state from device 0c40:8000 4 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 Scanning for bootflows in all bootmethods Seq Type State Uclass Part Name Filename --- ----------- ------ -------- ---- ------------------------ ---------------- Scanning bootmethod 'mmc@7e202000.bootmethod': 0 efi-loader loaded mmc 1 mmc@7e202000.bootmethod.p efi/boot/bootarm.efi ** Booting bootflow 'mmc@7e202000.bootmethod.part_1' Scanning disk m...@7e202000.blk... ** Unrecognized filesystem type ** Card did not respond to voltage select! : -110 Scanning disk sd...@7e300000.blk... Disk sd...@7e300000.blk not ready Found 4 disks No EFI system partition Booting /efi\boot Waiting for Ethernet connection... done. Fedora (5.11.12-300.fc34.armv7hl) 34 (Workstation Edition) UEFI Firmware Settings Use the ▲ and ▼ keys to change the selection. Press 'e' to edit the selected item, or 'c' for a command prompt. Press Escape to return to the previous menu. The selected entry will be started automatically in 0s. Changes in v3: - Change the function to return a pointer to the first digit - Add some tests, including one for 'abc123def456' - Add new patch to rename uclass_get_by_name_len() - Add new patch to support finding a uclass device by partial name - Mention bootflow_state[] in enum bootflow_state_t - Add CONFIG_BOOTSTD_FULL to enable the full feature set - Support bootdev-order and filename-prefixes only with CONFIG_BOOTSTD_FULL - Update for the new trailing_strtoln_end() - Add bootdev_get_from_blk() function - Use blk_find_device() to find the block device for a media device - Move bootdev ordering into the uclass - Move bootmeth ordering into the uclass - Support "bootmeths" env var - Add some more common functions - Point to the header file for bootflow_state[] docs - Explain why it is OK to use "?" as an unknown bootflow state - Move bootmeth/bootdev ordering into the uclass - Use separate Kconfig options for each command - Use separate Kconfig options for each command - Put some features behind CONFIG_BOOTFLOW_FULL - Move bootmeth ordering into the uclass - Use new bootmeth_try_file() function - Use a short name when BOOTSTD_FULL is not enabled - Use common bootmeth functions - Adjust for new blk_find_device() function - Add a log category - Use a short name when BOOTSTD_FULL is not enabled - Add a log category - Use a short name when BOOTSTD_FULL is not enabled - Align the EFI load address - Use common bootmeth functions - Add a log category - Add a log category - Add a log category - Add support for script boot - Update bootdev_test_order() for boot_targets env var - Add tests for the "bootmeths" env var - Update tests for the new 'bootmeth order' syntax - Update test condition to use CMD_BOOTFLOW - Update docs for "bootmeths" and "boot_targets" env vars Simon Glass (31): str: Move string tests to the string module test: Add tests for trailing_strtol() str: Fix a few bugs in trailing_strtoln() lib: Add a way to find the postiion of a trailing number dm: core: Rename uclass_get_by_name_len() dm: core: Allow finding a uclass device by partial name test: fastboot: Avoid using mmc1 test: dm: Restart USB before assuming it is stopped dm: blk: Add a function to return the device type bootstd: Add the concept of a bootflow bootstd: Add the bootstd uclass and core implementation bootstd: Add the bootdev uclass bootstd: Add the bootmeth uclass and helpers bootstd: Add support for bootflows bootstd: Add a bootdev command bootstd: Add a bootflow command bootstd: Add a bootmeth command bootstd: Add an implementation of distro boot bootstd: mmc: Add a bootdev driver bootstd: ethernet: Add a bootdev driver bootstd: Add an implementation of distro PXE boot bootstd: Add an implementation of EFI boot bootstd: Add a system bootdev for strange boot methods bootstd: Add an implementation of EFI bootmgr bootstd: Add a sandbox bootmeth driver bootstd: Add an implementation of script boot bootstd: usb: Add a bootdev driver bootstd: Add tests for bootstd including all uclasses bootstd: Add setup for the bootflow tests bootstd: doc: Add documentation RFC: Switch rpi over to use bootstd MAINTAINERS | 21 + arch/sandbox/dts/test.dts | 18 + boot/Kconfig | 101 +++- boot/Makefile | 15 + boot/bootdev-uclass.c | 649 ++++++++++++++++++++++++++ boot/bootflow.c | 410 ++++++++++++++++ boot/bootmeth-uclass.c | 298 ++++++++++++ boot/bootmeth_distro.c | 142 ++++++ boot/bootmeth_efi.c | 183 ++++++++ boot/bootmeth_efi_mgr.c | 86 ++++ boot/bootmeth_pxe.c | 186 ++++++++ boot/bootmeth_sandbox.c | 69 +++ boot/bootmeth_script.c | 137 ++++++ boot/bootstd-uclass.c | 183 ++++++++ boot/system_bootdev.c | 66 +++ cmd/Kconfig | 39 ++ cmd/Makefile | 3 + cmd/bootdev.c | 120 +++++ cmd/bootflow.c | 399 ++++++++++++++++ cmd/bootmeth.c | 113 +++++ common/usb_storage.c | 12 + configs/amcore_defconfig | 1 + configs/rcar3_salvator-x_defconfig | 1 + configs/sandbox_defconfig | 3 +- configs/sandbox_flattree_defconfig | 3 +- configs/tbs2910_defconfig | 1 + doc/develop/bootstd.rst | 638 +++++++++++++++++++++++++ doc/develop/distro.rst | 3 + doc/develop/index.rst | 1 + doc/device-tree-bindings/bootdev.txt | 26 ++ doc/device-tree-bindings/bootmeth.txt | 31 ++ doc/device-tree-bindings/bootstd.txt | 36 ++ doc/usage/bootdev.rst | 135 ++++++ doc/usage/bootflow.rst | 427 +++++++++++++++++ doc/usage/bootmeth.rst | 108 +++++ doc/usage/index.rst | 3 + drivers/block/blk-uclass.c | 8 + drivers/core/uclass.c | 20 +- drivers/mmc/Makefile | 5 + drivers/mmc/mmc-uclass.c | 23 + drivers/mmc/mmc_bootdev.c | 62 +++ drivers/usb/host/Makefile | 4 + drivers/usb/host/usb_bootdev.c | 61 +++ include/blk.h | 8 + include/bootdev.h | 275 +++++++++++ include/bootflow.h | 306 ++++++++++++ include/bootmeth.h | 234 ++++++++++ include/bootstd.h | 80 ++++ include/configs/rpi.h | 39 +- include/distro.h | 24 + include/dm/device.h | 2 +- include/dm/uclass-id.h | 3 + include/dm/uclass-internal.h | 16 + include/dm/uclass.h | 8 +- include/env_callback.h | 7 + include/mmc.h | 12 +- include/test/suites.h | 2 + include/vsprintf.h | 22 +- lib/strto.c | 23 +- net/Kconfig | 9 + net/Makefile | 1 + net/eth-uclass.c | 8 + net/eth_bootdev.c | 101 ++++ test/Makefile | 1 + test/boot/Makefile | 5 + test/boot/bootdev.c | 223 +++++++++ test/boot/bootflow.c | 398 ++++++++++++++++ test/boot/bootmeth.c | 122 +++++ test/boot/bootstd_common.c | 35 ++ test/boot/bootstd_common.h | 27 ++ test/cmd_ut.c | 7 + test/dm/blk.c | 6 + test/dm/fastboot.c | 4 +- test/print_ut.c | 40 -- test/py/tests/bootstd/mmc1.img.xz | Bin 0 -> 4448 bytes test/py/tests/test_ut.py | 103 ++++ test/str_ut.c | 72 +++ 77 files changed, 6971 insertions(+), 102 deletions(-) create mode 100644 boot/bootdev-uclass.c create mode 100644 boot/bootflow.c create mode 100644 boot/bootmeth-uclass.c create mode 100644 boot/bootmeth_distro.c create mode 100644 boot/bootmeth_efi.c create mode 100644 boot/bootmeth_efi_mgr.c create mode 100644 boot/bootmeth_pxe.c create mode 100644 boot/bootmeth_sandbox.c create mode 100644 boot/bootmeth_script.c create mode 100644 boot/bootstd-uclass.c create mode 100644 boot/system_bootdev.c create mode 100644 cmd/bootdev.c create mode 100644 cmd/bootflow.c create mode 100644 cmd/bootmeth.c create mode 100644 doc/develop/bootstd.rst create mode 100644 doc/device-tree-bindings/bootdev.txt create mode 100644 doc/device-tree-bindings/bootmeth.txt create mode 100644 doc/device-tree-bindings/bootstd.txt create mode 100644 doc/usage/bootdev.rst create mode 100644 doc/usage/bootflow.rst create mode 100644 doc/usage/bootmeth.rst create mode 100644 drivers/mmc/mmc_bootdev.c create mode 100644 drivers/usb/host/usb_bootdev.c create mode 100644 include/bootdev.h create mode 100644 include/bootflow.h create mode 100644 include/bootmeth.h create mode 100644 include/bootstd.h create mode 100644 include/distro.h create mode 100644 net/eth_bootdev.c create mode 100644 test/boot/Makefile create mode 100644 test/boot/bootdev.c create mode 100644 test/boot/bootflow.c create mode 100644 test/boot/bootmeth.c create mode 100644 test/boot/bootstd_common.c create mode 100644 test/boot/bootstd_common.h create mode 100644 test/py/tests/bootstd/mmc1.img.xz -- 2.34.1.703.g22d0c6ccf7-goog