[new uImage] Factor out common routines for getting os/arch/type/comp names

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@semihalf.com>
This commit is contained in:
Marian Balakowicz 2008-01-31 13:20:07 +01:00 committed by Wolfgang Denk
parent e99c26694a
commit 42b73e8ee0
3 changed files with 109 additions and 69 deletions

View file

@ -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[]) int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{ {
ulong iflag; ulong iflag;
char *name; const char *type_name;
uint unc_len = CFG_BOOTM_LEN; uint unc_len = CFG_BOOTM_LEN;
int verify = getenv_verify(); 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)) { switch (image_get_type (hdr)) {
case IH_TYPE_KERNEL: case IH_TYPE_KERNEL:
name = "Kernel Image";
os_data = image_get_data (hdr); os_data = image_get_data (hdr);
os_len = image_get_data_size (hdr); os_len = image_get_data_size (hdr);
break; break;
case IH_TYPE_MULTI: case IH_TYPE_MULTI:
name = "Multi-File Image";
image_multi_getimg (hdr, 0, &os_data, &os_len); image_multi_getimg (hdr, 0, &os_data, &os_len);
break; break;
default: default:
@ -222,6 +220,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
dcache_disable(); dcache_disable();
#endif #endif
type_name = image_get_type_name (image_get_type (hdr));
image_start = (ulong)hdr; image_start = (ulong)hdr;
image_end = image_get_image_end (hdr); image_end = image_get_image_end (hdr);
load_start = image_get_load (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)) { switch (image_get_comp (hdr)) {
case IH_COMP_NONE: case IH_COMP_NONE:
if (image_get_load (hdr) == img_addr) { if (image_get_load (hdr) == img_addr) {
printf (" XIP %s ... ", name); printf (" XIP %s ... ", type_name);
} else { } else {
printf (" Loading %s ... ", name); printf (" Loading %s ... ", type_name);
memmove_wd ((void *)image_get_load (hdr), memmove_wd ((void *)image_get_load (hdr),
(void *)os_data, os_len, CHUNKSZ); (void *)os_data, os_len, CHUNKSZ);
@ -242,7 +242,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
} }
break; break;
case IH_COMP_GZIP: case IH_COMP_GZIP:
printf (" Uncompressing %s ... ", name); printf (" Uncompressing %s ... ", type_name);
if (gunzip ((void *)image_get_load (hdr), unc_len, if (gunzip ((void *)image_get_load (hdr), unc_len,
(uchar *)os_data, &os_len) != 0) { (uchar *)os_data, &os_len) != 0) {
puts ("GUNZIP ERROR - must RESET board to recover\n"); 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; break;
#ifdef CONFIG_BZIP2 #ifdef CONFIG_BZIP2
case IH_COMP_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, * If we've got less than 4 MB of malloc() space,
* use slower decompression algorithm which requires * use slower decompression algorithm which requires
@ -544,65 +544,12 @@ void print_image_hdr (image_header_t *hdr)
static void print_type (image_header_t *hdr) static void print_type (image_header_t *hdr)
{ {
char *os, *arch, *type, *comp; const char *os, *arch, *type, *comp;
switch (image_get_os (hdr)) { os = image_get_os_name (image_get_os (hdr));
case IH_OS_INVALID: os = "Invalid OS"; break; arch = image_get_arch_name (image_get_arch (hdr));
case IH_OS_NETBSD: os = "NetBSD"; break; type = image_get_type_name (image_get_type (hdr));
case IH_OS_LINUX: os = "Linux"; break; comp = image_get_comp_name (image_get_comp (hdr));
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;
}
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;
}
printf ("%s %s %s (%s)", arch, os, type, comp); printf ("%s %s %s (%s)", arch, os, type, comp);
} }

View file

@ -193,3 +193,91 @@ void image_multi_getimg (image_header_t *hdr, ulong idx,
*data = 0; *data = 0;
} }
} }
#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;
}
#endif

View file

@ -290,6 +290,10 @@ static inline int image_check_os (image_header_t *hdr, uint8_t os)
return (image_get_os (hdr) == os); return (image_get_os (hdr) == os);
} }
ulong image_multi_count (image_header_t *hdr);
void image_multi_getimg (image_header_t *hdr, ulong idx,
ulong *data, ulong *len);
#ifndef USE_HOSTCC #ifndef USE_HOSTCC
static inline int image_check_target_arch (image_header_t *hdr) static inline int image_check_target_arch (image_header_t *hdr)
{ {
@ -322,10 +326,11 @@ static inline int image_check_target_arch (image_header_t *hdr)
return 1; return 1;
} }
#endif
ulong image_multi_count (image_header_t *hdr); const char* image_get_os_name (uint8_t os);
void image_multi_getimg (image_header_t *hdr, ulong idx, const char* image_get_arch_name (uint8_t arch);
ulong *data, ulong *len); const char* image_get_type_name (uint8_t type);
const char* image_get_comp_name (uint8_t comp);
#endif /* USE_HOSTCCa */
#endif /* __IMAGE_H__ */ #endif /* __IMAGE_H__ */