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

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 { ...@@ -70,6 +70,8 @@ struct sb_section_ctx {
struct sb_image_ctx { struct sb_image_ctx {
/* Image configuration */ /* Image configuration */
unsigned int verbose_boot:1; unsigned int verbose_boot:1;
char *input_filename;
char *output_filename;
char *cfg_filename; char *cfg_filename;
/* Number of section in the image */ /* Number of section in the image */
...@@ -350,8 +352,6 @@ static int sb_encrypt_image(struct sb_image_ctx *ictx) ...@@ -350,8 +352,6 @@ static int sb_encrypt_image(struct sb_image_ctx *ictx)
return 0; return 0;
} }
char *output_filename = NULL;
static int sb_write_image(struct sb_image_ctx *ictx) static int sb_write_image(struct sb_image_ctx *ictx)
{ {
struct sb_boot_image_header *sb_header = &ictx->payload; struct sb_boot_image_header *sb_header = &ictx->payload;
...@@ -363,7 +363,7 @@ static int sb_write_image(struct sb_image_ctx *ictx) ...@@ -363,7 +363,7 @@ static int sb_write_image(struct sb_image_ctx *ictx)
int fd; int fd;
ssize_t ret; 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) if (fd < 0)
return -EINVAL; return -EINVAL;
...@@ -1731,20 +1731,17 @@ static int sb_verify_image_end(struct sb_image_ctx *ictx, int fd, off_t filesz) ...@@ -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) static int sb_build_tree_from_img(struct sb_image_ctx *ictx)
{ {
const char *filename = input_filename;
off_t filesize; off_t filesize;
int fd, ret; int fd, ret;
if (!filename) { if (!ictx->input_filename) {
fprintf(stderr, "ERR: Missing filename!\n"); fprintf(stderr, "ERR: Missing filename!\n");
return -EINVAL; return -EINVAL;
} }
fd = open(filename, O_RDONLY); fd = open(ictx->input_filename, O_RDONLY);
if (fd < 0) if (fd < 0)
goto err_open; goto err_open;
...@@ -1788,7 +1785,7 @@ err_verify: ...@@ -1788,7 +1785,7 @@ err_verify:
err_file: err_file:
close(fd); close(fd);
err_open: 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; return -EINVAL;
} }
...@@ -1840,10 +1837,10 @@ int main(int argc, char **argv) ...@@ -1840,10 +1837,10 @@ int main(int argc, char **argv)
ctx.cfg_filename = optarg; ctx.cfg_filename = optarg;
break; break;
case 'o': case 'o':
output_filename = optarg; ctx.output_filename = optarg;
break; break;
case 'i': case 'i':
input_filename = optarg; ctx.input_filename = optarg;
break; break;
case 'v': case 'v':
ctx.verbose_boot = 1; ctx.verbose_boot = 1;
...@@ -1864,10 +1861,10 @@ int main(int argc, char **argv) ...@@ -1864,10 +1861,10 @@ int main(int argc, char **argv)
return -EINVAL; return -EINVAL;
} }
if (input_filename && !(ctx.cfg_filename || output_filename)) { if (ctx.input_filename && !(ctx.cfg_filename || ctx.output_filename)) {
/* Image verification and dump. */ /* Image verification and dump. */
ret = sb_build_tree_from_img(&ctx); 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 */ /* Image creation */
ret = sb_build_tree_from_cfg(&ctx); ret = sb_build_tree_from_cfg(&ctx);
if (ret) 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