All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <marek.behun@nic.cz>
To: u-boot@lists.denx.de, Chris Packham <judge.packham@gmail.com>,
	Stefan Roese <sr@denx.de>, Baruch Siach <baruch@tkos.co.il>,
	Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: "Dennis Gilmore" <dgilmore@redhat.com>,
	"Mario Six" <mario.six@gdsys.cc>,
	"Jon Nettleton" <jon@solid-run.com>,
	"Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-mvebu v3 15/41] tools: kwbimage: Add support for more BINARY headers
Date: Fri, 23 Jul 2021 11:14:09 +0200	[thread overview]
Message-ID: <20210723091435.20388-16-marek.behun@nic.cz> (raw)
In-Reply-To: <20210723091435.20388-1-marek.behun@nic.cz>

From: Pali Rohár <pali@kernel.org>

The kwbimage v1 format supports multiple BINARY executable headers.
Add support for it into mkimage/kwbimage tool.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Chris Packham <judge.packham@gmail.com>
Reviewed-by: Stefan Roese <sr@denx.de>
Tested-by: Chris Packham <judge.packham@gmail.com>
---
 tools/kwbimage.c | 59 +++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 6c9f93ae8b..1bfc524424 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -942,6 +942,7 @@ static size_t image_headersz_v1(int *hasext)
 {
 	struct image_cfg_element *binarye;
 	size_t headersz;
+	int cfgi;
 
 	/*
 	 * Calculate the size of the header and the size of the
@@ -949,21 +950,19 @@ static size_t image_headersz_v1(int *hasext)
 	 */
 	headersz = sizeof(struct main_hdr_v1);
 
-	if (image_count_options(IMAGE_CFG_BINARY) > 1) {
-		fprintf(stderr, "More than one binary blob, not supported\n");
-		return 0;
-	}
-
 	if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) {
 		fprintf(stderr, "More than one payload, not possible\n");
 		return 0;
 	}
 
