rockchip: mkimage: update rkimage to support pre-padded payloads

To simplify the creation of AArch64 SPL images for the RK3399, we
use the ENABLE_ARM_SOC_BOOT0_HOOK option and prepend 4 bytes of
padding at the start of the text section. This makes it easy for
mkimage to rewrite this word with the 'RK33' boot magic.

This change brings logic to calculate the header size and allocate
the header back in sync. For the RK3399 we now limit the header to
before the payload (i.e. the 'header0' and the padding up to the
actual image) and overwrite the first word (inserted by the
boot0-hook for this purpose) with the 'RK33' magic in-place.

X-AffectedPlatforms: RK3399-Q7
Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Tested-by: Klaus Goger <klaus.goger@theobroma-systems.com>
This commit is contained in:
Philipp Tomsich 2017-03-15 12:08:45 +01:00 committed by Simon Glass
parent 3d54eabcaf
commit 3082775692
2 changed files with 16 additions and 34 deletions

View File

@ -45,7 +45,6 @@ struct header0_info {
*/
struct header1_info {
uint32_t magic;
uint32_t first_insn;
};
/**
@ -55,7 +54,9 @@ struct header1_info {
* @spl_hdr: Boot ROM requires a 4-bytes spl header
* @spl_size: Spl size(include extra 4-bytes spl header)
* @spl_rc4: RC4 encode the SPL binary (same key as header)
* @spl_aarch64: Pad the header with an AArch64 'nop's to 8-bytes
* @spl_boot0: A new-style (ARM_SOC_BOOT0_HOOK) image that should
* have the boot magic (e.g. 'RK33') written to its first
* word.
*/
struct spl_info {
@ -63,7 +64,7 @@ struct spl_info {
const char *spl_hdr;
const uint32_t spl_size;
const bool spl_rc4;
const bool spl_aarch64;
const bool spl_boot0;
};
static struct spl_info spl_infos[] = {
@ -117,15 +118,6 @@ const char *rkcommon_get_spl_hdr(struct image_tool_params *params)
return info->spl_hdr;
}
const bool rkcommon_get_spl_hdr_padto8(struct image_tool_params *params)
{
struct spl_info *info = rkcommon_get_spl_info(params->imagename);
/*
* info would not be NULL, because of we checked params before.
*/
return info->spl_aarch64;
}
int rkcommon_get_spl_size(struct image_tool_params *params)
{
@ -147,6 +139,16 @@ bool rkcommon_need_rc4_spl(struct image_tool_params *params)
return info->spl_rc4;
}
bool rkcommon_spl_is_boot0(struct image_tool_params *params)
{
struct spl_info *info = rkcommon_get_spl_info(params->imagename);
/*
* info would not be NULL, because of we checked params before.
*/
return info->spl_boot0;
}
static void rkcommon_set_header0(void *buf, uint file_size,
struct image_tool_params *params)
{
@ -177,13 +179,6 @@ int rkcommon_set_header(void *buf, uint file_size,
/* Set up the SPL name and add the AArch64 'nop' padding, if needed */
memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE);
/*
* Pad the 4-byte header to 8-bytes using an AArch64 'nop'.
* Note that AArch64 insns are always encoded as little-endian.
*/
if (rkcommon_get_spl_hdr_padto8(params))
hdr->first_insn = cpu_to_le32(0xd503201f);
if (rkcommon_need_rc4_spl(params))
rkcommon_rc4_encode_spl(buf, RK_SPL_HDR_START,
params->file_size - RK_SPL_HDR_START);
@ -224,8 +219,8 @@ void rkcommon_vrec_header(struct image_tool_params *params,
* Depending on this, the header is either 0x804 or 0x808 bytes
* in length.
*/
if (rkcommon_get_spl_hdr_padto8(params))
tparams->header_size = RK_SPL_HDR_START + 8;
if (rkcommon_spl_is_boot0(params))
tparams->header_size = RK_SPL_HDR_START;
else
tparams->header_size = RK_SPL_HDR_START + 4;

View File

@ -33,19 +33,6 @@ int rkcommon_check_params(struct image_tool_params *params);
*/
const char *rkcommon_get_spl_hdr(struct image_tool_params *params);
/**
* rkcommon_get_spl_hdr_padto8() - check if we need to pad to 8 bytes
*
* Rockchip's bootrom starts execution right after the SPL header (i.e.
* at offset 4), but we can not reasonably align the test section of
* an AArch64 SPL at 4 bytes (as this would break natural alignment
* and any embedded constants might cause an alignment exception, which
* is illegal in privileged modes).
*
* Padding is (for now) assumed to occur with a single AArch64 'nop'.
*/
const bool rkcommon_get_spl_hdr_padto8(struct image_tool_params *params);
/**
* rkcommon_get_spl_size() - get spl size for a Rockchip boot image
*