*/
#include "imx8image.h"
+#include <image.h>
static int p_idx;
static int sector_size;
unsigned char *ptr;
uint8_t zeros[0x4000];
int size;
+ int ret;
if (align > 0x4000) {
fprintf(stderr, "Wrong alignment requested %d\n", align);
}
size = sbuf.st_size;
- lseek(ifd, offset, SEEK_SET);
+ ret = lseek(ifd, offset, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "%s: lseek error %s\n",
+ __func__, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
if (write(ifd, ptr, size) != size) {
fprintf(stderr, "Write error %s\n", strerror(errno));
exit(EXIT_FAILURE);
int tail;
int zero = 0;
uint8_t zeros[4096];
- int size;
+ int size, ret;
memset(zeros, 0, sizeof(zeros));
}
size = sbuf.st_size;
- lseek(ifd, offset, SEEK_SET);
+ ret = lseek(ifd, offset, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "%s: lseek error %s\n",
+ __func__, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
if (write(ifd, ptr, size) != size) {
fprintf(stderr, "Write error %s\n",
strerror(errno));
} else if (soc == QM && core == CORE_CA72) {
meta = IMAGE_A72_DEFAULT_META(custom_partition);
} else {
- fprintf(stderr, "Error: invalid AP core id: %lu\n",
+ fprintf(stderr,
+ "Error: invalid AP core id: %" PRIu64 "\n",
core);
exit(EXIT_FAILURE);
}
core = CORE_CM4_1;
meta = IMAGE_M4_1_DEFAULT_META(custom_partition);
} else {
- fprintf(stderr, "Error: invalid m4 core id: %lu\n", core);
+ fprintf(stderr,
+ "Error: invalid m4 core id: %" PRIu64 "\n",
+ core);
exit(EXIT_FAILURE);
}
img->hab_flags |= IMG_TYPE_EXEC;
}
ret = fread(&header, sizeof(header), 1, fd);
- if (ret != 1)
+ if (ret != 1) {
printf("Failure Read header %d\n", ret);
+ exit(EXIT_FAILURE);
+ }
fclose(fd);
if (header.tag != IVT_HEADER_TAG_B0) {
- fprintf(stderr, "header tag missmatched \n");
+ fprintf(stderr, "header tag mismatched \n");
exit(EXIT_FAILURE);
} else {
file_off +=
char *tmp_filename = NULL;
uint32_t size = 0;
uint32_t file_padding = 0;
+ int ret;
int container = -1;
int cont_img_count = 0; /* indexes to arrange the container */
case SCFW:
case DATA:
case MSG_BLOCK:
+ if (container < 0) {
+ fprintf(stderr, "No container found\n");
+ exit(EXIT_FAILURE);
+ }
check_file(&sbuf, img_sp->filename);
tmp_filename = img_sp->filename;
set_image_array_entry(&imx_header.fhdr[container],
break;
case SECO:
+ if (container < 0) {
+ fprintf(stderr, "No container found\n");
+ exit(EXIT_FAILURE);
+ }
check_file(&sbuf, img_sp->filename);
tmp_filename = img_sp->filename;
set_image_array_entry(&imx_header.fhdr[container],
} while (img_sp->option != NO_IMG);
/* Add padding or skip appended container */
- lseek(ofd, file_padding, SEEK_SET);
-
- /* Note: Image offset are not contained in the image */
- tmp = flatten_container_header(&imx_header, container + 1, &size,
- file_padding);
- /* Write image header */
- if (write(ofd, tmp, size) != size) {
- fprintf(stderr, "error writing image hdr\n");
+ ret = lseek(ofd, file_padding, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "%s: lseek error %s\n",
+ __func__, strerror(errno));
exit(EXIT_FAILURE);
}
- /* Clean-up memory used by the headers */
- free(tmp);
+ if (container >= 0) {
+ /* Note: Image offset are not contained in the image */
+ tmp = flatten_container_header(&imx_header, container + 1,
+ &size, file_padding);
+ /* Write image header */
+ if (write(ofd, tmp, size) != size) {
+ fprintf(stderr, "error writing image hdr\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Clean-up memory used by the headers */
+ free(tmp);
+ }
/*
* step through the image stack again this time copying