All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
@ 2023-07-12 15:04 Simon Glass
  2023-07-12 15:04 ` [PATCH v3 01/18] test: Skip flat-tree tests if devicetree is not used Simon Glass
                   ` (18 more replies)
  0 siblings, 19 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
to boot the kernel.

Full verified boot is not included at this stage - that is still a
separate chunk of code to be brought into standard boot at some point.
For now it just obtains the kernel and command line and boots. This should
be enough to boot Chrome OS from coreboot on all x86 machines in
circulation, although only Brya (2022) and Coral (2017) have been tested.

ChromiumOS needs quite large kernel parameters, to hold the DM verity
settings and other pieces. This makes it painful to modify just one
parameter, since the whole cmdline must be adjusted at once. To cope with
this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
command allows individual parameters to be added, modified and deleted.

To deal with enabling debug console, a variant supports setting 'earlycon'
and 'console' automatically. The 'bdinfo' command is updated to show
serial-port info also.

Booting the zimage is now done programmatically, rather than running
through the command-line interface. Minor tweaks are made to the coreboot
and coral config so that booting works correctly.

Note that the ACPI tables are not updated with the required firmware
information in this series, so a warning is shown on boot. This will be
addressed later since it requires quite a bit of configuration.

Finally, this fixes a recently introduced bug in unit testing and updates
the algorithm to avoid running flat-tree tests which don't actually use
the devicetree.

Changes in v3:
- Drop CONFIG_MISC and CONFIG_NVMEM
- Update commit message
- Separate out patch to restore test behaviour on failure

Changes in v2:
- Update host_bootdev.c too
- Correct 'it not known' typo
- Explain why the setup information is not behind an #ifdef
- Add comment for copy_in()
- Avoid multiplication on a boolean
- Add a comment as to why @len is needed
- Show error messages when something goes wrong
- Add new patch to create a little more room for U-Boot on qemu-x86_64
- Add new patch to switch x86 qemu to standard boot
- Drop mention of NVMe support

Simon Glass (18):
  test: Skip flat-tree tests if devicetree is not used
  bootstd: Correct the name of the QEMU bootmeth
  bootstd: Use bootdev instead of bootdevice
  bootstd: Correct baudrate typo
  bootstd: Allow storing the OS command line in the bootflow
  bootstd: Use the bootargs env var for changing the cmdline
  bootstd: Allow storing x86 setup information
  bdinfo: Show information about the serial port
  bootstd: Add a function to update a command line
  bootstd: Add support for updating elements of the cmdline
  x86: qemu: Create a little more room for U-Boot
  x86: qemu: Switch to standard boot
  bootstd: Support automatically setting Linux parameters
  x86: Add a function to boot a zimage
  x86: zimage: Export the function to obtain the cmdline
  bootstd: Add a simple bootmeth for ChromiumOS
  x86: coreboot: Adjust various config options
  x86: coral: Adjust various config options

 arch/x86/include/asm/zimage.h      |  27 +++
 arch/x86/lib/zimage.c              |  93 ++++++--
 boot/Kconfig                       |  11 +
 boot/Makefile                      |   1 +
 boot/bootflow.c                    | 339 ++++++++++++++++++++++++++++-
 boot/bootmeth-uclass.c             |   2 +-
 boot/bootmeth_cros.c               | 212 ++++++++++++++++++
 boot/bootmeth_qfw.c                |   2 +-
 cmd/bdinfo.c                       |  21 ++
 cmd/bootflow.c                     |  87 +++++++-
 configs/chromebook_coral_defconfig |  10 +-
 configs/coreboot_defconfig         |  14 +-
 configs/qemu-x86_64_defconfig      |   5 +-
 configs/qemu-x86_defconfig         |   2 +-
 configs/tools-only_defconfig       |   1 +
 doc/usage/cmd/bootflow.rst         | 100 ++++++++-
 drivers/mmc/mmc_bootdev.c          |   2 +-
 drivers/scsi/scsi_bootdev.c        |   2 +-
 drivers/usb/host/usb_bootdev.c     |   2 +-
 fs/sandbox/host_bootdev.c          |   2 +-
 include/bootdev.h                  |   2 +-
 include/bootflow.h                 | 100 ++++++++-
 include/configs/qemu-x86.h         |   8 -
 include/env_callback.h             |   6 +-
 net/eth_bootdev.c                  |   2 +-
 test/boot/bootflow.c               | 263 ++++++++++++++++++++++
 test/test-main.c                   |   3 +-
 27 files changed, 1263 insertions(+), 56 deletions(-)
 create mode 100644 boot/bootmeth_cros.c

-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v3 01/18] test: Skip flat-tree tests if devicetree is not used
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 02/18] bootstd: Correct the name of the QEMU bootmeth Simon Glass
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Many tests don't actually use the devicetree at all so there is no point
in running the tests both with livetree and flat tree. Check for this and
skip the flat tree test in that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 test/test-main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/test-main.c b/test/test-main.c
index 2a3b2ba364a8..778bf0a18a0f 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -476,7 +476,8 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
 	 *   (for sandbox we handle this by copying the tree, but not for other
 	 *    boards)
 	 */
