From d1e91ace22cfa21de0f7a786984b86859e6c5201 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Tue, 11 Jul 2017 18:10:02 +0200 Subject: icemulti: Treat coldboot as global flag --- icemulti/icemulti.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index da90da3..bac69cf 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -123,17 +123,15 @@ void Image::write(std::ostream &ofs, uint32_t &file_offset) class Header { uint32_t image_offs; - bool coldboot_flag; bool empty; public: Header() : empty(true) {} Header(const Image &i) : - image_offs(i.offset()), coldboot_flag(false), empty(false) {} - void set_coldboot_flag() { coldboot_flag = true; } - void write(std::ostream &ofs, uint32_t &file_offset); + image_offs(i.offset()), empty(false) {} + void write(std::ostream &ofs, uint32_t &file_offset, bool coldboot); }; -void Header::write(std::ostream &ofs, uint32_t &file_offset) +void Header::write(std::ostream &ofs, uint32_t &file_offset, bool coldboot) { if (empty) return; @@ -147,7 +145,7 @@ void Header::write(std::ostream &ofs, uint32_t &file_offset) // Boot mode write_byte(ofs, file_offset, 0x92); write_byte(ofs, file_offset, 0x00); - write_byte(ofs, file_offset, (coldboot_flag? 0x10: 0x00)); + write_byte(ofs, file_offset, coldboot ? 0x10 : 0x00); // Boot address write_byte(ofs, file_offset, 0x44); @@ -288,8 +286,6 @@ int main(int argc, char **argv) headers[0] = headers[por_image + 1]; for (int i=image_count; i < NUM_IMAGES; i++) headers[i + 1] = headers[0]; - if (coldboot) - headers[0].set_coldboot_flag(); std::ofstream ofs; std::ostream *osp; @@ -307,7 +303,7 @@ int main(int argc, char **argv) for (int i=0; i Date: Tue, 11 Jul 2017 18:11:57 +0200 Subject: icemulti: Remove unused flag Header::empty --- icemulti/icemulti.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index bac69cf..45e53c1 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -123,19 +123,15 @@ void Image::write(std::ostream &ofs, uint32_t &file_offset) class Header { uint32_t image_offs; - bool empty; public: - Header() : empty(true) {} + Header() {} Header(const Image &i) : - image_offs(i.offset()), empty(false) {} + image_offs(i.offset()) {} void write(std::ostream &ofs, uint32_t &file_offset, bool coldboot); }; void Header::write(std::ostream &ofs, uint32_t &file_offset, bool coldboot) { - if (empty) - return; - // Preamble write_byte(ofs, file_offset, 0x7e); write_byte(ofs, file_offset, 0xaa); -- cgit v1.2.3 From a96d1fffdc371bad3bc81172d8663e0a5a902945 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Tue, 11 Jul 2017 18:17:56 +0200 Subject: icemulti: Store image reference in header --- icemulti/icemulti.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 45e53c1..143d0d9 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -122,11 +122,8 @@ void Image::write(std::ostream &ofs, uint32_t &file_offset) } class Header { - uint32_t image_offs; public: - Header() {} - Header(const Image &i) : - image_offs(i.offset()) {} + Image const *image; void write(std::ostream &ofs, uint32_t &file_offset, bool coldboot); }; @@ -146,9 +143,9 @@ void Header::write(std::ostream &ofs, uint32_t &file_offset, bool coldboot) // Boot address write_byte(ofs, file_offset, 0x44); write_byte(ofs, file_offset, 0x03); - write_byte(ofs, file_offset, (image_offs >> 16) & 0xff); - write_byte(ofs, file_offset, (image_offs >> 8) & 0xff); - write_byte(ofs, file_offset, image_offs & 0xff); + write_byte(ofs, file_offset, (image->offset() >> 16) & 0xff); + write_byte(ofs, file_offset, (image->offset() >> 8) & 0xff); + write_byte(ofs, file_offset, image->offset() & 0xff); // Bank offset write_byte(ofs, file_offset, 0x82); @@ -278,10 +275,10 @@ int main(int argc, char **argv) // Populate headers for (int i=0; i Date: Tue, 11 Jul 2017 18:20:18 +0200 Subject: icemulti: Make function `write_header' global --- icemulti/icemulti.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 143d0d9..d73ef0c 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -124,10 +124,10 @@ void Image::write(std::ostream &ofs, uint32_t &file_offset) class Header { public: Image const *image; - void write(std::ostream &ofs, uint32_t &file_offset, bool coldboot); }; -void Header::write(std::ostream &ofs, uint32_t &file_offset, bool coldboot) +static void write_header(std::ostream &ofs, uint32_t &file_offset, + Image const *image, bool coldboot) { // Preamble write_byte(ofs, file_offset, 0x7e); @@ -296,7 +296,7 @@ int main(int argc, char **argv) for (int i=0; i Date: Tue, 11 Jul 2017 18:22:49 +0200 Subject: icemulti: Remove class `Header' --- icemulti/icemulti.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index d73ef0c..d9c6dae 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -121,11 +121,6 @@ void Image::write(std::ostream &ofs, uint32_t &file_offset) write_file(ofs, file_offset, ifs, filename); } -class Header { -public: - Image const *image; -}; - static void write_header(std::ostream &ofs, uint32_t &file_offset, Image const *image, bool coldboot) { @@ -193,7 +188,7 @@ int main(int argc, char **argv) int image_count = 0; int align_bits = 0; bool align_first = false; - Header headers[NUM_HEADERS]; + Image *header_images[NUM_HEADERS]; std::unique_ptr images[NUM_IMAGES]; const char *outfile_name = NULL; @@ -275,10 +270,10 @@ int main(int argc, char **argv) // Populate headers for (int i=0; i Date: Tue, 11 Jul 2017 18:30:56 +0200 Subject: icemulti: Populate headers early --- icemulti/icemulti.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index d9c6dae..21ddc04 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -248,7 +248,9 @@ int main(int argc, char **argv) while (optind != argc) { if (image_count >= NUM_IMAGES) error("Too many images supplied\n"); - images[image_count++].reset(new Image(argv[optind++])); + images[image_count].reset(new Image(argv[optind++])); + header_images[image_count + 1] = &*images[image_count]; + image_count++; } if (coldboot && por_image != 0) @@ -269,8 +271,6 @@ int main(int argc, char **argv) } // Populate headers - for (int i=0; i Date: Tue, 11 Jul 2017 18:35:00 +0200 Subject: icemulti: Differentiate between header and image count --- icemulti/icemulti.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 21ddc04..ff55e99 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -185,6 +185,7 @@ int main(int argc, char **argv) char *endptr = NULL; bool coldboot = false; int por_image = 0; + int header_count = 0; int image_count = 0; int align_bits = 0; bool align_first = false; @@ -246,17 +247,18 @@ int main(int argc, char **argv) } while (optind != argc) { - if (image_count >= NUM_IMAGES) + if (header_count >= NUM_IMAGES) error("Too many images supplied\n"); images[image_count].reset(new Image(argv[optind++])); - header_images[image_count + 1] = &*images[image_count]; + header_images[header_count + 1] = &*images[image_count]; + header_count++; image_count++; } if (coldboot && por_image != 0) error("Can't select power on reset boot image in cold boot mode\n"); - if (por_image >= image_count) + if (por_image >= header_count) error("Specified non-existing image for power on reset\n"); // Place images @@ -272,7 +274,7 @@ int main(int argc, char **argv) // Populate headers header_images[0] = header_images[por_image + 1]; - for (int i=image_count; i < NUM_IMAGES; i++) + for (int i=header_count; i < NUM_IMAGES; i++) header_images[i + 1] = header_images[0]; std::ofstream ofs; -- cgit v1.2.3 From a622580c13a7cba2476c40ad87bf89ecca8cbed0 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Tue, 11 Jul 2017 18:39:11 +0200 Subject: icemulti: Remove special first element from header lists --- icemulti/icemulti.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index ff55e99..bcf086a 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -189,7 +189,7 @@ int main(int argc, char **argv) int image_count = 0; int align_bits = 0; bool align_first = false; - Image *header_images[NUM_HEADERS]; + Image *header_images[NUM_IMAGES]; std::unique_ptr images[NUM_IMAGES]; const char *outfile_name = NULL; @@ -250,7 +250,7 @@ int main(int argc, char **argv) if (header_count >= NUM_IMAGES) error("Too many images supplied\n"); images[image_count].reset(new Image(argv[optind++])); - header_images[header_count + 1] = &*images[image_count]; + header_images[header_count] = &*images[image_count]; header_count++; image_count++; } @@ -273,9 +273,8 @@ int main(int argc, char **argv) } // Populate headers - header_images[0] = header_images[por_image + 1]; for (int i=header_count; i < NUM_IMAGES; i++) - header_images[i + 1] = header_images[0]; + header_images[i] = header_images[por_image]; std::ofstream ofs; std::ostream *osp; @@ -293,7 +292,10 @@ int main(int argc, char **argv) for (int i=0; i Date: Tue, 11 Jul 2017 18:40:15 +0200 Subject: icemulti: Remove constant `NUM_HEADERS' --- icemulti/icemulti.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index bcf086a..ae7d642 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -33,7 +33,6 @@ static char *program_short_name; int log_level = 0; static const int NUM_IMAGES = 4; -static const int NUM_HEADERS = NUM_IMAGES + 1; static const int HEADER_SIZE = 32; static void align_offset(uint32_t &offset, int bits) @@ -262,7 +261,7 @@ int main(int argc, char **argv) error("Specified non-existing image for power on reset\n"); // Place images - uint32_t offs = NUM_HEADERS * HEADER_SIZE; + uint32_t offs = (NUM_IMAGES + 1) * HEADER_SIZE; if (align_first) align_offset(offs, align_bits); for (int i=0; i Date: Mon, 14 Aug 2017 13:56:18 +0200 Subject: icemulti: Treat offset printing like ordinary flag --- icemulti/icemulti.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index ae7d642..03f1a68 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -25,13 +25,10 @@ #include #define log(...) fprintf(stderr, __VA_ARGS__); -#define info(...) do { if (log_level > 0) fprintf(stderr, __VA_ARGS__); } while (0) #define error(...) do { fprintf(stderr, "%s: ", program_short_name); fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) static char *program_short_name; -int log_level = 0; - static const int NUM_IMAGES = 4; static const int HEADER_SIZE = 32; @@ -191,6 +188,7 @@ int main(int argc, char **argv) Image *header_images[NUM_IMAGES]; std::unique_ptr images[NUM_IMAGES]; const char *outfile_name = NULL; + bool print_offsets = false; static struct option long_options[] = { {NULL, 0, NULL, 0} @@ -234,7 +232,7 @@ int main(int argc, char **argv) outfile_name = optarg; break; case 'v': - log_level++; + print_offsets = true; break; default: usage(); @@ -268,7 +266,8 @@ int main(int argc, char **argv) images[i]->place(offs); offs += images[i]->size(); align_offset(offs, align_bits); - info("Place image %d at %06x .. %06x.\n", i, int(images[i]->offset()), int(offs)); + if (print_offsets) + fprintf(stderr, "Place image %d at %06x .. %06x.\n", i, int(images[i]->offset()), int(offs)); } // Populate headers @@ -302,6 +301,5 @@ int main(int argc, char **argv) images[i]->write(*osp, file_offset); } - info("Done.\n"); return EXIT_SUCCESS; } -- cgit v1.2.3 From dd9ce3fcb5571d70e4ac7e17db58a797835572d1 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Mon, 14 Aug 2017 13:59:55 +0200 Subject: icemulti: Print image filenames along with offsets --- icemulti/icemulti.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 03f1a68..7bfe25e 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -79,11 +79,12 @@ static void pad_to(std::ostream &ofs, uint32_t &file_offset, uint32_t target) } class Image { - const char *filename; std::ifstream ifs; uint32_t offs; public: + const char *const filename; + Image(const char *filename); size_t size(); void write(std::ostream &ofs, uint32_t &file_offset); @@ -91,7 +92,7 @@ public: uint32_t offset() const { return offs; } }; -Image::Image(const char *filename) : filename(filename), ifs(filename, std::ifstream::binary) +Image::Image(const char *filename) : ifs(filename, std::ifstream::binary), filename(filename) { if (ifs.fail()) error("can't open input image `%s': %s\n", filename, strerror(errno)); @@ -267,7 +268,7 @@ int main(int argc, char **argv) offs += images[i]->size(); align_offset(offs, align_bits); if (print_offsets) - fprintf(stderr, "Place image %d at %06x .. %06x.\n", i, int(images[i]->offset()), int(offs)); + fprintf(stderr, "Place image %d at %06x .. %06x (`%s')\n", i, int(images[i]->offset()), int(offs), images[i]->filename); } // Populate headers -- cgit v1.2.3 From d1bfc4543e780a50694037bfb2a38fdca9178eae Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Tue, 11 Jul 2017 19:01:11 +0200 Subject: icemulti: Re-use images --- icemulti/icemulti.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 7bfe25e..65ae6b6 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -247,10 +247,18 @@ int main(int argc, char **argv) while (optind != argc) { if (header_count >= NUM_IMAGES) error("Too many images supplied\n"); - images[image_count].reset(new Image(argv[optind++])); + for (int i = 0; i < image_count; i++) + if (strcmp(argv[optind], images[i]->filename) == 0) { + header_images[header_count] = &*images[i]; + goto image_found; + } + images[image_count].reset(new Image(argv[optind])); header_images[header_count] = &*images[image_count]; - header_count++; image_count++; + + image_found: + header_count++; + optind++; } if (coldboot && por_image != 0) -- cgit v1.2.3