Skip to contentSkip to conversation

SPL: FIT: Bring the SPL_LOAD_FIT path in line with documentation

PATCH New Alexandru Gagniuc 2 participants 15 messages Mar 29, 2021 – Apr 16, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover SPL: FIT: Bring the SPL_LOAD_FIT path in line with documentation

When I wrote commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax"), I did not expect it to go through without objection. I didn't also write the code to go along with it. This series fixes that by updating one of the three FIT code paths to be compliant.

There are three code paths that deal with loading a FIT:
* ( )'bootm' command
* (x) SPL_LOAD_FIT
* ( ) SPL_LOAD_FIT_FULL

This series deals with SPL_LOAD_FIT.

I chose not to fix every nook and cranny because nobody is using those corner cases -- as evidenced by the lack of support. Known limitations are documented and clearly visible in the Kconfig menu.

Changes since v1:
- Replace NULL with 0 in comment for spl_load_fit_image().
- Updated Kconfig description for SPL_LOAD_FIT (add "property" word)
- Remove middle printf in warn_deprecated()
- Add newline before return in spl_fit_upload_fpga()

Alexandru Gagniuc (7):
spl: fit: Don't overwrite previous loadable if "load" is missing
doc: FIT image: Introduce "u-boot,fpga-legacy" property
spl: fit: Move FPGA loading code to separate functions
spl: fit: Warn if FIT contains "fpga" property in config node
spl: fit: Support loading FPGA images from list of "loadables"
Kconfig: Document the limitations of the simple SPL_LOAD_FIT path
doc: FIT image: Update FPGA example to make use of "loadables"

 common/Kconfig.boot                   |  10 +++
 common/spl/spl_fit.c                  | 113 ++++++++++++++++++++------
 doc/uImage.FIT/multi-with-fpga.its    |   3 +-
 doc/uImage.FIT/source_file_format.txt |   1 +
 4 files changed, 99 insertions(+), 28 deletions(-)

--
2.26.3

#1 lore raw

PATCH v2 1/7 spl: fit: Don't overwrite previous loadable if "load" is missing

spl_load_fit_image() will try to load an image at the address given in the "load" property. Absent such property, it uses

	image_info->load_addr

Correct use of this is demonstrated in spl_fit_append_fdt(), which resets the 'load_addr' before each spl_load_fit_image() call.

On the other hand loading "loadables" loop in spl_load_simple_fit() completely ignores this. It re-uses the same structure, but doesn't reset load_addr. If loadable [i] does not have a "load" property, its load address defaults to load_addr, which still contains the address of loadable [i - 1].

A simple solution is to treat NULL as an invalid load address. The caller can set load_addr = 0 to request an abort if the "load" property is absent.

---
 common/spl/spl_fit.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
common/spl/spl_fit.c +9 -2
index 75c8ff065b..57bcd2b9f1 100644
@@ -223,7 +223,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
  * @image_info:	will be filled with information about the loaded image
  *		If the FIT node does not contain a "load" (address) property,
  *		the image gets loaded to the address pointed to by the
- *		load_addr member in this struct.
+ *		load_addr member in this struct, if load_addr is not 0
  *
  * Return:	0 on success or a negative error number.
  */
@@ -258,8 +258,14 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 		debug("%s ", genimg_get_comp_name(image_comp));
 	}
 
