]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - tools/mkimage.c
* Patch by Bernhard Kuhn, 28 Oct 2003:
[karo-tx-uboot.git] / tools / mkimage.c
index 0f99f3b4ac0cb2adbb7545361699b7913569d12c..0e83546550e1c9d5757bfb1080234e5f66567464 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2000-2002
+ * (C) Copyright 2000-2003
  * DENX Software Engineering
  * Wolfgang Denk, wd@denx.de
  * All rights reserved.
@@ -39,6 +39,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;
@@ -70,6 +74,7 @@ table_entry_t arch_name[] = {
     {  IH_CPU_SH,      "sh",           "SuperH",               },
     {  IH_CPU_SPARC,   "sparc",        "SPARC",                },
     {  IH_CPU_SPARC64, "sparc64",      "SPARC 64 Bit",         },
+    {  IH_CPU_M68K,    "m68k",         "MC68000",              },
     {  -1,             "",             "",                     },
 };
 
@@ -92,6 +97,8 @@ table_entry_t os_name[] = {
     {  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",                },
     {  -1,             "",             "",                     },
 };
 
@@ -103,6 +110,7 @@ table_entry_t type_name[] = {
     {  IH_TYPE_MULTI,      "multi",      "Multi-File Image",   },
     {  IH_TYPE_FIRMWARE,   "firmware",   "Firmware",           },
     {  IH_TYPE_SCRIPT,     "script",     "Script",             },
+    {  IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image",   },
     {  -1,                 "",           "",                   },
 };
 
@@ -250,8 +258,9 @@ NXTARG:             ;
         */
        if (xflag) {
                if (ep != addr + sizeof(image_header_t)) {
-                       fprintf (stderr, "%s: For XIP, the entry point must be the load addr + %d\n",
-                               cmdname, sizeof(image_header_t));
+                       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);
                }
        }
@@ -259,13 +268,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) {
@@ -417,7 +422,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);
@@ -467,7 +472,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);
@@ -497,7 +502,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);
@@ -599,8 +604,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;
@@ -627,7 +632,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;