Skip to contentSkip to conversation

tools: mkimage: kwbimage list command support

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

lore
Share & tools
lore
#0 lore raw

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

---
Change log:
v2: braces removed on single-line statements
coding styles func() converted to func ()
used defines for error values

 common/image.c   |    4 ++--
 tools/kwbimage.c |   41 +++++++++++++++++++++++++++++++++++++++++
 tools/kwbimage.h |    6 ++++++
 tools/mkimage.c  |    7 ++++++-
 4 files changed, 55 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/kwbimage.h +6 -0
index 57db29f..d32f293 100644
@@ -55,6 +55,12 @@ enum kwbimage_cmd {
 	CMD_DDR_DATA
 };
 
+enum kwbimage_err {
+	EHDR_CSUM_NOT_MATCHED = -2,
+	MHDR_CSUM_NOT_MATCHED,
+	HDR_CSUM_MATCHED
+};
+
 /* typedefs */
 typedef struct bhr_t {
 	uint8_t blockid;		/*0     */
tools/mkimage.c +6 -1
index d77d1d6..71076fa 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
#1 lore raw

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

Dear Prafulla Wadaskar,

Quoted 1 line · In message <[email protected]> you wrote:

...

common/image.c static table_entry_t uimage_comp[] = { · line 162

Quoted 8 lines
common/image.c +1 -1
@@ -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);

When exporting this function, then please add prototype to header file.

Quoted 17 lines
common/image.c +1 -1
 #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 +0 -0
index f78d97a..9441a19 100644

tools/kwbimage.c line 36

Quoted 4 lines
tools/kwbimage.c +1 -0
@@ -33,6 +33,8 @@
 #include <unistd.h>
 #include "kwbimage.h"
 
+extern void genimg_print_size (uint32_t size);

Please delete and use prototype from header file.

Quoted 68 lines
tools/kwbimage.c +39 -0
 static struct kwb_header kwbimage_header;
 static int datacmd_cnt = 0;
 
@@ -262,3 +264,42 @@ void kwbimage_set_header (struct kwb_header *hdr, struct stat *sbuf,
 	exthdr->checkSum = kwbimage_checksum8 ((void *)exthdr,
 						sizeof(extbhr_t), 0);
 }
+
+/* -l support functions */
+int kwbimage_check_header (struct kwb_header *hdr)
+{
+	bhr_t *mhdr = &hdr->kwb_hdr;
+	extbhr_t *exthdr = &hdr->kwb_exthdr;
+	uint8_t calc_hdrcsum;
+	uint8_t calc_exthdrcsum;
+
+	calc_hdrcsum = kwbimage_checksum8 ((void *)mhdr,
+			sizeof(bhr_t) - sizeof(uint8_t), 0);
+	if (calc_hdrcsum != mhdr->checkSum)
+		return MHDR_CSUM_NOT_MATCHED;
+
+	calc_exthdrcsum = kwbimage_checksum8 ((void *)exthdr,
+			sizeof(extbhr_t) - sizeof(uint8_t), 0);
+	if (calc_hdrcsum != mhdr->checkSum)
+		return MHDR_CSUM_NOT_MATCHED;
+
+	return HDR_CSUM_MATCHED;
+}
+
+void kwbimage_print_contents (struct kwb_header *hdr) {
+	bhr_t *mhdr = &hdr->kwb_hdr;
+	char * bootdev = "Unknown";
+
+	if (mhdr->blockid == IBR_HDR_SPI_ID)
+		bootdev = "spi";
+	if (mhdr->blockid == IBR_HDR_NAND_ID)
+		bootdev = "nand";
+	if (mhdr->blockid == IBR_HDR_SATA_ID)
+		bootdev = "sata";
+
+	printf ("Image Type:   Kirkwood Boot from %s Image\n", bootdev);
+	printf ("Data Size:    ");
+	genimg_print_size (mhdr->blocksize - sizeof(uint32_t));
+	printf ("Load Address: %08x\n", mhdr->destaddr);
+	printf ("Entry Point:  %08x\n", mhdr->execaddr);
+}
tools/kwbimage.h +6 -0
index 57db29f..d32f293 100644
@@ -55,6 +55,12 @@ enum kwbimage_cmd {
 	CMD_DDR_DATA
 };
 
+enum kwbimage_err {
+	EHDR_CSUM_NOT_MATCHED = -2,
+	MHDR_CSUM_NOT_MATCHED,
+	HDR_CSUM_MATCHED
+};
+
 /* typedefs */
 typedef struct bhr_t {
 	uint8_t blockid;		/*0     */
tools/mkimage.c +0 -0
index d77d1d6..71076fa 100644

tools/mkimage.c NXTARG: ; · line 170

Quoted 6 lines
tools/mkimage.c +1 -1
@@ -166,7 +166,7 @@ NXTARG:		;
 		usage();
 
 	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
-		(xflag || lflag))
+		(xflag))
 		usage();

