Commit 5886192e authored by Marek Vasut's avatar Marek Vasut

mxssb: Fixup section counter and offset computation

The section offset computation has to be done after the
SB image header is filled in. Moreover, the TAG command
can be filled in only afterwards as well, since it's almost
exact copy of the section header. Implement a function that
fixes up the section headers and TAG commands.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent a7ac327a
......@@ -69,6 +69,7 @@ struct sb_image_ctx {
EVP_CIPHER_CTX cipher_ctx;
EVP_MD_CTX md_ctx;
int section_count;
struct sb_boot_image_header payload;
};
......@@ -746,6 +747,7 @@ static int sb_parse_sections(struct sb_image_ctx *ictx)
{
/* This function is a stub, we support only one section so far. */
struct sb_section_ctx *sctx;
struct sb_sections_header *shdr;
int ret;
sctx = calloc(1, sizeof(*sctx));
......@@ -753,15 +755,26 @@ static int sb_parse_sections(struct sb_image_ctx *ictx)
return -ENOMEM;
ret = sb_parse_cmds(sctx);
if (ret) {
free(sctx);
return ret;
}
if (ret)
goto fail;
shdr = &sctx->payload;
/* FIXME -- bootable by default. */
sctx->boot = 1;
/* FIXME -- the section ID should be configurable */
shdr->section_number = ictx->section_count++;
/* FIXME -- use this instead of sctx->size */
shdr->section_size = sctx->size / SB_BLOCK_SIZE;
shdr->section_flags = sctx->boot ? SB_SECTION_FLAG_BOOTABLE : 0;
ictx->sect = sctx;
return 0;
fail:
free(sctx);
return ret;
}
static int sb_prefill_image_header(struct sb_image_ctx *ictx)
......@@ -869,6 +882,45 @@ static int sb_postfill_image_header(struct sb_image_ctx *ictx)
return 0;
}
static int sb_fixup_sections_and_tags(struct sb_image_ctx *ictx)
{
/* Fixup the placement of sections. */
struct sb_boot_image_header *ihdr = &ictx->payload;
struct sb_section_ctx *sctx = ictx->sect;
struct sb_sections_header *shdr;
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
uint32_t offset = ihdr->first_boot_tag_block;
while (sctx) {
shdr = &sctx->payload;
/* Fill in the section TAG offset. */
shdr->section_offset = offset + 1;
offset += shdr->section_size;
/* Section length is measured from the TAG block. */
shdr->section_size--;
/* Fixup the TAG command. */
cctx = sctx->cmd;
while (cctx) {
ccmd = &cctx->payload;
if (ccmd->header.tag == ROM_TAG_CMD) {
ccmd->tag.section_number = shdr->section_number;
ccmd->tag.section_length = shdr->section_size;
ccmd->tag.section_flags = shdr->section_flags;
break;
}
cctx = cctx->cmd;
}
sctx = sctx->sect;
}
return 0;
}
static int sb_parse_image(struct sb_image_ctx *ictx)
{
int ret;
......@@ -887,6 +939,10 @@ static int sb_parse_image(struct sb_image_ctx *ictx)
return ret;
}
ret = sb_fixup_sections_and_tags(ictx);
if (ret)
return ret;
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment