Skip to contentSkip to conversation

tools: mkimage: hdr_size used to facilitate customized support

PATCH New Prafulla Wadaskar 2 participants 5 messages Jul 21, 2009 – Jul 22, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 tools: mkimage: hdr_size used to facilitate customized support

hdr_size variable is initialized
at the begining of image creation algorithm instead of reading it each time. This facilitate to use the common code for other image type implementations for ex. kwbimage

---
hdr_size declaration moved at the top

 tools/mkimage.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
tools/mkimage.c +8 -10
index 967fe9a..40363a9 100644
@@ -66,6 +66,7 @@ main (int argc, char **argv)
 	struct stat sbuf;
 	unsigned char *ptr;
 	char *name = "";
+	int hdr_size;
 
 	cmdname = *argv;
 
@@ -250,9 +251,9 @@ NXTARG:		;
 	 *
 	 * write dummy header, to be fixed later
 	 */
-	memset (hdr, 0, image_get_header_size ());
-
-	if (write(ifd, hdr, image_get_header_size ()) != image_get_header_size ()) {
+	hdr_size = image_get_header_size ();
+	memset (hdr, 0, hdr_size);
+	if (write(ifd, hdr, hdr_size) != hdr_size) {
 		fprintf (stderr, "%s: Write error on %s: %s\n",
 			cmdname, imagefile, strerror(errno));
 		exit (EXIT_FAILURE);
@@ -339,14 +340,12 @@ NXTARG:		;
 	hdr = (image_header_t *)ptr;
 
 	checksum = crc32 (0,
-			  (const char *)(ptr + image_get_header_size ()),
-			  sbuf.st_size - image_get_header_size ()
-			 );
-
+			(const char *)(ptr + hdr_size),
+			sbuf.st_size - hdr_size);
 	/* Build new header */
 	image_set_magic (hdr, IH_MAGIC);
 	image_set_time (hdr, sbuf.st_mtime);
-	image_set_size (hdr, sbuf.st_size - image_get_header_size ());
+	image_set_size (hdr, sbuf.st_size - hdr_size);
 	image_set_load (hdr, addr);
 	image_set_ep (hdr, ep);
 	image_set_dcrc (hdr, checksum);
@@ -354,10 +353,9 @@ NXTARG:		;
 	image_set_arch (hdr, opt_arch);
 	image_set_type (hdr, opt_type);
 	image_set_comp (hdr, opt_comp);
-
 	image_set_name (hdr, name);
 
-	checksum = crc32 (0, (const char *)hdr, image_get_header_size ());
+	checksum = crc32 (0, (const char *)hdr, hdr_size);
 
 	image_set_hcrc (hdr, checksum);
 
Signature · 1 line
1.5.3.4
#1 lore raw

PATCH v2 2/4 tools: mkimage (type=kwbimage) kirkwood boot image support

For more details refer docs/README.kwbimage

---
Change log:
v2: strtok_r() used for simple parser algorithm updated as per feedback for v1
all line checked to be below 78 :-)

 Makefile            |    5 +
 common/image.c      |    1 +
 doc/README.kwbimage |   93 ++++++++++++++++++
 include/image.h     |    1 +
 tools/Makefile      |    1 +
 tools/kwbimage.c    |  264 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/kwbimage.h    |  104 ++++++++++++++++++++
 tools/mkimage.c     |   26 +++++-
 8 files changed, 494 insertions(+), 1 deletions(-)
 create mode 100644 doc/README.kwbimage
 create mode 100644 tools/kwbimage.c
 create mode 100644 tools/kwbimage.h
Makefile +5 -0
index 55fc2a3..ebe00dc 100644
@@ -339,6 +339,10 @@ $(obj)u-boot.img:	$(obj)u-boot.bin
 			sed -e 's/"[	 ]*$$/ for $(BOARD) board"/') \
 		-d $< $@
 
+$(obj)u-boot.kwb:       $(obj)u-boot.bin
+		$(obj)tools/mkimage -n $(KWD_CONFIG) -T kwbimage \
+		-a $(TEXT_BASE) -e $(TEXT_BASE) -d $< $@
+
 $(obj)u-boot.sha1:	$(obj)u-boot.bin
 		$(obj)tools/ubsha1 $(obj)u-boot.bin
 