-	if (fit_image_get_load(fit, node, &load_addr))
+	if (fit_image_get_load(fit, node, &load_addr)) {
+		if (!image_info->load_addr) {
+			printf("Can't load %s: No load address and no buffer\n",
+			       fit_get_name(fit, node, NULL));
+			return -ENOBUFS;
+		}
 		load_addr = image_info->load_addr;
+	}
 
 	if (!fit_image_get_data_position(fit, node, &offset)) {
 		external_data = true;
@@ -697,6 +703,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		if (firmware_node == node)
 			continue;
 
+		image_info.load_addr = 0;
 		ret = spl_load_fit_image(info, sector, &ctx, node, &image_info);
 		if (ret < 0) {
 			printf("%s: can't load image loadables index %d (ret = %d)\n",
Signature · 1 line
2.26.3
#2 lore raw

PATCH v2 1/7 spl: fit: Don't overwrite previous loadable if "load" is missing

Quoted 14 lines · Alexandru Gagniuc

spl_load_fit_image() will try to load an image at the address given in the "load" property. Absent such property, it uses

	image_info->load_addr

Correct use of this is demonstrated in spl_fit_append_fdt(), which resets the 'load_addr' before each spl_load_fit_image() call.

On the other hand loading "loadables" loop in spl_load_simple_fit() completely ignores this. It re-uses the same structure, but doesn't reset load_addr. If loadable [i] does not have a "load" property, its load address defaults to load_addr, which still contains the address of loadable [i - 1].

Quoted 6 lines

A simple solution is to treat NULL as an invalid load address. The caller can set load_addr = 0 to request an abort if the "load" property is absent.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/d3c0d1aa/attachment.sig>
#3 lore raw

PATCH v2 2/7 doc: FIT image: Introduce "u-boot, fpga-legacy" property

In reply to Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") introduced a "compatible" property for loadable images. It did not define its contents. Use "u-boot,fpga-legacy" compatible string to specify that fpga_load() should be used to load the image.

---
 doc/uImage.FIT/source_file_format.txt | 1 +
 1 file changed, 1 insertion(+)
doc/uImage.FIT/source_file_format.txt +1 -0
index 00ed3ebe93..f93ac6d1c7 100644
@@ -184,6 +184,7 @@ the '/images' node should have the following layout:
     Mandatory for types: "firmware", and "kernel".
   - compatible : compatible method for loading image.
     Mandatory for types: "fpga", and images that do not specify a load address.
+    To use the generic fpga loading routine, use "u-boot,fpga-legacy".
 
   Optional nodes:
   - hash-1 : Each hash sub-node represents separate hash or checksum
Signature · 1 line
2.26.3
#4 lore raw

PATCH v2 2/7 doc: FIT image: Introduce "u-boot, fpga-legacy" property

Quoted 6 lines · Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") introduced a "compatible" property for loadable images. It did not define its contents. Use "u-boot,fpga-legacy" compatible string to specify that fpga_load() should be used to load the image.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/ba4cea2a/attachment.sig>
#5 lore raw

PATCH v2 3/7 spl: fit: Move FPGA loading code to separate functions

In reply to Alexandru Gagniuc

The FPGA loading code in spl_simple_fit_read() can easily be separated from the rest of the logic. It is split into two functions instead of one because spl_fit_upload_fpga() is used in a subsequent patch.

---
 common/spl/spl_fit.c | 70 ++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 25 deletions(-)
common/spl/spl_fit.c +45 -25
index 57bcd2b9f1..6e9d9808b3 100644
@@ -526,6 +526,49 @@ __weak bool spl_load_simple_fit_skip_processing(void)
 	return false;
 }
 
+static int spl_fit_upload_fpga(struct spl_fit_info *ctx, int node,
+			       struct spl_image_info *fpga_image)
+{
+	int ret;
+
+	debug("FPGA bitstream at: %x, size: %x\n",
+	      (u32)fpga_image->load_addr, fpga_image->size);
+
+	ret = fpga_load(0, (void *)fpga_image->load_addr, fpga_image->size,
+			BIT_FULL);
+	if (ret) {
+		printf("%s: Cannot load the image to the FPGA\n", __func__);
+		return ret;
+	}
+
+	puts("FPGA image loaded from FIT\n");
+
+	return 0;
+}
+
+static int spl_fit_load_fpga(struct spl_fit_info *ctx,
+			     struct spl_load_info *info, ulong sector)
+{
+	int node, ret;
+
+	struct spl_image_info fpga_image = {
+		.load_addr = 0,
+	};
+
+	node = spl_fit_get_image_node(ctx, "fpga", 0);
+	if (node < 0)
+		return node;
+
+	/* Load the image and set up the fpga_image structure */
+	ret = spl_load_fit_image(info, sector, ctx, node, &fpga_image);
+	if (ret) {
+		printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
+		return ret;
+	}
+
+	return spl_fit_upload_fpga(ctx, node, &fpga_image);
+}
+
 static int spl_simple_fit_read(struct spl_fit_info *ctx,
 			       struct spl_load_info *info, ulong sector,
 			       const void *fit_header)
@@ -609,31 +652,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	if (ret < 0)
 		return ret;
 
-#ifdef CONFIG_SPL_FPGA
-	node = spl_fit_get_image_node(&ctx, "fpga", 0);
-	if (node >= 0) {
-		/* Load the image and set up the spl_image structure */
-		ret = spl_load_fit_image(info, sector, &ctx, node, spl_image);
-		if (ret) {
-			printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
-			return ret;
-		}
-
-		debug("FPGA bitstream at: %x, size: %x\n",
-		      (u32)spl_image->load_addr, spl_image->size);
-
-		ret = fpga_load(0, (const void *)spl_image->load_addr,
-				spl_image->size, BIT_FULL);
-		if (ret) {
-			printf("%s: Cannot load the image to the FPGA\n",
-			       __func__);
-			return ret;
-		}
-
-		puts("FPGA image loaded from FIT\n");
-		node = -1;
-	}
-#endif
+	if (IS_ENABLED(CONFIG_SPL_FPGA))
+		spl_fit_load_fpga(&ctx, info, sector);
 
 	/*
 	 * Find the U-Boot image using the following search order:
Signature · 1 line
2.26.3
#6 lore raw

PATCH v2 3/7 spl: fit: Move FPGA loading code to separate functions

Quoted 6 lines · Alexandru Gagniuc

The FPGA loading code in spl_simple_fit_read() can easily be separated from the rest of the logic. It is split into two functions instead of one because spl_fit_upload_fpga() is used in a subsequent patch.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/06a332d3/attachment.sig>
#7 lore raw

PATCH v2 4/7 spl: fit: Warn if FIT contains "fpga" property in config node

In reply to Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") requires that FPGA images be referenced through the "loadables" in the config node. This means that "fpga" properties in config nodes are deprecated.

Given that there are likely FIT images which use "fpga", let's not break those right away. Print a warning message that such use is deprecated, and give users a couple of releases to update their

---
 common/spl/spl_fit.c | 8 ++++++++
 1 file changed, 8 insertions(+)
common/spl/spl_fit.c +8 -0
index 6e9d9808b3..1a6c4a0ea2 100644
@@ -526,6 +526,12 @@ __weak bool spl_load_simple_fit_skip_processing(void)
 	return false;
 }
 
+static void warn_deprecated(const char *msg)
+{
+	printf("DEPRECATED: %s\n", msg);
+	printf("\tSee doc/uImage.FIT/source_file_format.txt\n");
+}
+
 static int spl_fit_upload_fpga(struct spl_fit_info *ctx, int node,
 			       struct spl_image_info *fpga_image)
 {
@@ -559,6 +565,8 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx,
 	if (node < 0)
 		return node;
 
+	warn_deprecated("'fpga' property in config node. Use 'loadables'");
+
 	/* Load the image and set up the fpga_image structure */
 	ret = spl_load_fit_image(info, sector, ctx, node, &fpga_image);
 	if (ret) {
Signature · 1 line
2.26.3
#8 lore raw

PATCH v2 4/7 spl: fit: Warn if FIT contains "fpga" property in config node

Quoted 10 lines · Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") requires that FPGA images be referenced through the "loadables" in the config node. This means that "fpga" properties in config nodes are deprecated.

Given that there are likely FIT images which use "fpga", let's not break those right away. Print a warning message that such use is deprecated, and give users a couple of releases to update their

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/9ae7e247/attachment.sig>
#9 lore raw

PATCH v2 5/7 spl: fit: Support loading FPGA images from list of "loadables"

In reply to Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") and delegated FPGA images to be added via the list of "loadables" in lieu of the "fpga" property. Now actually implement this in code.

Note that the "compatible" property is ignored for the time being, as implementing "compatible" loading is beyond the scope of this change. However, "u-boot,fpga-legacy" is accepted without warning.

---
 common/spl/spl_fit.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
common/spl/spl_fit.c +24 -0
index 1a6c4a0ea2..9945ee1d7f 100644
@@ -477,6 +477,20 @@ static int spl_fit_record_loadable(const struct spl_fit_info *ctx, int index,
 	return ret;
 }
 
+static int spl_fit_image_is_fpga(const void *fit, int node)
+{
+	const char *type;
+
+	if (!IS_ENABLED(CONFIG_SPL_FPGA))
+		return 0;
+
+	type = fdt_getprop(fit, node, FIT_TYPE_PROP, NULL);
+	if (!type)
+		return 0;
+
+	return !strcmp(type, "fpga");
+}
+
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
 	if (!CONFIG_IS_ENABLED(FIT_IMAGE_TINY) || CONFIG_IS_ENABLED(OS_BOOT))
@@ -535,11 +549,18 @@ static void warn_deprecated(const char *msg)
 static int spl_fit_upload_fpga(struct spl_fit_info *ctx, int node,
 			       struct spl_image_info *fpga_image)
 {
+	const char *compatible;
 	int ret;
 
 	debug("FPGA bitstream at: %x, size: %x\n",
 	      (u32)fpga_image->load_addr, fpga_image->size);
 
+	compatible = fdt_getprop(ctx->fit, node, "compatible", NULL);
+	if (!compatible)
+		warn_deprecated("'fpga' image without 'compatible' property");
+	else if (strcmp(compatible, "u-boot,fpga-legacy"))
+		printf("Ignoring compatible = %s property\n", compatible);
+
 	ret = fpga_load(0, (void *)fpga_image->load_addr, fpga_image->size,
 			BIT_FULL);
 	if (ret) {
@@ -739,6 +760,9 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 			return ret;
 		}
 
+		if (spl_fit_image_is_fpga(ctx.fit, node))
+			spl_fit_upload_fpga(&ctx, node, &image_info);
+
 		if (!spl_fit_image_get_os(ctx.fit, node, &os_type))
 			debug("Loadable is %s\n", genimg_get_os_name(os_type));
 
Signature · 1 line
2.26.3
#10 lore raw

PATCH v2 5/7 spl: fit: Support loading FPGA images from list of "loadables"

Quoted 10 lines · Alexandru Gagniuc

Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify syntax") and delegated FPGA images to be added via the list of "loadables" in lieu of the "fpga" property. Now actually implement this in code.

Note that the "compatible" property is ignored for the time being, as implementing "compatible" loading is beyond the scope of this change. However, "u-boot,fpga-legacy" is accepted without warning.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/e09da121/attachment.sig>
#11 lore raw

PATCH v2 6/7 Kconfig: Document the limitations of the simple SPL_LOAD_FIT path

In reply to Alexandru Gagniuc

The "simple" SPL_LOAD_FIT path is the most compliant with the format documented in doc/uImage.FIT/source_file_format.txt. The other two paths to load a FIT are SPL_LOAD_FIT_FULL and the "bootm" command.

Since the Kconfig menu is the most likely place for a new user to see these options, it seems like the most logical candidate to document the limitations. This documents the _known_ issues, and is not intended to be a complete list of all follies.

---
 common/Kconfig.boot | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/Kconfig.boot +10 -0
index 9c335f4f8c..5a18d62d78 100644
@@ -202,6 +202,16 @@ config SPL_LOAD_FIT
 	  particular it can handle selecting from multiple device tree
 	  and passing the correct one to U-Boot.
 
+	  This path has the following limitations:
+
+	  1. "loadables" images, other than FTDs, which do not have a "load"
+	     property will not be loaded. This limitation also applies to FPGA
+	     images with the correct "compatible" string.
+	  2. For FPGA images, only the "compatible" = "u-boot,fpga-legacy"
+	     loading method is supported.
+	  3. FDTs are only loaded for images with an "os" property of "u-boot".
+	     "linux" images are also supported with Falcon boot mode.
+
 config SPL_LOAD_FIT_ADDRESS
 	hex "load address of fit image"
 	depends on SPL_LOAD_FIT
Signature · 1 line
2.26.3
#12 lore raw

PATCH v2 6/7 Kconfig: Document the limitations of the simple SPL_LOAD_FIT path

Quoted 11 lines · Alexandru Gagniuc

The "simple" SPL_LOAD_FIT path is the most compliant with the format documented in doc/uImage.FIT/source_file_format.txt. The other two paths to load a FIT are SPL_LOAD_FIT_FULL and the "bootm" command.

Since the Kconfig menu is the most likely place for a new user to see these options, it seems like the most logical candidate to document the limitations. This documents the _known_ issues, and is not intended to be a complete list of all follies.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/50b26e76/attachment.sig>
#13 lore raw

PATCH v2 7/7 doc: FIT image: Update FPGA example to make use of "loadables"

In reply to Alexandru Gagniuc

The new correct way to load an FPGA image is to declare it in the list of "loadables". multi-with-fpga.its used the now deprecated "fpga" property. Since this example most likely intended to use u-boot's generic FPGA loading code, compatible = "u-boot,fpga-legacy" is also appropriate here.

---
 doc/uImage.FIT/multi-with-fpga.its | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
doc/uImage.FIT/multi-with-fpga.its +2 -1
index 47ee5760c4..021cbc7cf4 100644
@@ -29,6 +29,7 @@
 			arch = "arm";
 			compression = "none";
 			load = <0x30000000>;
+			compatible = "u-boot,fpga-legacy"
 			hash-1 {
 				algo = "md5";
 			};
@@ -61,7 +62,7 @@
 			description = "Linux with fpga";
 			kernel = "linux_kernel";
 			fdt = "fdt-1";
-			fpga = "fpga";
+			loadables = "fpga";
 		};
 	};
 };
Signature · 1 line
2.26.3
#14 lore raw

PATCH v2 7/7 doc: FIT image: Update FPGA example to make use of "loadables"

Quoted 8 lines · Alexandru Gagniuc

The new correct way to load an FPGA image is to declare it in the list of "loadables". multi-with-fpga.its used the now deprecated "fpga" property. Since this example most likely intended to use u-boot's generic FPGA loading code, compatible = "u-boot,fpga-legacy" is also appropriate here.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210416/a8f08965/attachment.sig>