From bab66cefe125202062f1dd7772221c82ef3ae843 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 14 Jul 2013 22:09:38 +0200 Subject: [PATCH] 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 --- mxssb.c | 141 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 65 deletions(-) diff --git a/mxssb.c b/mxssb.c index 4368015..9d2ff75 100644 --- a/mxssb.c +++ b/mxssb.c @@ -943,10 +943,81 @@ static int sb_fixup_sections_and_tags(struct sb_image_ctx *ictx) 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) { int ret; + ret = sb_load_cmdfile(ictx); + if (ret) + return ret; + ret = sb_prefill_image_header(ictx); if (ret) return ret; @@ -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) { - char **table; - unsigned int i; - size_t flen, llen; - if (!strcmp("mx23", cpu)) { ictx->target_cpu = CPU_MX23; - ictx->sb_insts = sizeof(sb_input_mx23)/sizeof(sb_input_mx23[0]); - ictx->sb_insts_pos = 0; + return 0; } if (!strcmp("mx28", cpu)) { ictx->target_cpu = CPU_MX28; - ictx->sb_insts = sizeof(sb_input_mx28)/sizeof(sb_input_mx28[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]); - } - } + return 0; } - ictx->sb_input = table; - - return 0; + fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu); + print_help(pn); + return -EINVAL; } int main(int argc, char **argv) -- GitLab