diff mbox series

[U-Boot,6/9] spl: Add support for overlaying U-Boot DT

Message ID 20171228120621.4039-7-marex@denx.de
State Changes Requested
Delegated to: Tom Rini
Headers show
Series spl: Add full fit and u-boot dto support | expand

Commit Message

Marek Vasut Dec. 28, 2017, 12:06 p.m. UTC
Add support for loading fitImage with device tree overlay image, which
is applied to the U-Boot's own device tree. Once the DT is applied, the
fitImage loading process is restarted.

This patch allows a usecase where the DTO patches ie. load address in
the U-Boot's DT or patches in a new public key for authenticating the
subsequently loaded fitImages.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
---
 common/spl/spl.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

Comments

Lukasz Majewski Dec. 28, 2017, 2:23 p.m. UTC | #1
Hi Marek,

> Add support for loading fitImage with device tree overlay image, which
> is applied to the U-Boot's own device tree. Once the DT is applied,
> the fitImage loading process is restarted.
> 
> This patch allows a usecase where the DTO patches ie. load address in
> the U-Boot's DT or patches in a new public key for authenticating the
> subsequently loaded fitImages.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>  common/spl/spl.c | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index d429ea2c82..2444abbb08 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -140,6 +140,38 @@ void spl_set_header_raw_uboot(struct
> spl_image_info *spl_image) }
>  
>  #ifdef CONFIG_SPL_LOAD_FIT_FULL
> +#ifdef CONFIG_OF_LIBFDT_OVERLAY
> +static int spl_fit_overlay_uboot_fdt_full(const struct image_header
> *header) +{
> +	bootm_headers_t images;
> +	const char *fit_uname_config = NULL;
> +	const char *fit_uname_dtbo = "u-boot-dtbo";
> +	ulong dto_data = 0;
> +	ulong dto_len = 0;
> +	int ret;
> +
> +	ret = fit_image_load(&images, (ulong)header,
> +			     &fit_uname_dtbo, &fit_uname_config,
> +			     IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
> +			     FIT_LOAD_OPTIONAL, &dto_data, &dto_len);
> +	if (ret < 0)
> +		return 0;
> +
> +	ret = fdt_overlay_apply_verbose((struct fdt_header
> *)gd->fdt_blob,
> +					(void *)dto_data);
> +	if (ret)
> +		hang();
> +
> +	/* Restart the loading process to cater for the DT changes */
> +	return -EAGAIN;
> +}
> +#else
> +static int spl_fit_overlay_uboot_fdt_full(const struct image_header
> *header) +{
> +	return 0;
> +}
> +#endif
> +
>  /* Parse and load full fitImage in SPL */
>  static int spl_load_fit_image(struct spl_image_info *spl_image,
>  			      const struct image_header *header)
> @@ -152,6 +184,10 @@ static int spl_load_fit_image(struct
> spl_image_info *spl_image, ulong fw_len = 0, dt_len = 0;
>  	int ret;
>  
> +	ret = spl_fit_overlay_uboot_fdt_full(header);
> +	if (ret)
> +		return ret;
> +
>  	ret = fit_image_load(&images, (ulong)header,
>  			     NULL, &fit_uname_config,
>  			     IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
> @@ -182,7 +218,7 @@ int spl_parse_image_header(struct spl_image_info
> *spl_image, {
>  #ifdef CONFIG_SPL_LOAD_FIT_FULL
>  	int ret = spl_load_fit_image(spl_image, header);
> -	if (!ret)
> +	if (!ret || ret == -EAGAIN)
>  		return ret;
>  #endif
>  	if (image_get_magic(header) == IH_MAGIC) {

Reviewed-by: Lukasz Majewski <lukma@denx.de>

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Simon Glass Jan. 8, 2018, 4:20 a.m. UTC | #2
Hi Marek,

On 28 December 2017 at 05:06, Marek Vasut <marex@denx.de> wrote:
> Add support for loading fitImage with device tree overlay image, which
> is applied to the U-Boot's own device tree. Once the DT is applied, the
> fitImage loading process is restarted.
>
> This patch allows a usecase where the DTO patches ie. load address in
> the U-Boot's DT or patches in a new public key for authenticating the
> subsequently loaded fitImages.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>  common/spl/spl.c | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
>

This needs a test.

> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index d429ea2c82..2444abbb08 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -140,6 +140,38 @@ void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
>  }
>
>  #ifdef CONFIG_SPL_LOAD_FIT_FULL
> +#ifdef CONFIG_OF_LIBFDT_OVERLAY

Can we avoid this by doing

if (IS_ENABLED(...))

below?

> +static int spl_fit_overlay_uboot_fdt_full(const struct image_header *header)
> +{
> +       bootm_headers_t images;
> +       const char *fit_uname_config = NULL;
> +       const char *fit_uname_dtbo = "u-boot-dtbo";
> +       ulong dto_data = 0;
> +       ulong dto_len = 0;
> +       int ret;
> +
> +       ret = fit_image_load(&images, (ulong)header,
> +                            &fit_uname_dtbo, &fit_uname_config,
> +                            IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
> +                            FIT_LOAD_OPTIONAL, &dto_data, &dto_len);
> +       if (ret < 0)
> +               return 0;
> +
> +       ret = fdt_overlay_apply_verbose((struct fdt_header *)gd->fdt_blob,
> +                                       (void *)dto_data);
> +       if (ret)
> +               hang();
> +
> +       /* Restart the loading process to cater for the DT changes */
> +       return -EAGAIN;
> +}
> +#else
> +static int spl_fit_overlay_uboot_fdt_full(const struct image_header *header)
> +{
> +       return 0;
> +}
> +#endif
> +
>  /* Parse and load full fitImage in SPL */
>  static int spl_load_fit_image(struct spl_image_info *spl_image,
>                               const struct image_header *header)
> @@ -152,6 +184,10 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
>         ulong fw_len = 0, dt_len = 0;
>         int ret;
>
> +       ret = spl_fit_overlay_uboot_fdt_full(header);
> +       if (ret)
> +               return ret;
> +
>         ret = fit_image_load(&images, (ulong)header,
>                              NULL, &fit_uname_config,
>                              IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
> @@ -182,7 +218,7 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
>  {
>  #ifdef CONFIG_SPL_LOAD_FIT_FULL
>         int ret = spl_load_fit_image(spl_image, header);
> -       if (!ret)
> +       if (!ret || ret == -EAGAIN)
>                 return ret;
>  #endif
>         if (image_get_magic(header) == IH_MAGIC) {
> --
> 2.15.0
>

Regards,
Simon
diff mbox series

Patch

diff --git a/common/spl/spl.c b/common/spl/spl.c
index d429ea2c82..2444abbb08 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -140,6 +140,38 @@  void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
 }
 
 #ifdef CONFIG_SPL_LOAD_FIT_FULL
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+static int spl_fit_overlay_uboot_fdt_full(const struct image_header *header)
+{
+	bootm_headers_t images;
+	const char *fit_uname_config = NULL;
+	const char *fit_uname_dtbo = "u-boot-dtbo";
+	ulong dto_data = 0;
+	ulong dto_len = 0;
+	int ret;
+
+	ret = fit_image_load(&images, (ulong)header,
+			     &fit_uname_dtbo, &fit_uname_config,
+			     IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
+			     FIT_LOAD_OPTIONAL, &dto_data, &dto_len);
+	if (ret < 0)
+		return 0;
+
+	ret = fdt_overlay_apply_verbose((struct fdt_header *)gd->fdt_blob,
+					(void *)dto_data);
+	if (ret)
+		hang();
+
+	/* Restart the loading process to cater for the DT changes */
+	return -EAGAIN;
+}
+#else
+static int spl_fit_overlay_uboot_fdt_full(const struct image_header *header)
+{
+	return 0;
+}
+#endif
+
 /* Parse and load full fitImage in SPL */
 static int spl_load_fit_image(struct spl_image_info *spl_image,
 			      const struct image_header *header)
@@ -152,6 +184,10 @@  static int spl_load_fit_image(struct spl_image_info *spl_image,
 	ulong fw_len = 0, dt_len = 0;
 	int ret;
 
+	ret = spl_fit_overlay_uboot_fdt_full(header);
+	if (ret)
+		return ret;
+
 	ret = fit_image_load(&images, (ulong)header,
 			     NULL, &fit_uname_config,
 			     IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
@@ -182,7 +218,7 @@  int spl_parse_image_header(struct spl_image_info *spl_image,
 {
 #ifdef CONFIG_SPL_LOAD_FIT_FULL
 	int ret = spl_load_fit_image(spl_image, header);
-	if (!ret)
+	if (!ret || ret == -EAGAIN)
 		return ret;
 #endif
 	if (image_get_magic(header) == IH_MAGIC) {