-	if (!(test->flags & UT_TESTF_LIVE_TREE) &&
+	if ((test->flags & UT_TESTF_SCAN_FDT) &&
+	    !(test->flags & UT_TESTF_LIVE_TREE) &&
 	    (CONFIG_IS_ENABLED(OFNODE_MULTI_TREE) ||
 	     !(test->flags & UT_TESTF_OTHER_FDT)) &&
 	    (!runs || ut_test_run_on_flattree(test)) &&
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 02/18] bootstd: Correct the name of the QEMU bootmeth
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
  2023-07-12 15:04 ` [PATCH v3 01/18] test: Skip flat-tree tests if devicetree is not used Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 03/18] bootstd: Use bootdev instead of bootdevice Simon Glass
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

This does not relate to sandbox. Correct the name.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 boot/bootmeth_qfw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/bootmeth_qfw.c b/boot/bootmeth_qfw.c
index ecd4b082fd20..8ebbc3ebcd58 100644
--- a/boot/bootmeth_qfw.c
+++ b/boot/bootmeth_qfw.c
@@ -76,7 +76,7 @@ static int qfw_bootmeth_bind(struct udevice *dev)
 {
 	struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
 
-	plat->desc = "Sandbox boot for testing";
+	plat->desc = "QEMU boot using firmware interface";
 
 	return 0;
 }
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 03/18] bootstd: Use bootdev instead of bootdevice
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
  2023-07-12 15:04 ` [PATCH v3 01/18] test: Skip flat-tree tests if devicetree is not used Simon Glass
  2023-07-12 15:04 ` [PATCH v3 02/18] bootstd: Correct the name of the QEMU bootmeth Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 04/18] bootstd: Correct baudrate typo Simon Glass
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

It seems better to call this a 'bootdev' since this is name used in the
documentation. The older 'Bootdevice' name is no-longer used and may cause
confusion with the 'bootdevice' environment variable.

Update throughout to use bootdev.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Update host_bootdev.c too

 boot/bootflow.c                | 4 ++--
 drivers/mmc/mmc_bootdev.c      | 2 +-
 drivers/scsi/scsi_bootdev.c    | 2 +-
 drivers/usb/host/usb_bootdev.c | 2 +-
 fs/sandbox/host_bootdev.c      | 2 +-
 include/bootdev.h              | 2 +-
 include/bootflow.h             | 2 +-
 net/eth_bootdev.c              | 2 +-
 8 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 8f2cb876bb49..487552fa28c0 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -315,14 +315,14 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow)
 
 	/* If we got a valid bootflow, return it */
 	if (!ret) {
-		log_debug("Bootdevice '%s' part %d method '%s': Found bootflow\n",
+		log_debug("Bootdev '%s' part %d method '%s': Found bootflow\n",
 			  dev->name, iter->part, iter->method->name);
 		return 0;
 	}
 
 	/* Unless there is nothing more to try, move to the next device */
 	else if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) {
-		log_debug("Bootdevice '%s' part %d method '%s': Error %d\n",
+		log_debug("Bootdev '%s' part %d method '%s': Error %d\n",
 			  dev->name, iter->part, iter->method->name, ret);
 		/*
 		 * For 'all' we return all bootflows, even
diff --git a/drivers/mmc/mmc_bootdev.c b/drivers/mmc/mmc_bootdev.c
index b57b8a62276d..55ecead2ddf9 100644
--- a/drivers/mmc/mmc_bootdev.c
+++ b/drivers/mmc/mmc_bootdev.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Bootdevice for MMC
+ * Bootdev for MMC
  *
  * Copyright 2021 Google LLC
  * Written by Simon Glass <sjg@chromium.org>
diff --git a/drivers/scsi/scsi_bootdev.c b/drivers/scsi/scsi_bootdev.c
index 991013fe1ef2..218221fa3062 100644
--- a/drivers/scsi/scsi_bootdev.c
+++ b/drivers/scsi/scsi_bootdev.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Bootdevice for USB
+ * Bootdev for SCSI
  *
  * Copyright 2021 Google LLC
  * Written by Simon Glass <sjg@chromium.org>
diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c
index 06e8f61aa1c5..7fa1c601dff5 100644
--- a/drivers/usb/host/usb_bootdev.c
+++ b/drivers/usb/host/usb_bootdev.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Bootdevice for USB
+ * Bootdev for USB
  *
  * Copyright 2021 Google LLC
  * Written by Simon Glass <sjg@chromium.org>
diff --git a/fs/sandbox/host_bootdev.c b/fs/sandbox/host_bootdev.c
index 0d12ee4ef74f..3ef53627608a 100644
--- a/fs/sandbox/host_bootdev.c
+++ b/fs/sandbox/host_bootdev.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Bootdevice for MMC
+ * Bootdev for sandbox host
  *
  * Copyright 2021 Google LLC
  * Written by Simon Glass <sjg@chromium.org>
diff --git a/include/bootdev.h b/include/bootdev.h
index e72ef3650f7c..1533adfe5065 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -200,7 +200,7 @@ void bootdev_clear_bootflows(struct udevice *dev);
  * All fields in @bflow must be set up. Note that @bflow->dev is used to add the
  * bootflow to that device.
  *
- * @dev: Bootdevice device to add to
+ * @dev: Bootdev device to add to
  * @bflow: Bootflow to add. Note that fields within bflow must be allocated
  *	since this function takes over ownership of these. This functions makes
  *	a copy of @bflow itself (without allocating its fields again), so the
diff --git a/include/bootflow.h b/include/bootflow.h
index f20f575030f1..018d021b8107 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -58,7 +58,7 @@ enum bootflow_flags_t {
  *
  * @bm_node: Points to siblings in the same bootdev
  * @glob_node: Points to siblings in the global list (all bootdev)
- * @dev: Bootdevice device which produced this bootflow
+ * @dev: Bootdev device which produced this bootflow
  * @blk: Block device which contains this bootflow, NULL if this is a network
  *	device or sandbox 'host' device
  * @part: Partition number (0 for whole device)
diff --git a/net/eth_bootdev.c b/net/eth_bootdev.c
index f7b4196f78db..869adf8cbbd3 100644
--- a/net/eth_bootdev.c
+++ b/net/eth_bootdev.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Bootdevice for ethernet (uses PXE)
+ * Bootdev for ethernet (uses PXE)
  *
  * Copyright 2021 Google LLC
  * Written by Simon Glass <sjg@chromium.org>
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 04/18] bootstd: Correct baudrate typo
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (2 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 03/18] bootstd: Use bootdev instead of bootdevice Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 05/18] bootstd: Allow storing the OS command line in the bootflow Simon Glass
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

This is a copy error. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 boot/bootmeth-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 3b3e0614dafa..33662a753889 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -421,7 +421,7 @@ int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,
 /**
  * on_bootmeths() - Update the bootmeth order
  *
- * This will check for a valid baudrate and only apply it if valid.
+ * This will check for a valid list of bootmeths and only apply it if valid.
  */
 static int on_bootmeths(const char *name, const char *value, enum env_op op,
 			int flags)
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 05/18] bootstd: Allow storing the OS command line in the bootflow
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (3 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 04/18] bootstd: Correct baudrate typo Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 06/18] bootstd: Use the bootargs env var for changing the cmdline Simon Glass
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Some operating systems have a command line which can be adjusted before
booting. Store this in the bootflow so it can be controlled within
U-Boot.

Fix up the example output while we are here, since there are a few new
items.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Correct 'it not known' typo

 cmd/bootflow.c             | 6 ++++++
 doc/usage/cmd/bootflow.rst | 5 ++++-
 include/bootflow.h         | 2 ++
 test/boot/bootflow.c       | 1 +
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 5c61286a2a76..ddb168c70390 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -324,6 +324,12 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	printf("Buffer:    %lx\n", (ulong)map_to_sysmem(bflow->buf));
 	printf("Size:      %x (%d bytes)\n", bflow->size, bflow->size);
 	printf("OS:        %s\n", bflow->os_name ? bflow->os_name : "(none)");
+	printf("Cmdline:   ");
+	if (bflow->cmdline)
+		puts(bflow->cmdline);
+	else
+		puts("(none)");
+	putc('\n');
 	printf("Logo:      %s\n", bflow->logo ?
 	       simple_xtoa((ulong)map_to_sysmem(bflow->logo)) : "(none)");
 	if (bflow->logo) {
diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst
index 8590efca2182..907d44ad9f9b 100644
--- a/doc/usage/cmd/bootflow.rst
+++ b/doc/usage/cmd/bootflow.rst
@@ -258,7 +258,6 @@ displayed and booted::
     Name:      mmc@7e202000.bootdev.part_2
     Device:    mmc@7e202000.bootdev
     Block dev: mmc@7e202000.blk
-    Sequence:  1
     Method:    distro
     State:     ready
     Partition: 2
@@ -266,6 +265,10 @@ displayed and booted::
     Filename:  extlinux/extlinux.conf
     Buffer:    3db7ae88
     Size:      232 (562 bytes)
+    OS:        Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
+    Cmdline:   (none)
+    Logo:      (none)
+    FDT:       <NULL>
     Error:     0
     U-Boot> bootflow boot
     ** Booting bootflow 'smsc95xx_eth.bootdev.0'
diff --git a/include/bootflow.h b/include/bootflow.h
index 018d021b8107..a1c16ab93b75 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -81,6 +81,7 @@ enum bootflow_flags_t {
  * @fdt_size: Size of FDT file
  * @fdt_addr: Address of loaded fdt
  * @flags: Flags for the bootflow (see enum bootflow_flags_t)
+ * @cmdline: OS command line, or NULL if not known (allocated)
  */
 struct bootflow {
 	struct list_head bm_node;
@@ -104,6 +105,7 @@ struct bootflow {
 	int fdt_size;
 	ulong fdt_addr;
 	int flags;
+	char *cmdline;
 };
 
 /**
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 2b5f87d7f091..f7ebf9d7f278 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -226,6 +226,7 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
 	ut_assert_nextlinen("Buffer:    ");
 	ut_assert_nextline("Size:      253 (595 bytes)");
 	ut_assert_nextline("OS:        Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
+	ut_assert_nextline("Cmdline:   (none)");
 	ut_assert_nextline("Logo:      (none)");
 	ut_assert_nextline("FDT:       <NULL>");
 	ut_assert_nextline("Error:     0");
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 06/18] bootstd: Use the bootargs env var for changing the cmdline
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (4 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 05/18] bootstd: Allow storing the OS command line in the bootflow Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 07/18] bootstd: Allow storing x86 setup information Simon Glass
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

The "bootargs" environment variable is used to set the command-line
arguments to pass to the OS. Use this same mechanism with bootstd as well.
When the variable is updated, it is written to the current bootflow. When
the current bootflow is updated, the environment variable is updated too.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 boot/bootflow.c        | 59 ++++++++++++++++++++++++++++++++++++++++++
 cmd/bootflow.c         |  6 +++++
 include/env_callback.h |  6 +++--
 3 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 487552fa28c0..62b7f45ab278 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -12,6 +12,7 @@
 #include <bootmeth.h>
 #include <bootstd.h>
 #include <dm.h>
+#include <env_internal.h>
 #include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
@@ -552,3 +553,61 @@ int bootflow_iter_check_system(const struct bootflow_iter *iter)
 
 	return -ENOTSUPP;
 }
+
+/**
+ * bootflow_cmdline_set() - Set the command line for a bootflow
+ *
+ * @value: New command-line string
+ * Returns 0 if OK, -ENOENT if no current bootflow, -ENOMEM if out of memory
+ */
+int bootflow_cmdline_set(struct bootflow *bflow, const char *value)
+{
+	char *cmdline = NULL;
+
+	if (value) {
+		cmdline = strdup(value);
+		if (!cmdline)
+			return -ENOMEM;
+	}
+
+	free(bflow->cmdline);
+	bflow->cmdline = cmdline;
+
+	return 0;
+}
+
+#ifdef CONFIG_BOOTSTD_FULL
+/**
+ * on_bootargs() - Update the cmdline of a bootflow
+ */
+static int on_bootargs(const char *name, const char *value, enum env_op op,
+		       int flags)
+{
+	struct bootstd_priv *std;
+	struct bootflow *bflow;
+	int ret;
+
+	ret = bootstd_get_priv(&std);
+	if (ret)
+		return 0;
+	bflow = std->cur_bootflow;
+	if (!bflow)
+		return 0;
+
+	switch (op) {
+	case env_op_create:
+	case env_op_overwrite:
+		ret = bootflow_cmdline_set(bflow, value);
+		if (ret && ret != ENOENT)
+			return 1;
+		return 0;
+	case env_op_delete:
+		bootflow_cmdline_set(bflow, NULL);
+		fallthrough;
+	default:
+		return 0;
+	}
+}
+U_BOOT_ENV_CALLBACK(bootargs, on_bootargs);
+#endif
+
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index ddb168c70390..f33db7be5f2e 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -288,6 +288,12 @@ static int do_bootflow_select(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 	std->cur_bootflow = found;
+	if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
+		if (env_set("bootargs", found->cmdline)) {
+			printf("Cannot set bootargs\n");
+			return CMD_RET_FAILURE;
+		}
+	}
 
 	return 0;
 }
diff --git a/include/env_callback.h b/include/env_callback.h
index a9a14f2a84a5..23bc650c162d 100644
--- a/include/env_callback.h
+++ b/include/env_callback.h
@@ -60,8 +60,10 @@
 #define NET6_CALLBACKS
 #endif
 
-#ifdef CONFIG_BOOTSTD
-#define BOOTSTD_CALLBACK	"bootmeths:bootmeths,"
+#ifdef CONFIG_BOOTSTD_FULL
+#define BOOTSTD_CALLBACK \
+	"bootmeths:bootmeths," \
+	"bootargs:bootargs,"
 #else
 #define BOOTSTD_CALLBACK
 #endif
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 07/18] bootstd: Allow storing x86 setup information
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (5 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 06/18] bootstd: Use the bootargs env var for changing the cmdline Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 08/18] bdinfo: Show information about the serial port Simon Glass
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

On x86 boards Linux uses a block of binary data to provide information
about the command line, memory map, etc. Provide a way to store this in
the bootflow so it can be passed on to the OS.

No attempt is made to generalise the code, since other archs don't need
this information. The field is present always, though, to avoid needing
accessors or #ifdefs when building code on other archs.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Explain why the setup information is not behind an #ifdef

 cmd/bootflow.c     | 2 ++
 include/bootflow.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index f33db7be5f2e..bf30087c7c4e 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -336,6 +336,8 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	else
 		puts("(none)");
 	putc('\n');
+	if (bflow->x86_setup)
+		printf("X86 setup: %p\n", bflow->x86_setup);
 	printf("Logo:      %s\n", bflow->logo ?
 	       simple_xtoa((ulong)map_to_sysmem(bflow->logo)) : "(none)");
 	if (bflow->logo) {
diff --git a/include/bootflow.h b/include/bootflow.h
index a1c16ab93b75..f263173c4da5 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -82,6 +82,7 @@ enum bootflow_flags_t {
  * @fdt_addr: Address of loaded fdt
  * @flags: Flags for the bootflow (see enum bootflow_flags_t)
  * @cmdline: OS command line, or NULL if not known (allocated)
+ * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present
  */
 struct bootflow {
 	struct list_head bm_node;
@@ -106,6 +107,7 @@ struct bootflow {
 	ulong fdt_addr;
 	int flags;
 	char *cmdline;
+	char *x86_setup;
 };
 
 /**
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 08/18] bdinfo: Show information about the serial port
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (6 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 07/18] bootstd: Allow storing x86 setup information Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 09/18] bootstd: Add a function to update a command line Simon Glass
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

It is useful to see the detailed setting of the serial port, e.g. to
allow setting up earlycon or console for Linux. Add this output to the
'bdinfo' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 cmd/bdinfo.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 365357ca545f..dab73f1d93c4 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -13,6 +13,7 @@
 #include <lmb.h>
 #include <mapmem.h>
 #include <net.h>
+#include <serial.h>
 #include <video.h>
 #include <vsprintf.h>
 #include <asm/cache.h>
@@ -113,6 +114,25 @@ static void show_video_info(void)
 	}
 }
 
+static void print_serial(struct udevice *dev)
+{
+	struct serial_device_info info;
+	int ret;
+
+	if (!dev || !IS_ENABLED(CONFIG_DM_SERIAL))
+		return;
+
+	ret = serial_getinfo(dev, &info);
+	if (ret)
+		return;
+
+	bdinfo_print_num_l("serial addr", info.addr);
+	bdinfo_print_num_l(" width", info.reg_width);
+	bdinfo_print_num_l(" shift", info.reg_shift);
+	bdinfo_print_num_l(" offset", info.reg_offset);
+	bdinfo_print_num_l(" clock", info.clock);
+}
+
 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct bd_info *bd = gd->bd;
@@ -151,6 +171,7 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		if (IS_ENABLED(CONFIG_OF_REAL))
 			printf("devicetree  = %s\n", fdtdec_get_srcname());
 	}
+	print_serial(gd->cur_serial_dev);
 
 	arch_print_bdinfo();
 
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 09/18] bootstd: Add a function to update a command line
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (7 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 08/18] bdinfo: Show information about the serial port Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 10/18] bootstd: Add support for updating elements of the cmdline Simon Glass
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

The Linux command line consists of a number of words with optional values.
At present U-Boot allows this to be changed using the bootargs environment
variable.

But this is quite painful, since the command line can be very long.

Add a function which can adjust a single field in the command line, so
that it is easier to make changes before booting.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Add comment for copy_in()
- Avoid multiplication on a boolean
- Add a comment as to why @len is needed

 boot/bootflow.c      | 190 +++++++++++++++++++++++++++++++++++++++++++
 include/bootflow.h   |  40 +++++++++
 test/boot/bootflow.c | 154 +++++++++++++++++++++++++++++++++++
 3 files changed, 384 insertions(+)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 62b7f45ab278..26f26aee38a3 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -611,3 +611,193 @@ static int on_bootargs(const char *name, const char *value, enum env_op op,
 U_BOOT_ENV_CALLBACK(bootargs, on_bootargs);
 #endif
 
+/**
+ * copy_in() - Copy a string into a cmdline buffer
+ *
+ * @buf: Buffer to copy into
+ * @end: End of buffer (pointer to char after the end)
+ * @arg: String to copy from
+ * @len: Number of chars to copy from @arg (note that this is not usually the
+ * sane as strlen(arg) since the string may contain following arguments)
+ * @new_val: Value to put after arg, or BOOTFLOWCL_EMPTY to use an empty value
+ * with no '=' sign
+ * Returns: Number of chars written to @buf
+ */
+static int copy_in(char *buf, char *end, const char *arg, int len,
+		   const char *new_val)
+{
+	char *to = buf;
+
+	/* copy the arg name */
+	if (to + len >= end)
+		return -E2BIG;
+	memcpy(to, arg, len);
+	to += len;
+
+	if (new_val == BOOTFLOWCL_EMPTY) {
+		/* no value */
+	} else {
+		bool need_quote = strchr(new_val, ' ');
+		len = strlen(new_val);
+
+		/* need space for value, equals sign and maybe two quotes */
+		if (to + 1 + (need_quote ? 2 : 0) + len >= end)
+			return -E2BIG;
+		*to++ = '=';
+		if (need_quote)
+			*to++ = '"';
+		memcpy(to, new_val, len);
+		to += len;
+		if (need_quote)
+			*to++ = '"';
+	}
+
+	return to - buf;
+}
+
+int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
+		    const char *set_arg, const char *new_val, int *posp)
+{
+	bool found_arg = false;
+	const char *from;
+	char *to, *end;
+	int set_arg_len;
+	char empty = '\0';
+	int ret;
+
+	from = cmdline ?: &empty;
+
+	/* check if the value has quotes inside */
+	if (new_val && new_val != BOOTFLOWCL_EMPTY && strchr(new_val, '"'))
+		return -EBADF;
+
+	set_arg_len = strlen(set_arg);
+	for (to = buf, end = buf + maxlen; *from;) {
+		const char *val, *arg_end, *val_end, *p;
+		bool in_quote;
+
+		if (to >= end)
+			return -E2BIG;
+		while (*from == ' ')
+			from++;
+		if (!*from)
+			break;
+
+		/* find the end of this arg */
+		val = NULL;
+		arg_end = NULL;
+		val_end = NULL;
+		in_quote = false;
+		for (p = from;; p++) {
+			if (in_quote) {
+				if (!*p)
+					return -EINVAL;
+				if (*p == '"')
+					in_quote = false;
+				continue;
+			}
+			if (*p == '=') {
+				arg_end = p;
+				val = p + 1;
+			} else if (*p == '"') {
+				in_quote = true;
+			} else if (!*p || *p == ' ') {
+				val_end = p;
+				if (!arg_end)
+					arg_end = p;
+				break;
+			}
+		}
+		/*
+		 * At this point val_end points to the end of the value, or the
+		 * last char after the arg name, if there is no label.
+		 * arg_end is the char after the arg name
+		 * val points to the value, or NULL if there is none
+		 * char after the value.
+		 *
+		 *        fred=1234
+		 *        ^   ^^   ^
+		 *      from  ||   |
+		 *           / \    \
+		 *    arg_end  val   val_end
+		 */
+		log_debug("from %s arg_end %ld val %ld val_end %ld\n", from,
+			  (long)(arg_end - from), (long)(val - from),
+			  (long)(val_end - from));
+
+		if (to != buf) {
+			if (to >= end)
+				return -E2BIG;
+			*to++ = ' ';
+		}
+
+		/* if this is the target arg, update it */
+		if (!strncmp(from, set_arg, arg_end - from)) {
+			if (!buf) {
+				bool has_quote = val_end[-1] == '"';
+
+				/*
+				 * exclude any start/end quotes from
+				 * calculations
+				 */
+				if (!val)
+					val = val_end;
+				*posp = val - cmdline + has_quote;
+				return val_end - val - 2 * has_quote;
+			}
+			found_arg = true;
+			if (!new_val) {
+				/* delete this arg */
+				from = val_end + (*val_end == ' ');
+				log_debug("delete from: %s\n", from);
+				if (to != buf)
+					to--; /* drop the space we added */
+				continue;
+			}
+
+			ret = copy_in(to, end, from, arg_end - from, new_val);
+			if (ret < 0)
+				return ret;
+			to += ret;
+
+		/* if not the target arg, copy it unchanged */
+		} else if (to) {
+			int len;
+
+			len = val_end - from;
+			if (to + len >= end)
+				return -E2BIG;
+			memcpy(to, from, len);
+			to += len;
+		}
+		from = val_end;
+	}
+
+	/* If we didn't find the arg, add it */
+	if (!found_arg) {
+		/* trying to delete something that is not there */
+		if (!new_val || !buf)
+			return -ENOENT;
+		if (to >= end)
+			return -E2BIG;
+
+		/* add a space to separate it from the previous arg */
+		if (to != buf && to[-1] != ' ')
+			*to++ = ' ';
+		ret = copy_in(to, end, set_arg, set_arg_len, new_val);
+		log_debug("ret=%d, to: %s buf: %s\n", ret, to, buf);
+		if (ret < 0)
+			return ret;
+		to += ret;
+	}
+
+	/* delete any trailing space */
+	if (to > buf && to[-1] == ' ')
+		to--;
+
+	if (to >= end)
+		return -E2BIG;
+	*to++ = '\0';
+
+	return to - buf;
+}
diff --git a/include/bootflow.h b/include/bootflow.h
index f263173c4da5..8db875adf610 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -444,4 +444,44 @@ int bootflow_menu_apply_theme(struct expo *exp, ofnode node);
 int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
 		      struct bootflow **bflowp);
 
+#define BOOTFLOWCL_EMPTY	((void *)1)
+
+/**
+ * cmdline_set_arg() - Update or read an argument in a cmdline string
+ *
+ * Handles updating a single arg in a cmdline string, returning it in a supplied
+ * buffer; also reading an arg from a cmdline string
+ *
+ * When updating, consecutive spaces are squashed as are spaces at the start and
+ * end.
+ *
+ * @buf: Working buffer to use (initial contents are ignored). Use NULL when
+ * reading
+ * @maxlen: Length of working buffer. Use 0 when reading
+ * @cmdline: Command line to update, in the form:
+ *
+ *	fred mary= jane=123 john="has spaces"
+ *
+ * @set_arg: Argument to set or read (may or may not exist)
+ * @new_val: Value for the new argument. May not include quotes (") but may
+ * include embedded spaces, in which case it will be quoted when added to the
+ * command line. Use NULL to delete the argument from @cmdline, BOOTFLOWCL_EMPTY
+ * to set it to an empty value (no '=' sign after arg), "" to add an '=' sign
+ * but with an empty value. Use NULL when reading.
+ * @posp: Ignored when setting an argument; when getting an argument, returns
+ * the start position of its value in @cmdline, after the first quote, if any
+ *
+ * Return:
+ * For updating:
+ *	length of new buffer (including \0 terminator) on success, -ENOENT if
+ *	@new_val is NULL and @set_arg does not exist in @from, -EINVAL if a
+ *	quoted arg-value in @from is not terminated with a quote, -EBADF if
+ *	@new_val has spaces but does not start and end with quotes (or it has
+ *	quotes in the middle of the string), -E2BIG if @maxlen is too small
+ * For reading:
+ *	length of arg value (excluding quotes), -ENOENT if not found
+ */
+int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
+		    const char *set_arg, const char *new_val, int *posp);
+
 #endif
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index f7ebf9d7f278..ead71172e12f 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -683,3 +683,157 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/**
+ * check_arg() - Check both the normal case and the buffer-overflow case
+ *
+ * @uts: Unit-test state
+ * @expect_ret: Expected return value (i.e. buffer length)
+ * @expect_str: String expected to be returned
+ * @buf: Buffer to use
+ * @from: Original cmdline to update
+ * @arg: Argument to update (e.g. "console")
+ * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
+ * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
+ * it without any value ("initrd")
+ */
+static int check_arg(struct unit_test_state *uts, int expect_ret,
+		     const char *expect_str, char *buf, const char *from,
+		     const char *arg, const char *val)
+{
+	/* check for writing outside the reported bounds */
+	buf[expect_ret] = '[';
+	ut_asserteq(expect_ret,
+		    cmdline_set_arg(buf, expect_ret, from, arg, val, NULL));
+	ut_asserteq_str(expect_str, buf);
+	ut_asserteq('[', buf[expect_ret]);
+
+	/* do the test again but with one less byte in the buffer */
+	ut_asserteq(-E2BIG, cmdline_set_arg(buf, expect_ret - 1, from, arg,
+					    val, NULL));
+
+	return 0;
+}
+
+/* Test of bootflow_cmdline_set_arg() */
+static int test_bootflow_cmdline_set(struct unit_test_state *uts)
+{
+	char buf[50];
+	const int size = sizeof(buf);
+
+	/*
+	 * note that buffer-overflow tests are immediately each test case, just
+	 * top keep the code together
+	 */
+
+	/* add an arg that doesn't already exist, starting from empty */
+	ut_asserteq(-ENOENT, cmdline_set_arg(buf, size, NULL, "me", NULL,
+					     NULL));
+
+	ut_assertok(check_arg(uts, 3, "me", buf, NULL, "me", BOOTFLOWCL_EMPTY));
+	ut_assertok(check_arg(uts, 4, "me=", buf, NULL, "me", ""));
+	ut_assertok(check_arg(uts, 8, "me=fred", buf, NULL, "me", "fred"));
+
+	/* add an arg that doesn't already exist, starting from non-empty */
+	ut_assertok(check_arg(uts, 11, "arg=123 me", buf, "arg=123", "me",
+			      BOOTFLOWCL_EMPTY));
+	ut_assertok(check_arg(uts, 12, "arg=123 me=", buf, "arg=123", "me",
+			      ""));
+	ut_assertok(check_arg(uts, 16, "arg=123 me=fred", buf, "arg=123", "me",
+			      "fred"));
+
+	/* update an arg at the start */
+	ut_assertok(check_arg(uts, 1, "", buf, "arg=123", "arg", NULL));
+	ut_assertok(check_arg(uts, 4, "arg", buf, "arg=123", "arg",
+			      BOOTFLOWCL_EMPTY));
+	ut_assertok(check_arg(uts, 5, "arg=", buf, "arg=123", "arg", ""));
+	ut_assertok(check_arg(uts, 6, "arg=1", buf, "arg=123", "arg", "1"));
+	ut_assertok(check_arg(uts, 9, "arg=1234", buf, "arg=123", "arg",
+			      "1234"));
+
+	/* update an arg at the end */
+	ut_assertok(check_arg(uts, 5, "mary", buf, "mary arg=123", "arg",
+			      NULL));
+	ut_assertok(check_arg(uts, 9, "mary arg", buf, "mary arg=123", "arg",
+			      BOOTFLOWCL_EMPTY));
+	ut_assertok(check_arg(uts, 10, "mary arg=", buf, "mary arg=123", "arg",
+			      ""));
+	ut_assertok(check_arg(uts, 11, "mary arg=1", buf, "mary arg=123", "arg",
+			      "1"));
+	ut_assertok(check_arg(uts, 14, "mary arg=1234", buf, "mary arg=123",
+			      "arg", "1234"));
+
+	/* update an arg in the middle */
+	ut_assertok(check_arg(uts, 16, "mary=abc john=2", buf,
+			      "mary=abc arg=123 john=2", "arg", NULL));
+	ut_assertok(check_arg(uts, 20, "mary=abc arg john=2", buf,
+			      "mary=abc arg=123 john=2", "arg",
+			      BOOTFLOWCL_EMPTY));
+	ut_assertok(check_arg(uts, 21, "mary=abc arg= john=2", buf,
+			      "mary=abc arg=123 john=2", "arg", ""));
+	ut_assertok(check_arg(uts, 22, "mary=abc arg=1 john=2", buf,
+			      "mary=abc arg=123 john=2", "arg", "1"));
+	ut_assertok(check_arg(uts, 25, "mary=abc arg=1234 john=2", buf,
+			      "mary=abc arg=123 john=2", "arg", "1234"));
+
+	/* handle existing args with quotes */
+	ut_assertok(check_arg(uts, 16, "mary=\"abc\" john", buf,
+			      "mary=\"abc\" arg=123 john", "arg", NULL));
+
+	/* handle existing args with quoted spaces */
+	ut_assertok(check_arg(uts, 20, "mary=\"abc def\" john", buf,
+			      "mary=\"abc def\" arg=123 john", "arg", NULL));
+
+	ut_assertok(check_arg(uts, 34, "mary=\"abc def\" arg=123 john def=4",
+			      buf, "mary=\"abc def\" arg=123 john", "def",
+			      "4"));
+
+	/* quote at the start */
+	ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+					    "mary=\"abc def\" arg=\"123 456\"",
+					    "arg", "\"4 5 6", NULL));
+
+	/* quote at the end */
+	ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+					    "mary=\"abc def\" arg=\"123 456\"",
+					    "arg", "4 5 6\"", NULL));
+
+	/* quote in the middle */
+	ut_asserteq(-EBADF, cmdline_set_arg(buf, size,
+					    "mary=\"abc def\" arg=\"123 456\"",
+					    "arg", "\"4 \"5 6\"", NULL));
+
+	/* handle updating a quoted arg */
+	ut_assertok(check_arg(uts, 27, "mary=\"abc def\" arg=\"4 5 6\"", buf,
+			      "mary=\"abc def\" arg=\"123 456\"", "arg",
+			      "4 5 6"));
+
+	/* changing a quoted arg to a non-quoted arg */
+	ut_assertok(check_arg(uts, 23, "mary=\"abc def\" arg=789", buf,
+			      "mary=\"abc def\" arg=\"123 456\"", "arg",
+			      "789"));
+
+	/* changing a non-quoted arg to a quoted arg */
+	ut_assertok(check_arg(uts, 29, "mary=\"abc def\" arg=\"456 789\"", buf,
+			      "mary=\"abc def\" arg=123", "arg", "456 789"));
+
+	/* handling of spaces */
+	ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123"));
+	ut_assertok(check_arg(uts, 8, "arg=123", buf, "   ", "arg", "123"));
+	ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john  ", "arg",
+			      "123"));
+	ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john  arg=123  ",
+			      "arg", "123"));
+	ut_assertok(check_arg(uts, 18, "john arg=123 mary", buf,
+			      " john  arg=123 mary ", "arg", "123"));
+
+	/* unchanged arg */
+	ut_assertok(check_arg(uts, 3, "me", buf, "me", "me", BOOTFLOWCL_EMPTY));
+
+	/* arg which starts with the same name */
+	ut_assertok(check_arg(uts, 28, "mary=abc johnathon=2 john=3", buf,
+			      "mary=abc johnathon=2 john=1", "john", "3"));
+
+	return 0;
+}
+BOOTSTD_TEST(test_bootflow_cmdline_set, 0);
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 10/18] bootstd: Add support for updating elements of the cmdline
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (8 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 09/18] bootstd: Add a function to update a command line Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 11/18] x86: qemu: Create a little more room for U-Boot Simon Glass
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Add a bootflow command to update the command line more easily. This allows
changing a particular parameter rather than editing a very long strings.
It is also easier to handle with scripting.

The new 'bootflow cmdline' command allows getting and setting single
parameters.

Fix up the example output while we are here, since there are a few new
items.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Show error messages when something goes wrong

 boot/bootflow.c            |  53 ++++++++++++++++++
 cmd/bootflow.c             |  70 +++++++++++++++++++++++-
 doc/usage/cmd/bootflow.rst |  22 +++++++-
 include/bootflow.h         |  42 +++++++++++++++
 test/boot/bootflow.c       | 108 +++++++++++++++++++++++++++++++++++++
 5 files changed, 293 insertions(+), 2 deletions(-)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 26f26aee38a3..8c649e8e66ca 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -801,3 +801,56 @@ int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
 
 	return to - buf;
 }
+
+int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *set_arg,
+			     const char *new_val, bool set_env)
+{
+	char buf[2048];
+	char *cmd = NULL;
+	int ret;
+
+	ret = cmdline_set_arg(buf, sizeof(buf), bflow->cmdline, set_arg,
+			      new_val, NULL);
+	if (ret < 0)
+		return ret;
+
+	ret = bootflow_cmdline_set(bflow, buf);
+	if (*buf) {
+		cmd = strdup(buf);
+		if (!cmd)
+			return -ENOMEM;
+	}
+	free(bflow->cmdline);
+	bflow->cmdline = cmd;
+
+	if (set_env) {
+		ret = env_set("bootargs", bflow->cmdline);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+int cmdline_get_arg(const char *cmdline, const char *arg, int *posp)
+{
+	int ret;
+
+	ret = cmdline_set_arg(NULL, 1, cmdline, arg, NULL, posp);
+
+	return ret;
+}
+
+int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
+			     const char **val)
+{
+	int ret;
+	int pos;
+
+	ret = cmdline_get_arg(bflow->cmdline, arg, &pos);
+	if (ret < 0)
+		return ret;
+	*val = bflow->cmdline + pos;
+
+	return ret;
+}
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index bf30087c7c4e..ab00e4a19e14 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -431,6 +431,72 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	return 0;
 }
+
+static int do_bootflow_cmdline(struct cmd_tbl *cmdtp, int flag, int argc,
+			       char *const argv[])
+{
+	struct bootstd_priv *std;
+	struct bootflow *bflow;
+	const char *op, *arg, *val = NULL;
+	int ret;
+
+	if (argc < 3)
+		return CMD_RET_USAGE;
+
+	ret = bootstd_get_priv(&std);
+	if (ret)
+		return CMD_RET_FAILURE;
+
+	bflow = std->cur_bootflow;
+	if (!bflow) {
+		printf("No bootflow selected\n");
+		return CMD_RET_FAILURE;
+	}
+
+	op = argv[1];
+	arg = argv[2];
+	if (*op == 's') {
+		if (argc < 4)
+			return CMD_RET_USAGE;
+		val = argv[3];
+	}
+
+	switch (*op) {
+	case 'c':	/* clear */
+		val = "";
+		fallthrough;
+	case 's':	/* set */
+	case 'd':	/* delete */
+		ret = bootflow_cmdline_set_arg(bflow, arg, val, true);
+		break;
+	case 'g':	/* get */
+		ret = bootflow_cmdline_get_arg(bflow, arg, &val);
+		if (ret >= 0)
+			printf("%.*s\n", ret, val);
+		break;
+	}
+	switch (ret) {
+	case -E2BIG:
+		printf("Argument too long\n");
+		break;
+	case -ENOENT:
+		printf("Argument not found\n");
+		break;
+	case -EINVAL:
+		printf("Mismatched quotes\n");
+		break;
+	case -EBADF:
+		printf("Value must be quoted\n");
+		break;
+	default:
+		if (ret < 0)
+			printf("Unknown error: %dE\n", ret);
+	}
+	if (ret < 0)
+		return CMD_RET_FAILURE;
+
+	return 0;
+}
 #endif /* CONFIG_CMD_BOOTFLOW_FULL */
 
 #ifdef CONFIG_SYS_LONGHELP
@@ -441,7 +507,8 @@ static char bootflow_help_text[] =
 	"bootflow select [<num>|<name>] - select a bootflow\n"
 	"bootflow info [-d]             - show info on current bootflow (-d dump bootflow)\n"
 	"bootflow boot                  - boot current bootflow (or first available if none selected)\n"
-	"bootflow menu [-t]             - show a menu of available bootflows";
+	"bootflow menu [-t]             - show a menu of available bootflows\n"
+	"bootflow cmdline [set|get|clear|delete] <param> [<value>] - update cmdline";
 #else
 	"scan - boot first available bootflow\n";
 #endif
@@ -455,5 +522,6 @@ U_BOOT_CMD_WITH_SUBCMDS(bootflow, "Boot flows", bootflow_help_text,
 	U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info),
 	U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot),
 	U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu),
+	U_BOOT_SUBCMD_MKENT(cmdline, 4, 1, do_bootflow_cmdline),
 #endif
 );
diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst
index 907d44ad9f9b..07af789e6702 100644
--- a/doc/usage/cmd/bootflow.rst
+++ b/doc/usage/cmd/bootflow.rst
@@ -13,7 +13,7 @@ Synopis
     bootflow select [<num|name>]
     bootflow info [-d]
     bootflow boot
-
+    bootflow cmdline [set|get|clear|delete] <param> [<value>]
 
 Description
 -----------
@@ -198,6 +198,26 @@ bootflow boot
 This boots the current bootflow.
 
 
+bootflow cmdline
+~~~~~~~~~~~~~~~~
+
+Some bootmeths can obtain the OS command line since it is stored with the OS.
+In that case, you can use `bootflow cmdline` to adjust this. The command line
+is assumed to be in the format used by Linux, i.e. a space-separated set of
+parameters with optional values, e.g. "noinitrd console=/dev/tty0".
+
+To change or add a parameter, use::
+
+    bootflow cmdline set <param> <value>
+
+To clear a parameter value to empty you can use "" for the value, or use::
+
+    bootflow cmdline clear <param>
+
+To delete a parameter entirely, use::
+
+    bootflow cmdline delete <param>
+
 Example
 -------
 
diff --git a/include/bootflow.h b/include/bootflow.h
index 8db875adf610..7a8595f3dfcf 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -484,4 +484,46 @@ int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
 int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
 		    const char *set_arg, const char *new_val, int *posp);
 
+/**
+ * bootflow_cmdline_set_arg() - Set a single argument for a bootflow
+ *
+ * Update the allocated cmdline and set the bootargs variable
+ *
+ * @bflow: Bootflow to update
+ * @arg: Argument to update (e.g. "console")
+ * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
+ * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
+ * it without any value ("initrd")
+ * @set_env: true to set the "bootargs" environment variable too
+ *
+ * Return: 0 if OK, -ENOMEM if out of memory
+ */
+int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *arg,
+			     const char *val, bool set_env);
+
+/**
+ * cmdline_get_arg() - Read an argument from a cmdline
+ *
+ * @cmdline: Command line to read, in the form:
+ *
+ *	fred mary= jane=123 john="has spaces"
+ * @arg: Argument to read (may or may not exist)
+ * @posp: Returns position of argument (after any leading quote) if present
+ * Return: Length of argument value excluding quotes if found, -ENOENT if not
+ * found
+ */
+int cmdline_get_arg(const char *cmdline, const char *arg, int *posp);
+
+/**
+ * bootflow_cmdline_get_arg() - Read an argument from a cmdline
+ *
+ * @bootflow: Bootflow to read from
+ * @arg: Argument to read (may or may not exist)
+ * @valp: Returns a pointer to the argument (after any leading quote) if present
+ * Return: Length of argument value excluding quotes if found, -ENOENT if not
+ * found
+ */
+int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
+			     const char **val);
+
 #endif
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index ead71172e12f..8a4e090e9bcf 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -837,3 +837,111 @@ static int test_bootflow_cmdline_set(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(test_bootflow_cmdline_set, 0);
+
+/* Test of bootflow_cmdline_set_arg() */
+static int bootflow_set_arg(struct unit_test_state *uts)
+{
+	struct bootflow s_bflow, *bflow = &s_bflow;
+	ulong mem_start;
+
+	ut_assertok(env_set("bootargs", NULL));
+
+	mem_start = ut_check_delta(0);
+
+	/* Do a simple sanity check. Rely on bootflow_cmdline() for the rest */
+	bflow->cmdline = NULL;
+	ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", "123", false));
+	ut_asserteq_str(bflow->cmdline, "fred=123");
+
+	ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "and here", false));
+	ut_asserteq_str(bflow->cmdline, "fred=123 mary=\"and here\"");
+
+	ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", NULL, false));
+	ut_asserteq_str(bflow->cmdline, "fred=123");
+	ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", NULL, false));
+	ut_asserteq_ptr(bflow->cmdline, NULL);
+
+	ut_asserteq(0, ut_check_delta(mem_start));
+
+	ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "here", true));
+	ut_asserteq_str("mary=here", env_get("bootargs"));
+	ut_assertok(env_set("bootargs", NULL));
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_set_arg, 0);
+
+/* Test of bootflow_cmdline_get_arg() */
+static int bootflow_cmdline_get(struct unit_test_state *uts)
+{
+	int pos;
+
+	/* empty string */
+	ut_asserteq(-ENOENT, cmdline_get_arg("", "fred", &pos));
+
+	/* arg with empty value */
+	ut_asserteq(0, cmdline_get_arg("fred= mary", "fred", &pos));
+	ut_asserteq(5, pos);
+
+	/* arg with a value */
+	ut_asserteq(2, cmdline_get_arg("fred=23", "fred", &pos));
+	ut_asserteq(5, pos);
+
+	/* arg with a value */
+	ut_asserteq(3, cmdline_get_arg("mary=1 fred=234", "fred", &pos));
+	ut_asserteq(12, pos);
+
+	/* arg with a value, after quoted arg */
+	ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=234", "fred", &pos));
+	ut_asserteq(16, pos);
+
+	/* arg in the middle */
+	ut_asserteq(0, cmdline_get_arg("mary=\"1 2\" fred john=23", "fred",
+				       &pos));
+	ut_asserteq(15, pos);
+
+	/* quoted arg */
+	ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=\"3 4\" john=23",
+				       "fred", &pos));
+	ut_asserteq(17, pos);
+
+	/* args starting with the same prefix */
+	ut_asserteq(1, cmdline_get_arg("mary=abc johnathon=3 john=1", "john",
+				       &pos));
+	ut_asserteq(26, pos);
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_cmdline_get, 0);
+
+static int bootflow_cmdline(struct unit_test_state *uts)
+{
+	ut_assertok(run_command("bootflow scan mmc", 0));
+	ut_assertok(run_command("bootflow sel 0", 0));
+	console_record_reset_enable();
+
+	ut_asserteq(1, run_command("bootflow cmdline get fred", 0));
+	ut_assert_nextline("Argument not found");
+	ut_assert_console_end();
+
+	ut_asserteq(0, run_command("bootflow cmdline set fred 123", 0));
+	ut_asserteq(0, run_command("bootflow cmdline get fred", 0));
+	ut_assert_nextline("123");
+
+	ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0));
+	ut_asserteq(0, run_command("bootflow cmdline get mary", 0));
+	ut_assert_nextline("abc");
+
+	ut_asserteq(0, run_command("bootflow cmdline delete fred", 0));
+	ut_asserteq(1, run_command("bootflow cmdline get fred", 0));
+	ut_assert_nextline("Argument not found");
+
+	ut_asserteq(0, run_command("bootflow cmdline clear mary", 0));
+	ut_asserteq(0, run_command("bootflow cmdline get mary", 0));
+	ut_assert_nextline_empty();
+
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootflow_cmdline, 0);
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 11/18] x86: qemu: Create a little more room for U-Boot
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (9 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 10/18] bootstd: Add support for updating elements of the cmdline Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 12/18] x86: qemu: Switch to standard boot Simon Glass
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

We want to enable some of the more interesting bootstd features. Move SPL
up to create some room for the larger U-Boot binary. Also disable
microcode since this is not needed

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Add new patch to create a little more room for U-Boot on qemu-x86_64

 configs/qemu-x86_64_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/qemu-x86_64_defconfig b/configs/qemu-x86_64_defconfig
index f29a5aa0f813..b311843e68be 100644
--- a/configs/qemu-x86_64_defconfig
+++ b/configs/qemu-x86_64_defconfig
@@ -6,12 +6,13 @@ CONFIG_ENV_SIZE=0x40000
 CONFIG_MAX_CPUS=2
 CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="qemu-x86_i440fx"
-CONFIG_SPL_TEXT_BASE=0xfffd0000
+CONFIG_SPL_TEXT_BASE=0xfffd8000
 CONFIG_DEBUG_UART_BASE=0x3f8
 CONFIG_DEBUG_UART_CLOCK=1843200
 CONFIG_X86_RUN_64BIT=y
 CONFIG_TARGET_QEMU_X86_64=y
 CONFIG_DEBUG_UART=y
+# CONFIG_HAVE_MICROCODE is not set
 CONFIG_SMP=y
 CONFIG_GENERATE_PIRQ_TABLE=y
 CONFIG_GENERATE_MP_TABLE=y
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 12/18] x86: qemu: Switch to standard boot
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (10 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 11/18] x86: qemu: Create a little more room for U-Boot Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 13/18] bootstd: Support automatically setting Linux parameters Simon Glass
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Drop use of the distro boot script and use standard boot instead.

Moving to a text-based environment would be desirable also, but requires
additional work.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v2)

Changes in v2:
- Add new patch to switch x86 qemu to standard boot

 configs/qemu-x86_64_defconfig | 2 +-
 configs/qemu-x86_defconfig    | 2 +-
 include/configs/qemu-x86.h    | 8 --------
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/configs/qemu-x86_64_defconfig b/configs/qemu-x86_64_defconfig
index b311843e68be..9272419d4539 100644
--- a/configs/qemu-x86_64_defconfig
+++ b/configs/qemu-x86_64_defconfig
@@ -20,7 +20,7 @@ CONFIG_X86_OFFSET_U_BOOT=0xfff00000
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_SYS_MONITOR_BASE=0x01110000
-CONFIG_DISTRO_DEFAULTS=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_SHOW_BOOT_PROGRESS=y
diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig
index 9bf29647fe59..783de0d45657 100644
--- a/configs/qemu-x86_defconfig
+++ b/configs/qemu-x86_defconfig
@@ -9,7 +9,7 @@ CONFIG_SMP=y
 CONFIG_GENERATE_PIRQ_TABLE=y
 CONFIG_GENERATE_MP_TABLE=y
 CONFIG_FIT=y
-CONFIG_DISTRO_DEFAULTS=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_SHOW_BOOT_PROGRESS=y
diff --git a/include/configs/qemu-x86.h b/include/configs/qemu-x86.h
index 33263a46a407..3e5235291a28 100644
--- a/include/configs/qemu-x86.h
+++ b/include/configs/qemu-x86.h
@@ -12,14 +12,6 @@
 
 #include <linux/sizes.h>
 
-#define BOOT_TARGET_DEVICES(func) \
-	func(USB, usb, 0) \
-	func(SCSI, scsi, 0) \
-	func(VIRTIO, virtio, 0) \
-	func(IDE, ide, 0) \
-	func(DHCP, dhcp, na)
-
-#include <config_distro_bootcmd.h>
 #include <configs/x86-common.h>
 
 #define CFG_STD_DEVICES_SETTINGS	"stdin=serial,i8042-kbd\0" \
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 13/18] bootstd: Support automatically setting Linux parameters
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (11 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 12/18] x86: qemu: Switch to standard boot Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 14/18] x86: Add a function to boot a zimage Simon Glass
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Some Linux parameters can be set automatically by U-Boot, if it knows the
device being used. For example, since U-Boot knows the serial console
being used, it can add parameters for earlycon and console.

Add support for this.

Note that this is an experimental feature and we will see how useful it
turns out to be. It is very handy for ChromeOS, since otherwise it is very
difficult to manually determine the UART address or port number,
particularly in a script.

Provide an example of how this is used with ChromeOS.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 boot/bootflow.c            | 33 +++++++++++++++++
 cmd/bootflow.c             |  5 ++-
 doc/usage/cmd/bootflow.rst | 75 +++++++++++++++++++++++++++++++++++++-
 include/bootflow.h         | 12 ++++++
 4 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 8c649e8e66ca..81b5829d5b37 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -14,6 +14,7 @@
 #include <dm.h>
 #include <env_internal.h>
 #include <malloc.h>
+#include <serial.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
 
@@ -854,3 +855,35 @@ int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
 
 	return ret;
 }
+
+int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg)
+{
+	struct serial_device_info info;
+	char buf[50];
+	int ret;
+
+	ret = serial_getinfo(gd->cur_serial_dev, &info);
+	if (ret)
+		return ret;
+
+	*buf = '\0';
+	if (!strcmp("earlycon", arg)) {
+		snprintf(buf, sizeof(buf),
+			 "uart8250,mmio32,%#lx,%dn8", info.addr,
+			 info.baudrate);
+	} else if (!strcmp("console", arg)) {
+		snprintf(buf, sizeof(buf),
+			 "ttyS0,%dn8", info.baudrate);
+	}
+
+	if (!*buf) {
+		printf("Unknown param '%s\n", arg);
+		return -ENOENT;
+	}
+
+	ret = bootflow_cmdline_set_arg(bflow, arg, buf, true);
+	if (ret)
+		return ret;
+
+	return 0;
+}
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index ab00e4a19e14..c0aa4f84fe8d 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -474,6 +474,9 @@ static int do_bootflow_cmdline(struct cmd_tbl *cmdtp, int flag, int argc,
 		if (ret >= 0)
 			printf("%.*s\n", ret, val);
 		break;
+	case 'a':	/* auto */
+		ret = bootflow_cmdline_auto(bflow, arg);
+		break;
 	}
 	switch (ret) {
 	case -E2BIG:
@@ -508,7 +511,7 @@ static char bootflow_help_text[] =
 	"bootflow info [-d]             - show info on current bootflow (-d dump bootflow)\n"
 	"bootflow boot                  - boot current bootflow (or first available if none selected)\n"
 	"bootflow menu [-t]             - show a menu of available bootflows\n"
-	"bootflow cmdline [set|get|clear|delete] <param> [<value>] - update cmdline";
+	"bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline";
 #else
 	"scan - boot first available bootflow\n";
 #endif
diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst
index 07af789e6702..a8af1f8f6030 100644
--- a/doc/usage/cmd/bootflow.rst
+++ b/doc/usage/cmd/bootflow.rst
@@ -13,7 +13,7 @@ Synopis
     bootflow select [<num|name>]
     bootflow info [-d]
     bootflow boot
-    bootflow cmdline [set|get|clear|delete] <param> [<value>]
+    bootflow cmdline [set|get|clear|delete|auto] <param> [<value>]
 
 Description
 -----------
@@ -218,6 +218,16 @@ To delete a parameter entirely, use::
 
     bootflow cmdline delete <param>
 
+Automatic parameters are available in a very few cases. You can use these to
+add parmeters where the value is known by U-Boot. For example::
+
+    bootflow cmdline auto earlycon
+    bootflow cmdline auto console
+
+can be used to set the early console (or console) to a suitable value so that
+output appears on the serial port. This is only supported by the 16550 serial
+driver so far.
+
 Example
 -------
 
@@ -450,6 +460,69 @@ Here is am example using the -e flag to see all errors::
     (21 bootflows, 2 valid)
     U-Boot>
 
+Here is an example of booting ChromeOS, adjusting the console beforehand. Note that
+the cmdline is word-wrapped here and some parts of the command line are elided::
+
+    => bootfl list
+    Showing all bootflows
+    Seq  Method       State   Uclass    Part  Name                      Filename
+    ---  -----------  ------  --------  ----  ------------------------  ----------------
+    0  cros         ready   nvme         0  5.10.153-20434-g98da1eb2c <NULL>
+    1  efi          ready   nvme         c  nvme#0.blk#1.bootdev.part efi/boot/bootia32.efi
+    2  efi          ready   usb_mass_    2  usb_mass_storage.lun0.boo efi/boot/bootia32.efi
+    ---  -----------  ------  --------  ----  ------------------------  ----------------
+    (3 bootflows, 3 valid)
+    => bootfl sel 0
+    => bootfl inf
+    Name:      5.10.153-20434-g98da1eb2cf9d (chrome-bot@chromeos-release-builder-us-central1-b-x32-12-xijx) #1 SMP PREEMPT Tue Jan 24 19:38:23 PST 2023
+    Device:    nvme#0.blk#1.bootdev
+    Block dev: nvme#0.blk#1
+    Method:    cros
+    State:     ready
+    Partition: 0
+    Subdir:    (none)
+    Filename:  <NULL>
+    Buffer:    737a1400
+    Size:      c47000 (12873728 bytes)
+    OS:        ChromeOS
+    Cmdline:   console= loglevel=7 init=/sbin/init cros_secure drm.trace=0x106
+        root=/dev/dm-0 rootwait ro dm_verity.error_behavior=3
+        dm_verity.max_bios=-1 dm_verity.dev_wait=1
+        dm="1 vroot none ro 1,0 6348800
+          verity payload=PARTUUID=799c935b-ae62-d143-8493-816fa936eef7/PARTNROFF=1
+          hashtree=PARTUUID=799c935b-ae62-d143-8493-816fa936eef7/PARTNROFF=1
+          hashstart=6348800 alg=sha256
+          root_hexdigest=78cc462cd45aecbcd49ca476587b4dee59aa1b00ba5ece58e2c29ec9acd914ab
+          salt=8dec4dc80a75dd834a9b3175c674405e15b16a253fdfe05c79394ae5fd76f66a"
+        noinitrd vt.global_cursor_default=0
+        kern_guid=799c935b-ae62-d143-8493-816fa936eef7 add_efi_memmap boot=local
+        noresume noswap i915.modeset=1 ramoops.ecc=1 tpm_tis.force=0
+        intel_pmc_core.warn_on_s0ix_failures=1 i915.enable_guc=3 i915.enable_dc=4
+        xdomain=0 swiotlb=65536 intel_iommu=on i915.enable_psr=1
+        usb-storage.quirks=13fe:6500:u
+    X86 setup: 742e3400
+    Logo:      (none)
+    FDT:       <NULL>
+    Error:     0
+    => bootflow cmdline auto earlycon
+    => bootflow cmd auto console
+    => print bootargs
+    bootargs=console=ttyS0,115200n8 loglevel=7 ...
+        usb-storage.quirks=13fe:6500:u earlycon=uart8250,mmio32,0xfe03e000,115200n8
+    => bootflow cmd del console
+    => print bootargs
+    bootargs=loglevel=7 ... earlycon=uart8250,mmio32,0xfe03e000,115200n8
+    => bootfl boot
+    ** Booting bootflow '5.10.153-20434-g98da1eb2cf9d (chrome-bot@chromeos-release-builder-us-central1-b-x32-12-xijx) #1 SMP PREEMPT Tue Jan 24 19:38:23 PST 2023' with cros
+    Kernel command line: "loglevel=7 ... earlycon=uart8250,mmio32,0xfe03e000,115200n8"
+
+    Starting kernel ...
+
+    [    0.000000] Linux version 5.10.153-20434-g98da1eb2cf9d (chrome-bot@chromeos-release-builder-us-central1-b-x32-12-xijx) (Chromium OS 15.0_pre465103_p20220825-r4 clang version 15.0.0 (/var/tmp/portage/sys-devel/llvm-15.0_pre465103_p20220825-r4/work/llvm-15.0_pre465103_p20220825/clang db1978b67431ca3462ad8935bf662c15750b8252), LLD 15.0.0) #1 SMP PREEMPT Tue Jan 24 19:38:23 PST 2023
+    [    0.000000] Command line: loglevel=7 ... usb-storage.quirks=13fe:6500:u earlycon=uart8250,mmio32,0xfe03e000,115200n8
+    [    0.000000] x86/split lock detection: warning about user-space split_locks
+
+
 
 Return value
 ------------
diff --git a/include/bootflow.h b/include/bootflow.h
index 7a8595f3dfcf..4152577afb71 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -526,4 +526,16 @@ int cmdline_get_arg(const char *cmdline, const char *arg, int *posp);
 int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
 			     const char **val);
 
+/**
+ * bootflow_cmdline_auto() - Automatically set a value for a known argument
+ *
+ * This handles a small number of known arguments, for Linux in particular. It
+ * adds suitable kernel parameters automatically, e.g. to enable the console.
+ *
+ * @bflow: Bootflow to update
+ * @arg: Name of argument to set (e.g. "earlycon" or "console")
+ * Return: 0 if OK -ve on error
+ */
+int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg);
+
 #endif
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 14/18] x86: Add a function to boot a zimage
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (12 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 13/18] bootstd: Support automatically setting Linux parameters Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 15/18] x86: zimage: Export the function to obtain the cmdline Simon Glass
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Add a direct interface to booting a zimage, so that bootstd can call it
without going through the command-line interface.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 arch/x86/include/asm/zimage.h | 17 ++++++++
 arch/x86/lib/zimage.c         | 82 ++++++++++++++++++++++++++++++-----
 2 files changed, 88 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 000b38ea8993..966d7224eb18 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -72,4 +72,21 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
  */
 void zimage_dump(struct boot_params *base_ptr);
 
+/**
+ * zboot_start() - Boot a zimage
+ *
+ * Boot a zimage, given the component parts
+ *
+ * @addr: Address where the bzImage is moved before booting, either
+ *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ * @base: Pointer to the boot parameters, typically at address
+ *	DEFAULT_SETUP_BASE
+ * @initrd: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @cmdline: Command line to use for booting
+ * Return: -EFAULT on error (normally it does not return)
+ */
+int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+		ulong base, char *cmdline);
+
 #endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index e5ea5129c1e9..540d4d888bc7 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -22,6 +22,7 @@
 #include <irq_func.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <acpi/acpi_table.h>
 #include <asm/io.h>
 #include <asm/ptrace.h>
@@ -442,8 +443,7 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
-			 char *const argv[])
+static int zboot_load(void)
 {
 	struct boot_params *base_ptr;
 
@@ -460,31 +460,51 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 				       &state.load_address);
 		if (!base_ptr) {
 			puts("## Kernel loading failed ...\n");
-			return CMD_RET_FAILURE;
+			return -EINVAL;
 		}
 	}
 	state.base_ptr = base_ptr;
-	if (env_set_hex("zbootbase", (ulong)base_ptr) ||
+
+	return 0;
+}
+
+static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	if (zboot_load())
+		return CMD_RET_FAILURE;
+
+	if (env_set_hex("zbootbase", map_to_sysmem(state.base_ptr)) ||
 	    env_set_hex("zbootaddr", state.load_address))
 		return CMD_RET_FAILURE;
 
 	return 0;
 }
 
+static int zboot_setup(void)
+{
+	struct boot_params *base_ptr = state.base_ptr;
+	int ret;
+
+	ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
+			   0, state.initrd_addr, state.initrd_size,
+			   (ulong)state.cmdline);
+	if (ret)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
 	struct boot_params *base_ptr = state.base_ptr;
-	int ret;
 
 	if (!base_ptr) {
 		printf("base is not set: use 'zboot load' first\n");
 		return CMD_RET_FAILURE;
 	}
-	ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
-			   0, state.initrd_addr, state.initrd_size,
-			   (ulong)state.cmdline);
-	if (ret) {
+	if (zboot_setup()) {
 		puts("Setting up boot parameters failed ...\n");
 		return CMD_RET_FAILURE;
 	}
@@ -501,8 +521,7 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
-		       char *const argv[])
+static int zboot_go(void)
 {
 	struct boot_params *params = state.base_ptr;
 	struct setup_header *hdr = &params->hdr;
@@ -522,11 +541,52 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* we assume that the kernel is in place */
 	ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit);
+
+	return ret;
+}
+
+static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
+		       char *const argv[])
+{
+	int ret;
+
+	ret = zboot_go();
 	printf("Kernel returned! (err=%d)\n", ret);
 
 	return CMD_RET_FAILURE;
 }
 
+int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+		ulong base, char *cmdline)
+{
+	int ret;
+
+	memset(&state, '\0', sizeof(state));
+
+	if (base) {
+		state.base_ptr = map_sysmem(base, 0);
+		state.load_address = addr;
+	} else {
+		state.bzimage_addr = addr;
+	}
+	state.bzimage_size = size;
+	state.initrd_addr = initrd;
+	state.initrd_size = initrd_size;
+	state.cmdline = cmdline;
+
+	ret = zboot_load();
+	if (ret)
+		return log_msg_ret("ld", ret);
+	ret = zboot_setup();
+	if (ret)
+		return log_msg_ret("set", ret);
+	ret = zboot_go();
+	if (ret)
+		return log_msg_ret("set", ret);
+
+	return -EFAULT;
+}
+
 static void print_num(const char *name, ulong value)
 {
 	printf("%-20s: %lx\n", name, value);
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 15/18] x86: zimage: Export the function to obtain the cmdline
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (13 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 14/18] x86: Add a function to boot a zimage Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 16/18] bootstd: Add a simple bootmeth for ChromiumOS Simon Glass
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Allow reading the command line from a zimage, so that it can be recorded
in the bootflow.

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 arch/x86/include/asm/zimage.h | 10 ++++++++++
 arch/x86/lib/zimage.c         | 11 ++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 966d7224eb18..9ad74dc0b946 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -89,4 +89,14 @@ void zimage_dump(struct boot_params *base_ptr);
 int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
 		ulong base, char *cmdline);
 
+/*
+ * zimage_get_kernel_version() - Get the version string from a kernel
+ *
+ * @params: boot_params pointer
+ * @kernel_base: base address of kernel
+ * Return: Kernel version as a NUL-terminated string
+ */
+const char *zimage_get_kernel_version(struct boot_params *params,
+				      void *kernel_base);
+
 #endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 540d4d888bc7..062e3d3e3151 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -181,7 +181,7 @@ static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
 	return 0;
 }
 
-static const char *get_kernel_version(struct boot_params *params,
+const char *zimage_get_kernel_version(struct boot_params *params,
 				      void *kernel_base)
 {
 	struct setup_header *hdr = &params->hdr;
@@ -189,10 +189,14 @@ static const char *get_kernel_version(struct boot_params *params,
 	const char *s, *end;
 
 	bootproto = get_boot_protocol(hdr, false);
+	log_debug("bootproto %x, hdr->setup_sects %x\n", bootproto,
+		  hdr->setup_sects);
 	if (bootproto < 0x0200 || hdr->setup_sects < 15)
 		return NULL;
 
 	/* sanity-check the kernel version in case it is missing */
+	log_debug("hdr->kernel_version %x, str at %p\n", hdr->kernel_version,
+		  kernel_base + hdr->kernel_version + 0x200);
 	for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s;
 	     s++) {
 		if (!isprint(*s))
@@ -239,7 +243,7 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 	log_debug("Using boot protocol version %x.%02x\n",
 		  (bootproto & 0xff00) >> 8, bootproto & 0xff);
 
-	version = get_kernel_version(params, image);
+	version = zimage_get_kernel_version(params, image);
 	if (version)
 		printf("Linux kernel version %s\n", version);
 	else
@@ -728,7 +732,8 @@ void zimage_dump(struct boot_params *base_ptr)
 	print_num("Real mode switch", hdr->realmode_swtch);
 	print_num("Start sys seg", hdr->start_sys_seg);
 	print_num("Kernel version", hdr->kernel_version);
-	version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
+	version = zimage_get_kernel_version(base_ptr,
+					    (void *)state.bzimage_addr);
 	if (version)
 		printf("   @%p: %s\n", version, version);
 	print_num("Type of loader", hdr->type_of_loader);
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 16/18] bootstd: Add a simple bootmeth for ChromiumOS
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (14 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 15/18] x86: zimage: Export the function to obtain the cmdline Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 17/18] x86: coreboot: Adjust various config options Simon Glass
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

It is possible to boot x86-based ChromeOS machines by parsing a table and
locating the kernel and command line. Add a bootmeth for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

(no changes since v1)

 boot/Kconfig                 |  11 ++
 boot/Makefile                |   1 +
 boot/bootmeth_cros.c         | 212 +++++++++++++++++++++++++++++++++++
 configs/tools-only_defconfig |   1 +
 4 files changed, 225 insertions(+)
 create mode 100644 boot/bootmeth_cros.c

diff --git a/boot/Kconfig b/boot/Kconfig
index a643a3d12863..08ca2b0fa9d3 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -463,6 +463,17 @@ config BOOTMETH_GLOBAL
 	  EFI bootmgr, since they take full control over which bootdevs are
 	  selected to boot.
 
+config BOOTMETH_CROS
+	bool "Bootdev support for Chromium OS"
+	depends on X86 || SANDBOX
+	default y
+	help
+	  Enables support for booting Chromium OS using bootdevs. This uses the
+	  kernel A slot and obtains the kernel command line from the parameters
+	  provided there.
+
+	  Note that only x86 devices are supported at present.
+
 config BOOTMETH_EXTLINUX
 	bool "Bootdev support for extlinux boot"
 	select PXE_UTILS
diff --git a/boot/Makefile b/boot/Makefile
index f94c31d922de..6e4cdbd4ce28 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EXTLINUX) += bootmeth_extlinux.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EXTLINUX_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_CROS) += bootmeth_cros.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c
new file mode 100644
index 000000000000..aa19ae097f56
--- /dev/null
+++ b/boot/bootmeth_cros.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for ChromiumOS
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include <common.h>
+#include <blk.h>
+#include <bootdev.h>
+#include <bootflow.h>
+#include <bootmeth.h>
+#include <dm.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <part.h>
+#ifdef CONFIG_X86
+#include <asm/zimage.h>
+#endif
+#include <linux/sizes.h>
+
+enum {
+	/* Offsets in the kernel-partition header */
+	KERN_START	= 0x4f0,
+	KERN_SIZE	= 0x518,
+
+	SETUP_OFFSET	= 0x1000,	/* bytes before base */
+	CMDLINE_OFFSET	= 0x2000,	/* bytes before base */
+	OFFSET_BASE	= 0x100000,	/* assumed kernel load-address */
+};
+
+static int cros_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+	/* This only works on block and network devices */
+	if (bootflow_iter_check_blk(iter))
+		return log_msg_ret("blk", -ENOTSUPP);
+
+	return 0;
+}
+
+static int copy_cmdline(const char *from, const char *uuid, char **bufp)
+{
+	const int maxlen = 2048;
+	char buf[maxlen];
+	char *cmd, *to, *end;
+	int len;
+
+	/* Allow space for cmdline + UUID */
+	len = strnlen(from, sizeof(buf));
+	if (len >= maxlen)
+		return -E2BIG;
+
+	log_debug("uuid %d %s\n", uuid ? (int)strlen(uuid) : 0, uuid);
+	for (to = buf, end = buf + maxlen - UUID_STR_LEN - 1; *from; from++) {
+		if (to >= end)
+			return -E2BIG;
+		if (from[0] == '%' && from[1] == 'U' && uuid &&
+		    strlen(uuid) == UUID_STR_LEN) {
+			strcpy(to, uuid);
+			to += UUID_STR_LEN;
+			from++;
+		} else {
+			*to++ = *from;
+		}
+	}
+	*to = '\0';
+	len = to - buf;
+	cmd = strdup(buf);
+	if (!cmd)
+		return -ENOMEM;
+	free(*bufp);
+	*bufp = cmd;
+
+	return 0;
+}
+
+static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+	struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
+	ulong base, start, size, setup, cmdline, num_blks, kern_base;
+	struct disk_partition info;
+	const char *uuid = NULL;
+	void *buf, *hdr;
+	int ret;
+
+	log_debug("starting, part=%d\n", bflow->part);
+
+	/* We consider the whole disk, not any one partition */
+	if (bflow->part)
+		return log_msg_ret("max", -ENOENT);
+
+	/* Check partition 2 */
+	ret = part_get_info(desc, 2, &info);
+	if (ret)
+		return log_msg_ret("part", ret);
+
+	/* Make a buffer for the header information */
+	num_blks = SZ_4K >> desc->log2blksz;
+	log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n",
+		  bflow->blk->name, (ulong)info.start, num_blks);
+	hdr = memalign(SZ_1K, SZ_4K);
+	if (!hdr)
+		return log_msg_ret("hdr", -ENOMEM);
+	ret = blk_read(bflow->blk, info.start, num_blks, hdr);
+	if (ret != num_blks)
+		return log_msg_ret("inf", ret);
+
+	if (memcmp("CHROMEOS", hdr, 8))
+		return -ENOENT;
+
+	log_info("Header at %lx\n", (ulong)map_to_sysmem(hdr));
+	start = *(u32 *)(hdr + KERN_START);
+	size = ALIGN(*(u32 *)(hdr + KERN_SIZE), desc->blksz);
+	log_debug("Reading start %lx size %lx\n", start, size);
+	bflow->size = size;
+
+	buf = memalign(SZ_1K, size);
+	if (!buf)
+		return log_msg_ret("buf", -ENOMEM);
+	num_blks = size >> desc->log2blksz;
+	log_debug("Reading data, blk=%s, start=%lx, blocks=%lx\n",
+		  bflow->blk->name, (ulong)info.start, num_blks);
+	ret = blk_read(bflow->blk, (ulong)info.start + 0x80, num_blks, buf);
+	if (ret != num_blks)
+		return log_msg_ret("inf", ret);
+	base = map_to_sysmem(buf);
+
+	setup = base + start - OFFSET_BASE - SETUP_OFFSET;
+	cmdline = base + start - OFFSET_BASE - CMDLINE_OFFSET;
+	kern_base = base + start - OFFSET_BASE + SZ_16K;
+	log_debug("base %lx setup %lx, cmdline %lx, kern_base %lx\n", base,
+		  setup, cmdline, kern_base);
+
+#ifdef CONFIG_X86
+	const char *version;
+
+	version = zimage_get_kernel_version(map_sysmem(setup, 0),
+					    map_sysmem(kern_base, 0));
+	log_debug("version %s\n", version);
+	if (version)
+		bflow->name = strdup(version);
+#endif
+	if (!bflow->name)
+		bflow->name = strdup("ChromeOS");
+	if (!bflow->name)
+		return log_msg_ret("nam", -ENOMEM);
+	bflow->os_name = strdup("ChromeOS");
+	if (!bflow->os_name)
+		return log_msg_ret("os", -ENOMEM);
+
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
+	uuid = info.uuid;
+#endif
+	ret = copy_cmdline(map_sysmem(cmdline, 0), uuid, &bflow->cmdline);
+	if (ret)
+		return log_msg_ret("cmd", ret);
+
+	bflow->state = BOOTFLOWST_READY;
+	bflow->buf = buf;
+	bflow->x86_setup = map_sysmem(setup, 0);
+
+	return 0;
+}
+
+static int cros_read_file(struct udevice *dev, struct bootflow *bflow,
+			 const char *file_path, ulong addr, ulong *sizep)
+{
+	return -ENOSYS;
+}
+
+static int cros_boot(struct udevice *dev, struct bootflow *bflow)
+{
+#ifdef CONFIG_X86
+	zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0,
+		    map_to_sysmem(bflow->x86_setup),
+		    bflow->cmdline);
+#endif
+
+	return log_msg_ret("go", -EFAULT);
+}
+
+static int cros_bootmeth_bind(struct udevice *dev)
+{
+	struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
+
+	plat->desc = "ChromiumOS boot";
+
+	return 0;
+}
+
+static struct bootmeth_ops cros_bootmeth_ops = {
+	.check		= cros_check,
+	.read_bootflow	= cros_read_bootflow,
+	.read_file	= cros_read_file,
+	.boot		= cros_boot,
+};
+
+static const struct udevice_id cros_bootmeth_ids[] = {
+	{ .compatible = "u-boot,cros" },
+	{ }
+};
+
+U_BOOT_DRIVER(bootmeth_cros) = {
+	.name		= "bootmeth_cros",
+	.id		= UCLASS_BOOTMETH,
+	.of_match	= cros_bootmeth_ids,
+	.ops		= &cros_bootmeth_ops,
+	.bind		= cros_bootmeth_bind,
+};
diff --git a/configs/tools-only_defconfig b/configs/tools-only_defconfig
index 2bc3bd9e912c..3f588ea69bee 100644
--- a/configs/tools-only_defconfig
+++ b/configs/tools-only_defconfig
@@ -10,6 +10,7 @@ CONFIG_FIT=y
 CONFIG_TIMESTAMP=y
 CONFIG_FIT_SIGNATURE=y
 # CONFIG_BOOTSTD_FULL is not set
+# CONFIG_BOOTMETH_CROS is not set
 # CONFIG_BOOTMETH_VBE is not set
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run distro_bootcmd"
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 17/18] x86: coreboot: Adjust various config options
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (15 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 16/18] bootstd: Add a simple bootmeth for ChromiumOS Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-12 15:04 ` [PATCH v3 18/18] x86: coral: " Simon Glass
  2023-07-13 13:14 ` [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Bin Meng
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Drop IDE and add NVME since this is more common now.

Add ms so it is easier to search for tables in memory.

Expand the command-line and print buffers so that we can deal with the
very long ChromeOS command lines. (typically 700 characters).

Enable BOOTSTD_FULL to get the full set up standard-boot options.

Finally, expand the malloc() space so we can read large kernels into a
bootflow.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3:
- Drop CONFIG_MISC and CONFIG_NVMEM
- Update commit message

 configs/coreboot_defconfig | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index 058caf008f9a..0e7c104efb41 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -1,5 +1,6 @@
 CONFIG_X86=y
 CONFIG_TEXT_BASE=0x1110000
+CONFIG_SYS_MALLOC_LEN=0x2000000
 CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="coreboot"
@@ -8,12 +9,11 @@ CONFIG_VENDOR_COREBOOT=y
 CONFIG_TARGET_COREBOOT=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_BOOTSTD_FULL=y
 CONFIG_SYS_MONITOR_BASE=0x01110000
 CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="ext2load scsi 0:3 01000000 /boot/vmlinuz; zboot 01000000"
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_LOG=y
@@ -23,9 +23,6 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_PCI_INIT_R=y
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PBSIZE=532
-CONFIG_CMD_MEM_SEARCH=y
-CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
 CONFIG_CMD_USB=y
@@ -53,13 +50,6 @@ CONFIG_USE_ROOTPATH=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 # CONFIG_ACPIGEN is not set
-CONFIG_SYS_IDE_MAXDEVICE=4
-CONFIG_SYS_ATA_DATA_OFFSET=0
-CONFIG_SYS_ATA_REG_OFFSET=0
-CONFIG_SYS_ATA_ALT_OFFSET=0
-CONFIG_ATAPI=y
-CONFIG_LBA48=y
-CONFIG_SYS_64BIT_LBA=y
 CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
 CONFIG_SOUND=y
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v3 18/18] x86: coral: Adjust various config options
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (16 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 17/18] x86: coreboot: Adjust various config options Simon Glass
@ 2023-07-12 15:04 ` Simon Glass
  2023-07-13 13:14 ` [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Bin Meng
  18 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-12 15:04 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Tom Rini, Bin Meng, Simon Glass

Add ms so it is easier to search for tables in memory.

Expand the command-line and print buffers so that we can deal with the
very long ChromeOS command lines. (typically 700 characters).

Enable BOOTSTD_FULL to get the full set of standard-boot options.

Replace the existing manual script with 'bootflow scan', since it can
find and boot the OS.

Finally, expand the malloc() space so we can read large kernels into a
bootflow.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3:
- Separate out patch to restore test behaviour on failure

Changes in v2:
- Drop mention of NVMe support

 configs/chromebook_coral_defconfig | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
index f5995f22004e..fe61153b93d8 100644
--- a/configs/chromebook_coral_defconfig
+++ b/configs/chromebook_coral_defconfig
@@ -1,5 +1,6 @@
 CONFIG_X86=y
 CONFIG_TEXT_BASE=0x1110000
+CONFIG_SYS_MALLOC_LEN=0x2000000
 CONFIG_SYS_MALLOC_F_LEN=0x3d00
 CONFIG_NR_DRAM_BANKS=8
 CONFIG_MAX_CPUS=8
@@ -22,6 +23,7 @@ CONFIG_X86_OFFSET_U_BOOT=0xffd00000
 CONFIG_X86_OFFSET_SPL=0xffe80000
 CONFIG_INTEL_ACPIGEN=y
 CONFIG_INTEL_GENERIC_WIFI=y
+CONFIG_BOOTSTD_FULL=y
 CONFIG_SYS_MONITOR_BASE=0x01110000
 CONFIG_CHROMEOS=y
 CONFIG_BOOTSTAGE=y
@@ -33,8 +35,10 @@ CONFIG_BOOTSTAGE_STASH=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS_SUBST=y
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="tpm init; tpm startup TPM2_SU_CLEAR; read mmc 0:2 100000 0 80; setexpr loader *001004f0; setexpr size *00100518; setexpr blocks $size / 200; read mmc 0:2 100000 80 $blocks; setexpr setup $loader - 1000; setexpr cmdline_ptr $loader - 2000; setexpr.s cmdline *$cmdline_ptr; setexpr cmdline gsub %U \\\\${uuid}; if part uuid mmc 0:2 uuid; then zboot start 100000 0 0 0 $setup cmdline; zboot load; zboot setup; zboot dump; zboot go;fi"
+CONFIG_BOOTCOMMAND="tpm init; tpm startup TPM2_SU_CLEAR; bootflow scan -lb"
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_LOG=y
+CONFIG_LOGF_FUNC=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_BLOBLIST=y
@@ -52,9 +56,11 @@ CONFIG_SPL_POWER=y
 CONFIG_TPL_SYS_MALLOC_SIMPLE=y
 CONFIG_TPL_POWER=y
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PBSIZE=532
+CONFIG_SYS_CBSIZE=1024
+CONFIG_SYS_PBSIZE=1024
 CONFIG_CMD_CPU=y
 CONFIG_CMD_PMC=y
+CONFIG_CMD_MEM_SEARCH=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PART=y
-- 
2.41.0.390.g38632f3daf-goog


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
                   ` (17 preceding siblings ...)
  2023-07-12 15:04 ` [PATCH v3 18/18] x86: coral: " Simon Glass
@ 2023-07-13 13:14 ` Bin Meng
  2023-07-14  9:29   ` Bin Meng
  18 siblings, 1 reply; 27+ messages in thread
From: Bin Meng @ 2023-07-13 13:14 UTC (permalink / raw)
  To: Simon Glass; +Cc: U-Boot Mailing List, Tom Rini

On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org> wrote:
>
> This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> to boot the kernel.
>
> Full verified boot is not included at this stage - that is still a
> separate chunk of code to be brought into standard boot at some point.
> For now it just obtains the kernel and command line and boots. This should
> be enough to boot Chrome OS from coreboot on all x86 machines in
> circulation, although only Brya (2022) and Coral (2017) have been tested.
>
> ChromiumOS needs quite large kernel parameters, to hold the DM verity
> settings and other pieces. This makes it painful to modify just one
> parameter, since the whole cmdline must be adjusted at once. To cope with
> this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> command allows individual parameters to be added, modified and deleted.
>
> To deal with enabling debug console, a variant supports setting 'earlycon'
> and 'console' automatically. The 'bdinfo' command is updated to show
> serial-port info also.
>
> Booting the zimage is now done programmatically, rather than running
> through the command-line interface. Minor tweaks are made to the coreboot
> and coral config so that booting works correctly.
>
> Note that the ACPI tables are not updated with the required firmware
> information in this series, so a warning is shown on boot. This will be
> addressed later since it requires quite a bit of configuration.
>
> Finally, this fixes a recently introduced bug in unit testing and updates
> the algorithm to avoid running flat-tree tests which don't actually use
> the devicetree.
>
> Changes in v3:
> - Drop CONFIG_MISC and CONFIG_NVMEM
> - Update commit message
> - Separate out patch to restore test behaviour on failure
>

series applied to u-boot-x86, thanks!

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-13 13:14 ` [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Bin Meng
@ 2023-07-14  9:29   ` Bin Meng
  2023-07-14 17:29     ` Tom Rini
  0 siblings, 1 reply; 27+ messages in thread
From: Bin Meng @ 2023-07-14  9:29 UTC (permalink / raw)
  To: Simon Glass; +Cc: U-Boot Mailing List, Tom Rini

Hi Simon,

On Thu, Jul 13, 2023 at 9:14 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> > to boot the kernel.
> >
> > Full verified boot is not included at this stage - that is still a
> > separate chunk of code to be brought into standard boot at some point.
> > For now it just obtains the kernel and command line and boots. This should
> > be enough to boot Chrome OS from coreboot on all x86 machines in
> > circulation, although only Brya (2022) and Coral (2017) have been tested.
> >
> > ChromiumOS needs quite large kernel parameters, to hold the DM verity
> > settings and other pieces. This makes it painful to modify just one
> > parameter, since the whole cmdline must be adjusted at once. To cope with
> > this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> > command allows individual parameters to be added, modified and deleted.
> >
> > To deal with enabling debug console, a variant supports setting 'earlycon'
> > and 'console' automatically. The 'bdinfo' command is updated to show
> > serial-port info also.
> >
> > Booting the zimage is now done programmatically, rather than running
> > through the command-line interface. Minor tweaks are made to the coreboot
> > and coral config so that booting works correctly.
> >
> > Note that the ACPI tables are not updated with the required firmware
> > information in this series, so a warning is shown on boot. This will be
> > addressed later since it requires quite a bit of configuration.
> >
> > Finally, this fixes a recently introduced bug in unit testing and updates
> > the algorithm to avoid running flat-tree tests which don't actually use
> > the devicetree.
> >
> > Changes in v3:
> > - Drop CONFIG_MISC and CONFIG_NVMEM
> > - Update commit message
> > - Separate out patch to restore test behaviour on failure
> >
>
> series applied to u-boot-x86, thanks!

Could you please look at the CI failure?
https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures

Regards,
Bin

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-14  9:29   ` Bin Meng
@ 2023-07-14 17:29     ` Tom Rini
  2023-07-15 23:40       ` Simon Glass
  0 siblings, 1 reply; 27+ messages in thread
From: Tom Rini @ 2023-07-14 17:29 UTC (permalink / raw)
  To: Bin Meng; +Cc: Simon Glass, U-Boot Mailing List

[-- Attachment #1: Type: text/plain, Size: 2509 bytes --]

On Fri, Jul 14, 2023 at 05:29:40PM +0800, Bin Meng wrote:
> Hi Simon,
> 
> On Thu, Jul 13, 2023 at 9:14 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org> wrote:
> > >
> > > This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> > > to boot the kernel.
> > >
> > > Full verified boot is not included at this stage - that is still a
> > > separate chunk of code to be brought into standard boot at some point.
> > > For now it just obtains the kernel and command line and boots. This should
> > > be enough to boot Chrome OS from coreboot on all x86 machines in
> > > circulation, although only Brya (2022) and Coral (2017) have been tested.
> > >
> > > ChromiumOS needs quite large kernel parameters, to hold the DM verity
> > > settings and other pieces. This makes it painful to modify just one
> > > parameter, since the whole cmdline must be adjusted at once. To cope with
> > > this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> > > command allows individual parameters to be added, modified and deleted.
> > >
> > > To deal with enabling debug console, a variant supports setting 'earlycon'
> > > and 'console' automatically. The 'bdinfo' command is updated to show
> > > serial-port info also.
> > >
> > > Booting the zimage is now done programmatically, rather than running
> > > through the command-line interface. Minor tweaks are made to the coreboot
> > > and coral config so that booting works correctly.
> > >
> > > Note that the ACPI tables are not updated with the required firmware
> > > information in this series, so a warning is shown on boot. This will be
> > > addressed later since it requires quite a bit of configuration.
> > >
> > > Finally, this fixes a recently introduced bug in unit testing and updates
> > > the algorithm to avoid running flat-tree tests which don't actually use
> > > the devicetree.
> > >
> > > Changes in v3:
> > > - Drop CONFIG_MISC and CONFIG_NVMEM
> > > - Update commit message
> > > - Separate out patch to restore test behaviour on failure
> > >
> >
> > series applied to u-boot-x86, thanks!
> 
> Could you please look at the CI failure?
> https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures

I _think_ if you rebase on master this should be fixed with
https://patchwork.ozlabs.org/project/uboot/patch/20230712024632.2365887-1-sjg@chromium.org/
applied.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-14 17:29     ` Tom Rini
@ 2023-07-15 23:40       ` Simon Glass
  2023-07-17  2:13         ` Bin Meng
  0 siblings, 1 reply; 27+ messages in thread
From: Simon Glass @ 2023-07-15 23:40 UTC (permalink / raw)
  To: Tom Rini; +Cc: Bin Meng, U-Boot Mailing List

Hi Tom,

On Fri, 14 Jul 2023 at 11:29, Tom Rini <trini@konsulko.com> wrote:
>
> On Fri, Jul 14, 2023 at 05:29:40PM +0800, Bin Meng wrote:
> > Hi Simon,
> >
> > On Thu, Jul 13, 2023 at 9:14 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org> wrote:
> > > >
> > > > This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> > > > to boot the kernel.
> > > >
> > > > Full verified boot is not included at this stage - that is still a
> > > > separate chunk of code to be brought into standard boot at some point.
> > > > For now it just obtains the kernel and command line and boots. This should
> > > > be enough to boot Chrome OS from coreboot on all x86 machines in
> > > > circulation, although only Brya (2022) and Coral (2017) have been tested.
> > > >
> > > > ChromiumOS needs quite large kernel parameters, to hold the DM verity
> > > > settings and other pieces. This makes it painful to modify just one
> > > > parameter, since the whole cmdline must be adjusted at once. To cope with
> > > > this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> > > > command allows individual parameters to be added, modified and deleted.
> > > >
> > > > To deal with enabling debug console, a variant supports setting 'earlycon'
> > > > and 'console' automatically. The 'bdinfo' command is updated to show
> > > > serial-port info also.
> > > >
> > > > Booting the zimage is now done programmatically, rather than running
> > > > through the command-line interface. Minor tweaks are made to the coreboot
> > > > and coral config so that booting works correctly.
> > > >
> > > > Note that the ACPI tables are not updated with the required firmware
> > > > information in this series, so a warning is shown on boot. This will be
> > > > addressed later since it requires quite a bit of configuration.
> > > >
> > > > Finally, this fixes a recently introduced bug in unit testing and updates
> > > > the algorithm to avoid running flat-tree tests which don't actually use
> > > > the devicetree.
> > > >
> > > > Changes in v3:
> > > > - Drop CONFIG_MISC and CONFIG_NVMEM
> > > > - Update commit message
> > > > - Separate out patch to restore test behaviour on failure
> > > >
> > >
> > > series applied to u-boot-x86, thanks!
> >
> > Could you please look at the CI failure?
> > https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures
>
> I _think_ if you rebase on master this should be fixed with
> https://patchwork.ozlabs.org/project/uboot/patch/20230712024632.2365887-1-sjg@chromium.org/
> applied.

Yes it should be.

Regards,
Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-15 23:40       ` Simon Glass
@ 2023-07-17  2:13         ` Bin Meng
  2023-07-17  2:15           ` Simon Glass
  0 siblings, 1 reply; 27+ messages in thread
From: Bin Meng @ 2023-07-17  2:13 UTC (permalink / raw)
  To: Simon Glass; +Cc: Tom Rini, U-Boot Mailing List

Hi Tom and Simon,

On Sun, Jul 16, 2023 at 7:40 AM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Tom,
>
> On Fri, 14 Jul 2023 at 11:29, Tom Rini <trini@konsulko.com> wrote:
> >
> > On Fri, Jul 14, 2023 at 05:29:40PM +0800, Bin Meng wrote:
> > > Hi Simon,
> > >
> > > On Thu, Jul 13, 2023 at 9:14 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org> wrote:
> > > > >
> > > > > This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> > > > > to boot the kernel.
> > > > >
> > > > > Full verified boot is not included at this stage - that is still a
> > > > > separate chunk of code to be brought into standard boot at some point.
> > > > > For now it just obtains the kernel and command line and boots. This should
> > > > > be enough to boot Chrome OS from coreboot on all x86 machines in
> > > > > circulation, although only Brya (2022) and Coral (2017) have been tested.
> > > > >
> > > > > ChromiumOS needs quite large kernel parameters, to hold the DM verity
> > > > > settings and other pieces. This makes it painful to modify just one
> > > > > parameter, since the whole cmdline must be adjusted at once. To cope with
> > > > > this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> > > > > command allows individual parameters to be added, modified and deleted.
> > > > >
> > > > > To deal with enabling debug console, a variant supports setting 'earlycon'
> > > > > and 'console' automatically. The 'bdinfo' command is updated to show
> > > > > serial-port info also.
> > > > >
> > > > > Booting the zimage is now done programmatically, rather than running
> > > > > through the command-line interface. Minor tweaks are made to the coreboot
> > > > > and coral config so that booting works correctly.
> > > > >
> > > > > Note that the ACPI tables are not updated with the required firmware
> > > > > information in this series, so a warning is shown on boot. This will be
> > > > > addressed later since it requires quite a bit of configuration.
> > > > >
> > > > > Finally, this fixes a recently introduced bug in unit testing and updates
> > > > > the algorithm to avoid running flat-tree tests which don't actually use
> > > > > the devicetree.
> > > > >
> > > > > Changes in v3:
> > > > > - Drop CONFIG_MISC and CONFIG_NVMEM
> > > > > - Update commit message
> > > > > - Separate out patch to restore test behaviour on failure
> > > > >
> > > >
> > > > series applied to u-boot-x86, thanks!
> > >
> > > Could you please look at the CI failure?
> > > https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures
> >
> > I _think_ if you rebase on master this should be fixed with
> > https://patchwork.ozlabs.org/project/uboot/patch/20230712024632.2365887-1-sjg@chromium.org/
> > applied.
>
> Yes it should be.
>

Rebased u-boot-x86 against u-boot/master, but CI still has these
sandbox failures.
https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16920/failures

Regards,
Bin

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-17  2:13         ` Bin Meng
@ 2023-07-17  2:15           ` Simon Glass
  2023-07-17  2:48             ` Bin Meng
  0 siblings, 1 reply; 27+ messages in thread
From: Simon Glass @ 2023-07-17  2:15 UTC (permalink / raw)
  To: Bin Meng; +Cc: Tom Rini, U-Boot Mailing List

Hi Tom and Bin,

I've already sent a patch in the new series that fixes bdinfo. Please take
a look.

Thanks,
Simon


On Sun, Jul 16, 2023, 20:13 Bin Meng <bmeng.cn@gmail.com> wrote:

> Hi Tom and Simon,
>
> On Sun, Jul 16, 2023 at 7:40 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Tom,
> >
> > On Fri, 14 Jul 2023 at 11:29, Tom Rini <trini@konsulko.com> wrote:
> > >
> > > On Fri, Jul 14, 2023 at 05:29:40PM +0800, Bin Meng wrote:
> > > > Hi Simon,
> > > >
> > > > On Thu, Jul 13, 2023 at 9:14 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > On Wed, Jul 12, 2023 at 11:04 PM Simon Glass <sjg@chromium.org>
> wrote:
> > > > > >
> > > > > > This series adds a simple bootmeth for ChromiumOS on x86. It
> uses zimage
> > > > > > to boot the kernel.
> > > > > >
> > > > > > Full verified boot is not included at this stage - that is still
> a
> > > > > > separate chunk of code to be brought into standard boot at some
> point.
> > > > > > For now it just obtains the kernel and command line and boots.
> This should
> > > > > > be enough to boot Chrome OS from coreboot on all x86 machines in
> > > > > > circulation, although only Brya (2022) and Coral (2017) have
> been tested.
> > > > > >
> > > > > > ChromiumOS needs quite large kernel parameters, to hold the DM
> verity
> > > > > > settings and other pieces. This makes it painful to modify just
> one
> > > > > > parameter, since the whole cmdline must be adjusted at once. To
> cope with
> > > > > > this, a new cmdline-editing feature is provided: the 'bootflow
> cmdline'
> > > > > > command allows individual parameters to be added, modified and
> deleted.
> > > > > >
> > > > > > To deal with enabling debug console, a variant supports setting
> 'earlycon'
> > > > > > and 'console' automatically. The 'bdinfo' command is updated to
> show
> > > > > > serial-port info also.
> > > > > >
> > > > > > Booting the zimage is now done programmatically, rather than
> running
> > > > > > through the command-line interface. Minor tweaks are made to the
> coreboot
> > > > > > and coral config so that booting works correctly.
> > > > > >
> > > > > > Note that the ACPI tables are not updated with the required
> firmware
> > > > > > information in this series, so a warning is shown on boot. This
> will be
> > > > > > addressed later since it requires quite a bit of configuration.
> > > > > >
> > > > > > Finally, this fixes a recently introduced bug in unit testing
> and updates
> > > > > > the algorithm to avoid running flat-tree tests which don't
> actually use
> > > > > > the devicetree.
> > > > > >
> > > > > > Changes in v3:
> > > > > > - Drop CONFIG_MISC and CONFIG_NVMEM
> > > > > > - Update commit message
> > > > > > - Separate out patch to restore test behaviour on failure
> > > > > >
> > > > >
> > > > > series applied to u-boot-x86, thanks!
> > > >
> > > > Could you please look at the CI failure?
> > > >
> https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures
> > >
> > > I _think_ if you rebase on master this should be fixed with
> > >
> https://patchwork.ozlabs.org/project/uboot/patch/20230712024632.2365887-1-sjg@chromium.org/
> > > applied.
> >
> > Yes it should be.
> >
>
> Rebased u-boot-x86 against u-boot/master, but CI still has these
> sandbox failures.
>
> https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16920/failures
>
> Regards,
> Bin
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-17  2:15           ` Simon Glass
@ 2023-07-17  2:48             ` Bin Meng
  2023-07-17  3:19               ` Simon Glass
  0 siblings, 1 reply; 27+ messages in thread
From: Bin Meng @ 2023-07-17  2:48 UTC (permalink / raw)
  To: Simon Glass; +Cc: Tom Rini, U-Boot Mailing List

Hi Simon,

On Mon, Jul 17, 2023 at 10:16 AM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Tom and Bin,
>
> I've already sent a patch in the new series that fixes bdinfo. Please take a look.
>

Are these sandbox failures regressions? Or issues introduced in your series?

If the latter, I think we should squash the patch into one of your series.

BTW please provide the patch link so that I can verify the CI build locally.

Regards,
Bin

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86
  2023-07-17  2:48             ` Bin Meng
@ 2023-07-17  3:19               ` Simon Glass
  0 siblings, 0 replies; 27+ messages in thread
From: Simon Glass @ 2023-07-17  3:19 UTC (permalink / raw)
  To: Bin Meng; +Cc: Tom Rini, U-Boot Mailing List

Hi Bin,

On Sun, 16 Jul 2023 at 20:48, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Mon, Jul 17, 2023 at 10:16 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Tom and Bin,
> >
> > I've already sent a patch in the new series that fixes bdinfo. Please take a look.
> >
>
> Are these sandbox failures regressions? Or issues introduced in your series?

It is a race between my series (which has been sitting for a while)
and a new test written by Marek.

>
> If the latter, I think we should squash the patch into one of your series.
>
> BTW please provide the patch link so that I can verify the CI build locally.
>

It is:

https://patchwork.ozlabs.org/project/uboot/patch/20230716033929.253357-2-sjg@chromium.org/

Regards,
Simon

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2023-07-17  3:19 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 15:04 [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Simon Glass
2023-07-12 15:04 ` [PATCH v3 01/18] test: Skip flat-tree tests if devicetree is not used Simon Glass
2023-07-12 15:04 ` [PATCH v3 02/18] bootstd: Correct the name of the QEMU bootmeth Simon Glass
2023-07-12 15:04 ` [PATCH v3 03/18] bootstd: Use bootdev instead of bootdevice Simon Glass
2023-07-12 15:04 ` [PATCH v3 04/18] bootstd: Correct baudrate typo Simon Glass
2023-07-12 15:04 ` [PATCH v3 05/18] bootstd: Allow storing the OS command line in the bootflow Simon Glass
2023-07-12 15:04 ` [PATCH v3 06/18] bootstd: Use the bootargs env var for changing the cmdline Simon Glass
2023-07-12 15:04 ` [PATCH v3 07/18] bootstd: Allow storing x86 setup information Simon Glass
2023-07-12 15:04 ` [PATCH v3 08/18] bdinfo: Show information about the serial port Simon Glass
2023-07-12 15:04 ` [PATCH v3 09/18] bootstd: Add a function to update a command line Simon Glass
2023-07-12 15:04 ` [PATCH v3 10/18] bootstd: Add support for updating elements of the cmdline Simon Glass
2023-07-12 15:04 ` [PATCH v3 11/18] x86: qemu: Create a little more room for U-Boot Simon Glass
2023-07-12 15:04 ` [PATCH v3 12/18] x86: qemu: Switch to standard boot Simon Glass
2023-07-12 15:04 ` [PATCH v3 13/18] bootstd: Support automatically setting Linux parameters Simon Glass
2023-07-12 15:04 ` [PATCH v3 14/18] x86: Add a function to boot a zimage Simon Glass
2023-07-12 15:04 ` [PATCH v3 15/18] x86: zimage: Export the function to obtain the cmdline Simon Glass
2023-07-12 15:04 ` [PATCH v3 16/18] bootstd: Add a simple bootmeth for ChromiumOS Simon Glass
2023-07-12 15:04 ` [PATCH v3 17/18] x86: coreboot: Adjust various config options Simon Glass
2023-07-12 15:04 ` [PATCH v3 18/18] x86: coral: " Simon Glass
2023-07-13 13:14 ` [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86 Bin Meng
2023-07-14  9:29   ` Bin Meng
2023-07-14 17:29     ` Tom Rini
2023-07-15 23:40       ` Simon Glass
2023-07-17  2:13         ` Bin Meng
2023-07-17  2:15           ` Simon Glass
2023-07-17  2:48             ` Bin Meng
2023-07-17  3:19               ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.