[U-Boot] [PATCH] spl: Add full fitImage support

Add support for loading U-Boot and optionally FDT from a fitImage in SPL by using the full fitImage support from U-Boot. While we do have limited SPL loading support in SPL with a small footprint, it is missing a lot of important features, like checking signatures. This support has all the fitImage features, while the footprint is obviously larger.
Signed-off-by: Marek Vasut marex@denx.de Cc: Pantelis Antoniou pantelis.antoniou@konsulko.com Cc: Simon Glass sjg@chromium.org --- V2: - Drop blank line below spl_load_fit_image() - Explicitly enable image verification if available --- Kconfig | 11 +++++++++ common/spl/spl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
diff --git a/Kconfig b/Kconfig index 7d9e971f0e..5a82c95dd8 100644 --- a/Kconfig +++ b/Kconfig @@ -328,6 +328,17 @@ config SPL_LOAD_FIT particular it can handle selecting from multiple device tree and passing the correct one to U-Boot.
+config SPL_LOAD_FIT_FULL + bool "Enable SPL loading U-Boot as a FIT" + select SPL_FIT + help + Normally with the SPL framework a legacy image is generated as part + of the build. This contains U-Boot along with information as to + where it should be loaded. This option instead enables generation + of a FIT (Flat Image Tree) which provides more flexibility. In + particular it can handle selecting from multiple device tree + and passing the correct one to U-Boot. + config SPL_FIT_IMAGE_POST_PROCESS bool "Enable post-processing of FIT artifacts after loading by the SPL" depends on SPL_LOAD_FIT diff --git a/common/spl/spl.c b/common/spl/spl.c index 079780c6df..7dace07543 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -150,9 +150,83 @@ void spl_set_header_raw_uboot(struct spl_image_info *spl_image) spl_image->name = "U-Boot"; }
+#ifdef CONFIG_SPL_LOAD_FIT_FULL +/* Parse and load full fitImage in SPL */ +static int spl_load_fit_image(struct spl_image_info *spl_image, + const struct image_header *header) +{ + bootm_headers_t images; + const char *fit_uname_config = NULL; + const char *fit_uname_fdt = FIT_FDT_PROP; + const char *uname; + ulong fw_data = 0, dt_data = 0, img_data = 0; + ulong fw_len = 0, dt_len = 0, img_len = 0; + int idx, conf_noffset; + int ret; + +#ifdef CONFIG_SPL_FIT_SIGNATURE + images.verify = 1; +#endif + ret = fit_image_load(&images, (ulong)header, + NULL, &fit_uname_config, + IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1, + FIT_LOAD_REQUIRED, &fw_data, &fw_len); + if (ret < 0) + return ret; + + spl_image->size = fw_len; + spl_image->entry_point = fw_data; + spl_image->load_addr = fw_data; + spl_image->os = IH_OS_U_BOOT; + spl_image->name = "U-Boot"; + + debug("spl: payload image: %.*s load addr: 0x%lx size: %d\n", + (int)sizeof(spl_image->name), spl_image->name, + spl_image->load_addr, spl_image->size); + +#ifdef CONFIG_SPL_FIT_SIGNATURE + images.verify = 1; +#endif + fit_image_load(&images, (ulong)header, + &fit_uname_fdt, &fit_uname_config, + IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1, + FIT_LOAD_OPTIONAL, &dt_data, &dt_len); + + conf_noffset = fit_conf_get_node((const void *)header, + fit_uname_config); + if (conf_noffset <= 0) + return 0; + + for (idx = 0; + uname = fdt_stringlist_get((const void *)header, conf_noffset, + FIT_LOADABLE_PROP, idx, + NULL), uname; + idx++) + { +#ifdef CONFIG_SPL_FIT_SIGNATURE + images.verify = 1; +#endif + ret = fit_image_load(&images, (ulong)header, + &uname, &fit_uname_config, + IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1, + FIT_LOAD_OPTIONAL_NON_ZERO, + &img_data, &img_len); + if (ret < 0) + return ret; + } + + return 0; +} +#endif + int spl_parse_image_header(struct spl_image_info *spl_image, const struct image_header *header) { +#ifdef CONFIG_SPL_LOAD_FIT_FULL + int ret = spl_load_fit_image(spl_image, header); + if (!ret) + return ret; +#endif if (image_get_magic(header) == IH_MAGIC) { #ifdef CONFIG_SPL_LEGACY_IMAGE_SUPPORT u32 header_size = sizeof(struct image_header);

