Skip to contentSkip to conversation

Initial implementation of bootmethod/bootflow

PATCH Superseded Simon Glass 7 participants 60 messages Aug 19, 2021 – Aug 26, 2021

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Initial implementation of bootmethod/bootflow

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Simon Glass (28):
Create a new boot/ directory
pxe: Move API comments to the header files
pxe: Use a context pointer
pxe: Move do_getfile() into the context
pxe: Add a userdata field to the context
pxe: Tidy up the is_pxe global
pxe: Move pxe_utils files
pxe: Tidy up some comments in pxe_utils
pxe: Tidy up code style a little in pxe_utils
pxe: Move common parsing coding into pxe_util
pxe: Clean up the use of bootfile
pxe: Drop get_bootfile_path()
lib: Add tests for simple_itoa()
lib: Add a function to convert a string to a hex value
pxe: Return the file size from the getfile() function
pxe: Refactor sysboot to have one helper
doc: Move distro boot doc to rST
pxe: Allow calling the pxe_get logic directly
bootmethod: Add the uclass and core implementation
bootmethod: Add an implementation of distro boot
bootmethod: Add a command
bootflow: Add a command
bootmethod: Add tests for bootmethod and bootflow
bootmethod: doc: Add documentation
mmc: Allow for children other than the block device
mmc: Add a bootmethod
ethernet: Add a bootmethod
RFC: rpi: Switch over to use bootflow

 Kconfig                                   |   2 +
 MAINTAINERS                               |  16 +
 Makefile                                  |   3 +-
 README                                    |   1 +
 common/Kconfig.boot => boot/Kconfig       |  22 +-
 boot/Makefile                             |  39 ++
 {common => boot}/android_ab.c             |   0
 {common => boot}/boot_fit.c               |   0
 {common => boot}/bootm.c                  |   0
 {common => boot}/bootm_os.c               |   0
 boot/bootmethod.c                         | 485 ++++++++++++++++++++
 {common => boot}/bootretry.c              |   0
 {common => boot}/common_fit.c             |   0
 boot/distro.c                             | 194 ++++++++
 {common => boot}/fdt_region.c             |   0
 {common => boot}/image-android-dt.c       |   0
 {common => boot}/image-android.c          |   0
 {common => boot}/image-cipher.c           |   0
 {common => boot}/image-fdt.c              |   0
 {common => boot}/image-fit-sig.c          |   0
 {common => boot}/image-fit.c              |   0
 {common => boot}/image-sig.c              |   0
 {common => boot}/image.c                  |   0
 {cmd => boot}/pxe_utils.c                 | 512 +++++++++++-----------
 cmd/Kconfig                               |   8 +
 cmd/Makefile                              |   5 +-
 cmd/bootflow.c                            | 399 +++++++++++++++++
 cmd/bootmethod.c                          | 130 ++++++
 cmd/pxe.c                                 | 136 +++---
 cmd/pxe_utils.h                           |  91 ----
 cmd/sysboot.c                             | 114 +++--
 common/Kconfig                            |   2 -
 common/Makefile                           |  22 -
 configs/sandbox_defconfig                 |   3 +-
 doc/android/boot-image.rst                |   2 +-
 doc/develop/bootflow.rst                  | 323 ++++++++++++++
 doc/{README.distro => develop/distro.rst} | 180 ++++----
 doc/develop/index.rst                     |   2 +
 doc/device-tree-bindings/bootmethod.txt   |  14 +
 doc/usage/bootflow.rst                    | 419 ++++++++++++++++++
 doc/usage/bootmethod.rst                  | 138 ++++++
 doc/usage/index.rst                       |   2 +
 drivers/mmc/Makefile                      |   5 +
 drivers/mmc/mmc-uclass.c                  |  23 +-
 drivers/mmc/mmc_bootmethod.c              |  46 ++
 include/bootmethod.h                      | 357 +++++++++++++++
 include/configs/rpi.h                     |  37 +-
 include/distro.h                          |  62 +++
 include/dm/uclass-id.h                    |   1 +
 include/mmc.h                             |  12 +-
 include/pxe_utils.h                       | 253 +++++++++++
 include/test/suites.h                     |   2 +
 include/vsprintf.h                        |  25 +-
 lib/vsprintf.c                            |  20 +-
 net/Kconfig                               |   9 +
 net/Makefile                              |   1 +
 net/eth-uclass.c                          |   8 +
 net/eth_bootmethod.c                      |  76 ++++
 scripts/Makefile.spl                      |   4 +-
 test/Makefile                             |   1 +
 test/boot/Makefile                        |   5 +
 test/boot/bootmethod.c                    | 271 ++++++++++++
 test/cmd_ut.c                             |   4 +
 test/print_ut.c                           |  33 ++
 tools/Makefile                            |  16 +-
 try.sh                                    | 131 ++++++
 66 files changed, 4035 insertions(+), 631 deletions(-)
 rename common/Kconfig.boot => boot/Kconfig (98%)
 create mode 100644 boot/Makefile
 rename {common => boot}/android_ab.c (100%)
 rename {common => boot}/boot_fit.c (100%)
 rename {common => boot}/bootm.c (100%)
 rename {common => boot}/bootm_os.c (100%)
 create mode 100644 boot/bootmethod.c
 rename {common => boot}/bootretry.c (100%)
 rename {common => boot}/common_fit.c (100%)
 create mode 100644 boot/distro.c
 rename {common => boot}/fdt_region.c (100%)
 rename {common => boot}/image-android-dt.c (100%)
 rename {common => boot}/image-android.c (100%)
 rename {common => boot}/image-cipher.c (100%)
 rename {common => boot}/image-fdt.c (100%)
 rename {common => boot}/image-fit-sig.c (100%)
 rename {common => boot}/image-fit.c (100%)
 rename {common => boot}/image-sig.c (100%)
 rename {common => boot}/image.c (100%)
 rename {cmd => boot}/pxe_utils.c (74%)
 create mode 100644 cmd/bootflow.c
 create mode 100644 cmd/bootmethod.c
 delete mode 100644 cmd/pxe_utils.h
 create mode 100644 doc/develop/bootflow.rst
 rename doc/{README.distro => develop/distro.rst} (76%)
 create mode 100644 doc/device-tree-bindings/bootmethod.txt
 create mode 100644 doc/usage/bootflow.rst
 create mode 100644 doc/usage/bootmethod.rst
 create mode 100644 drivers/mmc/mmc_bootmethod.c
 create mode 100644 include/bootmethod.h
 create mode 100644 include/distro.h
 create mode 100644 include/pxe_utils.h
 create mode 100644 net/eth_bootmethod.c
 create mode 100644 test/boot/Makefile
 create mode 100644 test/boot/bootmethod.c
 create mode 100755 try.sh
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#1 lore raw

PATCH 1/28 Create a new boot/ directory

Quite a lot of the code in common/relates to booting and images. Before adding more it seems like a good time to move the code into its own directory.

Most files with 'boot' or 'image' in them are moved, except:

- autoboot.c which relates to U-Boot automatically running a script
- bootstage.c which relates to U-Boot timing

Drop the removal of boot* files from the output directory, since this interfers with the symlinks created by tools and there does not appear to be any such file from my brief testing.

---

 Kconfig                             |  2 ++
 Makefile                            |  3 ++-
 README                              |  1 +
 common/Kconfig.boot => boot/Kconfig |  0
 boot/Makefile                       | 34 +++++++++++++++++++++++++++++
 {common => boot}/android_ab.c       |  0
 {common => boot}/boot_fit.c         |  0
 {common => boot}/bootm.c            |  0
 {common => boot}/bootm_os.c         |  0
 {common => boot}/bootretry.c        |  0
 {common => boot}/common_fit.c       |  0
 {common => boot}/fdt_region.c       |  0
 {common => boot}/image-android-dt.c |  0
 {common => boot}/image-android.c    |  0
 {common => boot}/image-cipher.c     |  0
 {common => boot}/image-fdt.c        |  0
 {common => boot}/image-fit-sig.c    |  0
 {common => boot}/image-fit.c        |  0
 {common => boot}/image-sig.c        |  0
 {common => boot}/image.c            |  0
 common/Kconfig                      |  2 --
 common/Makefile                     | 22 -------------------
 doc/android/boot-image.rst          |  2 +-
 scripts/Makefile.spl                |  4 ++--
 tools/Makefile                      | 16 +++++++-------
 25 files changed, 50 insertions(+), 36 deletions(-)
 rename common/Kconfig.boot => boot/Kconfig (100%)
 create mode 100644 boot/Makefile
 rename {common => boot}/android_ab.c (100%)
 rename {common => boot}/boot_fit.c (100%)
 rename {common => boot}/bootm.c (100%)
 rename {common => boot}/bootm_os.c (100%)
 rename {common => boot}/bootretry.c (100%)
 rename {common => boot}/common_fit.c (100%)
 rename {common => boot}/fdt_region.c (100%)
 rename {common => boot}/image-android-dt.c (100%)
 rename {common => boot}/image-android.c (100%)
 rename {common => boot}/image-cipher.c (100%)
 rename {common => boot}/image-fdt.c (100%)
 rename {common => boot}/image-fit-sig.c (100%)
 rename {common => boot}/image-fit.c (100%)
 rename {common => boot}/image-sig.c (100%)
 rename {common => boot}/image.c (100%)
Kconfig +2 -0
index a6c42b902f7..56ae57930f3 100644
@@ -455,6 +455,8 @@ endmenu		# General setup
 
 source "api/Kconfig"
 
+source "boot/Kconfig"
+
 source "common/Kconfig"
 
 source "cmd/Kconfig"
Makefile +2 -1
index 3c8437d21af..3a50ad2188e 100644
@@ -804,6 +804,7 @@ HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makef
 
 libs-$(CONFIG_API) += api/
 libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
+libs-y += boot/
 libs-y += cmd/
 libs-y += common/
 libs-$(CONFIG_OF_EMBED) += dts/
@@ -2092,7 +2093,7 @@ CLEAN_DIRS  += $(MODVERDIR) \
 			$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
 
 CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \
-	       boot* u-boot* MLO* SPL System.map fit-dtb.blob* \
+	       u-boot* MLO* SPL System.map fit-dtb.blob* \
 	       u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
 	       lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
 	       idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
README +1 -0
index 1c1db980987..1a74616d60e 100644
@@ -144,6 +144,7 @@ Directory Hierarchy:
   /xtensa		Files generic to Xtensa architecture
 /api			Machine/arch-independent API for external apps
 /board			Board-dependent files
+/boot			Support for images and booting
 /cmd			U-Boot commands functions
 /common			Misc architecture-independent functions
 /configs		Board default configuration files
boot/Kconfig renamed from common/Kconfig.boot +0 -0
similarity index 100%
rename from common/Kconfig.boot
rename to boot/Kconfig
boot/Makefile new file +34 -0
new file mode 100644
index 00000000000..57d26346afb
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2004-2006
+# Wolfgang Denk, DENX Software Engineering, [email protected].
+
+ifndef CONFIG_SPL_BUILD
+
+# This option is not just y/n - it can have a numeric value
+ifdef CONFIG_BOOT_RETRY_TIME
+obj-y += bootretry.o
+endif
+
+obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
+obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o
+obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
+
+endif
+
+obj-y += image.o
+obj-$(CONFIG_ANDROID_AB) += android_ab.o
+obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.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
+obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
+obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o
+obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o
+obj-$(CONFIG_$(SPL_TPL_)FIT_CIPHER) += image-cipher.o
+
+obj-$(CONFIG_CMD_ADTIMG) += image-android-dt.o
+
+ifdef CONFIG_SPL_BUILD
+obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
+endif
boot/android_ab.c renamed from common/android_ab.c +0 -0
similarity index 100%
rename from common/android_ab.c
rename to boot/android_ab.c
boot/boot_fit.c renamed from common/boot_fit.c +0 -0
similarity index 100%
rename from common/boot_fit.c
rename to boot/boot_fit.c
boot/bootm.c renamed from common/bootm.c +0 -0
similarity index 100%
rename from common/bootm.c
rename to boot/bootm.c
boot/bootm_os.c renamed from common/bootm_os.c +0 -0
similarity index 100%
rename from common/bootm_os.c
rename to boot/bootm_os.c
boot/bootretry.c renamed from common/bootretry.c +0 -0
similarity index 100%
rename from common/bootretry.c
rename to boot/bootretry.c
boot/common_fit.c renamed from common/common_fit.c +0 -0
similarity index 100%
rename from common/common_fit.c
rename to boot/common_fit.c
boot/fdt_region.c renamed from common/fdt_region.c +0 -0
similarity index 100%
rename from common/fdt_region.c
rename to boot/fdt_region.c
boot/image-android-dt.c renamed from common/image-android-dt.c +0 -0
similarity index 100%
rename from common/image-android-dt.c
rename to boot/image-android-dt.c
boot/image-android.c renamed from common/image-android.c +0 -0
similarity index 100%
rename from common/image-android.c
rename to boot/image-android.c
boot/image-cipher.c renamed from common/image-cipher.c +0 -0
similarity index 100%
rename from common/image-cipher.c
rename to boot/image-cipher.c
boot/image-fdt.c renamed from common/image-fdt.c +0 -0
similarity index 100%
rename from common/image-fdt.c
rename to boot/image-fdt.c
boot/image-fit-sig.c renamed from common/image-fit-sig.c +0 -0
similarity index 100%
rename from common/image-fit-sig.c
rename to boot/image-fit-sig.c
boot/image-fit.c renamed from common/image-fit.c +0 -0
similarity index 100%
rename from common/image-fit.c
rename to boot/image-fit.c
boot/image-sig.c renamed from common/image-sig.c +0 -0
similarity index 100%
rename from common/image-sig.c
rename to boot/image-sig.c
boot/image.c renamed from common/image.c +0 -0
similarity index 100%
rename from common/image.c
rename to boot/image.c
common/Kconfig +0 -2
index 2ab20a6c85b..f8afa2ceff1 100644
@@ -1,5 +1,3 @@
-source "common/Kconfig.boot"
-
 menu "Console"
 
 config MENU
common/Makefile +0 -22
index 9063ed93910..de993700dd5 100644
@@ -12,21 +12,12 @@ obj-$(CONFIG_HASH) += hash.o
 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 
-# This option is not just y/n - it can have a numeric value
-ifdef CONFIG_BOOT_RETRY_TIME
-obj-y += bootretry.o
-endif
-
 # # boards
 obj-y += board_f.o
 obj-y += board_r.o
 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
 
-obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
-obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o
-obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
-
 obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o
 obj-$(CONFIG_MII) += miiphyutil.o
@@ -68,7 +59,6 @@ obj-$(CONFIG_DFU_OVER_USB) += dfu.o
 endif
 obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o
 obj-$(CONFIG_TPL_HASH_SUPPORT) += hash.o
-obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o
 
@@ -104,22 +94,10 @@ obj-y += malloc_simple.o
 endif
 endif
 
-obj-y += image.o
-obj-$(CONFIG_ANDROID_AB) += android_ab.o
-obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.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
-obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
-obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o
-obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o
-obj-$(CONFIG_$(SPL_TPL_)FIT_CIPHER) += image-cipher.o
 obj-$(CONFIG_IO_TRACE) += iotrace.o
 obj-y += memsize.o
 obj-y += stdio.o
 
-obj-$(CONFIG_CMD_ADTIMG) += image-android-dt.o
-
 ifdef CONFIG_CMD_EEPROM_LAYOUT
 obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
 endif
doc/android/boot-image.rst +1 -1
index fa8f2a47ee3..71db02521b0 100644
@@ -139,7 +139,7 @@ overview on the whole Android 10 boot process can be found at [8]_.
 C API for working with Android Boot Image format
 ------------------------------------------------
 
-.. kernel-doc:: common/image-android.c
+.. kernel-doc:: boot/image-android.c
    :internal:
 
 References
scripts/Makefile.spl +2 -2
index 25a3e7fa52e..f2a619e28a7 100644
@@ -92,10 +92,10 @@ libs-y += common/init/
 
 # Special handling for a few options which support SPL/TPL
 ifeq ($(CONFIG_TPL_BUILD),y)
-libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
+libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
 libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/
 else
-libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
+libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
 libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
 ifdef CONFIG_SPL_FRAMEWORK
 libs-$(CONFIG_PARTITIONS) += disk/
tools/Makefile +8 -8
index 4a86321f646..2cda7cdd75f 100644
@@ -76,9 +76,9 @@ hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign
 
 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
 
-FIT_OBJS-y := fit_common.o fit_image.o image-host.o common/image-fit.o
-FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o common/image-fit-sig.o
-FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := common/image-cipher.o
+FIT_OBJS-y := fit_common.o fit_image.o image-host.o boot/image-fit.o
+FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o boot/image-fit-sig.o
+FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := boot/image-cipher.o
 
 # The following files are synced with upstream DTC.
 # Use synced versions from scripts/dtc/libfdt/.
@@ -106,13 +106,13 @@ dumpimage-mkimage-objs := aisimage.o \
 			$(FIT_OBJS-y) \
 			$(FIT_SIG_OBJS-y) \
 			$(FIT_CIPHER_OBJS-y) \
-			common/fdt_region.o \
-			common/bootm.o \
+			boot/fdt_region.o \
+			boot/bootm.o \
 			lib/crc32.o \
 			default_image.o \
 			lib/fdtdec_common.o \
 			lib/fdtdec.o \
-			common/image.o \
+			boot/image.o \
 			imagetool.o \
 			imximage.o \
 			imx8image.o \
@@ -226,7 +226,7 @@ hostprogs-$(CONFIG_ARCH_OCTEON) += update_octeon_header
 update_octeon_header-objs := update_octeon_header.o lib/crc32.o
 
 hostprogs-y += fdtgrep
-fdtgrep-objs += $(LIBFDT_OBJS) common/fdt_region.o fdtgrep.o
+fdtgrep-objs += $(LIBFDT_OBJS) boot/fdt_region.o fdtgrep.o
 
 ifneq ($(TOOLS_ONLY),y)
 hostprogs-y += spl_size_limit
@@ -253,7 +253,7 @@ HOSTCFLAGS_sha512.o := -pedantic -DCONFIG_SHA512 -DCONFIG_SHA384
 quiet_cmd_wrap = WRAP    $@
 cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
 
-$(obj)/lib/%.c $(obj)/common/%.c $(obj)/env/%.c:
+$(obj)/boot/%.c $(obj)/common/%.c $(obj)/env/%.c $(obj)/lib/%.c:
 	$(call cmd,wrap)
 
 clean-dirs := lib common
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#2 lore raw

PATCH 2/28 pxe: Move API comments to the header files

In reply to Simon Glass

Put the function comments in the header file so that the full API can we examined in one place.

Expand the comments to cover parameters and return values.

---

 cmd/pxe_utils.c | 45 -----------------------------
 cmd/pxe_utils.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 74 insertions(+), 48 deletions(-)
cmd/pxe_utils.c +0 -45
index 067c24e5ff4..d7f4017efeb 100644
@@ -32,16 +32,6 @@
 
 bool is_pxe;
 
-/*
- * Convert an ethaddr from the environment to the format used by pxelinux
- * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
- * the beginning of the ethernet address to indicate a hardware type of
- * Ethernet. Also converts uppercase hex characters into lowercase, to match
- * pxelinux's behavior.
- *
- * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
- * environment, or some other value < 0 on error.
- */
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
 	uchar ethaddr[6];
@@ -146,13 +136,6 @@ static int get_relfile(struct cmd_tbl *cmdtp, const char *file_path,
 	return do_getfile(cmdtp, relfile, addr_buf);
 }
 
-/*
- * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
- * 'bootfile' was specified in the environment, the path to bootfile will be
- * prepended to 'file_path' and the resulting path will be used.
- *
- * Returns 1 on success, or < 0 for error.
- */
 int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
 		 unsigned long file_addr)
 {
@@ -187,13 +170,6 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
 
 #define PXELINUX_DIR "pxelinux.cfg/"
 
-/*
- * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
- * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
- * from the bootfile path, as described above.
- *
- * Returns 1 on success or < 0 on error.
- */
 int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
 		      unsigned long pxefile_addr_r)
 {
@@ -1309,15 +1285,6 @@ void destroy_pxe_menu(struct pxe_menu *cfg)
 	free(cfg);
 }
 
-/*
- * Entry point for parsing a pxe file. This is only used for the top level
- * file.
- *
- * Returns NULL if there is an error, otherwise, returns a pointer to a
- * pxe_menu struct populated with the results of parsing the pxe file (and any
- * files it includes). The resulting pxe_menu struct can be free()'d by using
- * the destroy_pxe_menu() function.
- */
 struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
 {
 	struct pxe_menu *cfg;
@@ -1415,18 +1382,6 @@ static void boot_unattempted_labels(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
 	}
 }
 