@@ -3638,6 +3642,7 @@ clobber:	clean
 	@rm -f $(OBJS) $(obj)*.bak $(obj)ctags $(obj)etags $(obj)TAGS \
 		$(obj)cscope.* $(obj)*.*~
 	@rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
+	@rm -f $(obj)u-boot.kwb
 	@rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes}
 	@rm -f $(obj)cpu/mpc824x/bedbug_603e.c
 	@rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
common/image.c +1 -0
index e22c974..845006f 100644
@@ -145,6 +145,7 @@ static table_entry_t uimage_type[] = {
 	{	IH_TYPE_SCRIPT,     "script",	  "Script",		},
 	{	IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
 	{	IH_TYPE_FLATDT,     "flat_dt",    "Flat Device Tree",	},
+	{	IH_TYPE_KWBIMAGE,   "kwbimage",   "Kirkwood Boot Image",},
 	{	-1,		    "",		  "",			},
 };
 
doc/README.kwbimage new file +93 -0

93 lines not on this page · raw message

include/image.h +1 -0
index f183757..be322bd 100644
@@ -158,6 +158,7 @@
 #define IH_TYPE_SCRIPT		6	/* Script file			*/
 #define IH_TYPE_FILESYSTEM	7	/* Filesystem Image (any type)	*/
 #define IH_TYPE_FLATDT		8	/* Binary Flat Device Tree Blob	*/
+#define IH_TYPE_KWBIMAGE	9	/* Kirkwood Boot Image		*/
 
 /*
  * Compression Types
tools/Makefile +1 -0
index 43c284c..5ead74c 100644
@@ -167,6 +167,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 	$(STRIP) $@
 
 $(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
+			$(obj)kwbimage.o \
 			$(obj)sha1.o $(LIBFDT_OBJS) $(obj)os_support.o
 	$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 	$(STRIP) $@
tools/kwbimage.c new file +264 -0

264 lines not on this page · raw message

tools/kwbimage.h new file +104 -0

104 lines not on this page · raw message

tools/mkimage.c +25 -1
index 40363a9..ba71874 100644
@@ -24,6 +24,7 @@
 
 #include "mkimage.h"
 #include <image.h>
+#include "kwbimage.h"
 
 extern int errno;
 
@@ -164,6 +165,10 @@ NXTARG:		;
 		(lflag && (dflag || fflag)))
 		usage();
 
+	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
+		(xflag || lflag))
+		usage();
+
 	if (!eflag) {
 		ep = addr;
 		/* If XIP, entry point must be after the U-Boot header */
@@ -251,7 +256,12 @@ NXTARG:		;
 	 *
 	 * write dummy header, to be fixed later
 	 */
-	hdr_size = image_get_header_size ();
+	if (opt_type == IH_TYPE_KWBIMAGE) {
+		hdr = kwbimage_get_header_ptr();
+		hdr_size = kwbimage_get_header_size ();
+	} else
+		hdr_size = image_get_header_size ();
+
 	memset (hdr, 0, hdr_size);
 	if (write(ifd, hdr, hdr_size) != hdr_size) {
 		fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -339,6 +349,19 @@ NXTARG:		;
 
 	hdr = (image_header_t *)ptr;
 
+	/* Build new header */
+	if (opt_type == IH_TYPE_KWBIMAGE) {
+	checksum = kwbimage_checksum32((uint32_t *)ptr, sbuf.st_size, 0);
+
+		if (write(ifd, &checksum, sizeof(uint32_t))
+					!= sizeof(uint32_t)) {
+			fprintf (stderr, "%s: Checksum wr err on %s: %s\n",
+				cmdname, imagefile, strerror(errno));
+			exit (EXIT_FAILURE);
+		}
+		sbuf.st_size += sizeof(uint32_t);
+		kwbimage_set_header (hdr, &sbuf, addr, ep, name);
+	} else {
 	checksum = crc32 (0,
 			(const char *)(ptr + hdr_size),
 			sbuf.st_size - hdr_size);
@@ -361,6 +384,7 @@ NXTARG:		;
 
 	image_print_contents (hdr);
 
+	}
 	(void) munmap((void *)ptr, sbuf.st_size);
 
 	/* We're a bit of paranoid */
Signature · 1 line
1.5.3.4
#2 lore raw

PATCH 3/4 tools: mkimage: kwbimage list command support

---
 common/image.c   |    4 ++--
 tools/kwbimage.c |   41 +++++++++++++++++++++++++++++++++++++++++
 tools/mkimage.c  |    7 ++++++-
 3 files changed, 49 insertions(+), 3 deletions(-)
common/image.c +2 -2
index 845006f..e3ad3e5 100644
@@ -159,7 +159,7 @@ static table_entry_t uimage_comp[] = {
 
 uint32_t crc32 (uint32_t, const unsigned char *, uint);
 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
-static void genimg_print_size (uint32_t size);
+void genimg_print_size (uint32_t size);
 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
 static void genimg_print_time (time_t timestamp);
 #endif
@@ -473,7 +473,7 @@ void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
 }
 #endif /* !USE_HOSTCC */
 
-static void genimg_print_size (uint32_t size)
+void genimg_print_size (uint32_t size)
 {
 #ifndef USE_HOSTCC
 	printf ("%d Bytes = ", size);
tools/kwbimage.c +41 -0

50 lines not on this page · raw message

tools/mkimage.c +6 -1
index ba71874..0d46bda 100644
@@ -166,7 +166,7 @@ NXTARG:		;
 		usage();
 
 	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
-		(xflag || lflag))
+		(xflag))
 		usage();
 
 	if (!eflag) {
@@ -231,6 +231,11 @@ NXTARG:		;
 			exit (EXIT_FAILURE);
 		}
 
+		if (!(kwbimage_check_header ((struct kwb_header *)ptr))) {
+			kwbimage_print_contents ((struct kwb_header *)ptr);
+			exit (EXIT_SUCCESS);
+		}
+
 		if (fdt_check_header (ptr)) {
 			/* old-style image */
 			image_verify_header ((char *)ptr, sbuf.st_size);
Signature · 1 line
1.5.3.4
#3 lore raw

PATCH v2 2/4 tools: mkimage (type=kwbimage) kirkwood boot image support

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

Quoted 14 lines · In message <[email protected]> you wrote:

For more details refer docs/README.kwbimage

tools/kwbimage.c new file +10 -0
+enum kwbimage_cmd kwbimage_check_cfgcmd(char *token,
+				struct kwb_header *kwbhdr)
+{
+	extbhr_t *exthdr = &kwbhdr->kwb_exthdr;
+	char tempptr[MAX_TEMPBUF_LEN];
+
+	/* command string processing */
+	if (strcmp(token, "BOOT_FROM") == 0)
+		return CMD_BOOT_FROM;
+	else if (strcmp(token, "NAND_ECC_MODE") == 0)

tools/kwbimage.c line 99

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+		return CMD_NAND_ECC_MODE;
+	else if (strcmp(token, "NAND_PAGE_SIZE") == 0)
+		return CMD_NAND_PAGE_SIZE;
+	else if (strcmp(token, "SATA_PIO_MODE") == 0)
+		return CMD_SATA_PIO_MODE;
+	else if (strcmp(token, "DDR_INIT_DELAY") == 0)
+		return CMD_DDR_INIT_DELAY;
+	else {
+		exthdr->rcfg[datacmd_cnt].raddr =
+			(uint32_t) strtoul (token, tempptr, 16);

No error checking here? What happens if token does not repesent a valid number format?

Quoted 7 lines
tools/kwbimage.c new file +7 -0
+void kwbimage_check_cfgdata(char *token, enum kwbimage_cmd cmdsw,
+					struct kwb_header *kwbhdr)
+{
+	bhr_t *mhdr = &kwbhdr->kwb_hdr;
+	extbhr_t *exthdr = &kwbhdr->kwb_exthdr;
+	char tempptr[MAX_TEMPBUF_LEN];
+

tools/kwbimage.c line 120

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+	switch(cmdsw) {
+	case CMD_BOOT_FROM:
+		if (strcmp(token, "spi") == 0) {
+			mhdr->blockid = IBR_HDR_SPI_ID;
+		} else if (strcmp(token, "nand") == 0) {
+			mhdr->blockid = IBR_HDR_NAND_ID;
+		} else if (strcmp(token, "sata") == 0) {
+			mhdr->blockid = IBR_HDR_SATA_ID;
+		} else {
+			printf("Err.. Invalid kwimage data\n");

Well, please print a more helpful error message here: print the line number where the error occurs, and what's wrong (i. e. boot medium is neither "spi" or "nand" or "sata" but ``token'' instead.

tools/kwbimage.c line 138

Quoted 13 lines
tools/kwbimage.c new file +13 -0
+	case CMD_NAND_ECC_MODE:
+		if (strcmp(token, "default") == 0) {
+			mhdr->nandeccmode = IBR_HDR_ECC_DEFAULT;
+		} else if (strcmp(token, "hamming") == 0) {
+			mhdr->nandeccmode =
+				IBR_HDR_ECC_FORCED_HAMMING;
+		} else if (strcmp(token, "rs") == 0) {
+			mhdr->nandeccmode =
+				IBR_HDR_ECC_FORCED_RS;
+		} else if (strcmp(token, "disabled") == 0) {
+			mhdr->nandeccmode = IBR_HDR_ECC_DISABLED;
+		} else {
+			printf("Err.. Invalid kwimage data\n");

Ditto.

It seems you have several such places where you try to find a value in a list of valid tokens. I suggest you use array of strings for that, for example:

	char *boot_from[] = {
		"spi",
		"nand",
		"sata",
		NULL,
	};

So you can search in a loop instead of a (long) if...else...else list; put that in a function, and you can use this function fol all such searches by just passing a different string list as argument.

Quoted 9 lines
tools/kwbimage.c new file +9 -0
+	case CMD_NAND_PAGE_SIZE:
+		mhdr->nandpagesize =
+			(uint16_t) strtoul (token, tempptr, 16);
+			printf("Nand page size = %x\n", mhdr->nandpagesize);
+		break;
+	case CMD_SATA_PIO_MODE:
+		mhdr->satapiomode =
+			(uint8_t) strtoul (token, tempptr, 16);
+			printf("Sata PIO mode = %x\n", mhdr->satapiomode);

tools/kwbimage.c line 161

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+		break;
+	case CMD_DDR_INIT_DELAY:
+		mhdr->ddrinitdelay =
+			(uint16_t) strtoul (token, tempptr, 16);
+		printf("DDR init delay = %d msec\n",
+					mhdr->ddrinitdelay);
+		break;
+	case CMD_DDR_DATA:
+		exthdr->rcfg[datacmd_cnt].rdata =
+			(uint32_t) strtoul (token, tempptr, 16);

Please add error checking for all these strtoul() calls.

Please also use a consistent coding style. Either you consistently use a space after the function name, i. e. "foo ()", or you do not, i. e. "foo()" - but please do not mix both styles at random.

tools/kwbimage.c line 166

Quoted 4 lines
tools/kwbimage.c new file +4 -0
+		if (datacmd_cnt > KWBIMAGE_MAX_CONFIG ) {
+			printf("Err.. found more than max "
+				"allowed(%d) configurations\n",
+				KWBIMAGE_MAX_CONFIG);

Where is this limit coming from? Can the be arbitrarily changed, or is it some inherent linif of your image format?

Eventually also print line number information, etc.

tools/kwbimage.c line 173

Quoted 7 lines
tools/kwbimage.c new file +7 -0
+			exit (EXIT_FAILURE);
+		} else
+			datacmd_cnt++;
+		break;
+	case CMD_INVALID:
+	default:
+		printf("Error.. invalid data %s\n",token);

Please print a more helpful error message - see above.

And please try and use a consistent format for error messages, don;t mix for example "Err..." and "Error...".

My recommendation is to use something like

	"Error: %s[%d] - ...", filename, linenumber, ...
Quoted 12 lines
tools/kwbimage.c new file +12 -0
+void kwdimage_set_ext_header(struct kwb_header *kwbhdr, char* fname) {
+	bhr_t *mhdr = &kwbhdr->kwb_hdr;
+	extbhr_t *exthdr = &kwbhdr->kwb_exthdr;
+	int fd = -1;
+	int lineno, j;
+	char *line = NULL;
+	char * token, *saveptr1, *saveptr2;
+	size_t len = 0;
+	enum kwbimage_cmd cmd;
+
+	/* set dram register offset */
+	exthdr->dramregsoffs = (uint32_t)&exthdr->rcfg - (uint32_t)mhdr;

tools/kwbimage.c line 199

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+
+	if ((fd = fopen(fname, "r")) == 0) {
+		if (strlen(fname))
+			fprintf (stderr, "Err: Can't open %s: %s\n",
+				fname, strerror(errno));
+		else
+			fprintf (stderr, "Err: kwbimage.cfg not specified "
+				"%s\n"
+				"add -n <file>/<kwbimage.cfg> to the cmd\n",
+			strerror(errno));

This makes no sense. If no file name is given you should detect this based on the argument parsing, not based on the string length. And this test should be run _before_ you attempot to open the file.

tools/kwbimage.c line 213

Quoted 11 lines
tools/kwbimage.c new file +11 -0
+	/* Simple kwimage.cfg file parser */
+	lineno=0;
+	while ((getline(&line, &len, fd)) != -1) {
+		lineno++;
+		token = strtok_r(line, "\r\n", &saveptr1);
+		/* drop all lines with zero tokens (= empty lines) */
+		if (token == NULL)
+			continue;
+
+		for (j = 0, cmd = CMD_INVALID, line = token; ; line = NULL) {
+			token = strtok_r(line, " 	", &saveptr2);

Please write as " \t" so the content of the string constant is clear.

Review

Quoted 2 lines
(quoted diff) +2 -0
+			if (token == NULL)
+			break;

Comment?

Quoted 12 lines
tools/kwbimage.c new file +12 -0
+			/* Drop all text starting with '#' as comments */
+			if (token[0] == '#')
+				break;
+
+			/* Process rest as valid config command line */
+			if (j == 0) {
+				cmd = kwbimage_check_cfgcmd(token, kwbhdr);
+				if (cmd == CMD_INVALID)
+					break;
+			} else if (j == 1) {
+				kwbimage_check_cfgdata(token, cmd, kwbhdr);
+			} else {

tools/kwbimage.c line 237

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+				/*
+				 * Command format permits only two strings
+				 * on a line, i.e. command and data
+				 * if more than two are observed, then error
+				 * will be reported
+				 */
+				printf("Error.. Invalid command line(%d)\n",
+					lineno);
+				exit (EXIT_FAILURE);
+			}

Maybe a "case (...) { ...}" would be easier to read here.

tools/kwbimage.h line 4

Quoted 10 lines
tools/kwbimage.h new file +4 -0
new file mode 100644
index 0000000..98ab34f
@@ -0,0 +1,104 @@
+/*
+ * (C) Copyright 2008
+ * Marvell Semiconductor <www.marvell.com>
+ * iWritten-by: Prafulla Wadaskar <[email protected]>

Typo?

Quoted 13 lines
tools/mkimage.c +1 -0
index 40363a9..ba71874 100644
@@ -24,6 +24,7 @@
 
 #include "mkimage.h"
 #include <image.h>
+#include "kwbimage.h"
 
 extern int errno;
 

tools/mkimage.c NXTARG: ; · line 170

Quoted 6 lines
tools/mkimage.c +3 -0
@@ -164,6 +165,10 @@ NXTARG:		;
 		(lflag && (dflag || fflag)))
 		usage();
 
+	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
+		(xflag || lflag))
+		usage();

Do you promise to add support for listing the image (lflag) later?

tools/mkimage.c NXTARG: ; · line 263

Quoted 13 lines
tools/mkimage.c +5 -1
 	if (!eflag) {
 		ep = addr;
 		/* If XIP, entry point must be after the U-Boot header */
@@ -251,7 +256,12 @@ NXTARG:		;
 	 *
 	 * write dummy header, to be fixed later
 	 */
-	hdr_size = image_get_header_size ();
+	if (opt_type == IH_TYPE_KWBIMAGE) {
+		hdr = kwbimage_get_header_ptr();
+		hdr_size = kwbimage_get_header_size ();
+	} else
+		hdr_size = image_get_header_size ();

Maybe we should use a function pointer for image_get_header_size() which can be set just once, so we don't have to change the code?

Quoted 11 lines
tools/mkimage.c +4 -0
 	memset (hdr, 0, hdr_size);
 	if (write(ifd, hdr, hdr_size) != hdr_size) {
 		fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -339,6 +349,19 @@ NXTARG:		;
 
 	hdr = (image_header_t *)ptr;
 
+	/* Build new header */
+	if (opt_type == IH_TYPE_KWBIMAGE) {
+	checksum = kwbimage_checksum32((uint32_t *)ptr, sbuf.st_size, 0);
+

tools/mkimage.c NXTARG: ; · line 365

Quoted 10 lines
tools/mkimage.c +9 -0
+		if (write(ifd, &checksum, sizeof(uint32_t))
+					!= sizeof(uint32_t)) {
+			fprintf (stderr, "%s: Checksum wr err on %s: %s\n",
+				cmdname, imagefile, strerror(errno));
+			exit (EXIT_FAILURE);
+		}
+		sbuf.st_size += sizeof(uint32_t);
+		kwbimage_set_header (hdr, &sbuf, addr, ep, name);
+	} else {
 	checksum = crc32 (0,

Here indentation becomes wrong.

And I don't like this if()...else... thingy here. I think we should move the respective code into functions, and just set a pointer to the function the builds the header.

This prevents an ever growing list of if()...else...else...else... in case more image formats need to get added.

#4 lore raw

PATCH v2 2/4 tools: mkimage (type=kwbimage) kirkwood boot image support

Quoted 10 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Wednesday, July 22, 2009 2:06 PM
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Ashish Karkare; Prabhanjan Sarnaik
Subject: Re: [U-Boot] [PATCH v2 2/4] tools: mkimage (type=kwbimage) kirkwood boot image support

<snip>

Quoted 8 lines

tools/kwbimage.c line 166

Quoted 5 lines
tools/kwbimage.c new file +4 -0
+		if (datacmd_cnt > KWBIMAGE_MAX_CONFIG ) {
+			printf("Err.. found more than max "
+				"allowed(%d) configurations\n",
+				KWBIMAGE_MAX_CONFIG);

Where is this limit coming from? Can the be arbitrarily changed, or is it some inherent linif of your image format?

This limit is coming from the BootROM header size on kirkwood.

<snip>

Quoted 9 lines

tools/mkimage.c NXTARG: ; · line 170

Quoted 7 lines
tools/mkimage.c +3 -0
@@ -164,6 +165,10 @@ NXTARG:		;
 		(lflag && (dflag || fflag)))
 		usage();
 
+	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
+		(xflag || lflag))
+		usage();

Do you promise to add support for listing the image (lflag) later?

Yes, I have already done it :-)

Quoted 19 lines

tools/mkimage.c NXTARG: ;

Quoted 4 lines
tools/mkimage.c +0 -0
 	if (!eflag) {
 		ep = addr;
 		/* If XIP, entry point must be after the U-Boot 

header */

tools/mkimage.c NXTARG: ; · line 263

Quoted 10 lines
tools/mkimage.c +5 -1
@@ -251,7 +256,12 @@ NXTARG:		;
 	 *
 	 * write dummy header, to be fixed later
 	 */
-	hdr_size = image_get_header_size ();
+	if (opt_type == IH_TYPE_KWBIMAGE) {
+		hdr = kwbimage_get_header_ptr();
+		hdr_size = kwbimage_get_header_size ();
+	} else
+		hdr_size = image_get_header_size ();

Maybe we should use a function pointer for image_get_header_size() which can be set just once, so we don't have to change the code?

<snip>

Quoted 7 lines

tools/mkimage.c NXTARG: ; · line 365

Quoted 4 lines
tools/mkimage.c +3 -0
+		sbuf.st_size += sizeof(uint32_t);
+		kwbimage_set_header (hdr, &sbuf, addr, ep, name);
+	} else {
 	checksum = crc32 (0,

Here indentation becomes wrong.

Quoted 6 lines

And I don't like this if()...else... thingy here. I think we should move the respective code into functions, and just set a pointer to the function the builds the header.

This prevents an ever growing list of if()...else...else...else... in case more image formats need to get added.

That's good idea. My initial intention was not to disturb mkimage code much. But doing this will make more easier for growing support.
I will have to restructure my code and mkimage code too.
I will do it.

Regards..
Prafulla . .

Quoted 2 lines