Skip to contentSkip to conversation

Initial implementation of standard boot

PATCH In review Simon Glass 4 participants 36 messages Apr 25, 2022 – May 9, 2022

Subsystems (7)
Networking VFS USB Block layer +3 more subsystems
lore
Share & tools
lore
#0 lore raw

v5 cover Initial implementation of standard boot

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@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 '[email protected]':
0 efi-loader loaded mmc 1 [email protected] efi/boot/bootarm.efi
** Booting bootflow '[email protected]_1' Scanning disk [email protected]...
** Unrecognized filesystem type **
Card did not respond to voltage select! : -110 Scanning disk [email protected]...
Disk [email protected] 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
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#1 lore raw

PATCH v5 1/34 lib: Move string tests to the string module

A few string tests were added to the print module by mistake. Move them.

---

(no changes since v4)

Changes in v4:
- Correct the commit tag

 test/print_ut.c | 40 ----------------------------------------
 test/str_ut.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 40 deletions(-)
test/print_ut.c +0 -40
index 247011f2db0..47a6ce57840 100644
@@ -345,26 +345,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
 }
 PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC);
 
-static int print_itoa(struct unit_test_state *uts)
-{
-	ut_asserteq_str("123", simple_itoa(123));
-	ut_asserteq_str("0", simple_itoa(0));
-	ut_asserteq_str("2147483647", simple_itoa(0x7fffffff));
-	ut_asserteq_str("4294967295", simple_itoa(0xffffffff));
-
-	/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
-	if (sizeof(ulong) == 8) {
-		ut_asserteq_str("9223372036854775807",
-				simple_itoa((1UL << 63) - 1));
-		ut_asserteq_str("18446744073709551615", simple_itoa(-1));
-	}
-#endif /* CONFIG_PHYS_64BIT */
-
-	return 0;
-}
-PRINT_TEST(print_itoa, 0);
-
 static int snprint(struct unit_test_state *uts)
 {
 	char buf[10] = "xxxxxxxxx";
@@ -391,26 +371,6 @@ static int snprint(struct unit_test_state *uts)
 }
 PRINT_TEST(snprint, 0);
 
-static int print_xtoa(struct unit_test_state *uts)
-{
-	ut_asserteq_str("7f", simple_xtoa(127));
-	ut_asserteq_str("00", simple_xtoa(0));
-	ut_asserteq_str("7fffffff", simple_xtoa(0x7fffffff));
-	ut_asserteq_str("ffffffff", simple_xtoa(0xffffffff));
-
-	/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
-	if (sizeof(ulong) == 8) {
-		ut_asserteq_str("7fffffffffffffff",
-				simple_xtoa((1UL << 63) - 1));
-		ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1));
-	}
-#endif /* CONFIG_PHYS_64BIT */
-
-	return 0;
-}
-PRINT_TEST(print_xtoa, 0);
-
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
test/str_ut.c +40 -0
index d2840d51524..6c817f6f72f 100644
@@ -202,6 +202,46 @@ static int str_dectoul(struct unit_test_state *uts)
 }
 STR_TEST(str_dectoul, 0);
 
+static int str_itoa(struct unit_test_state *uts)
+{
+	ut_asserteq_str("123", simple_itoa(123));
+	ut_asserteq_str("0", simple_itoa(0));
+	ut_asserteq_str("2147483647", simple_itoa(0x7fffffff));
+	ut_asserteq_str("4294967295", simple_itoa(0xffffffff));
+
+	/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
+#ifdef CONFIG_PHYS_64BIT
+	if (sizeof(ulong) == 8) {
+		ut_asserteq_str("9223372036854775807",
+				simple_itoa((1UL << 63) - 1));
+		ut_asserteq_str("18446744073709551615", simple_itoa(-1));
+	}
+#endif /* CONFIG_PHYS_64BIT */
+
+	return 0;
+}
+STR_TEST(str_itoa, 0);
+
+static int str_xtoa(struct unit_test_state *uts)
+{
+	ut_asserteq_str("7f", simple_xtoa(127));
+	ut_asserteq_str("00", simple_xtoa(0));
+	ut_asserteq_str("7fffffff", simple_xtoa(0x7fffffff));
+	ut_asserteq_str("ffffffff", simple_xtoa(0xffffffff));
+
+	/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
+#ifdef CONFIG_PHYS_64BIT
+	if (sizeof(ulong) == 8) {
+		ut_asserteq_str("7fffffffffffffff",
+				simple_xtoa((1UL << 63) - 1));
+		ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1));
+	}
+#endif /* CONFIG_PHYS_64BIT */
+
+	return 0;
+}
+STR_TEST(str_xtoa, 0);
+
 int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(str_test);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#2 lore raw

PATCH v5 2/34 test: Add tests for trailing_strtol()

In reply to Simon Glass

This function currently has no tests. Add some.

---

(no changes since v4)

Changes in v4:
- Use new Return style in function comments

 include/vsprintf.h |  4 ++--
 test/str_ut.c      | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
include/vsprintf.h +2 -2
index 532ef3650bd..3d1f968df44 100644
@@ -99,7 +99,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base);
  * For example, "abc123" would return 123.
  *
  * @str:	String to exxamine
- * Return: training number if found, else -1
+ * Return: trailing number if found, else -1
  */
 long trailing_strtol(const char *str);
 
@@ -114,7 +114,7 @@ long trailing_strtol(const char *str);
  * @str:	String to exxamine
  * @end:	Pointer to end of string to examine, or NULL to use the
  *		whole string
- * Return: training number if found, else -1
+ * Return: trailing number if found, else -1
  */
 long trailing_strtoln(const char *str, const char *end);
 
test/str_ut.c +19 -0
index 6c817f6f72f..9674a59f2a6 100644
@@ -242,6 +242,25 @@ static int str_xtoa(struct unit_test_state *uts)
 }
 STR_TEST(str_xtoa, 0);
 
+static int str_trailing(struct unit_test_state *uts)
+{
+	char str1[] = "abc123def";
+
+	ut_asserteq(-1, trailing_strtol(""));
+	ut_asserteq(-1, trailing_strtol("123"));
+	ut_asserteq(123, trailing_strtol("abc123"));
+	ut_asserteq(4, trailing_strtol("12c4"));
+	ut_asserteq(-1, trailing_strtol("abd"));
+	ut_asserteq(-1, trailing_strtol("abc123def"));
+
+	ut_asserteq(-1, trailing_strtoln(str1, NULL));
+	ut_asserteq(123, trailing_strtoln(str1, str1 + 6));
+	ut_asserteq(-1, trailing_strtoln(str1, str1 + 9));
+
+	return 0;
+}
+STR_TEST(str_trailing, 0);
+
 int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct unit_test *tests = UNIT_TEST_SUITE_START(str_test);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#3 lore raw

PATCH v5 3/34 lib: Correct comment formatting to avoid sphinx problems

In reply to Simon Glass

Tweak a few comments to kep sphinx happy, in case we want to include this file one day.

Also fix the 'exxamine' typo.

Patch-notes:
This uses:

sed -i 's/@param \(\S*\)\s*/@\1: /' include/vsprintf.h

to convert the @param to the new format.

---

(no changes since v4)

Changes in v4:
- Add new patch to correct comment formatting to avoid sphinx errors
- Correct the commit tag

 include/vsprintf.h | 92 +++++++++++++++++++++++-----------------------
 1 file changed, 46 insertions(+), 46 deletions(-)
include/vsprintf.h +46 -46
index 3d1f968df44..d4bf3211da4 100644
@@ -13,9 +13,9 @@
 /**
  * simple_strtoul - convert a string to an unsigned long
  *
- * @param cp	The string to be converted
- * @param endp	Updated to point to the first character not converted
- * @param base	The number base to use (0 for the default)
+ * @cp: The string to be converted
+ * @endp: Updated to point to the first character not converted
+ * @base: The number base to use (0 for the default)
  * Return: value decoded from string (0 if invalid)
  *
  * Converts a string to an unsigned long. If there are invalid characters at
@@ -34,8 +34,8 @@ ulong simple_strtoul(const char *cp, char **endp, unsigned int base);
 /**
  * hex_strtoul - convert a string in hex to an unsigned long
  *
- * @param cp	The string to be converted
- * @param endp	Updated to point to the first character not converted
+ * @cp: The string to be converted
+ * @endp: Updated to point to the first character not converted
  * Return: value decoded from string (0 if invalid)
  *
  * Converts a hex string to an unsigned long. If there are invalid characters at
@@ -47,8 +47,8 @@ unsigned long hextoul(const char *cp, char **endp);
 /**
  * dec_strtoul - convert a string in decimal to an unsigned long
  *
- * @param cp	The string to be converted
- * @param endp	Updated to point to the first character not converted
+ * @cp: The string to be converted
+ * @endp: Updated to point to the first character not converted
  * Return: value decoded from string (0 if invalid)
  *
  * Converts a decimal string to an unsigned long. If there are invalid
@@ -59,11 +59,11 @@ unsigned long dectoul(const char *cp, char **endp);
 
 /**
  * strict_strtoul - convert a string to an unsigned long strictly
- * @param cp	The string to be converted
- * @param base	The number base to use (0 for the default)
- * @param res	The converted result value
- * Return: 0 if conversion is successful and *res is set to the converted
- * value, otherwise it returns -EINVAL and *res is set to 0.
+ * @cp: The string to be converted
+ * @base: The number base to use (0 for the default)
+ * @res: The converted result value
+ * Return: 0 if conversion is successful and `*res` is set to the converted
+ * value, otherwise it returns -EINVAL and `*res` is set to 0.
  *
  * strict_strtoul converts a string to an unsigned long only if the
  * string is really an unsigned long string, any string containing
@@ -98,7 +98,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base);
  * Given a string this finds a trailing number on the string and returns it.
  * For example, "abc123" would return 123.
  *
- * @str:	String to exxamine
+ * @str:	String to examine
  * Return: trailing number if found, else -1
  */
 long trailing_strtol(const char *str);
@@ -111,7 +111,7 @@ long trailing_strtol(const char *str);
  * characters between @str and @end - 1 are examined. If @end is NULL, it is
  * set to str + strlen(str).
  *
- * @str:	String to exxamine
+ * @str:	String to examine
  * @end:	Pointer to end of string to examine, or NULL to use the
  *		whole string
  * Return: trailing number if found, else -1
@@ -124,7 +124,7 @@ long trailing_strtoln(const char *str, const char *end);
  * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
  * defined, then it will hang instead of resetting.
  *
- * @param fmt:	printf() format string for message, which should not include
+ * @fmt: printf() format string for message, which should not include
  *		\n, followed by arguments
  */
 void panic(const char *fmt, ...)
@@ -139,16 +139,16 @@ void panic(const char *fmt, ...)
  * This function can be used instead of panic() when your board does not
  * already use printf(), * to keep code size small.
  *
- * @param fmt:	string to display, which should not include \n
+ * @str: string to display, which should not include \n
  */
 void panic_str(const char *str) __attribute__ ((noreturn));
 
 /**
  * Format a string and place it in a buffer
  *
- * @param buf	The buffer to place the result into
- * @param fmt	The format string to use
- * @param ...	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
  *
  * The function returns the number of characters written
  * into @buf.
@@ -161,9 +161,9 @@ int sprintf(char *buf, const char *fmt, ...)
 /**
  * Format a string and place it in a buffer (va_list version)
  *
- * @param buf	The buffer to place the result into
- * @param fmt	The format string to use
- * @param args	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @fmt: The format string to use
+ * @args: Arguments for the format string
  * Return: the number of characters which have been written into
  * the @buf not including the trailing '\0'.
  *
@@ -178,7 +178,7 @@ int vsprintf(char *buf, const char *fmt, va_list args);
  *
  * This returns a static string containing the decimal representation of the
  * given value. The returned value may be overwritten by other calls to other
- * simple_... functions, so should be used immediately
+ * simple... functions, so should be used immediately
  *
  * @val: Value to convert
  * Return: string containing the decimal representation of @val
@@ -190,9 +190,9 @@ char *simple_itoa(ulong val);
  *
  * This returns a static string containing the hexadecimal representation of the
  * given value. The returned value may be overwritten by other calls to other
- * simple_... functions, so should be used immediately
+ * simple... functions, so should be used immediately
  *
- * @val: Value to convert
+ * @num: Value to convert
  * Return: string containing the hexecimal representation of @val
  */
 char *simple_xtoa(ulong num);
