All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dannenberg <dannenberg@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 1/9] spl: fit: add support for post-processing of images
Date: Wed, 15 Jun 2016 14:26:33 -0500	[thread overview]
Message-ID: <1466018801-18044-2-git-send-email-dannenberg@ti.com> (raw)
In-Reply-To: <1466018801-18044-1-git-send-email-dannenberg@ti.com>

From: Daniel Allred <d-allred@ti.com>

The next stage boot loader image and the selected FDT can be
post-processed by board/platform/device-specific code, which can include
modifying the size and altering the starting source address before
copying these binary blobs to their final desitination. This might be
desired to do things like strip headers or footers attached to the
images before they were packeaged into the FIT, or to perform operations
such as decryption or authentication.

Signed-off-by: Daniel Allred <d-allred@ti.com>
Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
---
 common/spl/spl_fit.c | 21 ++++++++++++++++-----
 include/image.h      | 15 +++++++++++++++
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 9874708..ecbcb97 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -121,6 +121,10 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
 	return (data_size + info->bl_len - 1) / info->bl_len;
 }
 
+void __weak board_fit_image_post_process(void **p_src, size_t *p_size)
+{
+}
+
 int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
 {
 	int sectors;
@@ -132,7 +136,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
 	int data_offset, data_size;
 	int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
 	int src_sector;
-	void *dst;
+	void *dst, *src;
 
 	/*
 	 * Figure out where the external images start. This is the base for the
@@ -206,8 +210,11 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
 		return -EIO;
 	debug("image: dst=%p, data_offset=%x, size=%x\n", dst, data_offset,
 	      data_size);
-	memcpy(dst, dst + get_aligned_image_overhead(info, data_offset),
-	       data_size);
+	src = dst + get_aligned_image_overhead(info, data_offset);
+
+	board_fit_image_post_process((void **)&src, (size_t *)&data_size);
+
+	memcpy(dst, src, data_size);
 
 	/* Figure out which device tree the board wants to use */
 	fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
@@ -236,8 +243,12 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
 	 */
 	debug("fdt: dst=%p, data_offset=%x, size=%x\n", dst, fdt_offset,
 	      fdt_len);
-	memcpy(load_ptr + data_size,
-	       dst + get_aligned_image_overhead(info, fdt_offset), fdt_len);
+	src = dst + get_aligned_image_overhead(info, fdt_offset);
+	dst = load_ptr + data_size;
+
+	board_fit_image_post_process((void **)&src, (size_t *)&fdt_len);
+
+	memcpy(dst, src, fdt_len);
 
 	return 0;
 }
diff --git a/include/image.h b/include/image.h
index a8f6bd1..9536874 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1172,4 +1172,19 @@ ulong android_image_get_kload(const struct andr_img_hdr *hdr);
  */
 int board_fit_config_name_match(const char *name);
 
+/**
+ * board_fit_image_post_process() - Do any post-process on FIT binary data
+ *
+ * This is used to do any sort of image manipulation, verification, decryption
+ * etc. in a platform or board specific way. Obviously, anything done here would
+ * need to be comprehended in how the images were prepared before being injected
+ * into the FIT creation (i.e. the binary blobs would have been pre-processed
+ * before being added to the FIT image).
+ *
+ * @image: pointer to the image start pointer
+ * @size: pointer to the image size
+ * @return no return value (failure should be handled internally)
+ */
+void board_fit_image_post_process(void **p_image, size_t *p_size);
+
 #endif	/* __IMAGE_H__ */
-- 
2.6.4

  reply	other threads:[~2016-06-15 19:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15 19:26 [U-Boot] [RFC 0/9] Secure Boot by Authenticating/Decrypting SPL FIT blobs Andreas Dannenberg
2016-06-15 19:26 ` Andreas Dannenberg [this message]
2016-06-17  3:52   ` [U-Boot] [RFC 1/9] spl: fit: add support for post-processing of images Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 2/9] arm: cache: add missing dummy functions for when dcache disabled Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-20  2:13   ` Tom Rini
2016-06-15 19:26 ` [U-Boot] [RFC 3/9] arm: omap-common: add secure smc entry Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 4/9] arm: omap-common: add secure rom call API for secure devices Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:18   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 5/9] arm: omap5: add secure ROM signature verify API Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-20  2:13     ` Tom Rini
2016-06-15 19:26 ` [U-Boot] [RFC 6/9] arm: omap5: add FIT image post process function Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:26   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 7/9] arm: am4x: add secure ROM signature verify API Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 8/9] arm: am4x: add FIT image post process function Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:27   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 9/9] ti: omap-common: Update to generate secure FIT Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17 16:13     ` Andreas Dannenberg
2016-06-20 22:40       ` Simon Glass
2016-06-21  2:35         ` Andreas Dannenberg
2016-06-23  4:59           ` Masahiro Yamada
2016-06-23 13:23             ` Andreas Dannenberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466018801-18044-2-git-send-email-dannenberg@ti.com \
    --to=dannenberg@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.