[new uImage] Update naming convention for bootm/uImage related code

This patch introduces the following prefix convention for the
image format handling and bootm related code:

genimg_		- dual format shared code
image_		- legacy uImage format specific code
fit_		- new uImage format specific code
boot_		- booting process related code

Related routines are renamed and a few pieces of code are moved around and
re-grouped.

Signed-off-by: Marian Balakowicz <m8@semihalf.com>
diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c
index f9ab1d9..60ffc7d 100644
--- a/common/cmd_autoscript.c
+++ b/common/cmd_autoscript.c
@@ -61,7 +61,7 @@
 
 	verify = getenv_verify ();
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
@@ -90,7 +90,7 @@
 		/* get length of script */
 		data = (ulong *)image_get_data (hdr);
 
-		if ((len = image_to_cpu (*data)) == 0) {
+		if ((len = uimage_to_cpu (*data)) == 0) {
 			puts ("Empty Script\n");
 			return 1;
 		}
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 8595ef6..10403aa 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -66,7 +66,7 @@
 static void fixup_silent_linux (void);
 #endif
 
-static void *get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
+static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
 		bootm_headers_t *images, ulong *os_data, ulong *os_len);
 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 
@@ -143,7 +143,7 @@
 	board_lmb_reserve(&lmb);
 
 	/* get kernel image header, start address and length */
-	os_hdr = get_kernel (cmdtp, flag, argc, argv,
+	os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
 			&images, &os_data, &os_len);
 	if (os_len == 0)
 		return 1;
@@ -151,7 +151,7 @@
 	show_boot_progress (6);
 
 	/* get image parameters */