@@ -200,10 +200,10 @@ char *simple_xtoa(ulong num);
 /**
  * Format a string and place it in a buffer
  *
- * @param buf	The buffer to place the result into
- * @param size	The size of the buffer, including the trailing null space
- * @param fmt	The format string to use
- * @param ...	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
  * Return: the number of characters which would be
  * generated for the given input, excluding the trailing null,
  * as per ISO C99.  If the return is greater than or equal to
@@ -217,10 +217,10 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)
 /**
  * Format a string and place it in a buffer
  *
- * @param buf	The buffer to place the result into
- * @param size	The size of the buffer, including the trailing null space
- * @param fmt	The format string to use
- * @param ...	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
  *
  * The return value is the number of characters written into @buf not including
  * the trailing '\0'. If @size is == 0 the function returns 0.
@@ -233,10 +233,10 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
 /**
  * Format a string and place it in a buffer (base function)
  *
- * @param buf	The buffer to place the result into
- * @param size	The size of the buffer, including the trailing null space
- * @param fmt	The format string to use
- * @param args	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @args: Arguments for the format string
  * Return: The number characters which would be generated for the given
  * input, excluding the trailing '\0', as per ISO C99. Note that fewer
  * characters may be written if this number of characters is >= size.
@@ -258,10 +258,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
 /**
  * Format a string and place it in a buffer (va_list version)
  *
- * @param buf	The buffer to place the result into
- * @param size	The size of the buffer, including the trailing null space
- * @param fmt	The format string to use
- * @param args	Arguments for the format string
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @args: Arguments for the format string
  * Return: the number of characters which have been written into
  * the @buf not including the trailing '\0'. If @size is == 0 the function
  * returns 0.
@@ -278,8 +278,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
  * This prints a value with grouped digits, like 12,345,678 to make it easier
  * to read.
  *
- * @val:	Value to print
- * @digits:	Number of digiits to print
+ * @int_val: Value to print
+ * @digits: Number of digiits to print
  */
 void print_grouped_ull(unsigned long long int_val, int digits);
 
@@ -309,9 +309,9 @@ void str_to_upper(const char *in, char *out, size_t len);
 
 /**
  * vsscanf - Unformat a buffer into a list of arguments
- * @buf:	input buffer
- * @fmt:	format of buffer
- * @args:	arguments
+ * @inp: input buffer
+ * @fmt0: format of buffer
+ * @ap: arguments
  */
 int vsscanf(const char *inp, char const *fmt0, va_list ap);
 
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#4 lore raw

PATCH v5 4/34 lib: Fix a few bugs in trailing_strtoln()

In reply to Simon Glass

At present this has a minor bug in that it reads the byte before the start of the string, if it is empty. Also it doesn't handle a non-numeric prefix which is only one character long.

Fix these bugs with a reworked implementation. Add a test for the second case. The first one is hard to test.

---

(no changes since v4)

Changes in v4:
- Correct the commit tag
- Reword the commit message
- Update the function comment to clarify its intert / limitations

 include/vsprintf.h |  3 +++
 lib/strto.c        | 11 ++++++-----
 test/str_ut.c      |  2 ++
 3 files changed, 11 insertions(+), 5 deletions(-)
include/vsprintf.h +3 -0
index d4bf3211da4..5172ceedec1 100644
@@ -98,6 +98,9 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base);
  * Given a string this finds a trailing number on the string and returns it.
  * For example, "abc123" would return 123.
  *
+ * Note that this does not handle a string without a prefix. See dectoul() for
+ * that case.
+ *
  * @str:	String to examine
  * Return: trailing number if found, else -1
  */
lib/strto.c +6 -5
index f1918843765..b1d803a77d9 100644
@@ -189,11 +189,12 @@ long trailing_strtoln(const char *str, const char *end)
 
 	if (!end)
 		end = str + strlen(str);
-	if (isdigit(end[-1])) {
-		for (p = end - 1; p > str; p--) {
-			if (!isdigit(*p))
-				return dectoul(p + 1, NULL);
-		}
+	p = end - 1;
+	if (p > str && isdigit(*p)) {
+		do {
+			if (!isdigit(p[-1]))
+				return dectoul(p, NULL);
+		} while (--p > str);
 	}
 
 	return -1;
test/str_ut.c +2 -0
index 9674a59f2a6..058b3594379 100644
@@ -257,6 +257,8 @@ static int str_trailing(struct unit_test_state *uts)
 	ut_asserteq(123, trailing_strtoln(str1, str1 + 6));
 	ut_asserteq(-1, trailing_strtoln(str1, str1 + 9));
 
+	ut_asserteq(3, trailing_strtol("a3"));
+
 	return 0;
 }
 STR_TEST(str_trailing, 0);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#5 lore raw

PATCH v5 5/34 lib: Add a way to find the postiion of a trailing number

In reply to Simon Glass

At present it is not possible to find out which part of the string is the number part and which is before it. Add a new variant which provides this feature, so we can separate the two in the caller.

---

(no changes since v4)

Changes in v4:
- Use new Return style in function comments

Changes in v3:
- Add some tests, including one for 'abc123def456'
- Change the function to return a pointer to the first digit

 include/vsprintf.h | 18 ++++++++++++++++++
 lib/strto.c        | 14 ++++++++++++--
 test/str_ut.c      | 13 ++++++++++++-
 3 files changed, 42 insertions(+), 3 deletions(-)
include/vsprintf.h +18 -0
index 5172ceedec1..e006af200fd 100644
@@ -121,6 +121,24 @@ long trailing_strtol(const char *str);
  */
 long trailing_strtoln(const char *str, const char *end);
 
+/**
+ * trailing_strtoln_end() - extract trailing integer from a fixed-length string
+ *
+ * Given a fixed-length string this finds a trailing number on the string
+ * and returns it. For example, "abc123" would return 123. Only the
+ * characters between @str and @end - 1 are examined. If @end is NULL, it is
+ * set to str + strlen(str).
+ *
+ * @str:	String to examine
+ * @end:	Pointer to end of string to examine, or NULL to use the
+ *		whole string
+ * @endp:	If non-NULL, this is set to point to the character where the
+ *	number starts, e.g. for "mmc0" this would be point to the '0'; if no
+ *	trailing number is found, it is set to the end of the string
+ * Return: training number if found, else -1
+ */
+long trailing_strtoln_end(const char *str, const char *end, char const **endp);
+
 /**
  * panic() - Print a message and reset/hang
  *
lib/strto.c +12 -2
index b1d803a77d9..6462d4fddf1 100644
@@ -183,7 +183,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
 	return simple_strtoull(cp, endp, base);
 }
 
-long trailing_strtoln(const char *str, const char *end)
+long trailing_strtoln_end(const char *str, const char *end, char const **endp)
 {
 	const char *p;
 
@@ -192,14 +192,24 @@ long trailing_strtoln(const char *str, const char *end)
 	p = end - 1;
 	if (p > str && isdigit(*p)) {
 		do {
-			if (!isdigit(p[-1]))
+			if (!isdigit(p[-1])) {
+				if (endp)
+					*endp = p;
 				return dectoul(p, NULL);
+			}
 		} while (--p > str);
 	}
+	if (endp)
+		*endp = end;
 
 	return -1;
 }
 
+long trailing_strtoln(const char *str, const char *end)
+{
+	return trailing_strtoln_end(str, end, NULL);
+}
+
 long trailing_strtol(const char *str)
 {
 	return trailing_strtoln(str, NULL);
test/str_ut.c +12 -1
index 058b3594379..5a844347c2b 100644
@@ -244,7 +244,9 @@ STR_TEST(str_xtoa, 0);
 
 static int str_trailing(struct unit_test_state *uts)
 {
-	char str1[] = "abc123def";
+	const char str1[] = "abc123def";
+	const char str2[] = "abc123def456";
+	const char *end;
 
 	ut_asserteq(-1, trailing_strtol(""));
 	ut_asserteq(-1, trailing_strtol("123"));
@@ -259,6 +261,15 @@ static int str_trailing(struct unit_test_state *uts)
 
 	ut_asserteq(3, trailing_strtol("a3"));
 
+	ut_asserteq(123, trailing_strtoln_end(str1, str1 + 6, &end));
+	ut_asserteq(3, end - str1);
+
+	ut_asserteq(-1, trailing_strtoln_end(str1, str1 + 7, &end));
+	ut_asserteq(7, end - str1);
+
+	ut_asserteq(456, trailing_strtoln_end(str2, NULL, &end));
+	ut_asserteq(9, end - str2);
+
 	return 0;
 }
 STR_TEST(str_trailing, 0);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#6 lore raw

PATCH v5 6/34 dm: core: Rename and fix uclass_get_by_name_len()

In reply to Simon Glass

It seems that namelen is more common in U-Boot. Rename this function to fit in better. Also fix a bug where it breaks the operation of uclass_get_by_name() and add a test.

---

(no changes since v4)

Changes in v4:
- Correct bug in this function and add test
- Use new sphynx Return style

Changes in v3:
- Add new patch to rename uclass_get_by_name_len()

 drivers/core/uclass.c | 7 ++++---
 include/dm/uclass.h   | 6 +++---
 test/dm/core.c        | 2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/core/uclass.c +4 -3
index 2578803b7a4..4b9b54f0f15 100644
@@ -180,14 +180,15 @@ void uclass_set_priv(struct uclass *uc, void *priv)
 	uc->priv_ = priv;
 }
 
-enum uclass_id uclass_get_by_name_len(const char *name, int len)
+enum uclass_id uclass_get_by_namelen(const char *name, int len)
 {
 	int i;
 
 	for (i = 0; i < UCLASS_COUNT; i++) {
 		struct uclass_driver *uc_drv = lists_uclass_lookup(i);
 
-		if (uc_drv && !strncmp(uc_drv->name, name, len))
+		if (uc_drv && !strncmp(uc_drv->name, name, len) &&
+		    strlen(uc_drv->name) == len)
 			return i;
 	}
 
@@ -196,7 +197,7 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
 
 enum uclass_id uclass_get_by_name(const char *name)
 {
-	return uclass_get_by_name_len(name, strlen(name));
+	return uclass_get_by_namelen(name, strlen(name));
 }
 
 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
include/dm/uclass.h +3 -3
index aafe6522886..f6c0110b061 100644
@@ -173,13 +173,13 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
 const char *uclass_get_name(enum uclass_id id);
 
 /**
- * uclass_get_by_name_len() - Look up a uclass by its partial driver name
+ * uclass_get_by_namelen() - Look up a uclass by its driver name
  *
  * @name: Name to look up
- * @len: Length of the partial name
+ * @len: Length of @name (the uclass driver name must have the same length)
  * Return: the associated uclass ID, or UCLASS_INVALID if not found
  */