-	binarye = image_find_option(IMAGE_CFG_BINARY);
-	if (binarye) {
+	for (cfgi = 0; cfgi < cfgn; cfgi++) {
 		int ret;
 		struct stat s;
 
+		binarye = &image_cfg[cfgi];
+		if (binarye->type != IMAGE_CFG_BINARY)
+			continue;
+
 		ret = stat(binarye->binary.file, &s);
 		if (ret < 0) {
 			char cwd[PATH_MAX];
@@ -1018,10 +1017,10 @@ static size_t image_headersz_v1(int *hasext)
 	return ALIGN(headersz, 4096);
 }
 
-int add_binary_header_v1(uint8_t *cur)
+int add_binary_header_v1(uint8_t **cur, uint8_t **next_ext,
+			 struct image_cfg_element *binarye)
 {
-	struct image_cfg_element *binarye;
-	struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur;
+	struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)*cur;
 	uint32_t *args;
 	size_t binhdrsz;
 	struct stat s;
@@ -1029,11 +1028,6 @@ int add_binary_header_v1(uint8_t *cur)
 	FILE *bin;
 	int ret;
 
-	binarye = image_find_option(IMAGE_CFG_BINARY);
-
-	if (!binarye)
-		return 0;
-
 	hdr->headertype = OPT_HDR_V1_BINARY_TYPE;
 
 	bin = fopen(binarye->binary.file, "r");
@@ -1055,17 +1049,17 @@ int add_binary_header_v1(uint8_t *cur)
 	hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF);
 	hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
 
-	cur += sizeof(struct opt_hdr_v1);
+	*cur += sizeof(struct opt_hdr_v1);
 
-	args = (uint32_t *)cur;
+	args = (uint32_t *)*cur;
 	*args = cpu_to_le32(binarye->binary.nargs);
 	args++;
 	for (argi = 0; argi < binarye->binary.nargs; argi++)
 		args[argi] = cpu_to_le32(binarye->binary.args[argi]);
 
-	cur += (binarye->binary.nargs + 1) * sizeof(uint32_t);
+	*cur += (binarye->binary.nargs + 1) * sizeof(uint32_t);
 
-	ret = fread(cur, s.st_size, 1, bin);
+	ret = fread(*cur, s.st_size, 1, bin);
 	if (ret != 1) {
 		fprintf(stderr,
 			"Could not read binary image %s\n",
@@ -1075,17 +1069,13 @@ int add_binary_header_v1(uint8_t *cur)
 
 	fclose(bin);
 
-	cur += ALIGN(s.st_size, 4);
+	*cur += ALIGN(s.st_size, 4);
 
-	/*
-	 * For now, we don't support more than one binary
-	 * header, and no other header types are
-	 * supported. So, the binary header is necessarily the
-	 * last one
-	 */
-	*((uint32_t *)cur) = 0x00000000;
+	*((uint32_t *)*cur) = 0x00000000;
+	**next_ext = 1;
+	*next_ext = *cur;
 
-	cur += sizeof(uint32_t);
+	*cur += sizeof(uint32_t);
 
 	return 0;
 
@@ -1218,6 +1208,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 	uint8_t *image, *cur;
 	int hasext = 0;
 	uint8_t *next_ext = NULL;
+	int cfgi;
 
 	/*
 	 * Calculate the size of the header and the size of the
@@ -1296,13 +1287,19 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 		 */
 		secure_hdr = (struct secure_hdr_v1 *)cur;
 		cur += sizeof(struct secure_hdr_v1);
+		*next_ext = 1;
 		next_ext = &secure_hdr->next;
 	}
 #endif
-	*next_ext = 1;
 
-	if (add_binary_header_v1(cur))
-		return NULL;
+	for (cfgi = 0; cfgi < cfgn; cfgi++) {
+		e = &image_cfg[cfgi];
+		if (e->type != IMAGE_CFG_BINARY)
+			continue;
+
+		if (add_binary_header_v1(&cur, &next_ext, e))
+			return NULL;
+	}
 
 #if defined(CONFIG_KWB_SECURE)
 	if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz,
-- 
2.31.1


  parent reply	other threads:[~2021-07-23  9:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  9:13 [PATCH u-boot-mvebu v3 00/41] kwboot / kwbimage improvements reducing image size Marek Behún
2021-07-23  9:13 ` [PATCH u-boot-mvebu v3 01/41] tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS Marek Behún
2021-07-23  9:13 ` [PATCH u-boot-mvebu v3 02/41] tools: kwbimage: Simplify aligning and calculating checksum Marek Behún
2021-07-23  9:13 ` [PATCH u-boot-mvebu v3 03/41] tools: kwbimage: Align SPI and NAND images to 256 bytes Marek Behún
2021-07-23  9:13 ` [PATCH u-boot-mvebu v3 04/41] tools: kwbimage: Add constant for SDIO bootfrom Marek Behún
2021-07-23  9:13 ` [PATCH u-boot-mvebu v3 05/41] tools: kwbimage: Fix generation of SATA, SDIO and PCIe images Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 06/41] tools: kwbimage: Don't crash when binary file name does not contain '/' Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 07/41] tools: kwbimage: Fix check for v0 extended header checksum Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 08/41] tools: kwbimage: Validate extended headers of v1 images Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 09/41] tools: kwbimage: Validate data checksum " Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 10/41] tools: kwbimage: Print size of binary header in kwbimage_print_header() Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 11/41] tools: kwbimage: Cosmetic fix - remove redundant space character Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 12/41] tools: kwbimage: Use -a parameter (load address) for v1 images Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 13/41] tools: kwbimage: Change maximum number of arguments in binary header to 256 Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 14/41] tools: kwbimage: Fix calculating size of binary header Marek Behún
2021-07-23  9:14 ` Marek Behún [this message]
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 16/41] tools: kwbimage: Don't parse PAYLOAD keyword Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 17/41] tools: kwbimage: Add support for DATA command also for v1 images Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 18/41] tools: kwbimage: Add support for a new DATA_DELAY command Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 19/41] tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 20/41] tools: kwbimage: Mark all BootROM structures __packed Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 21/41] tools: dumpimage: Fix crashing when trying to extract data from kwbimage Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 22/41] tools: dumpimage: Show error message " Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 23/41] tools: kwboot: Fix wrong parameter passed to read() Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 24/41] tools: kwboot: Fix restoring terminal Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 25/41] tools: kwboot: Print trailing newline after terminal is terminated Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 26/41] tools: kwboot: Cosmetic fix - add missing curly brackets Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 27/41] tools: kwboot: Check for v1 header size Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 28/41] tools: kwboot: Fix checking image header version Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 29/41] arm: mvebu: Fix return_to_bootrom() Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 30/41] arm: mvebu: Mark return_to_bootrom() as a noreturn function Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 31/41] arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 32/41] arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 33/41] SPL: Add support for specifying offset between header and image Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 34/41] SPL: Add support for parsing board / BootROM specific image types Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 35/41] arm: mvebu: Load U-Boot proper binary in SPL code based on kwbimage header Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 36/41] arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 37/41] tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 38/41] arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 39/41] arm: mvebu: gdsys: Remove custom spl_board_init() Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 40/41] kwbimage: Add support for extracting images via dumpimage tool Marek Behún
2021-07-23  9:14 ` [PATCH u-boot-mvebu v3 41/41] kwbimage: Update help message about how to extract from an existing image Marek Behún
2021-07-31 10:00 ` [PATCH u-boot-mvebu v3 00/41] kwboot / kwbimage improvements reducing image size Stefan Roese

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=20210723091435.20388-16-marek.behun@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=baruch@tkos.co.il \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=dgilmore@redhat.com \
    --cc=jon@solid-run.com \
    --cc=judge.packham@gmail.com \
    --cc=mario.six@gdsys.cc \
    --cc=pali@kernel.org \
    --cc=sr@denx.de \
    --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.