Commit e9120dba authored by Marek Vasut's avatar Marek Vasut

mxssb: Clean up sb_load_binary

The sb_load_binary() call is now redundant, since the files are
now loaded while preparing the SB image header. Reduce this to
a stub function that fills the sb instruction stream.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 4c5bd7d4
......@@ -530,53 +530,12 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
static int sb_load_binary(const char *filename, const unsigned int spl)
{
off_t real_size, roundup_size;
uint8_t *data;
int fd, ret;
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
fd = open(filename, O_RDONLY);
if (fd < 0)
goto err_open;
real_size = lseek(fd, 0, SEEK_END);
if (real_size < 0)
goto err_file;
lseek(fd, 0, SEEK_SET);
roundup_size = roundup(real_size, SB_BLOCK_SIZE);
data = calloc(1, roundup_size);
if (!data)
goto err_file;
ret = read(fd, data, real_size);
if (ret != real_size)
goto err_alloc;
lst[slot].payload = data;
lst[slot].length = roundup_size;
lst[slot].filename = (char *)filename;
close(fd);
return 0;
err_alloc:
free(data);
err_file:
close(fd);
err_open:
printf("Failed to load file \"%s\"\n", filename);
return -EINVAL;
}
static void sb_unload_binary(const unsigned int spl)
{
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
free(lst[slot].payload);
}
static int sb_save_image(const char *filename, uint8_t *image, int len)
......@@ -710,8 +669,14 @@ 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");
/* Update LOAD instruction. */
cctx->payload.load.count = cctx->length;
cctx->payload.load.crc32 = crc32(cctx->data, cctx->length);
len += cctx->length;
}
......@@ -1018,13 +983,8 @@ int main(int argc, char **argv)
return -1;
}
ret = sb_load_binary(spl_filename, 1);
if (ret)
return ret;
ret = sb_load_binary(uboot_filename, 0);
if (ret)
return ret;
sb_load_binary(spl_filename, 1);
sb_load_binary(uboot_filename, 0);
ret = sb_parse_image(&ctx);
if (ret)
......@@ -1040,9 +1000,6 @@ int main(int argc, char **argv)
fail:
sb_free_image(&ctx);
sb_unload_binary(1);
sb_unload_binary(0);
if (image)
free(image);
......
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