-	switch (gen_image_get_format (os_hdr)) {
+	switch (genimg_get_format (os_hdr)) {
 	case IMAGE_FORMAT_LEGACY:
 		type = image_get_type (os_hdr);
 		comp = image_get_comp (os_hdr);
@@ -172,7 +172,7 @@
 
 	image_start = (ulong)os_hdr;
 	load_end = 0;
-	type_name = image_get_type_name (type);
+	type_name = genimg_get_type_name (type);
 
 	/*
 	 * We have reached the point of no return: we are going to
@@ -309,16 +309,16 @@
 }
 
 /**
- * get_kernel - find kernel image
- * @os_data: pointer to a ulong variable, will hold os data start address
- * @os_len: pointer to a ulong variable, will hold os data length
+ * image_get_kernel - verify legacy format kernel image
+ * @img_addr: in RAM address of the legacy format image to be verified
+ * @verify: data CRC verification flag
  *
- * get_kernel() tries to find a kernel image, verifies its integrity
- * and locates kernel data.
+ * image_get_kernel() verifies legacy image integrity and returns pointer to
+ * legacy image header if image verification was completed successfully.
  *
  * returns:
- *     pointer to image header if valid image was found, plus kernel start
- *     address and length, otherwise NULL
+ *     pointer to a legacy image header if valid image was found
+ *     otherwise return NULL
  */
 static image_header_t *image_get_kernel (ulong img_addr, int verify)
 {
@@ -360,18 +360,18 @@
 }
 
 /**
- * get_kernel - find kernel image
+ * boot_get_kernel - find kernel image
  * @os_data: pointer to a ulong variable, will hold os data start address
  * @os_len: pointer to a ulong variable, will hold os data length
  *
- * get_kernel() tries to find a kernel image, verifies its integrity
+ * boot_get_kernel() tries to find a kernel image, verifies its integrity
  * and locates kernel data.
  *
  * returns:
  *     pointer to image header if valid image was found, plus kernel start
  *     address and length, otherwise NULL
  */
-static void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		bootm_headers_t *images, ulong *os_data, ulong *os_len)
 {
 	image_header_t	*hdr;
@@ -406,10 +406,10 @@
 	printf ("## Booting kernel image at %08lx ...\n", img_addr);
 
 	/* copy from dataflash if needed */
-	img_addr = gen_get_image (img_addr);
+	img_addr = genimg_get_image (img_addr);
 
 	/* check image type, for FIT images get FIT kernel node */
-	switch (gen_image_get_format ((void *)img_addr)) {
+	switch (genimg_get_format ((void *)img_addr)) {
 	case IMAGE_FORMAT_LEGACY:
 
 		debug ("*  kernel: legacy format image\n");
@@ -531,7 +531,7 @@
 
 	printf ("\n## Checking Image at %08lx ...\n", addr);
 
-	switch (gen_image_get_format (hdr)) {
+	switch (genimg_get_format (hdr)) {
 	case IMAGE_FORMAT_LEGACY:
 		puts ("   Legacy image found\n");
 		if (!image_check_magic (hdr)) {
@@ -599,7 +599,7 @@
 			if (!hdr)
 				goto next_sector;
 
-			switch (gen_image_get_format (hdr)) {
+			switch (genimg_get_format (hdr)) {
 			case IMAGE_FORMAT_LEGACY:
 				if (!image_check_magic (hdr))
 					goto next_sector;
diff --git a/common/cmd_doc.c b/common/cmd_doc.c
index 3358b04..293b1aa 100644
--- a/common/cmd_doc.c
+++ b/common/cmd_doc.c
@@ -261,7 +261,7 @@
 	}
 	show_boot_progress (38);
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c
index b6e023a..80301b9 100644
--- a/common/cmd_fdc.c
+++ b/common/cmd_fdc.c
@@ -836,7 +836,7 @@
 		return 1;
 	}
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 		if (!image_check_magic (hdr)) {
diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c
index 10199f5..0bb82f6 100644
--- a/common/cmd_fpga.c
+++ b/common/cmd_fpga.c
@@ -216,7 +216,7 @@
 		break;
 
 	case FPGA_LOADMK:
-		switch (gen_image_get_format (fpga_data)) {
+		switch (genimg_get_format (fpga_data)) {
 		case IMAGE_FORMAT_LEGACY:
 			{
 				image_header_t *hdr = (image_header_t *)fpga_data;
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index bef04db..79b7dfb 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -446,7 +446,7 @@
 	}
 	show_boot_progress (48);
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index b099afe..86959dc 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -512,7 +512,7 @@
 	}
 	show_boot_progress (56);
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
@@ -994,7 +994,7 @@
 	}
 	show_boot_progress (56);
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index 42b3072..7868805 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -273,7 +273,7 @@
 		return 1;
 	}
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index ad3873c..8ee7d27 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -386,7 +386,7 @@
 		return 1;
 	}
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 		hdr = (image_header_t *)addr;
 
diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c
index 4dadc37..360b05e 100644
--- a/common/cmd_ximg.c
+++ b/common/cmd_ximg.c
@@ -57,7 +57,7 @@
 	}
 
 
-	switch (gen_image_get_format ((void *)addr)) {
+	switch (genimg_get_format ((void *)addr)) {
 	case IMAGE_FORMAT_LEGACY:
 
 		printf("## Copying from legacy image at %08lx ...\n", addr);
@@ -104,7 +104,7 @@
 			data += 4;
 			if (argc > 2 && part > i) {
 				u_long tail;
-				len = image_to_cpu (len_ptr[i]);
+				len = uimage_to_cpu (len_ptr[i]);
 				tail = len % 4;
 				data += len;
 				if (tail) {
@@ -116,7 +116,7 @@
 			printf("Bad Image Part\n");
 			return 1;
 		}
-		len = image_to_cpu (len_ptr[part]);
+		len = uimage_to_cpu (len_ptr[part]);
 #if defined(CONFIG_FIT)
 	case IMAGE_FORMAT_FIT:
 		fit_unsupported ("imxtract");
diff --git a/common/image.c b/common/image.c
index 9e446fa..99ed3b8 100644
--- a/common/image.c
+++ b/common/image.c
@@ -68,6 +68,9 @@
 
 unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
 
+/*****************************************************************************/
+/* Legacy format routines */
+/*****************************************************************************/
 int image_check_hcrc (image_header_t *hdr)
 {
 	ulong hcrc;
@@ -120,61 +123,6 @@
 	return (dcrc == image_get_dcrc (hdr));
 }
 
-int getenv_verify (void)
-{
-	char *s = getenv ("verify");
-	return (s && (*s == 'n')) ? 0 : 1;
-}
-
-int getenv_autostart (void)
-{
-	char *s = getenv ("autostart");
-	return (s && (*s == 'n')) ? 0 : 1;
-}
-
-ulong getenv_bootm_low(void)
-{
-	char *s = getenv ("bootm_low");
-	if (s) {
-		ulong tmp = simple_strtoul (s, NULL, 16);
-		return tmp;
-	}
-
-#ifdef CFG_SDRAM_BASE
-	return CFG_SDRAM_BASE;
-#else
-	return 0;
-#endif
-}
-
-ulong getenv_bootm_size(void)
-{
-	char *s = getenv ("bootm_size");
-	if (s) {
-		ulong tmp = simple_strtoul (s, NULL, 16);
-		return tmp;
-	}
-
-	return gd->bd->bi_memsize;
-}
-
-void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
-{
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	while (len > 0) {
-		size_t tail = (len > chunksz) ? chunksz : len;
-		WATCHDOG_RESET ();
-		memmove (to, from, tail);
-		to += tail;
-		from += tail;
-		len -= tail;
-	}
-#else	/* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
-	memmove (to, from, len);
-#endif	/* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
-}
-#endif /* USE_HOSTCC */
-
 /**
  * image_multi_count - get component (sub-image) count
  * @hdr: pointer to the header of the multi component image
@@ -262,100 +210,14 @@
 }
 
 #ifndef USE_HOSTCC
-const char* image_get_os_name (uint8_t os)
-{
-	const char *name;
-
-	switch (os) {
-	case IH_OS_INVALID:	name = "Invalid OS";		break;
-	case IH_OS_NETBSD:	name = "NetBSD";		break;
-	case IH_OS_LINUX:	name = "Linux";			break;
-	case IH_OS_VXWORKS:	name = "VxWorks";		break;
-	case IH_OS_QNX:		name = "QNX";			break;
-	case IH_OS_U_BOOT:	name = "U-Boot";		break;
-	case IH_OS_RTEMS:	name = "RTEMS";			break;
-#ifdef CONFIG_ARTOS
-	case IH_OS_ARTOS:	name = "ARTOS";			break;
-#endif
-#ifdef CONFIG_LYNXKDI
-	case IH_OS_LYNXOS:	name = "LynxOS";		break;
-#endif
-	default:		name = "Unknown OS";		break;
-	}
-
-	return name;
-}
-
-const char* image_get_arch_name (uint8_t arch)
-{
-	const char *name;
-
-	switch (arch) {
-	case IH_ARCH_INVALID:	name = "Invalid Architecture";	break;
-	case IH_ARCH_ALPHA:	name = "Alpha";			break;
-	case IH_ARCH_ARM:	name = "ARM";			break;
-	case IH_ARCH_AVR32:	name = "AVR32";			break;
-	case IH_ARCH_BLACKFIN:	name = "Blackfin";		break;
-	case IH_ARCH_I386:	name = "Intel x86";		break;
-	case IH_ARCH_IA64:	name = "IA64";			break;
-	case IH_ARCH_M68K:	name = "M68K"; 			break;
-	case IH_ARCH_MICROBLAZE:name = "Microblaze"; 		break;
-	case IH_ARCH_MIPS64:	name = "MIPS 64 Bit";		break;
-	case IH_ARCH_MIPS:	name = "MIPS";			break;
-	case IH_ARCH_NIOS2:	name = "Nios-II";		break;
-	case IH_ARCH_NIOS:	name = "Nios";			break;
-	case IH_ARCH_PPC:	name = "PowerPC";		break;
-	case IH_ARCH_S390:	name = "IBM S390";		break;
-	case IH_ARCH_SH:	name = "SuperH";		break;
-	case IH_ARCH_SPARC64:	name = "SPARC 64 Bit";		break;
-	case IH_ARCH_SPARC:	name = "SPARC";			break;
-	default:		name = "Unknown Architecture";	break;
-	}
-
-	return name;
-}
-
-const char* image_get_type_name (uint8_t type)
-{
-	const char *name;
-
-	switch (type) {
-	case IH_TYPE_INVALID:	name = "Invalid Image";		break;
-	case IH_TYPE_STANDALONE:name = "Standalone Program";	break;
-	case IH_TYPE_KERNEL:	name = "Kernel Image";		break;
-	case IH_TYPE_RAMDISK:	name = "RAMDisk Image";		break;
-	case IH_TYPE_MULTI:	name = "Multi-File Image";	break;
-	case IH_TYPE_FIRMWARE:	name = "Firmware";		break;
-	case IH_TYPE_SCRIPT:	name = "Script";		break;
-	case IH_TYPE_FLATDT:	name = "Flat Device Tree";	break;
-	default:		name = "Unknown Image";		break;
-	}
-
-	return name;
-}
-
-const char* image_get_comp_name (uint8_t comp)
-{
-	const char *name;
-
-	switch (comp) {
-	case IH_COMP_NONE:	name = "uncompressed";		break;
-	case IH_COMP_GZIP:	name = "gzip compressed";	break;
-	case IH_COMP_BZIP2:	name = "bzip2 compressed";	break;
-	default:		name = "unknown compression";	break;
-	}
-
-	return name;
-}
-
 static void image_print_type (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));
+	os = genimg_get_os_name (image_get_os (hdr));
+	arch = genimg_get_arch_name (image_get_arch (hdr));
+	type = genimg_get_type_name (image_get_type (hdr));
+	comp = genimg_get_comp_name (image_get_comp (hdr));
 
 	printf ("%s %s %s (%s)", arch, os, type, comp);
 }
@@ -399,109 +261,6 @@
 }
 
 /**
- * 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.
- *
- * New uImage format and FDT blob are based on a libfdt. FDT blob
- * may be passed directly or embedded in a FIT image. In both situations
- * gen_image_get_format() must be able to dectect libfdt header.
- *
- * 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) || defined(CONFIG_OF_LIBFDT)
-	char		*fit_hdr;
-#endif
-
-	hdr = (image_header_t *)img_addr;
-	if (image_check_magic(hdr))
-		format = IMAGE_FORMAT_LEGACY;
-#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
-	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 = img_addr;
-
-#ifdef CONFIG_HAS_DATAFLASH
-	ulong h_size, d_size;
-
-	if (addr_dataflash (img_addr)){
-		/* ger RAM address */
-		ram_addr = CFG_LOAD_ADDR;
-
-		/* get header 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
-
-		/* read in header */
-		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);
-
-		/* get data size */
-		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;
-		}
-
-		/* read in image data */
-		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 /* CONFIG_HAS_DATAFLASH */
-
-	return ram_addr;
-}
-
-/**
  * image_get_ramdisk - get and verify ramdisk image
  * @cmdtp: command table pointer
  * @flag: command flag
@@ -563,7 +322,7 @@
 	    !image_check_arch (rd_hdr, arch) ||
 	    !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
 		printf ("No Linux %s Ramdisk Image\n",
-				image_get_arch_name(arch));
+				genimg_get_arch_name(arch));
 		show_boot_progress (-13);
 		return NULL;
 	}
@@ -571,8 +330,255 @@
 	return rd_hdr;
 }
 
+/*****************************************************************************/
+/* Shared dual-format routines */
+/*****************************************************************************/
+int getenv_verify (void)
+{
+	char *s = getenv ("verify");
+	return (s && (*s == 'n')) ? 0 : 1;
+}
+
+int getenv_autostart (void)
+{
+	char *s = getenv ("autostart");
+	return (s && (*s == 'n')) ? 0 : 1;
+}
+
+ulong getenv_bootm_low(void)
+{
+	char *s = getenv ("bootm_low");
+	if (s) {
+		ulong tmp = simple_strtoul (s, NULL, 16);
+		return tmp;
+	}
+
+#ifdef CFG_SDRAM_BASE
+	return CFG_SDRAM_BASE;
+#else
+	return 0;
+#endif
+}
+
+ulong getenv_bootm_size(void)
+{
+	char *s = getenv ("bootm_size");
+	if (s) {
+		ulong tmp = simple_strtoul (s, NULL, 16);
+		return tmp;
+	}
+
+	return gd->bd->bi_memsize;
+}
+
+void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
+{
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+	while (len > 0) {
+		size_t tail = (len > chunksz) ? chunksz : len;
+		WATCHDOG_RESET ();
+		memmove (to, from, tail);
+		to += tail;
+		from += tail;
+		len -= tail;
+	}
+#else	/* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
+	memmove (to, from, len);
+#endif	/* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
+}
+#endif /* USE_HOSTCC */
+
+const char* genimg_get_os_name (uint8_t os)
+{
+	const char *name;
+
+	switch (os) {
+	case IH_OS_INVALID:	name = "Invalid OS";		break;
+	case IH_OS_NETBSD:	name = "NetBSD";		break;
+	case IH_OS_LINUX:	name = "Linux";			break;
+	case IH_OS_VXWORKS:	name = "VxWorks";		break;
+	case IH_OS_QNX:		name = "QNX";			break;
+	case IH_OS_U_BOOT:	name = "U-Boot";		break;
+	case IH_OS_RTEMS:	name = "RTEMS";			break;
+#ifdef CONFIG_ARTOS
+	case IH_OS_ARTOS:	name = "ARTOS";			break;
+#endif
+#ifdef CONFIG_LYNXKDI
+	case IH_OS_LYNXOS:	name = "LynxOS";		break;
+#endif
+	default:		name = "Unknown OS";		break;
+	}
+
+	return name;
+}
+
+const char* genimg_get_arch_name (uint8_t arch)
+{
+	const char *name;
+
+	switch (arch) {
+	case IH_ARCH_INVALID:	name = "Invalid Architecture";	break;
+	case IH_ARCH_ALPHA:	name = "Alpha";			break;
+	case IH_ARCH_ARM:	name = "ARM";			break;
+	case IH_ARCH_AVR32:	name = "AVR32";			break;
+	case IH_ARCH_BLACKFIN:	name = "Blackfin";		break;
+	case IH_ARCH_I386:	name = "Intel x86";		break;
+	case IH_ARCH_IA64:	name = "IA64";			break;
+	case IH_ARCH_M68K:	name = "M68K"; 			break;
+	case IH_ARCH_MICROBLAZE:name = "Microblaze"; 		break;
+	case IH_ARCH_MIPS64:	name = "MIPS 64 Bit";		break;
+	case IH_ARCH_MIPS:	name = "MIPS";			break;
+	case IH_ARCH_NIOS2:	name = "Nios-II";		break;
+	case IH_ARCH_NIOS:	name = "Nios";			break;
+	case IH_ARCH_PPC:	name = "PowerPC";		break;
+	case IH_ARCH_S390:	name = "IBM S390";		break;
+	case IH_ARCH_SH:	name = "SuperH";		break;
+	case IH_ARCH_SPARC64:	name = "SPARC 64 Bit";		break;
+	case IH_ARCH_SPARC:	name = "SPARC";			break;
+	default:		name = "Unknown Architecture";	break;
+	}
+
+	return name;
+}
+
+const char* genimg_get_type_name (uint8_t type)
+{
+	const char *name;
+
+	switch (type) {
+	case IH_TYPE_INVALID:	name = "Invalid Image";		break;
+	case IH_TYPE_STANDALONE:name = "Standalone Program";	break;
+	case IH_TYPE_KERNEL:	name = "Kernel Image";		break;
+	case IH_TYPE_RAMDISK:	name = "RAMDisk Image";		break;
+	case IH_TYPE_MULTI:	name = "Multi-File Image";	break;
+	case IH_TYPE_FIRMWARE:	name = "Firmware";		break;
+	case IH_TYPE_SCRIPT:	name = "Script";		break;
+	case IH_TYPE_FLATDT:	name = "Flat Device Tree";	break;
+	default:		name = "Unknown Image";		break;
+	}
+
+	return name;
+}
+
+const char* genimg_get_comp_name (uint8_t comp)
+{
+	const char *name;
+
+	switch (comp) {
+	case IH_COMP_NONE:	name = "uncompressed";		break;
+	case IH_COMP_GZIP:	name = "gzip compressed";	break;
+	case IH_COMP_BZIP2:	name = "bzip2 compressed";	break;
+	default:		name = "unknown compression";	break;
+	}
+
+	return name;
+}
+
 /**
- * get_ramdisk - main ramdisk handling routine
+ * genimg_get_format - get image format type
+ * @img_addr: image start address
+ *
+ * genimg_get_format() checks whether provided address points to a valid
+ * legacy or FIT image.
+ *
+ * New uImage format and FDT blob are based on a libfdt. FDT blob
+ * may be passed directly or embedded in a FIT image. In both situations
+ * genimg_get_format() must be able to dectect libfdt header.
+ *
+ * returns:
+ *     image format type or IMAGE_FORMAT_INVALID if no image is present
+ */
+int genimg_get_format (void *img_addr)
+{
+	ulong		format = IMAGE_FORMAT_INVALID;
+	image_header_t	*hdr;
+#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
+	char		*fit_hdr;
+#endif
+
+	hdr = (image_header_t *)img_addr;
+	if (image_check_magic(hdr))
+		format = IMAGE_FORMAT_LEGACY;
+#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
+	else {
+		fit_hdr = (char *)img_addr;
+		if (fdt_check_header (fit_hdr) == 0)
+			format = IMAGE_FORMAT_FIT;
+	}
+#endif
+
+	return format;
+}
+
+/**
+ * genimg_get_image - get image from special storage (if necessary)
+ * @img_addr: image start address
+ *
+ * genimg_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 genimg_get_image (ulong img_addr)
+{
+	ulong ram_addr = img_addr;
+
+#ifdef CONFIG_HAS_DATAFLASH
+	ulong h_size, d_size;
+
+	if (addr_dataflash (img_addr)){
+		/* ger RAM address */
+		ram_addr = CFG_LOAD_ADDR;
+
+		/* get header 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
+
+		/* read in header */
+		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);
+
+		/* get data size */
+		switch (genimg_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;
+		}
+
+		/* read in image data */
+		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 /* CONFIG_HAS_DATAFLASH */
+
+	return ram_addr;
+}
+
+/**
+ * boot_get_ramdisk - main ramdisk handling routine
  * @cmdtp: command table pointer
  * @flag: command flag
  * @argc: command argument count
@@ -582,7 +588,7 @@
  * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  * @rd_end: pointer to a ulong variable, will hold ramdisk end
  *
- * get_ramdisk() is responsible for finding a valid ramdisk image.
+ * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
  * Curently supported are the following ramdisk sources:
  *      - multicomponent kernel/ramdisk image,
  *      - commandline provided address of decicated ramdisk image.
@@ -593,7 +599,7 @@
  *     rd_start and rd_end are set to 0 if no ramdisk exists
  *     return 1 if ramdisk image is found but corrupted
  */
-int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		bootm_headers_t *images, uint8_t arch,
 		ulong *rd_start, ulong *rd_end)
 {
@@ -645,14 +651,14 @@
 		/* copy from dataflash if needed */
 		printf ("## Loading init Ramdisk Image at %08lx ...\n",
 				rd_addr);
-		rd_addr = gen_get_image (rd_addr);
+		rd_addr = genimg_get_image (rd_addr);
 
 		/*
 		 * Check if there is an initrd image at the
 		 * address provided in the second bootm argument
 		 * check image type, for FIT images get FIT node.
 		 */
-		switch (gen_image_get_format ((void *)rd_addr)) {
+		switch (genimg_get_format ((void *)rd_addr)) {
 		case IMAGE_FORMAT_LEGACY:
 
 			debug ("*  ramdisk: legacy format image\n");
@@ -729,7 +735,7 @@
 
 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
 /**
- * ramdisk_high - relocate init ramdisk
+ * boot_ramdisk_high - relocate init ramdisk
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @rd_data: ramdisk data start address
  * @rd_len: ramdisk data length
@@ -738,18 +744,18 @@
  * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  *      end address (after possible relocation)
  *
- * ramdisk_high() takes a relocation hint from "initrd_high" environement
+ * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
  * variable and if requested ramdisk data is moved to a specified location.
  *
+ * Initrd_start and initrd_end are set to final (after relocation) ramdisk
+ * start/end addresses if ramdisk image start and len were provided,
+ * otherwise set initrd_start and initrd_end set to zeros.
+ *
  * returns:
- *     - initrd_start and initrd_end are set to final (after relocation) ramdisk
- *     start/end addresses if ramdisk image start and len were provided
- *     otherwise set initrd_start and initrd_end set to zeros
- *     - returns:
- *        0 - success
- *       -1 - failure
+ *      0 - success
+ *     -1 - failure
  */
-int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
+int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
 		  ulong *initrd_start, ulong *initrd_end)
 {
 	char	*s;
@@ -779,12 +785,12 @@
 			lmb_reserve(lmb, rd_data, rd_len);
 		} else {
 			if (initrd_high)
-				*initrd_start = lmb_alloc_base(lmb, rd_len, 0x1000, initrd_high);
+				*initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
 			else
-				*initrd_start = lmb_alloc(lmb, rd_len, 0x1000);
+				*initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
 
 			if (*initrd_start == 0) {
-				puts("ramdisk - allocation error\n");
+				puts ("ramdisk - allocation error\n");
 				goto error;
 			}
 			show_boot_progress (12);
@@ -793,7 +799,7 @@
 			printf ("   Loading Ramdisk to %08lx, end %08lx ... ",
 					*initrd_start, *initrd_end);
 
-			memmove_wd((void *)*initrd_start,
+			memmove_wd ((void *)*initrd_start,
 					(void *)rd_data, rd_len, CHUNKSZ);
 
 			puts ("OK\n");
@@ -804,6 +810,7 @@
 	}
 	debug ("   ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
 			*initrd_start, *initrd_end);
+
 	return 0;
 
 error:
@@ -811,14 +818,14 @@
 }
 
 /**
- * get_boot_cmdline - allocate and initialize kernel cmdline
+ * boot_get_cmdline - allocate and initialize kernel cmdline
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @cmd_start: pointer to a ulong variable, will hold cmdline start
  * @cmd_end: pointer to a ulong variable, will hold cmdline end
  * @bootmap_base: ulong variable, holds offset in physical memory to
  * base of bootmap
  *
- * get_boot_cmdline() allocates space for kernel command line below
+ * boot_get_cmdline() allocates space for kernel command line below
  * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  * variable is present its contents is copied to allocated kernel
  * command line.
@@ -827,7 +834,7 @@
  *      0 - success
  *     -1 - failure
  */
-int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
+int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
 			ulong bootmap_base)
 {
 	char *cmdline;
@@ -853,13 +860,13 @@
 }
 
 /**
- * get_boot_kbd - allocate and initialize kernel copy of board info
+ * boot_get_kbd - allocate and initialize kernel copy of board info
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @kbd: double pointer to board info data
  * @bootmap_base: ulong variable, holds offset in physical memory to
  * base of bootmap
  *
- * get_boot_kbd() allocates space for kernel copy of board info data below
+ * boot_get_kbd() allocates space for kernel copy of board info data below
  * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  * the current u-boot board info data.
  *
@@ -867,7 +874,7 @@
  *      0 - success
  *     -1 - failure
  */
-int get_boot_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
+int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
 {
 	*kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
 				      CFG_BOOTMAPSZ + bootmap_base);