mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 11/12] move code now only used in mkimage to mkimage
Date: Thu, 15 Dec 2011 11:30:33 +0100	[thread overview]
Message-ID: <1323945034-19687-12-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1323945034-19687-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/image.c    |  169 -------------------------------------
 include/image.h   |  103 -----------------------
 scripts/mkimage.c |  240 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+), 272 deletions(-)

diff --git a/common/image.c b/common/image.c
index 7a7c0df..e7d2242 100644
--- a/common/image.c
+++ b/common/image.c
@@ -144,172 +144,3 @@ const char *image_get_comp_name(uint8_t comp)
 	return get_table_entry_name(comp_name, "Unknown Compression", comp);
 }
 #endif
-
-/**
- * image_multi_count - get component (sub-image) count
- * @hdr: pointer to the header of the multi component image
- *
- * image_multi_count() returns number of components in a multi
- * component image.
- *
- * Note: no checking of the image type is done, caller must pass
- * a valid multi component image.
- *
- * returns:
- *     number of components
- */
-ulong image_multi_count(void *data)
-{
-	ulong i, count = 0;
-	uint32_t *size;
-
-	/* get start of the image payload, which in case of multi
-	 * component images that points to a table of component sizes */
-	size = (uint32_t *)data;
-
-	/* count non empty slots */
-	for (i = 0; size[i]; ++i)
-		count++;
-
-	return count;
-}
-
-/**
- * image_multi_getimg - get component data address and size
- * @hdr: pointer to the header of the multi component image
- * @idx: index of the requested component
- * @data: pointer to a ulong variable, will hold component data address
- * @len: pointer to a ulong variable, will hold component size
- *
- * image_multi_getimg() returns size and data address for the requested
- * component in a multi component image.
- *
- * Note: no checking of the image type is done, caller must pass
- * a valid multi component image.
- *
- * returns:
- *     data address and size of the component, if idx is valid
- *     0 in data and len, if idx is out of range
- */
-void image_multi_getimg(void *data, ulong idx,
-			ulong *img_data, ulong *len)
-{
-	int i;
-	uint32_t *size;
-	ulong offset, count, tmp_img_data;
-
-	/* get number of component */
-	count = image_multi_count(data);
-
-	/* get start of the image payload, which in case of multi
-	 * component images that points to a table of component sizes */
-	size = (uint32_t *)data;
-
-	/* get address of the proper component data start, which means
-	 * skipping sizes table (add 1 for last, null entry) */
-	tmp_img_data = (ulong)data + (count + 1) * sizeof (uint32_t);
-
-	if (idx < count) {
-		*len = uimage_to_cpu(size[idx]);
-		offset = 0;
-
-		/* go over all indices preceding requested component idx */
-		for (i = 0; i < idx; i++) {
-			/* add up i-th component size, rounding up to 4 bytes */
-			offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
-		}
-
-		/* calculate idx-th component data address */
-		*img_data = tmp_img_data + offset;
-	} else {
-		*len = 0;
-		*img_data = 0;
-	}
-}
-
-static void image_print_type(const image_header_t *hdr)
-{
-	const char *os, *arch, *type, *comp;
-
-	os = image_get_os_name(image_get_os(hdr));
-	arch = image_get_arch_name(image_get_arch(hdr));
-	type = image_get_type_name(image_get_type(hdr));
-	comp = image_get_comp_name(image_get_comp(hdr));
-
-	printf ("%s %s %s (%s)\n", arch, os, type, comp);
-}
-
-#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || !defined(__BAREBOX__)
-static void image_print_time(time_t timestamp)
-{
-#if defined(__BAREBOX__)
-	struct rtc_time tm;
-
-	to_tm(timestamp, &tm);
-	printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
-			tm.tm_year, tm.tm_mon, tm.tm_mday,
-			tm.tm_hour, tm.tm_min, tm.tm_sec);
-#else
-	printf("%s", ctime(&timestamp));
-#endif
-}
-#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || !__BAREBOX__ */
-
-void image_print_size(uint32_t size)
-{
-#ifdef __BAREBOX__
-	printf("%d Bytes = %s\n", size, size_human_readable(size));
-#else
-	printf("%d Bytes = %.2f kB = %.2f MB\n",
-			size, (double)size / 1.024e3,
-			(double)size / 1.048576e6);
-#endif
-}
-
-void image_print_contents(const image_header_t *hdr, void *data)
-{
-	const char *p;
-	int type;
-
-#ifdef __BAREBOX__
-	p = "   ";
-#else
-	p = "";
-#endif
-
-	printf("%sImage Name:   %.*s\n", p, IH_NMLEN, image_get_name(hdr));
-#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || !defined(__BAREBOX__)
-	printf("%sCreated:      ", p);
-	image_print_time((time_t)image_get_time(hdr));
-#endif
-	printf ("%sImage Type:   ", p);
-	image_print_type(hdr);
-	printf ("%sData Size:    ", p);
-	image_print_size(image_get_data_size(hdr));
-	printf ("%sLoad Address: %08x\n", p, image_get_load(hdr));
-	printf ("%sEntry Point:  %08x\n", p, image_get_ep(hdr));
-
-	type = image_get_type(hdr);
-	if (data && (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT)) {
-		int i;
-		ulong img_data, len;
-		ulong count = image_multi_count(data);
-
-		printf ("%sContents:\n", p);
-		for (i = 0; i < count; i++) {
-			image_multi_getimg(data, i, &img_data, &len);
-
-			printf("%s   Image %d: ", p, i);
-			image_print_size(len);
-
-			if (image_get_type(hdr) != IH_TYPE_SCRIPT && i > 0) {
-				/*
-				 * the user may need to know offsets
-				 * if planning to do something with
-				 * multiple files
-				 */
-				printf("%s    Offset = 0x%08lx\n", p, img_data);
-			}
-		}
-	}
-}
diff --git a/include/image.h b/include/image.h
index 97de881..35ff01b 100644
--- a/include/image.h
+++ b/include/image.h
@@ -218,109 +218,6 @@ static inline const char *image_get_comp_name(uint8_t comp)
 #define uimage_to_cpu(x)		be32_to_cpu(x)
 #define cpu_to_uimage(x)		cpu_to_be32(x)
 
