Commit aa974acc authored by Marek Vasut's avatar Marek Vasut

mxssb: Load instructions from file

Load the instructions that shall be inserted into the SB image
from file. There is now an easy parser and the built-in instruction
tables are gone.

WARNING: This breaks the command line interface!
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent c289ba8d
......@@ -82,8 +82,7 @@ struct sb_image_ctx {
uint8_t digest[32];
struct sb_cmd_list *sb_cmd_list;
struct sb_cmd_list *sb_cmd_pos;
char *spl_filename;
char *uboot_filename;
char *cfg_filename;
struct sb_key_dictionary_key sb_dict_key;
......@@ -103,27 +102,6 @@ struct sb_image_ctx {
* LOAD IVT address IVT_entry_point
* CALL [HAB] address [r0_arg]
*/
static const char *sb_input_mx23[] = {
"CPU mx23",
"SECTION 0x0",
" TAG LAST",
" LOAD 0x0 "/* spl/u-boot-spl.bin appended below */,
" CALL 0x14 0x0",
" LOAD 0x0 "/* u-boot.bin appended below */,
" CALL 0x40000100 0x0",
};
static const char *sb_input_mx28[] = {
"CPU mx28",
"SECTION 0x0",
" TAG LAST",
" LOAD 0x0 "/* spl/u-boot-spl.bin appended below */,
" LOAD IVT 0x8000 0x14",
" CALL HAB 0x8000 0x0",
" LOAD 0x40000100 "/* u-boot.bin appended below */,
" LOAD IVT 0x8000 0x40000100",
" CALL HAB 0x8000 0x0",
};
/* Blank image key. */
static uint8_t image_key[16] = {0};
......@@ -939,73 +917,49 @@ static int sb_fixup_sections_and_tags(struct sb_image_ctx *ictx)
static int sb_load_cmdfile(struct sb_image_ctx *ictx)
{
unsigned int i, sb_insts;
struct sb_cmd_list *head = NULL, *prev = NULL, *curr;
if (ictx->target_cpu == CPU_MX23)
sb_insts = sizeof(sb_input_mx23)/sizeof(sb_input_mx23[0]);
else if (ictx->target_cpu == CPU_MX28)
sb_insts = sizeof(sb_input_mx28)/sizeof(sb_input_mx28[0]);
int fd;
FILE *fp;
char *line = NULL;
ssize_t rlen;
size_t len = 0;
fd = open(ictx->cfg_filename, O_RDONLY);
if (fd < 0)
goto err_open;
fp = fdopen(fd, "r");
if (!fp)
goto err_file;
for (i = 0; i < sb_insts; i++) {
while ((rlen = getline(&line, &len, fp)) > 0) {
curr = calloc(1, sizeof(*curr));
if (!curr)
goto err;
goto err_alloc;
if (!head)
head = curr;
/* Compat -- patch in the file names */
if (ictx->target_cpu == CPU_MX23) {
curr->len = strlen(sb_input_mx23[i]);
if (i == 3) {
curr->len += strlen(ictx->spl_filename) + 1;
curr->cmd = calloc(1, curr->len);
if (!curr->cmd)
goto err;
snprintf(curr->cmd, curr->len, "%s%s",
sb_input_mx23[i], ictx->spl_filename);
} else if (i == 5) {
curr->len += strlen(ictx->uboot_filename) + 1;
curr->cmd = calloc(1, curr->len);
if (!curr->cmd)
goto err;
snprintf(curr->cmd, curr->len, "%s%s",
sb_input_mx23[i], ictx->uboot_filename);
} else {
curr->cmd = strdup(sb_input_mx23[i]);
}
} else {
curr->len = strlen(sb_input_mx28[i]);
if (i == 3) {
curr->len += strlen(ictx->spl_filename) + 1;
curr->cmd = calloc(1, curr->len);
if (!curr->cmd)
goto err;
snprintf(curr->cmd, curr->len, "%s%s",
sb_input_mx28[i], ictx->spl_filename);
} else if (i == 6) {
curr->len += strlen(ictx->uboot_filename) + 1;
curr->cmd = calloc(1, curr->len);
if (!curr->cmd)
goto err;
snprintf(curr->cmd, curr->len, "%s%s",
sb_input_mx28[i], ictx->uboot_filename);
} else {
curr->cmd = strdup(sb_input_mx28[i]);
}
}
curr->cmd = line;
curr->len = rlen;
line[rlen - 1] = 0;
if (prev)
prev->next = curr;
prev = curr;
line = NULL;
}
free(line);
ictx->sb_cmd_list = head;
ictx->sb_cmd_pos = ictx->sb_cmd_list;
fclose(fp);
return 0;
err:
err_alloc:
while (head) {
curr = head;
head = head->next;
......@@ -1014,7 +968,12 @@ err:
free(curr);
}
return -ENOMEM;
err_file:
fclose(fp);
err_open:
fprintf(stderr, "ERR: Failed to load file \"%s\"\n", ictx->cfg_filename);
return -EINVAL;
}
static int sb_parse_image(struct sb_image_ctx *ictx)
......@@ -1080,52 +1039,26 @@ static void sb_free_image(struct sb_image_ctx *ictx)
static void print_help(const char *pn)
{
printf(
"Usage: %s -c CPU -s FILE -u FILE -o FILE [-v] [-h]\n\n"
" -c CPU ...... CPU model (\"mx23\" or \"mx28\")\n"
" -s FILE ..... path to U-Boot SPL (spl/u-boot-spl.bin)\n"
" -u FILE ..... path to U-Boot (u-boot.bin)\n"
"Usage: %s -c FILE -o FILE [-v] [-h]\n\n"
" -c FILE ..... path to command file (mxsimage.cfg)\n"
" -o FILE ..... path to output SB file (u-boot.sb)\n"
" -v .......... verbose boot output from BootROM\n"
" -h .......... print help\n", pn);
}
static int set_cpu(struct sb_image_ctx *ictx, const char *pn, const char *cpu)
{
if (!strcmp("mx23", cpu)) {
ictx->target_cpu = CPU_MX23;
return 0;
}
if (!strcmp("mx28", cpu)) {
ictx->target_cpu = CPU_MX28;
return 0;
}
fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu);
print_help(pn);
return -EINVAL;
}
int main(int argc, char **argv)
{
int ret;
int opt;
char *cpuid;
struct sb_image_ctx ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.target_cpu = CPU_UNKNOWN;
while ((opt = getopt(argc, argv, "c:s:u:o:vh")) != -1) {
while ((opt = getopt(argc, argv, "c:o:vh")) != -1) {
switch (opt) {
case 'c':
cpuid = optarg;
break;
case 's':
ctx.spl_filename = optarg;
break;
case 'u':
ctx.uboot_filename = optarg;
ctx.cfg_filename = optarg;
break;
case 'o':
output_filename = optarg;
......@@ -1149,16 +1082,12 @@ int main(int argc, char **argv)
return -1;
}
if (!ctx.spl_filename || !ctx.uboot_filename || !output_filename) {
if (!ctx.cfg_filename || !output_filename) {
fprintf(stderr, "ERROR: Input files not specified!\n\n");
print_help(argv[0]);
return -1;
}
ret = set_cpu(&ctx, argv[0], cpuid);
if (ret)
goto fail;
ret = sb_parse_image(&ctx);
if (ret)
goto fail;
......
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