+ fclose(bin);
+
+ cur += s.st_size;
+
+ /*
+ * For now, we don't support more than one binary
+ * header, and no other header types are
+ * supported. So, the binary header is necessarily the
+ * last one
+ */
+ *((unsigned char *)cur) = 0;
+
+ cur += sizeof(uint32_t);
+ }
+
+ /* Calculate and set the header checksum */
+ main_hdr->checksum = image_checksum8(main_hdr, headersz);
+
+ *imagesz = headersz;
+ return image;
+}
+
+static int image_create_config_parse_oneline(char *line,
+ struct image_cfg_element *el)
+{
+ char *keyword, *saveptr;
+ char deliminiters[] = " \t";
+
+ keyword = strtok_r(line, deliminiters, &saveptr);
+ if (!strcmp(keyword, "VERSION")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ el->type = IMAGE_CFG_VERSION;
+ el->version = atoi(value);
+ } else if (!strcmp(keyword, "BOOT_FROM")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ int ret = image_boot_mode_id(value);
+ if (ret < 0) {
+ fprintf(stderr,
+ "Invalid boot media '%s'\n", value);
+ return -1;
+ }
+ el->type = IMAGE_CFG_BOOT_FROM;
+ el->bootfrom = ret;
+ } else if (!strcmp(keyword, "NAND_BLKSZ")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ el->type = IMAGE_CFG_NAND_BLKSZ;
+ el->nandblksz = strtoul(value, NULL, 16);
+ } else if (!strcmp(keyword, "NAND_BADBLK_LOCATION")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ el->type = IMAGE_CFG_NAND_BADBLK_LOCATION;
+ el->nandbadblklocation =
+ strtoul(value, NULL, 16);
+ } else if (!strcmp(keyword, "NAND_ECC_MODE")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ int ret = image_nand_ecc_mode_id(value);
+ if (ret < 0) {
+ fprintf(stderr,
+ "Invalid NAND ECC mode '%s'\n", value);
+ return -1;
+ }
+ el->type = IMAGE_CFG_NAND_ECC_MODE;
+ el->nandeccmode = ret;
+ } else if (!strcmp(keyword, "NAND_PAGE_SIZE")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ el->type = IMAGE_CFG_NAND_PAGESZ;
+ el->nandpagesz = strtoul(value, NULL, 16);
+ } else if (!strcmp(keyword, "BINARY")) {
+ char *value = strtok_r(NULL, deliminiters, &saveptr);
+ int argi = 0;
+
+ el->type = IMAGE_CFG_BINARY;
+ el->binary.file = strdup(value);
+ while (1) {
+ value = strtok_r(NULL, deliminiters, &saveptr);
+ if (!value)
+ break;
+ el->binary.args[argi] = strtoul(value, NULL, 16);
+ argi++;
+ if (argi >= BINARY_MAX_ARGS) {
+ fprintf(stderr,
+ "Too many argument for binary\n");
+ return -1;