All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] bootflow: Rename bootflow_flags_t
@ 2023-01-29  1:27 Simon Glass
  2023-01-29  1:27 ` [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot Simon Glass
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Glass @ 2023-01-29  1:27 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Mark Kettenis, Tom Rini, Simon Glass

These flags actually relate to the iterator, not the bootflow struct
itself. Rename them.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 boot/bootdev-uclass.c   | 16 ++++++-------
 boot/bootflow.c         | 20 ++++++++--------
 cmd/bootflow.c          |  8 +++----
 doc/develop/bootstd.rst | 12 +++++-----
 include/bootflow.h      | 51 +++++++++++++++++++++--------------------
 test/boot/bootdev.c     | 10 ++++----
 test/boot/bootflow.c    |  2 +-
 7 files changed, 60 insertions(+), 59 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 99ee08e3353..73e89ae1458 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -626,11 +626,11 @@ int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp)
 			if (++iter->cur_prio == BOOTDEVP_COUNT)
 				return log_msg_ret("fin", -ENODEV);
 
-			if (iter->flags & BOOTFLOWF_HUNT) {
+			if (iter->flags & BOOTFLOWIF_HUNT) {
 				/* hunt to find new bootdevs */
 				ret = bootdev_hunt_prio(iter->cur_prio,
 							iter->flags &
-							BOOTFLOWF_SHOW);
+							BOOTFLOWIF_SHOW);
 				log_debug("- hunt ret %d\n", ret);
 				if (ret)
 					return log_msg_ret("hun", ret);
@@ -654,7 +654,7 @@ int bootdev_setup_iter(struct bootflow_iter *iter, const char *label,
 		       struct udevice **devp, int *method_flagsp)
 {
 	struct udevice *bootstd, *dev = NULL;
-	bool show = iter->flags & BOOTFLOWF_SHOW;
+	bool show = iter->flags & BOOTFLOWIF_SHOW;
 	int method_flags;
 	int ret;
 
@@ -665,7 +665,7 @@ int bootdev_setup_iter(struct bootflow_iter *iter, const char *label,
 	}
 
 	/* hunt for any pre-scan devices */
-	if (iter->flags & BOOTFLOWF_HUNT) {
+	if (iter->flags & BOOTFLOWIF_HUNT) {
 		ret = bootdev_hunt_prio(BOOTDEVP_1_PRE_SCAN, show);
 		if (ret)
 			return log_msg_ret("pre", ret);
@@ -673,7 +673,7 @@ int bootdev_setup_iter(struct bootflow_iter *iter, const char *label,
 
 	/* Handle scanning a single device */
 	if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && label) {
-		if (iter->flags & BOOTFLOWF_HUNT) {
+		if (iter->flags & BOOTFLOWIF_HUNT) {
 			ret = bootdev_hunt(label, show);
 			if (ret)
 				return log_msg_ret("hun", ret);
@@ -684,11 +684,11 @@ int bootdev_setup_iter(struct bootflow_iter *iter, const char *label,
 
 		log_debug("method_flags: %x\n", method_flags);
 		if (method_flags & BOOTFLOW_METHF_SINGLE_UCLASS)
-			iter->flags |= BOOTFLOWF_SINGLE_UCLASS;
+			iter->flags |= BOOTFLOWIF_SINGLE_UCLASS;
 		else if (method_flags & BOOTFLOW_METHF_SINGLE_DEV)
-			iter->flags |= BOOTFLOWF_SINGLE_DEV;
+			iter->flags |= BOOTFLOWIF_SINGLE_DEV;
 		else
-			iter->flags |= BOOTFLOWF_SINGLE_MEDIA;
+			iter->flags |= BOOTFLOWIF_SINGLE_MEDIA;
 		log_debug("Selected label: %s, flags %x\n", label, iter->flags);
 	} else {
 		bool ok;
diff --git a/boot/bootflow.c b/boot/bootflow.c
index dc3f1f0c731..4999018e36e 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -139,8 +139,8 @@ static void bootflow_iter_set_dev(struct bootflow_iter *iter,
 		if (dev && iter->num_devs < iter->max_devs)
 			iter->dev_used[iter->num_devs++] = dev;
 
-		if ((iter->flags & (BOOTFLOWF_SHOW | BOOTFLOWF_SINGLE_DEV)) ==
-		    BOOTFLOWF_SHOW) {
+		if ((iter->flags & (BOOTFLOWIF_SHOW | BOOTFLOWIF_SINGLE_DEV)) ==
+		    BOOTFLOWIF_SHOW) {
 			if (dev)
 				printf("Scanning bootdev '%s':\n", dev->name);
 			else if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) &&
@@ -215,7 +215,7 @@ static int iter_incr(struct bootflow_iter *iter)
 	iter->max_part = 0;
 
 	/* ...select next bootdev */
-	if (iter->flags & BOOTFLOWF_SINGLE_DEV) {
+	if (iter->flags & BOOTFLOWIF_SINGLE_DEV) {
 		ret = -ENOENT;
 	} else {
 		int method_flags;
@@ -227,7 +227,7 @@ static int iter_incr(struct bootflow_iter *iter)
 			ret = bootdev_setup_iter(iter, NULL, &dev,
 						 &method_flags);
 		} else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) &&
-			   (iter->flags & BOOTFLOWF_SINGLE_UCLASS)) {
+			   (iter->flags & BOOTFLOWIF_SINGLE_UCLASS)) {
 			/* Move to the next bootdev in this uclass */
 			uclass_find_next_device(&dev);
 			if (!dev) {
@@ -236,7 +236,7 @@ static int iter_incr(struct bootflow_iter *iter)
 				ret = -ENODEV;
 			}
 		} else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) &&
-			   iter->flags & BOOTFLOWF_SINGLE_MEDIA) {
+			   iter->flags & BOOTFLOWIF_SINGLE_MEDIA) {
 			log_debug("next in single\n");
 			method_flags = 0;
 			do {
@@ -324,7 +324,7 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow)
 		 * For 'all' we return all bootflows, even
 		 * those with errors
 		 */
-		if (iter->flags & BOOTFLOWF_ALL)
+		if (iter->flags & BOOTFLOWIF_ALL)
 			return log_msg_ret("all", ret);
 	}
 	if (ret)
@@ -340,14 +340,14 @@ int bootflow_scan_first(struct udevice *dev, const char *label,
 	int ret;
 
 	if (dev || label)
-		flags |= BOOTFLOWF_SKIP_GLOBAL;
+		flags |= BOOTFLOWIF_SKIP_GLOBAL;
 	bootflow_iter_init(iter, flags);
 
 	/*
 	 * Set up the ordering of bootmeths. This sets iter->doing_global and
 	 * iter->first_glob_method if we are starting with the global bootmeths
 	 */
-	ret = bootmeth_setup_iter_order(iter, !(flags & BOOTFLOWF_SKIP_GLOBAL));
+	ret = bootmeth_setup_iter_order(iter, !(flags & BOOTFLOWIF_SKIP_GLOBAL));
 	if (ret)
 		return log_msg_ret("obmeth", -ENODEV);
 
@@ -369,7 +369,7 @@ int bootflow_scan_first(struct udevice *dev, const char *label,
 	if (ret) {
 		log_debug("check - ret=%d\n", ret);
 		if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) {
-			if (iter->flags & BOOTFLOWF_ALL)
+			if (iter->flags & BOOTFLOWIF_ALL)
 				return log_msg_ret("all", ret);
 		}
 		iter->err = ret;
@@ -398,7 +398,7 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow)
 				return 0;
 			iter->err = ret;
 			if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) {
-				if (iter->flags & BOOTFLOWF_ALL)
+				if (iter->flags & BOOTFLOWIF_ALL)
 					return log_msg_ret("all", ret);
 			}
 		} else {
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 692bc6d117f..2250dd42e03 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -135,13 +135,13 @@ static int do_bootflow_scan(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	flags = 0;
 	if (list)
-		flags |= BOOTFLOWF_SHOW;
+		flags |= BOOTFLOWIF_SHOW;
 	if (all)
-		flags |= BOOTFLOWF_ALL;
+		flags |= BOOTFLOWIF_ALL;
 	if (no_global)
-		flags |= BOOTFLOWF_SKIP_GLOBAL;
+		flags |= BOOTFLOWIF_SKIP_GLOBAL;
 	if (!no_hunter)
-		flags |= BOOTFLOWF_HUNT;
+		flags |= BOOTFLOWIF_HUNT;
 
 	/*
 	 * If we have a device, just scan for bootflows attached to that device
diff --git a/doc/develop/bootstd.rst b/doc/develop/bootstd.rst
index 281aabf74b2..c92ec0f590d 100644
--- a/doc/develop/bootstd.rst
+++ b/doc/develop/bootstd.rst
@@ -485,22 +485,22 @@ in a valid bootflow, whether to iterate through just a single bootdev, etc.
 Then the iterator is set up to according to the parameters given:
 
 - When `dev` is provided, then a single bootdev is scanned. In this case,
-  `BOOTFLOWF_SKIP_GLOBAL` and `BOOTFLOWF_SINGLE_DEV` are set. No hunters are
+  `BOOTFLOWIF_SKIP_GLOBAL` and `BOOTFLOWIF_SINGLE_DEV` are set. No hunters are
   used in this case
 
 - Otherwise, when `label` is provided, then a single label or named bootdev is
-  scanned. In this case `BOOTFLOWF_SKIP_GLOBAL` is set and there are three
+  scanned. In this case `BOOTFLOWIF_SKIP_GLOBAL` is set and there are three
   options (with an effect on the `iter_incr()` function described later):
 
   - If `label` indicates a numeric bootdev number (e.g. "2") then
     `BOOTFLOW_METHF_SINGLE_DEV` is set. In this case, moving to the next bootdev
     simple stops, since there is only one. No hunters are used.
   - If `label` indicates a particular media device (e.g. "mmc1") then
-    `BOOTFLOWF_SINGLE_MEDIA` is set. In this case, moving to the next bootdev
+    `BOOTFLOWIF_SINGLE_MEDIA` is set. In this case, moving to the next bootdev
     processes just the children of the media device. Hunters are used, in this
     example just the "mmc" hunter.
   - If `label` indicates a media uclass (e.g. "mmc") then
-    `BOOTFLOWF_SINGLE_UCLASS` is set. In this case, all bootdevs in that uclass
+    `BOOTFLOWIF_SINGLE_UCLASS` is set. In this case, all bootdevs in that uclass
     are used. Hunters are used, in this example just the "mmc" hunter
 
 - Otherwise, none of the above flags is set and iteration is set up to work
@@ -539,7 +539,7 @@ bootdev.
 With the iterator ready, `bootflow_scan_first()` checks whether the current
 settings produce a valid bootflow. This is handled by `bootflow_check()`, which
 either returns 0 (if it got something) or an error if not (more on that later).
-If the `BOOTFLOWF_ALL` iterator flag is set, even errors are returned as
+If the `BOOTFLOWIF_ALL` iterator flag is set, even errors are returned as
 incomplete bootflows, but normally an error results in moving onto the next
 iteration.
 
@@ -647,7 +647,7 @@ e.g. updating the state, depending on what it finds. For global bootmeths the
 Based on what the bootdev or bootmeth responds with, `bootflow_check()` either
 returns a valid bootflow, or a partial one with an error. A partial bootflow
 is one that has some fields set up, but did not reach the `BOOTFLOWST_READY`
-state. As noted before, if the `BOOTFLOWF_ALL` iterator flag is set, then all
+state. As noted before, if the `BOOTFLOWIF_ALL` iterator flag is set, then all
 bootflows are returned, even partial ones. This can help with debugging.
 
 So at this point you can see that total control over whether a bootflow can
diff --git a/include/bootflow.h b/include/bootflow.h
index f516bf8dea4..e5fdf5f29d1 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -93,36 +93,36 @@ struct bootflow {
 };
 
 /**
- * enum bootflow_flags_t - flags for the bootflow iterator
+ * enum bootflow_iter_flags_t - flags for the bootflow iterator
  *
- * @BOOTFLOWF_FIXED: Only used fixed/internal media
- * @BOOTFLOWF_SHOW: Show each bootdev before scanning it; show each hunter
+ * @BOOTFLOWIF_FIXED: Only used fixed/internal media
+ * @BOOTFLOWIF_SHOW: Show each bootdev before scanning it; show each hunter
  * before using it
- * @BOOTFLOWF_ALL: Return bootflows with errors as well
- * @BOOTFLOWF_HUNT: Hunt for new bootdevs using the bootdrv hunters
+ * @BOOTFLOWIF_ALL: Return bootflows with errors as well
+ * @BOOTFLOWIF_HUNT: Hunt for new bootdevs using the bootdrv hunters
  *
  * Internal flags:
- * @BOOTFLOWF_SINGLE_DEV: (internal) Just scan one bootdev
- * @BOOTFLOWF_SKIP_GLOBAL: (internal) Don't scan global bootmeths
- * @BOOTFLOWF_SINGLE_UCLASS: (internal) Keep scanning through all devices in
+ * @BOOTFLOWIF_SINGLE_DEV: (internal) Just scan one bootdev
+ * @BOOTFLOWIF_SKIP_GLOBAL: (internal) Don't scan global bootmeths
+ * @BOOTFLOWIF_SINGLE_UCLASS: (internal) Keep scanning through all devices in
  * this uclass (used with things like "mmc")
- * @BOOTFLOWF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used
+ * @BOOTFLOWIF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used
  * with things like "mmc1")
  */
-enum bootflow_flags_t {
-	BOOTFLOWF_FIXED		= 1 << 0,
-	BOOTFLOWF_SHOW		= 1 << 1,
-	BOOTFLOWF_ALL		= 1 << 2,
-	BOOTFLOWF_HUNT		= 1 << 3,
+enum bootflow_iter_flags_t {
+	BOOTFLOWIF_FIXED		= 1 << 0,
+	BOOTFLOWIF_SHOW			= 1 << 1,
+	BOOTFLOWIF_ALL			= 1 << 2,
+	BOOTFLOWIF_HUNT			= 1 << 3,
 
 	/*
 	 * flags used internally by standard boot - do not set these when
 	 * calling bootflow_scan_bootdev() etc.
 	 */
-	BOOTFLOWF_SINGLE_DEV	= 1 << 16,
-	BOOTFLOWF_SKIP_GLOBAL	= 1 << 17,
-	BOOTFLOWF_SINGLE_UCLASS	= 1 << 18,
-	BOOTFLOWF_SINGLE_MEDIA	= 1 << 19,
+	BOOTFLOWIF_SINGLE_DEV		= 1 << 16,
+	BOOTFLOWIF_SKIP_GLOBAL		= 1 << 17,
+	BOOTFLOWIF_SINGLE_UCLASS	= 1 << 18,
+	BOOTFLOWIF_SINGLE_MEDIA		= 1 << 19,
 };
 
 /**
@@ -164,9 +164,9 @@ enum bootflow_meth_flags_t {
  * updated to a larger value, no less than the number of available partitions.
  * This ensures that iteration works through all partitions on the bootdev.
  *
- * @flags: Flags to use (see enum bootflow_flags_t). If BOOTFLOWF_GLOBAL_FIRST is
- *	enabled then the global bootmeths are being scanned, otherwise we have
- *	moved onto the bootdevs
+ * @flags: Flags to use (see enum bootflow_iter_flags_t). If
+ *	BOOTFLOWIF_GLOBAL_FIRST is enabled then the global bootmeths are being
+ *	scanned, otherwise we have moved onto the bootdevs
  * @dev: Current bootdev, NULL if none. This is only ever updated in
  * bootflow_iter_set_dev()
  * @part: Current partition number (0 for whole device)
@@ -233,7 +233,7 @@ void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
  * This sets everything to the starting point, ready for use.
  *
  * @iter: Place to store private info (inited by this call)
- * @flags: Flags to use (see enum bootflow_flags_t)
+ * @flags: Flags to use (see enum bootflow_iter_flags_t)
  */
 void bootflow_iter_init(struct bootflow_iter *iter, int flags);
 
@@ -259,15 +259,16 @@ int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter,
 /**
  * bootflow_scan_first() - find the first bootflow for a device or label
  *
- * If @flags includes BOOTFLOWF_ALL then bootflows with errors are returned too
+ * If @flags includes BOOTFLOWIF_ALL then bootflows with errors are returned too
  *
  * @dev:	Boot device to scan, NULL to work through all of them until it
  *	finds one that can supply a bootflow
  * @label:	Label to control the scan, NULL to work through all devices
  *	until it finds one that can supply a bootflow
  * @iter:	Place to store private info (inited by this call)
- * @flags:	Flags for iterator (enum bootflow_flags_t). Note that if @dev
- * is NULL, then BOOTFLOWF_SKIP_GLOBAL is set automatically by this function
+ * @flags:	Flags for iterator (enum bootflow_iter_flags_t). Note that if
+ *	@dev is NULL, then BOOTFLOWIF_SKIP_GLOBAL is set automatically by this
+ *	function
  * @bflow:	Place to put the bootflow if found
  * Return: 0 if found,  -ENODEV if no device, other -ve on other error
  *	(iteration can continue)
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index ef5215bbcec..92a8ac48c80 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -285,7 +285,7 @@ static int bootdev_test_prio(struct unit_test_state *uts)
 
 	/* try again but enable hunting, which brings in SCSI */
 	bootflow_iter_uninit(&iter);
-	ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWF_HUNT,
+	ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT,
 					&bflow));
 	ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
 	ut_asserteq(7, iter.num_devs);
@@ -420,8 +420,8 @@ static int bootdev_test_hunt_scan(struct unit_test_state *uts)
 
 	ut_assertok(bootstd_test_drop_bootdev_order(uts));
 	ut_assertok(bootflow_scan_first(NULL, NULL, &iter,
-					BOOTFLOWF_SHOW | BOOTFLOWF_HUNT |
-					BOOTFLOWF_SKIP_GLOBAL, &bflow));
+					BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT |
+					BOOTFLOWIF_SKIP_GLOBAL, &bflow));
 	ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used);
 
 	return 0;
@@ -642,7 +642,7 @@ static int bootdev_test_next_prio(struct unit_test_state *uts)
 	iter.part = 0;
 	uclass_first_device(UCLASS_BOOTMETH, &bflow.method);
 	iter.cur_prio = 0;
-	iter.flags = BOOTFLOWF_SHOW;
+	iter.flags = BOOTFLOWIF_SHOW;
 
 	dev = NULL;
 	console_record_reset_enable();
@@ -655,7 +655,7 @@ static int bootdev_test_next_prio(struct unit_test_state *uts)
 	ut_assert_console_end();
 
 	/* now try again with hunting enabled */
-	iter.flags = BOOTFLOWF_SHOW | BOOTFLOWF_HUNT;
+	iter.flags = BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT;
 	iter.cur_prio = 0;
 	iter.part = 0;
 
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index b9284fc464a..fd0e1d62435 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -277,7 +277,7 @@ static int bootflow_iter(struct unit_test_state *uts)
 	/* The first device is mmc2.bootdev which has no media */
 	ut_asserteq(-EPROTONOSUPPORT,
 		    bootflow_scan_first(NULL, NULL, &iter,
-					BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow));
+					BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow));
 	ut_asserteq(2, iter.num_methods);
 	ut_asserteq(0, iter.cur_method);
 	ut_asserteq(0, iter.part);
-- 
2.39.1.456.gfc5497dd1b-goog


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

* [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot
  2023-01-29  1:27 [PATCH v2 1/2] bootflow: Rename bootflow_flags_t Simon Glass
@ 2023-01-29  1:27 ` Simon Glass
  2023-01-30 17:10   ` Tom Rini
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Glass @ 2023-01-29  1:27 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Mark Kettenis, Tom Rini, Simon Glass

For EFI, the distro boot scripts search in three different directories
for the .dtb file. The SOC-based filename fallback is supported only for
32-bit ARM.

Adjust the code to mirror this behaviour.

Also some boards can use a prior-stage FDT if one is not found in the
normal way. Support this and show a warning in that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mark Kettenis <kettenis@openbsd.org>
---

Changes in v2:
- Allow use of the prior-stage FDT if nothing else is found
- Warn about using a prior-stage FDT

 boot/bootflow.c     |  3 ++
 boot/bootmeth_efi.c | 70 +++++++++++++++++++++++++++++++++++++++------
 include/bootflow.h  | 14 +++++++++
 3 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 4999018e36e..5ee12eb2bab 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -463,6 +463,9 @@ int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow)
 
 	printf("** Booting bootflow '%s' with %s\n", bflow->name,
 	       bflow->method->name);
+	if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
+	    (bflow->flags & BOOTFLOWF_USE_PRIOR_FDT))
+		printf("** Warning: Using prior-stage device tree\n");
 	ret = bootflow_boot(bflow);
 	if (!IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
 		printf("Boot failed (err=%d)\n", ret);
diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
index 67c972e3fe4..6a97ac02ff5 100644
--- a/boot/bootmeth_efi.c
+++ b/boot/bootmeth_efi.c
@@ -147,25 +147,60 @@ static int distro_efi_check(struct udevice *dev, struct bootflow_iter *iter)
 	return 0;
 }
 
-static void distro_efi_get_fdt_name(char *fname, int size)
+/**
+ * distro_efi_get_fdt_name() - Get the filename for reading the .dtb file
+ *
+ * @fname: Place to put filename
+ * @size: Max size of filename
+ * @seq: Sequence number, to cycle through options (0=first)
+ * Returns: 0 on success, -ENOENT if the "fdtfile" env var does not exist,
+ * -EINVAL if there are no more options, -EALREADY if the control FDT should be
+ * used
+ */
+static int distro_efi_get_fdt_name(char *fname, int size, int seq)
 {
 	const char *fdt_fname;
+	const char *prefix;
+
+	/* select the prefix */
+	switch (seq) {
+	case 0:
+		/* this is the default */
+		prefix = "/dtb";
+		break;
+	case 1:
+		prefix = "";
+		break;
+	case 2:
+		prefix = "/dtb/current";
+		break;
+	default:
+		return log_msg_ret("pref", -EINVAL);
+	}
 
 	fdt_fname = env_get("fdtfile");
 	if (fdt_fname) {
-		snprintf(fname, size, "dtb/%s", fdt_fname);
+		snprintf(fname, size, "%s/%s", prefix, fdt_fname);
 		log_debug("Using device tree: %s\n", fname);
-	} else {
+	} else if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE)) {
+		strcpy(fname, "<prior>");
+		return log_msg_ret("pref", -EALREADY);
+	/* Use this fallback only for 32-bit ARM */
+	} else if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_ARM64)) {
 		const char *soc = env_get("soc");
 		const char *board = env_get("board");
 		const char *boardver = env_get("boardver");
 
 		/* cf the code in label_boot() which seems very complex */
-		snprintf(fname, size, "dtb/%s%s%s%s.dtb",
+		snprintf(fname, size, "%s/%s%s%s%s.dtb", prefix,
 			 soc ? soc : "", soc ? "-" : "", board ? board : "",
 			 boardver ? boardver : "");
 		log_debug("Using default device tree: %s\n", fname);
+	} else {
+		return log_msg_ret("env", -ENOENT);
 	}
+
+	return 0;
 }
 
 static int distro_efi_read_bootflow_file(struct udevice *dev,
@@ -174,7 +209,7 @@ static int distro_efi_read_bootflow_file(struct udevice *dev,
 	struct blk_desc *desc = NULL;
 	ulong fdt_addr, size;
 	char fname[256];
-	int ret;
+	int ret, seq;
 
 	/* We require a partition table */
 	if (!bflow->part)
@@ -196,13 +231,26 @@ static int distro_efi_read_bootflow_file(struct udevice *dev,
 	if (ret)
 		return log_msg_ret("read", -EINVAL);
 
-	distro_efi_get_fdt_name(fname, sizeof(fname));
+	fdt_addr = env_get_hex("fdt_addr_r", 0);
+
+	/* try the various available names */
+	ret = -ENOENT;
+	for (seq = 0; ret; seq++) {
+		ret = distro_efi_get_fdt_name(fname, sizeof(fname), seq);
+		if (ret == -EALREADY) {
+			bflow->flags = BOOTFLOWF_USE_PRIOR_FDT;
+			break;
+		}
+		if (ret)
+			return log_msg_ret("nam", ret);
+		ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr,
+						&size);
+	}
+
 	bflow->fdt_fname = strdup(fname);
 	if (!bflow->fdt_fname)
 		return log_msg_ret("fil", -ENOMEM);
 
-	fdt_addr = env_get_hex("fdt_addr_r", 0);
-	ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr, &size);
 	if (!ret) {
 		bflow->fdt_size = size;
 		bflow->fdt_addr = fdt_addr;
@@ -277,7 +325,11 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 	fdt_addr = hextoul(fdt_addr_str, NULL);
 	sprintf(file_addr, "%lx", fdt_addr);
 
-	distro_efi_get_fdt_name(fname, sizeof(fname));
+	/* We only allow the first prefix with PXE */
+	ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0);
+	if (ret)
+		return log_msg_ret("nam", ret);
+
 	bflow->fdt_fname = strdup(fname);
 	if (!bflow->fdt_fname)
 		return log_msg_ret("fil", -ENOMEM);
diff --git a/include/bootflow.h b/include/bootflow.h
index e5fdf5f29d1..f20f575030f 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -36,6 +36,18 @@ enum bootflow_state_t {
 	BOOTFLOWST_COUNT
 };
 
+/**
+ * enum bootflow_flags_t - flags for bootflows
+ *
+ * @BOOTFLOWF_USE_PRIOR_FDT: Indicates that an FDT was not found by the bootmeth
+ *	and it is using the prior-stage FDT, which is the U-Boot control FDT.
+ *	This is only possible with the EFI bootmeth (distro-efi) and only when
+ *	CONFIG_OF_HAS_PRIOR_STAGE is enabled
+ */
+enum bootflow_flags_t {
+	BOOTFLOWF_USE_PRIOR_FDT	= 1 << 0,
+};
+
 /**
  * struct bootflow - information about a bootflow
  *
@@ -68,6 +80,7 @@ enum bootflow_state_t {
  * @fdt_fname: Filename of FDT file
  * @fdt_size: Size of FDT file
  * @fdt_addr: Address of loaded fdt
+ * @flags: Flags for the bootflow (see enum bootflow_flags_t)
  */
 struct bootflow {
 	struct list_head bm_node;
@@ -90,6 +103,7 @@ struct bootflow {
 	char *fdt_fname;
 	int fdt_size;
 	ulong fdt_addr;
+	int flags;
 };
 
 /**
-- 
2.39.1.456.gfc5497dd1b-goog


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

* Re: [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot
  2023-01-29  1:27 ` [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot Simon Glass
@ 2023-01-30 17:10   ` Tom Rini
  2023-02-07  4:02     ` Simon Glass
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rini @ 2023-01-30 17:10 UTC (permalink / raw)
  To: Simon Glass; +Cc: U-Boot Mailing List, Mark Kettenis

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

On Sat, Jan 28, 2023 at 06:27:15PM -0700, Simon Glass wrote:
> For EFI, the distro boot scripts search in three different directories
> for the .dtb file. The SOC-based filename fallback is supported only for
> 32-bit ARM.
> 
> Adjust the code to mirror this behaviour.
> 
> Also some boards can use a prior-stage FDT if one is not found in the
> normal way. Support this and show a warning in that case.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Suggested-by: Mark Kettenis <kettenis@openbsd.org>
> ---
> 
> Changes in v2:
> - Allow use of the prior-stage FDT if nothing else is found
> - Warn about using a prior-stage FDT
> 
>  boot/bootflow.c     |  3 ++
>  boot/bootmeth_efi.c | 70 +++++++++++++++++++++++++++++++++++++++------
>  include/bootflow.h  | 14 +++++++++
>  3 files changed, 78 insertions(+), 9 deletions(-)
> 
> diff --git a/boot/bootflow.c b/boot/bootflow.c
> index 4999018e36e..5ee12eb2bab 100644
> --- a/boot/bootflow.c
> +++ b/boot/bootflow.c
> @@ -463,6 +463,9 @@ int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow)
>  
>  	printf("** Booting bootflow '%s' with %s\n", bflow->name,
>  	       bflow->method->name);
> +	if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
> +	    (bflow->flags & BOOTFLOWF_USE_PRIOR_FDT))
> +		printf("** Warning: Using prior-stage device tree\n");

