Skip to contentSkip to conversation

tools: mkimage : bugfix returns correct value for list command

PATCH Superseded Prafulla Wadaskar 2 participants 20 messages Jul 28, 2009 – Aug 10, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 tools: mkimage : bugfix returns correct value for list command

List command always return "EXIT_SUCCESS" even in case of failure by any means.

This patch return 0 if list command is sucessful, returns negative value reported by check_header functions

---
 tools/mkimage.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)
tools/mkimage.c +13 -14
index 02cdb95..b7b383a 100644
@@ -28,7 +28,7 @@
 extern	unsigned long	crc32 (unsigned long crc, const char *buf, unsigned int len);
 static	void		copy_file (int, const char *, int);
 static	void		usage (void);
-static	void		image_verify_header (char *, int);
+static	int		image_verify_header (char *, int);
 static	void		fit_handle_file (void);
 
 char	*datafile;
@@ -60,6 +60,7 @@ main (int argc, char **argv)
 	struct stat sbuf;
 	unsigned char *ptr;
 	char *name = "";
+	int retval;
 
 	cmdname = *argv;
 
@@ -219,24 +220,21 @@ NXTARG:		;
 			exit (EXIT_FAILURE);
 		}
 
-		if (fdt_check_header (ptr)) {
-			/* old-style image */
-			image_verify_header ((char *)ptr, sbuf.st_size);
-			image_print_contents ((image_header_t *)ptr);
-		} else {
-			/* FIT image */
+		if (!(retval = fdt_check_header (ptr)))	/* FIT image */
 			fit_print_contents (ptr);
-		}
+		else if (!(retval = image_verify_header (
+			(char *)ptr, sbuf.st_size))) /* old-style image */
+			image_print_contents ((image_header_t *)ptr);
 
 		(void) munmap((void *)ptr, sbuf.st_size);
 		(void) close (ifd);
 
-		exit (EXIT_SUCCESS);
+		exit (retval);
 	} else if (fflag) {
 		/* Flattened Image Tree (FIT) format  handling */
 		debug ("FIT format handling\n");
 		fit_handle_file ();
-		exit (EXIT_SUCCESS);
+		exit (retval);
 	}
 
 	/*
@@ -480,7 +478,7 @@ usage ()
 	exit (EXIT_FAILURE);
 }
 
-static void
+static int
 image_verify_header (char *ptr, int image_size)
 {
 	int len;
@@ -500,7 +498,7 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: Bad Magic Number: \"%s\" is no valid image\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADMAGIC;
 	}
 
 	data = (char *)hdr;
@@ -513,7 +511,7 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: ERROR: \"%s\" has bad header checksum!\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADSTATE;
 	}
 
 	data = ptr + sizeof(image_header_t);
@@ -523,8 +521,9 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: ERROR: \"%s\" has corrupted data!\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADSTRUCTURE;
 	}
+	return 0;
 }
 
 /**
Signature · 1 line
1.5.3.3
#1 lore raw

PATCH 2/8 tools: mkimage: code abstraction generic and image specific

This is first step towards cleaning mkimage code for kwbimage support in clean way. Current mkimage code is very specific to uimge generation whereas the same framework can be used to generate other image types like kwbimage.
For this, the architecture of mkimage code need to modified.

Here is the brief plan for the same:-
a) Abstract image specific code to saperate file (this patch)
b) Move image header code from mkimage.c to respective image specific code
c) Implement callback function for image specific functions
d) Add kwbimage type support to this framework

In this patch-
1. Image specific code abstracted from mkimage.c to default_image.c/h to make mkimage code more generic
2. struct mkimage_params introduced to pass basic mkimage specific flags and variables to image specific functions

---
 tools/Makefile        |    4 +
 tools/default_image.c |  227 ++++++++++++++++++++++++++++++
 tools/default_image.h |   36 +++++
 tools/mkimage.c       |  368 ++++++++++++++-----------------------------------
 tools/mkimage.h       |   25 ++++
 5 files changed, 394 insertions(+), 266 deletions(-)
 create mode 100644 tools/default_image.c
 create mode 100644 tools/default_image.h
tools/Makefile +4 -0
index b5a1e39..6ef15d9 100644
@@ -171,6 +171,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 	$(STRIP) $@
 
 $(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
+			$(obj)default_image.o \
 			$(obj)sha1.o $(LIBFDT_OBJS) $(obj)os_support.o
 	$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 	$(STRIP) $@
@@ -203,6 +204,9 @@ $(obj)bin2header$(SFX): $(obj)bin2header.o
 $(obj)image.o: $(SRCTREE)/common/image.c
 	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
+$(obj)default_image.o: $(SRCTREE)/tools/default_image.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
 $(obj)mkimage.o: $(SRCTREE)/tools/mkimage.c
 	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
tools/default_image.c new file +227 -0

227 lines not on this page · raw message

tools/default_image.h new file +36 -0
new file mode 100644
index 0000000..6ebc689
@@ -0,0 +1,36 @@
+/*
+ * (C) Copyright 2009
+ * Marvell Semiconductor <www.marvell.com>
+ * Written-by: Prafulla Wadaskar <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#ifndef _DEFAULT_IMAGE_H_
+#define _DEFAULT_IMAGE_H_
+
+int image_check_params (struct mkimage_params *params);
+int image_verify_header (char *ptr, int image_size,
+			struct mkimage_params *params);
+void image_print_header (char *ptr);
+void image_set_header (char *ptr, struct stat *sbuf,
+			struct mkimage_params *params);
+void fit_handle_file (struct mkimage_params *params);
+
+#endif /* _DEFAULT_IMAGE_H_ */
tools/mkimage.c +102 -266

626 lines not on this page · raw message

tools/mkimage.h +25 -0
index 70c53ad..0418644 100644
@@ -20,6 +20,9 @@
  * MA 02111-1307 USA
  */
 
+#ifndef _MKIIMAGE_H_
+#define _MKIIMAGE_H_
+
 #include "os_support.h"
 #include <errno.h>
 #include <fcntl.h>
@@ -45,3 +48,25 @@
 #define MKIMAGE_DEFAULT_DTC_OPTIONS	"-I dts -O dtb -p 500"
 #define MKIMAGE_MAX_DTC_CMDLINE_LEN	512
 #define MKIMAGE_DTC			"dtc"   /* assume dtc is in $PATH */
+
+struct mkimage_params {
+	int dflag;
+	int eflag;
+	int fflag;
+	int lflag;
+	int vflag;
+	int xflag;
+	int opt_os;
+	int opt_arch;
+	int opt_type;
+	int opt_comp;
+	char *opt_dtc;
+	uint32_t addr;
+	uint32_t ep;
+	char *imagename;
+	char *datafile;
+	char *imagefile;
+	char *cmdname;
+};
+
+#endif /* _MKIIMAGE_H_ */
Signature · 1 line
1.5.3.3
#2 lore raw

PATCH 3/8 tools: mkimage: Move image header code to image specific files

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

---
 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(-)
tools/default_image.c +18 -4
index 45afde1..e1a9bc7 100644
@@ -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);
 }