-/*
- * Boot the system as prescribed by a pxe_menu.
- *
- * Use the menu system to either get the user's choice or the default, based
- * on config or user input.  If there is no default or user's choice,
- * attempted to boot labels in the order they were given in pxe files.
- * If the default or user's choice fails to boot, attempt to boot other
- * labels in the order they were given in pxe files.
- *
- * If this function returns, there weren't any labels that successfully
- * booted, or the user interrupted the menu selection via ctrl+c.
- */
 void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
 {
 	void *choice;
cmd/pxe_utils.h +74 -3

86 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#3 lore raw

PATCH 3/28 pxe: Use a context pointer

In reply to Simon Glass

At present the PXE functions pass around a pointer to command-table entry which is very strange. It is only needed in a few places and it is odd to pass around a data structure from another module in this way.

For bootmethod we will need to provide some context information when reading files.

Create a PXE context struct to hold the command-table-entry pointer and pass that around instead. We can then add more things to the context as needed.

---

 cmd/pxe.c       | 28 +++++++++--------
 cmd/pxe_utils.c | 80 ++++++++++++++++++++++++++-----------------------
 cmd/pxe_utils.h | 43 +++++++++++++++++++-------
 cmd/sysboot.c   |  8 +++--
 4 files changed, 97 insertions(+), 62 deletions(-)
cmd/pxe.c +16 -12
index 46ac08fa3a0..17ce54fc049 100644
@@ -43,7 +43,7 @@ static int do_get_tftp(struct cmd_tbl *cmdtp, const char *file_path,
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_uuid_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
 {
 	char *uuid_str;
 
@@ -52,7 +52,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
 	if (!uuid_str)
 		return -ENOENT;
 
-	return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
+	return get_pxelinux_path(ctx, uuid_str, pxefile_addr_r);
 }
 
 /*
@@ -61,7 +61,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_mac_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
 {
 	char mac_str[21];
 	int err;
@@ -71,7 +71,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
 	if (err < 0)
 		return err;
 
-	return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
+	return get_pxelinux_path(ctx, mac_str, pxefile_addr_r);
 }
 
 /*
@@ -81,7 +81,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_r)
 {
 	char ip_addr[9];
 	int mask_pos, err;
@@ -89,7 +89,7 @@ static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
 	sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
 
 	for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
-		err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
+		err = get_pxelinux_path(ctx, ip_addr, pxefile_addr_r);
 
 		if (err > 0)
 			return err;
@@ -118,8 +118,10 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	char *pxefile_addr_str;
 	unsigned long pxefile_addr_r;
+	struct pxe_context ctx;
 	int err, i = 0;
 
+	pxe_setup_ctx(&ctx, cmdtp);
 	do_getfile = do_get_tftp;
 
 	if (argc != 1)
@@ -139,16 +141,16 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	 * Keep trying paths until we successfully get a file we're looking
 	 * for.
 	 */
-	if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
-	    pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
-	    pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
+	if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 ||
+	    pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
+	    pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
 		printf("Config file found\n");
 
 		return 0;
 	}
 
 	while (pxe_default_paths[i]) {
-		if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
+		if (get_pxelinux_path(&ctx, pxe_default_paths[i],
 				      pxefile_addr_r) > 0) {
 			printf("Config file found\n");
 			return 0;
@@ -172,7 +174,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	unsigned long pxefile_addr_r;
 	struct pxe_menu *cfg;
 	char *pxefile_addr_str;
+	struct pxe_context ctx;
 
+	pxe_setup_ctx(&ctx, cmdtp);
 	do_getfile = do_get_tftp;
 
 	if (argc == 1) {
@@ -191,14 +195,14 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		return 1;
 	}
 
-	cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+	cfg = parse_pxefile(&ctx, pxefile_addr_r);
 
 	if (!cfg) {
 		printf("Error parsing config file\n");
 		return 1;
 	}
 
-	handle_pxe_menu(cmdtp, cfg);
+	handle_pxe_menu(&ctx, cfg);
 
 	destroy_pxe_menu(cfg);
 
cmd/pxe_utils.c +43 -37

281 lines not on this page · raw message

cmd/pxe_utils.h +33 -10

92 lines not on this page · raw message

cmd/sysboot.c +5 -3
index af6a2f1b7f1..9ba713c8aae 100644
@@ -59,6 +59,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
 	unsigned long pxefile_addr_r;
+	struct pxe_context ctx;
 	struct pxe_menu *cfg;
 	char *pxefile_addr_str;
 	char *filename;
@@ -90,6 +91,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		env_set("bootfile", filename);
 	}
 
+	pxe_setup_ctx(&ctx, cmdtp);
 	if (strstr(argv[3], "ext2")) {
 		do_getfile = do_get_ext2;
 	} else if (strstr(argv[3], "fat")) {
@@ -108,12 +110,12 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		return 1;
 	}
 
-	if (get_pxe_file(cmdtp, filename, pxefile_addr_r) < 0) {
+	if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
 		printf("Error reading config file\n");
 		return 1;
 	}
 
-	cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+	cfg = parse_pxefile(&ctx, pxefile_addr_r);
 
 	if (!cfg) {
 		printf("Error parsing config file\n");
@@ -123,7 +125,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 	if (prompt)
 		cfg->prompt = 1;
 
-	handle_pxe_menu(cmdtp, cfg);
+	handle_pxe_menu(&ctx, cfg);
 
 	destroy_pxe_menu(cfg);
 
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#4 lore raw

PATCH 4/28 pxe: Move do_getfile() into the context

In reply to Simon Glass

Rather than having a global variable, pass the function as part of the context.

---

 cmd/pxe.c       | 10 ++++------
 cmd/pxe_utils.c |  9 ++++-----
 cmd/pxe_utils.h | 20 +++++++++++++++++---
 cmd/sysboot.c   | 20 ++++++++++----------
 4 files changed, 35 insertions(+), 24 deletions(-)
cmd/pxe.c +4 -6
index 17ce54fc049..70dbde3a636 100644
@@ -24,7 +24,7 @@ const char *pxe_default_paths[] = {
 	NULL
 };
 
-static int do_get_tftp(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
 		       char *file_addr)
 {
 	char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
@@ -32,7 +32,7 @@ static int do_get_tftp(struct cmd_tbl *cmdtp, const char *file_path,
 	tftp_argv[1] = file_addr;
 	tftp_argv[2] = (void *)file_path;
 
-	if (do_tftpb(cmdtp, 0, 3, tftp_argv))
+	if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
 		return -ENOENT;
 
 	return 1;
@@ -121,8 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct pxe_context ctx;
 	int err, i = 0;
 
-	pxe_setup_ctx(&ctx, cmdtp);
-	do_getfile = do_get_tftp;
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp);
 
 	if (argc != 1)
 		return CMD_RET_USAGE;
@@ -176,8 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	char *pxefile_addr_str;
 	struct pxe_context ctx;
 
-	pxe_setup_ctx(&ctx, cmdtp);
-	do_getfile = do_get_tftp;
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp);
 
 	if (argc == 1) {
 		pxefile_addr_str = from_env("pxefile_addr_r");
cmd/pxe_utils.c +4 -5
index 280be55d9b3..2caae6d1555 100644
@@ -94,9 +94,6 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 	return 1;
 }
 
-int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
-		  char *file_addr);
-
 /*
  * As in pxelinux, paths to files referenced from files we retrieve are
  * relative to the location of bootfile. get_relfile takes such a path and
@@ -133,7 +130,7 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 
 	sprintf(addr_buf, "%lx", file_addr);
 
-	return do_getfile(ctx->cmdtp, relfile, addr_buf);
+	return ctx->getfile(ctx, relfile, addr_buf);
 }
 
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
@@ -1434,7 +1431,9 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 	boot_unattempted_labels(ctx, cfg);
 }
 
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp)
+void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+		   pxe_getfile_func getfile)
 {
 	ctx->cmdtp = cmdtp;
+	ctx->getfile = getfile;
 }
cmd/pxe_utils.h +17 -3
index cd0d3371765..ca2696f48b0 100644
@@ -77,16 +77,28 @@ struct pxe_menu {
 
 extern bool is_pxe;
 
-extern int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
-			 char *file_addr);
+struct pxe_context;
+typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
+				char *file_addr);
 
 /**
  * struct pxe_context - context information for PXE parsing
  *
  * @cmdtp: Pointer to command table to use when calling other commands
+ * @getfile: Function called by PXE to read a file
  */
 struct pxe_context {
 	struct cmd_tbl *cmdtp;
+	/**
+	 * getfile() - read a file
+	 *
+	 * @ctx: PXE context
+	 * @file_path: Path to the file
+	 * @file_addr: String containing the hex address to put the file in
+	 *	memory
+	 * Return 0 if OK, -ve on error
+	 */
+	pxe_getfile_func getfile;
 };
 
 /**
@@ -179,7 +191,9 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  *
  * @ctx: Context to set up
  * @cmdtp: Command table entry which started this action
+ * @getfile: Function to call to read a file
  */
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp);
+void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+		   pxe_getfile_func getfile);
 
 #endif /* __PXE_UTILS_H */
cmd/sysboot.c +10 -10
index 9ba713c8aae..082f23543d1 100644
@@ -8,7 +8,7 @@
 
 static char *fs_argv[5];
 
-static int do_get_ext2(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_ext2(struct pxe_context *ctx, const char *file_path,
 		       char *file_addr)
 {
 #ifdef CONFIG_CMD_EXT2
@@ -16,13 +16,13 @@ static int do_get_ext2(struct cmd_tbl *cmdtp, const char *file_path,
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
-	if (!do_ext2load(cmdtp, 0, 5, fs_argv))
+	if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv))
 		return 1;
 #endif
 	return -ENOENT;
 }
 
-static int do_get_fat(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_fat(struct pxe_context *ctx, const char *file_path,
 		      char *file_addr)
 {
 #ifdef CONFIG_CMD_FAT
@@ -30,13 +30,13 @@ static int do_get_fat(struct cmd_tbl *cmdtp, const char *file_path,
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
-	if (!do_fat_fsload(cmdtp, 0, 5, fs_argv))
+	if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv))
 		return 1;
 #endif
 	return -ENOENT;
 }
 
-static int do_get_any(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_any(struct pxe_context *ctx, const char *file_path,
 		      char *file_addr)
 {
 #ifdef CONFIG_CMD_FS_GENERIC
@@ -44,7 +44,7 @@ static int do_get_any(struct cmd_tbl *cmdtp, const char *file_path,
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
-	if (!do_load(cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
+	if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
 		return 1;
 #endif
 	return -ENOENT;
@@ -91,13 +91,13 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		env_set("bootfile", filename);
 	}
 
-	pxe_setup_ctx(&ctx, cmdtp);
+	pxe_setup_ctx(&ctx, cmdtp, NULL);
 	if (strstr(argv[3], "ext2")) {
-		do_getfile = do_get_ext2;
+		ctx.getfile = do_get_ext2;
 	} else if (strstr(argv[3], "fat")) {
-		do_getfile = do_get_fat;
+		ctx.getfile = do_get_fat;
 	} else if (strstr(argv[3], "any")) {
-		do_getfile = do_get_any;
+		ctx.getfile = do_get_any;
 	} else {
 		printf("Invalid filesystem: %s\n", argv[3]);
 		return 1;
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#5 lore raw

PATCH 5/28 pxe: Add a userdata field to the context

In reply to Simon Glass

Allow the caller to provide some info which is passed back to the readfile() method.

---

 cmd/pxe.c       | 4 ++--
 cmd/pxe_utils.c | 3 ++-
 cmd/pxe_utils.h | 6 +++++-
 cmd/sysboot.c   | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)
cmd/pxe.c +2 -2
index 70dbde3a636..d79b9b733d7 100644
@@ -121,7 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct pxe_context ctx;
 	int err, i = 0;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp);
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL);
 
 	if (argc != 1)
 		return CMD_RET_USAGE;
@@ -175,7 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	char *pxefile_addr_str;
 	struct pxe_context ctx;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp);
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL);
 
 	if (argc == 1) {
 		pxefile_addr_str = from_env("pxefile_addr_r");
cmd/pxe_utils.c +2 -1
index 2caae6d1555..5ad6d3e3d44 100644
@@ -1432,8 +1432,9 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 }
 
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile)
+		   pxe_getfile_func getfile, void *userdata)
 {
 	ctx->cmdtp = cmdtp;
 	ctx->getfile = getfile;
+	ctx->userdata = userdata;
 }
cmd/pxe_utils.h +5 -1
index ca2696f48b0..921455f694e 100644
@@ -86,6 +86,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  *
  * @cmdtp: Pointer to command table to use when calling other commands
  * @getfile: Function called by PXE to read a file
+ * @userdata: Data the caller requires for @getfile
  */
 struct pxe_context {
 	struct cmd_tbl *cmdtp;
@@ -99,6 +100,8 @@ struct pxe_context {
 	 * Return 0 if OK, -ve on error
 	 */
 	pxe_getfile_func getfile;
+
+	void *userdata;
 };
 
 /**
@@ -192,8 +195,9 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @ctx: Context to set up
  * @cmdtp: Command table entry which started this action
  * @getfile: Function to call to read a file
+ * @userdata: Data the caller requires for @getfile - stored in ctx->userdata
  */
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile);
+		   pxe_getfile_func getfile, void *userdata);
 
 #endif /* __PXE_UTILS_H */
cmd/sysboot.c +1 -1
index 082f23543d1..5615e81e9ca 100644
@@ -91,7 +91,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		env_set("bootfile", filename);
 	}
 
-	pxe_setup_ctx(&ctx, cmdtp, NULL);
+	pxe_setup_ctx(&ctx, cmdtp, NULL, NULL);
 	if (strstr(argv[3], "ext2")) {
 		ctx.getfile = do_get_ext2;
 	} else if (strstr(argv[3], "fat")) {
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#6 lore raw

PATCH 6/28 pxe: Tidy up the is_pxe global

In reply to Simon Glass

Move this into the context to avoid a global variable. Also rename it since the current name does not explain what it actually affects.

---

 cmd/pxe.c       |  6 ++----
 cmd/pxe_utils.c | 13 +++++++------
 cmd/pxe_utils.h |  8 +++++---
 cmd/sysboot.c   |  4 +---
 4 files changed, 15 insertions(+), 16 deletions(-)
cmd/pxe.c +2 -4
index d79b9b733d7..17fe364bed9 100644
@@ -121,7 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct pxe_context ctx;
 	int err, i = 0;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL);
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
 
 	if (argc != 1)
 		return CMD_RET_USAGE;
@@ -175,7 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	char *pxefile_addr_str;
 	struct pxe_context ctx;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL);
+	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
 
 	if (argc == 1) {
 		pxefile_addr_str = from_env("pxefile_addr_r");
@@ -235,8 +235,6 @@ static int do_pxe(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
-	is_pxe = true;
-
 	/* drop initial "pxe" arg */
 	argc--;
 	argv++;
cmd/pxe_utils.c +7 -6
index 5ad6d3e3d44..7d15c75dd87 100644
@@ -30,8 +30,6 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
-bool is_pxe;
-
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
 	uchar ethaddr[6];
@@ -58,13 +56,13 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * be interpreted as "don't prepend anything to paths".
  */
 static int get_bootfile_path(const char *file_path, char *bootfile_path,
-			     size_t bootfile_path_size)
+			     size_t bootfile_path_size, bool allow_abs_path)
 {
 	char *bootfile, *last_slash;
 	size_t path_len = 0;
 
 	/* Only syslinux allows absolute paths */
-	if (file_path[0] == '/' && !is_pxe)
+	if (file_path[0] == '/' && allow_abs_path)
 		goto ret;
 
 	bootfile = from_env("bootfile");
@@ -110,7 +108,8 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 	char addr_buf[18];
 	int err;
 
-	err = get_bootfile_path(file_path, relfile, sizeof(relfile));
+	err = get_bootfile_path(file_path, relfile, sizeof(relfile),
+				ctx->allow_abs_path);
 
 	if (err < 0)
 		return err;
@@ -1432,9 +1431,11 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 }
 
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile, void *userdata)
+		   pxe_getfile_func getfile, void *userdata,
+		   bool allow_abs_path)
 {
 	ctx->cmdtp = cmdtp;
 	ctx->getfile = getfile;
 	ctx->userdata = userdata;
+	ctx->allow_abs_path = allow_abs_path;
 }
cmd/pxe_utils.h +5 -3
index 921455f694e..6681442ea55 100644
@@ -75,8 +75,6 @@ struct pxe_menu {
 	struct list_head labels;
 };
 
-extern bool is_pxe;
-
 struct pxe_context;
 typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
 				char *file_addr);
@@ -87,6 +85,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  * @cmdtp: Pointer to command table to use when calling other commands
  * @getfile: Function called by PXE to read a file
  * @userdata: Data the caller requires for @getfile
+ * @allow_abs_path: true to allow absolute paths
  */
 struct pxe_context {
 	struct cmd_tbl *cmdtp;
@@ -102,6 +101,7 @@ struct pxe_context {
 	pxe_getfile_func getfile;
 
 	void *userdata;
+	bool allow_abs_path;
 };
 
 /**
@@ -196,8 +196,10 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @cmdtp: Command table entry which started this action
  * @getfile: Function to call to read a file
  * @userdata: Data the caller requires for @getfile - stored in ctx->userdata
+ * @allow_abs_path: true to allow absolute paths
  */
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile, void *userdata);
+		   pxe_getfile_func getfile, void *userdata,
+		   bool allow_abs_path);
 
 #endif /* __PXE_UTILS_H */
cmd/sysboot.c +1 -3
index 5615e81e9ca..85fa5d8aa01 100644
@@ -65,8 +65,6 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 	char *filename;
 	int prompt = 0;
 
-	is_pxe = false;
-
 	if (argc > 1 && strstr(argv[1], "-p")) {
 		prompt = 1;
 		argc--;
@@ -91,7 +89,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		env_set("bootfile", filename);
 	}
 
-	pxe_setup_ctx(&ctx, cmdtp, NULL, NULL);
+	pxe_setup_ctx(&ctx, cmdtp, NULL, NULL, true);
 	if (strstr(argv[3], "ext2")) {
 		ctx.getfile = do_get_ext2;
 	} else if (strstr(argv[3], "fat")) {
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#7 lore raw

PATCH 7/28 pxe: Move pxe_utils files

In reply to Simon Glass

Move the header file into the main include/ directory so we can use it from the bootmethod code. Move the C file into boot/ since it relates to booting.

---

 boot/Makefile                | 3 +++
 {cmd => boot}/pxe_utils.c    | 0
 cmd/Makefile                 | 4 ++--
 cmd/sysboot.c                | 2 +-
 {cmd => include}/pxe_utils.h | 0
 5 files changed, 6 insertions(+), 3 deletions(-)
 rename {cmd => boot}/pxe_utils.c (100%)
 rename {cmd => include}/pxe_utils.h (100%)
boot/Makefile +3 -0
index 57d26346afb..e8f984248e6 100644
@@ -14,6 +14,9 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
 obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o
 obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
 
+obj-$(CONFIG_CMD_PXE) += pxe_utils.o
+obj-$(CONFIG_CMD_SYSBOOT) += pxe_utils.o
+
 endif
 
 obj-y += image.o
boot/pxe_utils.c renamed from cmd/pxe_utils.c +0 -0
similarity index 100%
rename from cmd/pxe_utils.c
rename to boot/pxe_utils.c
cmd/Makefile +2 -2
index ed3669411e6..891819ae0f6 100644
@@ -123,7 +123,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PMC) += pmc.o
 obj-$(CONFIG_CMD_PSTORE) += pstore.o
 obj-$(CONFIG_CMD_PWM) += pwm.o
-obj-$(CONFIG_CMD_PXE) += pxe.o pxe_utils.o
+obj-$(CONFIG_CMD_PXE) += pxe.o
 obj-$(CONFIG_CMD_WOL) += wol.o
 obj-$(CONFIG_CMD_QFW) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
@@ -145,7 +145,7 @@ obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
 obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
-obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o pxe_utils.o
+obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
 obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
 obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
cmd/sysboot.c +1 -1
index 85fa5d8aa01..b81255e155a 100644
@@ -4,7 +4,7 @@
 #include <command.h>
 #include <env.h>
 #include <fs.h>
-#include "pxe_utils.h"
+#include <pxe_utils.h>
 
 static char *fs_argv[5];
 
include/pxe_utils.h renamed from cmd/pxe_utils.h +0 -0
similarity index 100%
rename from cmd/pxe_utils.h
rename to include/pxe_utils.h
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#8 lore raw

PATCH 8/28 pxe: Tidy up some comments in pxe_utils

In reply to Simon Glass

Some of these functions are a big vague in the comments. Tidy them up a bit.

---

 boot/pxe_utils.c | 189 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 138 insertions(+), 51 deletions(-)
boot/pxe_utils.c +138 -51
index 7d15c75dd87..7a2213a5925 100644
@@ -30,6 +30,21 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
+/**
+ * format_mac_pxe() - obtain a MAC address in the PXE format
+ *
+ * This produces a MAC-address string in the format for the current ethernet
+ * device:
+ *
+ *   01-aa-bb-cc-dd-ee-ff
+ *
+ * where aa-ff is the MAC address in hex
+ *
+ * @outbuf: Buffer to write string to
+ * @outbuf_len: length of buffer
+ * @return 1 if OK, -ENOSPC if buffer is too small, -ENOENT is there is no
+ *	current ethernet device
+ */
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
 	uchar ethaddr[6];
@@ -37,7 +52,7 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 	if (outbuf_len < 21) {
 		printf("outbuf is too small (%zd < 21)\n", outbuf_len);
 
-		return -EINVAL;
+		return -ENOSPC;
 	}
 
 	if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
@@ -50,10 +65,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 	return 1;
 }
 
-/*
- * Returns the directory the file specified in the bootfile env variable is
+/**
+ * get_bootfile_path() - Figure out the path of a file to read
+ *
+ * Returns the directory the file specified in the 'bootfile' env variable is
  * in. If bootfile isn't defined in the environment, return NULL, which should
  * be interpreted as "don't prepend anything to paths".
+ *
+ * @file_path: File path to read (relative to the PXE file)
+ * @bootfile_path: Place to put the bootfile path
+ * @bootfile_path_size: Size of @bootfile_path in bytes
+ * @allow_abs_path: true to allow an absolute path (where @file_path starts with
+ *	'/', false to return an empty path (and success) in that case
+ * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
+ *	resulting path
  */
 static int get_bootfile_path(const char *file_path, char *bootfile_path,
 			     size_t bootfile_path_size, bool allow_abs_path)
@@ -81,7 +106,7 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 		printf("bootfile_path too small. (%zd < %zd)\n",
 		       bootfile_path_size, path_len);
 
-		return -1;
+		return -ENOSPC;
 	}
 
 	strncpy(bootfile_path, bootfile, path_len);
@@ -92,13 +117,18 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 	return 1;
 }
 
-/*
+/**
+ * get_relfile() - read a file relative to the PXE file
+ *
  * As in pxelinux, paths to files referenced from files we retrieve are
  * relative to the location of bootfile. get_relfile takes such a path and
  * joins it with the bootfile path to get the full path to the target file. If
  * the bootfile path is NULL, we use file_path as is.
  *
- * Returns 1 for success, or < 0 on error.
+ * @ctx: PXE context
+ * @file_path: File path to read (relative to the PXE file)
+ * @file_addr: Address to load file to
+ * Returns 1 for success, or < 0 on error
  */
 static int get_relfile(struct pxe_context *ctx, const char *file_path,
 		       unsigned long file_addr)
@@ -132,6 +162,16 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 	return ctx->getfile(ctx, relfile, addr_buf);
 }
 
+/**
+ * get_pxe_file() - read a file
+ *
+ * The file is read and nul-terminated
+ *
+ * @ctx: PXE context
+ * @file_path: File path to read (relative to the PXE file)
+ * @file_addr: Address to load file to
+ * Returns 1 for success, or < 0 on error
+ */
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 		 unsigned long file_addr)
 {
@@ -166,6 +206,14 @@ int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 
 #define PXELINUX_DIR "pxelinux.cfg/"
 
+/**
+ * get_pxelinux_path() - Get a file in the pxelinux.cfg/ directory
+ *
+ * @ctx: PXE context
+ * @file: Filename to process (relative to pxelinux.cfg/)
+ * Returns 1 for success, -ENAMETOOLONG if the resulting path is too long.
+ *	or other value < 0 on other error
+ */
 int get_pxelinux_path(struct pxe_context *ctx, const char *file,
 		      unsigned long pxefile_addr_r)
 {
@@ -183,12 +231,20 @@ int get_pxelinux_path(struct pxe_context *ctx, const char *file,
 	return get_pxe_file(ctx, path, pxefile_addr_r);
 }
 
-/*
+/**
+ * get_relfile_envaddr() - read a file to an address in an env var
+ *
  * Wrapper to make it easier to store the file at file_path in the location
  * specified by envaddr_name. file_path will be joined to the bootfile path,
  * if any is specified.
  *
- * Returns 1 on success or < 0 on error.
+ * @ctx: PXE context
+ * @file_path: File path to read (relative to the PXE file)
+ * @envaddr_name: Name of environment variable which contains the address to
+ *	load to
+ * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an
+ *	environment variable, -EINVAL if its format is not valid hex, or other
+ *	value < 0 on other error
  */
 static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
 			       const char *envaddr_name)
@@ -207,11 +263,13 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
 	return get_relfile(ctx, file_path, file_addr);
 }
 
-/*
+/**
+ * label_create() - crate a new PXE label
+ *
  * Allocates memory for and initializes a pxe_label. This uses malloc, so the
  * result must be free()'d to reclaim the memory.
  *
- * Returns NULL if malloc fails.
+ * Returns a pointer to the label, or NULL if out of memory
  */
 static struct pxe_label *label_create(void)
 {
@@ -227,13 +285,18 @@ static struct pxe_label *label_create(void)
 	return label;
 }
 