It should not be a warning. It should just be a statement. It's not an
inherent failure or problem, but it is something the user should be
aware of as it may be unexpected. Or simply because they should be just
as aware here as when it's loaded from $file at $location. A huge
general stumbling block when working on custom / new hardware is "did
the device tree I want really get used?" so being clear where the one
being used is from is important.

-- 
Tom

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

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

* Re: [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot
  2023-01-30 17:10   ` Tom Rini
@ 2023-02-07  4:02     ` Simon Glass
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2023-02-07  4:02 UTC (permalink / raw)
  To: Tom Rini; +Cc: U-Boot Mailing List, Mark Kettenis

On Mon, 30 Jan 2023 at 10:10, Tom Rini <trini@konsulko.com> wrote:
>
> On Sat, Jan 28, 2023 at 06:27:15PM -0700, Simon Glass wrote:
> > For EFI, the distro boot scripts search in three different directories
> > for the .dtb file. The SOC-based filename fallback is supported only for
> > 32-bit ARM.
> >
> > Adjust the code to mirror this behaviour.
> >
> > Also some boards can use a prior-stage FDT if one is not found in the
> > normal way. Support this and show a warning in that case.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > Suggested-by: Mark Kettenis <kettenis@openbsd.org>
> > ---
> >
> > Changes in v2:
> > - Allow use of the prior-stage FDT if nothing else is found
> > - Warn about using a prior-stage FDT
> >
> >  boot/bootflow.c     |  3 ++
> >  boot/bootmeth_efi.c | 70 +++++++++++++++++++++++++++++++++++++++------
> >  include/bootflow.h  | 14 +++++++++
> >  3 files changed, 78 insertions(+), 9 deletions(-)
> >
> > diff --git a/boot/bootflow.c b/boot/bootflow.c
> > index 4999018e36e..5ee12eb2bab 100644
> > --- a/boot/bootflow.c
> > +++ b/boot/bootflow.c
> > @@ -463,6 +463,9 @@ int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow)
> >
> >       printf("** Booting bootflow '%s' with %s\n", bflow->name,
> >              bflow->method->name);
> > +     if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
> > +         (bflow->flags & BOOTFLOWF_USE_PRIOR_FDT))
> > +             printf("** Warning: Using prior-stage device tree\n");
>
> It should not be a warning. It should just be a statement. It's not an
> inherent failure or problem, but it is something the user should be
> aware of as it may be unexpected. Or simply because they should be just
> as aware here as when it's loaded from $file at $location. A huge
> general stumbling block when working on custom / new hardware is "did
> the device tree I want really get used?" so being clear where the one
> being used is from is important.

Thanks Tom.


- Simon

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

end of thread, other threads:[~2023-02-07  4:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-29  1:27 [PATCH v2 1/2] bootflow: Rename bootflow_flags_t Simon Glass
2023-01-29  1:27 ` [PATCH v2 2/2] bootstd: Replicate the dtb-filename quirks of distroboot Simon Glass
2023-01-30 17:10   ` Tom Rini
2023-02-07  4:02     ` 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.