Lines Matching defs:info

81 static void scramble(const struct image_info *info,
88 if (info->boot0) {
91 unsigned seedmod = info->eraseblock_size / info->page_size;
94 if (!info->scramble)
113 static int write_page(const struct image_info *info, uint8_t *buffer,
117 int steps = info->usable_page_size / info->ecc_step_size;
118 int eccbytes = DIV_ROUND_UP(info->ecc_strength * 14, 8);
126 memset(buffer, 0xff, info->page_size + info->oob_size);
127 cnt = fread(buffer, 1, info->usable_page_size, src);
138 fwrite(buffer, info->page_size + info->oob_size, 1, dst);
140 for (i = 0; i < info->usable_page_size; i++) {
146 if (i == info->usable_page_size)
153 if (info->scramble) {
156 if (info->boot0) {
159 offs = steps * (info->ecc_step_size + eccbytes + 4);
160 cnt = info->page_size + info->oob_size - offs;
168 offs = info->page_size + (steps * (eccbytes + 4));
169 cnt = info->page_size + info->oob_size - offs;
171 scramble(info, page, buffer + offs, cnt);
181 memset(buffer, 0xff, info->ecc_step_size + eccbytes + 4);
182 ecc = buffer + info->ecc_step_size + 4;
183 if (info->boot0) {
184 data_offs = i * (info->ecc_step_size + eccbytes + 4);
185 ecc_offs = data_offs + info->ecc_step_size + 4;
187 data_offs = i * info->ecc_step_size;
188 ecc_offs = info->page_size + 4 + (i * (eccbytes + 4));
191 cnt = fread(buffer, 1, info->ecc_step_size, src);
198 pad = info->ecc_step_size - cnt;
200 if (info->scramble && info->boot0) {
215 swap_bits(buffer, info->ecc_step_size + 4);
216 encode_bch(bch, buffer, info->ecc_step_size + 4, ecc);
217 swap_bits(buffer, info->ecc_step_size + 4);
219 scramble(info, page, buffer, info->ecc_step_size + 4 + eccbytes);
222 fwrite(buffer, info->ecc_step_size, 1, dst);
228 fseek(dst, pos + info->page_size, SEEK_SET);
233 fseek(dst, pos + info->page_size + info->oob_size, SEEK_SET);
238 static int create_image(const struct image_info *info)
240 off_t page = info->offset / info->page_size;
245 bch = init_bch(14, info->ecc_strength, BCH_PRIMITIVE_POLY);
251 buffer = malloc(info->page_size + info->oob_size);
257 memset(buffer, 0xff, info->page_size + info->oob_size);
259 src = fopen(info->source, "r");
262 info->source);
266 dst = fopen(info->dest, "w");
268 fprintf(stderr, "Failed to open dest file (%s)\n", info->dest);
281 ret = write_page(info, buffer, src, rnd, dst, bch, page++);
343 static int check_image_info(struct image_info *info)
349 if (!info->page_size) {
354 if (!info->page_size) {
359 if (!info->eraseblock_size) {
364 if (info->ecc_step_size != 512 && info->ecc_step_size != 1024) {
366 info->ecc_step_size);
371 if (valid_ecc_strengths[i] == info->ecc_strength)
377 info->ecc_strength);
381 eccbytes = DIV_ROUND_UP(info->ecc_strength * 14, 8);
386 eccsteps = info->usable_page_size / info->ecc_step_size;
388 if (info->page_size + info->oob_size <
389 info->usable_page_size + (eccsteps * eccbytes)) {
400 struct image_info info;
402 memset(&info, 0, sizeof(info));
432 info.scramble = 1;
435 info.ecc_strength = strtol(optarg, &endptr, 0);
437 info.ecc_step_size = strtol(endptr + 1, NULL, 0);
440 info.page_size = strtol(optarg, NULL, 0);
443 info.oob_size = strtol(optarg, NULL, 0);
446 info.usable_page_size = strtol(optarg, NULL, 0);
449 info.eraseblock_size = strtol(optarg, NULL, 0);
452 info.boot0 = 1;
455 info.offset = strtoull(optarg, NULL, 0);
466 info.source = argv[optind];
467 info.dest = argv[optind + 1];
469 if (!info.boot0) {
470 info.usable_page_size = info.page_size;
471 } else if (!info.usable_page_size) {
472 if (info.page_size > 8192)
473 info.usable_page_size = 8192;
474 else if (info.page_size > 4096)
475 info.usable_page_size = 4096;
477 info.usable_page_size = 1024;
480 if (check_image_info(&info))
483 return create_image(&info);