-/*
- * Free the memory used by a pxe_label, including that used by its name,
- * kernel, append and initrd members, if they're non NULL.
+/**
+ * label_destroy() - free the memory used by a pxe_label
+ *
+ * This frees @label itself as well as memory used by its name,
+ * kernel, config, append, initrd, fdt, fdtdir and fdtoverlay members, if
+ * they're non-NULL.
  *
  * So - be sure to only use dynamically allocated memory for the members of
  * the pxe_label struct, unless you want to clean it up first. These are
  * currently only created by the pxe file parsing code.
+ *
+ * @label: Label to free
  */
 static void label_destroy(struct pxe_label *label)
 {
@@ -264,11 +327,13 @@ static void label_destroy(struct pxe_label *label)
 	free(label);
 }
 
-/*
- * Print a label and its string members if they're defined.
+/**
+ * label_print() - Print a label and its string members if they're defined
  *
  * This is passed as a callback to the menu code for displaying each
  * menu entry.
+ *
+ * @data: Label to print (is cast to struct pxe_label *)
  */
 static void label_print(void *data)
 {
@@ -278,14 +343,16 @@ static void label_print(void *data)
 	printf("%s:\t%s\n", label->num, c);
 }
 
-/*
- * Boot a label that specified 'localboot'. This requires that the 'localcmd'
- * environment variable is defined. Its contents will be executed as U-Boot
- * command.  If the label specified an 'append' line, its contents will be
- * used to overwrite the contents of the 'bootargs' environment variable prior
- * to running 'localcmd'.
+/**
+ * label_localboot() - Boot a label that specified 'localboot'
+ *
+ * This requires that the 'localcmd' environment variable is defined. Its
+ * contents will be executed as U-Boot commands.  If the label specified an
+ * 'append' line, its contents will be used to overwrite the contents of the
+ * 'bootargs' environment variable prior to running 'localcmd'.
  *
- * Returns 1 on success or < 0 on error.
+ * @label: Label to process
+ * Returns 1 on success or < 0 on error
  */
 static int label_localboot(struct pxe_label *label)
 {
@@ -309,8 +376,11 @@ static int label_localboot(struct pxe_label *label)
 	return run_command_list(localcmd, strlen(localcmd), 0);
 }
 
-/*
- * Loads fdt overlays specified in 'fdtoverlays'.
+/**
+ * label_boot_fdtoverlay() - Loads fdt overlays specified in 'fdtoverlays'
+ *
+ * @ctx: PXE context
+ * @label: Label to process
  */
 #ifdef CONFIG_OF_LIBFDT_OVERLAY
 static void label_boot_fdtoverlay(struct pxe_context *ctx,
@@ -396,8 +466,8 @@ skip_overlay:
 }
 #endif
 
-/*
- * Boot according to the contents of a pxe_label.
+/**
+ * label_boot() - Boot according to the contents of a pxe_label
  *
  * If we can't boot for any reason, we return.  A successful boot never
  * returns.
@@ -410,6 +480,11 @@ skip_overlay:
  *
  * If the label specifies an 'append' line, its contents will overwrite that
  * of the 'bootargs' environment variable.
+ *
+ * @ctx: PXE context
+ * @label: Label to process
+ * Returns does not return on success, otherwise returns 0 if a localboot
+ *	label was processed, or 1 on error
  */
 static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 {
@@ -648,9 +723,7 @@ cleanup:
 	return 1;
 }
 
-/*
- * Tokens for the pxe file parser.
- */
+/** enum token_type - Tokens for the pxe file parser */
 enum token_type {
 	T_EOL,
 	T_STRING,
@@ -676,17 +749,13 @@ enum token_type {
 	T_INVALID
 };
 
-/*
- * A token - given by a value and a type.
- */
+/** struct token - token - given by a value and a type */
 struct token {
 	char *val;
 	enum token_type type;
 };
 
-/*
- * Keywords recognized.
- */
+/* Keywords recognized */
 static const struct token keywords[] = {
 	{"menu", T_MENU},
 	{"title", T_TITLE},
@@ -711,7 +780,9 @@ static const struct token keywords[] = {
 	{NULL, T_INVALID}
 };
 
-/*
+/**
+ * enum lex_state - lexer state
+ *
  * Since pxe(linux) files don't have a token to identify the start of a
  * literal, we have to keep track of when we're in a state where a literal is
  * expected vs when we're in a state a keyword is expected.
@@ -722,11 +793,10 @@ enum lex_state {
 	L_SLITERAL
 };
 
-/*
- * get_string retrieves a string from *p and stores it as a token in
- * *t.
+/**
+ * get_string() - retrieves a string from *p and stores it as a token in *t.
  *
- * get_string used for scanning both string literals and keywords.
+ * This is used for scanning both string literals and keywords.
  *
  * Characters from *p are copied into t-val until a character equal to
  * delim is found, or a NUL byte is reached. If delim has the special value of
@@ -739,9 +809,15 @@ enum lex_state {
  * The location of *p is updated to point to the first character after the end
  * of the token - the ending delimiter.
  *
- * On success, the new value of t->val is returned. Memory for t->val is
- * allocated using malloc and must be free()'d to reclaim it.  If insufficient
- * memory is available, NULL is returned.
+ * Memory for t->val is allocated using malloc and must be free()'d to reclaim
+ * it.
+ *
+ * @p: Points to a pointer to the current position in the input being processed.
+ *	Updated to point at the first character after the current token
+ * @t: Pointers to a token to fill in
+ * @delim: Delimiter character to look for, either newline or space
+ * @lower: true to convert the string to lower case when storing
+ * Returns the new value of t->val, on success, NULL if out of memory
  */
 static char *get_string(char **p, struct token *t, char delim, int lower)
 {
@@ -792,8 +868,11 @@ static char *get_string(char **p, struct token *t, char delim, int lower)
 	return t->val;
 }
 
-/*
- * Populate a keyword token with a type and value.
+/**
+ * get_keyword() - Populate a keyword token with a type and value
+ *
+ * Updates the ->type field based on the keyword string in @val
+ * @t: Token to populate
  */
 static void get_keyword(struct token *t)
 {
@@ -807,11 +886,14 @@ static void get_keyword(struct token *t)
 	}
 }
 
-/*
- * Get the next token.  We have to keep track of which state we're in to know
- * if we're looking to get a string literal or a keyword.
+/**
+ * get_token() - Get the next token
+ *
+ * We have to keep track of which state we're in to know if we're looking to get
+ * a string literal or a keyword.
  *
- * *p is updated to point at the first character after the current token.
+ * @p: Points to a pointer to the current position in the input being processed.
+ *	Updated to point at the first character after the current token
  */
 static void get_token(char **p, struct token *t, enum lex_state state)
 {
@@ -855,8 +937,13 @@ static void get_token(char **p, struct token *t, enum lex_state state)
 	*p = c;
 }
 
-/*
- * Increment *c until we get to the end of the current line, or EOF.
+/**
+ * eol_or_eof() - Find end of line
+ *
+ * Increment *c until we get to the end of the current line, or EOF
+ *
+ * @c: Points to a pointer to the current position in the input being processed.
+ *	Updated to point at the first character after the current token
  */
 static void eol_or_eof(char **c)
 {
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#9 lore raw

PATCH 9/28 pxe: Tidy up code style a little in pxe_utils

In reply to Simon Glass

There are a few more blank lines than makes sense for readability. Also free() handles a NULL pointer so drop the pointless checks.

---

 boot/pxe_utils.c | 66 ++++++++++--------------------------------------
 1 file changed, 13 insertions(+), 53 deletions(-)
boot/pxe_utils.c +13 -53
index 7a2213a5925..9f3edeab06a 100644
@@ -51,7 +51,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 
 	if (outbuf_len < 21) {
 		printf("outbuf is too small (%zd < 21)\n", outbuf_len);
-
 		return -ENOSPC;
 	}
 
@@ -91,12 +90,10 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path,
 		goto ret;
 
 	bootfile = from_env("bootfile");
-
 	if (!bootfile)
 		goto ret;
 
 	last_slash = strrchr(bootfile, '/');
-
 	if (!last_slash)
 		goto ret;
 
@@ -140,7 +137,6 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 
 	err = get_bootfile_path(file_path, relfile, sizeof(relfile),
 				ctx->allow_abs_path);
-
 	if (err < 0)
 		return err;
 
@@ -181,7 +177,6 @@ int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 	char *buf;
 
 	err = get_relfile(ctx, file_path, file_addr);
-
 	if (err < 0)
 		return err;
 
@@ -190,7 +185,6 @@ int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 	 * and add the NUL byte.
 	 */
 	tftp_filesize = from_env("filesize");
-
 	if (!tftp_filesize)
 		return -ENOENT;
 
@@ -253,7 +247,6 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
 	char *envaddr;
 
 	envaddr = from_env(envaddr_name);
-
 	if (!envaddr)
 		return -ENOENT;
 
@@ -276,7 +269,6 @@ static struct pxe_label *label_create(void)
 	struct pxe_label *label;
 
 	label = malloc(sizeof(struct pxe_label));
-
 	if (!label)
 		return NULL;
 
@@ -300,30 +292,14 @@ static struct pxe_label *label_create(void)
  */
 static void label_destroy(struct pxe_label *label)
 {
-	if (label->name)
-		free(label->name);
-
-	if (label->kernel)
-		free(label->kernel);
-
-	if (label->config)
-		free(label->config);
-
-	if (label->append)
-		free(label->append);
-
-	if (label->initrd)
-		free(label->initrd);
-
-	if (label->fdt)
-		free(label->fdt);
-
-	if (label->fdtdir)
-		free(label->fdtdir);
-
-	if (label->fdtoverlays)
-		free(label->fdtoverlays);
-
+	free(label->name);
+	free(label->kernel);
+	free(label->config);
+	free(label->append);
+	free(label->initrd);
+	free(label->fdt);
+	free(label->fdtdir);
+	free(label->fdtoverlays);
 	free(label);
 }
 
@@ -359,7 +335,6 @@ static int label_localboot(struct pxe_label *label)
 	char *localcmd;
 
 	localcmd = from_env("localcmd");
-
 	if (!localcmd)
 		return -ENOENT;
 
@@ -718,8 +693,8 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 	unmap_sysmem(buf);
 
 cleanup:
-	if (fit_addr)
-		free(fit_addr);
+	free(fit_addr);
+
 	return 1;
 }
 
@@ -832,7 +807,6 @@ static char *get_string(char **p, struct token *t, char delim, int lower)
 	 */
 	b = *p;
 	e = *p;
-
 	while (*e) {
 		if ((delim == ' ' && isspace(*e)) || delim == *e)
 			break;
@@ -858,11 +832,8 @@ static char *get_string(char **p, struct token *t, char delim, int lower)
 
 	t->val[len] = '\0';
 
-	/*
-	 * Update *p so the caller knows where to continue scanning.
-	 */
+	/* Update *p so the caller knows where to continue scanning */
 	*p = e;
-
 	t->type = T_STRING;
 
 	return t->val;
@@ -988,7 +959,6 @@ static int parse_integer(char **c, int *dst)
 	char *s = *c;
 
 	get_token(c, &t, L_SLITERAL);
-
 	if (t.type != T_STRING) {
 		printf("Expected string: %.*s\n", (int)(*c - s), s);
 		return -EINVAL;
@@ -1022,14 +992,12 @@ static int handle_include(struct pxe_context *ctx, char **c, unsigned long base,
 	int ret;
 
 	err = parse_sliteral(c, &include_path);
-
 	if (err < 0) {
 		printf("Expected include path: %.*s\n", (int)(*c - s), s);
 		return err;
 	}
 
 	err = get_pxe_file(ctx, include_path, base);
-
 	if (err < 0) {
 		printf("Couldn't retrieve %s\n", include_path);
 		return err;
@@ -1079,7 +1047,6 @@ static int parse_menu(struct pxe_context *ctx, char **c, struct pxe_menu *cfg,
 		printf("Ignoring malformed menu command: %.*s\n",
 		       (int)(*c - s), s);
 	}
-
 	if (err < 0)
 		return err;
 
@@ -1353,11 +1320,8 @@ void destroy_pxe_menu(struct pxe_menu *cfg)
 	struct list_head *pos, *n;
 	struct pxe_label *label;
 
-	if (cfg->title)
-		free(cfg->title);
-
-	if (cfg->default_label)
-		free(cfg->default_label);
+	free(cfg->title);
+	free(cfg->default_label);
 
 	list_for_each_safe(pos, n, &cfg->labels) {
 		label = list_entry(pos, struct pxe_label, list);
@@ -1375,7 +1339,6 @@ struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg)
 	int r;
 
 	cfg = malloc(sizeof(struct pxe_menu));
-
 	if (!cfg)
 		return NULL;
 
@@ -1386,7 +1349,6 @@ struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg)
 	buf = map_sysmem(menucfg, 0);
 	r = parse_pxefile_top(ctx, buf, menucfg, cfg, 1);
 	unmap_sysmem(buf);
-
 	if (r < 0) {
 		destroy_pxe_menu(cfg);
 		return NULL;
@@ -1413,7 +1375,6 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
 	 */
 	m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10),
 			cfg->prompt, NULL, label_print, NULL, NULL);
-
 	if (!m)
 		return NULL;
 
@@ -1492,7 +1453,6 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 		return;
 
 	err = menu_get_choice(m, &choice);
-
 	menu_destroy(m);
 
 	/*
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#10 lore raw

PATCH 10/28 pxe: Move common parsing coding into pxe_util

In reply to Simon Glass

Both the syslinux and pxe commands use essentially the same code to parse and run extlinux.conf files. Move this into a common function.

---

 boot/pxe_utils.c    | 20 ++++++++++++++++++++
 cmd/pxe.c           | 15 ++++-----------
 cmd/sysboot.c       | 18 ++++--------------
 include/pxe_utils.h |  9 +++++++++
 4 files changed, 37 insertions(+), 25 deletions(-)
boot/pxe_utils.c +20 -0
index 9f3edeab06a..225729ce57f 100644
@@ -1486,3 +1486,23 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
 	ctx->userdata = userdata;
 	ctx->allow_abs_path = allow_abs_path;
 }
+
+int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt)
+{
+	struct pxe_menu *cfg;
+
+	cfg = parse_pxefile(ctx, pxefile_addr_r);
+	if (!cfg) {
+		printf("Error parsing config file\n");
+		return 1;
+	}
+
+	if (prompt)
+		cfg->prompt = 1;
+
+	handle_pxe_menu(ctx, cfg);
+
+	destroy_pxe_menu(cfg);
+
+	return 0;
+}
cmd/pxe.c +4 -11
index 17fe364bed9..4fa51d2e053 100644
@@ -171,9 +171,9 @@ static int
 do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	unsigned long pxefile_addr_r;
-	struct pxe_menu *cfg;
 	char *pxefile_addr_str;
 	struct pxe_context ctx;
+	int ret;
 
 	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
 
@@ -193,16 +193,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		return 1;
 	}
 
-	cfg = parse_pxefile(&ctx, pxefile_addr_r);
-
-	if (!cfg) {
-		printf("Error parsing config file\n");
-		return 1;
-	}
-
-	handle_pxe_menu(&ctx, cfg);
-
-	destroy_pxe_menu(cfg);
+	ret = pxe_process(&ctx, pxefile_addr_r, false);
+	if (ret)
+		return CMD_RET_FAILURE;
 
 	copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name));
 
cmd/sysboot.c +4 -14
index b81255e155a..7ee14df79e5 100644
@@ -60,10 +60,10 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	unsigned long pxefile_addr_r;
 	struct pxe_context ctx;
-	struct pxe_menu *cfg;
 	char *pxefile_addr_str;
 	char *filename;
 	int prompt = 0;
+	int ret;
 
 	if (argc > 1 && strstr(argv[1], "-p")) {
 		prompt = 1;
@@ -113,19 +113,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		return 1;
 	}
 
-	cfg = parse_pxefile(&ctx, pxefile_addr_r);
-
-	if (!cfg) {
-		printf("Error parsing config file\n");
-		return 1;
-	}
-
-	if (prompt)
-		cfg->prompt = 1;
-
-	handle_pxe_menu(&ctx, cfg);
-
-	destroy_pxe_menu(cfg);
+	ret = pxe_process(&ctx, pxefile_addr_r, prompt);
+	if (ret)
+		return CMD_RET_FAILURE;
 
 	return 0;
 }
include/pxe_utils.h +9 -0
index 6681442ea55..0cae0dabec3 100644
@@ -202,4 +202,13 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
 		   pxe_getfile_func getfile, void *userdata,
 		   bool allow_abs_path);
 
+/**
+ * pxe_process() - Process a PXE file through to boot
+ *
+ * @ctx: PXE context created with pxe_setup_ctx()
+ * @pxefile_addr_r: Address to load file
+ * @prompt: Force a prompt for the user
+ */
+int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt);
+
 #endif /* __PXE_UTILS_H */
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#11 lore raw

PATCH 11/28 pxe: Clean up the use of bootfile

In reply to Simon Glass

The 'bootfile' environment variable is read in the bowels of pxe_util to provide a directory to which all loaded files are relative.

This is not obvious from the API to PXE and it is strange to make the caller set an environment variable rather than pass this as a parameter.

The code is also convoluted, which this feature implemented by get_bootfile_path().

Update the API to improve this. Unfortunately this means that pxe_setup_ctx() can fail, so add error checking.

---

 boot/pxe_utils.c    | 60 ++++++++++++++++++++++++++++-----------------
 cmd/pxe.c           | 18 +++++++++++---
 cmd/sysboot.c       | 15 +++++++++---
 include/pxe_utils.h | 19 +++++++++++---
 4 files changed, 79 insertions(+), 33 deletions(-)
boot/pxe_utils.c +38 -22
index 225729ce57f..c04be110ea4 100644
@@ -67,10 +67,10 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 /**
  * get_bootfile_path() - Figure out the path of a file to read
  *
- * Returns the directory the file specified in the 'bootfile' env variable is
- * in. If bootfile isn't defined in the environment, return NULL, which should
- * be interpreted as "don't prepend anything to paths".
+ * Copies the boot directory into the supplied buffer. If there is no boot
+ * directory, set it to ""
  *
+ * @ctx: PXE context
  * @file_path: File path to read (relative to the PXE file)
  * @bootfile_path: Place to put the bootfile path
  * @bootfile_path_size: Size of @bootfile_path in bytes
@@ -79,34 +79,25 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
  *	resulting path
  */
-static int get_bootfile_path(const char *file_path, char *bootfile_path,
-			     size_t bootfile_path_size, bool allow_abs_path)
+static int get_bootfile_path(struct pxe_context *ctx, const char *file_path,
+			     char *bootfile_path, size_t bootfile_path_size,
+			     bool allow_abs_path)
 {
-	char *bootfile, *last_slash;
 	size_t path_len = 0;
 
 	/* Only syslinux allows absolute paths */
 	if (file_path[0] == '/' && allow_abs_path)
 		goto ret;
 
-	bootfile = from_env("bootfile");
-	if (!bootfile)
-		goto ret;
-
-	last_slash = strrchr(bootfile, '/');
-	if (!last_slash)
-		goto ret;
-
-	path_len = (last_slash - bootfile) + 1;
-
-	if (bootfile_path_size < path_len) {
+	path_len = strlen(ctx->bootdir);
+	if (bootfile_path_size < path_len + 1) {
 		printf("bootfile_path too small. (%zd < %zd)\n",
 		       bootfile_path_size, path_len);
 
 		return -ENOSPC;
 	}
 
-	strncpy(bootfile_path, bootfile, path_len);
+	strncpy(bootfile_path, ctx->bootdir, path_len);
 
  ret:
 	bootfile_path[path_len] = '\0';
@@ -135,7 +126,7 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 	char addr_buf[18];
 	int err;
 
-	err = get_bootfile_path(file_path, relfile, sizeof(relfile),
+	err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile),
 				ctx->allow_abs_path);
 	if (err < 0)
 		return err;
@@ -1477,14 +1468,39 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 	boot_unattempted_labels(ctx, cfg);
 }
 
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile, void *userdata,
-		   bool allow_abs_path)
+int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+		  pxe_getfile_func getfile, void *userdata,
+		  bool allow_abs_path, const char *bootfile)
 {
+	const char *last_slash;
+	size_t path_len = 0;
+
+	memset(ctx, '\0', sizeof(*ctx));
 	ctx->cmdtp = cmdtp;
 	ctx->getfile = getfile;
 	ctx->userdata = userdata;
 	ctx->allow_abs_path = allow_abs_path;
+
+	/* figure out the boot directory, if there is one */
+	if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN)
+		return -ENOSPC;
+	ctx->bootdir = strdup(bootfile ? bootfile : "");
+	if (!ctx->bootdir)
+		return -ENOMEM;
+
+	if (bootfile) {
+		last_slash = strrchr(bootfile, '/');
+		if (last_slash)
+			path_len = (last_slash - bootfile) + 1;
+	}
+	ctx->bootdir[path_len] = '\0';
+
+	return 0;
+}
+
+void pxe_destroy_ctx(struct pxe_context *ctx)
+{
+	free(ctx->bootdir);
 }
 
 int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt)
cmd/pxe.c +14 -4
index 4fa51d2e053..e319db51ef5 100644
@@ -121,8 +121,6 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct pxe_context ctx;
 	int err, i = 0;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
-
 	if (argc != 1)
 		return CMD_RET_USAGE;
 
@@ -136,6 +134,11 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (err < 0)
 		return 1;
 