tools/default_image.h +1 -0
index 6ebc689..2311ede 100644
@@ -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);
tools/mkimage.c +12 -12
index 66d6c8e..d1636d8 100644
@@ -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;
tools/mkimage.h +8 -0
index 0418644..3e94911 100644
@@ -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_ */
Signature · 1 line
1.5.3.3
#3 lore raw

PATCH 4/8 tools: mkimage: Implemented callback function for default image support

This is Third step towards cleaning mkimage code for kwbimage
support in clean way. In this patch-
1. callback functions are used in mkimage.c those are defined in defaut_image.c for currently supported images.
2. scan loop implemented for image header verify and print

---
 include/image.h       |    1 +
 tools/default_image.c |   38 +++++++++++++++++++++++++++++++---
 tools/default_image.h |    3 +-
 tools/mkimage.c       |   53 ++++++++++++++++++++++++++++++++++++++++--------
 tools/mkimage.h       |   15 +++++++++++++
 5 files changed, 96 insertions(+), 14 deletions(-)
include/image.h +1 -0
index beb3a16..b519e5e 100644
@@ -155,6 +155,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_MAX		IH_TYPE_FLATDT	/* Max supported types  */
 
 /*
  * Compression Types
tools/default_image.c +34 -4
index e1a9bc7..78e29f2 100644
@@ -37,6 +37,10 @@ image_header_t header;
 struct image_type_params defimage_params = {
 	.header_size = sizeof(image_header_t),
 	.hdr = (void*)&header,
+	.check_params = image_check_params,
+	.verify_header = image_verify_header,
+	.print_header = image_print_header,
+	.set_header = image_set_header,
 };
 
 void *image_get_tparams (void){
@@ -101,12 +105,10 @@ image_verify_header (char *ptr, int image_size,
 
 void image_print_header (char *ptr)
 {
-	image_header_t * hdr = (image_header_t *)ptr;
-
-	image_print_contents (hdr);
+	image_print_contents ((image_header_t *)ptr);
 }
 
-void image_set_header (char *ptr, struct stat *sbuf,
+void image_set_header (char *ptr, struct stat *sbuf, int ifd,
 				struct mkimage_params *params)
 {
 	uint32_t checksum;
@@ -136,6 +138,34 @@ void image_set_header (char *ptr, struct stat *sbuf,
 	image_set_hcrc (hdr, checksum);
 }
 
+/*
+ * FIT image support
+ */
+int
+fitimage_verify_header (char *ptr, int image_size,
+			struct mkimage_params *params)
+{
+	fdt_check_header ((void *)ptr);
+}
+
+void fitimage_print_header (char *ptr)
+{
+	fit_print_contents ((void *)ptr);
+}
+
+struct image_type_params fitimage_params = {
+	.header_size = sizeof(image_header_t),
+	.hdr = (void*)&header,
+	.check_params = image_check_params,
+	.verify_header = fitimage_verify_header,
+	.print_header = fitimage_print_header,
+	.set_header = image_set_header,
+};
+
+void *fitimage_get_tparams (void){
+	return (void *)&fitimage_params;
+}
+
 /**
  * fit_handle_file - main FIT file processing function
  *
tools/default_image.h +2 -1
index 2311ede..ba95521 100644
@@ -25,12 +25,13 @@
 #ifndef _DEFAULT_IMAGE_H_
 #define _DEFAULT_IMAGE_H_
 
+void *fitimage_get_tparams (void);
 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);
 void image_print_header (char *ptr);
-void image_set_header (char *ptr, struct stat *sbuf,
+void image_set_header (char *ptr, struct stat *sbuf, int ifd,
 			struct mkimage_params *params);
 void fit_handle_file (struct mkimage_params *params);
 
tools/mkimage.c +44 -9

92 lines not on this page · raw message

tools/mkimage.h +15 -0
index 3e94911..a9f20a7 100644
@@ -71,10 +71,25 @@ struct mkimage_params {
 
 /*
  * These are image type specific variables
+ * and callback functions
  */
 struct image_type_params {
 	uint32_t header_size;
 	void *hdr;
+	int (*check_params) (struct mkimage_params *);
+	int (*verify_header) (char *, int, struct mkimage_params *);
+	void (*print_header) (char *);
+	void (*set_header) (char *, struct stat *, int,
+					struct mkimage_params *);
 };
 
+/*
+ * Image type specific function pointers list
+ */
+struct image_functions {
+	void *	(*get_tparams) (void);
+};
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 #endif /* _MKIIMAGE_H_ */
Signature · 1 line
1.5.3.3
#4 lore raw

PATCH 5/8 tools: mkimage: Making genimg_print_size API global

Currently it is used by image.c only
This API can be used by additional mkimage types supports for ex. kwbimage, to use it the API is made global

---
 common/image.c  |    3 +--
 include/image.h |    1 +
 2 files changed, 2 insertions(+), 2 deletions(-)
common/image.c +1 -2
index e22c974..232348c 100644
@@ -158,7 +158,6 @@ 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);
 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
 static void genimg_print_time (time_t timestamp);
 #endif
@@ -472,7 +471,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);
include/image.h +1 -0
index b519e5e..88a13ab 100644
@@ -300,6 +300,7 @@ int genimg_get_comp_id (const char *name);
 #define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
 #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
 
+void genimg_print_size (uint32_t size);
 int genimg_get_format (void *img_addr);
 int genimg_has_config (bootm_headers_t *images);
 ulong genimg_get_image (ulong img_addr);
Signature · 1 line
1.5.3.3
#5 lore raw

PATCH 6/8 tools: mkimage: Making table_entry code global

1. get_table_entry_id API made global
2. get_table_entry_name API made global
3. typedef table_entry_t moved to image.h

Currently it is used by image.c only
These APIs can be used by additional mkimage types supports for ex. kwbimage, to use it the API is made global

---
 common/image.c  |   10 ++--------
 include/image.h |   10 ++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
common/image.c +2 -8
index 232348c..8cf675d 100644
@@ -74,12 +74,6 @@ static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
 #include <image.h>
 #endif /* !USE_HOSTCC*/
 
