All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT
@ 2018-11-17  9:10 Peng Fan
  2018-11-17  9:10 ` [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes Peng Fan
  2018-12-08 17:41 ` [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Stefano Babic
  0 siblings, 2 replies; 4+ messages in thread
From: Peng Fan @ 2018-11-17  9:10 UTC (permalink / raw)
  To: u-boot

From: Ye Li <ye.li@nxp.com>

Introduce two board level callback functions to FIT image loading process, and
a SPL_FIT_FOUND flag to differentiate FIT image or RAW image.

Implement functions in imx common SPL codes to call HAB funtion
to authenticate the FIT image. Generally, we have to sign multiple regions
in FIT image:
1. Sign FIT FDT data (configuration)
2. Sign FIT external data (Sub-images)

Because the CSF supports to sign multiple memory blocks, so that we can use one
signature to cover all regions in FIT image and only authenticate once.
The authentication should be done after the entire FIT image is loaded into
memory including all sub-images.
We use "-p" option to generate FIT image to reserve a space for FIT IVT
and FIT CSF, also this help to fix the offset of the external data (u-boot-nodtb.bin,
ATF, u-boot DTB).

The signed FIT image layout is as below:
--------------------------------------------------
|     |     |     |   |           |     |        |
| FIT | FIT | FIT |   | U-BOOT    | ATF | U-BOOT |
| FDT | IVT | CSF |   | nodtb.bin |     |   DTB  |
|     |     |     |   |           |     |        |
--------------------------------------------------

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 Add Tom's review tag

 arch/arm/mach-imx/spl.c | 44 ++++++++++++++++++++++++++++++++++++++------
 common/spl/spl_fit.c    | 21 +++++++++++++++++++--
 include/spl.h           |  1 +
 3 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index a20b30d154..6f0b5cdb4c 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -220,14 +220,46 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 
 	debug("image entry point: 0x%lX\n", spl_image->entry_point);
 
-	/* HAB looks for the CSF at the end of the authenticated data therefore,
-	 * we need to subtract the size of the CSF from the actual filesize */
-	offset = spl_image->size - CONFIG_CSF_SIZE;
-	if (!imx_hab_authenticate_image(spl_image->load_addr,
-					offset + IVT_SIZE + CSF_PAD_SIZE,
-					offset)) {
+	if (spl_image->flags & SPL_FIT_FOUND) {
 		image_entry();
 	} else {
+		/*
+		 * HAB looks for the CSF at the end of the authenticated
+		 * data therefore, we need to subtract the size of the
+		 * CSF from the actual filesize
+		 */
+		offset = spl_image->size - CONFIG_CSF_SIZE;
+		if (!imx_hab_authenticate_image(spl_image->load_addr,
+						offset + IVT_SIZE +
+						CSF_PAD_SIZE, offset)) {
+			image_entry();
+		} else {
+			puts("spl: ERROR:  image authentication fail\n");
+			hang();
+		}
+	}
+}
+
+ulong board_spl_fit_size_align(ulong size)
+{
+	/*
+	 * HAB authenticate_image requests the IVT offset is
+	 * aligned to 0x1000
+	 */
+
+	size = ALIGN(size, 0x1000);
+	size += CONFIG_CSF_SIZE;
+
+	return size;
+}
+
+void board_spl_fit_post_load(ulong load_addr, size_t length)
+{
+	u32 offset = length - CONFIG_CSF_SIZE;
+
+	if (imx_hab_authenticate_image(load_addr,
+				       offset + IVT_SIZE + CSF_PAD_SIZE,
+				       offset)) {
 		puts("spl: ERROR:  image authentication unsuccessful\n");
 		hang();
 	}
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index faf4ddbd1f..db436268cb 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -15,6 +15,15 @@
 #define CONFIG_SYS_BOOTM_LEN	(64 << 20)
 #endif
 
+__weak void board_spl_fit_post_load(ulong load_addr, size_t length)
+{
+}
+
+__weak ulong board_spl_fit_size_align(ulong size)
+{
+	return size;
+}
+
 /**
  * spl_fit_get_image_name(): By using the matching configuration subnode,
  * retrieve the name of an image, specified by a property name and an index
@@ -350,6 +359,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	 */
 	size = fdt_totalsize(fit);
 	size = (size + 3) & ~3;
+	size = board_spl_fit_size_align(size);
 	base_offset = (size + 3) & ~3;
 
 	/*
@@ -373,8 +383,9 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	fit = spl_get_load_buffer(-hsize, hsize);
 	sectors = get_aligned_image_size(info, size, 0);
 	count = info->read(info, sector, sectors, fit);
-	debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
-	      sector, sectors, fit, count);
+	debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu, size=0x%lx\n",
+	      sector, sectors, fit, count, size);
+
 	if (count == 0)
 		return -EIO;
 
@@ -510,5 +521,11 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	if (spl_image->entry_point == FDT_ERROR || spl_image->entry_point == 0)
 		spl_image->entry_point = spl_image->load_addr;
 
+	spl_image->flags |= SPL_FIT_FOUND;
+
+#ifdef CONFIG_SECURE_BOOT
+	board_spl_fit_post_load((ulong)fit, size);
+#endif
+
 	return 0;
 }
diff --git a/include/spl.h b/include/spl.h
index 9a439f468b..5dd25ab611 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -77,6 +77,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 			struct spl_load_info *info, ulong sector, void *fdt);
 
 #define SPL_COPY_PAYLOAD_ONLY	1
+#define SPL_FIT_FOUND		2
 
 /* SPL common functions */
 void preloader_console_init(void);
-- 
2.14.1

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

* [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes
  2018-11-17  9:10 [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Peng Fan
@ 2018-11-17  9:10 ` Peng Fan
  2018-12-11  1:03   ` Simon Glass
  2018-12-08 17:41 ` [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Stefano Babic
  1 sibling, 1 reply; 4+ messages in thread
From: Peng Fan @ 2018-11-17  9:10 UTC (permalink / raw)
  To: u-boot

Introduce function prototypes for board_spl_fit_size_align and
board_spl_fit_post_load

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 New file per Simon's comments

 include/spl.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/spl.h b/include/spl.h
index 5dd25ab611..d6f7f11ddb 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -312,6 +312,18 @@ void spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
  */
 void board_return_to_bootrom(void);
 
+/**
+ * board_spl_fit_post_load - allow process images after loading finished
+ *
+ */
+void board_spl_fit_post_load(ulong load_addr, size_t length);
+
+/**
+ * board_spl_fit_size_align - specific size align before processing payload
+ *
+ */
+ulong board_spl_fit_size_align(ulong size);
+
 /**
  * spl_perform_fixups() - arch/board-specific callback before processing
  *                        the boot-payload
-- 
2.14.1

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

* [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT
  2018-11-17  9:10 [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Peng Fan
  2018-11-17  9:10 ` [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes Peng Fan
@ 2018-12-08 17:41 ` Stefano Babic
  1 sibling, 0 replies; 4+ messages in thread
From: Stefano Babic @ 2018-12-08 17:41 UTC (permalink / raw)
  To: u-boot



On 17/11/18 10:10, Peng Fan wrote:
> From: Ye Li <ye.li@nxp.com>
> 
> Introduce two board level callback functions to FIT image loading process, and
> a SPL_FIT_FOUND flag to differentiate FIT image or RAW image.
> 
> Implement functions in imx common SPL codes to call HAB funtion
> to authenticate the FIT image. Generally, we have to sign multiple regions
> in FIT image:
> 1. Sign FIT FDT data (configuration)
> 2. Sign FIT external data (Sub-images)
> 
> Because the CSF supports to sign multiple memory blocks, so that we can use one
> signature to cover all regions in FIT image and only authenticate once.
> The authentication should be done after the entire FIT image is loaded into
> memory including all sub-images.
> We use "-p" option to generate FIT image to reserve a space for FIT IVT
> and FIT CSF, also this help to fix the offset of the external data (u-boot-nodtb.bin,
> ATF, u-boot DTB).
> 
> The signed FIT image layout is as below:
> --------------------------------------------------
> |     |     |     |   |           |     |        |
> | FIT | FIT | FIT |   | U-BOOT    | ATF | U-BOOT |
> | FDT | IVT | CSF |   | nodtb.bin |     |   DTB  |
> |     |     |     |   |           |     |        |
> --------------------------------------------------
> 
> Signed-off-by: Ye Li <ye.li@nxp.com>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

* [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes
  2018-11-17  9:10 ` [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes Peng Fan
@ 2018-12-11  1:03   ` Simon Glass
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2018-12-11  1:03 UTC (permalink / raw)
  To: u-boot

On Sat, 17 Nov 2018 at 02:10, Peng Fan <peng.fan@nxp.com> wrote:
>
> Introduce function prototypes for board_spl_fit_size_align and
> board_spl_fit_post_load
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>
> V2:
>  New file per Simon's comments
>
>  include/spl.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

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

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

end of thread, other threads:[~2018-12-11  1:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-17  9:10 [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Peng Fan
2018-11-17  9:10 ` [U-Boot] [PATCH V2 2/2] spl: introduce function prototypes Peng Fan
2018-12-11  1:03   ` Simon Glass
2018-12-08 17:41 ` [U-Boot] [PATCH V2 1/2] SPL: Add HAB image authentication to FIT Stefano Babic

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.