#include "mkimage.h"
#include "rkcommon.h"
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
enum {
RK_SIGNATURE = 0x0ff0aa55,
};
{
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;
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)
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);
}
rkcommon_set_header0(buf, file_size, params);
- /* Set up the SPL name and add the AArch64 'nop' padding, if needed */
+ /* Set up the SPL name */
memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE);
if (rkcommon_need_rc4_spl(params))
*
* 0x0 header0 (see rkcommon.c)
* 0x800 spl_name ('RK30', ..., 'RK33')
+ * (start of the payload for AArch64 payloads: we expect the
+ * first 4 bytes to be available for overwriting with our
+ * spl_name)
* 0x804 first instruction to be executed
- * (image start for AArch32, 'nop' for AArch64))
- * 0x808 second instruction to be executed
- * (image start for AArch64)
+ * (start of the image/payload for 32bit payloads)
*
- * For AArch64 (ARMv8) payloads, we receive an input file that
- * needs to start on an 8-byte boundary (natural alignment), so
- * we need to put a NOP at 0x804.
+ * For AArch64 (ARMv8) payloads, natural alignment (8-bytes) is
+ * required for its sections (so the image we receive needs to
+ * have the first 4 bytes reserved for the spl_name). Reserving
+ * these 4 bytes is done using the BOOT0_HOOK infrastructure.
*
- * Depending on this, the header is either 0x804 or 0x808 bytes
- * in length.
+ * Depending on this, the header is either 0x800 (if this is a
+ * 'boot0'-style payload, which has reserved 4 bytes at the
+ * beginning for the 'spl_name' and expects us to overwrite
+ * its first 4 bytes) or 0x804 bytes in length.
*/
if (rkcommon_spl_is_boot0(params))
tparams->header_size = RK_SPL_HDR_START;