+	if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
+			  env_get("bootfile"))) {
+		printf("Out of memory\n");
+		return CMD_RET_FAILURE;
+	}
 	/*
 	 * Keep trying paths until we successfully get a file we're looking
 	 * for.
@@ -144,6 +147,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	    pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
 	    pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
 		printf("Config file found\n");
+		pxe_destroy_ctx(&ctx);
 
 		return 0;
 	}
@@ -152,12 +156,14 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		if (get_pxelinux_path(&ctx, pxe_default_paths[i],
 				      pxefile_addr_r) > 0) {
 			printf("Config file found\n");
+			pxe_destroy_ctx(&ctx);
 			return 0;
 		}
 		i++;
 	}
 
 	printf("Config file not found\n");
+	pxe_destroy_ctx(&ctx);
 
 	return 1;
 }
@@ -175,8 +181,6 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct pxe_context ctx;
 	int ret;
 
-	pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
-
 	if (argc == 1) {
 		pxefile_addr_str = from_env("pxefile_addr_r");
 		if (!pxefile_addr_str)
@@ -193,7 +197,13 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		return 1;
 	}
 
+	if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
+			  env_get("bootfile"))) {
+		printf("Out of memory\n");
+		return CMD_RET_FAILURE;
+	}
 	ret = pxe_process(&ctx, pxefile_addr_r, false);
+	pxe_destroy_ctx(&ctx);
 	if (ret)
 		return CMD_RET_FAILURE;
 
cmd/sysboot.c +11 -4
index 7ee14df79e5..c45fed774d6 100644
@@ -59,6 +59,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
 	unsigned long pxefile_addr_r;
+	pxe_getfile_func getfile;
 	struct pxe_context ctx;
 	char *pxefile_addr_str;
 	char *filename;
@@ -89,13 +90,12 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		env_set("bootfile", filename);
 	}
 
-	pxe_setup_ctx(&ctx, cmdtp, NULL, NULL, true);
 	if (strstr(argv[3], "ext2")) {
-		ctx.getfile = do_get_ext2;
+		getfile = do_get_ext2;
 	} else if (strstr(argv[3], "fat")) {
-		ctx.getfile = do_get_fat;
+		getfile = do_get_fat;
 	} else if (strstr(argv[3], "any")) {
-		ctx.getfile = do_get_any;
+		getfile = do_get_any;
 	} else {
 		printf("Invalid filesystem: %s\n", argv[3]);
 		return 1;
@@ -108,12 +108,19 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		return 1;
 	}
 
+	if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) {
+		printf("Out of memory\n");
+		return CMD_RET_FAILURE;
+	}
+
 	if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
 		printf("Error reading config file\n");
+		pxe_destroy_ctx(&ctx);
 		return 1;
 	}
 
 	ret = pxe_process(&ctx, pxefile_addr_r, prompt);
+	pxe_destroy_ctx(&ctx);
 	if (ret)
 		return CMD_RET_FAILURE;
 
include/pxe_utils.h +16 -3
index 0cae0dabec3..543d0245c8a 100644
@@ -86,6 +86,8 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  * @getfile: Function called by PXE to read a file
  * @userdata: Data the caller requires for @getfile
  * @allow_abs_path: true to allow absolute paths
+ * @bootdir: Directory that files are loaded from ("" if no directory). This is
+ *	allocated
  */
 struct pxe_context {
 	struct cmd_tbl *cmdtp;
@@ -102,6 +104,7 @@ struct pxe_context {
 
 	void *userdata;
 	bool allow_abs_path;
+	char *bootdir;
 };
 
 /**
@@ -197,10 +200,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @getfile: Function to call to read a file
  * @userdata: Data the caller requires for @getfile - stored in ctx->userdata
  * @allow_abs_path: true to allow absolute paths
+ * @bootfile: Bootfile whose directory loaded files are relative to, NULL if
+ *	none
+ * @return 0 if OK, -ENOMEM if out of memory
  */
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-		   pxe_getfile_func getfile, void *userdata,
-		   bool allow_abs_path);
+int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+		  pxe_getfile_func getfile, void *userdata,
+		  bool allow_abs_path, const char *bootfile);
+
+/**
+ * pxe_destroy_ctx() - Destroy a PXE context
+ *
+ * @ctx: Context to destroy
+ */
+void pxe_destroy_ctx(struct pxe_context *ctx);
 
 /**
  * pxe_process() - Process a PXE file through to boot
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#12 lore raw

PATCH 12/28 pxe: Drop get_bootfile_path()

In reply to Simon Glass

This function no longer makes sense, since it is pretty easy to prepend the boot directory to the filename. Drop it and update its only caller.

---

 boot/pxe_utils.c    | 53 +++++----------------------------------------
 include/pxe_utils.h |  3 ++-
 2 files changed, 7 insertions(+), 49 deletions(-)
boot/pxe_utils.c +5 -48
index c04be110ea4..f36f1f8a60c 100644
@@ -64,47 +64,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 	return 1;
 }
 
-/**
- * get_bootfile_path() - Figure out the path of a file to read
- *
- * Copies the boot directory into the supplied buffer. If there is no boot
- * directory, set it to ""
- *
- * @ctx: PXE context
- * @file_path: File path to read (relative to the PXE file)
- * @bootfile_path: Place to put the bootfile path
- * @bootfile_path_size: Size of @bootfile_path in bytes
- * @allow_abs_path: true to allow an absolute path (where @file_path starts with
- *	'/', false to return an empty path (and success) in that case
- * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
- *	resulting path
- */
-static int get_bootfile_path(struct pxe_context *ctx, const char *file_path,
-			     char *bootfile_path, size_t bootfile_path_size,
-			     bool allow_abs_path)
-{
-	size_t path_len = 0;
-
-	/* Only syslinux allows absolute paths */
-	if (file_path[0] == '/' && allow_abs_path)
-		goto ret;
-
-	path_len = strlen(ctx->bootdir);
-	if (bootfile_path_size < path_len + 1) {
-		printf("bootfile_path too small. (%zd < %zd)\n",
-		       bootfile_path_size, path_len);
-
-		return -ENOSPC;
-	}
-
-	strncpy(bootfile_path, ctx->bootdir, path_len);
-
- ret:
-	bootfile_path[path_len] = '\0';
-
-	return 1;
-}
-
 /**
  * get_relfile() - read a file relative to the PXE file
  *
@@ -124,15 +83,13 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 	size_t path_len;
 	char relfile[MAX_TFTP_PATH_LEN + 1];
 	char addr_buf[18];
-	int err;
 
-	err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile),
-				ctx->allow_abs_path);
-	if (err < 0)
-		return err;
+	if (file_path[0] == '/' && ctx->allow_abs_path)
+		*relfile = '\0';
+	else
+		strncpy(relfile, ctx->bootdir, MAX_TFTP_PATH_LEN);
 
-	path_len = strlen(file_path);
-	path_len += strlen(relfile);
+	path_len = strlen(file_path) + strlen(relfile);
 
 	if (path_len > MAX_TFTP_PATH_LEN) {
 		printf("Base path too long (%s%s)\n", relfile, file_path);
include/pxe_utils.h +2 -1
index 543d0245c8a..8b50f2e6861 100644
@@ -202,7 +202,8 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @allow_abs_path: true to allow absolute paths
  * @bootfile: Bootfile whose directory loaded files are relative to, NULL if
  *	none
- * @return 0 if OK, -ENOMEM if out of memory
+ * @return 0 if OK, -ENOMEM if out of memory, -E2BIG if bootfile is larger than
+ *	MAX_TFTP_PATH_LEN bytes
  */
 int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
 		  pxe_getfile_func getfile, void *userdata,
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#13 lore raw

PATCH 13/28 lib: Add tests for simple_itoa()

In reply to Simon Glass

Add test and a comment for this function.

---

 include/vsprintf.h | 13 ++++++++++++-
 test/print_ut.c    | 17 +++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
include/vsprintf.h +12 -1
index 83d187e53d4..4479df0af3f 100644
@@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...)
  * See the vsprintf() documentation for format string extensions over C99.
  */
 int vsprintf(char *buf, const char *fmt, va_list args);
-char *simple_itoa(ulong i);
+
+/**
+ * simple_itoa() - convert an unsigned integer to a string
+ *
+ * This returns a static string containing the decimal representation of the
+ * given value. The returned value may be overwritten by other calls to the
+ * same function, so should be used immediately
+ *
+ * @val: Value to convert
+ * @return string containing the decimal representation of @val
+ */
+char *simple_itoa(ulong val);
 
 /**
  * Format a string and place it in a buffer
test/print_ut.c +17 -0
index e2bcfbef007..737845afd33 100644
@@ -10,6 +10,7 @@
 #include <log.h>
 #include <mapmem.h>
 #include <version.h>
+#include <vsprintf.h>
 #include <test/suites.h>
 #include <test/test.h>
 #include <test/ut.h>
@@ -328,6 +329,22 @@ 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));
+	if (sizeof(ulong) == 8) {
+		ut_asserteq_str("9223372036854775807",
+				simple_itoa((1UL << 63) - 1));
+		ut_asserteq_str("18446744073709551615", simple_itoa(-1));
+	}
+
+	return 0;
+}
+PRINT_TEST(print_itoa, 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);
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#14 lore raw

PATCH 14/28 lib: Add a function to convert a string to a hex value

In reply to Simon Glass

Add an xtoa() function, similar to itoa() but for hex instead.

---

 include/vsprintf.h | 16 ++++++++++++++--
 lib/vsprintf.c     | 20 ++++++++++++++++++--
 test/print_ut.c    | 16 ++++++++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)
include/vsprintf.h +14 -2
index 4479df0af3f..b4746301462 100644
@@ -177,14 +177,26 @@ int vsprintf(char *buf, const char *fmt, va_list args);
  * simple_itoa() - convert an unsigned integer to a string
  *
  * This returns a static string containing the decimal representation of the
- * given value. The returned value may be overwritten by other calls to the
- * same function, so should be used immediately
+ * given value. The returned value may be overwritten by other calls to other
+ * simple_... functions, so should be used immediately
  *
  * @val: Value to convert
  * @return string containing the decimal representation of @val
  */
 char *simple_itoa(ulong val);
 
+/**
+ * simple_xtoa() - convert an unsigned integer to a hex string
+ *
+ * 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
+ *
+ * @val: Value to convert
+ * @return string containing the hexecimal representation of @val
+ */
+char *simple_xtoa(ulong num);
+
 /**
  * Format a string and place it in a buffer
  *
lib/vsprintf.c +18 -2
index d7ee35b4773..e634bd70b66 100644
@@ -816,11 +816,12 @@ int vprintf(const char *fmt, va_list args)
 }
 #endif
 
+static char local_toa[22];
+
 char *simple_itoa(ulong i)
 {
 	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-	static char local[22];
-	char *p = &local[21];
+	char *p = &local_toa[21];
 
 	*p-- = '\0';
 	do {
@@ -830,6 +831,21 @@ char *simple_itoa(ulong i)
 	return p + 1;
 }
 
+char *simple_xtoa(ulong num)
+{
+	/* 16 digits plus nul terminator, good for 64-bit or smaller ints */
+	char *p = &local_toa[17];
+
+	*--p = '\0';
+	do {
+		p -= 2;
+		hex_byte_pack(p, num & 0xff);
+		num >>= 8;
+	} while (num > 0);
+
+	return p;
+}
+
 /* We don't seem to have %'d in U-Boot */
 void print_grouped_ull(unsigned long long int_val, int digits)
 {
test/print_ut.c +16 -0
index 737845afd33..13068bc619d 100644
@@ -345,6 +345,22 @@ static int print_itoa(struct unit_test_state *uts)
 }
 PRINT_TEST(print_itoa, 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));
+	if (sizeof(ulong) == 8) {
+		ut_asserteq_str("7fffffffffffffff",
+				simple_xtoa((1UL << 63) - 1));
+		ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1));
+	}
+
+	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);
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#15 lore raw

PATCH 15/28 pxe: Return the file size from the getfile() function

In reply to Simon Glass

It is pretty strange that the pxe code uses the 'filesize' environment variable find the size of a file it has just read.

Partly this is because it uses the command-line interpreter to parse its request to load the file.

As a first step towards unwinding this, return it directly from the getfile() function. This makes the code a bit longer, for now, but will be cleaned up in future patches.

---

 boot/pxe_utils.c    | 70 ++++++++++++++++++++++++++++-----------------
 cmd/pxe.c           |  7 ++++-
 cmd/sysboot.c       | 21 ++++++++++++--
 include/pxe_utils.h | 13 ++++++++-
 4 files changed, 79 insertions(+), 32 deletions(-)
boot/pxe_utils.c +43 -27
index f36f1f8a60c..e377e16be56 100644
@@ -30,6 +30,20 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
+int pxe_get_file_size(ulong *sizep)
+{
+	const char *val;
+
+	val = from_env("filesize");
+	if (!val)
+		return -ENOENT;
+
+	if (strict_strtoul(val, 16, sizep) < 0)
+		return -EINVAL;
+
+	return 0;
+}
+
 /**
  * format_mac_pxe() - obtain a MAC address in the PXE format
  *
@@ -75,14 +89,17 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * @ctx: PXE context
  * @file_path: File path to read (relative to the PXE file)
  * @file_addr: Address to load file to
+ * @filesizep: If not NULL, returns the file size in bytes
  * Returns 1 for success, or < 0 on error
  */
 static int get_relfile(struct pxe_context *ctx, const char *file_path,
-		       unsigned long file_addr)
+		       unsigned long file_addr, ulong *filesizep)
 {
 	size_t path_len;
 	char relfile[MAX_TFTP_PATH_LEN + 1];
 	char addr_buf[18];
+	ulong size;
+	int ret;
 
 	if (file_path[0] == '/' && ctx->allow_abs_path)
 		*relfile = '\0';
@@ -103,7 +120,13 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
 
 	sprintf(addr_buf, "%lx", file_addr);
 
-	return ctx->getfile(ctx, relfile, addr_buf);
+	ret = ctx->getfile(ctx, relfile, addr_buf, &size);
+	if (ret < 0)
+		return log_msg_ret("get", ret);
+	if (filesizep)
+		*filesizep = size;
+
+	return 1;
 }
 
 /**
@@ -117,29 +140,17 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
  * Returns 1 for success, or < 0 on error
  */
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
-		 unsigned long file_addr)
+		 ulong file_addr)
 {
-	unsigned long config_file_size;
-	char *tftp_filesize;
+	ulong size;
 	int err;
 	char *buf;
 
-	err = get_relfile(ctx, file_path, file_addr);
+	err = get_relfile(ctx, file_path, file_addr, &size);
 	if (err < 0)
 		return err;
 
-	/*
-	 * the file comes without a NUL byte at the end, so find out its size
-	 * and add the NUL byte.
-	 */
-	tftp_filesize = from_env("filesize");
-	if (!tftp_filesize)
-		return -ENOENT;
-
-	if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
-		return -EINVAL;
-
-	buf = map_sysmem(file_addr + config_file_size, 1);
+	buf = map_sysmem(file_addr + size, 1);
 	*buf = '\0';
 	unmap_sysmem(buf);
 
@@ -184,12 +195,13 @@ int get_pxelinux_path(struct pxe_context *ctx, const char *file,
  * @file_path: File path to read (relative to the PXE file)
  * @envaddr_name: Name of environment variable which contains the address to
  *	load to
+ * @filesizep: Returns the file size in bytes
  * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an
  *	environment variable, -EINVAL if its format is not valid hex, or other
  *	value < 0 on other error
  */
 static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
-			       const char *envaddr_name)
+			       const char *envaddr_name, ulong *filesizep)
 {
 	unsigned long file_addr;
 	char *envaddr;
@@ -201,7 +213,7 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
 	if (strict_strtoul(envaddr, 16, &file_addr) < 0)
 		return -EINVAL;
 
-	return get_relfile(ctx, file_path, file_addr);
+	return get_relfile(ctx, file_path, file_addr, filesizep);
 }
 
 /**
@@ -357,8 +369,8 @@ static void label_boot_fdtoverlay(struct pxe_context *ctx,
 			goto skip_overlay;
 
 		/* Load overlay file */
-		err = get_relfile_envaddr(ctx, overlayfile,
-					  "fdtoverlay_addr_r");
+		err = get_relfile_envaddr(ctx, overlayfile, "fdtoverlay_addr_r",
+					  NULL);
 		if (err < 0) {
 			printf("Failed loading overlay %s\n", overlayfile);
 			goto skip_overlay;
@@ -438,7 +450,10 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 	}
 
 	if (label->initrd) {
-		if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r") < 0) {
+		ulong size;
+
+		if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r",
+					&size) < 0) {
 			printf("Skipping %s for failure retrieving initrd\n",
 			       label->name);
 			return 1;
@@ -447,11 +462,12 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 		bootm_argv[2] = initrd_str;
 		strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
 		strcat(bootm_argv[2], ":");
-		strncat(bootm_argv[2], env_get("filesize"), 9);
+		strcat(bootm_argv[2], simple_xtoa(size));
 		bootm_argc = 3;
 	}
 
-	if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r") < 0) {
+	if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r",
+				NULL) < 0) {
 		printf("Skipping %s for failure retrieving kernel\n",
 		       label->name);
 		return 1;
@@ -592,7 +608,7 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 
 		if (fdtfile) {
 			int err = get_relfile_envaddr(ctx, fdtfile,
-						      "fdt_addr_r");
+						      "fdt_addr_r", NULL);
 
 			free(fdtfilefree);
 			if (err < 0) {
@@ -1384,7 +1400,7 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 	if (IS_ENABLED(CONFIG_CMD_BMP)) {
 		/* display BMP if available */
 		if (cfg->bmp) {
-			if (get_relfile(ctx, cfg->bmp, image_load_addr)) {
+			if (get_relfile(ctx, cfg->bmp, image_load_addr, NULL)) {
 				if (CONFIG_IS_ENABLED(CMD_CLS))
 					run_command("cls", 0);
 				bmp_display(image_load_addr,
cmd/pxe.c +6 -1
index e319db51ef5..81703386c42 100644
@@ -25,15 +25,20 @@ const char *pxe_default_paths[] = {
 };
 
 static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
-		       char *file_addr)
+		       char *file_addr, ulong *sizep)
 {
 	char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
+	int ret;
 
 	tftp_argv[1] = file_addr;
 	tftp_argv[2] = (void *)file_path;
 
 	if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
 		return -ENOENT;
+	ret = pxe_get_file_size(sizep);
+	if (ret)
+		return log_msg_ret("tftp", ret);
+	ctx->pxe_file_size = *sizep;
 
 	return 1;
 }
cmd/sysboot.c +18 -3
index c45fed774d6..6344ecd357b 100644
@@ -9,43 +9,58 @@
 static char *fs_argv[5];
 
 static int do_get_ext2(struct pxe_context *ctx, const char *file_path,
-		       char *file_addr)
+		       char *file_addr, ulong *sizep)
 {
 #ifdef CONFIG_CMD_EXT2
+	int ret;
+
 	fs_argv[0] = "ext2load";
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
 	if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv))
 		return 1;
+	ret = pxe_get_file_size(sizep);
+	if (ret)
+		return log_msg_ret("tftp", ret);
 #endif
 	return -ENOENT;
 }
 
 static int do_get_fat(struct pxe_context *ctx, const char *file_path,
-		      char *file_addr)
+		      char *file_addr, ulong *sizep)
 {
 #ifdef CONFIG_CMD_FAT
+	int ret;
+
 	fs_argv[0] = "fatload";
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
 	if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv))
 		return 1;
+	ret = pxe_get_file_size(sizep);
+	if (ret)
+		return log_msg_ret("tftp", ret);
 #endif
 	return -ENOENT;
 }
 
 static int do_get_any(struct pxe_context *ctx, const char *file_path,
-		      char *file_addr)
+		      char *file_addr, ulong *sizep)
 {
 #ifdef CONFIG_CMD_FS_GENERIC
+	int ret;
+
 	fs_argv[0] = "load";
 	fs_argv[3] = file_addr;
 	fs_argv[4] = (void *)file_path;
 
 	if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
 		return 1;
+	ret = pxe_get_file_size(sizep);
+	if (ret)
+		return log_msg_ret("tftp", ret);
 #endif
 	return -ENOENT;
 }
include/pxe_utils.h +12 -1
index 8b50f2e6861..194a5ed8cc7 100644
@@ -77,7 +77,7 @@ struct pxe_menu {
 
 struct pxe_context;
 typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
-				char *file_addr);
+				char *file_addr, ulong *filesizep);
 
 /**
  * struct pxe_context - context information for PXE parsing
@@ -88,6 +88,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  * @allow_abs_path: true to allow absolute paths
  * @bootdir: Directory that files are loaded from ("" if no directory). This is
  *	allocated
+ * @pxe_file_size: Size of the PXE file
  */
 struct pxe_context {
 	struct cmd_tbl *cmdtp;
@@ -98,6 +99,7 @@ struct pxe_context {
 	 * @file_path: Path to the file
 	 * @file_addr: String containing the hex address to put the file in
 	 *	memory
+	 * @filesizep: Returns the file size in bytes
 	 * Return 0 if OK, -ve on error
 	 */
 	pxe_getfile_func getfile;
@@ -105,6 +107,7 @@ struct pxe_context {
 	void *userdata;
 	bool allow_abs_path;
 	char *bootdir;
+	ulong pxe_file_size;
 };
 
 /**
@@ -225,4 +228,12 @@ void pxe_destroy_ctx(struct pxe_context *ctx);
  */
 int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt);
 
+/**
+ * pxe_get_file_size() - Read the value of the 'filesize' environment variable
+ *
+ * @sizep: Place to put the value
+ * @return 0 if OK, -ENOENT if no such variable, -EINVAL if format is invalid
+ */
+int pxe_get_file_size(ulong *sizep);
+
 #endif /* __PXE_UTILS_H */
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#16 lore raw

PATCH 16/28 pxe: Refactor sysboot to have one helper

In reply to Simon Glass

The only difference between the three helpers is the filesystem type. Factor this out and call the filesystem functions directly, instead of through the command-line interpreter. This allows the file size to be obtained directly, instead of via an environment variable.

We cannot do the same thing with PXE's tftpboot since there is no API at present to obtain information about the file that was read. So there is no point in changing pxe_getfile_func to use a ulong for the address, for example.

This is as far as the refactoring can go for the present.

---

 cmd/sysboot.c | 94 ++++++++++++++++++++-------------------------------
 1 file changed, 36 insertions(+), 58 deletions(-)
cmd/sysboot.c +36 -58
index 6344ecd357b..04c07020269 100644
@@ -6,63 +6,40 @@
 #include <fs.h>
 #include <pxe_utils.h>
 
-static char *fs_argv[5];
-
-static int do_get_ext2(struct pxe_context *ctx, const char *file_path,
-		       char *file_addr, ulong *sizep)
+/**
+ * struct sysboot_info - useful information for sysboot helpers
+ *
+ * @fstype: Filesystem type (FS_TYPE_...)
+ * @ifname: Interface name (e.g. "ide", "scsi")
+ * @dev_part_str is in the format:
+ *	<dev>.<hw_part>:<part> where <dev> is the device number,
+ *	<hw_part> is the optional hardware partition number and
+ *	<part> is the partition number
+ */
+struct sysboot_info {
+	int fstype;
+	const char *ifname;
+	const char *dev_part_str;
+};
+
+static int sysboot_read_file(struct pxe_context *ctx, const char *file_path,
+			     char *file_addr, ulong *sizep)
 {
-#ifdef CONFIG_CMD_EXT2
+	struct sysboot_info *info = ctx->userdata;
+	loff_t len_read;
+	ulong addr;
 	int ret;
 
-	fs_argv[0] = "ext2load";
-	fs_argv[3] = file_addr;
-	fs_argv[4] = (void *)file_path;
-
-	if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv))
-		return 1;
-	ret = pxe_get_file_size(sizep);
+	addr = simple_strtoul(file_addr, NULL, 16);
+	ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype);
 	if (ret)
-		return log_msg_ret("tftp", ret);
-#endif
-	return -ENOENT;
-}
-
-static int do_get_fat(struct pxe_context *ctx, const char *file_path,
-		      char *file_addr, ulong *sizep)
-{
-#ifdef CONFIG_CMD_FAT
-	int ret;
-
-	fs_argv[0] = "fatload";
-	fs_argv[3] = file_addr;
-	fs_argv[4] = (void *)file_path;
-
-	if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv))
-		return 1;
-	ret = pxe_get_file_size(sizep);
+		return ret;
+	ret = fs_read(file_path, addr, 0, 0, &len_read);
 	if (ret)
