Commit 60a67d8f authored by Marek Vasut's avatar Marek Vasut

mxssb: Wrap the input and output filename into image context

Instead of having such free-standing variables, wrap the input
and output file names into image context alongside configuration
file name.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 6eb8564b
......@@ -70,6 +70,8 @@ struct sb_section_ctx {
struct sb_image_ctx {
/* Image configuration */
unsigned int verbose_boot:1;
char *input_filename;
char *output_filename;
char *cfg_filename;
/* Number of section in the image */
......@@ -350,8 +352,6 @@ static int sb_encrypt_image(struct sb_image_ctx *ictx)
return 0;
}
char *output_filename = NULL;
static int sb_write_image(struct sb_image_ctx *ictx)
{
struct sb_boot_image_header *sb_header = &ictx->payload;
......@@ -363,7 +363,7 @@ static int sb_write_image(struct sb_image_ctx *ictx)
int fd;
ssize_t ret;
fd = open(output_filename, O_CREAT | O_WRONLY, 0644);
fd = open(ictx->output_filename, O_CREAT | O_WRONLY, 0644);
if (fd < 0)
return -EINVAL;
......@@ -1731,20 +1731,17 @@ static int sb_verify_image_end(struct sb_image_ctx *ictx, int fd, off_t filesz)
}
char *input_filename;
static int sb_build_tree_from_img(struct sb_image_ctx *ictx)
{
const char *filename = input_filename;
off_t filesize;
int fd, ret;
if (!filename) {
if (!ictx->input_filename) {
fprintf(stderr, "ERR: Missing filename!\n");
return -EINVAL;
}
fd = open(filename, O_RDONLY);
fd = open(ictx->input_filename, O_RDONLY);
if (fd < 0)
goto err_open;
......@@ -1788,7 +1785,7 @@ err_verify:
err_file:
close(fd);
err_open:
fprintf(stderr, "ERR: Failed to load file \"%s\"\n", filename);
fprintf(stderr, "ERR: Failed to load file \"%s\"\n", ictx->input_filename);
return -EINVAL;
}
......@@ -1840,10 +1837,10 @@ int main(int argc, char **argv)
ctx.cfg_filename = optarg;
break;
case 'o':
output_filename = optarg;
ctx.output_filename = optarg;
break;
case 'i':
input_filename = optarg;
ctx.input_filename = optarg;
break;
case 'v':
ctx.verbose_boot = 1;
......@@ -1864,10 +1861,10 @@ int main(int argc, char **argv)
return -EINVAL;
}
if (input_filename && !(ctx.cfg_filename || output_filename)) {
if (ctx.input_filename && !(ctx.cfg_filename || ctx.output_filename)) {
/* Image verification and dump. */
ret = sb_build_tree_from_img(&ctx);
} else if (!input_filename && (ctx.cfg_filename && output_filename)) {
} else if (!ctx.input_filename && (ctx.cfg_filename && ctx.output_filename)) {
/* Image creation */
ret = sb_build_tree_from_cfg(&ctx);
if (ret)
......
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