[U-Boot-Users] [PATCH 5/6] [new uImage] Factor out common routines for getting os/arch/type/comp names

Marian Balakowicz m8 at semihalf.com
Wed Jan 23 16:00:29 CET 2008


Move numeric-id to name translation for image os/arch/type/comp header
fields to a helper routines: image_get_os_name(), image_get_arch_name(),
image_get_type_name(), image_get_comp_name().

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

 common/cmd_bootm.c |   77 +++++++----------------------------------------
 common/image.c     |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/image.h    |    5 +++
 3 files changed, 103 insertions(+), 65 deletions(-)


diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 9fccb32..356c8b3 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -116,7 +116,7 @@ ulong load_addr = CFG_LOAD_ADDR;	/* Default Load Address */
 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	ulong		iflag;
-	char		*name;
+	const char	*type_name;
 	uint		unc_len = CFG_BOOTM_LEN;
 	int		verify = getenv_verify();
 
@@ -189,12 +189,10 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 	switch (image_get_type (hdr)) {
 	case IH_TYPE_KERNEL:
-		name = "Kernel Image";
 		os_data = image_get_data (hdr);
 		os_len = image_get_data_size (hdr);
 		break;
 	case IH_TYPE_MULTI:
-		name = "Multi-File Image";
 		image_multi_getimg (hdr, 0, &os_data, &os_len);
 		break;
 	default:
@@ -222,6 +220,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	dcache_disable();
 #endif
 
+	type_name = image_get_type_name (image_get_type (hdr));
+
 	image_start = (ulong)hdr;
 	image_end = image_get_image_end (hdr);
 	load_start = image_get_load (hdr);
@@ -230,9 +230,9 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	switch (image_get_comp (hdr)) {
 	case IH_COMP_NONE:
 		if (image_get_load (hdr) == img_addr) {
-			printf ("   XIP %s ... ", name);
+			printf ("   XIP %s ... ", type_name);
 		} else {
-			printf ("   Loading %s ... ", name);
+			printf ("   Loading %s ... ", type_name);
 
 			memmove_wd ((void *)image_get_load (hdr),
 				   (void *)os_data, os_len, CHUNKSZ);
@@ -242,7 +242,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		}
 		break;
 	case IH_COMP_GZIP:
-		printf ("   Uncompressing %s ... ", name);
+		printf ("   Uncompressing %s ... ", type_name);
 		if (gunzip ((void *)image_get_load (hdr), unc_len,
 					(uchar *)os_data, &os_len) != 0) {
 			puts ("GUNZIP ERROR - must RESET board to recover\n");
@@ -254,7 +254,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		break;
 #ifdef CONFIG_BZIP2
 	case IH_COMP_BZIP2:
-		printf ("   Uncompressing %s ... ", name);
+		printf ("   Uncompressing %s ... ", type_name);
 		/*
 		 * If we've got less than 4 MB of malloc() space,
 		 * use slower decompression algorithm which requires
@@ -556,65 +556,12 @@ void print_image_hdr (image_header_t *hdr)
 
 static void print_type (image_header_t *hdr)
 {
-	char *os, *arch, *type, *comp;
-
-	switch (image_get_os (hdr)) {
-	case IH_OS_INVALID:	os = "Invalid OS";		break;
-	case IH_OS_NETBSD:	os = "NetBSD";			break;
-	case IH_OS_LINUX:	os = "Linux";			break;
-	case IH_OS_VXWORKS:	os = "VxWorks";			break;
-	case IH_OS_QNX:		os = "QNX";			break;
-	case IH_OS_U_BOOT:	os = "U-Boot";			break;
-	case IH_OS_RTEMS:	os = "RTEMS";			break;
-#ifdef CONFIG_ARTOS
-	case IH_OS_ARTOS:	os = "ARTOS";			break;
-#endif
-#ifdef CONFIG_LYNXKDI
-	case IH_OS_LYNXOS:	os = "LynxOS";			break;
-#endif
-	default:		os = "Unknown OS";		break;
-	}
+	const char *os, *arch, *type, *comp;
 
-	switch (image_get_arch (hdr)) {
-	case IH_ARCH_INVALID:	arch = "Invalid CPU";		break;
-	case IH_ARCH_ALPHA:	arch = "Alpha";			break;
-	case IH_ARCH_ARM:	arch = "ARM";			break;
-	case IH_ARCH_AVR32:	arch = "AVR32";			break;
-	case IH_ARCH_BLACKFIN:	arch = "Blackfin";		break;
-	case IH_ARCH_I386:	arch = "Intel x86";		break;
-	case IH_ARCH_IA64:	arch = "IA64";			break;
-	case IH_ARCH_M68K:	arch = "M68K"; 			break;
-	case IH_ARCH_MICROBLAZE:arch = "Microblaze"; 		break;
-	case IH_ARCH_MIPS64:	arch = "MIPS 64 Bit";		break;
-	case IH_ARCH_MIPS:	arch = "MIPS";			break;
-	case IH_ARCH_NIOS2:	arch = "Nios-II";		break;
-	case IH_ARCH_NIOS:	arch = "Nios";			break;
-	case IH_ARCH_PPC:	arch = "PowerPC";		break;
-	case IH_ARCH_S390:	arch = "IBM S390";		break;
-	case IH_ARCH_SH:	arch = "SuperH";		break;
-	case IH_ARCH_SPARC64:	arch = "SPARC 64 Bit";		break;
-	case IH_ARCH_SPARC:	arch = "SPARC";			break;
-	default:		arch = "Unknown Architecture";	break;
-	}
-
-	switch (image_get_type (hdr)) {
-	case IH_TYPE_INVALID:	type = "Invalid Image";		break;
-	case IH_TYPE_STANDALONE:type = "Standalone Program";	break;
-	case IH_TYPE_KERNEL:	type = "Kernel Image";		break;
-	case IH_TYPE_RAMDISK:	type = "RAMDisk Image";		break;
-	case IH_TYPE_MULTI:	type = "Multi-File Image";	break;
-	case IH_TYPE_FIRMWARE:	type = "Firmware";		break;
-	case IH_TYPE_SCRIPT:	type = "Script";		break;
-	case IH_TYPE_FLATDT:	type = "Flat Device Tree";	break;
-	default:		type = "Unknown Image";		break;
-	}
-
-	switch (image_get_comp (hdr)) {
-	case IH_COMP_NONE:	comp = "uncompressed";		break;
-	case IH_COMP_GZIP:	comp = "gzip compressed";	break;
-	case IH_COMP_BZIP2:	comp = "bzip2 compressed";	break;
-	default:		comp = "unknown compression";	break;
-	}
+	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)", arch, os, type, comp);
 }
diff --git a/common/image.c b/common/image.c
index 6eee83d..9aeca9f 100644
--- a/common/image.c
+++ b/common/image.c
@@ -193,3 +193,89 @@ void image_multi_getimg (image_header_t *hdr, ulong idx,
 		*data = 0;
 	}
 }
+
+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;
+}
diff --git a/include/image.h b/include/image.h
index c605d66..87ef5d8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -328,4 +328,9 @@ ulong image_multi_count (image_header_t *hdr);
 void image_multi_getimg (image_header_t *hdr, ulong idx,
 			ulong *data, ulong *len);
 
+const char* image_get_os_name (uint8_t os);
+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);
+
 #endif	/* __IMAGE_H__ */





More information about the U-Boot mailing list