-		return log_msg_ret("tftp", ret);
-#endif
-	return -ENOENT;
-}
-
-static int do_get_any(struct pxe_context *ctx, const char *file_path,
-		      char *file_addr, ulong *sizep)
-{
-#ifdef CONFIG_CMD_FS_GENERIC
-	int ret;
-
-	fs_argv[0] = "load";
-	fs_argv[3] = file_addr;
-	fs_argv[4] = (void *)file_path;
+		return ret;
+	*sizep = len_read;
 
-	if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
-		return 1;
-	ret = pxe_get_file_size(sizep);
-	if (ret)
-		return log_msg_ret("tftp", ret);
-#endif
-	return -ENOENT;
+	return 0;
 }
 
 /*
@@ -74,9 +51,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
 	unsigned long pxefile_addr_r;
-	pxe_getfile_func getfile;
 	struct pxe_context ctx;
 	char *pxefile_addr_str;
+	struct sysboot_info info;
 	char *filename;
 	int prompt = 0;
 	int ret;
@@ -106,24 +83,25 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	if (strstr(argv[3], "ext2")) {
-		getfile = do_get_ext2;
+		info.fstype = FS_TYPE_EXT;
 	} else if (strstr(argv[3], "fat")) {
-		getfile = do_get_fat;
+		info.fstype = FS_TYPE_FAT;
 	} else if (strstr(argv[3], "any")) {
-		getfile = do_get_any;
+		info.fstype = FS_TYPE_ANY;
 	} else {
 		printf("Invalid filesystem: %s\n", argv[3]);
 		return 1;
 	}
-	fs_argv[1] = argv[1];
-	fs_argv[2] = argv[2];
+	info.ifname = argv[1];
+	info.dev_part_str = argv[2];
 
 	if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
 		printf("Invalid pxefile address: %s\n", pxefile_addr_str);
 		return 1;
 	}
 
-	if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) {
+	if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true,
+			  filename)) {
 		printf("Out of memory\n");
 		return CMD_RET_FAILURE;
 	}
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#17 lore raw

PATCH 17/28 doc: Move distro boot doc to rST

In reply to Simon Glass

Move this over to the new rST format.

---

 doc/{README.distro => develop/distro.rst} | 177 ++++++++++------------
 doc/develop/index.rst                     |   1 +
 2 files changed, 80 insertions(+), 98 deletions(-)
 rename doc/{README.distro => develop/distro.rst} (76%)
doc/develop/distro.rst renamed from doc/README.distro +79 -98
similarity index 76%
rename from doc/README.distro
rename to doc/develop/distro.rst
index c4f041ca712..105dcf28190 100644
@@ -1,9 +1,4 @@
-SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2014 Red Hat Inc.
- * Copyright (c) 2014-2015, NVIDIA CORPORATION.  All rights reserved.
- * Copyright (C) 2015 K. Merker <[email protected]>
- */
+.. SPDX-License-Identifier: GPL-2.0+
 
 Generic Distro Configuration Concept
 ====================================
@@ -73,9 +68,8 @@ Boot Configuration Files
 
 The standard format for boot configuration files is that of extlinux.conf, as
 handled by U-Boot's "syslinux" (disk) or "pxe boot" (network). This is roughly
-as specified at:
+as specified at BootLoaderSpec_:
 
-http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
 
 ... with the exceptions that the BootLoaderSpec document:
 
@@ -87,73 +81,70 @@ http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
 * Does not document the fdtdir option, which automatically selects the DTB to
   pass to the kernel.
 
-One example extlinux.conf generated by the Fedora installer is:
+One example extlinux.conf generated by the Fedora installer is::
 
-------------------------------------------------------------
-# extlinux.conf generated by anaconda
+    # extlinux.conf generated by anaconda
 
-ui menu.c32
+    ui menu.c32
 
-menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a key for options.
-menu title Fedora Boot Options.
-menu hidden
+    menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a key for options.
+    menu title Fedora Boot Options.
+    menu hidden
 
-timeout 50
-#totaltimeout 9000
+    timeout 50
+    #totaltimeout 9000
 
-default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
+    default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
 
-label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
-	kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
-	append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
-	fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
-	initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
+    label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
+        kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
+        append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
+        fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
+        initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
 
-label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
-	kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
-	append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
-	fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
-	initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
+    label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
+        kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
+        append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
+        fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
+        initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
 
-label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc (0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
-	kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
-	initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
-	append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8
-	fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
-------------------------------------------------------------
+    label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc (0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
+        kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
+        initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
+        append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 console=ttyS0,115200n8
+        fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
 
-Another hand-crafted network boot configuration file is:
 
-------------------------------------------------------------
-TIMEOUT 100
+Another hand-crafted network boot configuration file is::
 
-MENU TITLE TFTP boot options
+    TIMEOUT 100
 
-LABEL jetson-tk1-emmc
-        MENU LABEL ../zImage root on Jetson TK1 eMMC
-        LINUX ../zImage
-        FDTDIR ../
-        APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=80a5a8e9-c744-491a-93c1-4f4194fd690b
+    MENU TITLE TFTP boot options
 
-LABEL venice2-emmc
-        MENU LABEL ../zImage root on Venice2 eMMC
-        LINUX ../zImage
-        FDTDIR ../
-        APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=5f71e06f-be08-48ed-b1ef-ee4800cc860f
+    LABEL jetson-tk1-emmc
+            MENU LABEL ../zImage root on Jetson TK1 eMMC
+            LINUX ../zImage
+            FDTDIR ../
+            APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=80a5a8e9-c744-491a-93c1-4f4194fd690b
 
-LABEL sdcard
-        MENU LABEL ../zImage, root on 2GB sdcard
-        LINUX ../zImage
-        FDTDIR ../
-        APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=b2f82cda-2535-4779-b467-094a210fbae7
+    LABEL venice2-emmc
+            MENU LABEL ../zImage root on Venice2 eMMC
+            LINUX ../zImage
+            FDTDIR ../
+            APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=5f71e06f-be08-48ed-b1ef-ee4800cc860f
 
-LABEL fedora-installer-fk
-        MENU LABEL Fedora installer w/ Fedora kernel
-        LINUX fedora-installer/vmlinuz
-        INITRD fedora-installer/initrd.img.orig
-        FDTDIR fedora-installer/dtb
-        APPEND loglevel=8 ip=dhcp inst.repo=http://10.0.0.2/mirrors/fedora/linux/development/rawhide/armhfp/os/ rd.shell cma=64M
-------------------------------------------------------------
+    LABEL sdcard
+            MENU LABEL ../zImage, root on 2GB sdcard
+            LINUX ../zImage
+            FDTDIR ../
+            APPEND console=ttyS0,115200n8 console=tty1 loglevel=8 rootwait rw earlyprintk root=PARTUUID=b2f82cda-2535-4779-b467-094a210fbae7
+
+    LABEL fedora-installer-fk
+            MENU LABEL Fedora installer w/ Fedora kernel
+            LINUX fedora-installer/vmlinuz
+            INITRD fedora-installer/initrd.img.orig
+            FDTDIR fedora-installer/dtb
+            APPEND loglevel=8 ip=dhcp inst.repo=http://10.0.0.2/mirrors/fedora/linux/development/rawhide/armhfp/os/ rd.shell cma=64M
 
 U-Boot Implementation
 =====================
@@ -166,13 +157,11 @@ 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.
 
-In your board configuration file, include the following:
+In your board configuration file, include the following::
 
-------------------------------------------------------------
-#ifndef CONFIG_SPL_BUILD
-#include <config_distro_bootcmd.h>
-#endif
-------------------------------------------------------------
+    #ifndef CONFIG_SPL_BUILD
+    #include <config_distro_bootcmd.h>
+    #endif
 
 The first of those headers primarily enables a core set of U-Boot features,
 such as support for MBR and GPT partitions, ext* and FAT filesystems, booting
@@ -205,7 +194,6 @@ CONFIG_EXTRA_ENV_SETTINGS in the board's U-Boot configuration file, so that
 the user doesn't have to configure them.
 
 fdt_addr:
-
   Mandatory for any system that provides the DTB in HW (e.g. ROM) and wishes
   to pass that DTB to Linux, rather than loading a DTB from the boot
   filesystem. Prohibited for any other system.
@@ -214,7 +202,6 @@ fdt_addr:
   address.
 
 fdt_addr_r:
-
   Mandatory. The location in RAM where the DTB will be loaded or copied to when
   processing the fdtdir/devicetreedir or fdt/devicetree options in
   extlinux.conf.
@@ -225,7 +212,6 @@ fdt_addr_r:
   A size of 1MB for the FDT/DTB seems reasonable.
 
 fdtfile:
-
   Mandatory. the name of the DTB file for the specific board for instance
   the espressobin v5 board the value is "marvell/armada-3720-espressobin.dtb"
   while on a clearfog pro it is "armada-388-clearfog-pro.dtb" in the case of
@@ -236,16 +222,14 @@ fdtfile:
   SoC vendor directories. 
 
 ramdisk_addr_r:
-
   Mandatory. The location in RAM where the initial ramdisk will be loaded to
   when processing the initrd option in extlinux.conf.
 
-  It is recommended that this location be highest in RAM out of fdt_addr_,
+  It is recommended that this location be highest in RAM out of fdt_addr_r,
   kernel_addr_r, and ramdisk_addr_r, so that the RAM disk can vary in size
   and use any available RAM.
 
 kernel_addr_r:
-
   Mandatory. The location in RAM where the kernel will be loaded to when
   processing the kernel option in the extlinux.conf.
 
@@ -270,14 +254,12 @@ kernel_comp_size:
   size has to at least the size of loaded image for decompression to succeed.
 
 pxefile_addr_r:
-
   Mandatory. The location in RAM where extlinux.conf will be loaded to prior
   to processing.
 
   A size of 1MB for extlinux.conf is more than adequate.
 
 scriptaddr:
-
   Mandatory, if the boot script is boot.scr rather than extlinux.conf. The
   location in RAM where boot.scr will be loaded to prior to execution.
 
@@ -292,24 +274,22 @@ MEM_LAYOUT_ENV_SETTINGS in include/configs/tegra124-common.h.
 Boot Target Configuration
 -------------------------
 
-<config_distro_bootcmd.h> defines $bootcmd and many helper command variables
-that automatically search attached disks for boot configuration files and
-execute them. Boards must provide configure <config_distro_bootcmd.h> so that
-it supports the correct set of possible boot device types. To provide this
+The `config_distro_bootcmd.h` file defines $bootcmd and many helper command
+variables that automatically search attached disks for boot configuration files
+and execute them. Boards must provide configure <config_distro_bootcmd.h> so
+that it supports the correct set of possible boot device types. To provide this
 configuration, simply define macro BOOT_TARGET_DEVICES prior to including
-<config_distro_bootcmd.h>. For example:
-
-------------------------------------------------------------
-#ifndef CONFIG_SPL_BUILD
-#define BOOT_TARGET_DEVICES(func) \
-        func(MMC, mmc, 1) \
-        func(MMC, mmc, 0) \
-        func(USB, usb, 0) \
-        func(PXE, pxe, na) \
-        func(DHCP, dhcp, na)
-#include <config_distro_bootcmd.h>
-#endif
-------------------------------------------------------------
+<config_distro_bootcmd.h>. For example::
+
+    #ifndef CONFIG_SPL_BUILD
+    #define BOOT_TARGET_DEVICES(func) \
+            func(MMC, mmc, 1) \
+            func(MMC, mmc, 0) \
+            func(USB, usb, 0) \
+            func(PXE, pxe, na) \
+            func(DHCP, dhcp, na)
+    #include <config_distro_bootcmd.h>
+    #endif
 
 Each entry in the macro defines a single boot device (e.g. a specific eMMC
 device or SD card) or type of boot device (e.g. USB disk). The parameters to
@@ -328,7 +308,6 @@ up by <config_distro_bootcmd.h>. After this, various environment variables may
 be altered to influence the boot process:
 
 boot_targets:
-
   The list of boot locations searched.
 
   Example: mmc0, mmc1, usb, pxe
@@ -336,7 +315,6 @@ boot_targets:
   Entries may be removed or re-ordered in this list to affect the boot order.
 
 boot_prefixes:
-
   For disk-based booting, the list of directories within a partition that are
   searched for boot configuration files (extlinux.conf, boot.scr).
 
@@ -346,7 +324,6 @@ boot_prefixes:
   directories which are searched.
 
 boot_scripts:
-
   The name of U-Boot style boot.scr files that $bootcmd searches for.
 
   Example: boot.scr.uimg boot.scr
@@ -358,17 +335,14 @@ boot_scripts:
   filenames which are supported.
 
 scan_dev_for_extlinux:
-
   If you want to disable extlinux.conf on all disks, set the value to something
   innocuous, e.g. setenv scan_dev_for_extlinux true.
 
 scan_dev_for_scripts:
-
   If you want to disable boot.scr on all disks, set the value to something
   innocuous, e.g. setenv scan_dev_for_scripts true.
 
 boot_net_usb_start:
-
   If you want to prevent USB enumeration by distro boot commands which execute
   network operations, set the value to something innocuous, e.g. setenv
   boot_net_usb_start true. This would be useful if you know your Ethernet
@@ -376,7 +350,6 @@ boot_net_usb_start:
   avoiding unnecessary actions.
 
 boot_net_pci_enum:
-
   If you want to prevent PCI enumeration by distro boot commands which execute
   network operations, set the value to something innocuous, e.g. setenv
   boot_net_pci_enum true. This would be useful if you know your Ethernet
@@ -412,10 +385,12 @@ Examples:
 The list of possible targets consists of:
 
 - network targets
+
   * dhcp
   * pxe
 
 - storage targets (to which a device number must be appended)
+
   * mmc
   * sata
   * scsi
@@ -428,3 +403,9 @@ of the boot environment and are not guaranteed to exist or work in the same
 way in future u-boot versions.  In particular the <device type>_boot
 variables (e.g. mmc_boot, usb_boot) are a strictly internal implementation
 detail and must not be used as a public interface.
+
+.. _BootLoaderSpec: http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
+
+.. sectionauthor:: (C) Copyright 2014 Red Hat Inc.
+.. sectionauthor:: Copyright (c) 2014-2015, NVIDIA CORPORATION.  All rights reserved.
+.. sectionauthor:: Copyright (C) 2015 K. Merker <[email protected]>
doc/develop/index.rst +1 -0
index 83c929babda..1fb0f06f6e8 100644
@@ -12,6 +12,7 @@ Implementation
    ci_testing
    commands
    devicetree/index
+   distro
    driver-model/index
    global_data
    logging
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#18 lore raw

PATCH 18/28 pxe: Allow calling the pxe_get logic directly

In reply to Simon Glass

Refactor this code so that we can call the 'pxe get' command without going through the command-line interpreter. This makes it easier to get the information we need, without going through environment variables.

---

 cmd/pxe.c           | 92 +++++++++++++++++++++++++++++----------------
 include/pxe_utils.h | 14 +++++++
 2 files changed, 73 insertions(+), 33 deletions(-)
cmd/pxe.c +59 -33
index 81703386c42..db8e4697f24 100644
@@ -104,6 +104,49 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_
 
 	return -ENOENT;
 }
+
+int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep)
+{
+	struct cmd_tbl cmdtp[] = {};	/* dummy */
+	struct pxe_context ctx;
+	int i;
+
+	if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
+			  env_get("bootfile")))
+		return -ENOMEM;
+	/*
+	 * Keep trying paths until we successfully get a file we're looking
+	 * for.
+	 */
+	if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 ||
+	    pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
+	    pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0)
+		goto done;
+
+	i = 0;
+	while (pxe_default_paths[i]) {
+		if (get_pxelinux_path(&ctx, pxe_default_paths[i],
+				      pxefile_addr_r) > 0)
+			goto done;
+		i++;
+	}
+
+	pxe_destroy_ctx(&ctx);
+
+	return -ENOENT;
+done:
+	*bootdirp = env_get("bootfile");
+
+	/*
+	 * The PXE file size is returned but not the name. It is probably not
+	 * that useful.
+	 */
+	*sizep = ctx.pxe_file_size;
+	pxe_destroy_ctx(&ctx);
+
+	return 0;
+}
+
 /*
  * Entry point for the 'pxe get' command.
  * This Follows pxelinux's rules to download a config file from a tftp server.
@@ -122,9 +165,10 @@ static int
 do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	char *pxefile_addr_str;
-	unsigned long pxefile_addr_r;
-	struct pxe_context ctx;
-	int err, i = 0;
+	ulong pxefile_addr_r;
+	char *fname;
+	ulong size;
+	int ret;
 
 	if (argc != 1)
 		return CMD_RET_USAGE;
@@ -134,43 +178,25 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (!pxefile_addr_str)
 		return 1;
 
-	err = strict_strtoul(pxefile_addr_str, 16,
+	ret = strict_strtoul(pxefile_addr_str, 16,
 			     (unsigned long *)&pxefile_addr_r);
-	if (err < 0)
+	if (ret < 0)
 		return 1;
 
-	if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
-			  env_get("bootfile"))) {
+	ret = pxe_get(pxefile_addr_r, &fname, &size);
+	switch (ret) {
+	case 0:
+		printf("Config file '%s' found\n", fname);
+		break;
+	case -ENOMEM:
 		printf("Out of memory\n");
 		return CMD_RET_FAILURE;
+	default:
+		printf("Config file not found\n");
+		return CMD_RET_FAILURE;
 	}
-	/*
-	 * Keep trying paths until we successfully get a file we're looking
-	 * for.
-	 */
-	if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 ||
-	    pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
-	    pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
-		printf("Config file found\n");
-		pxe_destroy_ctx(&ctx);
-
-		return 0;
-	}
-
-	while (pxe_default_paths[i]) {
-		if (get_pxelinux_path(&ctx, pxe_default_paths[i],
-				      pxefile_addr_r) > 0) {
-			printf("Config file found\n");
-			pxe_destroy_ctx(&ctx);
-			return 0;
-		}
-		i++;
-	}
-
-	printf("Config file not found\n");
-	pxe_destroy_ctx(&ctx);
 
-	return 1;
+	return 0;
 }
 
 /*
include/pxe_utils.h +14 -0
index 194a5ed8cc7..b7037f841a6 100644
@@ -236,4 +236,18 @@ int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt);
  */
 int pxe_get_file_size(ulong *sizep);
 
+/**
+ * pxe_get() - Get the PXE file from the server
+ *
+ * This tries various filenames to obtain a PXE file
+ *
+ * @pxefile_addr_r: Address to put file
+ * @bootdirp: Returns the boot filename, or NULL if none. This is the 'bootfile'
+ *	option provided by the DHCP server. If none, returns NULL. For example,
+ *	"rpi/info", which indicates that all files should be fetched from the
+ *	"rpi/" subdirectory
+ * @sizep: Size of the PXE file (not bootfile)
+ */
+int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep);
+
 #endif /* __PXE_UTILS_H */
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#19 lore raw

PATCH 19/28 bootmethod: Add the uclass and core implementation

In reply to Simon Glass

Add a uclass for bootmethod and the various helpers needed to make it work.

---

 MAINTAINERS            |   6 +
 boot/Kconfig           |   9 +
 boot/Makefile          |   1 +
 boot/bootmethod.c      | 445 +++++++++++++++++++++++++++++++++++++++++
 include/bootmethod.h   | 355 ++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h |   1 +
 6 files changed, 817 insertions(+)
 create mode 100644 boot/bootmethod.c
 create mode 100644 include/bootmethod.h
MAINTAINERS +6 -0
index 776ff703b9b..d977cee562b 100644
@@ -630,6 +630,12 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	tools/binman/
 
+BOOTMETHOD
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	boot/bootmethod.c
+F:	include/bootmethod.h
+
 BTRFS
 M:	Marek Behun <[email protected]>
 R:	Qu Wenruo <[email protected]>
boot/Kconfig +9 -0
index 0d4c38402c1..90f716c3ef1 100644
@@ -290,6 +290,15 @@ endif # SPL
 
 endif # FIT
 
+config BOOTMETHOD
+	bool "Bootmethod support"
+	default y
+	help
+	  A bootmethod is a standard way of locating something to boot,
+	  typically an Operating System such as Linux. Enable this to support
+	  iterating through available bootmethods to find a bootflow suitable
+	  for booting.
+
 config LEGACY_IMAGE_FORMAT
 	bool "Enable support for the legacy image format"
 	default y if !FIT_SIGNATURE
boot/Makefile +1 -0
index e8f984248e6..10d427e115c 100644
@@ -22,6 +22,7 @@ endif
 obj-y += image.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD) += bootmethod.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/bootmethod.c new file +445 -0

445 lines not on this page · raw message

include/bootmethod.h new file +355 -0

355 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index e7edd409f30..116d2f02f26 100644
@@ -38,6 +38,7 @@ enum uclass_id {
 	UCLASS_AXI,		/* AXI bus */
 	UCLASS_BLK,		/* Block device */
 	UCLASS_BOOTCOUNT,       /* Bootcount backing store */
+	UCLASS_BOOTMETHOD,	/* Bootmethod for locating an OS to boot*/
 	UCLASS_BUTTON,		/* Button */
 	UCLASS_CACHE,		/* Cache controller */
 	UCLASS_CLK,		/* Clock source, e.g. used by peripherals */
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#20 lore raw

PATCH 20/28 bootmethod: Add an implementation of distro boot

In reply to Simon Glass

Add a bootmethod type which handles distro boot, so we can boot a bootflow using this commonly used mechanism.

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

For now this requires the 'pxe' command be enabled.

---

 MAINTAINERS          |   2 +
 boot/Kconfig         |  11 +++
 boot/Makefile        |   1 +
 boot/bootmethod.c    |  14 ++++
 boot/distro.c        | 194 +++++++++++++++++++++++++++++++++++++++++++
 include/bootmethod.h |   2 +
 include/distro.h     |  62 ++++++++++++++
 7 files changed, 286 insertions(+)
 create mode 100644 boot/distro.c
 create mode 100644 include/distro.h
MAINTAINERS +2 -0
index d977cee562b..f78141c138b 100644
@@ -634,7 +634,9 @@ BOOTMETHOD
 M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	boot/bootmethod.c
+F:	boot/distro.c
 F:	include/bootmethod.h
+F:	include/distro.h
 
 BTRFS
 M:	Marek Behun <[email protected]>
boot/Kconfig +11 -0
index 90f716c3ef1..8565fbeab84 100644
@@ -299,6 +299,17 @@ config BOOTMETHOD
 	  iterating through available bootmethods to find a bootflow suitable
 	  for booting.
 
+config BOOTMETHOD_DISTRO
+	bool "Bootmethod support for distro boot"
+	depends on BOOTMETHOD && CMD_PXE
+	default y
+	help
+	  Enables support for distro boot using bootmethods. This makes the
+	  bootmethods look for a 'extlinux/extlinux.conf' on each filesystem
+	  they scan.
+
+	  This provides a way to try out bootmethod on an existing boot flow.
+
 config LEGACY_IMAGE_FORMAT
 	bool "Enable support for the legacy image format"
 	default y if !FIT_SIGNATURE
boot/Makefile +1 -0
index 10d427e115c..4ce721242b0 100644
@@ -23,6 +23,7 @@ obj-y += image.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD) += bootmethod.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD_DISTRO) += distro.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/bootmethod.c +14 -0
index 8e4157c6a47..be9d4aa02cc 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <blk.h>
 #include <bootmethod.h>
+#include <distro.h>
 #include <dm.h>
 #include <fs.h>
 #include <log.h>
@@ -34,6 +35,7 @@ static const char *const bootmethod_state[BOOTFLOWST_COUNT] = {
 };
 
 static const char *const bootmethod_type[BOOTFLOWT_COUNT] = {
+	"distro-boot",
 };
 
 int bootmethod_get_state(struct bootflow_state **statep)
