summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
commite6b18f7fa973e22f4a7829412a9ac1aabb51b286 (patch)
tree521d2da0cd5f0cd3025ff72afa5a1e7157fea011 /scripts
parent13e7822149d6f7653dabba6b4e4a1f122d3dae6f (diff)
parent527422a4ad764c46bc958f91603e6b5e9860d4ba (diff)
downloadbarebox-e6b18f7fa973e22f4a7829412a9ac1aabb51b286.tar.gz
barebox-e6b18f7fa973e22f4a7829412a9ac1aabb51b286.tar.xz
Merge branch 'for-next/imx'
Diffstat (limited to 'scripts')
-rw-r--r--scripts/imx/imx-image.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 34a072039d..a7f1421fa3 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -153,7 +153,8 @@ static int extract_key(const char *certfile, uint8_t **modulus, int *modulus_len
fp = fopen(certfile, "r");
if (!fp) {
- fprintf(stderr, "unable to open certfile: %s\n", certfile);
+ fprintf(stderr, "unable to open certfile %s: %s\n", certfile,
+ strerror(errno));
return -errno;
}
@@ -458,7 +459,8 @@ static void write_dcd(const char *outfile)
outfd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (outfd < 0) {
- perror("open");
+ fprintf(stderr, "Cannot open %s for wrinting: %s\n", outfile,
+ strerror(errno));
exit(1);
}
@@ -671,6 +673,11 @@ static int hab_sign(struct config_data *data)
}
outfd = open(data->outfile, O_WRONLY | O_APPEND);
+ if (outfd < 0) {
+ fprintf(stderr, "Cannot open %s for writing: %s\n", data->outfile,
+ strerror(errno));
+ exit(1);
+ }
ret = xwrite(outfd, buf, csf_space);
if (ret < 0) {
@@ -687,7 +694,7 @@ static int hab_sign(struct config_data *data)
return 0;
}
-static void *read_file(const char *filename, size_t *size)
+static void *xread_file(const char *filename, size_t *size)
{
int fd, ret;
void *buf;
@@ -695,18 +702,22 @@ static void *read_file(const char *filename, size_t *size)
fd = open(filename, O_RDONLY);
if (fd < 0) {
- perror("open");
+ fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno));
exit(1);
}
ret = fstat(fd, &s);
- if (ret)
- return NULL;
+ if (ret) {
+ fprintf(stderr, "Cannot stat %s: %s\n", filename, strerror(errno));
+ exit(1);
+ }
*size = s.st_size;
buf = malloc(*size);
- if (!buf)
+ if (!buf) {
+ perror("malloc");
exit(1);
+ }
xread(fd, buf, *size);
@@ -877,12 +888,8 @@ int main(int argc, char *argv[])
if (data.signed_hdmi_firmware_file) {
free(buf);
- buf = read_file(data.signed_hdmi_firmware_file,
+ buf = xread_file(data.signed_hdmi_firmware_file,
&signed_hdmi_firmware_size);
- if (!buf) {
- perror("read_file");
- exit(1);
- }
signed_hdmi_firmware_size =
roundup(signed_hdmi_firmware_size,
@@ -924,13 +931,12 @@ int main(int argc, char *argv[])
bb_header[0] = data.first_opcode;
bb_header[ARM_HEAD_SIZE_INDEX] = barebox_image_size;
- infile = read_file(imagename, &insize);
- if (!infile)
- exit(1);
+ infile = xread_file(imagename, &insize);
outfd = open(data.outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (outfd < 0) {
- perror("open");
+ fprintf(stderr, "Cannot open %s for writing: %s\n", data.outfile,
+ strerror(errno));
exit(1);
}
@@ -990,7 +996,7 @@ int main(int argc, char *argv[])
if (create_usb_image) {
uint32_t *dcd;
- infile = read_file(data.outfile, &insize);
+ infile = xread_file(data.outfile, &insize);
dcd = infile + dcd_ptr_offset;
*dcd = dcd_ptr_content;