]> git.sur5r.net Git - u-boot/blobdiff - tools/rkcommon.c
arm: am33xx: Add support for mulitiple PLL input frequencies
[u-boot] / tools / rkcommon.c
index 1880fef5248b9e16ca4054410c5b89f4a1536275..8283a740c13d3062b34cc6e2ff20404565c16843 100644 (file)
@@ -13,6 +13,8 @@
 #include "mkimage.h"
 #include "rkcommon.h"
 
+#define DIV_ROUND_UP(n, d)     (((n) + (d) - 1) / (d))
+
 enum {
        RK_SIGNATURE            = 0x0ff0aa55,
 };
@@ -84,6 +86,9 @@ static struct spl_info *rkcommon_get_spl_info(char *imagename)
 {
        int i;
 
+       if (!imagename)
+               return NULL;
+
        for (i = 0; i < ARRAY_SIZE(spl_infos); i++)
                if (!strncmp(imagename, spl_infos[i].imagename, 6))
                        return spl_infos + i;
@@ -96,17 +101,24 @@ int rkcommon_check_params(struct image_tool_params *params)
        int i;
 
        if (rkcommon_get_spl_info(params->imagename) != NULL)
-               return 0;
+               return EXIT_SUCCESS;
+
+       /*
+        * If this is a operation (list or extract), the don't require
+        * imagename to be set.
+        */
+       if (params->lflag || params->iflag)
+               return EXIT_SUCCESS;
 
        fprintf(stderr, "ERROR: imagename (%s) is not supported!\n",
-               strlen(params->imagename) > 0 ? params->imagename : "NULL");
+               params->imagename ? params->imagename : "NULL");
 
        fprintf(stderr, "Available imagename:");
        for (i = 0; i < ARRAY_SIZE(spl_infos); i++)
                fprintf(stderr, "\t%s", spl_infos[i].imagename);
        fprintf(stderr, "\n");
 
-       return -1;
+       return EXIT_FAILURE;
 }
 
 const char *rkcommon_get_spl_hdr(struct image_tool_params *params)
@@ -160,9 +172,21 @@ static void rkcommon_set_header0(void *buf, uint file_size,
        hdr->disable_rc4 = !rkcommon_need_rc4_spl(params);
        hdr->init_offset = RK_INIT_OFFSET;
 
-       hdr->init_size = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE;
-       hdr->init_size = (hdr->init_size + 3) & ~3;
-       hdr->init_boot_size = hdr->init_size + RK_MAX_BOOT_SIZE / RK_BLK_SIZE;
+       hdr->init_size = DIV_ROUND_UP(file_size, RK_BLK_SIZE);
+       /*
+        * The init_size has to be a multiple of 4 blocks (i.e. of 2K)
+        * or the BootROM will not boot the image.
+        *
+        * Note: To verify that this is not a legacy constraint, we
+        *       rechecked this against the RK3399 BootROM.
+        */
+       hdr->init_size = ROUND(hdr->init_size, 4);
+       /*
+        * The images we create do not contain the stage following the SPL as
+        * part of the SPL image, so the init_boot_size (which might have been
+        * read by Rockchip's miniloder) should be the same as the init_size.
+        */
+       hdr->init_boot_size = hdr->init_size;
 
        rc4_encode(buf, RK_BLK_SIZE, rc4_key);
 }