Commit 1343518e authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Calculate the section size when processing it



Calculate the size of the section block while reading it. This
value can be later reused when calculating the placement of the
final image blocks.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 0044795e
......@@ -54,6 +54,7 @@ struct sb_cmd_ctx {
struct sb_section_ctx {
unsigned int boot:1;
uint32_t size;
struct sb_section_ctx *sect;
struct sb_cmd_ctx *cmd;
......@@ -681,6 +682,7 @@ static int sb_parse_cmds(struct sb_section_ctx *sctx)
struct sb_cmd_ctx *cctx, *prev = NULL, *head = NULL;
struct sb_source_entry *src = sb_get_boot_list(target_cpu);
unsigned int insts = sb_get_boot_list_size(target_cpu);
uint32_t len = 0;
int ret;
struct sb_command *cmd;
......@@ -699,6 +701,8 @@ static int sb_parse_cmds(struct sb_section_ctx *sctx)
memcpy(&cctx->payload, cmd, sizeof(*cmd));
free(cmd);
len += sizeof(*cmd);
/* FIXME -- this is where the file loading will happen. */
if (src->tag == ROM_LOAD_CMD) {
if (src->filename) {
......@@ -710,6 +714,9 @@ static int sb_parse_cmds(struct sb_section_ctx *sctx)
cctx->data = src->payload;
cctx->length = src->length;
}
if (cctx->length & (SB_BLOCK_SIZE - 1))
fprintf(stderr, "WARN: Unaligned payload!\n");
len += cctx->length;
}
if (prev)
......@@ -719,6 +726,7 @@ static int sb_parse_cmds(struct sb_section_ctx *sctx)
}
sctx->cmd = head;
sctx->size = len;
return 0;
err:
......@@ -794,7 +802,6 @@ static int sb_postfill_image_header(struct sb_image_ctx *ictx)
{
struct sb_boot_image_header *hdr = &ictx->payload;
struct sb_section_ctx *sctx = ictx->sect;
struct sb_cmd_ctx *cctx;
uint32_t kd_size, sections_blocks;
signed int bootable_section = -1;
EVP_MD_CTX md_ctx;
......@@ -817,27 +824,15 @@ static int sb_postfill_image_header(struct sb_image_ctx *ictx)
fprintf(stderr, "WARN: Multiple bootable sections!\n");
}
/* Load CMD pointer, move section pointer. */
cctx = sctx->cmd;
sctx = sctx->sect;
hdr->section_count++;
hdr->image_blocks += sctx->size / SB_BLOCK_SIZE;
/* Check for degenerated section. */
if (!cctx) {
if (!sctx->cmd)
fprintf(stderr, "WARN: Empty section!\n");
continue;
}
while (cctx) {
hdr->image_blocks += sizeof(struct sb_command) / SB_BLOCK_SIZE;
if (cctx->data) {
if (cctx->length & (SB_BLOCK_SIZE - 1))
fprintf(stderr, "WARN: Unaligned payload!\n");
hdr->image_blocks += cctx->length / SB_BLOCK_SIZE;
}
cctx = cctx->cmd;
}
/* Move section pointer. */
sctx = sctx->sect;
hdr->section_count++;
}
if (bootable_section < 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