-enum uclass_id uclass_get_by_name_len(const char *name, int len);
+enum uclass_id uclass_get_by_namelen(const char *name, int len);
 
 /**
  * uclass_get_by_name() - Look up a uclass by its driver name
test/dm/core.c +2 -0
index 0ce0b3c4a2e..2c73ecf54a0 100644
@@ -1161,6 +1161,8 @@ static int dm_test_uclass_names(struct unit_test_state *uts)
 	ut_asserteq_str("test", uclass_get_name(UCLASS_TEST));
 	ut_asserteq(UCLASS_TEST, uclass_get_by_name("test"));
 
+	ut_asserteq(UCLASS_SPI, uclass_get_by_name("spi"));
+
 	return 0;
 }
 DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#7 lore raw

PATCH v5 7/34 dm: core: Allow finding a uclass device by partial name

In reply to Simon Glass

In some cases two devices are related and the only way to tell is to check that the names partially patch. Add a way to check this without needing to create a new string for the comparison.

Fix the comment for device_find_child_by_namelen() while we are here.

---

(no changes since v4)

Changes in v4:
- Add a test also
- Use new sphynx Return style

Changes in v3:
- Add new patch to support finding a uclass device by partial name

 drivers/core/uclass.c        | 13 ++++++++++---
 include/dm/device.h          |  2 +-
 include/dm/uclass-internal.h | 16 ++++++++++++++++
 test/dm/core.c               | 15 +++++++++++++++
 4 files changed, 42 insertions(+), 4 deletions(-)
drivers/core/uclass.c +10 -3
index 4b9b54f0f15..08d9ed82de2 100644
@@ -274,8 +274,8 @@ int uclass_find_next_device(struct udevice **devp)
 	return 0;
 }
 
-int uclass_find_device_by_name(enum uclass_id id, const char *name,
-			       struct udevice **devp)
+int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len,
+				  struct udevice **devp)
 {
 	struct uclass *uc;
 	struct udevice *dev;
@@ -289,7 +289,8 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name,
 		return ret;
 
 	uclass_foreach_dev(dev, uc) {
-		if (!strcmp(dev->name, name)) {
+		if (!strncmp(dev->name, name, len) &&
+		    strlen(dev->name) == len) {
 			*devp = dev;
 			return 0;
 		}
@@ -298,6 +299,12 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name,
 	return -ENODEV;
 }
 
+int uclass_find_device_by_name(enum uclass_id id, const char *name,
+			       struct udevice **devp)
+{
+	return uclass_find_device_by_namelen(id, name, strlen(name), devp);
+}
+
 int uclass_find_next_free_seq(struct uclass *uc)
 {
 	struct udevice *dev;
include/dm/device.h +1 -1
index e0f86f5df9f..b474888d025 100644
@@ -799,7 +799,7 @@ int device_find_first_child_by_uclass(const struct udevice *parent,
 				      struct udevice **devp);
 
 /**
- * device_find_child_by_name() - Find a child by device name
+ * device_find_child_by_namelen() - Find a child by device name
  *
  * @parent:	Parent device to search
  * @name:	Name to look for
include/dm/uclass-internal.h +16 -0
index daf856c03cf..3ddcdd21439 100644
@@ -154,6 +154,22 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
  */
 int uclass_find_next_device(struct udevice **devp);
 
+/**
+ * uclass_find_device_by_namelen() - Find uclass device based on ID and name
+ *
+ * This searches for a device with the exactly given name.
+ *
+ * The device is NOT probed, it is merely returned.
+ *
+ * @id: ID to look up
+ * @name: name of a device to find
+ * @len: Length of @name (the uclass driver name must have the same length)
+ * @devp: Returns pointer to device (the first one with the name)
+ * Return: 0 if OK, -ve on error
+ */
+int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len,
+				  struct udevice **devp);
+
 /**
  * uclass_find_device_by_name() - Find uclass device based on ID and name
  *
test/dm/core.c +15 -0
index 2c73ecf54a0..ebd504427d1 100644
@@ -1260,3 +1260,18 @@ static int dm_test_get_stats(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_get_stats, UT_TESTF_SCAN_FDT);
+
+/* Test uclass_find_device_by_name() */
+static int dm_test_uclass_find_device(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_find_device_by_name(UCLASS_I2C, "i2c@0", &dev));
+	ut_asserteq(-ENODEV,
+		    uclass_find_device_by_name(UCLASS_I2C, "i2c@0x", &dev));
+	ut_assertok(uclass_find_device_by_namelen(UCLASS_I2C, "i2c@0x", 5,
+						  &dev));
+
+	return 0;
+}
+DM_TEST(dm_test_uclass_find_device, UT_TESTF_SCAN_FDT);
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#8 lore raw

PATCH v5 8/34 test: fastboot: Avoid using mmc1

In reply to Simon Glass

The bootflow tests need to use an MMC with an associated backing file containing a filesystem. Update the fastboot tests to cope with this.

---

(no changes since v1)

 test/dm/fastboot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/dm/fastboot.c +2 -2
index e7f8c362b85..758538d0e85 100644
@@ -81,9 +81,9 @@ static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
 						  &part_info, response));
 	ut_asserteq(0, fastboot_mmc_get_part_info("0.0:0", &fb_dev_desc,
 						  &part_info, response));
-	ut_asserteq(0, fastboot_mmc_get_part_info("1", &fb_dev_desc,
+	ut_asserteq(0, fastboot_mmc_get_part_info("2", &fb_dev_desc,
 						  &part_info, response));
-	ut_asserteq(0, fastboot_mmc_get_part_info("1.0", &fb_dev_desc,
+	ut_asserteq(0, fastboot_mmc_get_part_info("2.0", &fb_dev_desc,
 						  &part_info, response));
 	ut_asserteq(1, fastboot_mmc_get_part_info(":1", &fb_dev_desc,
 						  &part_info, response));
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#9 lore raw

PATCH v5 9/34 test: dm: Restart USB before assuming it is stopped

In reply to Simon Glass

Update the blk test to stop USB first, in case another test has started it.

---

(no changes since v1)

 test/dm/blk.c | 6 ++++++
 1 file changed, 6 insertions(+)
test/dm/blk.c +6 -0
index 8556cc7159c..85c3a3bd45c 100644
@@ -15,6 +15,9 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/* Allow resetting the USB-started flag */
+extern char usb_started;
+
 /* Test that block devices can be created */
 static int dm_test_blk_base(struct unit_test_state *uts)
 {
@@ -66,8 +69,11 @@ static int dm_test_blk_usb(struct unit_test_state *uts)
 	struct udevice *usb_dev, *dev;
 	struct blk_desc *dev_desc;
 
+	usb_started = false;
+
 	/* Get a flash device */
 	state_set_skip_delays(true);
+	ut_assertok(usb_stop());
 	ut_assertok(usb_init());
 	ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &usb_dev));
 	ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc));
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#10 lore raw

PATCH v5 10/34 dm: blk: Add a function to return the device type

In reply to Simon Glass

Use the uclass name to get the device type for a block device.

---

(no changes since v4)

Changes in v4:
- Use new sphynx Return style

 drivers/block/blk-uclass.c | 7 +++++++
 include/blk.h              | 8 ++++++++
 2 files changed, 15 insertions(+)
drivers/block/blk-uclass.c +7 -0
index f1e4a856467..29f355fa154 100644
@@ -509,6 +509,13 @@ int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 	return 0;
 }
 
+const char *blk_get_devtype(struct udevice *dev)
+{
+	struct udevice *parent = dev_get_parent(dev);
+
+	return uclass_get_name(device_get_uclass_id(parent));
+};
+
 int blk_find_max_devnum(enum if_type if_type)
 {
 	struct udevice *dev;
include/blk.h +8 -0
index dbe9ae219da..9503369db83 100644
@@ -433,6 +433,14 @@ int blk_select_hwpart(struct udevice *dev, int hwpart);
  */
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
 
+/**
+ * blk_get_devtype() - Get the device type of a block device
+ *
+ * @dev:	Block device to check
+ * Return: device tree, i.e. the uclass name of its parent, e.g. "mmc"
+ */
+const char *blk_get_devtype(struct udevice *dev);
+
 /**
  * blk_get_by_device() - Get the block device descriptor for the given device
  * @dev:	Instance of a storage device
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#11 lore raw

PATCH v5 11/34 fs: Add a function to set the filesystem type

In reply to Simon Glass

When sandbox is used with hostfs we won't have a block device, but still must set up the filesystem type before any filesystem operation, such as loading a file. Add a function to handle this.

---

(no changes since v4)

Changes in v4:
- Add new patch with a function to set the filesystem type

 fs/fs.c      |  5 +++++
 include/fs.h | 11 +++++++++++
 2 files changed, 16 insertions(+)
fs/fs.c +5 -0
index b812597ced9..6de1a3eb6d5 100644
@@ -36,6 +36,11 @@ static int fs_dev_part;
 static struct disk_partition fs_partition;
 static int fs_type = FS_TYPE_ANY;
 
+void fs_set_type(int type)
+{
+	fs_type = type;
+}
+
 static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
 				      struct disk_partition *fs_partition)
 {
include/fs.h +11 -0
index e2beba36b98..b43f16a692f 100644
@@ -57,6 +57,17 @@ int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
  */
 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
 
+/**
+ * fs_set_type() - Tell fs layer which filesystem type is used
+ *
+ * This is needed when reading from a non-block device such as sandbox. It does
+ * a similar job to fs_set_blk_dev() but just sets the filesystem type instead
+ * of detecting it and loading it on the block device
+ *
+ * @type: Filesystem type to use (FS_TYPE...)
+ */
+void fs_set_type(int type);
+
 /*
  * fs_set_blk_dev_with_part - Set current block device + partition
  *
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#12 lore raw

PATCH v5 12/34 bootstd: Add the concept of a bootflow

In reply to Simon Glass

A bootflow encapsulates the process used to boot an operating system. It typically has a control file (such as extlinux.conf) and information about which 'bootdev' it came from.

Add the header file for this first, since it is needed by all other files.

---

(no changes since v4)

Changes in v4:
- Add a new fs_type field for use with sandbox
- Use new Return style in function comments

Changes in v3:
- Mention bootflow_state[] in enum bootflow_state_t

 MAINTAINERS        |   5 +
 include/bootflow.h | 260 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 265 insertions(+)
 create mode 100644 include/bootflow.h
MAINTAINERS +5 -0
index f7665fccf7a..d6d45573fdc 100644
@@ -693,6 +693,11 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	tools/binman/
 
+BOOTDEVICE
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	include/bootflow.h
+
 BTRFS
 M:	Marek Behun <[email protected]>
 R:	Qu Wenruo <[email protected]>
include/bootflow.h new file +260 -0

260 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#13 lore raw

PATCH v5 13/34 bootstd: Add the bootstd uclass and core implementation

In reply to Simon Glass

The 'bootstd' device provides the central information about U-Boot standard boot.

Add a uclass for bootstd and the various helpers needed to make it work. Also add a binding file.

---

Changes in v5:
- Disable bootstd for EFI app builds, since they use dm_scan_other()

Changes in v4:
- NULL-terminate the default prefix list
- Use new Return style in function comments

Changes in v3:
- Add CONFIG_BOOTSTD_FULL to enable the full feature set
- Support bootdev-order and filename-prefixes only with CONFIG_BOOTSTD_FULL

 MAINTAINERS                          |   2 +
 boot/Kconfig                         |  34 ++++++
 boot/Makefile                        |   3 +
 boot/bootstd-uclass.c                | 152 +++++++++++++++++++++++++++
 configs/efi-x86_app32_defconfig      |   1 +
 configs/efi-x86_app64_defconfig      |   1 +
 doc/device-tree-bindings/bootstd.txt |  28 +++++
 include/bootstd.h                    |  80 ++++++++++++++
 include/dm/uclass-id.h               |   1 +
 9 files changed, 302 insertions(+)
 create mode 100644 boot/bootstd-uclass.c
 create mode 100644 doc/device-tree-bindings/bootstd.txt
 create mode 100644 include/bootstd.h
MAINTAINERS +2 -0
index d6d45573fdc..dd099d6240f 100644
@@ -696,6 +696,8 @@ F:	tools/binman/
 BOOTDEVICE
 M:	Simon Glass <[email protected]>
 S:	Maintained
+F:	boot/bootstd.c
+F:	include/bootstd.h
 F:	include/bootflow.h
 
 BTRFS
boot/Kconfig +34 -0
index ec5b956490d..9faa55a5418 100644
@@ -292,6 +292,40 @@ endif # SPL
 
 endif # FIT
 
+config BOOTSTD
+	bool "Standard boot support"
+	default y
+	depends on DM && OF_CONTROL && BLK
+	help
+	  U-Boot supports a standard way of locating something to boot,
+	  typically an Operating System such as Linux, provided by a distro such
+	  as Arch Linux or Debian. Enable this to support iterating through
+	  available bootdevs and using bootmeths to find bootflows suitable for
+	  booting.
+
+	  Standard boot is not a standard way of booting, just a framework
+	  within U-Boot for supporting all the different ways that exist.
+
+	  Terminology:
+
+	    - bootdev - a device which can hold a distro (e.g. MMC)
+	    - 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)
+
+config BOOTSTD_FULL
+	bool "Enhanced features for standard boot"
+	default y if SANDBOX
+	help
+	  This enables various useful features for standard boot, which are not
+	  essential for operation:
+
+	  - bootdev, bootmeth commands
+	  - extra features in the bootflow command
+	  - support for selecting the ordering of bootmeths ("bootmeth order")
+	  - support for selecting the ordering of bootdevs using the devicetree
+	    as well as the "boot_targets" environment variable
+
 config LEGACY_IMAGE_FORMAT
 	bool "Enable support for the legacy image format"
 	default y if !FIT_SIGNATURE
boot/Makefile +3 -0
index 1b99e6ee33f..21dcf6a6056 100644
@@ -18,6 +18,9 @@ endif
 obj-y += image.o image-board.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
+
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
boot/bootstd-uclass.c new file +152 -0

152 lines not on this page · raw message

configs/efi-x86_app32_defconfig +1 -0
index 228643a1bd6..7a723c136c2 100644
@@ -8,6 +8,7 @@ CONFIG_VENDOR_EFI=y
 CONFIG_TARGET_EFI_APP32=y
 CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
configs/efi-x86_app64_defconfig +1 -0
index 1ed2f130509..98f91d81164 100644
@@ -8,6 +8,7 @@ CONFIG_VENDOR_EFI=y
 CONFIG_TARGET_EFI_APP64=y
 CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
doc/device-tree-bindings/bootstd.txt new file +28 -0
new file mode 100644
index 00000000000..f048b9dd327
@@ -0,0 +1,28 @@
+U-Boot standard boot device (bootstd)
+=====================================
+
+This is the controlling device for U-Boot standard boot, providing a way to
+boot operating systems in a way that can be controlled by distros.
+
+Required properties:
+
+compatible: "u-boot,boot-std"
+
+Optional properties:
+
+filename-prefixes:
+   List of strings, each a directory to search for bootflow files
+
+bootdev-order:
+   List of bootdevs to check for bootflows, each a bootdev label (the media
+   uclass followed by the numeric sequence number of the media device)
+
+
+Example:
+
+	bootstd {
+		compatible = "u-boot,boot-std";
+
+		filename-prefixes = "/", "/boot/";
+		bootdev-order = "mmc2", "mmc1";
+	};
include/bootstd.h new file +80 -0

80 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 0e26e1d1382..cece0626a11 100644
@@ -38,6 +38,7 @@ enum uclass_id {
 	UCLASS_AXI,		/* AXI bus */
 	UCLASS_BLK,		/* Block device */
 	UCLASS_BOOTCOUNT,       /* Bootcount backing store */
+	UCLASS_BOOTSTD,		/* Standard boot driver */
 	UCLASS_BUTTON,		/* Button */
 	UCLASS_CACHE,		/* Cache controller */
 	UCLASS_CLK,		/* Clock source, e.g. used by peripherals */
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#14 lore raw

PATCH v5 14/34 bootstd: Add the bootdev uclass

In reply to Simon Glass

A 'bootdev' is a device which can be used to boot an operating system. It is a child of the media device (e.g. MMC) which handles reading files from that device, such as a bootflow file.

Add a uclass for bootdev and the various helpers needed to make it work. Also add a binding file, empty for now.

---

(no changes since v4)

Changes in v4:
- Use new Return style in function comments

Changes in v3:
- Add bootdev_get_from_blk() function
- Move bootdev ordering into the uclass
- Update for the new trailing_strtoln_end()
- Use blk_find_device() to find the block device for a media device

 MAINTAINERS                          |   4 +-
 boot/Makefile                        |   1 +
 boot/bootdev-uclass.c                | 640 +++++++++++++++++++++++++++
 doc/device-tree-bindings/bootdev.txt |   8 +
 include/bootdev.h                    | 275 ++++++++++++
 include/dm/uclass-id.h               |   1 +
 6 files changed, 928 insertions(+), 1 deletion(-)
 create mode 100644 boot/bootdev-uclass.c
 create mode 100644 doc/device-tree-bindings/bootdev.txt
 create mode 100644 include/bootdev.h
MAINTAINERS +3 -1
index dd099d6240f..78ec857d182 100644
@@ -696,9 +696,11 @@ F:	tools/binman/
 BOOTDEVICE
 M:	Simon Glass <[email protected]>
 S:	Maintained
+F:	boot/bootdev*.c
 F:	boot/bootstd.c
-F:	include/bootstd.h
+F:	include/bootdev*.h
 F:	include/bootflow.h
+F:	include/bootstd.h
 
 BTRFS
 M:	Marek Behun <[email protected]>
boot/Makefile +1 -0
index 21dcf6a6056..301d75fb646 100644
@@ -19,6 +19,7 @@ obj-y += image.o image-board.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
boot/bootdev-uclass.c new file +640 -0

640 lines not on this page · raw message

doc/device-tree-bindings/bootdev.txt new file +8 -0
new file mode 100644
index 00000000000..95b7fec8212
@@ -0,0 +1,8 @@
+U-Boot boot device (bootdev)
+============================
+
+A bootdev provides a way to obtain a bootflow file from a device. It is a
+child of the media device (UCLASS_MMC, UCLASS_SPI_FLASH, etc.)
+
+The bootdev driver is provided by the media devices. The bindings for each
+are described in this file (to come).
include/bootdev.h new file +275 -0

275 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index cece0626a11..97ba4c02c42 100644
@@ -38,6 +38,7 @@ enum uclass_id {
 	UCLASS_AXI,		/* AXI bus */
 	UCLASS_BLK,		/* Block device */
 	UCLASS_BOOTCOUNT,       /* Bootcount backing store */
+	UCLASS_BOOTDEV,		/* Boot device for locating an OS to boot */
 	UCLASS_BOOTSTD,		/* Standard boot driver */
 	UCLASS_BUTTON,		/* Button */
 	UCLASS_CACHE,		/* Cache controller */
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#15 lore raw

PATCH v5 15/34 bootstd: Add the bootmeth uclass and helpers

In reply to Simon Glass

A bootmeth is a method of locating an operating system. For now, just add the uclass itself. Drivers for particular bootmeths are added later.

If no bootmeths devices are included in the devicetree, create them automatically. This avoids the need for boilerplate in the devicetree files.

---

(no changes since v4)

Changes in v4:
- Split out the file setup into into its own function
- Use new Return style in function comments

Changes in v3:
- Add some more common functions
- Move bootmeth ordering into the uclass
- Support "bootmeths" env var

 MAINTAINERS            |   2 +
 boot/Makefile          |   1 +
 boot/bootmeth-uclass.c | 333 +++++++++++++++++++++++++++++++++++++++++
 boot/bootstd-uclass.c  |  29 +++-
 include/bootmeth.h     | 234 +++++++++++++++++++++++++++++
 include/dm/uclass-id.h |   1 +
 include/env_callback.h |   7 +
 7 files changed, 605 insertions(+), 2 deletions(-)
 create mode 100644 boot/bootmeth-uclass.c
 create mode 100644 include/bootmeth.h
MAINTAINERS +2 -0
index 78ec857d182..7b6aada33c4 100644
@@ -696,10 +696,12 @@ F:	tools/binman/
 BOOTDEVICE
 M:	Simon Glass <[email protected]>
 S:	Maintained
+F:	boot/bootmeth*.c
 F:	boot/bootdev*.c
 F:	boot/bootstd.c
 F:	include/bootdev*.h
 F:	include/bootflow.h
+F:	include/bootmeth.h
 F:	include/bootstd.h
 
 BTRFS
boot/Makefile +1 -0
index 301d75fb646..1150051e737 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
boot/bootmeth-uclass.c new file +333 -0

333 lines not on this page · raw message

boot/bootstd-uclass.c +27 -2
index 615cd89bf0b..4c71c2829ef 100644
@@ -109,8 +109,10 @@ static int bootstd_probe(struct udevice *dev)
 /* For now, bind the boormethod device if none are found in the devicetree */
 int dm_scan_other(bool pre_reloc_only)
 {
-	struct udevice *bootstd;
-	int ret;
+	struct driver *drv = ll_entry_start(struct driver, driver);
+	const int n_ents = ll_entry_count(struct driver, driver);
+	struct udevice *dev, *bootstd;
+	int i, ret;
 
 	/* These are not needed before relocation */
 	if (!(gd->flags & GD_FLG_RELOC))
@@ -125,6 +127,29 @@ int dm_scan_other(bool pre_reloc_only)
 			return log_msg_ret("bootstd", ret);
 	}
 
+	/* If there are no bootmeth devices, create them */
+	uclass_find_first_device(UCLASS_BOOTMETH, &dev);
+	if (dev)
+		return 0;
+
+	for (i = 0; i < n_ents; i++, drv++) {
+		/*
+		 * Disable EFI Manager for now as no one uses it so it is
+		 * confusing
+		 */
+		if (drv->id == UCLASS_BOOTMETH &&
+		    strcmp("efi_mgr_bootmeth", drv->name)) {
+			const char *name = drv->name;
+
+			if (!strncmp("bootmeth_", name, 9))
+				name += 9;
+			ret = device_bind(bootstd, drv, name, 0, ofnode_null(),
+					  &dev);
+			if (ret)
+				return log_msg_ret("meth", ret);
+		}
+	}
+
 	return 0;
 }
 
include/bootmeth.h new file +234 -0

234 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 97ba4c02c42..5cee8bebf8e 100644
@@ -39,6 +39,7 @@ enum uclass_id {
 	UCLASS_BLK,		/* Block device */
 	UCLASS_BOOTCOUNT,       /* Bootcount backing store */
 	UCLASS_BOOTDEV,		/* Boot device for locating an OS to boot */
+	UCLASS_BOOTMETH,	/* Bootmethod for booting an OS */
 	UCLASS_BOOTSTD,		/* Standard boot driver */
 	UCLASS_BUTTON,		/* Button */
 	UCLASS_CACHE,		/* Cache controller */
include/env_callback.h +7 -0
index 05e9516a0f4..d5d2b2fcad6 100644
@@ -57,6 +57,12 @@
 #define NET_CALLBACKS
 #endif
 
+#ifdef CONFIG_BOOTSTD
+#define BOOTSTD_CALLBACK	"bootmeths:bootmeths,"
+#else
+#define BOOTSTD_CALLBACK
+#endif
+
 /*
  * This list of callback bindings is static, but may be overridden by defining
  * a new association in the ".callbacks" environment variable.
@@ -65,6 +71,7 @@
 	ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
 	"baudrate:baudrate," \
 	NET_CALLBACKS \
+	BOOTSTD_CALLBACK \
 	"loadaddr:loadaddr," \
 	SILENT_CALLBACK \
 	SPLASHIMAGE_CALLBACK \
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#16 lore raw

PATCH v5 16/34 bootstd: Add support for bootflows

In reply to Simon Glass

Add support for bootflows, including maintaining a list of them and iterating to find them.

---

(no changes since v4)

Changes in v4:
- Show the bootmeth name when booting
- Use new Return style in function comments

Changes in v3:
- Explain why it is OK to use "?" as an unknown bootflow state
- Move bootmeth/bootdev ordering into the uclass
- Point to the header file for bootflow_state[] docs

 MAINTAINERS           |   3 +-
 boot/Makefile         |   1 +
 boot/bootdev-uclass.c |  11 +-
 boot/bootflow.c       | 411 ++++++++++++++++++++++++++++++++++++++++++
 boot/bootstd-uclass.c |   2 +-
 include/bootflow.h    |  50 +++++
 6 files changed, 475 insertions(+), 3 deletions(-)
 create mode 100644 boot/bootflow.c
MAINTAINERS +2 -1
index 7b6aada33c4..24e2ad75f82 100644
@@ -696,8 +696,9 @@ F:	tools/binman/
 BOOTDEVICE
 M:	Simon Glass <[email protected]>
 S:	Maintained
-F:	boot/bootmeth*.c
 F:	boot/bootdev*.c
+F:	boot/bootflow.c
+F:	boot/bootmeth*.c
 F:	boot/bootstd.c
 F:	include/bootdev*.h
 F:	include/bootflow.h
boot/Makefile +1 -0
index 1150051e737..ac861fd035f 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
boot/bootdev-uclass.c +10 -1
index e0baeb82b14..1ede933c2f2 100644
@@ -10,6 +10,7 @@
 #include <dm.h>
 #include <bootdev.h>
 #include <bootflow.h>
+#include <bootmeth.h>
 #include <bootstd.h>
 #include <env.h>
 #include <fs.h>
@@ -130,6 +131,10 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,
 
 	bflow->part = iter->part;
 
+	ret = bootmeth_check(bflow->method, iter);
+	if (ret)
+		return log_msg_ret("check", ret);
+
 	/*
 	 * partition numbers start at 0 so this cannot succeed, but it can tell
 	 * us whether there is valid media there
@@ -171,6 +176,10 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,
 		bflow->state = BOOTFLOWST_FS;
 	}
 
+	ret = bootmeth_read_bootflow(bflow->method, bflow);
+	if (ret)
+		return log_msg_ret("method", ret);
+
 	return 0;
 }
 
@@ -445,7 +454,7 @@ void bootdev_clear_bootflows(struct udevice *dev)
 
 		bflow = list_first_entry(&ucp->bootflow_head, struct bootflow,
 					 bm_node);
-		/* later bootflow_remove(bflow); */
+		bootflow_remove(bflow);
 	}
 }
 
