Commit 65851fcec305bae079b35e17103aa61c8ef54674
1 parent
fa8d3b00f9
Exists in
v2017.01-smarct4x
and in
37 other branches
x86: ifdtool: Use a structure for the file/address list
Rather than two independent arrays, use a single array of a suitable structure. Also add a 'type' member since we will shortly add additional types. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Showing 1 changed file with 18 additions and 6 deletions Side-by-side Diff
tools/ifdtool.c
... | ... | @@ -32,6 +32,16 @@ |
32 | 32 | #define FLREG_BASE(reg) ((reg & 0x00000fff) << 12); |
33 | 33 | #define FLREG_LIMIT(reg) (((reg & 0x0fff0000) >> 4) | 0xfff); |
34 | 34 | |
35 | +enum input_file_type_t { | |
36 | + IF_normal, | |
37 | +}; | |
38 | + | |
39 | +struct input_file { | |
40 | + char *fname; | |
41 | + unsigned int addr; | |
42 | + enum input_file_type_t type; | |
43 | +}; | |
44 | + | |
35 | 45 | /** |
36 | 46 | * find_fd() - Find the flash description in the ROM image |
37 | 47 | * |
... | ... | @@ -790,8 +800,7 @@ |
790 | 800 | char *desc_fname = NULL, *addr_str = NULL; |
791 | 801 | int region_type = -1, inputfreq = 0; |
792 | 802 | enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ; |
793 | - unsigned int addr[WRITE_MAX]; | |
794 | - char *wr_fname[WRITE_MAX]; | |
803 | + struct input_file input_file[WRITE_MAX], *ifile; | |
795 | 804 | unsigned char wr_idx, wr_num = 0; |
796 | 805 | int rom_size = -1; |
797 | 806 | bool write_it; |
798 | 807 | |
799 | 808 | |
... | ... | @@ -895,14 +904,16 @@ |
895 | 904 | exit(EXIT_SUCCESS); |
896 | 905 | break; |
897 | 906 | case 'w': |
907 | + ifile = &input_file[wr_num]; | |
898 | 908 | mode_write = 1; |
899 | 909 | if (wr_num < WRITE_MAX) { |
900 | 910 | if (get_two_words(optarg, &addr_str, |
901 | - &wr_fname[wr_num])) { | |
911 | + &ifile->fname)) { | |
902 | 912 | print_usage(argv[0]); |
903 | 913 | exit(EXIT_FAILURE); |
904 | 914 | } |
905 | - addr[wr_num] = strtol(optarg, NULL, 0); | |
915 | + ifile->addr = strtol(optarg, NULL, 0); | |
916 | + ifile->type = IF_normal; | |
906 | 917 | wr_num++; |
907 | 918 | } else { |
908 | 919 | fprintf(stderr, |
... | ... | @@ -1022,8 +1033,9 @@ |
1022 | 1033 | |
1023 | 1034 | if (mode_write) { |
1024 | 1035 | for (wr_idx = 0; wr_idx < wr_num; wr_idx++) { |
1025 | - ret = write_data(image, size, | |
1026 | - addr[wr_idx], wr_fname[wr_idx]); | |
1036 | + ifile = &input_file[wr_idx]; | |
1037 | + ret = write_data(image, size, ifile->addr, | |
1038 | + ifile->fname); | |
1027 | 1039 | if (ret) |
1028 | 1040 | break; |
1029 | 1041 | } |