@@ -360,6 +362,12 @@ int bootmethod_find_in_blk(struct udevice *dev, struct udevice *blk, int seq,
 
 	bflow->state = BOOTFLOWST_FS;
 
+	if (CONFIG_IS_ENABLED(BOOTMETHOD_DISTRO)) {
+		ret = distro_boot_setup(desc, partnum, bflow);
+		if (ret)
+			return log_msg_ret("distro", ret);
+	}
+
 	return 0;
 }
 
@@ -372,6 +380,12 @@ int bootflow_boot(struct bootflow *bflow)
 		return log_msg_ret("load", -EPROTO);
 
 	switch (bflow->type) {
+	case BOOTFLOWT_DISTRO:
+		if (CONFIG_IS_ENABLED(BOOTMETHOD_DISTRO)) {
+			done = true;
+			ret = distro_boot(bflow);
+		}
+		break;
 	case BOOTFLOWT_COUNT:
 		break;
 	}
boot/distro.c new file +194 -0

194 lines not on this page · raw message

include/bootmethod.h +2 -0
index a45897b0c0c..d80be556b8a 100644
@@ -24,6 +24,8 @@ enum bootflow_state_t {
 };
 
 enum bootflow_type_t {
+	BOOTFLOWT_DISTRO,	/**< Distro boot */
+
 	BOOTFLOWT_COUNT,
 };
 
include/distro.h new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#21 lore raw

PATCH 21/28 bootmethod: Add a command

In reply to Simon Glass

Add a 'bootmethod' command to handle listing and selection of bootmethods.

---

 MAINTAINERS      |   1 +
 cmd/Kconfig      |   8 +++
 cmd/bootmethod.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 cmd/bootmethod.c
MAINTAINERS +1 -0
index f78141c138b..655746265f8 100644
@@ -635,6 +635,7 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	boot/bootmethod.c
 F:	boot/distro.c
+F:	cmd/bootmethod.c
 F:	include/bootmethod.h
 F:	include/distro.h
 
cmd/Kconfig +8 -0
index ffef3cc76ca..eec0dee8773 100644
@@ -194,6 +194,14 @@ config CMD_BOOTM
 	help
 	  Boot an application image from the memory.
 
+config CMD_BOOTMETHOD
+	bool "bootmethod"
+	default y if BOOTMETHOD
+	help
+	  Support working with bootmethods, including listing available ones
+	  and showing information about a particular one. It also allows
+	  looking at bootflows available with the bootmethod.
+
 config BOOTM_EFI
 	bool "Support booting UEFI FIT images"
 	depends on CMD_BOOTEFI && CMD_BOOTM && FIT
cmd/bootmethod.c new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#22 lore raw

PATCH 22/28 bootflow: Add a command

In reply to Simon Glass

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

---

 MAINTAINERS       |   1 +
 boot/bootmethod.c |  26 +++
 cmd/Makefile      |   1 +
 cmd/bootflow.c    | 399 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 427 insertions(+)
 create mode 100644 cmd/bootflow.c
MAINTAINERS +1 -0
index 655746265f8..367193358b7 100644
@@ -635,6 +635,7 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	boot/bootmethod.c
 F:	boot/distro.c
+F:	cmd/bootflow.c
 F:	cmd/bootmethod.c
 F:	include/bootmethod.h
 F:	include/distro.h
boot/bootmethod.c +26 -0
index be9d4aa02cc..b9752f75e54 100644
@@ -404,6 +404,32 @@ int bootflow_boot(struct bootflow *bflow)
 	return log_msg_ret("end", -EFAULT);
 }
 
+void bootmethod_list(bool probe)
+{
+	struct udevice *dev;
+	int ret;
+	int i;
+
+	printf("Seq  Probed  Status  Uclass    Name\n");
+	printf("---  ------  ------  --------  ------------------\n");
+	if (probe)
+		ret = uclass_first_device_err(UCLASS_BOOTMETHOD, &dev);
+	else
+		ret = uclass_find_first_device(UCLASS_BOOTMETHOD, &dev);
+	for (i = 0; dev; i++) {
+		printf("%3x   [ %c ]  %6s  %-9.9s %s\n", dev_seq(dev),
+		       device_active(dev) ? '+' : ' ',
+		       ret ? simple_itoa(ret) : "OK",
+		       dev_get_uclass_name(dev_get_parent(dev)), dev->name);
+		if (probe)
+			ret = uclass_next_device_err(&dev);
+		else
+			ret = uclass_find_next_device(&dev);
+	}
+	printf("---  ------  ------  --------  ------------------\n");
+	printf("(%d device%s)\n", i, i != 1 ? "s" : "");
+}
+
 int bootmethod_setup_for_dev(struct udevice *parent, const char *drv_name)
 {
 	struct udevice *bm;
cmd/Makefile +1 -0
index 891819ae0f6..f6ad648c94e 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_BOOTMETHOD) += bootmethod.o 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 +399 -0

399 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#23 lore raw

PATCH 23/28 bootmethod: Add tests for bootmethod and bootflow

In reply to Simon Glass

Add a set of combined tests for these two commands.

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.

---

 MAINTAINERS               |   1 +
 configs/sandbox_defconfig |   2 +-
 include/test/suites.h     |   2 +
 test/Makefile             |   1 +
 test/boot/Makefile        |   5 +
 test/boot/bootmethod.c    | 271 ++++++++++++++++++++++++++++++++++++++
 test/cmd_ut.c             |   4 +
 try.sh                    | 131 ++++++++++++++++++
 8 files changed, 416 insertions(+), 1 deletion(-)
 create mode 100644 test/boot/Makefile
 create mode 100644 test/boot/bootmethod.c
 create mode 100755 try.sh
MAINTAINERS +1 -0
index 367193358b7..2f74f7dbb19 100644
@@ -639,6 +639,7 @@ F:	cmd/bootflow.c
 F:	cmd/bootmethod.c
 F:	include/bootmethod.h
 F:	include/distro.h
+F:	test/boot/bootmethod.c
 
 BTRFS
 M:	Marek Behun <[email protected]>
configs/sandbox_defconfig +1 -1
index 952d430304c..31a8d6a1d90 100644
@@ -26,7 +26,7 @@ CONFIG_AUTOBOOT_NEVER_TIMEOUT=y
 CONFIG_AUTOBOOT_STOP_STR_ENABLE=y
 CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=640000$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJpTr9tjZLZQyzqPASBY20xuK5Rent9"
 CONFIG_CONSOLE_RECORD=y
-CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
+CONFIG_CONSOLE_RECORD_OUT_SIZE=0x2000
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_LOG=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
include/test/suites.h +2 -0
index d35cd83a4eb..c36aa568e78 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_bootmethod(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..bb1599b9c0d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright 2021 Google LLC
+
+obj-$(CONFIG_BOOTMETHOD) += bootmethod.o
test/boot/bootmethod.c new file +271 -0

271 lines not on this page · raw message

test/cmd_ut.c +4 -0
index 90b260f72d6..c71f5575a04 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_BOOTMETHOD
+	U_BOOT_CMD_MKENT(bootmethod, CONFIG_SYS_MAXARGS, 1, do_ut_bootmethod,
+			 "", ""),
+#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, "", ""),
try.sh new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#24 lore raw

PATCH 24/28 bootmethod: doc: Add documentation

In reply to Simon Glass

Add documentation for this feature, including the commands.

---

 MAINTAINERS                             |   3 +
 doc/develop/bootflow.rst                | 323 ++++++++++++++++++
 doc/develop/index.rst                   |   1 +
 doc/device-tree-bindings/bootmethod.txt |  14 +
 doc/usage/bootflow.rst                  | 419 ++++++++++++++++++++++++
 doc/usage/bootmethod.rst                | 138 ++++++++
 doc/usage/index.rst                     |   2 +
 7 files changed, 900 insertions(+)
 create mode 100644 doc/develop/bootflow.rst
 create mode 100644 doc/device-tree-bindings/bootmethod.txt
 create mode 100644 doc/usage/bootflow.rst
 create mode 100644 doc/usage/bootmethod.rst
MAINTAINERS +3 -0
index 2f74f7dbb19..f472a589f61 100644
@@ -637,6 +637,9 @@ F:	boot/bootmethod.c
 F:	boot/distro.c
 F:	cmd/bootflow.c
 F:	cmd/bootmethod.c
+F:	doc/develop/bootflow.rst
+F:	doc/usage/bootflow.rst
+F:	doc/usage/bootmethod.rst
 F:	include/bootmethod.h
 F:	include/distro.h
 F:	test/boot/bootmethod.c
doc/develop/bootflow.rst new file +323 -0

323 lines not on this page · raw message

doc/develop/index.rst +1 -0
index 1fb0f06f6e8..e87bac0185b 100644
@@ -9,6 +9,7 @@ Implementation
 .. toctree::
    :maxdepth: 1
 
+   bootflow
    ci_testing
    commands
    devicetree/index
doc/device-tree-bindings/bootmethod.txt new file +14 -0
new file mode 100644
index 00000000000..ef2545cab68
@@ -0,0 +1,14 @@
+U-Boot Bootmethod
+=================
+
+A bootmethod 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 bootmethod driver is provided by the media devices. The bindings for each
+are described in this file.
+
+
+MMC bootmethod
+--------------
+
+Optional properties:
doc/usage/bootflow.rst new file +419 -0

419 lines not on this page · raw message

doc/usage/bootmethod.rst new file +138 -0

138 lines not on this page · raw message

doc/usage/index.rst +2 -0
index 356f2a56181..0abfad26e8e 100644
@@ -21,8 +21,10 @@ Shell commands
    askenv
    base
    bootefi
+   bootflow
    booti
    bootmenu
+   bootmethod
    button
    x86/cbsysinfo
    conitrace
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#25 lore raw

PATCH 25/28 mmc: Allow for children other than the block device

In reply to Simon Glass

At present the MMC uclass assumes that the only child it can have is a block device. Update this so we can add a bootmethod too.

---

 drivers/mmc/mmc-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +2 -2
index 0e13238c7e7..9e39fdd6c44 100644
@@ -320,7 +320,7 @@ struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
 	struct blk_desc *desc;
 	struct udevice *dev;
 
-	device_find_first_child(mmc->dev, &dev);
+	device_find_first_child_by_uclass(mmc->dev, UCLASS_BLK, &dev);
 	if (!dev)
 		return NULL;
 	desc = dev_get_uclass_plat(dev);
@@ -422,7 +422,7 @@ int mmc_unbind(struct udevice *dev)
 {
 	struct udevice *bdev;
 
-	device_find_first_child(dev, &bdev);
+	device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
 	if (bdev) {
 		device_remove(bdev, DM_REMOVE_NORMAL);
 		device_unbind(bdev);
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#26 lore raw

PATCH 26/28 mmc: Add a bootmethod

In reply to Simon Glass

Add a bootmethod for MMC. It mostly just calls the bootmethod 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.

---

 MAINTAINERS                  |  1 +
 drivers/mmc/Makefile         |  5 ++++
 drivers/mmc/mmc-uclass.c     | 19 +++++++++++++++
 drivers/mmc/mmc_bootmethod.c | 46 ++++++++++++++++++++++++++++++++++++
 include/mmc.h                | 12 +++++++++-
 5 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mmc/mmc_bootmethod.c
MAINTAINERS +1 -0
index f472a589f61..246c5e60270 100644
@@ -640,6 +640,7 @@ F:	cmd/bootmethod.c
 F:	doc/develop/bootflow.rst
 F:	doc/usage/bootflow.rst
 F:	doc/usage/bootmethod.rst
+F:	drivers/mmc/mmc_bootmethod.c
 F:	include/bootmethod.h
 F:	include/distro.h
 F:	test/boot/bootmethod.c
drivers/mmc/Makefile +5 -0
index dde6cd563ff..0b6ddfb5165 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_)BOOTMETHOD) += mmc_bootmethod.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 +19 -0
index 9e39fdd6c44..42474bc197e 100644
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY UCLASS_MMC
 
 #include <common.h>
+#include <bootmethod.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;
@@ -403,6 +418,10 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	mmc->cfg = cfg;
 	mmc->priv = dev;
 
+	ret = bootmethod_setup_for_dev(dev, "mmc_bootmethod");
+	if (ret)
+		return log_msg_ret("bootmethod", ret);
+
 	/* the following chunk was from mmc_register() */
 
 	/* Setup dsr related values */
drivers/mmc/mmc_bootmethod.c new file +46 -0

46 lines not on this page · raw message

include/mmc.h +11 -1
index 0bf19de20e5..1cd274f6253 100644
@@ -959,10 +959,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.33.0.rc1.237.g0d66db33f3-goog
#27 lore raw

PATCH 27/28 ethernet: Add a bootmethod

In reply to Simon Glass

Add a bootmethod for Ethernet. It uses the distro boot mechanism to locate a file.

---

 MAINTAINERS               |  1 +
 configs/sandbox_defconfig |  1 +
 net/Kconfig               |  9 +++++
 net/Makefile              |  1 +
 net/eth-uclass.c          |  8 +++++
 net/eth_bootmethod.c      | 76 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644 net/eth_bootmethod.c
MAINTAINERS +1 -0
index 246c5e60270..74e8eaafb10 100644
@@ -643,6 +643,7 @@ F:	doc/usage/bootmethod.rst
 F:	drivers/mmc/mmc_bootmethod.c
 F:	include/bootmethod.h
 F:	include/distro.h
+F:	net/eth_bootmethod.c
 F:	test/boot/bootmethod.c
 
 BTRFS
configs/sandbox_defconfig +1 -0
index 31a8d6a1d90..321d32be73e 100644
@@ -116,6 +116,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_BOOTMETHOD_ETH is not set
 CONFIG_BOOTP_SEND_HOSTNAME=y
 CONFIG_NETCONSOLE=y
 CONFIG_IP_DEFRAG=y
net/Kconfig +9 -0
index ba0ca813ce5..6f92fe44a8c 100644
@@ -14,6 +14,15 @@ config PROT_UDP
 	  Enable a generic udp framework that allows defining a custom
 	  handler for udp protocol.
 
+config BOOTMETHOD_ETH
+	bool "Enable bootmethod for ethernet"
+	depends on BOOTMETHOD
+	default y
+	help
+	  Provide a bootmethod 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..c86bbd90349 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_)BOOTMETHOD_ETH) += eth_bootmethod.o
 else
 obj-$(CONFIG_NET)      += eth_legacy.o
 endif
net/eth-uclass.c +8 -0
index 0da0e85be03..0284215b113 100644
@@ -8,6 +8,7 @@
 #define LOG_CATEGORY UCLASS_ETH
 
 #include <common.h>
+#include <bootmethod.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(BOOTMETHOD_ETH)) {
+		ret = bootmethod_setup_for_dev(dev, "eth_bootmethod");
+		if (ret)
+			return log_msg_ret("bootmethod", ret);
+	}
 
 	return 0;
 }
net/eth_bootmethod.c new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#28 lore raw

PATCH 28/28 RFC: rpi: Switch over to use bootflow

In reply to Simon Glass

Drop the distro boot scripts and use bootflow instead.

Note: This is just a demonstration. It does not support EFI at present.

---

 boot/Kconfig           |  2 +-
 doc/develop/distro.rst |  3 +++
 include/configs/rpi.h  | 37 +------------------------------------
 3 files changed, 5 insertions(+), 37 deletions(-)
boot/Kconfig +1 -1
index 8565fbeab84..a1beb182f60 100644
@@ -1011,7 +1011,7 @@ 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 DISTRO_DEFAULTS
 	help
 	  This is the string of commands that will be used as bootcmd and if
 	  AUTOBOOT is set, automatically run.
doc/develop/distro.rst +3 -0
index 105dcf28190..8b26bc1f73b 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
include/configs/rpi.h +1 -36
index 522b41c02db..d2bac1e1df2 100644
@@ -161,46 +161,11 @@
 	"fdt_addr_r=0x02600000\0" \
 	"ramdisk_addr_r=0x02700000\0"
 
-#if CONFIG_IS_ENABLED(CMD_MMC)
-	#define BOOT_TARGET_MMC(func) \
-		func(MMC, mmc, 0) \
-		func(MMC, mmc, 1)
-#else
-	#define BOOT_TARGET_MMC(func)
-#endif
-
-#if CONFIG_IS_ENABLED(CMD_USB)
-	#define BOOT_TARGET_USB(func) func(USB, usb, 0)
-#else
-	#define BOOT_TARGET_USB(func)
-#endif
-
-#if CONFIG_IS_ENABLED(CMD_PXE)
-	#define BOOT_TARGET_PXE(func) func(PXE, pxe, na)
-#else
-	#define BOOT_TARGET_PXE(func)
-#endif
-
-#if CONFIG_IS_ENABLED(CMD_DHCP)
-	#define BOOT_TARGET_DHCP(func) func(DHCP, dhcp, na)
-#else
-	#define BOOT_TARGET_DHCP(func)
-#endif
-
-#define BOOT_TARGET_DEVICES(func) \
-	BOOT_TARGET_MMC(func) \
-	BOOT_TARGET_USB(func) \
-	BOOT_TARGET_PXE(func) \
-	BOOT_TARGET_DHCP(func)
-
-#include <config_distro_bootcmd.h>
-
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	"dhcpuboot=usb start; dhcp u-boot.uimg; bootm\0" \
 	ENV_DEVICE_SETTINGS \
 	ENV_DFU_SETTINGS \
-	ENV_MEM_LAYOUT_SETTINGS \
-	BOOTENV
+	ENV_MEM_LAYOUT_SETTINGS
 
 
 #endif
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#29 lore raw
In reply to Simon Glass
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Signature · 1 line
Tom
#30 lore raw

Hi Tom,

Quoted 52 lines · Tom Rini
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Regards,
Simon

#31 lore raw
Quoted 74 lines · Simon Glass

Hi Tom,

Quoted 52 lines · Tom Rini
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Quoted 5 lines

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

OK, good. I'd certainly like to see how this looks with EFI added.

Signature · 1 line
Tom
#32 lore raw
Quoted 75 lines · Tom Rini
Quoted 74 lines · Simon Glass

Hi Tom,

Quoted 52 lines · Tom Rini
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Quoted 8 lines
Quoted 5 lines

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

OK, good. I'd certainly like to see how this looks with EFI added.

What would be the order preference after scanning?

Keep in mind that our efibootmgr is pretty complete wrt to booting. It can even support booting multiple OS'es without GRUB2 (even loading different initrds is supported). Ideally (and assuming we want to support EFI booting for more devices), I would map existing extlinux configs into efibootmgr entries.

Regards
/Ilias

Quoted 2 lines
Signature · 1 line
Tom
#33 lore raw

Hi Ilias,

Quoted 83 lines · Ilias Apalodimas
Quoted 81 lines · Tom Rini
Quoted 79 lines · Simon Glass

Hi Tom,

Quoted 52 lines · Tom Rini
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 4 lines
Quoted 2 lines

OK, good. I'd certainly like to see how this looks with EFI added.

What would be the order preference after scanning?

(from other thread)
With distro boot this is done with an environment variable, as I understand it. That is not implemented in this series, but is easy to do and is in the TODO. For now it can only be done with aliases to set the order of the bootmethods and that requires adding to the DT, so I don't think it scales well. I'm open to ideas though.

Quoted 6 lines

Keep in mind that our efibootmgr is pretty complete wrt to booting. It can even support booting multiple OS'es without GRUB2 (even loading different initrds is supported). Ideally (and assuming we want to support EFI booting for more devices), I would map existing extlinux configs into efibootmgr entries.

Yes I understand. I believe distro boot supports multiple OSes too, but perhaps only on different media? I'm not sure. Anywayt ere are always going to be people who don't want or need to use EFI (or grub) and it would be nice to support both seamlessly with the same concepts. From my side, my objective here is to provide suitable frameworks for:

- locating devices we can boot from (via 'bootmethod' drivers)
- locating instructions from OSes to boot (called 'bootflows')

There are core features for a bootloader and U-Boot should probably have had them some time ago.

From what I can tell, we can make substantial improvements to the integration of the EFI code within U-Boot, particularly when the DM migrations are done. I see bootmethod/bootflow as part of that.

BTW in the other direction, I have a prototype of U-Boot booting on EFI and accessing EFI devices from which to boot. It is based on Heinrich's work for iSCSI.

Regards,
Simon

#34 lore raw
Quoted 106 lines · Simon Glass

Hi Ilias,

Quoted 83 lines · Ilias Apalodimas
Quoted 81 lines · Tom Rini
Quoted 79 lines · Simon Glass

Hi Tom,

Quoted 52 lines · Tom Rini
Quoted 43 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 4 lines
Quoted 2 lines

OK, good. I'd certainly like to see how this looks with EFI added.

What would be the order preference after scanning?

(from other thread)
With distro boot this is done with an environment variable, as I understand it. That is not implemented in this series, but is easy to do and is in the TODO. For now it can only be done with aliases to set the order of the bootmethods and that requires adding to the DT, so I don't think it scales well. I'm open to ideas though.

Quoted 6 lines

Keep in mind that our efibootmgr is pretty complete wrt to booting. It can even support booting multiple OS'es without GRUB2 (even loading different initrds is supported). Ideally (and assuming we want to support EFI booting for more devices), I would map existing extlinux configs into efibootmgr entries.

Quoted 3 lines

Yes I understand. I believe distro boot supports multiple OSes too, but perhaps only on different media? I'm not sure. Anywayt ere are always going to be people who don't want or need to use EFI (or grub)

Well, here's where I'm a bit curious. I have seen at least twice "wait, EFI stub in the linux kernel adds how much?" type commentary. I don't know how prevalent that type of concern will really be given just how often I don't see the Linux kernel config shrunk down from what the reference platform started with. And as Ilias is pointing out, you can do _a_lot_ with efibootmgr and without grub/whatever. And both Arm (the company) and RISC-V (the overarching organization) are both pushing to standardize around the idea that if you're on something bigger than an MCU, EFI-the-ABI should get you up and running.

Signature · 1 line
Tom
#35 lore raw

Hi Tom,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[...]

Quoted 50 lines
Quoted 46 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 11 lines
Quoted 1 line

The series is available at u-boot-dm/bmea-working

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 4 lines
Quoted 2 lines

OK, good. I'd certainly like to see how this looks with EFI added.

What would be the order preference after scanning?

(from other thread)
With distro boot this is done with an environment variable, as I understand it. That is not implemented in this series, but is easy to do and is in the TODO. For now it can only be done with aliases to set the order of the bootmethods and that requires adding to the DT, so I don't think it scales well. I'm open to ideas though.

Quoted 6 lines

Keep in mind that our efibootmgr is pretty complete wrt to booting. It can even support booting multiple OS'es without GRUB2 (even loading different initrds is supported). Ideally (and assuming we want to support EFI booting for more devices), I would map existing extlinux configs into efibootmgr entries.

Quoted 3 lines

Yes I understand. I believe distro boot supports multiple OSes too, but perhaps only on different media? I'm not sure. Anywayt ere are always going to be people who don't want or need to use EFI (or grub)

Quoted 9 lines

