[PATCH 13/18] bootstd: Support automatically setting Linux parameters

Simon Glass sjg at chromium.org
Fri Apr 28 21:18:13 CEST 2023


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 at chromium.org>
---

 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 dbf93701cfb..745472a0b7a 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>
 
@@ -842,3 +843,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 dc54124621c..9d93b457408 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -476,6 +476,9 @@ static int do_bootflow_cmdline(struct cmd_tbl *cmdtp, int flag, int argc,
 		else
 			printf("%.*s\n", ret, val);
 		break;
+	case 'a':	/* auto */
+		ret = bootflow_cmdline_auto(bflow, arg);
+		break;
 	}
 	if (ret < 0) {
 		printf("Operation failed\n");
@@ -495,7 +498,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 0dbbb4a327c..d5f5ae79882 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 at 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 at 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 at 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 af4b762dc5e..f65098a2dc3 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.40.1.495.gc816e09b53d-goog



More information about the U-Boot mailing list