| 477 | } |
| 478 | |
| 479 | static void dump_flashrom_layout(char *image, int size, const char *layout_fname) |
| 480 | { |
| 481 | const struct frba *frba = find_frba(image, size); |
| 482 | if (!frba) |
| 483 | exit(EXIT_FAILURE); |
| 484 | |
| 485 | int layout_fd = open(layout_fname, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 486 | if (layout_fd == -1) { |
| 487 | perror("Could not open file"); |
| 488 | exit(EXIT_FAILURE); |
| 489 | } |
| 490 | |
| 491 | for (unsigned int i = 0; i < max_regions; i++) { |
| 492 | struct region region = get_region(frba, i); |
| 493 | |
| 494 | /* A region limit of 0 is an indicator of an unused region |
| 495 | * A region base of 7FFFh is an indicator of a reserved region |
| 496 | */ |
| 497 | if (region.limit == 0 || region.base == 0x07FFF000) |
| 498 | continue; |
| 499 | |
| 500 | char buf[LAYOUT_LINELEN]; |
| 501 | snprintf(buf, LAYOUT_LINELEN, "%08x:%08x %s\n", region.base, region.limit, region_names[i].terse); |
| 502 | if (write(layout_fd, buf, strlen(buf)) < 0) { |
| 503 | perror("Could not write to file"); |
| 504 | exit(EXIT_FAILURE); |
| 505 | } |
| 506 | } |
| 507 | close(layout_fd); |
| 508 | printf("Wrote layout to %s\n", layout_fname); |
| 509 | } |
| 510 | |
| 511 | static void _decode_spi_frequency(unsigned int freq) |
| 512 | { |