[PATCH v5 00/34] Initial implementation of standard boot

Simon Glass sjg at chromium.org
Mon Apr 25 07:30:53 CEST 2022


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.

Version 4 makes some minor improvements and leaves out the RFC patch for
rpi conversion, in the hope of getting the base support applied sooner
rather than later.

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 at 7e202000: 0, sdhci at 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 at 7e980000: USB DWC2
scanning bus usb at 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 at 7e202000.bootmethod':
  0  efi-loader   loaded  mmc          1  mmc at 7e202000.bootmethod.p efi/boot/bootarm.efi
** Booting bootflow 'mmc at 7e202000.bootmethod.part_1'
Scanning disk mmc at 7e202000.blk...
** Unrecognized filesystem type **
Card did not respond to voltage select! : -110
Scanning disk sdhci at 7e300000.blk...
Disk sdhci at 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 v5:
- Add a Kconfig to select bootstd by default
- Disable bootstd for EFI app builds, since they use dm_scan_other()
- Rebase to master

Changes in v4:
- Add a new fs_type field for use with sandbox
- Add a test also
- Add new patch to correct comment formatting to avoid sphinx errors
- Add new patch with a function to set the filesystem type
- Allow use without a block device
- Correct bug in this function and add test
- Correct the commit tag
- Fix 'a' typo
- Improve debugging in efiload_read_file()
- Make CMD_BOOTSTD_FULL depend on BOOTSTD_FULL
- NULL-terminate the default prefix list
- Reword the commit message
- Show the bootmeth name when booting
- Split out the file setup into into its own function
- Update docs for typos that have been fixed
- Update tests for code changes
- Update the function comment to clarify its intert / limitations
- Use new Return style in function comments
- Use new sphynx Return style
- Warn when trying to use the full bootflow command but it is not enabled

Changes in v3:
- Add CONFIG_BOOTSTD_FULL to enable the full feature set
- Add a log category
- Add bootdev_get_from_blk() function
- Add new patch to rename uclass_get_by_name_len()
- Add new patch to support finding a uclass device by partial name
- Add some more common functions
- Add some tests, including one for 'abc123def456'
- Add support for script boot
- Add tests for the "bootmeths" env var
- Adjust for new blk_find_device() function
- Align the EFI load address
- Change the function to return a pointer to the first digit
- Explain why it is OK to use "?" as an unknown bootflow state
- Mention bootflow_state[] in enum bootflow_state_t
- Move bootdev ordering into the uclass
- Move bootmeth ordering into the uclass
- Move bootmeth/bootdev ordering into the uclass
- Point to the header file for bootflow_state[] docs
- Put some features behind CONFIG_BOOTFLOW_FULL
- Support "bootmeths" env var
- Support bootdev-order and filename-prefixes only with CONFIG_BOOTSTD_FULL
- Update bootdev_test_order() for boot_targets env var
- Update docs for "bootmeths" and "boot_targets" env vars
- Update for the new trailing_strtoln_end()
- Update test condition to use CMD_BOOTFLOW
- Update tests for the new 'bootmeth order' syntax
- Use a short name when BOOTSTD_FULL is not enabled
- Use blk_find_device() to find the block device for a media device
- Use common bootmeth functions
- Use new bootmeth_try_file() function
- Use separate Kconfig options for each command

Simon Glass (34):
  lib: Move string tests to the string module
  test: Add tests for trailing_strtol()
  lib: Correct comment formatting to avoid sphinx problems
  lib: Fix a few bugs in trailing_strtoln()
  lib: Add a way to find the postiion of a trailing number
  dm: core: Rename and fix 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
  fs: Add a function to set the filesystem 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: sandbox: Add a hostfs bootdev
  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
  bootstd: Provide a default command

 MAINTAINERS                           |  21 +
 arch/sandbox/dts/sandbox.dts          |   4 +
 arch/sandbox/dts/sandbox.dtsi         |   5 +
 arch/sandbox/dts/test.dts             |  18 +
 boot/Kconfig                          | 115 ++++-
 boot/Makefile                         |  15 +
 boot/bootdev-uclass.c                 | 649 ++++++++++++++++++++++++++
 boot/bootflow.c                       | 411 ++++++++++++++++
 boot/bootmeth-uclass.c                | 333 +++++++++++++
 boot/bootmeth_distro.c                | 143 ++++++
 boot/bootmeth_efi.c                   | 188 ++++++++
 boot/bootmeth_efi_mgr.c               |  86 ++++
 boot/bootmeth_pxe.c                   | 186 ++++++++
 boot/bootmeth_sandbox.c               |  69 +++
 boot/bootmeth_script.c                | 139 ++++++
 boot/bootstd-uclass.c                 | 183 ++++++++
 boot/system_bootdev.c                 |  66 +++
 cmd/Kconfig                           |  39 ++
 cmd/Makefile                          |   3 +
 cmd/bootdev.c                         | 120 +++++
 cmd/bootflow.c                        | 404 ++++++++++++++++
 cmd/bootmeth.c                        | 113 +++++
 common/usb_storage.c                  |  11 +
 configs/efi-x86_app32_defconfig       |   1 +
 configs/efi-x86_app64_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/cmd/bootdev.rst             | 135 ++++++
 doc/usage/cmd/bootflow.rst            | 427 +++++++++++++++++
 doc/usage/cmd/bootmeth.rst            | 108 +++++
 doc/usage/index.rst                   |   3 +
 drivers/block/blk-uclass.c            |   7 +
 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 +++
 fs/Kconfig                            |   2 +
 fs/fs.c                               |   5 +
 fs/sandbox/Kconfig                    |   2 +
 fs/sandbox/Makefile                   |   1 +
 fs/sandbox/host_bootdev.c             |  56 +++
 include/blk.h                         |   8 +
 include/bootdev.h                     | 275 +++++++++++
 include/bootflow.h                    | 310 ++++++++++++
 include/bootmeth.h                    | 234 ++++++++++
 include/bootstd.h                     |  80 ++++
 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                   |   6 +-
 include/env_callback.h                |   7 +
 include/fs.h                          |  11 +
 include/mmc.h                         |  12 +-
 include/test/suites.h                 |   2 +
 include/vsprintf.h                    | 117 +++--
 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                  | 400 ++++++++++++++++
 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/core.c                        |  17 +
 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 +++
 86 files changed, 7188 insertions(+), 110 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/cmd/bootdev.rst
 create mode 100644 doc/usage/cmd/bootflow.rst
 create mode 100644 doc/usage/cmd/bootmeth.rst
 create mode 100644 drivers/mmc/mmc_bootdev.c
 create mode 100644 drivers/usb/host/usb_bootdev.c
 create mode 100644 fs/sandbox/Kconfig
 create mode 100644 fs/sandbox/host_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.36.0.rc2.479.g8af0fa9b8e-goog



More information about the U-Boot mailing list