Commit bab66cef authored by Marek Vasut's avatar Marek Vasut

mxssb: Shift command file parsing into separate funciton

The command file parsing should be in a separate function and
should be called right before the image is being produced. Move
the parsing into separate function from set_cpu().
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 308c9756
...@@ -943,10 +943,81 @@ static int sb_fixup_sections_and_tags(struct sb_image_ctx *ictx) ...@@ -943,10 +943,81 @@ static int sb_fixup_sections_and_tags(struct sb_image_ctx *ictx)
return 0; return 0;
} }
static int sb_load_cmdfile(struct sb_image_ctx *ictx)
{
char **table;
unsigned int i;
size_t flen, llen;
if (ictx->target_cpu == CPU_MX23) {
ictx->sb_insts = sizeof(sb_input_mx23)/sizeof(sb_input_mx23[0]);
ictx->sb_insts_pos = 0;
} else if (ictx->target_cpu == CPU_MX28) {
ictx->sb_insts = sizeof(sb_input_mx28)/sizeof(sb_input_mx28[0]);
ictx->sb_insts_pos = 0;
}
table = calloc(1, ictx->sb_insts * sizeof(*table));
if (!table)
return -ENOMEM;
for (i = 0; i < ictx->sb_insts; i++) {
/* Compat -- patch in the file names */
if (ictx->target_cpu == CPU_MX23) {
if (i == 3) {
llen = strlen(sb_input_mx23[i]);
flen = strlen(ictx->spl_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx23[i], ictx->spl_filename);
} else if (i == 5) {
llen = strlen(sb_input_mx23[i]);
flen = strlen(ictx->uboot_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx23[i], ictx->uboot_filename);
} else {
table[i] = strdup(sb_input_mx23[i]);
}
} else {
if (i == 3) {
llen = strlen(sb_input_mx28[i]);
flen = strlen(ictx->spl_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx28[i], ictx->spl_filename);
} else if (i == 6) {
llen = strlen(sb_input_mx28[i]);
flen = strlen(ictx->uboot_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx28[i], ictx->uboot_filename);
} else {
table[i] = strdup(sb_input_mx28[i]);
}
}
}
ictx->sb_input = table;
return 0;
}
static int sb_parse_image(struct sb_image_ctx *ictx) static int sb_parse_image(struct sb_image_ctx *ictx)
{ {
int ret; int ret;
ret = sb_load_cmdfile(ictx);
if (ret)
return ret;
ret = sb_prefill_image_header(ictx); ret = sb_prefill_image_header(ictx);
if (ret) if (ret)
return ret; return ret;
...@@ -1013,79 +1084,19 @@ static void print_help(const char *pn) ...@@ -1013,79 +1084,19 @@ static void print_help(const char *pn)
static int set_cpu(struct sb_image_ctx *ictx, const char *pn, const char *cpu) static int set_cpu(struct sb_image_ctx *ictx, const char *pn, const char *cpu)
{ {
char **table;
unsigned int i;
size_t flen, llen;
if (!strcmp("mx23", cpu)) { if (!strcmp("mx23", cpu)) {
ictx->target_cpu = CPU_MX23; ictx->target_cpu = CPU_MX23;
ictx->sb_insts = sizeof(sb_input_mx23)/sizeof(sb_input_mx23[0]); return 0;
ictx->sb_insts_pos = 0;
} }
if (!strcmp("mx28", cpu)) { if (!strcmp("mx28", cpu)) {
ictx->target_cpu = CPU_MX28; ictx->target_cpu = CPU_MX28;
ictx->sb_insts = sizeof(sb_input_mx28)/sizeof(sb_input_mx28[0]); return 0;
ictx->sb_insts_pos = 0;
}
if (ictx->target_cpu == CPU_UNKNOWN) {
fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu);
print_help(pn);
return -EINVAL;
}
table = calloc(1, ictx->sb_insts * sizeof(*table));
if (!table)
return -ENOMEM;
for (i = 0; i < ictx->sb_insts; i++) {
/* Compat -- patch in the file names */
if (ictx->target_cpu == CPU_MX23) {
if (i == 3) {
llen = strlen(sb_input_mx23[i]);
flen = strlen(ictx->spl_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx23[i], ictx->spl_filename);
} else if (i == 5) {
llen = strlen(sb_input_mx23[i]);
flen = strlen(ictx->uboot_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx23[i], ictx->uboot_filename);
} else {
table[i] = strdup(sb_input_mx23[i]);
}
} else {
if (i == 3) {
llen = strlen(sb_input_mx28[i]);
flen = strlen(ictx->spl_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx28[i], ictx->spl_filename);
} else if (i == 6) {
llen = strlen(sb_input_mx28[i]);
flen = strlen(ictx->uboot_filename);
table[i] = calloc(1, llen + flen + 1);
if (!table[i])
return -ENOMEM;
snprintf(table[i], llen + flen + 1, "%s%s",
sb_input_mx28[i], ictx->uboot_filename);
} else {
table[i] = strdup(sb_input_mx28[i]);
}
}
} }
ictx->sb_input = table; fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu);
print_help(pn);
return 0; return -EINVAL;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
......
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