summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-10-08 00:02:59 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-10-08 00:03:22 +0800
commitad4da3a4a1c817a7ed38de25788fda11496e53a7 (patch)
tree519bd2412ecac461080427965cf3abc0ed77a2cd /scripts
parent6d2812b93d67be5eb7b41106ab9d8756d4bbc9d4 (diff)
downloadbarebox-ad4da3a4a1c817a7ed38de25788fda11496e53a7.tar.gz
barebox-ad4da3a4a1c817a7ed38de25788fda11496e53a7.tar.xz
image: factorise string helper
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/mkimage.c121
1 files changed, 8 insertions, 113 deletions
diff --git a/scripts/mkimage.c b/scripts/mkimage.c
index ae5c1e0e76..fcecfc89e6 100644
--- a/scripts/mkimage.c
+++ b/scripts/mkimage.c
@@ -27,6 +27,7 @@
#include "compiler.h"
#include "../include/image.h"
+#include "../common/image.c"
char *cmdname;
@@ -35,87 +36,10 @@ char *cmdname;
//extern unsigned long crc32 (unsigned long crc, const char *buf, unsigned int len);
-typedef struct table_entry {
- int val; /* as defined in image.h */
- char *sname; /* short (input) name */
- char *lname; /* long (output) name */
-} table_entry_t;
-
-table_entry_t arch_name[] = {
- { IH_CPU_INVALID, NULL, "Invalid CPU", },
- { IH_CPU_ALPHA, "alpha", "Alpha", },
- { IH_CPU_ARM, "arm", "ARM", },
- { IH_CPU_I386, "x86", "Intel x86", },
- { IH_CPU_IA64, "ia64", "IA64", },
- { IH_CPU_M68K, "m68k", "MC68000", },
- { IH_CPU_MICROBLAZE, "microblaze", "MicroBlaze", },
- { IH_CPU_MIPS, "mips", "MIPS", },
- { IH_CPU_MIPS64, "mips64", "MIPS 64 Bit", },
- { IH_CPU_NIOS, "nios", "NIOS", },
- { IH_CPU_NIOS2, "nios2", "NIOS II", },
- { IH_CPU_PPC, "ppc", "PowerPC", },
- { IH_CPU_S390, "s390", "IBM S390", },
- { IH_CPU_SH, "sh", "SuperH", },
- { IH_CPU_SPARC, "sparc", "SPARC", },
- { IH_CPU_SPARC64, "sparc64", "SPARC 64 Bit", },
- { IH_CPU_BLACKFIN, "blackfin", "Blackfin", },
- { IH_CPU_AVR32, "avr32", "AVR32", },
- { -1, "", "", },
-};
-
-table_entry_t os_name[] = {
- { IH_OS_INVALID, NULL, "Invalid OS", },
- { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
- { IH_OS_ARTOS, "artos", "ARTOS", },
- { IH_OS_DELL, "dell", "Dell", },
- { IH_OS_ESIX, "esix", "Esix", },
- { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
- { IH_OS_IRIX, "irix", "Irix", },
- { IH_OS_LINUX, "linux", "Linux", },
- { IH_OS_LYNXOS, "lynxos", "LynxOS", },
- { IH_OS_NCR, "ncr", "NCR", },
- { IH_OS_NETBSD, "netbsd", "NetBSD", },
- { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
- { IH_OS_PSOS, "psos", "pSOS", },
- { IH_OS_QNX, "qnx", "QNX", },
- { IH_OS_RTEMS, "rtems", "RTEMS", },
- { IH_OS_SCO, "sco", "SCO", },
- { IH_OS_SOLARIS, "solaris", "Solaris", },
- { IH_OS_SVR4, "svr4", "SVR4", },
- { IH_OS_BAREBOX, "barebox", "barebox", },
- { IH_OS_VXWORKS, "vxworks", "VxWorks", },
- { -1, "", "", },
-};
-
-table_entry_t type_name[] = {
- { IH_TYPE_INVALID, NULL, "Invalid Image", },
- { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
- { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
- { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
- { IH_TYPE_MULTI, "multi", "Multi-File Image", },
- { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
- { IH_TYPE_SCRIPT, "script", "Script", },
- { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
- { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
- { -1, "", "", },
-};
-
-table_entry_t comp_name[] = {
- { IH_COMP_NONE, "none", "uncompressed", },
- { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
- { IH_COMP_GZIP, "gzip", "gzip compressed", },
- { -1, "", "", },
-};
-
static void copy_file (int, const char *, int);
static void usage (void);
static void print_header (image_header_t *);
static void print_type (image_header_t *);
-static char *put_table_entry (table_entry_t *, char *, int);
-static char *put_arch (int);
-static char *put_type (int);
-static char *put_os (int);
-static char *put_comp (int);
static int get_table_entry (table_entry_t *, char *, char *);
static int get_arch(char *);
static int get_comp(char *);
@@ -636,42 +560,13 @@ static void
print_type (image_header_t *hdr)
{
printf ("%s %s %s (%s)\n",
- put_arch (hdr->ih_arch),
- put_os (hdr->ih_os ),
- put_type (hdr->ih_type),
- put_comp (hdr->ih_comp)
+ image_arch(hdr->ih_arch),
+ image_os(hdr->ih_os),
+ image_type(hdr->ih_type),
+ image_compression(hdr->ih_comp)
);
}
-static char *put_arch (int arch)
-{
- return (put_table_entry(arch_name, "Unknown Architecture", arch));
-}
-
-static char *put_os (int os)
-{
- return (put_table_entry(os_name, "Unknown OS", os));
-}
-
-static char *put_type (int type)
-{
- return (put_table_entry(type_name, "Unknown Image", type));
-}
-
-static char *put_comp (int comp)
-{
- return (put_table_entry(comp_name, "Unknown Compression", comp));
-}
-
-static char *put_table_entry (table_entry_t *table, char *msg, int type)
-{
- for (; table->val>=0; ++table) {
- if (table->val == type)
- return (table->lname);
- }
- return (msg);
-}
-
static int get_arch(char *name)
{
return (get_table_entry(arch_name, "CPU", name));
@@ -700,12 +595,12 @@ static int get_table_entry (table_entry_t *table, char *msg, char *name)
table_entry_t *t;
int first = 1;
- for (t=table; t->val>=0; ++t) {
+ for (t=table; t->id>=0; ++t) {
if (t->sname && strcasecmp(t->sname, name)==0)
- return (t->val);
+ return (t->id);
}
fprintf (stderr, "\nInvalid %s Type - valid names are", msg);
- for (t=table; t->val>=0; ++t) {
+ for (t=table; t->id>=0; ++t) {
if (t->sname == NULL)
continue;
fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);