All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartlomiej Sieka <tur@semihalf.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH 3/6] [new uImage] Add gen_get_image() routine
Date: Wed, 20 Feb 2008 18:20:09 +0100	[thread overview]
Message-ID: <20080220172009.25624.30095.stgit@pollux.denx.de> (raw)
In-Reply-To: <20080220171950.25624.71201.stgit@pollux.denx.de>

From: Marian Balakowicz <m8@semihalf.com>

This routine assures that image (whether legacy or FIT) is not
in a special dataflash storage.

If image address is a dataflash address image is moved to system RAM.

Signed-off-by: Marian Balakowicz <m8@semihalf.com>
---

 common/cmd_bootm.c |   22 +--------
 common/image.c     |  124 +++++++++++++++++++++++++++++++++++++++++++---------
 include/image.h    |    6 +++
 lib_ppc/bootm.c    |    5 ++
 4 files changed, 117 insertions(+), 40 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 2ddb191..ebb6b69 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -44,10 +44,6 @@
 #include <hush.h>
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-#include <dataflash.h>
-#endif
-
 DECLARE_GLOBAL_DATA_PTR;
 
 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
@@ -304,12 +300,8 @@ static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
 	show_boot_progress (1);
 	printf ("## Booting image at %08lx ...\n", img_addr);
 
-#ifdef CONFIG_HAS_DATAFLASH
-	if (addr_dataflash (img_addr)){
-		hdr = (image_header_t *)CFG_LOAD_ADDR;
-		read_dataflash (img_addr, image_get_header_size (), (char *)hdr);
-	} else
-#endif
+	/* copy from dataflash if needed */
+	img_addr = gen_get_image (img_addr);
 	hdr = (image_header_t *)img_addr;
 
 	if (!image_check_magic(hdr)) {
@@ -324,16 +316,8 @@ static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
 		show_boot_progress (-2);
 		return NULL;
 	}
-	show_boot_progress (3);
 
