Skip to contentSkip to conversation

tools/ifdtool: Support writing multiple files (-w) simultaneously

PATCH New Bin Meng 2 participants 3 messages Dec 4, 2014 – Dec 5, 2014

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 2/25 tools/ifdtool: Support writing multiple files (-w) simultaneously

Currently ifdtool only supports writing one file (-w) at a time. This looks verbose when generating u-boot.rom for x86 targets. This change allows at most 16 files to be written simultaneously.

---
 tools/ifdtool.c | 29 ++++++++++++++++++++++-------
 tools/ifdtool.h |  2 ++
 2 files changed, 24 insertions(+), 7 deletions(-)
tools/ifdtool.c +22 -7
index a4b481f..58640ca 100644
@@ -732,6 +732,7 @@ static void print_usage(const char *name)
 	       "   -x | --extract:                   extract intel fd modules\n"
 	       "   -i | --inject <region>:<module>   inject file <module> into region <region>\n"
 	       "   -w | --write <addr>:<file>        write file to appear at memory address <addr>\n"
+	       "                                     multiple files can be written simultaneously\n"
 	       "   -s | --spifreq <20|33|50>         set the SPI frequency\n"
 	       "   -e | --em100                      set SPI frequency to 20MHz and disable\n"
 	       "                                     Dual Output Fast Read Support\n"
@@ -782,7 +783,9 @@ int main(int argc, char *argv[])
 	char *addr_str = NULL;
 	int region_type = -1, inputfreq = 0;
 	enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ;
-	unsigned int addr = 0;
+	unsigned int addr[WRITE_NUM] = { 0 };
+	char *wr_fname[WRITE_NUM] = { NULL };
+	unsigned char wr_idx, wr_num = 0;
 	int rom_size = -1;
 	bool write_it;
 	char *filename;
@@ -886,11 +889,17 @@ int main(int argc, char *argv[])
 			break;
 		case 'w':
 			mode_write = 1;