boot/bootflow.c new file +411 -0

411 lines not on this page · raw message

boot/bootstd-uclass.c +1 -1
index 4c71c2829ef..266bd7cb2e3 100644
@@ -45,7 +45,7 @@ static void bootstd_clear_glob_(struct bootstd_priv *priv)
 
 		bflow = list_first_entry(&priv->glob_head, struct bootflow,
 					 glob_node);
-		/* add later bootflow_remove(bflow); */
+		bootflow_remove(bflow);
 	}
 }
 
include/bootflow.h +50 -0

60 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#17 lore raw

PATCH v5 17/34 bootstd: Add a bootdev command

In reply to Simon Glass

Add a 'bootdev' command to handle listing and selection of bootdevs.

Disable standard boot for a few boards which otherwise run out of space.

---

(no changes since v3)

Changes in v3:
- Use separate Kconfig options for each command

 MAINTAINERS                        |   1 +
 cmd/Kconfig                        |  10 +++
 cmd/Makefile                       |   1 +
 cmd/bootdev.c                      | 120 +++++++++++++++++++++++++++++
 configs/rcar3_salvator-x_defconfig |   1 +
 configs/tbs2910_defconfig          |   1 +
 6 files changed, 134 insertions(+)
 create mode 100644 cmd/bootdev.c
MAINTAINERS +1 -0
index 24e2ad75f82..5a48b841990 100644
@@ -700,6 +700,7 @@ F:	boot/bootdev*.c
 F:	boot/bootflow.c
 F:	boot/bootmeth*.c
 F:	boot/bootstd.c
+F:	cmd/bootdev.c
 F:	include/bootdev*.h
 F:	include/bootflow.h
 F:	include/bootmeth.h
cmd/Kconfig +10 -0
index f580797d2d3..a5c69187911 100644
@@ -211,6 +211,16 @@ config CMD_BOOTM_PRE_LOAD
 	 This stage allow to check or modify the image provided
 	 to the bootm command.
 
+config CMD_BOOTDEV
+	bool "bootdev"
+	depends on BOOTSTD
+	default y if BOOTSTD_FULL
+	help
+	  Support listing available bootdevs (boot devices) which can provide an
+	  OS to boot, as well as showing information about a particular one.
+
+	  This command is not necessary for bootstd to work.
+
 config BOOTM_EFI
 	bool "Support booting UEFI FIT images"
 	depends on CMD_BOOTEFI && CMD_BOOTM && FIT
cmd/Makefile +1 -0
index ede634d731c..474f6d55f84 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o
 obj-$(CONFIG_CMD_ADC) += adc.o
 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o
+obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o
 obj-$(CONFIG_CMD_SOURCE) += source.o
 obj-$(CONFIG_CMD_BCB) += bcb.o
 obj-$(CONFIG_CMD_BDI) += bdinfo.o
cmd/bootdev.c new file +120 -0

120 lines not on this page · raw message

configs/rcar3_salvator-x_defconfig +1 -0
index f333291aa4b..6ef62ab4cbb 100644
@@ -14,6 +14,7 @@ CONFIG_SYS_LOAD_ADDR=0x58000000
 CONFIG_LTO=y
 CONFIG_REMAKE_ELF=y
 CONFIG_FIT=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_SYS_MONITOR_BASE=0x00000000
 CONFIG_USE_BOOTARGS=y
configs/tbs2910_defconfig +1 -0
index 60a816059a6..9f7642f25ca 100644
@@ -17,6 +17,7 @@ CONFIG_SYS_MEMTEST_END=0x2f400000
 CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=392192
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTCOMMAND=y
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#18 lore raw

PATCH v5 18/34 bootstd: Add a bootflow command

In reply to Simon Glass

Add a 'bootflow' command to handle listing and selection of bootflow.

---

(no changes since v4)

Changes in v4:
- Make CMD_BOOTSTD_FULL depend on BOOTSTD_FULL
- Warn when trying to use the full bootflow command but it is not enabled

Changes in v3:
- Put some features behind CONFIG_BOOTFLOW_FULL
- Use separate Kconfig options for each command

 cmd/Kconfig    |  18 +++
 cmd/Makefile   |   1 +
 cmd/bootflow.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 cmd/bootflow.c
cmd/Kconfig +18 -0
index a5c69187911..d2ffc5370a9 100644
@@ -221,6 +221,24 @@ config CMD_BOOTDEV
 
 	  This command is not necessary for bootstd to work.
 
+config CMD_BOOTFLOW
+	bool "bootflow"
+	depends on BOOTSTD
+	default y
+	help
+	  Support scanning for bootflows available with the bootdevs. The
+	  bootflows can optionally be booted.
+
+config CMD_BOOTFLOW_FULL
+	bool "bootflow - extract subcommands"
+	depends on BOOTSTD_FULL
+	default y if BOOTSTD_FULL
+	help
+	  Add the ability to list the available bootflows, select one and obtain
+	  information about it.
+
+	  This command is not necessary for bootstd to work.
+
 config BOOTM_EFI
 	bool "Support booting UEFI FIT images"
 	depends on CMD_BOOTEFI && CMD_BOOTM && FIT
cmd/Makefile +1 -0
index 474f6d55f84..addb8f02056 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_CMD_ADC) += adc.o
 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o
 obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o
+obj-$(CONFIG_CMD_BOOTFLOW) += bootflow.o
 obj-$(CONFIG_CMD_SOURCE) += source.o
 obj-$(CONFIG_CMD_BCB) += bcb.o
 obj-$(CONFIG_CMD_BDI) += bdinfo.o
cmd/bootflow.c new file +404 -0

404 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#19 lore raw

PATCH v5 19/34 bootstd: Add a bootmeth command

In reply to Simon Glass

Add a 'bootmeth' command to handle listing and ordering of boot methods.

---

(no changes since v3)

Changes in v3:
- Move bootmeth ordering into the uclass

 cmd/Kconfig    |  11 +++++
 cmd/Makefile   |   1 +
 cmd/bootmeth.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 125 insertions(+)
 create mode 100644 cmd/bootmeth.c
cmd/Kconfig +11 -0
index d2ffc5370a9..1205ef501e9 100644
@@ -239,6 +239,17 @@ config CMD_BOOTFLOW_FULL
 
 	  This command is not necessary for bootstd to work.
 
+config CMD_BOOTMETH
+	bool "bootmeth"
+	depends on BOOTSTD
+	default y if BOOTSTD_FULL
+	help
+	  Support listing available bootmethds (methods used to boot an
+	  Operating System), as well as selecting the order that the bootmeths
+	  are used.
+
+	  This command is not necessary for bootstd to work.
+
 config BOOTM_EFI
 	bool "Support booting UEFI FIT images"
 	depends on CMD_BOOTEFI && CMD_BOOTM && FIT
cmd/Makefile +1 -0
index addb8f02056..5e43a1e022e 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o
 obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o
 obj-$(CONFIG_CMD_BOOTFLOW) += bootflow.o
+obj-$(CONFIG_CMD_BOOTMETH) += bootmeth.o
 obj-$(CONFIG_CMD_SOURCE) += source.o
 obj-$(CONFIG_CMD_BCB) += bcb.o
 obj-$(CONFIG_CMD_BDI) += bdinfo.o
cmd/bootmeth.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#20 lore raw

PATCH v5 21/34 bootstd: mmc: Add a bootdev driver

In reply to Simon Glass

Add a bootdev driver for MMC. It mostly just calls the bootdev helper function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

---

(no changes since v4)

Changes in v4:
- Use new Return style in function comments

Changes in v3:
- Adjust for new blk_find_device() function

 MAINTAINERS               |  1 +
 drivers/mmc/Makefile      |  5 ++++
 drivers/mmc/mmc-uclass.c  | 23 +++++++++++++++
 drivers/mmc/mmc_bootdev.c | 62 +++++++++++++++++++++++++++++++++++++++
 include/mmc.h             | 12 +++++++-
 5 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mmc/mmc_bootdev.c
MAINTAINERS +1 -0
index d9125fca850..239fa2eeb75 100644
@@ -702,6 +702,7 @@ F:	boot/bootmeth*.c
 F:	boot/bootstd.c
 F:	cmd/bootdev.c
 F:	cmd/bootflow.c
+F:	drivers/mmc/mmc_bootdev.c
 F:	include/bootdev.h
 F:	include/bootflow.h
 F:	include/bootmeth.h
drivers/mmc/Makefile +5 -0
index 17ebc04203e..96275093022 100644
@@ -5,6 +5,11 @@
 
 obj-y += mmc.o
 obj-$(CONFIG_$(SPL_)DM_MMC) += mmc-uclass.o
+
+ifdef CONFIG_$(SPL_TPL_)DM_MMC
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += mmc_bootdev.o
+endif
+
 obj-$(CONFIG_$(SPL_)MMC_WRITE) += mmc_write.o
 obj-$(CONFIG_MMC_PWRSEQ) += mmc-pwrseq.o
 obj-$(CONFIG_MMC_SDHCI_ADMA_HELPERS) += sdhci-adma.o
drivers/mmc/mmc-uclass.c +23 -0
index 57da788ad80..688bdc06d42 100644
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY UCLASS_MMC
 
 #include <common.h>
+#include <bootdev.h>
 #include <log.h>
 #include <mmc.h>
 #include <dm.h>
@@ -315,6 +316,20 @@ int mmc_get_next_devnum(void)
 	return blk_find_max_devnum(IF_TYPE_MMC);
 }
 