-static inline uint32_t image_get_header_size(void)
-{
-	return sizeof(image_header_t);
-}
-
-#define image_get_hdr_u32(x)					\
-static inline uint32_t image_get_##x(const image_header_t *hdr)	\
-{								\
-	return uimage_to_cpu(hdr->ih_##x);			\
-}
-
-image_get_hdr_u32(magic);	/* image_get_magic */
-image_get_hdr_u32(hcrc);	/* image_get_hcrc */
-image_get_hdr_u32(time);	/* image_get_time */
-image_get_hdr_u32(size);	/* image_get_size */
-image_get_hdr_u32(load);	/* image_get_load */
-image_get_hdr_u32(ep);		/* image_get_ep */
-image_get_hdr_u32(dcrc);	/* image_get_dcrc */
-
-#define image_get_hdr_u8(x)					\
-static inline uint8_t image_get_##x(const image_header_t *hdr)	\
-{								\
-	return hdr->ih_##x;					\
-}
-image_get_hdr_u8(os);		/* image_get_os */
-image_get_hdr_u8(arch);		/* image_get_arch */
-image_get_hdr_u8(type);		/* image_get_type */
-image_get_hdr_u8(comp);		/* image_get_comp */
-
-static inline char *image_get_name(const image_header_t *hdr)
-{
-	return (char*)hdr->ih_name;
-}
-
-static inline uint32_t image_get_data_size(const image_header_t *hdr)
-{
-	return image_get_size(hdr);
-}
-
-/**
- * image_get_data - get image payload start address
- * @hdr: image header
- *
- * image_get_data() returns address of the image payload. For single
- * component images it is image data start. For multi component
- * images it points to the null terminated table of sub-images sizes.
- *
- * returns:
- *     image payload data start address
- */
-static inline ulong image_get_data(const image_header_t *hdr)
-{
-	return ((ulong)hdr + image_get_header_size());
-}
-
-static inline uint32_t image_get_image_size(const image_header_t *hdr)
-{
-	return (image_get_size(hdr) + image_get_header_size());
-}
-
-static inline ulong image_get_image_end(const image_header_t *hdr)
-{
-	return ((ulong)hdr + image_get_image_size(hdr));
-}
-
-#define image_set_hdr_u32(x)						\
-static inline void image_set_##x(image_header_t *hdr, uint32_t val)	\
-{									\
-	hdr->ih_##x = cpu_to_uimage(val);				\
-}
-
-image_set_hdr_u32(magic);	/* image_set_magic */
-image_set_hdr_u32(hcrc);	/* image_set_hcrc */
-image_set_hdr_u32(time);	/* image_set_time */
-image_set_hdr_u32(size);	/* image_set_size */
-image_set_hdr_u32(load);	/* image_set_load */
-image_set_hdr_u32(ep);		/* image_set_ep */
-image_set_hdr_u32(dcrc);	/* image_set_dcrc */
-
-#define image_set_hdr_u8(x)						\
-static inline void image_set_##x(image_header_t *hdr, uint8_t val)	\
-{									\
-	hdr->ih_##x = val;						\
-}
-
-image_set_hdr_u8(os);		/* image_set_os */
-image_set_hdr_u8(arch);		/* image_set_arch */
-image_set_hdr_u8(type);		/* image_set_type */
-image_set_hdr_u8(comp);		/* image_set_comp */
-
-static inline void image_set_name(image_header_t *hdr, const char *name)
-{
-	strncpy(image_get_name(hdr), name, IH_NMLEN);
-}
-
-ulong image_multi_count(void *data);
-void image_multi_getimg(void *data, ulong idx,
-			ulong *img_data, ulong *len);
-
-void image_print_size(uint32_t size);
-
-void image_print_contents(const image_header_t *hdr, void *data);
-
 struct uimage_handle_data {
 	size_t offset; /* offset in the image */
 	ulong len;
diff --git a/scripts/mkimage.c b/scripts/mkimage.c
index b219cb8..64290cf 100644
--- a/scripts/mkimage.c
+++ b/scripts/mkimage.c
@@ -62,6 +62,246 @@ int opt_comp = IH_COMP_GZIP;
 image_header_t header;
 image_header_t *hdr = &header;
 
+static inline uint32_t image_get_header_size(void)
+{
+	return sizeof(image_header_t);
+}
+
+#define image_get_hdr_u32(x)					\
+static inline uint32_t image_get_##x(const image_header_t *hdr)	\
+{								\
+	return uimage_to_cpu(hdr->ih_##x);			\
+}
+
+image_get_hdr_u32(magic);	/* image_get_magic */
+image_get_hdr_u32(hcrc);	/* image_get_hcrc */
+image_get_hdr_u32(time);	/* image_get_time */
+image_get_hdr_u32(size);	/* image_get_size */
+image_get_hdr_u32(load);	/* image_get_load */
+image_get_hdr_u32(ep);		/* image_get_ep */
+image_get_hdr_u32(dcrc);	/* image_get_dcrc */
+
+#define image_get_hdr_u8(x)					\
+static inline uint8_t image_get_##x(const image_header_t *hdr)	\
+{								\
+	return hdr->ih_##x;					\
+}
+image_get_hdr_u8(os);		/* image_get_os */
+image_get_hdr_u8(arch);		/* image_get_arch */
+image_get_hdr_u8(type);		/* image_get_type */
+image_get_hdr_u8(comp);		/* image_get_comp */
+
+static inline char *image_get_name(const image_header_t *hdr)
+{
+	return (char*)hdr->ih_name;
+}
+
+static inline uint32_t image_get_data_size(const image_header_t *hdr)
+{
+	return image_get_size(hdr);
+}
+
+/**
+ * image_get_data - get image payload start address
+ * @hdr: image header
+ *
+ * image_get_data() returns address of the image payload. For single
+ * component images it is image data start. For multi component
+ * images it points to the null terminated table of sub-images sizes.
+ *
+ * returns:
+ *     image payload data start address
+ */
+static inline ulong image_get_data(const image_header_t *hdr)
+{
+	return ((ulong)hdr + image_get_header_size());
+}
+
+static inline uint32_t image_get_image_size(const image_header_t *hdr)
+{
+	return (image_get_size(hdr) + image_get_header_size());
+}
+
+static inline ulong image_get_image_end(const image_header_t *hdr)
+{
+	return ((ulong)hdr + image_get_image_size(hdr));
+}
+
+#define image_set_hdr_u32(x)						\
+static inline void image_set_##x(image_header_t *hdr, uint32_t val)	\
+{									\
+	hdr->ih_##x = cpu_to_uimage(val);				\
+}
+
+image_set_hdr_u32(magic);	/* image_set_magic */
+image_set_hdr_u32(hcrc);	/* image_set_hcrc */
+image_set_hdr_u32(time);	/* image_set_time */
+image_set_hdr_u32(size);	/* image_set_size */
+image_set_hdr_u32(load);	/* image_set_load */
+image_set_hdr_u32(ep);		/* image_set_ep */
+image_set_hdr_u32(dcrc);	/* image_set_dcrc */
+
+#define image_set_hdr_u8(x)						\
+static inline void image_set_##x(image_header_t *hdr, uint8_t val)	\
+{									\
+	hdr->ih_##x = val;						\
+}
+
+image_set_hdr_u8(os);		/* image_set_os */
+image_set_hdr_u8(arch);		/* image_set_arch */
+image_set_hdr_u8(type);		/* image_set_type */
+image_set_hdr_u8(comp);		/* image_set_comp */
+
+static inline void image_set_name(image_header_t *hdr, const char *name)
+{
+	strncpy(image_get_name(hdr), name, IH_NMLEN);
+}
+
+/**
+ * image_multi_count - get component (sub-image) count
+ * @hdr: pointer to the header of the multi component image
+ *
+ * image_multi_count() returns number of components in a multi
+ * component image.
+ *
+ * Note: no checking of the image type is done, caller must pass
+ * a valid multi component image.
+ *
+ * returns:
+ *     number of components
+ */
+static ulong image_multi_count(void *data)
+{
+	ulong i, count = 0;
+	uint32_t *size;
+
+	/* get start of the image payload, which in case of multi
+	 * component images that points to a table of component sizes */
+	size = (uint32_t *)data;
+
+	/* count non empty slots */
+	for (i = 0; size[i]; ++i)
+		count++;
+
+	return count;
+}
+
+/**
+ * image_multi_getimg - get component data address and size
+ * @hdr: pointer to the header of the multi component image
+ * @idx: index of the requested component
+ * @data: pointer to a ulong variable, will hold component data address
+ * @len: pointer to a ulong variable, will hold component size
+ *
+ * image_multi_getimg() returns size and data address for the requested
+ * component in a multi component image.
+ *
+ * Note: no checking of the image type is done, caller must pass
+ * a valid multi component image.
+ *
+ * returns:
+ *     data address and size of the component, if idx is valid
+ *     0 in data and len, if idx is out of range
+ */
+static void image_multi_getimg(void *data, ulong idx,
+			ulong *img_data, ulong *len)
+{
+	int i;
+	uint32_t *size;
+	ulong offset, count, tmp_img_data;
+
+	/* get number of component */
+	count = image_multi_count(data);
+
+	/* get start of the image payload, which in case of multi
+	 * component images that points to a table of component sizes */
+	size = (uint32_t *)data;
+
+	/* get address of the proper component data start, which means
+	 * skipping sizes table (add 1 for last, null entry) */
+	tmp_img_data = (ulong)data + (count + 1) * sizeof (uint32_t);
+
+	if (idx < count) {
+		*len = uimage_to_cpu(size[idx]);
+		offset = 0;
+
+		/* go over all indices preceding requested component idx */
+		for (i = 0; i < idx; i++) {
+			/* add up i-th component size, rounding up to 4 bytes */
+			offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
+		}
+
+		/* calculate idx-th component data address */
+		*img_data = tmp_img_data + offset;
+	} else {
+		*len = 0;
+		*img_data = 0;
+	}
+}
+
+static void image_print_type(const image_header_t *hdr)
+{
+	const char *os, *arch, *type, *comp;
+
+	os = image_get_os_name(image_get_os(hdr));
+	arch = image_get_arch_name(image_get_arch(hdr));
+	type = image_get_type_name(image_get_type(hdr));
+	comp = image_get_comp_name(image_get_comp(hdr));
+
+	printf ("%s %s %s (%s)\n", arch, os, type, comp);
+}
+
+static void image_print_time(time_t timestamp)
+{
+	printf("%s", ctime(&timestamp));
+}
+
+static void image_print_size(uint32_t size)
+{
+	printf("%d Bytes = %.2f kB = %.2f MB\n",
+			size, (double)size / 1.024e3,
+			(double)size / 1.048576e6);
+}
+
+static void image_print_contents(const image_header_t *hdr, void *data)
+{
+	int type;
+
+	printf("Image Name:   %.*s\n", IH_NMLEN, image_get_name(hdr));
+	printf("Created:      ");
+	image_print_time((time_t)image_get_time(hdr));
+	printf ("Image Type:   ");
+	image_print_type(hdr);
+	printf ("Data Size:    ");
+	image_print_size(image_get_data_size(hdr));
+	printf ("Load Address: %08x\n", image_get_load(hdr));
+	printf ("Entry Point:  %08x\n", image_get_ep(hdr));
+
+	type = image_get_type(hdr);
+	if (data && (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT)) {
+		int i;
+		ulong img_data, len;
+		ulong count = image_multi_count(data);
+
+		printf ("Contents:\n");
+		for (i = 0; i < count; i++) {
+			image_multi_getimg(data, i, &img_data, &len);
+
+			printf("   Image %d: ", i);
+			image_print_size(len);
+
+			if (image_get_type(hdr) != IH_TYPE_SCRIPT && i > 0) {
+				/*
+				 * the user may need to know offsets
+				 * if planning to do something with
+				 * multiple files
+				 */
+				printf("    Offset = 0x%08lx\n", img_data);
+			}
+		}
+	}
+}
+
 int
 main (int argc, char **argv)
 {
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-12-15 10:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 10:30 reimplement bootm support Sascha Hauer
2011-12-15 10:30 ` [PATCH 01/12] oftree: add of_fix_tree() Sascha Hauer
2011-12-18 13:07   ` *** PROBABLY SPAM *** " Jean-Christophe PLAGNIOL-VILLARD
2011-12-19 10:31     ` Sascha Hauer
2011-12-20 14:03       ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-23 17:14         ` Sascha Hauer
2011-12-25  6:09           ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-02 11:49             ` Sascha Hauer
2011-12-15 10:30 ` [PATCH 02/12] filetype: Add oftree detection Sascha Hauer
2011-12-15 10:30 ` [PATCH 03/12] uncompress: implement uncompress_fd_to_buf Sascha Hauer
2011-12-15 10:30 ` [PATCH 04/12] libbb: add read_full/write_full functions Sascha Hauer
2011-12-15 10:30 ` [PATCH 05/12] ARM: call start_linux directly with initrd start/size and oftree Sascha Hauer
2011-12-15 10:30 ` [PATCH 06/12] reimplement uImage code Sascha Hauer
2011-12-15 13:33   ` *** PROBABLY SPAM *** " Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 15:27     ` Sascha Hauer
2011-12-15 16:20       ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 16:39         ` Sascha Hauer
2011-12-15 10:30 ` [PATCH 07/12] bootm: use new uimage code Sascha Hauer
2011-12-15 10:30 ` [PATCH 08/12] add uimage command Sascha Hauer
2011-12-15 10:30 ` [PATCH 09/12] remove now obsolete iminfo command Sascha Hauer
2011-12-15 10:30 ` [PATCH 10/12] remove now unused uImage code Sascha Hauer
2011-12-15 10:30 ` Sascha Hauer [this message]
2011-12-15 10:30 ` [PATCH 12/12] defaultenv: simplify boot Sascha Hauer
2011-12-15 13:37 ` *** PROBABLY SPAM *** reimplement bootm support Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 14:47   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323945034-19687-12-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox