3 * Copyright (C) 2007-2008 OpenWrt.org
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg at openwrt.org>
6 * This code was based on the information of the ZyXEL's firmware
7 * image format written by Kolja Waschk, can be found at:
8 * http://www.ixo.de/info/zyxel_uclinux
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
20 #include <unistd.h> /* for unlink() */
22 #include <getopt.h> /* for getopt() */
26 #include <endian.h> /* for __BYTE_ORDER */
27 #if defined(__CYGWIN__)
28 # include <byteswap.h>
34 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
35 # define HOST_TO_LE16(x) (x)
36 # define HOST_TO_LE32(x) (x)
37 # define LE16_TO_HOST(x) (x)
38 # define LE32_TO_HOST(x) (x)
39 # define HOST_TO_BE16(x) bswap_16(x)
40 # define HOST_TO_BE32(x) bswap_32(x)
41 # define BE16_TO_HOST(x) bswap_16(x)
42 # define BE32_TO_HOST(x) bswap_32(x)
44 # define HOST_TO_BE16(x) (x)
45 # define HOST_TO_BE32(x) (x)
46 # define BE16_TO_HOST(x) (x)
47 # define BE32_TO_HOST(x) (x)
48 # define HOST_TO_LE16(x) bswap_16(x)
49 # define HOST_TO_LE32(x) bswap_32(x)
50 # define LE16_TO_HOST(x) bswap_16(x)
51 # define LE32_TO_HOST(x) bswap_32(x)
54 #define ALIGN(x,y) (((x)+((y)-1)) & ~((y)-1))
56 #define MAX_NUM_BLOCKS 8
57 #define MAX_ARG_COUNT 32
58 #define MAX_ARG_LEN 1024
59 #define FILE_BUF_LEN (16*1024)
69 uint32_t align; /* alignment of this block */
70 char *file_name; /* name of the file */
71 uint32_t file_size; /* length of the file */
72 char *mmap_name; /* name in the MMAP table */
73 int type; /* block type */
78 #define BLOCK_TYPE_BOOTEXT 0
79 #define BLOCK_TYPE_RAW 1
87 #define MMAP_DATA_SIZE 1024
91 char *name; /* model name */
92 char *desc; /* description */
93 uint16_t vendor; /* vendor id */
94 uint16_t model; /* model id */
95 uint32_t flash_base; /* flash base address */
96 uint32_t flash_size; /* board flash size */
97 uint32_t code_start; /* code start address */
98 uint32_t romio_offs; /* offset of the firmware within the flash */
99 uint32_t bootext_size; /* maximum size of bootext block */
109 struct board_info *board = NULL;
111 struct fw_block blocks[MAX_NUM_BLOCKS];
112 struct fw_block *bootext_block = NULL;
115 #define ADM5120_FLASH_BASE 0xBFC00000
116 #define ADM5120_CODE_START 0x80008000
118 /* TODO: check values for AR7 */
119 #define AR7_FLASH_BASE 0xB0000000
120 #define AR7_CODE_START 0x94008000
122 #define ATHEROS_FLASH_BASE 0xBFC00000
123 #define ATHEROS_CODE_START 0x80e00000
125 #define AR71XX_FLASH_BASE 0xBFC00000
126 #define AR71XX_CODE_START 0x81E00000
128 #define BOARD(n, d, v, m, fb, fs, cs, fo) { \
129 .name = (n), .desc=(d), \
130 .vendor = (v), .model = (m), \
131 .flash_base = (fb), .flash_size = (fs)<<20, \
132 .code_start = (cs), .romio_offs = (fo), \
133 .bootext_size = BOOTEXT_DEF_SIZE \
136 #define ADMBOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \
137 ADM5120_FLASH_BASE, fs, ADM5120_CODE_START, 0x8000)
139 #define ADMBOARD2(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \
140 ADM5120_FLASH_BASE, fs, ADM5120_CODE_START, 0x10000)
142 #define AR7BOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \
143 AR7_FLASH_BASE, fs, AR7_CODE_START, 0x8000)
145 #define ATHEROSBOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \
146 ATHEROS_FLASH_BASE, fs, ATHEROS_CODE_START, 0x30000)
148 #define AR71XXBOARD1(n, d, m, fs) { \
149 .name = (n), .desc=(d), \
150 .vendor = (ZYNOS_VENDOR_ID_ZYXEL), .model = (m), \
151 .flash_base = (AR71XX_FLASH_BASE), .flash_size = (fs)<<20, \
152 .code_start = (AR71XX_CODE_START), .romio_offs = (0x40000), \
153 .bootext_size = 0x30000 \
157 static struct board_info boards[] = {
159 * Infineon/ADMtek ADM5120 based boards
161 ADMBOARD2("ES-2024A", "ZyXEL ES-2024A", ZYNOS_MODEL_ES_2024A, 4),
162 ADMBOARD2("ES-2024PWR", "ZyXEL ES-2024PWR", ZYNOS_MODEL_ES_2024PWR, 4),
163 ADMBOARD2("ES-2108", "ZyXEL ES-2108", ZYNOS_MODEL_ES_2108, 4),
164 ADMBOARD2("ES-2108-F", "ZyXEL ES-2108-F", ZYNOS_MODEL_ES_2108_F, 4),
165 ADMBOARD2("ES-2108-G", "ZyXEL ES-2108-G", ZYNOS_MODEL_ES_2108_G, 4),
166 ADMBOARD2("ES-2108-LC", "ZyXEL ES-2108-LC", ZYNOS_MODEL_ES_2108_LC, 4),
167 ADMBOARD2("ES-2108PWR", "ZyXEL ES-2108PWR", ZYNOS_MODEL_ES_2108PWR, 4),
168 ADMBOARD1("HS-100", "ZyXEL HomeSafe 100", ZYNOS_MODEL_HS_100, 2),
169 ADMBOARD1("HS-100W", "ZyXEL HomeSafe 100W", ZYNOS_MODEL_HS_100W, 2),
170 ADMBOARD1("P-334", "ZyXEL Prestige 334", ZYNOS_MODEL_P_334, 2),
171 ADMBOARD1("P-334U", "ZyXEL Prestige 334U", ZYNOS_MODEL_P_334U, 4),
172 ADMBOARD1("P-334W", "ZyXEL Prestige 334W", ZYNOS_MODEL_P_334W, 2),
173 ADMBOARD1("P-334WH", "ZyXEL Prestige 334WH", ZYNOS_MODEL_P_334WH, 4),
174 ADMBOARD1("P-334WHD", "ZyXEL Prestige 334WHD", ZYNOS_MODEL_P_334WHD, 4),
175 ADMBOARD1("P-334WT", "ZyXEL Prestige 334WT", ZYNOS_MODEL_P_334WT, 4),
176 ADMBOARD1("P-335", "ZyXEL Prestige 335", ZYNOS_MODEL_P_335, 4),
177 ADMBOARD1("P-335Plus", "ZyXEL Prestige 335Plus", ZYNOS_MODEL_P_335PLUS, 4),
178 ADMBOARD1("P-335U", "ZyXEL Prestige 335U", ZYNOS_MODEL_P_335U, 4),
179 ADMBOARD1("P-335WT", "ZyXEL Prestige 335WT", ZYNOS_MODEL_P_335WT, 4),
182 .name = "P-2602HW-D1A",
183 .desc = "ZyXEL P-2602HW-D1A",
184 .vendor = ZYNOS_VENDOR_ID_ZYXEL,
185 .model = ZYNOS_MODEL_P_2602HW_D1A,
186 .flash_base = AR7_FLASH_BASE,
187 .flash_size = 4*1024*1024,
188 .code_start = 0x94008000,
189 .romio_offs = 0x20000,
190 .bootext_size = BOOTEXT_DEF_SIZE,
195 * Texas Instruments AR7 based boards
197 AR7BOARD1("P-660H-61", "ZyXEL P-660H-61", ZYNOS_MODEL_P_660H_61, 2),
198 AR7BOARD1("P-660H-63", "ZyXEL P-660H-63", ZYNOS_MODEL_P_660H_63, 2),
199 AR7BOARD1("P-660H-D1", "ZyXEL P-660H-D1", ZYNOS_MODEL_P_660H_D1, 2),
200 AR7BOARD1("P-660H-D3", "ZyXEL P-660H-D3", ZYNOS_MODEL_P_660H_D3, 2),
201 AR7BOARD1("P-660HW-61", "ZyXEL P-660HW-61", ZYNOS_MODEL_P_660HW_61, 2),
202 AR7BOARD1("P-660HW-63", "ZyXEL P-660HW-63", ZYNOS_MODEL_P_660HW_63, 2),
203 AR7BOARD1("P-660HW-67", "ZyXEL P-660HW-67", ZYNOS_MODEL_P_660HW_67, 2),
204 AR7BOARD1("P-660HW-D1", "ZyXEL P-660HW-D1", ZYNOS_MODEL_P_660HW_D1, 2),
205 AR7BOARD1("P-660HW-D3", "ZyXEL P-660HW-D3", ZYNOS_MODEL_P_660HW_D3, 2),
206 AR7BOARD1("P-660R-61", "ZyXEL P-660R-61", ZYNOS_MODEL_P_660R_61, 2),
207 AR7BOARD1("P-660R-61C", "ZyXEL P-660R-61C", ZYNOS_MODEL_P_660R_61C, 2),
208 AR7BOARD1("P-660R-63", "ZyXEL P-660R-63", ZYNOS_MODEL_P_660R_63, 2),
209 AR7BOARD1("P-660R-63C", "ZyXEL P-660R-63C", ZYNOS_MODEL_P_660R_63C, 2),
210 AR7BOARD1("P-660R-67", "ZyXEL P-660R-67", ZYNOS_MODEL_P_660R_67, 2),
211 AR7BOARD1("P-660R-D1", "ZyXEL P-660R-D1", ZYNOS_MODEL_P_660R_D1, 2),
212 AR7BOARD1("P-660R-D3", "ZyXEL P-660R-D3", ZYNOS_MODEL_P_660R_D3, 2),
216 .desc = "O2 DSL Surf & Phone",
217 .vendor = ZYNOS_VENDOR_ID_O2,
218 .model = ZYNOS_MODEL_O2SURF,
219 .flash_base = AR7_FLASH_BASE,
220 .flash_size = 8*1024*1024,
221 .code_start = 0x94014000,
222 .romio_offs = 0x40000,
223 .bootext_size = BOOTEXT_DEF_SIZE,
229 ATHEROSBOARD1("NBG-318S", "ZyXEL NBG-318S", ZYNOS_MODEL_NBG_318S, 4),
232 * Atheros ar71xx based boards
234 AR71XXBOARD1("NBG-460N", "ZyXEL NBG-460N", ZYNOS_MODEL_NBG_460N, 4),
242 #define ERR(fmt, ...) do { \
244 fprintf(stderr, "[%s] *** error: " fmt "\n", \
245 progname, ## __VA_ARGS__ ); \
248 #define ERRS(fmt, ...) do { \
251 fprintf(stderr, "[%s] *** error: " fmt ", %s\n", \
252 progname, ## __VA_ARGS__, strerror(save)); \
255 #define WARN(fmt, ...) do { \
256 fprintf(stderr, "[%s] *** warning: " fmt "\n", \
257 progname, ## __VA_ARGS__ ); \
260 #define DBG(lev, fmt, ...) do { \
261 if (verblevel < lev) \
263 fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
267 #define ERR_INVALID_IMAGE -2
275 FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
276 struct board_info *board;
278 fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
282 " -B <board> create image for the board specified with <board>.\n"
283 " valid <board> values:\n"
285 for (board = boards; board->name != NULL; board++){
288 board->name, board->desc);
291 " -b <file>[:<align>]\n"
292 " add boot extension block to the image\n"
293 " -r <file>[:<align>]\n"
294 " add raw block to the image\n"
295 " -o <file> write output to the file <file>\n"
296 " -h show this screen\n"
307 str2u32(char *arg, uint32_t *val)
313 t = strtoul(arg, &err, 0);
314 if (errno || (err==arg) || ((err != NULL) && *err)) {
324 str2u16(char *arg, uint16_t *val)
330 t = strtoul(arg, &err, 0);
331 if (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x10000)) {
340 str2u8(char *arg, uint8_t *val)
346 t = strtoul(arg, &err, 0);
347 if (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x100)) {
356 str2sig(char *arg, uint32_t *sig)
358 if (strlen(arg) != 4)
361 *sig = arg[0] | (arg[1] << 8) | (arg[2] << 16) | (arg[3] << 24);
368 parse_arg(char *arg, char *buf, char *argv[])
376 memset(argv, 0, MAX_ARG_COUNT * sizeof(void *));
389 if (argl >= MAX_ARG_LEN) {
390 /* argument is too long */
391 argl = MAX_ARG_LEN-1;
394 memcpy(buf, arg, argl);
397 for (i = 0; i < MAX_ARG_COUNT; i++) {
398 tok = strsep(ap, ":");
403 else if (tok[0] == '\0') {
416 required_arg(char c, char *arg)
418 if (arg == NULL || *arg != '-')
421 ERR("option -%c requires an argument\n", c);
427 is_empty_arg(char *arg)
438 csum_init(struct csum_state *css)
447 csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
453 css->sum += (css->tmp << 8) + p[0];
454 if (css->sum > 0xFFFF) {
463 for ( ; len > 1; len -= 2, p +=2 ) {
464 css->sum += (p[0] << 8) + p[1];
465 if (css->sum > 0xFFFF) {
479 csum_get(struct csum_state *css)
483 csum_update(&pad, 1, css);
488 csum_buf(uint8_t *p, uint32_t len)
490 struct csum_state css;
493 csum_update(p, len, &css);
494 return csum_get(&css);
499 * routines to write data to the output file
502 write_out_data(FILE *outfile, uint8_t *data, size_t len,
503 struct csum_state *css)
507 fwrite(data, len, 1, outfile);
509 ERR("unable to write output file");
514 csum_update(data, len, css);
522 write_out_padding(FILE *outfile, size_t len, uint8_t padc,
523 struct csum_state *css)
526 size_t buflen = sizeof(buf);
528 memset(buf, padc, buflen);
533 if (write_out_data(outfile, buf, buflen, css))
544 write_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,
545 struct csum_state *css)
550 res = write_out_data(outfile, data, len, css);
554 padlen = ALIGN(len,align) - len;
555 res = write_out_padding(outfile, padlen, 0xFF, css);
562 write_out_header(FILE *outfile, struct zyn_rombin_hdr *hdr)
564 struct zyn_rombin_hdr t;
567 if (fseek(outfile, 0, SEEK_SET) != 0) {
568 ERRS("fseek failed on output file");
572 /* setup temporary header fields */
573 memset(&t, 0, sizeof(t));
574 t.addr = HOST_TO_BE32(hdr->addr);
575 memcpy(&t.sig, ROMBIN_SIGNATURE, ROMBIN_SIG_LEN);
577 t.flags = hdr->flags;
578 t.osize = HOST_TO_BE32(hdr->osize);
579 t.csize = HOST_TO_BE32(hdr->csize);
580 t.ocsum = HOST_TO_BE16(hdr->ocsum);
581 t.ccsum = HOST_TO_BE16(hdr->ccsum);
582 t.mmap_addr = HOST_TO_BE32(hdr->mmap_addr);
584 DBG(2, "hdr.addr = 0x%08x", hdr->addr);
585 DBG(2, "hdr.type = 0x%02x", hdr->type);
586 DBG(2, "hdr.osize = 0x%08x", hdr->osize);
587 DBG(2, "hdr.csize = 0x%08x", hdr->csize);
588 DBG(2, "hdr.flags = 0x%02x", hdr->flags);
589 DBG(2, "hdr.ocsum = 0x%04x", hdr->ocsum);
590 DBG(2, "hdr.ccsum = 0x%04x", hdr->ccsum);
591 DBG(2, "hdr.mmap_addr = 0x%08x", hdr->mmap_addr);
593 return write_out_data(outfile, (uint8_t *)&t, sizeof(t), NULL);
598 write_out_mmap(FILE *outfile, struct fw_mmap *mmap, struct csum_state *css)
600 struct zyn_mmt_hdr *mh;
601 uint8_t buf[MMAP_DATA_SIZE];
606 memset(buf, 0, sizeof(buf));
608 mh = (struct zyn_mmt_hdr *)buf;
610 /* TODO: needs to recreate the memory map too? */
613 /* Build user data section */
614 data = buf+sizeof(*mh);
615 data += sprintf(data, "Vendor 1 %d", board->vendor);
617 data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model));
619 /* TODO: make hardware version configurable? */
620 data += sprintf(data, "HwVerRange 2 %d %d", 0, 0);
623 user_size = (uint8_t *)data - buf;
624 mh->user_start= HOST_TO_BE32(mmap->addr+sizeof(*mh));
625 mh->user_end= HOST_TO_BE32(mmap->addr+user_size);
626 mh->csum = HOST_TO_BE16(csum_buf(buf+sizeof(*mh), user_size));
628 res = write_out_data(outfile, buf, sizeof(buf), css);
635 block_stat_file(struct fw_block *block)
640 if (block->file_name == NULL)
643 res = stat(block->file_name, &st);
645 ERRS("stat failed on %s", block->file_name);
649 block->file_size = st.st_size;
655 read_magic(uint16_t *magic)
661 f = fopen(bootext_block->file_name,"r");
663 ERRS("unable to open file: %s", bootext_block->file_name);
668 fread(magic, 2, 1, f);
670 ERRS("unable to read from file: %s", bootext_block->file_name);
684 write_out_file(FILE *outfile, char *name, size_t len, struct csum_state *css)
686 char buf[FILE_BUF_LEN];
687 size_t buflen = sizeof(buf);
691 DBG(2, "writing out file, name=%s, len=%zu",
697 ERRS("unable to open file: %s", name);
705 /* read data from source file */
707 fread(buf, buflen, 1, f);
709 ERRS("unable to read from file: %s",name);
714 res = write_out_data(outfile, buf, buflen, css);
727 write_out_block(FILE *outfile, struct fw_block *block, struct csum_state *css)
734 if (block->file_name == NULL)
737 if (block->file_size == 0)
740 res = write_out_file(outfile, block->file_name,
741 block->file_size, css);
747 write_out_image(FILE *outfile)
749 struct fw_block *block;
751 struct zyn_rombin_hdr hdr;
752 struct csum_state css;
759 /* setup header fields */
760 memset(&hdr, 0, sizeof(hdr));
761 hdr.addr = board->code_start;
762 hdr.type = OBJECT_TYPE_BOOTEXT;
763 hdr.flags = ROMBIN_FLAG_OCSUM;
765 offset = board->romio_offs;
767 res = write_out_header(outfile, &hdr);
771 offset += sizeof(hdr);
774 res = write_out_block(outfile, bootext_block, &css);
778 offset += bootext_block->file_size;
779 if (offset > (board->romio_offs + board->bootext_size)) {
780 ERR("bootext file '%s' is too big", bootext_block->file_name);
784 padlen = ALIGN(offset, MMAP_ALIGN) - offset;
785 res = write_out_padding(outfile, padlen, 0xFF, &css);
791 mmap.addr = board->flash_base + offset;
792 res = write_out_mmap(outfile, &mmap, &css);
796 offset += MMAP_DATA_SIZE;
798 if ((offset - board->romio_offs) < board->bootext_size) {
799 padlen = board->romio_offs + board->bootext_size - offset;
800 res = write_out_padding(outfile, padlen, 0xFF, &css);
805 DBG(2, "bootext end at %08x", offset);
808 for (i = 0; i < num_blocks; i++) {
811 if (block->type == BLOCK_TYPE_BOOTEXT)
814 padlen = ALIGN(offset, block->align) - offset;
815 res = write_out_padding(outfile, padlen, 0xFF, &css);
820 res = write_out_block(outfile, block, &css);
823 offset += block->file_size;
826 padlen = ALIGN(offset, 4) - offset;
827 res = write_out_padding(outfile, padlen, 0xFF, &css);
832 csum = csum_get(&css);
833 hdr.mmap_addr = mmap.addr;
836 res = read_magic(&hdr.ocsum);
839 hdr.ocsum = BE16_TO_HOST(hdr.ocsum);
841 if (csum <= hdr.ocsum)
842 t = hdr.ocsum - csum;
844 t = hdr.ocsum - csum - 1;
846 DBG(2, "ocsum=%04x, csum=%04x, fix=%04x", hdr.ocsum, csum, t);
849 res = write_out_data(outfile, (uint8_t *)&t, 2, NULL);
854 res = write_out_header(outfile, &hdr);
861 find_board(char *name)
863 struct board_info *ret;
864 struct board_info *board;
867 for (board = boards; board->name != NULL; board++){
868 if (strcasecmp(name, board->name) == 0) {
879 parse_opt_board(char ch, char *arg)
882 DBG(1,"parsing board option: -%c %s", ch, arg);
885 ERR("only one board option allowed");
889 if (required_arg(ch, arg))
892 board = find_board(arg);
894 ERR("invalid/unknown board specified: %s", arg);
903 parse_opt_ofname(char ch, char *arg)
906 if (ofname != NULL) {
907 ERR("only one output file allowed");
911 if (required_arg(ch, arg))
921 parse_opt_block(char ch, char *arg)
923 char buf[MAX_ARG_LEN];
924 char *argv[MAX_ARG_COUNT];
927 struct fw_block *block;
930 if ( num_blocks >= MAX_NUM_BLOCKS ) {
931 ERR("too many blocks specified");
935 block = &blocks[num_blocks++];
937 /* setup default field values */
943 ERR("only one boot extension block allowed");
946 block->type = BLOCK_TYPE_BOOTEXT;
947 bootext_block = block;
950 block->type = BLOCK_TYPE_RAW;
954 argc = parse_arg(arg, buf, argv);
958 if (is_empty_arg(p)) {
959 ERR("no file specified in %s", arg);
962 block->file_name = strdup(p);
963 if (block->file_name == NULL) {
964 ERR("not enough memory");
969 if (block->type == BLOCK_TYPE_BOOTEXT)
973 if (!is_empty_arg(p)) {
974 if (str2u32(p, &block->align) != 0) {
975 ERR("invalid block align in %s", arg);
985 calc_block_offsets(int type, uint32_t *offset)
987 struct fw_block *block;
992 DBG(1,"calculating block offsets, starting with %" PRIu32,
996 for (i = 0; i < num_blocks; i++) {
999 if (block->type != type)
1002 next_offs = ALIGN(*offset, block->align);
1003 avail = board->flash_size - next_offs;
1004 if (block->file_size > avail) {
1005 ERR("file %s is too big, offset = %u, size=%u,"
1006 " avail = %u, align = %u", block->file_name,
1007 (unsigned)next_offs,
1008 (unsigned)block->file_size,
1010 (unsigned)block->align);
1015 block->padlen = next_offs - *offset;
1016 *offset += block->file_size;
1023 process_blocks(void)
1025 struct fw_block *block;
1030 /* collecting file stats */
1031 for (i = 0; i < num_blocks; i++) {
1033 res = block_stat_file(block);
1038 offset = board->romio_offs + bootext_block->file_size;
1039 res = calc_block_offsets(BLOCK_TYPE_RAW, &offset);
1046 main(int argc, char *argv[])
1048 int optinvalid = 0; /* flag for invalid option */
1050 int res = EXIT_FAILURE;
1054 progname=basename(argv[0]);
1056 opterr = 0; /* could not print standard getopt error messages */
1060 c = getopt(argc, argv, "b:B:ho:r:v");
1067 optinvalid = parse_opt_block(c,optarg);
1070 optinvalid = parse_opt_board(c,optarg);
1073 optinvalid = parse_opt_ofname(c,optarg);
1079 usage(EXIT_SUCCESS);
1085 if (optinvalid != 0 ) {
1086 ERR("invalid option: -%c", optopt);
1091 if (board == NULL) {
1092 ERR("no board specified");
1096 if (ofname == NULL) {
1097 ERR("no output file specified");
1101 if (optind < argc) {
1102 ERR("invalid option: %s", argv[optind]);
1106 if (process_blocks() != 0) {
1110 outfile = fopen(ofname, "w");
1111 if (outfile == NULL) {
1112 ERRS("could not open \"%s\" for writing", ofname);
1116 if (write_out_image(outfile) != 0)
1119 DBG(1,"Image file %s completed.", ofname);
1126 if (res != EXIT_SUCCESS) {