-			if (get_two_words(optarg, &addr_str, &src_fname)) {
-				print_usage(argv[0]);
-				exit(EXIT_FAILURE);
+			if (wr_num < WRITE_NUM) {
+				if (get_two_words(optarg, &addr_str,
+						  &wr_fname[wr_num])) {
+					print_usage(argv[0]);
+					exit(EXIT_FAILURE);
+				}
+				addr[wr_num] = strtol(optarg, NULL, 0);
+				wr_num++;
+			} else {
+				fprintf(stderr, "The number of files to write simultaneously exceeds the limitation (%d)\n", WRITE_NUM);
 			}
-			addr = strtol(optarg, NULL, 0);
 			break;
 		case 'x':
 			mode_extract = 1;
@@ -1002,8 +1011,14 @@ int main(int argc, char *argv[])
 	if (mode_inject)
 		ret = inject_region(image, size, region_type, src_fname);
 
-	if (mode_write)
-		ret = write_data(image, size, addr, src_fname);
+	if (mode_write) {
+		for (wr_idx = 0; wr_idx < wr_num; wr_idx++) {
+			ret = write_data(image, size,
+					 addr[wr_idx], wr_fname[wr_idx]);
+			if (ret)
+				break;
+		}
+	}
 
 	if (mode_spifreq)
 		set_spi_frequency(image, size, spifreq);
tools/ifdtool.h +2 -0
index fbec421..72ba1de 100644
@@ -14,6 +14,8 @@
 
 #define IFDTOOL_VERSION "1.1-U-Boot"
 
+#define WRITE_NUM	16
+
 enum spi_frequency {
 	SPI_FREQUENCY_20MHZ = 0,
 	SPI_FREQUENCY_33MHZ = 1,
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 2/25 tools/ifdtool: Support writing multiple files (-w) simultaneously

Hi Bin,

Quoted 23 lines · Bin Meng

Currently ifdtool only supports writing one file (-w) at a time. This looks verbose when generating u-boot.rom for x86 targets. This change allows at most 16 files to be written simultaneously.

---
 tools/ifdtool.c | 29 ++++++++++++++++++++++-------
 tools/ifdtool.h |  2 ++
 2 files changed, 24 insertions(+), 7 deletions(-)
tools/ifdtool.c +1 -0
index a4b481f..58640ca 100644
@@ -732,6 +732,7 @@ static void print_usage(const char *name)
               "   -x | --extract:                   extract intel fd modules\n"
               "   -i | --inject <region>:<module>   inject file <module> into region <region>\n"
               "   -w | --write <addr>:<file>        write file to appear at memory address <addr>\n"
+              "                                     multiple files can be written simultaneously\n"
               "   -s | --spifreq <20|33|50>         set the SPI frequency\n"
               "   -e | --em100                      set SPI frequency to 20MHz and disable\n"
               "                                     Dual Output Fast Read Support\n"

tools/ifdtool.c int main(int argc, char *argv[]) · line 787

Quoted 6 lines
tools/ifdtool.c +2 -1
@@ -782,7 +783,9 @@ int main(int argc, char *argv[])
        char *addr_str = NULL;
        int region_type = -1, inputfreq = 0;
        enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ;
-       unsigned int addr = 0;
+       unsigned int addr[WRITE_NUM] = { 0 };
+       char *wr_fname[WRITE_NUM] = { NULL };

Do you need the initialiser?

Quoted 11 lines
tools/ifdtool.c +1 -3
+       unsigned char wr_idx, wr_num = 0;
        int rom_size = -1;
        bool write_it;
        char *filename;
@@ -886,11 +889,17 @@ int main(int argc, char *argv[])
                        break;
                case 'w':
                        mode_write = 1;
-                       if (get_two_words(optarg, &addr_str, &src_fname)) {
-                               print_usage(argv[0]);
-                               exit(EXIT_FAILURE);

tools/ifdtool.c int main(int argc, char *argv[]) · line 901

Quoted 10 lines
tools/ifdtool.c +10 -0
+                       if (wr_num < WRITE_NUM) {
+                               if (get_two_words(optarg, &addr_str,
+                                                 &wr_fname[wr_num])) {
+                                       print_usage(argv[0]);
+                                       exit(EXIT_FAILURE);
+                               }
+                               addr[wr_num] = strtol(optarg, NULL, 0);
+                               wr_num++;
+                       } else {
+                               fprintf(stderr, "The number of files to write simultaneously exceeds the limitation (%d)\n", WRITE_NUM);

80cols.

Quoted 27 lines
tools/ifdtool.c +8 -3
                        }
-                       addr = strtol(optarg, NULL, 0);
                        break;
                case 'x':
                        mode_extract = 1;
@@ -1002,8 +1011,14 @@ int main(int argc, char *argv[])
        if (mode_inject)
                ret = inject_region(image, size, region_type, src_fname);
 
-       if (mode_write)
-               ret = write_data(image, size, addr, src_fname);
+       if (mode_write) {
+               for (wr_idx = 0; wr_idx < wr_num; wr_idx++) {
+                       ret = write_data(image, size,
+                                        addr[wr_idx], wr_fname[wr_idx]);
+                       if (ret)
+                               break;
+               }
+       }
 
        if (mode_spifreq)
                set_spi_frequency(image, size, spifreq);
tools/ifdtool.h +0 -0
index fbec421..72ba1de 100644

tools/ifdtool.h line 17

Quoted 4 lines
tools/ifdtool.h +1 -0
@@ -14,6 +14,8 @@
 
 #define IFDTOOL_VERSION "1.1-U-Boot"
 
+#define WRITE_NUM      16

How about WRITE_MAX?

Quoted 7 lines
tools/ifdtool.h +1 -1
+
 enum spi_frequency {
        SPI_FREQUENCY_20MHZ = 0,
        SPI_FREQUENCY_33MHZ = 1,
--

1.8.2.1

Regards,
Simon

author
#2 lore raw

PATCH 2/25 tools/ifdtool: Support writing multiple files (-w) simultaneously

Hi Simon,

Quoted 26 lines · Simon Glass

Hi Bin,

Quoted 23 lines · Bin Meng

Currently ifdtool only supports writing one file (-w) at a time. This looks verbose when generating u-boot.rom for x86 targets. This change allows at most 16 files to be written simultaneously.

---
 tools/ifdtool.c | 29 ++++++++++++++++++++++-------
 tools/ifdtool.h |  2 ++
 2 files changed, 24 insertions(+), 7 deletions(-)
tools/ifdtool.c +1 -0
index a4b481f..58640ca 100644
@@ -732,6 +732,7 @@ static void print_usage(const char *name)
               "   -x | --extract:                   extract intel fd modules\n"
               "   -i | --inject <region>:<module>   inject file <module> into region <region>\n"
               "   -w | --write <addr>:<file>        write file to appear at memory address <addr>\n"
+              "                                     multiple files can be written simultaneously\n"
               "   -s | --spifreq <20|33|50>         set the SPI frequency\n"
               "   -e | --em100                      set SPI frequency to 20MHz and disable\n"
               "                                     Dual Output Fast Read Support\n"
@@ -782,7 +783,9 @@ int main(int argc, char *argv[])
Quoted 8 lines

tools/ifdtool.c int main(int argc, char *argv[]) · line 787

Quoted 6 lines
tools/ifdtool.c +2 -1
        char *addr_str = NULL;
        int region_type = -1, inputfreq = 0;
        enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ;
-       unsigned int addr = 0;
+       unsigned int addr[WRITE_NUM] = { 0 };
+       char *wr_fname[WRITE_NUM] = { NULL };

Do you need the initialiser?

I don't think so. Will remove in v2.

Quoted 15 lines
Quoted 15 lines
tools/ifdtool.c +5 -3
+       unsigned char wr_idx, wr_num = 0;
        int rom_size = -1;
        bool write_it;
        char *filename;
@@ -886,11 +889,17 @@ int main(int argc, char *argv[])
                        break;
                case 'w':
                        mode_write = 1;
-                       if (get_two_words(optarg, &addr_str, &src_fname)) {
-                               print_usage(argv[0]);
-                               exit(EXIT_FAILURE);
+                       if (wr_num < WRITE_NUM) {
+                               if (get_two_words(optarg, &addr_str,
+                                                 &wr_fname[wr_num])) {
+                                       print_usage(argv[0]);
Quoted 8 lines

tools/ifdtool.c int main(int argc, char *argv[]) · line 901

Quoted 6 lines
tools/ifdtool.c +6 -0
+                                       exit(EXIT_FAILURE);
+                               }
+                               addr[wr_num] = strtol(optarg, NULL, 0);
+                               wr_num++;
+                       } else {
+                               fprintf(stderr, "The number of files to write simultaneously exceeds the limitation (%d)\n", WRITE_NUM);

80cols.

Will fix.

Quoted 28 lines
Quoted 28 lines
tools/ifdtool.c +8 -3
                        }
-                       addr = strtol(optarg, NULL, 0);
                        break;
                case 'x':
                        mode_extract = 1;
@@ -1002,8 +1011,14 @@ int main(int argc, char *argv[])
        if (mode_inject)
                ret = inject_region(image, size, region_type, src_fname);
 
-       if (mode_write)
-               ret = write_data(image, size, addr, src_fname);
+       if (mode_write) {
+               for (wr_idx = 0; wr_idx < wr_num; wr_idx++) {
+                       ret = write_data(image, size,
+                                        addr[wr_idx], wr_fname[wr_idx]);
+                       if (ret)
+                               break;
+               }
+       }
 
        if (mode_spifreq)
                set_spi_frequency(image, size, spifreq);
tools/ifdtool.h +0 -0
index fbec421..72ba1de 100644
@@ -14,6 +14,8 @@
 
Quoted 6 lines

tools/ifdtool.h line 17

Quoted 3 lines
tools/ifdtool.h +1 -0
 #define IFDTOOL_VERSION "1.1-U-Boot"
 
+#define WRITE_NUM      16

How about WRITE_MAX?

Sure.

Regards,
Bin