tools: mkimage: hdr_size used to facilitate customized support
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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
PATCH 3/4 tools: mkimage: kwbimage list command support
Quoted 1 line · On Tuesday 21 July 2009 23:25:50 Prafulla Wadaskar wrote:
Signed-off-by Prafulla Wadaskar <[email protected]>
Just some quick nitpicking comment below.
Quoted 49 lines
--- common/image.c | 4 ++-- tools/kwbimage.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/mkimage.c | 7 ++++++- 3 files changed, 49 insertions(+), 3 deletions(-)common/image.c +2
-2@@ -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 +6
-0@@ -33,6 +33,8 @@#include <unistd.h> #include "kwbimage.h" +extern void genimg_print_size (uint32_t size); +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) +{
tools/kwbimage.c void kwbimage_set_header (struct kwb_header *hdr, · line 280
Quoted 10 lines
tools/kwbimage.c +10
-0+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 -1 ;/* main header csum not matched */ + }
No braces needed on single-line statements.
tools/kwbimage.c void kwbimage_set_header (struct kwb_header *hdr, struct stat *sbuf, · line 284
Quoted 4 lines
tools/kwbimage.c +4
-0+ calc_exthdrcsum =kwbimage_checksum8 ((void *)exthdr, +sizeof (extbhr_t) -sizeof (uint8_t ),0 ); +if (calc_hdrcsum != mhdr->checkSum) { +return -2 ;/* ext header csum not matched */
Perhaps use some defines for those errors (-1, -2 etc).
tools/kwbimage.c void kwbimage_set_header (struct kwb_header *hdr, · line 285
Quoted 1 line
tools/kwbimage.c +1
-0+ }
Again, no braces here.
Quoted 9 lines
tools/kwbimage.c +9
-0+return 0 ; +} + +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" ;
tools/kwbimage.c void kwbimage_set_header (struct kwb_header *hdr, struct stat *sbuf, · line 304
Quoted 10 lines
tools/kwbimage.c +10
-0+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);
You are mixing coding styles here. func() vs. func () (space before "("). Please use only one style per file.
Thanks.
Best regards,
Stefan
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================