]> git.sur5r.net Git - u-boot/blobdiff - tools/mkimage.c
* Patch by Scott McNutt, 01 Nov 2004:
[u-boot] / tools / mkimage.c
index fc8310e78b23453d60e9f735babd433f39f2ad3d..fbc1a12549c06b446bb6bc085de7940188a334e6 100644 (file)
@@ -1,8 +1,23 @@
 /*
- * (C) Copyright 2000-2002
+ * (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 <errno.h>
@@ -39,6 +54,10 @@ typedef              unsigned int    uint32_t;
 #define     htonl(a)   SWAP_LONG(a)
 #endif /* __WIN32__ */
 
+#ifndef        O_BINARY                /* should be define'd on __WIN32__ */
+#define O_BINARY       0
+#endif
+
 #include <image.h>
 
 extern int errno;
@@ -58,60 +77,65 @@ 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",         },
-    {  -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", },
+    {  -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_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,             "",             "",                     },
 };
 
@@ -262,13 +286,9 @@ NXTARG:            ;
        imagefile = *argv;
 
        if (lflag) {
-               ifd = open(imagefile, O_RDONLY);
+               ifd = open(imagefile, O_RDONLY|O_BINARY);
        } else {
-#ifdef __WIN32__
                ifd = open(imagefile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666);
-#else
-               ifd = open(imagefile, O_RDWR|O_CREAT|O_TRUNC, 0666);
-#endif
        }
 
        if (ifd < 0) {
@@ -289,7 +309,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);
@@ -420,7 +440,7 @@ NXTARG:             ;
        }
 
        /* We're a bit of paranoid */
-#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__)
+#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
        (void) fdatasync (ifd);
 #else
        (void) fsync (ifd);
@@ -470,7 +490,7 @@ NXTARG:             ;
        (void) munmap((void *)ptr, sbuf.st_size);
 
        /* We're a bit of paranoid */
-#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__)
+#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
        (void) fdatasync (ifd);
 #else
        (void) fsync (ifd);
@@ -500,7 +520,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);
@@ -528,7 +548,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);
@@ -572,7 +592,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"
@@ -602,8 +622,8 @@ print_header (image_header_t *hdr)
        printf ("Image Type:   "); print_type(hdr);
        printf ("Data Size:    %d Bytes = %.2f kB = %.2f MB\n",
                size, (double)size / 1.024e3, (double)size / 1.048576e6 );
-       printf ("Load Address: 0x%08x\n", ntohl(hdr->ih_load));
-       printf ("Entry Point:  0x%08x\n", ntohl(hdr->ih_ep));
+       printf ("Load Address: 0x%08X\n", ntohl(hdr->ih_load));
+       printf ("Entry Point:  0x%08X\n", ntohl(hdr->ih_ep));
 
        if (hdr->ih_type == IH_TYPE_MULTI || hdr->ih_type == IH_TYPE_SCRIPT) {
                int i, ptrs;
@@ -630,7 +650,7 @@ print_header (image_header_t *hdr)
                                 * if planning to do something with
                                 * multiple files
                                 */
-                               printf ("    Offset = %08x\n", pos);
+                               printf ("    Offset = %08X\n", pos);
                        }
                        /* copy_file() will pad the first files to even word align */
                        size += 3;