+int mmc_get_blk(struct udevice *dev, struct udevice **blkp)
+{
+	struct udevice *blk;
+	int ret;
+
+	device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk);
+	ret = device_probe(blk);
+	if (ret)
+		return ret;
+	*blkp = blk;
+
+	return 0;
+}
+
 struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
 {
 	struct blk_desc *desc;
@@ -406,6 +421,10 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	mmc->cfg = cfg;
 	mmc->priv = dev;
 
+	ret = bootdev_setup_for_dev(dev, "mmc_bootdev");
+	if (ret)
+		return log_msg_ret("bootdev", ret);
+
 	/* the following chunk was from mmc_register() */
 
 	/* Setup dsr related values */
@@ -424,12 +443,16 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 int mmc_unbind(struct udevice *dev)
 {
 	struct udevice *bdev;
+	int ret;
 
 	device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
 	if (bdev) {
 		device_remove(bdev, DM_REMOVE_NORMAL);
 		device_unbind(bdev);
 	}
+	ret = bootdev_unbind_dev(dev);
+	if (ret)
+		return log_msg_ret("bootdev", ret);
 
 	return 0;
 }
drivers/mmc/mmc_bootdev.c new file +62 -0

62 lines not on this page · raw message

include/mmc.h +11 -1
index 6bdcce881dd..9b4dc683110 100644
@@ -956,10 +956,20 @@ int mmc_get_env_dev(void);
  * mmc_get_blk_desc() - Get the block descriptor for an MMC device
  *
  * @mmc:	MMC device
- * Return: block device if found, else NULL
+ * Return: block descriptor if found, else NULL
  */
 struct blk_desc *mmc_get_blk_desc(struct mmc *mmc);
 
+/**
+ * mmc_get_blk() - Get the block device for an MMC device
+ *
+ * @dev:	MMC device
+ * @blkp:	Returns pointer to probed block device on sucesss
+ *
+ * Return: 0 on success, -ve on error
+ */
+int mmc_get_blk(struct udevice *dev, struct udevice **blkp);
+
 /**
  * mmc_send_ext_csd() - read the extended CSD register
  *
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#21 lore raw

PATCH v5 22/34 bootstd: ethernet: Add a bootdev driver

In reply to Simon Glass

Add a bootdev driver for Ethernet. It can use the PXE boot mechanism to locate a file, added later.

---

(no changes since v1)

 MAINTAINERS       |   1 +
 net/Kconfig       |   9 +++++
 net/Makefile      |   1 +
 net/eth-uclass.c  |   8 ++++
 net/eth_bootdev.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 net/eth_bootdev.c
MAINTAINERS +1 -0
index 239fa2eeb75..77a34082249 100644
@@ -707,6 +707,7 @@ F:	include/bootdev.h
 F:	include/bootflow.h
 F:	include/bootmeth.h
 F:	include/bootstd.h
+F:	net/eth_bootdevice.c
 
 BTRFS
 M:	Marek Behun <[email protected]>
net/Kconfig +9 -0
index ef0aa161f73..964a4fe4999 100644
@@ -25,6 +25,15 @@ config PROT_UDP
 	  Enable a generic udp framework that allows defining a custom
 	  handler for udp protocol.
 
+config BOOTDEV_ETH
+	bool "Enable bootdev for ethernet"
+	depends on BOOTSTD
+	default y
+	help
+	  Provide a bootdev for ethernet so that is it possible to boot
+	  an operationg system over the network, using the PXE (Preboot
+	  Execution Environment) protocol.
+
 config BOOTP_SEND_HOSTNAME
 	bool "Send hostname to DNS server"
 	help
net/Makefile +1 -0
index fb3eba840ff..6c812502d3e 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_CMD_DNS)  += dns.o
 obj-$(CONFIG_DM_DSA)   += dsa-uclass.o
 ifdef CONFIG_DM_ETH
 obj-$(CONFIG_NET)      += eth-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTDEV_ETH) += eth_bootdev.o
 else
 obj-$(CONFIG_NET)      += eth_legacy.o
 endif
net/eth-uclass.c +8 -0
index 58c308f3327..bcefc54ded8 100644
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY UCLASS_ETH
 
 #include <common.h>
+#include <bootdev.h>
 #include <bootstage.h>
 #include <dm.h>
 #include <env.h>
@@ -473,6 +474,8 @@ int eth_initialize(void)
 
 static int eth_post_bind(struct udevice *dev)
 {
+	int ret;
+
 	if (strchr(dev->name, ' ')) {
 		printf("\nError: eth device name \"%s\" has a space!\n",
 		       dev->name);
@@ -482,6 +485,11 @@ static int eth_post_bind(struct udevice *dev)
 #ifdef CONFIG_DM_ETH_PHY
 	eth_phy_binds_nodes(dev);
 #endif
+	if (CONFIG_IS_ENABLED(BOOTDEV_ETH)) {
+		ret = bootdev_setup_for_dev(dev, "eth_bootdev");
+		if (ret)
+			return log_msg_ret("bootdev", ret);
+	}
 
 	return 0;
 }
net/eth_bootdev.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#22 lore raw

PATCH v5 23/34 bootstd: Add an implementation of distro PXE boot

In reply to Simon Glass

Add a bootmeth driver which handles distro boot from a network device, so we can boot a bootflow using this commonly used mechanism.

In effect, this provides the same functionality as the 'pxe' command and shares the same code. But the interface into it is via a bootmeth.

For now this requires the 'pxe' command be enabled. Future work may tidy this up so that it can be used without CONFIG_CMDLINE being enabled.

---

(no changes since v3)

Changes in v3:
- Add a log category
- Use a short name when BOOTSTD_FULL is not enabled

 boot/Kconfig        |  10 +++
 boot/Makefile       |   1 +
 boot/bootmeth_pxe.c | 186 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 197 insertions(+)
 create mode 100644 boot/bootmeth_pxe.c
boot/Kconfig +10 -0
index d34c31303dc..9e02a7549af 100644
@@ -339,6 +339,16 @@ config BOOTMETH_DISTRO
 
 	  This provides a way to try out standard boot on an existing boot flow.
 
+config BOOTMETH_DISTRO_PXE
+	bool "Bootdev support for distro boot over network"
+	depends on CMD_PXE && CMD_NET && DM_ETH
+	default y
+	help
+	  Enables support for distro boot using bootdevs. This makes the
+	  bootdevs look for a 'extlinux/extlinux.conf' on the tftp server.
+
+	  This provides a way to try out standard boot on an existing boot flow.
+
 endif
 
 config LEGACY_IMAGE_FORMAT
boot/Makefile +1 -0
index 6b7014b41ac..9c9613d22a1 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
boot/bootmeth_pxe.c new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#23 lore raw

PATCH v5 24/34 bootstd: Add an implementation of EFI boot

In reply to Simon Glass

Add a bootmeth driver which handles EFI boot, using EFI_LOADER.

In effect, this provides the same functionality as the 'bootefi' command and shares the same code. But the interface into it is via a bootmeth, so it does not require any special scripts, etc.

For now this requires the 'bootefi' command be enabled. Future work may tidy this up so that it can be used without CONFIG_CMDLINE being enabled.

There was much discussion about whether this is needed, but it seems that it is, at least for now.

---

(no changes since v4)

Changes in v4:
- Allow use without a block device
- Fix 'a' typo
- Improve debugging in efiload_read_file()

Changes in v3:
- Add a log category
- Align the EFI load address
- Use a short name when BOOTSTD_FULL is not enabled
- Use common bootmeth functions

 boot/Kconfig        |  21 +++++
 boot/Makefile       |   1 +
 boot/bootmeth_efi.c | 188 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 210 insertions(+)
 create mode 100644 boot/bootmeth_efi.c
boot/Kconfig +21 -0
index 9e02a7549af..0bfea2791da 100644
@@ -349,6 +349,27 @@ config BOOTMETH_DISTRO_PXE
 
 	  This provides a way to try out standard boot on an existing boot flow.
 
+config BOOTMETH_EFILOADER
+	bool "Bootdev support for EFI boot"
+	depends on CMD_BOOTEFI
+	default y
+	help
+	  Enables support for EFI boot using bootdevs. This makes the
+	  bootdevs look for a 'boot<arch>.efi' on each filesystem
+	  they scan. The resulting file is booted after enabling U-Boot's
+	  EFI loader support.
+
+	  The <arch> depends on the architecture of the board:
+
+	     aa64      - aarch64 (ARM 64-bit)
+	     arm       - ARM 32-bit
+	     ia32      - x86 32-bit
+	     x64       - x86 64-bit
+	     riscv32   - RISC-V 32-bit
+	     riscv64   - RISC-V 64-bit
+
+	  This provides a way to try out standard boot on an existing boot flow.
+
 endif
 
 config LEGACY_IMAGE_FORMAT
boot/Makefile +1 -0
index 9c9613d22a1..4f9267687fa 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
boot/bootmeth_efi.c new file +188 -0

188 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#24 lore raw

PATCH v5 26/34 bootstd: Add an implementation of EFI bootmgr

In reply to Simon Glass

Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.

In effect, this provides the same functionality as the 'bootefi bootmgr' command and shares the same code. But the interface into it is via a bootmeth, so it does not require any special scripts, etc.

For now this requires the 'bootefi' command be enabled. Future work may tidy this up so that it can be used without CONFIG_CMDLINE being enabled.

---

(no changes since v3)

Changes in v3:
- Add a log category

 boot/Makefile           |  3 ++
 boot/bootmeth_efi_mgr.c | 86 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 boot/bootmeth_efi_mgr.c
boot/Makefile +3 -0
index 7325dbc1dd6..fe221d7f441 100644
@@ -27,6 +27,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
+obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
+endif
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
boot/bootmeth_efi_mgr.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#25 lore raw

PATCH v5 27/34 bootstd: Add a sandbox bootmeth driver

In reply to Simon Glass

Add a bootmeth driver for sandbox, used for testing.

---

(no changes since v3)

Changes in v3:
- Add a log category

 boot/Kconfig            |  7 +++++
 boot/Makefile           |  1 +
 boot/bootmeth_sandbox.c | 69 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 boot/bootmeth_sandbox.c
boot/Kconfig +7 -0
index 0bfea2791da..373871c49a6 100644
@@ -370,6 +370,13 @@ config BOOTMETH_EFILOADER
 
 	  This provides a way to try out standard boot on an existing boot flow.
 
+config BOOTMETH_SANDBOX
+	def_bool y
+	depends on SANDBOX
+	help
+	  This is a sandbox bootmeth driver used for testing. It always returns
+	  -ENOTSUPP when attempting to boot.
+
 endif
 
 config LEGACY_IMAGE_FORMAT
boot/Makefile +1 -0
index fe221d7f441..444e6975f10 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
 obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
 endif
boot/bootmeth_sandbox.c new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#26 lore raw

PATCH v5 29/34 bootstd: Add an implementation of script boot

In reply to Simon Glass

Add a bootmeth driver which handles distro boot from a disk via a U-Boot script, so we can boot a bootflow using this commonly used mechanism. This is required by Armbian, for example.

---

(no changes since v4)

Changes in v4:
- Allow use without a block device

Changes in v3:
- Add support for script boot

 boot/Kconfig           |  11 ++++
 boot/Makefile          |   1 +
 boot/bootmeth_script.c | 139 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 boot/bootmeth_script.c
boot/Kconfig +11 -0
index 373871c49a6..64e16f3beba 100644
@@ -377,6 +377,17 @@ config BOOTMETH_SANDBOX
 	  This is a sandbox bootmeth driver used for testing. It always returns
 	  -ENOTSUPP when attempting to boot.
 
+config BOOTMETH_SCRIPT
+	bool "Bootdev support for U-Boot scripts"
+	default y if BOOTSTD_FULL
+	help
+	  Enables support for booting a distro via a U-Boot script. This makes
+	  the bootdevs look for a 'boot/boot.scr' file which can be used to
+	  boot the distro.
+
+	  This provides a way to try out standard boot on an existing boot flow.
+	  It is not enabled by default to save space.
+
 endif
 
 config LEGACY_IMAGE_FORMAT
boot/Makefile +1 -0
index 444e6975f10..a70674259c1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
 obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
 endif
boot/bootmeth_script.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#27 lore raw

PATCH v5 30/34 bootstd: usb: Add a bootdev driver

In reply to Simon Glass

Add a bootdev driver for USB host. It can use the distro boot mechanism to locate a file, or any other available bootmeth.

---

(no changes since v1)

 common/usb_storage.c           | 11 ++++++
 drivers/usb/host/Makefile      |  4 +++
 drivers/usb/host/usb_bootdev.c | 61 ++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 drivers/usb/host/usb_bootdev.c
common/usb_storage.c +11 -0
index 291728f37e0..eaa31374ef7 100644
@@ -34,6 +34,7 @@
 
 #include <common.h>
 #include <blk.h>
+#include <bootdev.h>
 #include <command.h>
 #include <dm.h>
 #include <errno.h>
@@ -243,6 +244,16 @@ static int usb_stor_probe_device(struct usb_device *udev)
 		ret = blk_probe_or_unbind(dev);
 		if (ret)
 			return ret;
+
+		ret = bootdev_setup_sibling_blk(dev, "usb_bootdev");
+		if (ret) {
+			int ret2;
+
+			ret2 = device_unbind(dev);
+			if (ret2)
+				return log_msg_ret("bootdev", ret2);
+			return log_msg_ret("bootdev", ret);
+		}
 	}
 #else
 	/* We don't have space to even probe if we hit the maximum */
drivers/usb/host/Makefile +4 -0
index a4472da9f18..7785b3744ef 100644
@@ -8,6 +8,10 @@ obj-y += usb-uclass.o
 obj-$(CONFIG_SANDBOX) += usb-sandbox.o
 endif
 
+ifdef CONFIG_$(SPL_TPL_)USB_STORAGE
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += usb_bootdev.o
+endif
+
 # ohci
 obj-$(CONFIG_USB_OHCI_NEW) += ohci-hcd.o
 obj-$(CONFIG_USB_ATMEL) += ohci-at91.o
drivers/usb/host/usb_bootdev.c new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#28 lore raw

PATCH v5 31/34 bootstd: Add tests for bootstd including all uclasses

In reply to Simon Glass

Add a set of combined tests for the bootdev, bootflow and bootmeth commands, along with associated functionality.

Expand the sandbox console-recording limit so that these can work.

These tests rely on a filesystem script which is not yet added to the Python tests. It is included here as a shell script.

---

(no changes since v4)

Changes in v4:
- Update tests for code changes

Changes in v3:
- Add tests for the "bootmeths" env var
- Update bootdev_test_order() for boot_targets env var
- Update tests for the new 'bootmeth order' syntax

 MAINTAINERS                        |   1 +
 arch/sandbox/dts/test.dts          |  18 ++
 configs/sandbox_defconfig          |   3 +-
 configs/sandbox_flattree_defconfig |   3 +-
 include/test/suites.h              |   2 +
 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 +
 13 files changed, 845 insertions(+), 2 deletions(-)
 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
MAINTAINERS +1 -0
index 77a34082249..963ec91c891 100644
@@ -708,6 +708,7 @@ F:	include/bootflow.h
 F:	include/bootmeth.h
 F:	include/bootstd.h
 F:	net/eth_bootdevice.c
+F:	test/boot/
 
 BTRFS
 M:	Marek Behun <[email protected]>
arch/sandbox/dts/test.dts +18 -0
index 5b38ee4a5f9..a8a86bc7155 100644
@@ -74,6 +74,21 @@
 		};
 	};
 