Well, here's where I'm a bit curious. I have seen at least twice "wait, EFI stub in the linux kernel adds how much?" type commentary. I don't know how prevalent that type of concern will really be given just how often I don't see the Linux kernel config shrunk down from what the reference platform started with. And as Ilias is pointing out, you can do _a_lot_ with efibootmgr and without grub/whatever. And both Arm (the company) and RISC-V (the overarching organization) are both pushing to standardize around the idea that if you're on something bigger than an MCU, EFI-the-ABI should get you up and running.

Exactly. Keep in mind that RISC-V is looking into EBBR as well, so this is far from an 'Arm thing'. Moreover, the efi stub side of the kernel for risc-v, will only load an initrd using the EFI_LOAD_FILE2 protocol we added support for. So right now the only way to properly boot a RISC-V with EFI is through the manager.

Regards
/Ilias

Quoted 3 lines
Signature · 2 lines
-- 
Tom
#36 lore raw

Hi Ilias,

Quoted 67 lines · Ilias Apalodimas

Hi Tom,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[...]

Quoted 50 lines
Quoted 46 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 11 lines
Quoted 1 line

The series is available at u-boot-dm/bmea-working

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 4 lines
Quoted 2 lines

OK, good. I'd certainly like to see how this looks with EFI added.

What would be the order preference after scanning?

(from other thread)
With distro boot this is done with an environment variable, as I understand it. That is not implemented in this series, but is easy to do and is in the TODO. For now it can only be done with aliases to set the order of the bootmethods and that requires adding to the DT, so I don't think it scales well. I'm open to ideas though.

Quoted 6 lines

Keep in mind that our efibootmgr is pretty complete wrt to booting. It can even support booting multiple OS'es without GRUB2 (even loading different initrds is supported). Ideally (and assuming we want to support EFI booting for more devices), I would map existing extlinux configs into efibootmgr entries.

Quoted 3 lines

Yes I understand. I believe distro boot supports multiple OSes too, but perhaps only on different media? I'm not sure. Anywayt ere are always going to be people who don't want or need to use EFI (or grub)

Quoted 9 lines

Well, here's where I'm a bit curious. I have seen at least twice "wait, EFI stub in the linux kernel adds how much?" type commentary. I don't know how prevalent that type of concern will really be given just how often I don't see the Linux kernel config shrunk down from what the reference platform started with. And as Ilias is pointing out, you can do _a_lot_ with efibootmgr and without grub/whatever. And both Arm (the company) and RISC-V (the overarching organization) are both pushing to standardize around the idea that if you're on something bigger than an MCU, EFI-the-ABI should get you up and running.

Quoted 5 lines

Exactly. Keep in mind that RISC-V is looking into EBBR as well, so this is far from an 'Arm thing'. Moreover, the efi stub side of the kernel for risc-v, will only load an initrd using the EFI_LOAD_FILE2 protocol we added support for. So right now the only way to properly boot a RISC-V with EFI is through the manager.

I had heard that RISC-V was just going to use UEFI (and not U-Boot), but perhaps that is not correct. So far I have not really done anything with RISC-V so am not familiar with it.

Regards,
Simon

#37 lore raw
Quoted 9 lines
Quoted 5 lines

Exactly. Keep in mind that RISC-V is looking into EBBR as well, so this is far from an 'Arm thing'. Moreover, the efi stub side of the kernel for risc-v, will only load an initrd using the EFI_LOAD_FILE2 protocol we added support for. So right now the only way to properly boot a RISC-V with EFI is through the manager.

I had heard that RISC-V was just going to use UEFI (and not U-Boot), but perhaps that is not correct. So far I have not really done anything with RISC-V so am not familiar with it.

My understanding is the intention is to just use UEFI of which U-Boot has a UEFI implementation.

#38 lore raw
Quoted 10 lines

From: Peter Robinson <[email protected]>
Date: Wed, 25 Aug 2021 14:29:45 +0100

Quoted 7 lines
Quoted 6 lines

Exactly. Keep in mind that RISC-V is looking into EBBR as well, so this is far from an 'Arm thing'. Moreover, the efi stub side of the kernel for risc-v, will only load an initrd using the EFI_LOAD_FILE2 protocol we added support for. So right now the only way to properly boot a RISC-V with EFI is through the manager.

Quoted 6 lines
Quoted 3 lines

I had heard that RISC-V was just going to use UEFI (and not U-Boot), but perhaps that is not correct. So far I have not really done anything with RISC-V so am not familiar with it.

My understanding is the intention is to just use UEFI of which U-Boot has a UEFI implementation.

The HiFive Unmatched ships with U-Boot. I'm booting OpenBSD via UEFI on that board by using the uSD card that came with the board.

The folks pushing the spec for RISC-V server hardware are probably considering a more traditional UEFI implementation for those systems since they also seem to be pushing for ACPI. But they explicitly mention EBBR for "embedded" systems, and EBBR was deliberately designed to allow the implementation of compliant systems using U-Boot's UEFI implementation.

#39 lore raw
Quoted 20 lines · Mark Kettenis
Quoted 10 lines

From: Peter Robinson <[email protected]>
Date: Wed, 25 Aug 2021 14:29:45 +0100

Quoted 7 lines
Quoted 6 lines

Exactly. Keep in mind that RISC-V is looking into EBBR as well, so this is far from an 'Arm thing'. Moreover, the efi stub side of the kernel for risc-v, will only load an initrd using the EFI_LOAD_FILE2 protocol we added support for. So right now the only way to properly boot a RISC-V with EFI is through the manager.

Quoted 6 lines
Quoted 3 lines

I had heard that RISC-V was just going to use UEFI (and not U-Boot), but perhaps that is not correct. So far I have not really done anything with RISC-V so am not familiar with it.

My understanding is the intention is to just use UEFI of which U-Boot has a UEFI implementation.

The HiFive Unmatched ships with U-Boot. I'm booting OpenBSD via UEFI on that board by using the uSD card that came with the board.

Quoted 6 lines

The folks pushing the spec for RISC-V server hardware are probably considering a more traditional UEFI implementation for those systems since they also seem to be pushing for ACPI. But they explicitly mention EBBR for "embedded" systems, and EBBR was deliberately designed to allow the implementation of compliant systems using U-Boot's UEFI implementation.

I don't know if any of the "right" people are listening here, but, I don't see why ACPI precludes U-Boot. We ship ACPI tables for x86 already...

Signature · 1 line
Tom
#40 lore raw
In reply to Simon Glass

Hi Simon,

Quoted 48 lines · Simon Glass

Hi Tom,

Quoted 45 lines · Tom Rini
Quoted 42 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Regarding the naming, I'm still a bit confused with bootmethod vs. bootflow. Personally, I prefer a more intuitive name against bootmethod, say, bootmedia or bootdevice (as the original distro_bootcmd uses).

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines
Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

I had the same concern.

Quoted 9 lines

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Quoted 5 lines

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

If I correctly understand this framework, we will have to write several functions:
(Here I will ignore "UEFI boot manager" sequence.)

1)boot/distro_efi.c
distro_boot_efi_setup() ; almost the same as distro_boot_setup()
distro_boot_efi() ; search for /EFI/BOOT/BOOTAA64.EFI (and dtb)

2)boot/bootflow.c
bootmethod_find_efi_in_blk()
call distro_boot_efi_setup()
bootflow_boot()
CASE BOOTFLOWT_DISTRO_EFI: ; new bootflow type
call distro_boot_efi()

3)drivers/mmc/mmc_bootmethod.c
mmc_efi_get_bootflow()
call bootmethod_find_efi_in_blk()
U_BOOT_DRIVER(mmc_efi_bootmethod) =
.name = "mmc_efi_bootmethod",
.id = UCLASS_BOOTMETHOD,

4)drivers/mm/Makefile
obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD) += mmc_bootmethod.o mmc_efi_bootmethod.o

Do you think that the above is correct?
If so, does (3) (+ (1)/(2)) inevitably increase the code size as we need functions for all devices?

-Takahiro Akashi

Quoted 2 lines

Regards,
Simon

#41 lore raw

Hi Takahiro,

Quoted 48 lines · AKASHI Takahiro

Hi Simon,

Quoted 44 lines · Simon Glass

Hi Tom,

Quoted 41 lines · Tom Rini
Quoted 38 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Regarding the naming, I'm still a bit confused with bootmethod vs. bootflow. Personally, I prefer a more intuitive name against bootmethod, say, bootmedia or bootdevice (as the original distro_bootcmd uses).

I quite like bootmedia. Would just 'media' be OK? That would reduce the use of the 'boot' prefix which I think is overused.

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines
Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Quoted 1 line

I had the same concern.

OK see my reply to Tom on this point. The separate of concerns between providing media and booting an OS is a key purpose of this series.

I have Fedora 34 in my lab and will send an update for it next week.

Quoted 16 lines
Quoted 10 lines

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Quoted 5 lines

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 7 lines

If I correctly understand this framework, we will have to write several functions:
(Here I will ignore "UEFI boot manager" sequence.)

1)boot/distro_efi.c
distro_boot_efi_setup() ; almost the same as distro_boot_setup()
distro_boot_efi() ; search for /EFI/BOOT/BOOTAA64.EFI (and dtb)

Yes

Quoted 7 lines

2)boot/bootflow.c
bootmethod_find_efi_in_blk()
call distro_boot_efi_setup()
bootflow_boot()
CASE BOOTFLOWT_DISTRO_EFI: ; new bootflow type
call distro_boot_efi()

Yes

Quoted 7 lines

3)drivers/mmc/mmc_bootmethod.c
mmc_efi_get_bootflow()
call bootmethod_find_efi_in_blk()
U_BOOT_DRIVER(mmc_efi_bootmethod) =
.name = "mmc_efi_bootmethod",
.id = UCLASS_BOOTMETHOD,

No, this is not needed. Bootmethod provides the media so we don't have a separate one for EFI. It is the bootflow detection that needs to be changed (as above).

Quoted 3 lines

4)drivers/mm/Makefile
obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD) += mmc_bootmethod.o mmc_efi_bootmethod.o

No, this is not needed.

See also the todo at the end of the bootflow docs. One day we may want to expand add sort of interface for locating the files, instead of calling it directly from bootflow.

Quoted 4 lines

Do you think that the above is correct?
If so, does (3) (+ (1)/(2)) inevitably increase the code size as we need functions for all devices?

Yes, of course any feature increases the code size., although I'd argue this is a feature that could/should have been added instead of the scripts approach. It is much easier to understand and test.

BTW you can try this out with sandbox.

$ u-boot -T
=> bootmethod list
=> bootflow scan

etc.

Regards,
Simon

#42 lore raw
Quoted 57 lines · Simon Glass

Hi Takahiro,

Quoted 53 lines · AKASHI Takahiro

Hi Simon,

Quoted 48 lines · Simon Glass

Hi Tom,

Quoted 45 lines · Tom Rini
Quoted 42 lines · Simon Glass

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 6 lines
Quoted 3 lines

Regarding the naming, I'm still a bit confused with bootmethod vs. bootflow. Personally, I prefer a more intuitive name against bootmethod, say, bootmedia or bootdevice (as the original distro_bootcmd uses).

I quite like bootmedia. Would just 'media' be OK? That would reduce the use of the 'boot' prefix which I think is overused.

If 'boot' prefix is removed, I'm afraid that the word, either media, method or flow, sounds quite generic and so ambiguous.
As far as the commands are concerned, on the other hand, it might be one way to have sub-commands under 'boot', like "boot media ..." or "boot flow ..." although I'm not sure it is a preferred style on U-Boot.

# I have no strong opinion here.

Quoted 68 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

Quoted 9 lines
Quoted 9 lines

My question / concern is this. Would the next step here be to implement the generic UEFI boot path? Today, I can write Fedora 34 for AArch64 to a USB stick, boot U-Boot off of uSD card and the installer automatically boots. I'm sure I could do the same with the BSDs. Reading the documentation left me with the impression that every OSV would be expected to write something, so that their installer / OS boot. But there's already standards for that, which they do, and we should be implementing (and do, via the current distro_boot) or making easier to enable. Thanks!

Quoted 1 line

I had the same concern.

OK see my reply to Tom on this point. The separate of concerns between providing media and booting an OS is a key purpose of this series.

I have Fedora 34 in my lab and will send an update for it next week.

Quoted 16 lines
Quoted 10 lines

Here you are talking about scanning for a bootflow. It is not actually OS-specific. If it were, there would be no point to this :-)

If you look in the distro scripts you will see 'scan_dev_for_efi' (and also scan_dev_for_scrips). At least the first needs to be implemented a bit like the distro boot is at present. So far I have only implemented scan_dev_for_extlinux (plus pxe) as it is enough to show the concept.

Quoted 5 lines

Adding EFI it's likely to be about the same amount of code as distro.c at present, perhaps a little less since we don't have the network case. It is used by Fedora 34, I believe, so is easy enough for me to do. But I wanted to get something out as the concept is visible in this series.

Quoted 7 lines

If I correctly understand this framework, we will have to write several functions:
(Here I will ignore "UEFI boot manager" sequence.)

1)boot/distro_efi.c
distro_boot_efi_setup() ; almost the same as distro_boot_setup()
distro_boot_efi() ; search for /EFI/BOOT/BOOTAA64.EFI (and dtb)

Yes

Quoted 7 lines

2)boot/bootflow.c
bootmethod_find_efi_in_blk()
call distro_boot_efi_setup()
bootflow_boot()
CASE BOOTFLOWT_DISTRO_EFI: ; new bootflow type
call distro_boot_efi()

Yes

Quoted 7 lines

3)drivers/mmc/mmc_bootmethod.c
mmc_efi_get_bootflow()
call bootmethod_find_efi_in_blk()
U_BOOT_DRIVER(mmc_efi_bootmethod) =
.name = "mmc_efi_bootmethod",
.id = UCLASS_BOOTMETHOD,

Quoted 3 lines

No, this is not needed. Bootmethod provides the media so we don't have a separate one for EFI. It is the bootflow detection that needs to be changed (as above).

Well, this is what I didn't really understand. How are all the boot flows enumerated? Looking at do_bootflow_scan(),

        for (i = 0, ret = 0; i < 100 && ret != -ESHUTDOWN; i++) {
                ret = bootmethod_get_bootflow(dev, i, &bflow);

Here, the second argument, i (or seq), is used to indicate a partition number. So how can we add more than one bootflow to the same bootmethod (bootmedia in my language :)?

-Takahiro Akashi

Quoted 29 lines
Quoted 3 lines

4)drivers/mm/Makefile
obj-$(CONFIG_$(SPL_TPL_)BOOTMETHOD) += mmc_bootmethod.o mmc_efi_bootmethod.o

No, this is not needed.

See also the todo at the end of the bootflow docs. One day we may want to expand add sort of interface for locating the files, instead of calling it directly from bootflow.

Quoted 4 lines

Do you think that the above is correct?
If so, does (3) (+ (1)/(2)) inevitably increase the code size as we need functions for all devices?

Yes, of course any feature increases the code size., although I'd argue this is a feature that could/should have been added instead of the scripts approach. It is much easier to understand and test.

BTW you can try this out with sandbox.

$ u-boot -T
=> bootmethod list
=> bootflow scan

etc.

Regards,
Simon

#43 lore raw
In reply to Simon Glass
Quoted 46 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

And how do we define the default order?

Quoted 138 lines

Simon Glass (28):
Create a new boot/ directory
pxe: Move API comments to the header files
pxe: Use a context pointer
pxe: Move do_getfile() into the context
pxe: Add a userdata field to the context
pxe: Tidy up the is_pxe global
pxe: Move pxe_utils files
pxe: Tidy up some comments in pxe_utils
pxe: Tidy up code style a little in pxe_utils
pxe: Move common parsing coding into pxe_util
pxe: Clean up the use of bootfile
pxe: Drop get_bootfile_path()
lib: Add tests for simple_itoa()
lib: Add a function to convert a string to a hex value
pxe: Return the file size from the getfile() function
pxe: Refactor sysboot to have one helper
doc: Move distro boot doc to rST
pxe: Allow calling the pxe_get logic directly
bootmethod: Add the uclass and core implementation
bootmethod: Add an implementation of distro boot
bootmethod: Add a command
bootflow: Add a command
bootmethod: Add tests for bootmethod and bootflow
bootmethod: doc: Add documentation
mmc: Allow for children other than the block device
mmc: Add a bootmethod
ethernet: Add a bootmethod
RFC: rpi: Switch over to use bootflow

 Kconfig                                   |   2 +
 MAINTAINERS                               |  16 +
 Makefile                                  |   3 +-
 README                                    |   1 +
 common/Kconfig.boot => boot/Kconfig       |  22 +-
 boot/Makefile                             |  39 ++
 {common => boot}/android_ab.c             |   0
 {common => boot}/boot_fit.c               |   0
 {common => boot}/bootm.c                  |   0
 {common => boot}/bootm_os.c               |   0
 boot/bootmethod.c                         | 485 ++++++++++++++++++++
 {common => boot}/bootretry.c              |   0
 {common => boot}/common_fit.c             |   0
 boot/distro.c                             | 194 ++++++++
 {common => boot}/fdt_region.c             |   0
 {common => boot}/image-android-dt.c       |   0
 {common => boot}/image-android.c          |   0
 {common => boot}/image-cipher.c           |   0
 {common => boot}/image-fdt.c              |   0
 {common => boot}/image-fit-sig.c          |   0
 {common => boot}/image-fit.c              |   0
 {common => boot}/image-sig.c              |   0
 {common => boot}/image.c                  |   0
 {cmd => boot}/pxe_utils.c                 | 512 +++++++++++-----------
 cmd/Kconfig                               |   8 +
 cmd/Makefile                              |   5 +-
 cmd/bootflow.c                            | 399 +++++++++++++++++
 cmd/bootmethod.c                          | 130 ++++++
 cmd/pxe.c                                 | 136 +++---
 cmd/pxe_utils.h                           |  91 ----
 cmd/sysboot.c                             | 114 +++--
 common/Kconfig                            |   2 -
 common/Makefile                           |  22 -
 configs/sandbox_defconfig                 |   3 +-
 doc/android/boot-image.rst                |   2 +-
 doc/develop/bootflow.rst                  | 323 ++++++++++++++
 doc/{README.distro => develop/distro.rst} | 180 ++++----
 doc/develop/index.rst                     |   2 +
 doc/device-tree-bindings/bootmethod.txt   |  14 +
 doc/usage/bootflow.rst                    | 419 ++++++++++++++++++
 doc/usage/bootmethod.rst                  | 138 ++++++
 doc/usage/index.rst                       |   2 +
 drivers/mmc/Makefile                      |   5 +
 drivers/mmc/mmc-uclass.c                  |  23 +-
 drivers/mmc/mmc_bootmethod.c              |  46 ++
 include/bootmethod.h                      | 357 +++++++++++++++
 include/configs/rpi.h                     |  37 +-
 include/distro.h                          |  62 +++
 include/dm/uclass-id.h                    |   1 +
 include/mmc.h                             |  12 +-
 include/pxe_utils.h                       | 253 +++++++++++
 include/test/suites.h                     |   2 +
 include/vsprintf.h                        |  25 +-
 lib/vsprintf.c                            |  20 +-
 net/Kconfig                               |   9 +
 net/Makefile                              |   1 +
 net/eth-uclass.c                          |   8 +
 net/eth_bootmethod.c                      |  76 ++++
 scripts/Makefile.spl                      |   4 +-
 test/Makefile                             |   1 +
 test/boot/Makefile                        |   5 +
 test/boot/bootmethod.c                    | 271 ++++++++++++
 test/cmd_ut.c                             |   4 +
 test/print_ut.c                           |  33 ++
 tools/Makefile                            |  16 +-
 try.sh                                    | 131 ++++++
 66 files changed, 4035 insertions(+), 631 deletions(-)
 rename common/Kconfig.boot => boot/Kconfig (98%)
 create mode 100644 boot/Makefile
 rename {common => boot}/android_ab.c (100%)
 rename {common => boot}/boot_fit.c (100%)
 rename {common => boot}/bootm.c (100%)
 rename {common => boot}/bootm_os.c (100%)
 create mode 100644 boot/bootmethod.c
 rename {common => boot}/bootretry.c (100%)
 rename {common => boot}/common_fit.c (100%)
 create mode 100644 boot/distro.c
 rename {common => boot}/fdt_region.c (100%)
 rename {common => boot}/image-android-dt.c (100%)
 rename {common => boot}/image-android.c (100%)
 rename {common => boot}/image-cipher.c (100%)
 rename {common => boot}/image-fdt.c (100%)
 rename {common => boot}/image-fit-sig.c (100%)
 rename {common => boot}/image-fit.c (100%)
 rename {common => boot}/image-sig.c (100%)
 rename {common => boot}/image.c (100%)
 rename {cmd => boot}/pxe_utils.c (74%)
 create mode 100644 cmd/bootflow.c
 create mode 100644 cmd/bootmethod.c
 delete mode 100644 cmd/pxe_utils.h
 create mode 100644 doc/develop/bootflow.rst
 rename doc/{README.distro => develop/distro.rst} (76%)
 create mode 100644 doc/device-tree-bindings/bootmethod.txt
 create mode 100644 doc/usage/bootflow.rst
 create mode 100644 doc/usage/bootmethod.rst
 create mode 100644 drivers/mmc/mmc_bootmethod.c
 create mode 100644 include/bootmethod.h
 create mode 100644 include/distro.h
 create mode 100644 include/pxe_utils.h
 create mode 100644 net/eth_bootmethod.c
 create mode 100644 test/boot/Makefile
 create mode 100644 test/boot/bootmethod.c
 create mode 100755 try.sh
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#44 lore raw

Hi Mark,

Quoted 47 lines · Mark Kettenis
Quoted 47 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

Quoted 7 lines
Quoted 5 lines

The design is described here:

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Anyway this feature is beyond scope of the current series, which is just to put in the basic plumbing. We need a non-volatile config file to hold this information (in VBE this is called NVdata).

Quoted 2 lines

And how do we define the default order?

With distro boot this is done with an environment variable, as I understand it. That is not implemented in this series, but is easy to do and is in the TODO. For now it can only be done with aliases to set the order of the bootmethods and that requires adding to the DT, so I don't think it scales well. I'm open to ideas though.

Regards,
SImon

#45 lore raw
Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Signature · 1 line
Tom
#46 lore raw
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 5 lines
Signature · 3 lines
Tom

[2:application/pgp-signature Show Save:signature.asc (659B)]
#47 lore raw
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

Quoted 10 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 5 lines
Signature · 3 lines
Tom

[2:application/pgp-signature Show Save:signature.asc (659B)]
Signature · 1 line
Emmanuel Vadot <[email protected]> <[email protected]>
#48 lore raw

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

I'm travelling for three weeks soon, so if it doesn't happen this week I'll continue this after that.

Regards,
Simon

#49 lore raw

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

-Takahiro Akashi

Quoted 5 lines

I'm travelling for three weeks soon, so if it doesn't happen this week I'll continue this after that.

Regards,
Simon

#50 lore raw
Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

Signature · 1 line
Tom
#51 lore raw
Quoted 139 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Cheers,

Mark

#52 lore raw
Quoted 163 lines · Mark Kettenis
Quoted 139 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

Signature · 1 line
Tom
#53 lore raw

Mark, Tom,

Quoted 147 lines · Tom Rini
Quoted 146 lines · Mark Kettenis
Quoted 145 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

Quoted 8 lines
Quoted 8 lines

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my

