[U-Boot] [PATCH 3/8] tools: mkimage: Move image header code to image specific files

Prafulla Wadaskar prafulla at marvell.com
Tue Jul 28 20:04:25 CEST 2009


This is second step towards cleaning mkimage code for kwbimage
support in clean way. In this patch-
1. The image_get_header_size function call is replaced by sizeof(image_header_t)
   in default_image.c
2. image header code moved form mkimage.c to default_image .c

Signed-off-by: Prafulla Wadaskar <prafulla at marvell.com>
---
 tools/default_image.c |   22 ++++++++++++++++++----
 tools/default_image.h |    1 +
 tools/mkimage.c       |   24 ++++++++++++------------
 tools/mkimage.h       |    8 ++++++++
 4 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/tools/default_image.c b/tools/default_image.c
index 45afde1..e1a9bc7 100644
--- a/tools/default_image.c
+++ b/tools/default_image.c
@@ -29,6 +29,20 @@
 #include <image.h>
 #include "default_image.h"
 
+image_header_t header;
+
+/*
+ * Default image parameters
+ */
+struct image_type_params defimage_params = {
+	.header_size = sizeof(image_header_t),
+	.hdr = (void*)&header,
+};
+
+void *image_get_tparams (void){
+	return (void *)&defimage_params;
+}
+
 int image_check_params (struct mkimage_params *params)
 {
 	return	((params->dflag && (params->fflag || params->lflag)) ||
@@ -100,13 +114,13 @@ void image_set_header (char *ptr, struct stat *sbuf,
 	image_header_t * 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 + sizeof(image_header_t)),
+			sbuf->st_size - sizeof(image_header_t));
 
 	/* 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 - sizeof(image_header_t));
 	image_set_load (hdr, params->addr);
 	image_set_ep (hdr, params->ep);
 	image_set_dcrc (hdr, checksum);
@@ -117,7 +131,7 @@ void image_set_header (char *ptr, struct stat *sbuf,
 
 	image_set_name (hdr, params->imagename);
 
-	checksum = crc32 (0, (const char *)hdr, image_get_header_size ());
+	checksum = crc32 (0, (const char *)hdr, sizeof(image_header_t));
 
 	image_set_hcrc (hdr, checksum);
 }
diff --git a/tools/default_image.h b/tools/default_image.h
index 6ebc689..2311ede 100644
--- a/tools/default_image.h
+++ b/tools/default_image.h
@@ -25,6 +25,7 @@
 #ifndef _DEFAULT_IMAGE_H_
 #define _DEFAULT_IMAGE_H_
 
+void *image_get_tparams (void);
 int image_check_params (struct mkimage_params *params);
 int image_verify_header (char *ptr, int image_size,
 			struct mkimage_params *params);
diff --git a/tools/mkimage.c b/tools/mkimage.c
index 66d6c8e..d1636d8 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -49,9 +49,6 @@ struct mkimage_params params = {
 	.cmdname = "",
 };
 
-image_header_t header;
-image_header_t *hdr = &header;
-
 int
 main (int argc, char **argv)
 {
@@ -59,6 +56,7 @@ main (int argc, char **argv)
 	struct stat sbuf;
 	unsigned char *ptr;
 	int retval;
+	struct image_type_params *tparams = image_get_tparams ();
 
 	params.cmdname = *argv;
 
@@ -163,7 +161,7 @@ NXTARG:		;
 		params.ep = params.addr;
 		/* If XIP, entry point must be after the U-Boot header */
 		if (params.xflag)
-			params.ep += image_get_header_size ();
+			params.ep += tparams->header_size;
 	}
 
 	/*
@@ -171,11 +169,11 @@ NXTARG:		;
 	 * the size of the U-Boot header.
 	 */
 	if (params.xflag) {
-		if (params.ep != params.addr + image_get_header_size ()) {
+		if (params.ep != params.addr + tparams->header_size) {
 			fprintf (stderr,
 				"%s: For XIP, the entry point must be the load addr + %lu\n",
 				params.cmdname,
-				(unsigned long)image_get_header_size ());
+				(unsigned long)tparams->header_size);
 			exit (EXIT_FAILURE);
 		}
 	}
@@ -209,7 +207,7 @@ NXTARG:		;
 			exit (EXIT_FAILURE);
 		}
 
-		if ((unsigned)sbuf.st_size < image_get_header_size ()) {
+		if ((unsigned)sbuf.st_size < tparams->header_size) {
 			fprintf (stderr,
 				"%s: Bad size: \"%s\" is no valid image\n",
 				params.cmdname, params.imagefile);
@@ -247,9 +245,10 @@ NXTARG:		;
 	 *
 	 * write dummy header, to be fixed later
 	 */
-	memset (hdr, 0, image_get_header_size ());
+	memset (tparams->hdr, 0, tparams->header_size);
 
-	if (write(ifd, hdr, image_get_header_size ()) != image_get_header_size ()) {
+	if (write(ifd, tparams->hdr, tparams->header_size)
+					!= tparams->header_size) {
 		fprintf (stderr, "%s: Write error on %s: %s\n",
 			params.cmdname, params.imagefile, strerror(errno));
 		exit (EXIT_FAILURE);
@@ -366,6 +365,7 @@ copy_file (int ifd, const char *datafile, int pad)
 	int zero = 0;
 	int offset = 0;
 	int size;
+	struct image_type_params *tparams = image_get_tparams ();
 
 	if (params.vflag) {
 		fprintf (stderr, "Adding Image %s\n", datafile);
@@ -398,14 +398,14 @@ copy_file (int ifd, const char *datafile, int pad)
 		 * reserved for it.
 		 */
 
-		if ((unsigned)sbuf.st_size < image_get_header_size ()) {
+		if ((unsigned)sbuf.st_size < tparams->header_size) {
 			fprintf (stderr,
 				"%s: Bad size: \"%s\" is too small for XIP\n",
 				params.cmdname, datafile);
 			exit (EXIT_FAILURE);
 		}
 
-		for (p = ptr; p < ptr + image_get_header_size (); p++) {
+		for (p = ptr; p < ptr + tparams->header_size; p++) {
 			if ( *p != 0xff ) {
 				fprintf (stderr,
 					"%s: Bad file: \"%s\" has invalid buffer for XIP\n",
@@ -414,7 +414,7 @@ copy_file (int ifd, const char *datafile, int pad)
 			}
 		}
 
-		offset = image_get_header_size ();
+		offset = tparams->header_size;
 	}
 
 	size = sbuf.st_size - offset;
diff --git a/tools/mkimage.h b/tools/mkimage.h
index 0418644..3e94911 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -69,4 +69,12 @@ struct mkimage_params {
 	char *cmdname;
 };
 
+/*
+ * These are image type specific variables
+ */
+struct image_type_params {
+	uint32_t header_size;
+	void *hdr;
+};
+
 #endif /* _MKIIMAGE_H_ */
-- 
1.5.3.3



More information about the U-Boot mailing list