Thanks. Please ignore my question in patch 2/4 :-)

tools/mkimage.c NXTARG: ; · line 236

Quoted 8 lines
tools/mkimage.c +3 -0
 	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);

I think you should add error checking here. For example, when the code detects a corruption of the image (checksum error or the like), it should return an error code here, so you can use "mkimage -l" to actually verify the consistency of an image (in automated scripts).

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Unix is like a toll road on which you have to stop every 50  feet  to
pay another nickel. But hey! You only feel 5 cents poorer each time.
                 - Larry Wall in <[email protected]>
#2 lore raw

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

Quoted 20 lines

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

Dear Prafulla Wadaskar,

In message

Quoted 1 line · <[email protected]> you wrote:

...

Quoted 4 lines
common/image.c +0 -0
@@ -159,7 +159,7 @@ static table_entry_t uimage_comp[] = {
 
Quoted 8 lines

common/image.c static table_entry_t uimage_comp[] = { · line 161

Quoted 2 lines
common/image.c +0 -0
 uint32_t crc32 (uint32_t, const unsigned char *, uint);  uint32_t 
 crc32_wd (uint32_t, const unsigned char *, uint, uint); 

-static void

common/image.c static table_entry_t uimage_comp[] = { · line 163

Quoted 2 lines
common/image.c +1 -0
 genimg_print_size (uint32_t size);
+void genimg_print_size (uint32_t size);

When exporting this function, then please add prototype to header file.

I have followed function crc32, I will do it.
Shall I do it for crc32 and other functions too? I should not disturb them?

Quoted 20 lines
Quoted 3 lines
common/image.c +0 -0
 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || 

defined(USE_HOSTCC) static void genimg_print_time (time_t

timestamp);

Quoted 16 lines

#endif @@ -473,7 +473,7 @@ void memmove_wd (void *to, void *from, size_t len, ulong chunksz) } #endif /* !USE_HOSTCC */

common/image.c +1 -1
-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 index renamed from tools/kwbimage.c +0 -0

f78d97a..9441a19 100644

tools/kwbimage.c +0 -0
@@ -33,6 +33,8 @@
 #include <unistd.h>
 #include "kwbimage.h"
 
Quoted 3 lines

tools/kwbimage.c line 36

Quoted 1 line
tools/kwbimage.c +1 -0
+extern void genimg_print_size (uint32_t size);

Please delete and use prototype from header file.

Same comments above

Quoted 72 lines

tools/kwbimage.c line 37

Quoted 2 lines
tools/kwbimage.c +0 -0
 static struct kwb_header kwbimage_header;  static int 

datacmd_cnt =

tools/kwbimage.c void kwbimage_set_header (struct

Quoted 3 lines
tools/kwbimage.c +0 -0
 0;
 
@@ -262,3 +264,42 @@ void kwbimage_set_header (struct 

kwb_header *hdr, struct stat *sbuf,

tools/mkimage.c index

Quoted 58 lines
tools/kwbimage.c +37 -0
 	exthdr->checkSum = kwbimage_checksum8 ((void *)exthdr,
 						sizeof(extbhr_t), 0);
 }
+
+/* -l support functions */
+int kwbimage_check_header (struct kwb_header *hdr) {
+	bhr_t *mhdr = &hdr->kwb_hdr;
+	extbhr_t *exthdr = &hdr->kwb_exthdr;
+	uint8_t calc_hdrcsum;
+	uint8_t calc_exthdrcsum;
+
+	calc_hdrcsum = kwbimage_checksum8 ((void *)mhdr,
+			sizeof(bhr_t) - sizeof(uint8_t), 0);
+	if (calc_hdrcsum != mhdr->checkSum)
+		return MHDR_CSUM_NOT_MATCHED;
+
+	calc_exthdrcsum = kwbimage_checksum8 ((void *)exthdr,
+			sizeof(extbhr_t) - sizeof(uint8_t), 0);
+	if (calc_hdrcsum != mhdr->checkSum)
+		return MHDR_CSUM_NOT_MATCHED;
+
+	return HDR_CSUM_MATCHED;
+}
+
+void kwbimage_print_contents (struct kwb_header *hdr) {
+	bhr_t *mhdr = &hdr->kwb_hdr;
+	char * bootdev = "Unknown";
+
+	if (mhdr->blockid == IBR_HDR_SPI_ID)
+		bootdev = "spi";
+	if (mhdr->blockid == IBR_HDR_NAND_ID)
+		bootdev = "nand";
+	if (mhdr->blockid == IBR_HDR_SATA_ID)
+		bootdev = "sata";
+
+	printf ("Image Type:   Kirkwood Boot from %s Image\n", bootdev);
+	printf ("Data Size:    ");
+	genimg_print_size (mhdr->blocksize - sizeof(uint32_t));
+	printf ("Load Address: %08x\n", mhdr->destaddr);
+	printf ("Entry Point:  %08x\n", mhdr->execaddr); }
tools/kwbimage.h index renamed from tools/kwbimage.h +0 -0

57db29f..d32f293 100644

tools/kwbimage.h +6 -0
@@ -55,6 +55,12 @@ enum kwbimage_cmd {
 	CMD_DDR_DATA
 };
 
+enum kwbimage_err {
+	EHDR_CSUM_NOT_MATCHED = -2,
+	MHDR_CSUM_NOT_MATCHED,
+	HDR_CSUM_MATCHED
+};
+
 /* typedefs */
 typedef struct bhr_t {
 	uint8_t blockid;		/*0     */
tools/mkimage.c index renamed from tools/mkimage.c +0 -0

d77d1d6..71076fa

Quoted 6 lines

100644

tools/mkimage.c +0 -0
@@ -166,7 +166,7 @@ NXTARG:		;
 		usage();
 
Quoted 6 lines

tools/mkimage.c NXTARG: ; · line 170

Quoted 4 lines
tools/mkimage.c +1 -1
 	if (((argc != 1) && (opt_type == IH_TYPE_KWBIMAGE)) &&
-		(xflag || lflag))
+		(xflag))
 		usage();

Thanks. Please ignore my question in patch 2/4 :-)

That's pleasure, sometime main objective restricts us to do lot more things.

Quoted 10 lines

tools/mkimage.c NXTARG: ; · line 234

Quoted 7 lines
tools/mkimage.c +1 -0
 	if (!eflag) {
@@ -231,6 +231,11 @@ NXTARG:		;
 			exit (EXIT_FAILURE);
 		}
 
+		if (!(kwbimage_check_header ((struct kwb_header 

*)ptr))) {

tools/mkimage.c NXTARG: ; · line 235

Quoted 1 line
tools/mkimage.c +1 -0
+			kwbimage_print_contents ((struct 

kwb_header *)ptr);

Quoted 7 lines

tools/mkimage.c NXTARG: ; · line 236

Quoted 1 line
tools/mkimage.c +1 -0
+			exit (EXIT_SUCCESS);

I think you should add error checking here. For example, when the code detects a corruption of the image (checksum error or the like), it should return an error code here, so you can use "mkimage -l" to actually verify the consistency of an image (in automated scripts).

Currently mkimage checks first kwbimage header followed by ftd/fit header checks
In that case returning an error code will not be useful
On the other hand,
we should detect filename extension (img/kwb) from input file and then only do relevant image checks.

Filenames can be altered so I think current implementation is okay. What do you think?

Regards..
Prafulla . .

Quoted 15 lines

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: 
wd at denx.de Unix is like a toll road on which you have to stop 
every 50  feet  to pay another nickel. But hey! You only feel 
5 cents poorer each time.
                 - Larry Wall in <[email protected]>
#3 lore raw

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

Dear Prafulla Wadaskar,

Quoted 4 lines · In message <[email protected]>…
Quoted 3 lines

When exporting this function, then please add prototype to header file.

I have followed function crc32, I will do it.

Ah, I see.

Quoted 1 line

Shall I do it for crc32 and other functions too? I should not disturb them?

If you would be so kind and clean up these other function declarations as well, that would be much appreciated. Thanks in advance.

...

Quoted 11 lines
Quoted 11 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		if (!(kwbimage_check_header ((struct kwb_header 

*)ptr))) {

Review

Quoted 1 line
(quoted diff) +1 -0
+			kwbimage_print_contents ((struct 

kwb_header *)ptr);

tools/mkimage.c NXTARG: ; · line 236

Quoted 1 line
tools/mkimage.c +1 -0
+			exit (EXIT_SUCCESS);

I think you should add error checking here. For example, when the code detects a corruption of the image (checksum error or the like), it should return an error code here, so you can use "mkimage -l" to actually verify the consistency of an image (in automated scripts).

Quoted 3 lines

Currently mkimage checks first kwbimage header followed by ftd/fit header c hecks
In that case returning an error code will not be useful

I don't understand what you mean here. Any corruption of an image should be detected and signalled to the caller by a non-zero return code of the mkimage command.

Quoted 3 lines

On the other hand,
we should detect filename extension (img/kwb) from input file and then only
do relevant image checks.

NO!! Never do anything like that. File names don't matter at all. We're not Windows, where just naming your virus code as "document.txt" will make it look harmless. Only the content matters - if the file is called "image.foo" or just "foo" or "sjjsdhashd" does not matter at all.

Quoted 2 lines

Filenames can be altered so I think current implementation is okay. What do you think?

Filenames must not play any role.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Sometimes a feeling is all we humans have to go on.
	-- Kirk, "A Taste of Armageddon", stardate 3193.9
#4 lore raw

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

Quoted 22 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Wednesday, July 22, 2009 4:11 PM
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Ashish Karkare; Prabhanjan Sarnaik
Subject: Re: [U-Boot] [PATCH v2 3/4] tools: mkimage: kwbimage list command support

Quoted 8 lines
Quoted 8 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		if (!(kwbimage_check_header ((struct kwb_header

*)ptr))) {

Review

Quoted 1 line
(quoted diff) +1 -0
+			kwbimage_print_contents ((struct

kwb_header *)ptr);

tools/mkimage.c NXTARG: ; · line 236

Quoted 1 line
tools/mkimage.c +1 -0
+			exit (EXIT_SUCCESS);

I think you should add error checking here. For example, when the code detects a corruption of the image (checksum error or

the like),

Quoted 1 line
Quoted 1 line

it should return an error code here, so you can use

"mkimage -l" to

Quoted 1 line
Quoted 1 line

actually verify the consistency of an image (in automated

Quoted 8 lines

scripts).

Quoted 2 lines

Currently mkimage checks first kwbimage header followed by ftd/fit header c hecks In that case returning an error code will

not be useful

I don't understand what you mean here. Any corruption of an image should be detected and signalled to the caller by a non-zero return code of the mkimage command.

My answer was only related to kwbimage point of view
your comment is more towards existing code cleanup, yes it returns success even though header check fails I will do it as a part of mkimage code cleanup.

Thanks and regards..
Prafulla . .