]> Git Repo - J-u-boot.git/blobdiff - tools/imx8mimage.c
tools: imx8mimage: not abort when mmap fail
[J-u-boot.git] / tools / imx8mimage.c
index 50a256cbac56dc984c0e2458f0d2e2ac323aae5c..4eed683396f8ad0ea20b433df0c30cd3dbb90edd 100644 (file)
@@ -21,14 +21,19 @@ static uint32_t sld_header_off;
 static uint32_t ivt_offset;
 static uint32_t using_fit;
 
+#define ROM_V1 1
+#define ROM_V2 2
+
+static uint32_t rom_version = ROM_V1;
+
 #define CSF_SIZE 0x2000
 #define HDMI_IVT_ID 0
 #define IMAGE_IVT_ID 1
 
 #define HDMI_FW_SIZE           0x17000 /* Use Last 0x1000 for IVT and CSF */
 #define ALIGN_SIZE             0x1000
-#define ALIGN(x,a)     __ALIGN_MASK((x), (__typeof__(x))(a) - 1, a)
-#define __ALIGN_MASK(x,mask,mask2) (((x) + (mask)) / (mask2) * (mask2))
+#define ALIGN_IMX(x, a)                        __ALIGN_MASK_IMX((x), (__typeof__(x))(a) - 1, a)
+#define __ALIGN_MASK_IMX(x, mask, mask2)       (((x) + (mask)) / (mask2) * (mask2))
 
 static uint32_t get_cfg_value(char *token, char *name,  int linenr)
 {
@@ -71,6 +76,7 @@ static table_entry_t imx8mimage_cmds[] = {
        {CMD_LOADER,            "LOADER",               "loader image",       },
        {CMD_SECOND_LOADER,     "SECOND_LOADER",        "2nd loader image",   },
        {CMD_DDR_FW,            "DDR_FW",               "ddr firmware",       },
+       {CMD_ROM_VERSION,       "ROM_VERSION",          "rom version",        },
        {-1,                    "",                     "",                   },
 };
 
@@ -90,6 +96,9 @@ static void parse_cfg_cmd(int32_t cmd, char *token, char *name, int lineno)
                                                token);
                if (!strncmp(token, "sd", 2))
                        rom_image_offset = 0x8000;
+
+               if (rom_version == ROM_V2)
+                       ivt_offset = 0;
                break;
        case CMD_LOADER:
                ap_img = token;
@@ -99,12 +108,19 @@ static void parse_cfg_cmd(int32_t cmd, char *token, char *name, int lineno)
                break;
        case CMD_SIGNED_HDMI:
                signed_hdmi = token;
-       case CMD_FIT:
-               using_fit = 1;
                break;
        case CMD_DDR_FW:
                /* Do nothing */
                break;
+       case CMD_ROM_VERSION:
+               if (!strncmp(token, "v2", 2)) {
+                       rom_version = ROM_V2;
+                       ivt_offset = 0;
+               } else if (!strncmp(token, "v1", 2)) {
+                       rom_version = ROM_V1;
+               }
+               break;
+
        }
 }
 
@@ -120,6 +136,11 @@ static void parse_cfg_fld(int32_t *cmd, char *token,
                                name, lineno, token);
                        exit(EXIT_FAILURE);
                }
+               switch (*cmd) {
+               case CMD_FIT:
+                       using_fit = 1;
+                       break;
+               }
                break;
        case CFG_REG_SIZE:
                parse_cfg_cmd(*cmd, token, name, lineno);
@@ -227,7 +248,7 @@ static void copy_file(int ifd, const char *datafile, int pad, int offset,
        struct stat sbuf;
        unsigned char *ptr;
        int tail;
-       int zero = 0;
+       uint64_t zero = 0;
        uint8_t zeros[4096];
        int size, ret;
 
@@ -250,7 +271,7 @@ static void copy_file(int ifd, const char *datafile, int pad, int offset,
        if (ptr == MAP_FAILED) {
                fprintf(stderr, "Can't read %s: %s\n",
                        datafile, strerror(errno));
-               exit(EXIT_FAILURE);
+               goto err_mmap;
        }
 
        size = sbuf.st_size - datafile_offset;
@@ -290,6 +311,7 @@ static void copy_file(int ifd, const char *datafile, int pad, int offset,
        }
 
        munmap((void *)ptr, sbuf.st_size);
+err_mmap:
        close(dfd);
 }
 
@@ -322,9 +344,8 @@ static int generate_ivt_for_fit(int fd, int fit_offset, uint32_t ep,
        }
 
        fit_size = fdt_totalsize(&image_header);
-       fit_size = (fit_size + 3) & ~3;
 
-       fit_size = ALIGN(fit_size, ALIGN_SIZE);
+       fit_size = ALIGN_IMX(fit_size, ALIGN_SIZE);
 
        ret = lseek(fd, fit_offset + fit_size, SEEK_SET);
        if (ret < 0) {
@@ -428,7 +449,7 @@ void build_image(int ofd)
                 * Aligned to 104KB = 92KB FW image + 0x8000
                 * (IVT and alignment) + 0x4000 (second IVT + CSF)
                 */
-               file_off += ALIGN(sbuf.st_size,
+               file_off += ALIGN_IMX(sbuf.st_size,
                                  HDMI_FW_SIZE + 0x2000 + 0x1000);
        }
 
@@ -461,7 +482,7 @@ void build_image(int ofd)
        imx_header[IMAGE_IVT_ID].boot_data.start =
                imx_header[IMAGE_IVT_ID].fhdr.self - ivt_offset;
        imx_header[IMAGE_IVT_ID].boot_data.size =
-               ALIGN(sbuf.st_size + sizeof(imx_header_v3_t) + ivt_offset,
+               ALIGN_IMX(sbuf.st_size + sizeof(imx_header_v3_t) + ivt_offset,
                      sector_size);
 
        image_off = header_image_off + sizeof(imx_header_v3_t);
@@ -488,8 +509,10 @@ void build_image(int ofd)
                         * Record the second bootloader relative offset in
                         * image's IVT reserved1
                         */
-                       imx_header[IMAGE_IVT_ID].fhdr.reserved1 =
-                               sld_header_off - header_image_off;
+                       if (rom_version == ROM_V1) {
+                               imx_header[IMAGE_IVT_ID].fhdr.reserved1 =
+                                       sld_header_off - header_image_off;
+                       }
                        sld_fd = open(sld_img, O_RDONLY | O_BINARY);
                        if (sld_fd < 0) {
                                fprintf(stderr, "%s: Can't open: %s\n",
This page took 0.030431 seconds and 4 git commands to generate.