X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=tools%2Fmkimage.c;h=fea3e5bc6b3079e3d2a915829f04a83c832797fb;hb=1cfefe8cb6e1bb43f6509c0aee254e2908d42f21;hp=148ee8dc8377af06870cee37344aa3372b5d592b;hpb=147031aef15cedbcb6dea3679094baba34002f66;p=oweals%2Fu-boot.git diff --git a/tools/mkimage.c b/tools/mkimage.c index 148ee8dc83..fea3e5bc6b 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -1,8 +1,23 @@ /* - * (C) Copyright 2000-2003 + * (C) Copyright 2000-2004 * DENX Software Engineering * Wolfgang Denk, wd@denx.de * All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA */ #include @@ -62,62 +77,66 @@ typedef struct table_entry { } 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_MIPS, "mips", "MIPS", }, - { IH_CPU_MIPS64, "mips64", "MIPS 64 Bit", }, - { 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_M68K, "m68k", "MC68000", }, - { -1, "", "", }, + { 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", }, + { -1, "", "", }, }; table_entry_t os_name[] = { { IH_OS_INVALID, NULL, "Invalid OS", }, - { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, - { IH_OS_NETBSD, "netbsd", "NetBSD", }, - { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, - { IH_OS_LINUX, "linux", "Linux", }, - { IH_OS_SVR4, "svr4", "SVR4", }, + { IH_OS_ARTOS, "artos", "ARTOS", }, + { IH_OS_DELL, "dell", "Dell", }, { IH_OS_ESIX, "esix", "Esix", }, - { IH_OS_SOLARIS, "solaris", "Solaris", }, + { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, { IH_OS_IRIX, "irix", "Irix", }, - { IH_OS_SCO, "sco", "SCO", }, - { IH_OS_DELL, "dell", "Dell", }, - { IH_OS_NCR, "ncr", "NCR", }, + { IH_OS_LINUX, "linux", "Linux", }, { IH_OS_LYNXOS, "lynxos", "LynxOS", }, - { IH_OS_VXWORKS, "vxworks", "VxWorks", }, + { 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_U_BOOT, "u-boot", "U-Boot", }, { IH_OS_RTEMS, "rtems", "RTEMS", }, - { IH_OS_ARTOS, "artos", "ARTOS", }, + { IH_OS_SCO, "sco", "SCO", }, + { IH_OS_SOLARIS, "solaris", "Solaris", }, + { IH_OS_SVR4, "svr4", "SVR4", }, + { IH_OS_U_BOOT, "u-boot", "U-Boot", }, + { IH_OS_VXWORKS, "vxworks", "VxWorks", }, { -1, "", "", }, }; table_entry_t type_name[] = { { IH_TYPE_INVALID, NULL, "Invalid Image", }, - { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, + { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, + { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, - { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, { IH_TYPE_MULTI, "multi", "Multi-File Image", }, - { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, + { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, { IH_TYPE_SCRIPT, "script", "Script", }, - { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, + { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, { -1, "", "", }, }; table_entry_t comp_name[] = { { IH_COMP_NONE, "none", "uncompressed", }, - { IH_COMP_GZIP, "gzip", "gzip compressed", }, { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, + { IH_COMP_GZIP, "gzip", "gzip compressed", }, { -1, "", "", }, }; @@ -258,7 +277,8 @@ NXTARG: ; */ if (xflag) { if (ep != addr + sizeof(image_header_t)) { - fprintf (stderr, "%s: For XIP, the entry point must be the load addr + %lu\n", + fprintf (stderr, + "%s: For XIP, the entry point must be the load addr + %lu\n", cmdname, (unsigned long)sizeof(image_header_t)); exit (EXIT_FAILURE); @@ -268,7 +288,7 @@ NXTARG: ; imagefile = *argv; if (lflag) { - ifd = open(imagefile, O_RDONLY); + ifd = open(imagefile, O_RDONLY|O_BINARY); } else { ifd = open(imagefile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666); } @@ -291,7 +311,7 @@ NXTARG: ; exit (EXIT_FAILURE); } - if (sbuf.st_size < sizeof(image_header_t)) { + if ((unsigned)sbuf.st_size < sizeof(image_header_t)) { fprintf (stderr, "%s: Bad size: \"%s\" is no valid image\n", cmdname, imagefile); @@ -328,8 +348,9 @@ NXTARG: ; if (crc32 (0, data, len) != checksum) { fprintf (stderr, - "*** Warning: \"%s\" has bad header checksum!\n", - imagefile); + "%s: ERROR: \"%s\" has bad header checksum!\n", + cmdname, imagefile); + exit (EXIT_FAILURE); } data = (char *)(ptr + sizeof(image_header_t)); @@ -337,8 +358,9 @@ NXTARG: ; if (crc32 (0, data, len) != ntohl(hdr->ih_dcrc)) { fprintf (stderr, - "*** Warning: \"%s\" has corrupted data!\n", - imagefile); + "%s: ERROR: \"%s\" has corrupted data!\n", + cmdname, imagefile); + exit (EXIT_FAILURE); } /* for multi-file images we need the data part, too */ @@ -365,7 +387,7 @@ NXTARG: ; if (opt_type == IH_TYPE_MULTI || opt_type == IH_TYPE_SCRIPT) { char *file = datafile; - unsigned long size; + uint32_t size; for (;;) { char *sep = NULL; @@ -502,7 +524,7 @@ copy_file (int ifd, const char *datafile, int pad) fprintf (stderr, "Adding Image %s\n", datafile); } - if ((dfd = open(datafile, O_RDONLY)) < 0) { + if ((dfd = open(datafile, O_RDONLY|O_BINARY)) < 0) { fprintf (stderr, "%s: Can't open %s: %s\n", cmdname, datafile, strerror(errno)); exit (EXIT_FAILURE); @@ -530,7 +552,7 @@ copy_file (int ifd, const char *datafile, int pad) * reserved for it. */ - if (sbuf.st_size < sizeof(image_header_t)) { + if ((unsigned)sbuf.st_size < sizeof(image_header_t)) { fprintf (stderr, "%s: Bad size: \"%s\" is too small for XIP\n", cmdname, datafile); @@ -574,7 +596,7 @@ usage () { fprintf (stderr, "Usage: %s -l image\n" " -l ==> list image header information\n" - " %s -A arch -O os -T type -C comp " + " %s [-x] -A arch -O os -T type -C comp " "-a addr -e ep -n name -d data_file[:data_file...] image\n", cmdname, cmdname); fprintf (stderr, " -A ==> set architecture to 'arch'\n"