static uint32_t parse_cfg_file(struct ubl_header *ublhdr, char *name) { FILE *fd = NULL; char *line = NULL; char *token, *saveptr1, *saveptr2; int lineno = 0; int i; char *ptr = (char *)ublhdr; int fld; size_t len; int dcd_len = 0; int32_t cmd; int ublhdrlen = sizeof(struct ubl_header); fd = fopen(name, "r"); if (fd == 0) { fprintf(stderr, "Error: %s - Can't open DCD file\n", name); exit(EXIT_FAILURE); } /* Fill header with 0xff */ for (i = 0; i < ublhdrlen; i++) { *ptr = 0xff; ptr++; } /* * Very simple parsing, line starting with # are comments * and are dropped */ while ((getline(&line, &len, fd)) > 0) { lineno++; token = strtok_r(line, "\r\n", &saveptr1); if (token == NULL) continue; /* Check inside the single line */ for (fld = CFG_COMMAND, cmd = CMD_INVALID, line = token; ; line = NULL, fld++) { token = strtok_r(line, " \t", &saveptr2); if (token == NULL) break; /* Drop all text starting with '#' as comments */ if (token[0] == '#') break; parse_cfg_fld(ublhdr, &cmd, token, name, lineno, fld, &dcd_len); } } fclose(fd); return dcd_len; }
static uint32_t parse_cfg_file(struct imx_header *imxhdr, char *name) { FILE *fd = NULL; char *line = NULL; char *token, *saveptr1, *saveptr2; int lineno = 0; int fld; size_t len; int dcd_len = 0; int32_t cmd; fd = fopen(name, "r"); if (fd == 0) { fprintf(stderr, "Error: %s - Can't open DCD file\n", name); exit(EXIT_FAILURE); } /* * Very simple parsing, line starting with # are comments * and are dropped */ while ((getline(&line, &len, fd)) > 0) { lineno++; token = strtok_r(line, "\r\n", &saveptr1); if (token == NULL) continue; /* Check inside the single line */ for (fld = CFG_COMMAND, cmd = CMD_INVALID, line = token; ; line = NULL, fld++) { token = strtok_r(line, " \t", &saveptr2); if (token == NULL) break; /* Drop all text starting with '#' as comments */ if (token[0] == '#') break; parse_cfg_fld(imxhdr, &cmd, token, name, lineno, fld, &dcd_len); } } (*set_dcd_rst)(imxhdr, dcd_len, name, lineno); fclose(fd); /* Exit if there is no BOOT_FROM field specifying the flash_offset */ if (imximage_ivt_offset == FLASH_OFFSET_UNDEFINED) { fprintf(stderr, "Error: No BOOT_FROM tag in %s\n", name); exit(EXIT_FAILURE); } return dcd_len; }
static uint32_t parse_cfg_file(image_t *param_stack, char *name) { FILE *fd = NULL; char *line = NULL; char *token, *saveptr1, *saveptr2; int lineno = 0; int fld; size_t len; int32_t cmd; fd = fopen(name, "r"); if (fd == 0) { fprintf(stderr, "Error: %s - Can't open cfg file\n", name); exit(EXIT_FAILURE); } /* * Very simple parsing, line starting with # are comments * and are dropped */ while ((getline(&line, &len, fd)) > 0) { lineno++; token = strtok_r(line, "\r\n", &saveptr1); if (!token) continue; /* Check inside the single line */ for (fld = CFG_COMMAND, cmd = CFG_INVALID, line = token; ; line = NULL, fld++) { token = strtok_r(line, " \t", &saveptr2); if (!token) break; /* Drop all text starting with '#' as comments */ if (token[0] == '#') break; parse_cfg_fld(param_stack, &cmd, token, name, lineno, fld); } } return 0; }