Well, if this is everyone's consensus in (U-Boot) community, it would be fine. But different people may have different opinions/requirements on different systems. So I believe that the safest way is to make UEFI implementation as compliant to the specification as possible.

Quoted 8 lines
Quoted 8 lines

OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Yes, it is doable, even I'm now trying to examine and address this issue as I am fully aware of the situation.

Quoted 8 lines
Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

It is more or less a matter of implementation.
Historically, removable media support was added to distro_bootcmd first and then boot manager was implemented later, only both were integrated at script level. Since then, nobody, AFAIK, has complained about the lack of integrity. That's what we see now.

One of difficulties that I found in the implementation is how to specify preferred boot media in a form of EFI device path. Take an example; I want to do
=> efidebug boot add -b 1 USB usb 0 "" -s "" ; USB port-1
^^^^^^^^ no image file specified
=> efidebug boot add -b 2 USB usb 1 "" -s "" ; USB port-2
=> efidebug boot add -b 3 MMC mmc 0 "" -s "" ; MMC slot-1
=> efidebug boot add -b 4 MYKERNEL scsi 0:1 /.../vmlinux.efi -s "..." => efidebug boot order 1 2 3 4
=> bootefi bootmgr

First three commands will fail now.

Under the current implementation, neither "usb 0", "usb 1" nor "mmc 0", which is set to be converted to device path representation in BootXXXX variable, are recognized as a valid device since there is no physical device attached to corresponding bus/port/slots at this time. Internally, UEFI system/efidebug always tries to look for a U-Boot's existing block device to identify the correct device path. (Remember that *buses* and *controller* are even not udevices?). So we would have to manage to create a valid internal representation of bus or port for those media.

# FYI, my current prototype work already supports the following command line

# and enables booting the system from the USB media if some storage device
# is attached to the port-1:
# => efidebug boot add -b 1 USB usb 0:1 "" -s ""    ; USB port-1
                                ^^^^^^^

As I'm not well-versed in U-Boot's device model, the rework would be simpler than I anticipate.

-Takahiro Akashi

Quoted 2 lines
Signature · 1 line
Tom
#54 lore raw
Quoted 159 lines · AKASHI Takahiro

Mark, Tom,

Quoted 147 lines · Tom Rini
Quoted 146 lines · Mark Kettenis
Quoted 145 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

Quoted 8 lines
Quoted 8 lines

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my

Quoted 5 lines

Well, if this is everyone's consensus in (U-Boot) community, it would be fine. But different people may have different opinions/requirements on different systems. So I believe that the safest way is to make UEFI implementation as compliant to the specification as possible.

Since a tangent to this has come up elsewhere recently, I just want to be clear that we should follow the spec, when there is a spec.

Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Yes, it is doable, even I'm now trying to examine and address this issue as I am fully aware of the situation.

Yay.

Quoted 42 lines
Quoted 8 lines
Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

It is more or less a matter of implementation.
Historically, removable media support was added to distro_bootcmd first and then boot manager was implemented later, only both were integrated at script level. Since then, nobody, AFAIK, has complained about the lack of integrity. That's what we see now.

One of difficulties that I found in the implementation is how to specify preferred boot media in a form of EFI device path. Take an example; I want to do
=> efidebug boot add -b 1 USB usb 0 "" -s "" ; USB port-1
^^^^^^^^ no image file specified
=> efidebug boot add -b 2 USB usb 1 "" -s "" ; USB port-2
=> efidebug boot add -b 3 MMC mmc 0 "" -s "" ; MMC slot-1
=> efidebug boot add -b 4 MYKERNEL scsi 0:1 /.../vmlinux.efi -s "..." => efidebug boot order 1 2 3 4
=> bootefi bootmgr

First three commands will fail now.

Under the current implementation, neither "usb 0", "usb 1" nor "mmc 0", which is set to be converted to device path representation in BootXXXX variable, are recognized as a valid device since there is no physical device attached to corresponding bus/port/slots at this time. Internally, UEFI system/efidebug always tries to look for a U-Boot's existing block device to identify the correct device path. (Remember that *buses* and *controller* are even not udevices?). So we would have to manage to create a valid internal representation of bus or port for those media.

Quoted 8 lines

# FYI, my current prototype work already supports the following command line

# and enables booting the system from the USB media if some storage device
# is attached to the port-1:
# => efidebug boot add -b 1 USB usb 0:1 "" -s ""    ; USB port-1
                                ^^^^^^^

As I'm not well-versed in U-Boot's device model, the rework would be simpler than I anticipate.

Thanks for the update on where you're at so far.

Signature · 1 line
Tom
#55 lore raw
In reply to Tom Rini
Quoted 175 lines

Date: Wed, 25 Aug 2021 18:06:05 -0400
From: Tom Rini <[email protected]>

Quoted 163 lines · Mark Kettenis
Quoted 139 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

U-Boot has some support for EFI variables, but there are some fundamental problems that make "full" support for them hard or even impossible.

Some non-volatile storage is necessary for these variables such that they can be persistent across boots. Obviously this very much applies to the BootOrder variable. EFI defines calls to manipulate variables as part of its runtime services. This means that the NV storage has to implemented in a way that doesn't interfere with normal OS usage of the hardware. That pretty much means that you need dedicated hardware for this, which most devices supported by U-Boot simply don't have. Having the EFI variables in the U-Boot environment on a reserved part of a uSD card isn't going to work if the OS assumes it has full control over the uSD controller.

Recent versions of the UEFI have made the implementation of some of the runtime services optional (more or less at the request of the EBBR folks) and allow certain calls (e.g. the SetVariable() call) to fail. This poses a bit of a problem though, which I'll try to sketch here:

The way things typically work on a x86 EFI system is that you boot your OS installer from removable media. The OS installer does its thing (partitions the disk, creates filesystems, installs the OS kernel, etc.) and at the end creates a boot option for the boot manager by creating an apropriate Boot#### variable and possibly modifying the BootOrder variable to include the newly created boot option. A typical x86 Linux distro will create a Boot#### variable that is effectively a devicepath pointing at grub.efi. Unfortunately that won't work if the SetVariable() EFI runtime interface doesn't work.

I'm not sure how the EBBR folks envisaged the OS installation user experience on these systems. Maybe Takahiro can explain. But as long as you don't really care about booting multiple OSes on a system, relying on the default removable media boot path works fine in most cases in that it automatically boots into the installed OS when you reboot after removing the installation media.

#56 lore raw
Quoted 211 lines · Mark Kettenis
Quoted 175 lines

Date: Wed, 25 Aug 2021 18:06:05 -0400
From: Tom Rini <[email protected]>

Quoted 163 lines · Mark Kettenis
Quoted 139 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan for bootflows from MMC and Ethernet. The only bootflow supported is distro boot, i.e. an extlinux.conf file included on a filesystem or tftp server. 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.

It is intended that this approach be expanded to support mechanisms other than distro boot, including EFI-related ones. With a standard way to identify boot devices, these features become easier. It also should support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and into a new boot/ directory. This helps to collect these related files in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation. Much of this series consists of cleaning up that code and refactoring it into something closer to a module that can be called, teasing apart its reliance on the command-line interpreter to access filesystems and the like. Also it now uses function arguments and its own context struct internally rather than environment variables, which is very hard to follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation. One question is the choice of naming. Since this is a bootloader, should we just call this a 'method' and a 'flow' ? The 'boot' prefix is already shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

U-Boot has some support for EFI variables, but there are some fundamental problems that make "full" support for them hard or even impossible.

Some non-volatile storage is necessary for these variables such that they can be persistent across boots. Obviously this very much applies to the BootOrder variable. EFI defines calls to manipulate variables as part of its runtime services. This means that the NV storage has to implemented in a way that doesn't interfere with normal OS usage of the hardware. That pretty much means that you need dedicated hardware for this, which most devices supported by U-Boot simply don't have. Having the EFI variables in the U-Boot environment on a reserved part of a uSD card isn't going to work if the OS assumes it has full control over the uSD controller.

Recent versions of the UEFI have made the implementation of some of the runtime services optional (more or less at the request of the EBBR folks) and allow certain calls (e.g. the SetVariable() call) to fail. This poses a bit of a problem though, which I'll try to sketch here:

The way things typically work on a x86 EFI system is that you boot your OS installer from removable media. The OS installer does its thing (partitions the disk, creates filesystems, installs the OS kernel, etc.) and at the end creates a boot option for the boot manager by creating an apropriate Boot#### variable and possibly modifying the BootOrder variable to include the newly created boot option. A typical x86 Linux distro will create a Boot#### variable that is effectively a devicepath pointing at grub.efi. Unfortunately that won't work if the SetVariable() EFI runtime interface doesn't work.

Quoted 6 lines

I'm not sure how the EBBR folks envisaged the OS installation user experience on these systems. Maybe Takahiro can explain. But as long as you don't really care about booting multiple OSes on a system, relying on the default removable media boot path works fine in most cases in that it automatically boots into the installed OS when you reboot after removing the installation media.

Ah right, run-time variables are where it gets tricky. I would think that when ENV_IS_IN_MMC/etc, where it's a hard location on something, and not a file (which would be hard to share since it's likely mounted via the OS) would let us get past that.

Signature · 1 line
Tom
#57 lore raw
Quoted 222 lines

Date: Thu, 26 Aug 2021 09:00:01 -0400
From: Tom Rini <[email protected]>

Quoted 211 lines · Mark Kettenis
Quoted 175 lines

Date: Wed, 25 Aug 2021 18:06:05 -0400
From: Tom Rini <[email protected]>

Quoted 163 lines · Mark Kettenis
Quoted 139 lines

Date: Wed, 25 Aug 2021 10:56:35 -0400
From: Tom Rini <[email protected]>

Quoted 132 lines · AKASHI Takahiro

Simon,

Quoted 110 lines · Simon Glass

Hi,

Quoted 94 lines · Emmanuel Vadot
Quoted 82 lines · On Tue, 24 Aug 2021 12:22:42 +0200 (CEST) Mark Kettenis…
Quoted 65 lines

Date: Mon, 23 Aug 2021 16:01:46 -0400
From: Tom Rini <[email protected]>

Quoted 52 lines · Simon Glass

Hi Mark,

Quoted 49 lines · Mark Kettenis
Quoted 49 lines

From: Simon Glass <[email protected]>
Date: Wed, 18 Aug 2021 21:45:33 -0600

Bootmethod and bootflow provide a built-in way for U-Boot to automatically boot
an Operating System without custom scripting and other customisation:

- bootmethod - a method to scan a device to find bootflows (owned by U-Boot)
- bootflow - a description of how to boot (owned by the distro)

This series provides an initial implementation of these, enable to scan
for bootflows from MMC and Ethernet. The only bootflow supported is
distro boot, i.e. an extlinux.conf file included on a filesystem or
tftp server. 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.

It is intended that this approach be expanded to support mechanisms other
than distro boot, including EFI-related ones. With a standard way to
identify boot devices, these features become easier. It also should
support U-Boot scripts, for backwards compatibility only.

The first patch of this series moves boot-related code out of common/ and
into a new boot/ directory. This helps to collect these related files
in one place, as common/ is quite large.

Like sysboot, this feature makes use of the existing PXE implementation.
Much of this series consists of cleaning up that code and refactoring it
into something closer to a module that can be called, teasing apart its
reliance on the command-line interpreter to access filesystems and the
like. Also it now uses function arguments and its own context struct
internally rather than environment variables, which is very hard to
follow. No core functional change is included in the included PXE patches.

For documentation, see the 'doc' patch.

There is quite a long list of future work included in the documentation.
One question is the choice of naming. Since this is a bootloader, should
we just call this a 'method' and a 'flow' ? The 'boot' prefix is already
shared by other commands like bootm, booti, etc.

The design is described here:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

https://drive.google.com/file/d/1ggW0KJpUOR__vBkj3l61L2dav4ZkNC12/view?usp=sharing

The series is available at u-boot-dm/bmea-working

How does the user control the order in which devices are scanned/booted?

That is not supported in distroboot at present, at least so far as I can see. For Fedora it seems to happen in grub. Do I have that right?

Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

U-Boot has some support for EFI variables, but there are some fundamental problems that make "full" support for them hard or even impossible.

Some non-volatile storage is necessary for these variables such that they can be persistent across boots. Obviously this very much applies to the BootOrder variable. EFI defines calls to manipulate variables as part of its runtime services. This means that the NV storage has to implemented in a way that doesn't interfere with normal OS usage of the hardware. That pretty much means that you need dedicated hardware for this, which most devices supported by U-Boot simply don't have. Having the EFI variables in the U-Boot environment on a reserved part of a uSD card isn't going to work if the OS assumes it has full control over the uSD controller.

Recent versions of the UEFI have made the implementation of some of the runtime services optional (more or less at the request of the EBBR folks) and allow certain calls (e.g. the SetVariable() call) to fail. This poses a bit of a problem though, which I'll try to sketch here:

The way things typically work on a x86 EFI system is that you boot your OS installer from removable media. The OS installer does its thing (partitions the disk, creates filesystems, installs the OS kernel, etc.) and at the end creates a boot option for the boot manager by creating an apropriate Boot#### variable and possibly modifying the BootOrder variable to include the newly created boot option. A typical x86 Linux distro will create a Boot#### variable that is effectively a devicepath pointing at grub.efi. Unfortunately that won't work if the SetVariable() EFI runtime interface doesn't work.

Quoted 6 lines

I'm not sure how the EBBR folks envisaged the OS installation user experience on these systems. Maybe Takahiro can explain. But as long as you don't really care about booting multiple OSes on a system, relying on the default removable media boot path works fine in most cases in that it automatically boots into the installed OS when you reboot after removing the installation media.

Quoted 4 lines

Ah right, run-time variables are where it gets tricky. I would think that when ENV_IS_IN_MMC/etc, where it's a hard location on something, and not a file (which would be hard to share since it's likely mounted via the OS) would let us get past that.

Not really. As soon as the OS takes over the MMC controller, U-Boot can't touch it anymore. The only thing that really works is using a dedicated device that isn't exposed to the OS. So U-Boot would need to remove its nodes from the device tree. But even then things get tricky with shared clocks and such.

The only really safe option is to use something like TrustZone on ARM devices to completely hide things from the non-secure world. I believe that is what Linaro is actually doing in their U-Boot based implementation where the EFI variable store is actually implemented in OP-TEE running in the secure world. However that places demands on the hardware that many SoCs and boards won't be able to fulfill.

A lot of the more advance EFI features that have been implemented/proposed (secure boot, capsule updates) do rely on having proper run-time variable support. So Simon does have a point that the EFI based approach for that has some serious issues that a "native" U-Boot implementation could avoid and that enabling these EFI features by default adds unecessary "bloat".

#58 lore raw

Hi Mark,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[...]

Quoted 140 lines
Quoted 135 lines
Quoted 128 lines
Quoted 92 lines
Quoted 84 lines
Quoted 60 lines
Quoted 57 lines
Quoted 38 lines
Quoted 25 lines
Quoted 17 lines
Quoted 6 lines

Well, there's "find the next stage", which is boot_targets environment variable, and then "where that next stage looks for stuff" which is OS-dependent. Sometimes the ESP grub.cfg file is just enough to tell grub to find the full grub.cfg file elsewhere, and sometimes it's a full grub.cfg file. I think Mark is talking about the former, and you've said it's not part of this series, yet, but on the TODO list.

Right. With the current distroboot code the order of the devices that appears in boot_targets is determined by per-board/SOC/machine config files and the order isn't the same for all of them. Users can change the order if necessary by modifying the environment variable and saving the environment. And for a one-off boot from a different device they can simply run an appropriate boot command. The boot_targets variable in particular is documented in various install documents so it would probably be good of the new "bootmethod" code would respect this variable.

Quoted 7 lines

For OpenBSD I'm not really interested in the bootflow part. As I explained in the past, that part of the problem is solved in a (mostly) uniform way across platforms by the OpenBSD bootloader which can read an /etc/boot.conf that allows bootflow customization. So as long as the default of the new code still results in \EFI\BOOT\BOOT{machine type short-name}.EFI being loaded and run if there is no U-Boot specific bootflow configured, I'm happy.

Quoted 3 lines

Mostly the same for FreeBSD, as long as the efi boot<arch>.efi is
loaded and run by default (respecting the boot_targets order) we will be fine.

OK thanks for the info. My expectation is that bootmethod/bootflow can support this easily enough (it is actually simpler than distro boot).

Quoted 5 lines
Quoted 5 lines

I can't speak for the other BSDs, but my impression is that they are pretty much in the same position. The FreeBSD bootloader for example supports a high-degree of "bootflow" customization and I doubt that taking it out of the loop is a viable option for most users.

Quoted 7 lines

I think the same may happen with grub. E.g. with Ubuntu I see quite a bit of code in the grub.cfg file and it's not clear to me that it can be replaced with a 'data instead of code' approach. Still, a valid bootflow is simply to jump to an EFI app, which seems to be what is happening here. The bootflow side is really just about describing what to do, and this case is no different. For now I see three types of bootflow, PXE/syslinux, EFI boot manager and EFI app.

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I think "bootefi bootmgr" only works if the BootOrder variable is defined, and currently that isn't the case.

The boot manager behaviour as specified in the UEFI specification is somewhat problematic to implement in U-Boot because of the limitations in how variables can be set at runtime. This is one of the reasons OpenBSD doesn't actually bother with setting the variables and simple relies on the "removable media" support mentioned above. All my OpenBSD systems that use U-Boot print the follwing lines:

BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

But maybe that last step can be intgrated into bootefi bootmgr at some point?

Quoted 7 lines

Also note that manually manipulating the EFI variables to change the boot order is quite cumbersome; it isn't a matter of just changed the aforementioned BootOrder variable. That's why I think boot_targets is the preferable way to define the order in which devices should be booted. I don't think that violates the UEFI specification. It merely is the way U-Boot implements the boot device selection that more traditional UEFI implementations implement using a menu.

Quoted 4 lines

As I don't want to side-track Simon's thread even further, I would like to see a bit more detailed explanation of why U-Boot cannot support EFI variables, or if it's just a matter of someone doing the work, and it's not been a priority yet.

U-Boot has some support for EFI variables, but there are some fundamental problems that make "full" support for them hard or even impossible.

Some non-volatile storage is necessary for these variables such that they can be persistent across boots. Obviously this very much applies to the BootOrder variable. EFI defines calls to manipulate variables as part of its runtime services. This means that the NV storage has to implemented in a way that doesn't interfere with normal OS usage of the hardware. That pretty much means that you need dedicated hardware for this, which most devices supported by U-Boot simply don't have. Having the EFI variables in the U-Boot environment on a reserved part of a uSD card isn't going to work if the OS assumes it has full control over the uSD controller.

Recent versions of the UEFI have made the implementation of some of the runtime services optional (more or less at the request of the EBBR folks) and allow certain calls (e.g. the SetVariable() call) to fail. This poses a bit of a problem though, which I'll try to sketch here:

The way things typically work on a x86 EFI system is that you boot your OS installer from removable media. The OS installer does its thing (partitions the disk, creates filesystems, installs the OS kernel, etc.) and at the end creates a boot option for the boot manager by creating an apropriate Boot#### variable and possibly modifying the BootOrder variable to include the newly created boot option. A typical x86 Linux distro will create a Boot#### variable that is effectively a devicepath pointing at grub.efi. Unfortunately that won't work if the SetVariable() EFI runtime interface doesn't work.

Quoted 6 lines

I'm not sure how the EBBR folks envisaged the OS installation user experience on these systems. Maybe Takahiro can explain. But as long as you don't really care about booting multiple OSes on a system, relying on the default removable media boot path works fine in most cases in that it automatically boots into the installed OS when you reboot after removing the installation media.

Quoted 4 lines

Ah right, run-time variables are where it gets tricky. I would think that when ENV_IS_IN_MMC/etc, where it's a hard location on something, and not a file (which would be hard to share since it's likely mounted via the OS) would let us get past that.

Quoted 8 lines

Not really. As soon as the OS takes over the MMC controller, U-Boot can't touch it anymore. The only thing that really works is using a dedicated device that isn't exposed to the OS. So U-Boot would need to remove its nodes from the device tree. But even then things get tricky with shared clocks and such.

The only really safe option is to use something like TrustZone on ARM devices to completely hide things from the non-secure world.

That's how it also works on servers. They all have dedicated hardware

Quoted 5 lines

I believe that is what Linaro is actually doing in their U-Boot based implementation where the EFI variable store is actually implemented in OP-TEE running in the secure world. However that places demands on the hardware that many SoCs and boards won't be able to fulfill.

There's two general categories here
- SPI/whatever flash on the secure world. That pretty much solves everything, but as you say, imposes hardware restrictions and the runtime part is missing from U-Boot.
- store the variables on an RPMB partition. This currently works on u-boot. It doesn't directly solve the problem with runtime variables, but you can get away with it if the OS agrees (which is against what EFI is trying to do :)). So the RPMB variable storage goes through OP-TEE, I have some out of tree patches for Linux, were the bootloader is installing an empty config table. Upon discovery the OS changes all the runtime callbacks to OP-TEE provided functions, so you can read/write variables properly. I understand that this isn't the best solution, but honestly from the discussions and thoughts I've had up to now, it seems the sanest way to solve the setvariable problem, if the OS is in control of the medium after ExitBootServices. We are in discussions internally to see if there's a better way to do it, and I am open to suggestions. In any case the OS has to do 'something' about it, since it controls the device.

Quoted 3 lines

A lot of the more advance EFI features that have been implemented/proposed (secure boot, capsule updates) do rely on having proper run-time variable support.

0fa5020c024e 'fixes' capsule update on-disk (but kinda breaks the spec)

Quoted 4 lines

So Simon does have a point that the
EFI based approach for that has some serious issues that a "native" U-Boot implementation could avoid and that enabling these EFI features by default adds unecessary "bloat".

Regards
/Ilias

#59 lore raw
In reply to Tom Rini
Quoted 14 lines
Quoted 11 lines

By "EFI app", do you mean a way of booting "/efi/boot/bootXX.efi" (default file name in case that no image path is specified)?

In fact, this behavior, or removable media support, is defined as part of UEFI boot manager in UEFI specification. (See section 3.5) What this means is that the boot order, including a removable media case and user-provided BootXXXX cases, should be controlled solely by "BootOrder" variable.
So the current combination of distro_bootcmd + UEFI boot manger doesn't fully comply with the specification.

Quoted 2 lines

Even if those two cases are integrated, I don't know how "BootOrder" semantics can be preserved in your approach.

Quoted 6 lines

I think the high level answer is that whereas today part of distro_bootcmd (and so iterating over boot_targets) "bootefi bootmgr" gets run, with what Simon is proposing we would have an easier / quicker way to get over to just running that. Perhaps a clean-up to just use that, even? Or are we not to the point yet where we could remove the direct fall-back to /efi/boot/bootXX.efi ?

I've not actually got as far as grabbing this series and trying it out but I like a bunch of the concepts.

If we can use this to replace a bunch of the distro_boot hush script checks for various devices in which to boot from and make it a more standardised logic I think that's an overall win. Double bonus points if we could have an easy way to specify a boot order and even have the ability to have a "Press F8 to display a boot menu" style option where a user could select the specific device they wish to attempt to boot from without having to interrupt the boot, and often dive into printenv and random commands to try and workout where/where/why to get it to overide the onboarad eMMC so they can boot off a USB stick!

Peter