-#ifdef CONFIG_HAS_DATAFLASH
-	if (addr_dataflash (img_addr))
-		read_dataflash (img_addr + image_get_header_size (),
-				image_get_data_size (hdr),
-				(char *)image_get_data (hdr));
-#endif
-
-	/* uImage is in a system RAM, pointed to by hdr */
+	show_boot_progress (3);
 	print_image_hdr (hdr);
 
 	if (verify) {
diff --git a/common/image.c b/common/image.c
index 39e5f23..8d5ca4e 100644
--- a/common/image.c
+++ b/common/image.c
@@ -41,6 +41,12 @@
 #include <logbuff.h>
 #endif
 
+#if defined(CONFIG_FIT)
+#include <fdt.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+#endif
+
 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 
 #ifdef CONFIG_CMD_BDI
@@ -305,6 +311,101 @@ const char* image_get_comp_name (uint8_t comp)
 }
 
 /**
+ * gen_image_get_format - get image format type
+ * @img_addr: image start address
+ *
+ * gen_image_get_format() checks whether provided address points to a valid
+ * legacy or FIT image.
+ *
+ * returns:
+ *     image format type or IMAGE_FORMAT_INVALID if no image is present
+ */
+int gen_image_get_format (void *img_addr)
+{
+	ulong		format = IMAGE_FORMAT_INVALID;
+	image_header_t	*hdr;
+#if defined(CONFIG_FIT)
+	char		*fit_hdr;
+#endif
+
+	hdr = (image_header_t *)img_addr;
+	if (image_check_magic(hdr))
+		format = IMAGE_FORMAT_LEGACY;
+#if defined(CONFIG_FIT)
+	else {
+		fit_hdr = (char *)img_addr;
+		if (fdt_check_header (fit_hdr) == 0)
+			format = IMAGE_FORMAT_FIT;
+	}
+#endif
+
+	return format;
+}
+
+/**
+ * gen_get_image - get image from special storage (if necessary)
+ * @img_addr: image start address
+ *
+ * gen_get_image() checks if provided image start adddress is located
+ * in a dataflash storage. If so, image is moved to a system RAM memory.
+ *
+ * returns:
+ *     image start address after possible relocation from special storage
+ */
+ulong gen_get_image (ulong img_addr)
+{
+	ulong ram_addr, h_size, d_size;
+
+	h_size = image_get_header_size ();
+#if defined(CONFIG_FIT)
+	if (sizeof(struct fdt_header) > h_size)
+		h_size = sizeof(struct fdt_header);
+#endif
+
+#ifdef CONFIG_HAS_DATAFLASH
+	if (addr_dataflash (img_addr)){
+		ram_addr = CFG_LOAD_ADDR;
+		debug ("   Reading image header from dataflash address "
+			"%08lx to RAM address %08lx\n", img_addr, ram_addr);
+		read_dataflash (img_addr, h_size, (char *)ram_addr);
+	} else
+#endif
+	ram_addr = img_addr;
+
+	switch (gen_image_get_format ((void *)ram_addr)) {
+	case IMAGE_FORMAT_LEGACY:
+		d_size = image_get_data_size ((image_header_t *)ram_addr);
+		debug ("   Legacy format image found at 0x%08lx, size 0x%08lx\n",
+				ram_addr, d_size);
+		break;
+#if defined(CONFIG_FIT)
+	case IMAGE_FORMAT_FIT:
+		d_size = fdt_totalsize((void *)ram_addr) - h_size;
+		debug ("   FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
+				ram_addr, d_size);
+
+		break;
+#endif
+	default:
+		printf ("   No valid image found at 0x%08lx\n", img_addr);
+		return ram_addr;
+	}
+
+#ifdef CONFIG_HAS_DATAFLASH
+	if (addr_dataflash (img_addr)) {
+		debug ("   Reading image remaining data from dataflash address "
+			"%08lx to RAM address %08lx\n", img_addr + h_size,
+			ram_addr + h_size);
+
+		read_dataflash (img_addr + h_size, d_size,
+				(char *)(ram_addr + h_size));
+	}
+#endif
+
+	return ram_addr;
+}
+
+/**
  * image_get_ramdisk - get and verify ramdisk image
  * @cmdtp: command table pointer
  * @flag: command flag
@@ -334,15 +435,8 @@ image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
 
 	show_boot_progress (9);
 
-#ifdef CONFIG_HAS_DATAFLASH
-	if (addr_dataflash (rd_addr)) {
-		rd_hdr = (image_header_t *)CFG_LOAD_ADDR;
-		debug ("   Reading Ramdisk image header from dataflash address "
-			"%08lx to %08lx\n", rd_addr, (ulong)rd_hdr);
-		read_dataflash (rd_addr, image_get_header_size (),
-				(char *)rd_hdr);
-	} else
-#endif
+	/* copy from dataflash if needed */
+	rd_addr = gen_get_image (rd_addr);
 	rd_hdr = (image_header_t *)rd_addr;
 
 	if (!image_check_magic (rd_hdr)) {
@@ -360,18 +454,6 @@ image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
 	show_boot_progress (10);
 	print_image_hdr (rd_hdr);
 
-#ifdef CONFIG_HAS_DATAFLASH
-	if (addr_dataflash (rd_addr)) {
-		debug ("   Reading Ramdisk image data from dataflash address "
-			"%08lx to %08lx\n", rd_addr + image_get_header_size,
-			(ulong)image_get_data (rd_hdr));
-
-		read_dataflash (rd_addr + image_get_header_size (),
-				image_get_data_size (rd_hdr),
-				(char *)image_get_data (rd_hdr));
-	}
-#endif
-
 	if (verify) {
 		puts("   Verifying Checksum ... ");
 		if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
diff --git a/include/image.h b/include/image.h
index ecfce72..b4de49d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -343,6 +343,12 @@ const char* image_get_arch_name (uint8_t arch);
 const char* image_get_type_name (uint8_t type);
 const char* image_get_comp_name (uint8_t comp);
 
+#define IMAGE_FORMAT_INVALID	0x00
+#define IMAGE_FORMAT_LEGACY	0x01
+#define IMAGE_FORMAT_FIT	0x02
+int gen_image_get_format (void *img_addr);
+ulong gen_get_image (ulong img_addr);
+
 image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
 		int argc, char *argv[],
 		ulong rd_addr, uint8_t arch, int verify);
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c
index 69ec459..04a9665 100644
--- a/lib_ppc/bootm.c
+++ b/lib_ppc/bootm.c
@@ -234,6 +234,11 @@ static ulong get_fdt (ulong alloc_current,
 
 	if(argc > 3) {
 		fdt = (char *)simple_strtoul (argv[3], NULL, 16);
+
+		debug ("## Checking for 'FDT'/'FDT image' at %08lx\n", fdt);
+
+		/* copy from dataflash if needed */
+		fdt = (char *)gen_get_image ((ulong)fdt);
 		fdt_hdr = (image_header_t *)fdt;
 
 		if (fdt_check_header (fdt) == 0) {

  parent reply	other threads:[~2008-02-20 17:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20 17:19 [U-Boot-Users] [PATCH 0/6] [new uImage] patchset4 - assorted patches Bartlomiej Sieka
2008-02-20 17:19 ` [U-Boot-Users] [PATCH 1/6] [new uImage] Pull in libfdt if CONFIG_FIT is enabled Bartlomiej Sieka
2008-02-20 17:20 ` [U-Boot-Users] [PATCH 2/6] [libfdt] Fix compilation errors is fdt_support.c Bartlomiej Sieka
2008-02-20 17:33   ` Jerry Van Baren
2008-02-20 19:10   ` Kumar Gala
2008-02-20 20:36     ` Bartlomiej Sieka
2008-02-20 17:20 ` Bartlomiej Sieka [this message]
2008-02-20 19:19   ` [U-Boot-Users] [PATCH 3/6] [new uImage] Add gen_get_image() routine Kumar Gala
2008-02-20 20:38     ` Bartlomiej Sieka
2008-02-20 20:44       ` Kumar Gala
2008-02-21 15:57         ` Bartlomiej Sieka
2008-02-20 17:20 ` [U-Boot-Users] [PATCH 4/6] [new uImage] Add fit_parse_conf() and fit_parse_subimage() routines Bartlomiej Sieka
2008-02-20 19:27   ` Kumar Gala
2008-02-20 20:39     ` Bartlomiej Sieka
2008-02-20 17:20 ` [U-Boot-Users] [PATCH 5/6] [new uImage] Rename and move print_image_hdr() routine Bartlomiej Sieka
2008-02-20 17:20 ` [U-Boot-Users] [PATCH 6/6] [new uImage] Fix erroneous use of image_get_magic() in fdc/usb cmds Bartlomiej Sieka

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=20080220172009.25624.30095.stgit@pollux.denx.de \
    --to=tur@semihalf.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.