Commit 03e58070 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Move the file loading into sb_tag_to_command



Move the loading of a file associated with a LOAD instruction into
sb_tag_to_command, since this is where the LOAD instruction is filled.
This will allow us to keep the handling of LOAD instruction in one
place.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent e4d59235
......@@ -345,9 +345,14 @@ static uint8_t sb_command_checksum(struct sb_command *inst)
return csum;
}
static int sb_load_file(struct sb_cmd_ctx *cctx, struct sb_source_entry *src);
static int sb_tag_to_command(struct sb_source_entry *src,
struct sb_command *cmd)
struct sb_cmd_ctx *cctx)
{
struct sb_command *cmd = &cctx->payload;
int ret;
cmd->header.checksum = 0x5a;
cmd->header.tag = src->tag;
cmd->header.flags = src->flags;
......@@ -359,8 +364,29 @@ static int sb_tag_to_command(struct sb_source_entry *src,
/* TAG instruction is filled later */
break;
case ROM_LOAD_CMD:
/* Load the file */
if (!strcmp(src->filename, "ivt:spl")) {
cctx->ivt = 1;
cctx->data = (uint8_t *)&sb_spl_ivt;
cctx->length = sizeof(sb_spl_ivt);
} else if (!strcmp(src->filename, "ivt:u-boot")) {
cctx->ivt = 1;
cctx->data = (uint8_t *)&sb_uboot_ivt;
cctx->length = sizeof(sb_uboot_ivt);
} else {
ret = sb_load_file(cctx, src);
if (ret)
return ret;
}
if (cctx->length & (SB_BLOCK_SIZE - 1))
fprintf(stderr, "WARN: Unaligned payload!\n");
/* Fill LOAD instruction. */
cmd->load.address = src->address;
/* cmd->load.count and cmd->load.crc32 are filled later */
cmd->load.count = cctx->length;
cmd->load.crc32 = crc32(cctx->data, cctx->length);
break;
case ROM_FILL_CMD: /* UNSUPPORTED */
goto unsupp;
......@@ -618,38 +644,14 @@ static int sb_parse_cmds(struct sb_section_ctx *sctx)
if (!head)
head = cctx;
ret = sb_tag_to_command(src, &cctx->payload);
ret = sb_tag_to_command(src, cctx);
if (ret)
goto err;
len += sizeof(struct sb_command);
/* FIXME -- this is where the file loading will happen. */
if (src->tag == ROM_LOAD_CMD) {
/* !FIXME HACK! -- generate IVT entries properly */
if (!strcmp(src->filename, "ivt:spl")) {
cctx->ivt = 1;
cctx->data = (uint8_t *)&sb_spl_ivt;
cctx->length = sizeof(sb_spl_ivt);
} else if (!strcmp(src->filename, "ivt:u-boot")) {
cctx->ivt = 1;
cctx->data = (uint8_t *)&sb_uboot_ivt;
cctx->length = sizeof(sb_uboot_ivt);
} else {
ret = sb_load_file(cctx, src);
if (ret)
goto err;
}
if (cctx->length & (SB_BLOCK_SIZE - 1))
fprintf(stderr, "WARN: Unaligned payload!\n");
/* Update LOAD instruction. */
cctx->payload.load.count = cctx->length;
cctx->payload.load.crc32 = crc32(cctx->data, cctx->length);
len += cctx->length;
}
if (cctx->payload.header.tag == ROM_LOAD_CMD)
len += cctx->payload.load.count;
if (prev)
prev->cmd = cctx;
......
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