+	bootstd {
+		compatible = "u-boot,boot-std";
+
+		filename-prefixes = "/", "/boot/";
+		bootdev-order = "mmc2", "mmc1";
+
+		syslinux {
+			compatible = "u-boot,distro-syslinux";
+		};
+
+		efi {
+			compatible = "u-boot,distro-efi";
+		};
+	};
+
 	reboot-mode0 {
 		compatible = "reboot-mode-gpio";
 		gpios = <&gpio_c 0 GPIO_ACTIVE_HIGH>, <&gpio_c 1 GPIO_ACTIVE_HIGH>;
@@ -891,10 +906,13 @@
 		non-removable;
 	};
 
+	/* This is used for the bootdev tests */
 	mmc1 {
 		compatible = "sandbox,mmc";
+		filename = "mmc1.img";
 	};
 
+	/* This is used for the fastboot tests */
 	mmc0 {
 		compatible = "sandbox,mmc";
 	};
configs/sandbox_defconfig +2 -1
index 14d7af4db28..fe8ea4626d9 100644
@@ -28,7 +28,7 @@ CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=640000$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJ
 CONFIG_IMAGE_PRE_LOAD=y
 CONFIG_IMAGE_PRE_LOAD_SIG=y
 CONFIG_CONSOLE_RECORD=y
-CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
+CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_LOG=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
@@ -120,6 +120,7 @@ CONFIG_ENV_IS_IN_EXT4=y
 CONFIG_ENV_EXT4_INTERFACE="host"
 CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
 CONFIG_ENV_IMPORT_FDT=y
+# CONFIG_BOOTDEV_ETH is not set
 CONFIG_BOOTP_SEND_HOSTNAME=y
 CONFIG_NETCONSOLE=y
 CONFIG_IP_DEFRAG=y
configs/sandbox_flattree_defconfig +2 -1
index ded16af9f51..80a4be47eba 100644
@@ -17,7 +17,7 @@ CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
-CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
+CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
@@ -72,6 +72,7 @@ CONFIG_ENV_IS_NOWHERE=y
 CONFIG_ENV_IS_IN_EXT4=y
 CONFIG_ENV_EXT4_INTERFACE="host"
 CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
+# CONFIG_BOOTDEV_ETH is not set
 CONFIG_BOOTP_SEND_HOSTNAME=y
 CONFIG_NETCONSOLE=y
 CONFIG_IP_DEFRAG=y
include/test/suites.h +2 -0
index 6553a765c6a..ee6858a802a 100644
@@ -29,6 +29,8 @@ int cmd_ut_category(const char *name, const char *prefix,
 int do_ut_addrmap(struct cmd_tbl *cmdtp, int flag, int argc,
 		  char *const argv[]);
 int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc,
+		  char *const argv[]);
 int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc,
 		   char *const argv[]);
 int do_ut_common(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
test/Makefile +1 -0
index b3b2902e2e7..abd605a4351 100644
@@ -22,6 +22,7 @@ obj-$(CONFIG_UT_TIME) += time_ut.o
 obj-y += ut.o
 
 ifeq ($(CONFIG_SPL_BUILD),)
+obj-$(CONFIG_UNIT_TEST) += boot/
 obj-$(CONFIG_UNIT_TEST) += common/
 obj-$(CONFIG_UNIT_TEST) += lib/
 obj-y += log/
test/boot/Makefile new file +5 -0
new file mode 100644
index 00000000000..1730792b5fa
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright 2021 Google LLC
+
+obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
test/boot/bootdev.c new file +223 -0

223 lines not on this page · raw message

test/boot/bootflow.c new file +400 -0

400 lines not on this page · raw message

test/boot/bootmeth.c new file +122 -0

122 lines not on this page · raw message

test/boot/bootstd_common.c new file +35 -0
new file mode 100644
index 00000000000..05347d87106
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for bootdev functions. All start with 'bootdev'
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <bootstd.h>
+#include <dm.h>
+#include <test/suites.h>
+#include <test/ut.h>
+#include "bootstd_common.h"
+
+int bootstd_test_drop_bootdev_order(struct unit_test_state *uts)
+{
+	struct bootstd_priv *priv;
+	struct udevice *bootstd;
+
+	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+	priv = dev_get_priv(bootstd);
+	priv->bootdev_order = NULL;
+
+	return 0;
+}
+
+int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct unit_test *tests = UNIT_TEST_SUITE_START(bootstd_test);
+	const int n_ents = UNIT_TEST_SUITE_COUNT(bootstd_test);
+
+	return cmd_ut_category("bootstd", "bootstd_test_",
+			       tests, n_ents, argc, argv);
+}
test/boot/bootstd_common.h new file +27 -0
new file mode 100644
index 00000000000..676ef0a57f9
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Common header file for bootdev, bootflow, bootmeth tests
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __bootstd_common_h
+#define __bootstd_common_h
+
+/* Declare a new bootdev test */
+#define BOOTSTD_TEST(_name, _flags) \
+		UNIT_TEST(_name, _flags, bootstd_test)
+
+struct unit_test_state;
+
+/**
+ * bootstd_test_drop_bootdev_order() - Remove the existing boot order
+ *
+ * Drop the boot order so that all bootdevs are used in their alias order
+ *
+ * @uts: Unit test state to use for ut_assert...() functions
+ */
+int bootstd_test_drop_bootdev_order(struct unit_test_state *uts);
+
+#endif
test/cmd_ut.c +7 -0
index 90b260f72d6..67a13ee32b8 100644
@@ -28,6 +28,10 @@ int cmd_ut_category(const char *name, const char *prefix,
 
 static struct cmd_tbl cmd_ut_sub[] = {
 	U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
+#ifdef CONFIG_BOOTSTD
+	U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
+			 "", ""),
+#endif
 	U_BOOT_CMD_MKENT(common, CONFIG_SYS_MAXARGS, 1, do_ut_common, "", ""),
 #if defined(CONFIG_UT_DM)
 	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
@@ -115,6 +119,9 @@ static char ut_help_text[] =
 	"ut bloblist - Test bloblist implementation\n"
 	"ut compression - Test compressors and bootm decompression\n"
 #endif
+#ifdef CONFIG_BOOTSTD
+	"ut bootstd - Test standard boot implementation\n"
+#endif
 #ifdef CONFIG_UT_DM
 	"ut dm [test-name]\n"
 #endif
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#29 lore raw

PATCH v5 32/34 bootstd: Add setup for the bootflow tests

In reply to Simon Glass

We need to create a disk image with a partition table and a DOS-format filesystem containing a few files. Provide a fallback binary for CI since it does not seem able to detect the loopback partitions.

Add this to a dm_init test so that it happens when needed.

---

(no changes since v3)

Changes in v3:
- Update test condition to use CMD_BOOTFLOW

 test/py/tests/bootstd/mmc1.img.xz | Bin 0 -> 4448 bytes
 test/py/tests/test_ut.py          | 103 ++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100644 test/py/tests/bootstd/mmc1.img.xz
test/py/tests/bootstd/mmc1.img.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4e7f39b830eb4bddcb9ff6df39e89f130b5706b9
GIT binary patch
test/py/tests/test_ut.py +103 -0

118 lines not on this page · raw message

Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#30 lore raw

Re: [PATCH v5 32/34] bootstd: Add setup for the bootflow tests

Quoted 88 lines · Simon Glass

We need to create a disk image with a partition table and a DOS-format filesystem containing a few files. Provide a fallback binary for CI since it does not seem able to detect the loopback partitions.

Add this to a dm_init test so that it happens when needed.

---

(no changes since v3)

Changes in v3:
- Update test condition to use CMD_BOOTFLOW

  test/py/tests/bootstd/mmc1.img.xz | Bin 0 -> 4448 bytes
  test/py/tests/test_ut.py          | 103 ++++++++++++++++++++++++++++++
  2 files changed, 103 insertions(+)

create mode 100644 test/py/tests/bootstd/mmc1.img.xz

test/py/tests/bootstd/mmc1.img.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4e7f39b830eb4bddcb9ff6df39e89f130b5706b9
GIT binary patch
test/py/tests/test_ut.py +13 -0
index 01c2b3ffa12..35fb393c1ff 100644
@@ -1,9 +1,102 @@
  # SPDX-License-Identifier: GPL-2.0
  # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 
+import gzip
+import os
  import os.path
  import pytest
 
+import u_boot_utils
+
+def mkdir_cond(dirname):
+    """Create a directory if it doesn't already exist
+
+    Args:
+        dirname: Name of directory to create
+    """
+    if not os.path.exists(dirname):
+        os.mkdir(dirname)
+

test/py/tests/test_ut.py line 29

Quoted 10 lines
test/py/tests/test_ut.py +10 -0
+def setup_bootflow_image(u_boot_console):
+    """Create a 20MB disk image with a single FAT partition"""
+    cons = u_boot_console
+    fname = os.path.join(cons.config.source_dir, 'mmc1.img')
+    mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
+    mkdir_cond(mnt)
+
+    u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
+    u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname,
+                             stdin=b'type=c')

We should never request to run a test as sudo.

Please, change this test to use virt-make-fs like we do in all other tests that create an image.

Best regards

Heinrich

Quoted 90 lines
test/py/tests/test_ut.py +80 -0
+
+    loop = None
+    mounted = False
+    complete = False
+    try:
+        out = u_boot_utils.run_and_log(cons,
+                                       'sudo losetup --show -f -P %s' % fname)
+        loop = out.strip()
+        fatpart = '%sp1' % loop
+        u_boot_utils.run_and_log(cons, 'sudo mkfs.vfat %s' % fatpart)
+        u_boot_utils.run_and_log(
+            cons, 'sudo mount -o loop %s %s -o uid=%d,gid=%d' %
+            (fatpart, mnt, os.getuid(), os.getgid()))
+        mounted = True
+
+        vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
+        initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
+        dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
+        script = '''# extlinux.conf generated by appliance-creator
+ui menu.c32
+menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options.
+menu title Fedora-Workstation-armhfp-31-1.9 Boot Options.
+menu hidden
+timeout 20
+totaltimeout 600
+
+label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
+        kernel /%s
+        append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB
+        fdtdir /%s/
+        initrd /%s''' % (vmlinux, dtbdir, initrd)
+        ext = os.path.join(mnt, 'extlinux')
+        mkdir_cond(ext)
+
+        with open(os.path.join(ext, 'extlinux.conf'), 'w') as fd:
+            print(script, file=fd)
+
+        inf = os.path.join(cons.config.persistent_data_dir, 'inf')
+        with open(inf, 'wb') as fd:
+            fd.write(gzip.compress(b'vmlinux'))
+        u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
+                                 (inf, os.path.join(mnt, vmlinux)))
+
+        with open(os.path.join(mnt, initrd), 'w') as fd:
+            print('initrd', file=fd)
+
+        mkdir_cond(os.path.join(mnt, dtbdir))
+
+        dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir)
+        u_boot_utils.run_and_log(
+            cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};')
+        complete = True
+    except ValueError as exc:
+        print('Falled to create image, failing back to prepared copy: %s',
+              str(exc))
+    finally:
+        if mounted:
+            u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt)
+        if loop:
+            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+
+    if not complete:
+        # Use a prepared image since we cannot create one
+        infname = os.path.join(cons.config.source_dir,
+                               'test/py/tests/bootstd/mmc1.img.xz')
+        u_boot_utils.run_and_log(
+            cons,
+            ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)])
+
+
  @pytest.mark.buildconfigspec('ut_dm')
  def test_ut_dm_init(u_boot_console):
      """Initialize data for ut dm tests."""
@@ -21,6 +114,16 @@ def test_ut_dm_init(u_boot_console):
          with open(fn, 'wb') as fh:
              fh.write(data)
 
[email protected]('cmd_bootflow')
+def test_ut_dm_init_bootstd(u_boot_console):
+    """Initialise data for bootflow tests"""
+
+    setup_bootflow_image(u_boot_console)
+
+    # Restart so that the new mmc1.img is picked up
+    u_boot_console.restart_uboot()
+
+
  def test_ut(u_boot_console, ut_subtest):
      """Execute a "ut" subtest.
 
#31 lore raw

PATCH v5 33/34 bootstd: doc: Add documentation

In reply to Simon Glass

Add documentation for this feature, including the commands and full devicetree bindings.

---

Changes in v5:
- Add a Kconfig to select bootstd by default
- Rebase to master

Changes in v4:
- Update docs for typos that have been fixed

Changes in v3:
- Update docs for "bootmeths" and "boot_targets" env vars

 MAINTAINERS                           |   4 +
 doc/develop/bootstd.rst               | 638 ++++++++++++++++++++++++++
 doc/develop/distro.rst                |   3 +
 doc/develop/index.rst                 |   1 +
 doc/device-tree-bindings/bootdev.txt  |  18 +
 doc/device-tree-bindings/bootmeth.txt |  31 ++
 doc/device-tree-bindings/bootstd.txt  |   8 +
 doc/usage/cmd/bootdev.rst             | 135 ++++++
 doc/usage/cmd/bootflow.rst            | 427 +++++++++++++++++
 doc/usage/cmd/bootmeth.rst            | 108 +++++
 doc/usage/index.rst                   |   3 +
 11 files changed, 1376 insertions(+)
 create mode 100644 doc/develop/bootstd.rst
 create mode 100644 doc/device-tree-bindings/bootmeth.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
MAINTAINERS +4 -0
index 963ec91c891..bda7b81efc5 100644
@@ -702,6 +702,10 @@ F:	boot/bootmeth*.c
 F:	boot/bootstd.c
 F:	cmd/bootdev.c
 F:	cmd/bootflow.c
+F:	doc/develop/bootstd.rst
+F:	doc/usage/bootdev.rst
+F:	doc/usage/bootflow.rst
+F:	doc/usage/bootmeth.rst
 F:	drivers/mmc/mmc_bootdev.c
 F:	include/bootdev.h
 F:	include/bootflow.h
doc/develop/bootstd.rst new file +638 -0

638 lines not on this page · raw message

doc/develop/distro.rst +3 -0
index 0113a3d4ec4..3ee3dac6a27 100644
@@ -157,6 +157,9 @@ a line with "CONFIG_DISTRO_DEFAULTS=y". If you want to enable this
 from Kconfig itself, for e.g. all boards using a specific SoC then
 add a "imply DISTRO_DEFAULTS" to your SoC CONFIG option.
 
+
+TO BE UPDATED:
+
 In your board configuration file, include the following::
 
     #ifndef CONFIG_SPL_BUILD
doc/develop/index.rst +1 -0
index 2e6d6c302a5..d32ec490221 100644
@@ -10,6 +10,7 @@ Implementation
    :maxdepth: 1
 
    bloblist
+   bootstd
    ci_testing
    commands
    config_binding
doc/device-tree-bindings/bootdev.txt +18 -0
index 95b7fec8212..4bb2345a0b9 100644
@@ -6,3 +6,21 @@ child of the media device (UCLASS_MMC, UCLASS_SPI_FLASH, etc.)
 
 The bootdev driver is provided by the media devices. The bindings for each
 are described in this file (to come).
+
+Required properties:
+
+compatible:
+   "u-boot,bootdev-eth" - Ethernet bootdev
+   "u-boot,bootdev-mmc" - MMC bootdev
+   "u-boot,bootdev-usb" - USB bootdev
+
+
+Example:
+
+	mmc1 {
+		compatible = "sandbox,mmc";
+
+		mmc-bootdev {
+			compatible = "u-boot,bootdev-eth";
+		};
+	};
doc/device-tree-bindings/bootmeth.txt new file +31 -0
new file mode 100644
index 00000000000..de6396a7b35
@@ -0,0 +1,31 @@
+U-Boot standard boot methods (bootmeth)
+======================================
+
+This provides methods (called bootmeths) for locating bootflows on a boot
+device (bootdev). These are normally created as children of the bootstd device.
+
+Required properties:
+
+compatible:
+   "u-boot,distro-syslinux" - distro boot from a block device
+   "u-boot,distro-pxe" - distro boot from a network device
+   "u-boot,distro-efi" - EFI boot from an .efi file
+   "u-boot,efi-bootmgr" - EFI boot using boot manager (bootmgr)
+
+
+Example:
+
+	bootstd {
+		compatible = "u-boot,boot-std";
+
+		filename-prefixes = "/", "/boot/";
+		bootdev-order = "mmc2", "mmc1";
+
+		syslinux {
+			compatible = "u-boot,distro-syslinux";
+		};
+
+		efi {
+			compatible = "u-boot,distro-efi";
+		};
+	};
doc/device-tree-bindings/bootstd.txt +8 -0
index f048b9dd327..8706c5f4993 100644
@@ -25,4 +25,12 @@ Example:
 
 		filename-prefixes = "/", "/boot/";
 		bootdev-order = "mmc2", "mmc1";
+
+		syslinux {
+			compatible = "u-boot,distro-syslinux";
+		};
+
+		efi {
+			compatible = "u-boot,distro-efi";
+		};
 	};
doc/usage/cmd/bootdev.rst new file +135 -0

135 lines not on this page · raw message

doc/usage/cmd/bootflow.rst new file +427 -0

427 lines not on this page · raw message

doc/usage/cmd/bootmeth.rst new file +108 -0

108 lines not on this page · raw message

doc/usage/index.rst +3 -0
index f343e4e05f7..c03f4aef9eb 100644
@@ -23,9 +23,12 @@ Shell commands
    cmd/addrmap
    cmd/askenv
    cmd/base
+   cmd/bootdev
    cmd/bootefi
+   cmd/bootflow
    cmd/booti
    cmd/bootmenu
+   cmd/bootmeth
    cmd/button
    cmd/cbsysinfo
    cmd/conitrace
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#32 lore raw

PATCH v5 34/34 bootstd: Provide a default command

In reply to Simon Glass

We would like to use bootstd by default when EFI boot manager is not enabled. But so far bootstd does not support all the of distro-boot fetures. So for now, add an option to select this.

---

(no changes since v1)

 boot/Kconfig | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/Kconfig +16 -1
index 64e16f3beba..4b0802b8c6e 100644
@@ -328,6 +328,19 @@ config BOOTSTD_FULL
 
 if BOOTSTD
 
+config BOOTSTD_BOOTCOMMAND
+	bool "Use bootstd to boot"
+	default y if !DISTRO_DEFAULTS
+	help
+	  Enable this to select a default boot-command suitable for booting
+	  with standard boot. This can be overridden by the board if needed,
+	  but the default command should be enough for most boards which use
+	  standard boot.
+
+	  For now this is only selected if distro boot is NOT used, since
+	  standard boot does not support all of the features of distro boot
+	  yet.
+
 config BOOTMETH_DISTRO
 	bool "Bootdev support for distro boot"
 	depends on CMD_PXE
@@ -1260,7 +1273,9 @@ config USE_BOOTCOMMAND
 config BOOTCOMMAND
 	string "bootcmd value"
 	depends on USE_BOOTCOMMAND && !USE_DEFAULT_ENV_FILE
-	default "run distro_bootcmd" if DISTRO_DEFAULTS
+	default "bootflow scan -lb" if BOOTSTD_BOOTCOMMAND && CMD_BOOTFLOW_FULL
+	default "bootflow scan" if BOOTSTD_BOOTCOMMAND && !CMD_BOOTFLOW_FULL
+	default "run distro_bootcmd" if !BOOTSTD_BOOTCOMMAND && DISTRO_DEFAULTS
 	help
 	  This is the string of commands that will be used as bootcmd and if
 	  AUTOBOOT is set, automatically run.
Signature · 1 line
2.36.0.rc2.479.g8af0fa9b8e-goog
#33 lore raw
In reply to Simon Glass
Quoted 9 lines · Simon Glass

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

Quoted 8 lines
                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.

I've put most of this cover letter in the merge commit, and applied this to u-boot/master. This is an incremental starting point at providing a alternative way of constructing and controlling the load and execute OS stage of booting. There is some growth on most platforms for this, but it is a reasonable alternative and will be iterated on.

Signature · 1 line
Tom
#34 lore raw
Quoted 18 lines
Quoted 9 lines

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

Quoted 8 lines
                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.

Quoted 5 lines

I've put most of this cover letter in the merge commit, and applied this to u-boot/master. This is an incremental starting point at providing a alternative way of constructing and controlling the load and execute OS stage of booting. There is some growth on most platforms for this, but it is a reasonable alternative and will be iterated on.

I'm guessing this would allow us to optionally disable hush and associated pieces for a lot of the boards which may equal it out?

#35 lore raw
Quoted 18 lines · Peter Robinson
Quoted 18 lines
Quoted 17 lines

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.

Quoted 8 lines
Quoted 5 lines

I've put most of this cover letter in the merge commit, and applied this to u-boot/master. This is an incremental starting point at providing a alternative way of constructing and controlling the load and execute OS stage of booting. There is some growth on most platforms for this, but it is a reasonable alternative and will be iterated on.

I'm guessing this would allow us to optionally disable hush and associated pieces for a lot of the boards which may equal it out?

Long term, we'll see what makes the most sense for everyone as a reasonable set of defaults. I also think that high level, there'll be places to optimize this for overall size down the line.

Signature · 1 line
Tom