-typedef struct table_entry {
-	int	id;		/* as defined in image.h	*/
-	char	*sname;		/* short (input) name		*/
-	char	*lname;		/* long (output) name		*/
-} table_entry_t;
-
 static table_entry_t uimage_arch[] = {
 	{	IH_ARCH_INVALID,	NULL,		"Invalid ARCH",	},
 	{	IH_ARCH_ALPHA,		"alpha",	"Alpha",	},
@@ -513,7 +507,7 @@ static void genimg_print_time (time_t timestamp)
  *     long entry name if translation succeeds
  *     msg otherwise
  */
-static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
+char *get_table_entry_name (table_entry_t *table, char *msg, int id)
 {
 	for (; table->id >= 0; ++table) {
 		if (table->id == id)
@@ -560,7 +554,7 @@ const char *genimg_get_comp_name (uint8_t comp)
  *     entry id if translation succeeds
  *     -1 otherwise
  */
-static int get_table_entry_id (table_entry_t *table,
+int get_table_entry_id (table_entry_t *table,
 		const char *table_name, const char *name)
 {
 	table_entry_t *t;
include/image.h +10 -0
index 88a13ab..f119cee 100644
@@ -168,6 +168,15 @@
 #define IH_MAGIC	0x27051956	/* Image Magic Number		*/
 #define IH_NMLEN		32	/* Image Name Length		*/
 
+typedef struct table_entry {
+	int	id;		/* as defined in image.h	*/
+	char	*sname;		/* short (input) name		*/
+	char	*lname;		/* long (output) name		*/
+} table_entry_t;
+
+int get_table_entry_id (table_entry_t *table,
+		const char *table_name, const char *name);
+
 /*
  * Legacy format image header,
  * all data in network byte order (aka natural aka bigendian).
@@ -300,6 +309,7 @@ int genimg_get_comp_id (const char *name);
 #define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
 #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
 
+char *get_table_entry_name (table_entry_t *table, char *msg, int id);
 void genimg_print_size (uint32_t size);
 int genimg_get_format (void *img_addr);
 int genimg_has_config (bootm_headers_t *images);
Signature · 1 line
1.5.3.3
#6 lore raw

PATCH 7/8 tools: mkimage: Add: Kirkwood Boot Image support (kwbimage)

This is Third step towards cleaning mkimage code for kwbimage support in clean way.

This patch adds type kwbimabe support for mkimage For more details refer docs/README.kwbimage

This patch is tested with Wheevaplub board

---
 Makefile            |    5 +
 common/image.c      |    1 +
 doc/README.kwbimage |   93 +++++++++++++
 include/image.h     |    3 +-
 tools/Makefile      |    4 +
 tools/kwbimage.c    |  364 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/kwbimage.h    |  118 +++++++++++++++++
 tools/mkimage.c     |    4 +-
 8 files changed, 590 insertions(+), 2 deletions(-)
 create mode 100644 doc/README.kwbimage
 create mode 100644 tools/kwbimage.c
 create mode 100644 tools/kwbimage.h
Makefile +5 -0
index ef535ed..336dcd4 100644
@@ -313,6 +313,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
 
@@ -3660,6 +3664,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 8cf675d..10b5deb 100644
@@ -139,6 +139,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 +2 -1
index f119cee..513f285 100644
@@ -155,7 +155,8 @@
 #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_MAX		IH_TYPE_FLATDT	/* Max supported types  */
+#define IH_TYPE_KWBIMAGE	9	/* Kirkwood Boot Image		*/
+#define IH_TYPE_MAX		IH_TYPE_KWBIMAGE
 
 /*
  * Compression Types
tools/Makefile +4 -0
index 6ef15d9..07a1c27 100644
@@ -172,6 +172,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 
 $(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
 			$(obj)default_image.o \
+			$(obj)kwbimage.o \
 			$(obj)sha1.o $(LIBFDT_OBJS) $(obj)os_support.o
 	$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 	$(STRIP) $@
@@ -207,6 +208,9 @@ $(obj)image.o: $(SRCTREE)/common/image.c
 $(obj)default_image.o: $(SRCTREE)/tools/default_image.c
 	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
+$(obj)kwbimage.o: $(SRCTREE)/tools/kwbimage.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
 $(obj)mkimage.o: $(SRCTREE)/tools/mkimage.c
 	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
tools/kwbimage.c new file +364 -0

364 lines not on this page · raw message

tools/kwbimage.h new file +118 -0

118 lines not on this page · raw message

tools/mkimage.c +3 -1
index 3a3cb19..7e29610 100644
@@ -25,6 +25,7 @@
 #include "mkimage.h"
 #include <image.h>
 #include "default_image.h"
+#include "kwbimage.h"
 
 static void copy_file(int, const char *, int);
 static void usage(void);
@@ -59,6 +60,7 @@ static struct image_functions image_ftable[] = {
 	{image_get_tparams,},	/* for IH_TYPE_SCRIPT */
 	{image_get_tparams,},	/* for IH_TYPE_STANDALONE */
 	{fitimage_get_tparams,},	/* for IH_TYPE_FLATDT */
+	{kwbimage_get_tparams,},        /* for IH_TYPE_KWBIMAGE */
 };
 
 int
@@ -111,7 +113,7 @@ main (int argc, char **argv)
 					(params.opt_type =
 					genimg_get_type_id (*++argv)) < 0)
 					usage ();
-				if (image_ftable_size <= params.opt_type) {
+				if (image_ftable_size < params.opt_type) {
 					fprintf (stderr,
 						"%s: Unsupported image type %s\n",
 						params.cmdname, *argv);
Signature · 1 line
1.5.3.3
#7 lore raw

PATCH v4 8/8 Kirkwood: Sheevaplug: kwimage configuration

---
Change log:
v2: updated as per review feedback for v1

v3: some white spaces removed

v4: tuned as per new kwbimage parsing (DATA command added for register setup)

 board/Marvell/sheevaplug/config.mk    |    3 +
 board/Marvell/sheevaplug/kwbimage.cfg |  162 +++++++++++++++++++++++++++++++++
 2 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 board/Marvell/sheevaplug/kwbimage.cfg
board/Marvell/sheevaplug/config.mk +3 -0
index a4ea769..2bd9f79 100644
@@ -23,3 +23,6 @@
 #
 
 TEXT_BASE = 0x00600000
+
+# Kirkwood Boot Image configuration file
+KWD_CONFIG = $(SRCTREE)/board/$(BOARDDIR)/kwbimage.cfg
board/Marvell/sheevaplug/kwbimage.cfg new file +162 -0

162 lines not on this page · raw message

Signature · 1 line
1.5.3.3
#8 lore raw

PATCH 7/8 tools: mkimage: Add: Kirkwood Boot Image support (kwbimage)

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

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

This is Third step towards cleaning mkimage code for kwbimage support in clean way.

Umm... The "Third step" was already in patch 4/8. I guess you have to check your commit messages better...

tools/Makefile $(obj)img2srec$(SFX): $(obj)img2srec.o · line 176

Quoted 10 lines
tools/Makefile +1 -0
index 6ef15d9..07a1c27 100644
@@ -172,6 +172,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 
 $(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
 			$(obj)default_image.o \
+			$(obj)kwbimage.o \
 			$(obj)sha1.o $(LIBFDT_OBJS) $(obj)os_support.o

Please keep sorted.

Quoted 33 lines
tools/kwbimage.c new file +30 -0
@@ -0,0 +1,364 @@
+/*
+ * (C) Copyright 2008
+ * Marvell Semiconductor <www.marvell.com>
+ * Written-by: Prafulla Wadaskar <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include "mkimage.h"
+#include <image.h>
+#include "kwbimage.h"
+
+/*
+ * Suported commands for configuration file

tools/kwbimage.c line 40

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+ */
+static table_entry_t kwbimage_cmds[] = {
+	{	CMD_BOOT_FROM,		"BOOT_FROM",		"",	},
+	{	CMD_NAND_ECC_MODE,	"NAND_ECC_MODE",	"",	},
+	{	CMD_NAND_PAGE_SIZE,	"NAND_PAGE_SIZE",	"",	},
+	{	CMD_SATA_PIO_MODE,	"SATA_PIO_MODE",	"",	},
+	{	CMD_DDR_INIT_DELAY,	"DDR_INIT_DELAY",	"",	},
+	{	CMD_DATA,		"DATA",			"",	},
+	{	CMD_INVALID,		"",			"",	},
+};

Why don't these entries have any printable names associated?

tools/kwbimage.c line 42

Quoted 2 lines
tools/kwbimage.c new file +2 -0
+/*
+ * Suported Boot options for configuration file

Typo.

...

tools/kwbimage.c line 63

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+/*
+ * Suported NAND ecc options configuration file
+ */
+static table_entry_t kwbimage_eccmodes[] = {
+	{	IBR_HDR_ECC_DEFAULT,	"default",		"",	},
+	{	IBR_HDR_ECC_FORCED_HAMMING,"hamming",		"",	},
+	{	IBR_HDR_ECC_FORCED_RS,	"rs",			"",	},
+	{	IBR_HDR_ECC_DISABLED,	"disabled",		"",	},
+	{	-1,			"",			"",	},
+};

Why don't these entries have any printable names associated?

tools/kwbimage.c line 109

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+uint32_t check_get_hexval (char *token)
+{
+	uint32_t hexval;
+
+	if (!sscanf (token, "%x", &hexval)) {
+		printf ("Error:%s[%d] - Invalid hex data\n", fname, lineno);
+		exit (EXIT_FAILURE);
+	}
+	return hexval;
+}

scanf() is not a good or reliable conversion tool. Better avoid it. Use strto[u]l() instead.

In the error case, please also print the string that you cannot convert.

tools/kwbimage.c line 122

Quoted 12 lines
tools/kwbimage.c new file +12 -0
+/*
+ * Generates 8 bit checksum
+ */
+uint8_t kwbimage_checksum8 (void *start, uint32_t len, uint8_t csum)
+{
+	register uint8_t sum = csum;
+	volatile uint8_t *startp = (volatile uint8_t *)start;
+
+	do {
+		sum += *startp;
+		startp++;
+	} while (--len);

"startp" is incorrectly named. It is only _start_ at the beginning. Just call it "p" :-)

Maybe you should add handling for the "len=0" case.

Quoted 4 lines
tools/kwbimage.c new file +4 -0
+/*
+ * Generates 32 bit checksum
+ */
+uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csum)

tools/kwbimage.c line 139

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+{
+	register uint32_t sum = csum;
+	volatile uint32_t *startp = start;
+
+	do {
+		sum += *startp;
+		startp++;
+		len -= sizeof(uint32_t);
+	} while (len > 0);
+	return (sum);

You should error handling for the cas ethet len is not an even multiple of sizeof(uint32_t).

Maybe you should add handling for the "len=0" case.

...

tools/kwbimage.c line 175

Quoted 5 lines
tools/kwbimage.c new file +5 -0
+	case CMD_NAND_PAGE_SIZE:
+		mhdr->nandpagesize =
+			(uint16_t) check_get_hexval (token);
+			printf ("Nand page size = 0x%x\n",
+					mhdr->nandpagesize);

Indentation incorrect.

tools/kwbimage.c line 181

Quoted 6 lines
tools/kwbimage.c new file +6 -0
+		break;
+	case CMD_SATA_PIO_MODE:
+		mhdr->satapiomode =
+			(uint8_t) check_get_hexval (token);
+			printf ("Sata PIO mode = 0x%x\n",
+					mhdr->satapiomode);

Indentation incorrect.

tools/kwbimage.c line 187

Quoted 6 lines
tools/kwbimage.c new file +6 -0
+		break;
+	case CMD_DDR_INIT_DELAY:
+		mhdr->ddrinitdelay =
+			(uint16_t) check_get_hexval (token);
+		printf ("DDR init delay = %d msec\n",
+					mhdr->ddrinitdelay);

Indentation incorrect.

tools/kwbimage.c line 191

Quoted 4 lines
tools/kwbimage.c new file +4 -0
+		break;
+	case CMD_DATA:
+		exthdr->rcfg[datacmd_cnt].raddr =
+			(uint32_t) check_get_hexval (token);

Umm... why are all these casts needed?

Please get rid of these.

tools/kwbimage.c line 199

Quoted 7 lines
tools/kwbimage.c new file +7 -0
+		break;
+	case CMD_INVALID:
+	default:
+INVL_DATA:
+		printf ("Error:%s[%d] - Invalid data\n", fname, lineno);
+		exit (EXIT_FAILURE);
+	}

I really dislike this jumping into another case. Please don;t. Move this code out of the switch().

tools/kwbimage.c line 202

Quoted 3 lines
tools/kwbimage.c new file +3 -0
+}
+
+void kwdimage_set_ext_header (struct kwb_header *kwbhdr, char* name) {

How about some comments what all these functions are supposed to do?

Quoted 4 lines
tools/kwbimage.c new file +4 -0
+			case CFG_DATA1:
+				if (cmd != CMD_DATA)
+					goto INVL_CMD;
+

tools/kwbimage.c line 265

Quoted 10 lines
tools/kwbimage.c new file +10 -0
+				exthdr->rcfg[datacmd_cnt].rdata =
+					(uint32_t) check_get_hexval (token);
+
+				if (datacmd_cnt > KWBIMAGE_MAX_CONFIG ) {
+					printf ("Error:%s[%d] - Found more "
+						"than max(%d) allowed "
+						"data configurations\n",
+						fname, lineno,
+						KWBIMAGE_MAX_CONFIG);
+				exit (EXIT_FAILURE);

Indentation incorrect.

tools/kwbimage.c line 276

Quoted 11 lines
tools/kwbimage.c new file +11 -0
+				} else
+					datacmd_cnt++;
+				break;
+
+			default:
+				/*
+				 * Command format permits maximum three
+				 * strings on a line, i.e. command and data
+				 * if more than two are observed, then error
+				 * will be reported
+				 */

That does not make sense. If three three stings are permitted, then why throwing an error when there are three?

And "three strings on a line, i.e. command and data" sounds incorrect, too.

tools/kwbimage.c line 280

Quoted 4 lines
tools/kwbimage.c new file +4 -0
+INVL_CMD:
+				printf ("Error:%s[%d] - Invalid command\n",
+					fname, lineno);
+				exit (EXIT_FAILURE);

Please do not jump right in the middle of a switch. Move this error code out of the switch.

Quoted 5 lines
tools/kwbimage.c new file +5 -0
+/* -l support functions */
+int kwbimage_verify_header (char *ptr, int image_size,
+			struct mkimage_params *params)
+{
+	struct kwb_header *hdr = (struct kwb_header *)ptr;

tools/kwbimage.c line 340

Quoted 10 lines
tools/kwbimage.c new file +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 -FDT_ERR_BADSTRUCTURE;	/* mhdr csum not matched */
+	}

No braces needed for single line statements.

tools/kwbimage.c line 345

Quoted 5 lines
tools/kwbimage.c new file +5 -0
+	calc_exthdrcsum = kwbimage_checksum8 ((void *)exthdr,
+			sizeof(extbhr_t) - sizeof(uint8_t), 0);
+	if (calc_hdrcsum != mhdr->checkSum) {
+		return -FDT_ERR_BADSTRUCTURE; /* exthdr csum not matched */
+	}

No braces needed for single line statements.

tools/kwbimage.c line 357

Quoted 9 lines
tools/kwbimage.c new file +9 -0
+void kwbimage_print_header (char *ptr)
+{
+	struct kwb_header *hdr = (struct kwb_header *) ptr;
+	bhr_t *mhdr = &hdr->kwb_hdr;
+
+	printf ("Image Type:   Kirkwood Boot from %s Image\n",
+		get_table_entry_name (kwbimage_bootops,
+			"Kwbimage boot option",
+			(int) mhdr->blockid));

Indentation looks ugly.

...

Quoted 21 lines
tools/mkimage.c +2 -0
index 3a3cb19..7e29610 100644
@@ -25,6 +25,7 @@
 #include "mkimage.h"
 #include <image.h>
 #include "default_image.h"
+#include "kwbimage.h"
 
 static void copy_file(int, const char *, int);
 static void usage(void);
@@ -59,6 +60,7 @@ static struct image_functions image_ftable[] = {
 	{image_get_tparams,},	/* for IH_TYPE_SCRIPT */
 	{image_get_tparams,},	/* for IH_TYPE_STANDALONE */
 	{fitimage_get_tparams,},	/* for IH_TYPE_FLATDT */
+	{kwbimage_get_tparams,},        /* for IH_TYPE_KWBIMAGE */
 };
 
 int

tools/mkimage.c main (int argc, char **argv) · line 116

Quoted 5 lines
tools/mkimage.c +1 -1
@@ -111,7 +113,7 @@ main (int argc, char **argv)
 					(params.opt_type =
 					genimg_get_type_id (*++argv)) < 0)
 					usage ();
-				if (image_ftable_size <= params.opt_type) {
+				if (image_ftable_size < params.opt_type) {

Ah! What's going on here????

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: [email protected]
When choosing between two evils, I always like to take the  one  I've
never tried before.                     -- Mae West, "Klondike Annie"
#9 lore raw

PATCH 6/8 tools: mkimage: Making table_entry code global

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

Quoted 6 lines · In message <[email protected]> you wrote:
include/image.h +0 -0
index 88a13ab..f119cee 100644

include/image.h line 175

Quoted 8 lines
include/image.h +5 -0
@@ -168,6 +168,15 @@
 #define IH_MAGIC	0x27051956	/* Image Magic Number		*/
 #define IH_NMLEN		32	/* Image Name Length		*/
 
+typedef struct table_entry {
+	int	id;		/* as defined in image.h	*/
+	char	*sname;		/* short (input) name		*/
+	char	*lname;		/* long (output) name		*/
+} table_entry_t;

Now read this code again, with the distance of a couple of days, and tell me what you think.

"as defined in image.h" - hey, this _is_ image.h !

So, "struct table_entry" - what sort of table is this?

"short (input) name", "long (output) name" - what the heck is this about?

In the old version, the declaration of the struct was followed by the declarations of the actual tables, so we could _see_ what was meant.

You rip the code out of context, which makes it unreadable and ununderstandable.

This is a really bad idea, it seems.

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
"He only drinks when he gets depressed." "Why does he get depressed?"
"Sometimes it's because he hasn't had a drink."
                                     - Terry Pratchett, _Men at Arms_
#10 lore raw

PATCH 6/8 tools: mkimage: Making table_entry code global

Quoted 42 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Saturday, August 08, 2009 4:32 AM
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Ashish Karkare; Prabhanjan Sarnaik
Subject: Re: [U-Boot] [PATCH 6/8] tools: mkimage: Making table_entry code global

Dear Prafulla Wadaskar,

In message

include/image.h index

Quoted 2 lines · <[email protected]> you wrote:
include/image.h index renamed from include/image.h +0 -0

88a13ab..f119cee

include/image.h line 168

Quoted 5 lines

100644

include/image.h +0 -0
@@ -168,6 +168,15 @@
 #define IH_MAGIC	0x27051956	/* Image Magic Number	
	*/

include/image.h line 169

Quoted 1 line
include/image.h +0 -0
 #define IH_NMLEN		32	/* Image Name Length	
	*/

include/image.h line 175

Quoted 6 lines
include/image.h +5 -0
+typedef struct table_entry {
+	int	id;		/* as defined in image.h	*/
+	char	*sname;		/* short (input) name		*/
+	char	*lname;		/* long (output) name		*/
+} table_entry_t;

Now read this code again, with the distance of a couple of days, and tell me what you think.

"as defined in image.h" - hey, this _is_ image.h !

So, "struct table_entry" - what sort of table is this?

"short (input) name", "long (output) name" - what the heck is this about?

Quoted 6 lines

In the old version, the declaration of the struct was followed by the declarations of the actual tables, so we could _see_ what was meant.

You rip the code out of context, which makes it unreadable and ununderstandable.

Dear Wolfgang,
I have gone through all the feedback that you have provided for this entire patch series. Thanks a lot...

Now I need to take care of issues raised by you on the top of presenting them, with comments wherever necessary to make it better readable and understandable.

I tried to maintain the flow in the series for easy understanding, but I failed :-( With these patches, new code looks differently compared to original code.
So I feel instead of providing incremental patches- I should provide
1. basic mkimge framework patch,
2. mkimage: add: uimage support patch,
3. mkimage: add: fit image support patch,
4. mkimage: add: Kirkwood boot image support patch.
I will do this in my next post.
I hope you will like it.
If you have any inputs in this regard or you think this is bad plan, pls kindly let me know.

Regards..
Prafulla . .

Quoted 16 lines

This is a really bad idea, it seems.

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 "He only drinks when he gets depressed." "Why does 
he get depressed?"
"Sometimes it's because he hasn't had a drink."
                                     - Terry Pratchett, _Men at Arms_
#11 lore raw

PATCH 6/8 tools: mkimage: Making table_entry code global

Dear Prafulla Wadaskar,

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

I have gone through all the feedback that you have provided for this entire patch series. Thanks a lot...

Thank you for your pat6ience. Sorry it's such a long story for such a apparently small addition.

Quoted 1 line

I tried to maintain the flow in the series for easy understanding, but I failed :-(

Actually you did not. I just did not agree with some implementation details. And the changes need beter documentation.

Quoted 5 lines

With these patches, new code looks differently compared to original code. So I feel instead of providing incremental patches- I should provide
1. basic mkimge framework patch,
2. mkimage: add: uimage support patch,
3. mkimage: add: fit image support patch,

Um... these three must never be split. I mean, we should not add any patch that breaks the (existing) mkimage support.

Quoted 5 lines

4. mkimage: add: Kirkwood boot image support patch.

I will do this in my next post.
I hope you will like it.
If you have any inputs in this regard or you think this is bad plan, pls kindly let me know.

I'm not sure if this will be an improvement. I guess it will make it even harder to understand the changes.

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
"Infidels in all ages have battled for the rights of man, and have at
all times been the fearless advocates of liberty and justice."
- Robert Green Ingersoll
#12 lore raw

PATCH 6/8 tools: mkimage: Making table_entry code global

Quoted 16 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Monday, August 10, 2009 2:00 AM
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Ashish Karkare; Prabhanjan Sarnaik
Subject: Re: [U-Boot] [PATCH 6/8] tools: mkimage: Making table_entry code global

Dear Prafulla Wadaskar,

In message <[email protected].

Quoted 1 line · com> you wrote:
Quoted 6 lines
Quoted 1 line

I have gone through all the feedback that you have provided

for this entire patch series.

Quoted 1 line

Thanks a lot...

Thank you for your pat6ience. Sorry it's such a long story for such a apparently small addition.

That's what my earlier intention was:-) Just to add small support with minimal modifications. But while doing it, the idea has generated why not improve it further? Like header_size, function callbacks. That need more work/rework and I can understand there will be more spins to get it through. So here I am to support you :-D

Quoted 6 lines
Quoted 2 lines

I tried to maintain the flow in the series for easy

understanding, but I failed :-(

Actually you did not. I just did not agree with some implementation details. And the changes need beter documentation.

Yes, I will take care of documentation, thanks

Quoted 10 lines
Quoted 2 lines

With these patches, new code looks differently compared to

original code.

Quoted 4 lines

So I feel instead of providing incremental patches- I should provide
1. basic mkimge framework patch,
2. mkimage: add: uimage support patch,
3. mkimage: add: fit image support patch,

Um... these three must never be split. I mean, we should not add any patch that breaks the (existing) mkimage support.

Okay I will take care of this

Quoted 10 lines
Quoted 6 lines

4. mkimage: add: Kirkwood boot image support patch.

I will do this in my next post.
I hope you will like it.
If you have any inputs in this regard or you think this is

bad plan, pls kindly let me know.

I'm not sure if this will be an improvement. I guess it will make it even harder to understand the changes.

Then I will try to post patches better combination of incremental ones :-)

Thanks and regards..
Prafulla . .

Quoted 13 lines

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
"Infidels in all ages have battled for the rights of man, and have at
all times been the fearless advocates of liberty and justice."
- Robert Green Ingersoll
#13 lore raw

PATCH 4/8 tools: mkimage: Implemented callback function for default image support

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

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

This is Third step towards cleaning mkimage code for kwbimage

BTW - I think "cleaning mkimage code" is not correct. This is not a clean up, but a major rework.

Quoted 2 lines

1. callback functions are used in mkimage.c those are defined in defaut_image.c for currently supported images.

Typo...

Quoted 1 line

2. scan loop implemented for image header verify and print

What does that mean? Please provide better documentation / comments so we understand what you are doing.

tools/default_image.c image_verify_header (char *ptr, int image_size, · line 109

Quoted 7 lines

void image_print_header (char *ptr)
{

tools/default_image.c +1 -3
-	image_header_t * hdr = (image_header_t *)ptr;
-
-	image_print_contents (hdr);
+	image_print_contents ((image_header_t *)ptr);
 }

The new code looks uglier than the old one. Please don;t change.

tools/default_image.c void image_set_header (char *ptr, struct stat *sbuf, · line 149

Quoted 9 lines
tools/default_image.c +9 -0
+/*
+ * FIT image support
+ */
+int
+fitimage_verify_header (char *ptr, int image_size,
+			struct mkimage_params *params)
+{
+	fdt_check_header ((void *)ptr);
+}

Do other image types need the provided parameters?

tools/default_image.c void image_set_header (char *ptr, struct stat *sbuf, · line 154

Quoted 4 lines
tools/default_image.c +4 -0
+void fitimage_print_header (char *ptr)
+{
+	fit_print_contents ((void *)ptr);
+}

Maybe we can omit this function, then?

tools/default_image.c void image_set_header (char *ptr, struct stat *sbuf, · line 161

Quoted 6 lines
tools/default_image.c +6 -0
+struct image_type_params fitimage_params = {
+	.header_size = sizeof(image_header_t),
+	.hdr = (void*)&header,
+	.check_params = image_check_params,
+	.verify_header = fitimage_verify_header,
+	.print_header = fitimage_print_header,

... and just use ".print_header = fit_print_contents," here?

...

Quoted 9 lines
tools/mkimage.c +1 -0
index d1636d8..3a3cb19 100644
@@ -49,14 +49,28 @@ struct mkimage_params params = {
 	.cmdname = "",
 };
 
+static struct image_functions image_ftable[] = {

tools/mkimage.c struct mkimage_params params = { · line 62

Quoted 10 lines
tools/mkimage.c +10 -0
+	{image_get_tparams,},	/* for IH_TYPE_INVALID */
+	{image_get_tparams,},	/* for IH_TYPE_FILESYSTEM */
+	{image_get_tparams,},	/* for IH_TYPE_FIRMWARE */
+	{image_get_tparams,},	/* for IH_TYPE_KERNEL */
+	{image_get_tparams,},	/* for IH_TYPE_MULTI */
+	{image_get_tparams,},	/* for IH_TYPE_RAMDISK */
+	{image_get_tparams,},	/* for IH_TYPE_SCRIPT */
+	{image_get_tparams,},	/* for IH_TYPE_STANDALONE */
+	{fitimage_get_tparams,},	/* for IH_TYPE_FLATDT */
+};

What is this? Please explain. The table looks pretty bogus to me. If all but one use the same function, why do we need such a table then?

tools/mkimage.c struct mkimage_params params = { · line 71

Quoted 9 lines
tools/mkimage.c +1 -1
 int
 main (int argc, char **argv)
 {
 	int ifd = -1;
 	struct stat sbuf;
 	unsigned char *ptr;
-	int retval;
+	int i, retval;
 	struct image_type_params *tparams = image_get_tparams ();

Such initialization here looks bad to me, as it is in no way correlated to the image_ftable[] settinga above.

tools/mkimage.c main (int argc, char **argv) · line 114

Quoted 10 lines
tools/mkimage.c +3 -0
+	struct image_type_params *scantparams;
+	int image_ftable_size = ARRAY_SIZE(image_ftable);
 
 	params.cmdname = *argv;
 
@@ -97,6 +111,15 @@ main (int argc, char **argv)
 					(params.opt_type =
 					genimg_get_type_id (*++argv)) < 0)
 					usage ();
+				if (image_ftable_size <= params.opt_type) {

Logic here looks inverted to me. And is the <= correct?

tools/mkimage.c NXTARG: ; · line 250

Quoted 3 lines
tools/mkimage.c +3 -0
+		/*
+		 * Scan image headers for all supported types
+		 * and print if veryfy_header sucessful

Typo.

I have to admit that I do not understand what you are actually doing here.

Quoted 7 lines
tools/mkimage.c +7 -0
+		 */
+		for (i = image_ftable_size - 1; i != IH_TYPE_INVALID; i--) {
+			scantparams = image_ftable[i].get_tparams ();
+			fprintf (stderr, "%s: Verify header for type=%s\n",
+				params.cmdname, genimg_get_type_name (i));
+
+			retval = scantparams->verify_header (

tools/mkimage.c NXTARG: ; · line 265

Quoted 10 lines
tools/mkimage.c +7 -2
 				(char *)ptr, sbuf.st_size,
-				&params))) /* old-style image */
-			image_print_contents ((image_header_t *)ptr);
+				&params);
+
+			if (retval == 0) {
+				scantparams->print_header ((char *)ptr);
+				break;
+			}
+		}

Maybe you can explain what you're doing?

tools/mkimage.c NXTARG: ; · line 373

Quoted 11 lines
tools/mkimage.c +2 -2
 		(void) munmap((void *)ptr, sbuf.st_size);
 		(void) close (ifd);
@@ -333,9 +368,9 @@ NXTARG:		;
 		exit (EXIT_FAILURE);
 	}
 
-	image_set_header (ptr, &sbuf, &params);
+	tparams->set_header (ptr, &sbuf, ifd, &params);
 
-	image_print_header (ptr);
+	tparams->print_header (ptr);

The longer I read this, the more I dislike the tparams-> code. I tend to think the type switching should be transparent, and not visible in the code.

tools/mkimage.c NXTARG: ;

Quoted 6 lines
tools/mkimage.c +6 -0
+/*
+ * Image type specific function pointers list
+ */
+struct image_functions {
+	void *	(*get_tparams) (void);
+};

What's that?

Quoted 1 line

+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

Why do you need to declare this here? Please use standard features.

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
Technology is dominated by those who manage what they do  not  under-
stand.
#14 lore raw

PATCH 3/8 tools: mkimage: Move image header code to image specific files

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

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

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

I still fail to understand why this would be needed, or even wanted.

Quoted 1 line

2. image header code moved form mkimage.c to default_image .c

This looks incorrect to me (not to mention the "form/from" typo):
I see no code being moved, only variable declarations.

tools/default_image.c line 44

Quoted 11 lines
tools/default_image.c +11 -0
+/*
+ * 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;
+}

We need better documentation. Why would that function be needed?

tools/default_image.c void image_set_header (char *ptr, struct stat *sbuf, · line 118

Quoted 11 lines

int image_check_params (struct mkimage_params *params) {

tools/default_image.c +2 -2
 	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));

I cannot help it, but this change looks like a step backward to me. Why don't we use the header_size entry from the image_type_params here, too?

...

Quoted 21 lines
tools/mkimage.c +1 -3
@@ -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;
 

tools/mkimage.c NXTARG: ; · line 164

Quoted 5 lines
tools/mkimage.c +1 -1
@@ -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;

Would it not be better to stick with the image_get_header_size() function, and instead make it aware which image type we are asking for?

The old code was homnogenuous: it consistently used image_get_header_size(); now we have a sizeof() here and a ptr->header_size there.

I really dislike that.

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
"Here's a fish hangs in the net like a poor man's right in  the  law.
'Twill hardly come out."     - Shakespeare, Pericles, Act II, Scene 1
#15 lore raw

PATCH 2/8 tools: mkimage: code abstraction generic and image specific

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

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

This is first step towards cleaning mkimage code for kwbimage support in clean way. Current mkimage code is very specific to uimge generation whereas the same framework can be used to generate other image types like kwbimage.
For this, the architecture of mkimage code need to modified.

Here is the brief plan for the same:-
a) Abstract image specific code to saperate file (this patch)
b) Move image header code from mkimage.c to respective image specific code
c) Implement callback function for image specific functions
d) Add kwbimage type support to this framework

In this patch-
1. Image specific code abstracted from mkimage.c to default_image.c/h to make mkimage code more generic
2. struct mkimage_params introduced to pass basic mkimage specific flags and variables to image specific functions

Quoted 9 lines
---
 tools/Makefile        |    4 +
 tools/default_image.c |  227 ++++++++++++++++++++++++++++++
 tools/default_image.h |   36 +++++
 tools/mkimage.c       |  368 ++++++++++++++-----------------------------------
 tools/mkimage.h       |   25 ++++
 5 files changed, 394 insertions(+), 266 deletions(-)
 create mode 100644 tools/default_image.c
 create mode 100644 tools/default_image.h

Just nitpicking...

tools/Makefile $(obj)img2srec$(SFX): $(obj)img2srec.o · line 175

Quoted 10 lines
tools/Makefile +1 -0
index b5a1e39..6ef15d9 100644
@@ -171,6 +171,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 	$(STRIP) $@
 
 $(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
+			$(obj)default_image.o \
 			$(obj)sha1.o $(LIBFDT_OBJS) $(obj)os_support.o

Please let's sort the files...

tools/Makefile $(obj)bin2header$(SFX): $(obj)bin2header.o · line 209

Quoted 9 lines
tools/Makefile +3 -0
 	$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 	$(STRIP) $@
@@ -203,6 +204,9 @@ $(obj)bin2header$(SFX): $(obj)bin2header.o
 $(obj)image.o: $(SRCTREE)/common/image.c
 	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
+$(obj)default_image.o: $(SRCTREE)/tools/default_image.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+

Please sort here, too.

Quoted 5 lines
tools/mkimage.c +0 -0
index b7b383a..66d6c8e 100644
@@ -24,28 +24,30 @@

...

Quoted 1 line

+struct mkimage_params params = {

...

Quoted 5 lines
tools/mkimage.c +5 -0
+	.opt_os = IH_OS_LINUX,
+	.opt_arch = IH_ARCH_PPC,
+	.opt_type = IH_TYPE_KERNEL,
+	.opt_comp = IH_COMP_GZIP,
+	.opt_dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,

...

tools/mkimage.c line 49

Quoted 4 lines
tools/mkimage.c +4 -0
+	.imagename = "",
+	.datafile = "",
+	.imagefile = "",
+	.cmdname = "",

I see no reason to initialize these strings. Please omit.

Quoted 1 line

+};

...

tools/mkimage.c int · line 82

Quoted 12 lines
tools/mkimage.c +4 -2
 			case 'A':
 				if ((--argc <= 0) ||
-				    (opt_arch = genimg_get_arch_id (*++argv)) < 0)
+					(params.opt_arch =
+					genimg_get_arch_id (*++argv)) < 0)
 					usage ();
 				goto NXTARG;
 			case 'C':
 				if ((--argc <= 0) ||
-				    (opt_comp = genimg_get_comp_id (*++argv)) < 0)
+					(params.opt_comp =
+					genimg_get_comp_id (*++argv)) < 0)

The new code looks really ugly here and in all the following case:s; This is mostly caused by the fact that the new code is much longer "params.opt_XXX" versus "opt_XXX"). With the new code all the options are in the params structure anyway, so ther eis no danger to confuse these withother variables, so we should omit the "opt_" part, I think.

This gives:

struct mkimage_params params = {
...
.os = IH_OS_LINUX,
.arch = IH_ARCH_PPC,
.type = IH_TYPE_KERNEL,
.comp = IH_COMP_GZIP,
.dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
...
};
...

			case 'A':
				if ((--argc <= 0) ||
				    (params.arch = genimg_get_arch_id(*++argv)) < 0) {
					usage ();
				}
				goto NXTARG;
			case 'C':
				if ((--argc <= 0) ||
				    (params.comp = genimg_get_comp_id(*++argv)) < 0) {
					usage ();
				}
				goto NXTARG;

...

etc.

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: [email protected]
Extended Epstein-Heisenberg Principle: In an R & D orbit, only  2  of
the  existing 3 parameters can be defined simultaneously. The parame-
ters are: task, time and resources ($).
#16 lore raw

PATCH 1/8 tools: mkimage : bugfix returns correct value for list command

In reply to Prafulla Wadaskar

Dear Prafulla Wadaskar,

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

List command always return "EXIT_SUCCESS" even in case of failure by any means.

This patch return 0 if list command is sucessful, returns negative value reported by check_header functions

---
 tools/mkimage.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

Just a minor nitpick:

...

tools/mkimage.c NXTARG: ; · line 227

Quoted 12 lines
tools/mkimage.c +4 -7
-		if (fdt_check_header (ptr)) {
-			/* old-style image */
-			image_verify_header ((char *)ptr, sbuf.st_size);
-			image_print_contents ((image_header_t *)ptr);
-		} else {
-			/* FIT image */
+		if (!(retval = fdt_check_header (ptr)))	/* FIT image */
 			fit_print_contents (ptr);
-		}
+		else if (!(retval = image_verify_header (
+			(char *)ptr, sbuf.st_size))) /* old-style image */
+			image_print_contents ((image_header_t *)ptr);

The resulting code looks ugly to me. Please write as:

		if (!(retval = fdt_check_header(ptr))) {
			/* FIT image */
			fit_print_contents (ptr);
		} else if (!(retval = image_verify_header((char *)ptr,
							  sbuf.st_size))) {
			/* old-style image */
			image_print_contents ((image_header_t *)ptr);
		}

Thanks.

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
There is a multi-legged creature crawling on your shoulder.
	-- Spock, "A Taste of Armageddon", stardate 3193.9
#17 lore raw

PATCH v2 1/8 tools: mkimage : bugfix returns correct value for list command

List command always return "EXIT_SUCCESS" even in case of failure by any means.

This patch return 0 if list command is sucessful, returns negative value reported by check_header functions

---
Change log:
v2: added code rewritten to look it better as per review feedback for v1

 tools/mkimage.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
tools/mkimage.c +14 -12
index 02cdb95..dc42924 100644
@@ -28,7 +28,7 @@
 extern	unsigned long	crc32 (unsigned long crc, const char *buf, unsigned int len);
 static	void		copy_file (int, const char *, int);
 static	void		usage (void);
-static	void		image_verify_header (char *, int);
+static	int		image_verify_header (char *, int);
 static	void		fit_handle_file (void);
 
 char	*datafile;
@@ -60,6 +60,7 @@ main (int argc, char **argv)
 	struct stat sbuf;
 	unsigned char *ptr;
 	char *name = "";
+	int retval;
 
 	cmdname = *argv;
 
@@ -219,24 +220,24 @@ NXTARG:		;
 			exit (EXIT_FAILURE);
 		}
 
-		if (fdt_check_header (ptr)) {
-			/* old-style image */
-			image_verify_header ((char *)ptr, sbuf.st_size);
-			image_print_contents ((image_header_t *)ptr);
-		} else {
+		if (!(retval = fdt_check_header (ptr))) {
 			/* FIT image */
 			fit_print_contents (ptr);
+		} else if (!(retval = image_verify_header ((char *)ptr,
+				sbuf.st_size))) {
+			/* old-style image */
+			image_print_contents ((image_header_t *)ptr);
 		}
 
 		(void) munmap((void *)ptr, sbuf.st_size);
 		(void) close (ifd);
 
-		exit (EXIT_SUCCESS);
+		exit (retval);
 	} else if (fflag) {
 		/* Flattened Image Tree (FIT) format  handling */
 		debug ("FIT format handling\n");
 		fit_handle_file ();
-		exit (EXIT_SUCCESS);
+		exit (retval);
 	}
 
 	/*
@@ -480,7 +481,7 @@ usage ()
 	exit (EXIT_FAILURE);
 }
 
-static void
+static int
 image_verify_header (char *ptr, int image_size)
 {
 	int len;
@@ -500,7 +501,7 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: Bad Magic Number: \"%s\" is no valid image\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADMAGIC;
 	}
 
 	data = (char *)hdr;
@@ -513,7 +514,7 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: ERROR: \"%s\" has bad header checksum!\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADSTATE;
 	}
 
 	data = ptr + sizeof(image_header_t);
@@ -523,8 +524,9 @@ image_verify_header (char *ptr, int image_size)
 		fprintf (stderr,
 			"%s: ERROR: \"%s\" has corrupted data!\n",
 			cmdname, imagefile);
-		exit (EXIT_FAILURE);
+		return -FDT_ERR_BADSTRUCTURE;
 	}
+	return 0;
 }
 
 /**
Signature · 1 line
1.5.3.3
#18 lore raw

PATCH v2 1/8 tools: mkimage : bugfix returns correct value for list command

Dear Prafulla Wadaskar,

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

List command always return "EXIT_SUCCESS" even in case of failure by any means.

This patch return 0 if list command is sucessful, returns negative value reported by check_header functions

Quoted 7 lines

---
Change log:
v2: added code rewritten to look it better as per review feedback for v1

 tools/mkimage.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

Thanks. To make some (visible) progress I decided to check in patches where we have full agreement into the (new) "mkimage" branch. This way we can gradually reduce the amount of stuff we need to discuss.

This patch has been applied to the "mkimage" branch. Thanks.

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
Fools ignore complexity. Pragmatists suffer it. Some  can  avoid  it.
Geniuses remove it.
     - Perlis's Programming Proverb #58, SIGPLAN Notices, Sept.  1982
#19 lore raw

PATCH v2 1/8 tools: mkimage : bugfix returns correct value for list command

Quoted 31 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Monday, August 10, 2009 2:37 PM
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de; Ashish Karkare; Prabhanjan Sarnaik
Subject: Re: [U-Boot] [PATCH v2 1/8] tools: mkimage : bugfix returns correct value for list command

Dear Prafulla Wadaskar,

In message

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

List command always return "EXIT_SUCCESS" even in case of

failure by

Quoted 9 lines

any means.

This patch return 0 if list command is sucessful, returns negative value reported by check_header functions

---
Change log:
v2: added code rewritten to look it better as per review

feedback for

Quoted 4 lines

v1

 tools/mkimage.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
Quoted 6 lines

Thanks. To make some (visible) progress I decided to check in patches where we have full agreement into the (new) "mkimage" branch. This way we can gradually reduce the amount of stuff we need to discuss.

This patch has been applied to the "mkimage" branch. Thanks.

Dear Wolfgang
Thanks

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 Fools ignore complexity. Pragmatists suffer it. 
Some  can  avoid  it.
Geniuses remove it.
     - Perlis's Programming Proverb #58, SIGPLAN Notices, Sept.  1982