On 13 May 2018 at 08:23, Marek Vasut marex@denx.de wrote:
Add support for loading U-Boot and optionally FDT from a fitImage in SPL by using the full fitImage support from U-Boot. While we do have limited SPL loading support in SPL with a small footprint, it is missing a lot of important features, like checking signatures. This support has all the fitImage features, while the footprint is obviously larger.
Signed-off-by: Marek Vasut marex@denx.de Cc: Pantelis Antoniou pantelis.antoniou@konsulko.com Cc: Simon Glass sjg@chromium.org
V2: - Drop blank line below spl_load_fit_image() - Explicitly enable image verification if available
Kconfig | 11 +++++++++ common/spl/spl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Can you add this to the FIT tests?

On 05/14/2018 12:02 AM, Simon Glass wrote:
On 13 May 2018 at 08:23, Marek Vasut marex@denx.de wrote:
Add support for loading U-Boot and optionally FDT from a fitImage in SPL by using the full fitImage support from U-Boot. While we do have limited SPL loading support in SPL with a small footprint, it is missing a lot of important features, like checking signatures. This support has all the fitImage features, while the footprint is obviously larger.
Signed-off-by: Marek Vasut marex@denx.de Cc: Pantelis Antoniou pantelis.antoniou@konsulko.com Cc: Simon Glass sjg@chromium.org
V2: - Drop blank line below spl_load_fit_image() - Explicitly enable image verification if available
Kconfig | 11 +++++++++ common/spl/spl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Can you add this to the FIT tests?
Yeah, do you have some pointers for me ?

Hi Marek,
On 13 May 2018 at 16:22, Marek Vasut marex@denx.de wrote:
On 05/14/2018 12:02 AM, Simon Glass wrote:
On 13 May 2018 at 08:23, Marek Vasut marex@denx.de wrote:
Add support for loading U-Boot and optionally FDT from a fitImage in SPL by using the full fitImage support from U-Boot. While we do have limited SPL loading support in SPL with a small footprint, it is missing a lot of important features, like checking signatures. This support has all the fitImage features, while the footprint is obviously larger.
Signed-off-by: Marek Vasut marex@denx.de Cc: Pantelis Antoniou pantelis.antoniou@konsulko.com Cc: Simon Glass sjg@chromium.org
V2: - Drop blank line below spl_load_fit_image() - Explicitly enable image verification if available
Kconfig | 11 +++++++++ common/spl/spl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Can you add this to the FIT tests?
Yeah, do you have some pointers for me ?
The current test is in test/py/tests/test_fit.py so you can start with that, or create a new one based on it.
At present we have sandbox_spl which includes SPL support. If you run a test with that (i.e. CONFIG_SPL set) it will run SPL, which in turn will load U-Boot. The logic for that is in u_boot_console_sandbox.py and the function which actually loads U-Boot is spl_board_load_image().
So I think you could create a FIT with U-Boot and a DTB in it, then modify spl_board_load_image() to use that instead. Then your test could simply check the console output. For example test_ofplatdata.py shows how to find a string in the output, although at present that test does nothing, since there is no way to tell SPL to output the platdata.
Regards, Simon

On Sun, May 13, 2018 at 12:23:17AM +0200, Marek Vasut wrote:
Add support for loading U-Boot and optionally FDT from a fitImage in SPL by using the full fitImage support from U-Boot. While we do have limited SPL loading support in SPL with a small footprint, it is missing a lot of important features, like checking signatures. This support has all the fitImage features, while the footprint is obviously larger.
Signed-off-by: Marek Vasut marex@denx.de Cc: Pantelis Antoniou pantelis.antoniou@konsulko.com Cc: Simon Glass sjg@chromium.org Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
participants (3)
-
Marek Vasut
-
Simon Glass
-
Tom Rini