2 * Copyright (C) 2006,2007 Gabor Juhos
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
15 #include <unistd.h> /* for unlink() */
17 #include <getopt.h> /* for getopt() */
21 #include <endian.h> /* for __BYTE_ORDER */
23 #if defined(__CYGWIN__)
24 # include <byteswap.h>
27 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
28 # define HOST_TO_LE16(x) (x)
29 # define HOST_TO_LE32(x) (x)
31 # define HOST_TO_LE16(x) bswap_16(x)
32 # define HOST_TO_LE32(x) bswap_32(x)
37 #define MAX_FW_BLOCKS 32
38 #define MAX_ARG_COUNT 32
39 #define MAX_ARG_LEN 1024
40 #define FILE_BUF_LEN (16*1024)
44 uint32_t blocklen
; /* length of the block */
47 char *name
; /* name of the file */
48 uint32_t size
; /* length of the file */
49 uint32_t crc
; /* crc value of the file */
52 #define BLOCK_FLAG_HAVEHDR 0x0001
55 char *model
; /* model number*/
56 char *name
; /* model name*/
57 char *desc
; /* description */
58 uint16_t vid
; /* vendor id */
59 uint16_t did
; /* device id */
60 uint16_t svid
; /* sub vendor id */
61 uint16_t sdid
; /* sub device id */
62 uint32_t flash_size
; /* size of flash */
65 #define BOARD(_vid, _did, _svid, _sdid, _flash, _mod, _name, _desc) { \
66 .model = _mod, .name = _name, .desc = _desc, \
67 .vid = _vid, .did = _did, .svid = _svid, .sdid = _sdid, \
68 .flash_size = (_flash << 20) }
70 #define CPX_BOARD(_did, _flash, _mod, _name, _desc) \
71 BOARD(VENID_COMPEX, _did, VENID_COMPEX, _did, _flash, _mod, _name, _desc)
73 #define ALIGN(x,y) ((x)+((y)-1)) & ~((y)-1)
78 uint32_t flash_size
= 0;
79 int fw_num_partitions
= 0;
80 int fw_num_blocks
= 0;
83 struct mylo_fw_header fw_header
;
84 struct mylo_partition fw_partitions
[MYLO_MAX_PARTITIONS
];
85 struct fw_block fw_blocks
[MAX_FW_BLOCKS
];
87 struct cpx_board boards
[] = {
88 CPX_BOARD(DEVID_COMPEX_NP18A
, 4,
89 "NP18A", "Compex NetPassage 18A",
90 "Dualband Wireless A+G Internet Gateway"),
91 CPX_BOARD(DEVID_COMPEX_NP26G8M
, 2,
92 "NP26G8M", "Compex NetPassage 26G (8M)",
93 "Wireless-G Broadband Multimedia Gateway"),
94 CPX_BOARD(DEVID_COMPEX_NP26G16M
, 4,
95 "NP26G16M", "Compex NetPassage 26G (16M)",
96 "Wireless-G Broadband Multimedia Gateway"),
97 CPX_BOARD(DEVID_COMPEX_NP27G
, 4,
98 "NP27G", "Compex NetPassage 27G",
99 "Wireless-G 54Mbps eXtended Range Router"),
100 CPX_BOARD(DEVID_COMPEX_NP28G
, 4,
101 "NP28G", "Compex NetPassage 28G",
102 "Wireless 108Mbps Super-G XR Multimedia Router with 4 USB Ports"),
103 CPX_BOARD(DEVID_COMPEX_NP28GHS
, 4,
104 "NP28GHS", "Compex NetPassage 28G (HotSpot)",
106 CPX_BOARD(DEVID_COMPEX_WP18
, 4,
107 "WP18", "Compex NetPassage WP18",
108 "Wireless-G 54Mbps A+G Dualband Access Point"),
109 CPX_BOARD(DEVID_COMPEX_WP54G
, 4,
110 "WP54G", "Compex WP54G",
111 "Wireless-G 54Mbps XR Access Point"),
112 CPX_BOARD(DEVID_COMPEX_WP54Gv1C
, 2,
113 "WP54Gv1C", "Compex WP54G rev.1C",
114 "Wireless-G 54Mbps XR Access Point"),
115 CPX_BOARD(DEVID_COMPEX_WP54AG
, 4,
116 "WP54AG", "Compex WP54AG",
117 "Wireless-AG 54Mbps XR Access Point"),
118 CPX_BOARD(DEVID_COMPEX_WPP54G
, 4,
119 "WPP54G", "Compex WPP54G",
120 "Outdoor Access Point"),
121 CPX_BOARD(DEVID_COMPEX_WPP54AG
, 4,
122 "WPP54AG", "Compex WPP54AG",
123 "Outdoor Access Point"),
128 errmsgv(int syserr
, const char *fmt
, va_list arg_ptr
)
133 fprintf(stderr
, "[%s] Error: ", progname
);
134 vfprintf(stderr
, fmt
, arg_ptr
);
136 fprintf(stderr
, ": %s", strerror(save
));
138 fprintf(stderr
, "\n");
142 errmsg(int syserr
, const char *fmt
, ...)
145 va_start(arg_ptr
, fmt
);
146 errmsgv(syserr
, fmt
, arg_ptr
);
151 dbgmsg(int level
, const char *fmt
, ...)
154 if (verblevel
>= level
) {
156 va_start(arg_ptr
, fmt
);
157 vfprintf(stderr
, fmt
, arg_ptr
);
158 fprintf(stderr
, "\n");
167 FILE *stream
= (status
!= EXIT_SUCCESS
) ? stderr
: stdout
;
168 struct cpx_board
*board
;
170 fprintf(stream
, "Usage: %s [OPTION...] <file>\n", progname
);
173 " <file> write output to the <file>\n"
176 " -B <board> create firmware for the board specified with <board>.\n"
177 " This option set vendor id, device id, subvendor id,\n"
178 " subdevice id, and flash size options to the right value.\n"
179 " valid <board> values:\n");
180 for (board
= boards
; board
->model
!= NULL
; board
++){
183 board
->model
, board
->name
);
186 " -i <vid>:<did>[:<svid>[:<sdid>]]\n"
187 " create firmware for board with vendor id <vid>, device\n"
188 " id <did>, subvendor id <svid> and subdevice id <sdid>.\n"
189 " -r <rev> set board revision to <rev>.\n"
190 " -s <size> set flash size to <size>\n"
191 " -b <addr>:<len>[:[<flags>]:<file>]\n"
192 " define block at <addr> with length of <len>.\n"
193 " valid <flag> values:\n"
194 " h : add crc header before the file data.\n"
195 " -p <addr>:<len>[:<flags>[:<param>[:<file>]]]\n"
196 " add partition at <addr>, with size of <len> to the\n"
197 " partition table, set partition flags to <flags> and\n"
198 " partition parameter to <param>. If the <file> is specified\n"
199 " content of the file is also added to the firmware image.\n"
200 " valid <flag> values:\n"
201 " a: this is the active partition. The bootloader loads\n"
202 " the firmware from this partition.\n"
203 " h: the partition data have a header.\n"
204 " p: the bootloader loads data from this partition to\n"
205 " the RAM before decompress it.\n"
206 " -h show this screen\n"
213 * Code to compute the CRC-32 table. Borrowed from
214 * gzip-1.0.3/makecrc.c.
217 static uint32_t crc_32_tab
[256];
222 /* Not copyrighted 1990 Mark Adler */
224 uint32_t c
; /* crc shift register */
225 uint32_t e
; /* polynomial exclusive-or pattern */
226 int i
; /* counter for all possible eight bit values */
227 int k
; /* byte being shifted into crc apparatus */
229 /* terms of polynomial defining this crc (except x^32): */
230 static const int p
[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
232 /* Make exclusive-or pattern from polynomial */
234 for (i
= 0; i
< sizeof(p
)/sizeof(int); i
++)
235 e
|= 1L << (31 - p
[i
]);
239 for (i
= 1; i
< 256; i
++) {
241 for (k
= i
| 256; k
!= 1; k
>>= 1) {
242 c
= c
& 1 ? (c
>> 1) ^ e
: c
>> 1;
252 update_crc(uint8_t *p
, uint32_t len
, uint32_t *crc
)
256 t
= *crc
^ 0xFFFFFFFFUL
;
258 t
= crc_32_tab
[(t
^ *p
++) & 0xff] ^ (t
>> 8);
260 *crc
= t
^ 0xFFFFFFFFUL
;
265 get_crc(uint8_t *p
, uint32_t len
)
270 update_crc(p
,len
, &crc
);
276 str2u32(char *arg
, uint32_t *val
)
282 t
= strtoul(arg
, &err
, 0);
283 if (errno
|| (err
==arg
) || ((err
!= NULL
) && *err
)) {
293 str2u16(char *arg
, uint16_t *val
)
299 t
= strtoul(arg
, &err
, 0);
300 if (errno
|| (err
==arg
) || ((err
!= NULL
) && *err
) || (t
>= 0x10000)) {
310 find_board(char *model
){
311 struct cpx_board
*board
;
312 struct cpx_board
*tmp
;
315 for (tmp
= boards
; tmp
->model
!= NULL
; tmp
++){
316 if (strcmp(model
, tmp
->model
) == 0) {
327 get_file_crc(struct fw_block
*ff
)
330 uint8_t buf
[FILE_BUF_LEN
];
331 uint32_t readlen
= sizeof(buf
);
335 if ((ff
->flags
& BLOCK_FLAG_HAVEHDR
) == 0) {
341 f
= fopen(ff
->name
,"r");
343 errmsg(1,"unable to open file %s", ff
->name
);
354 fread(buf
, readlen
, 1, f
);
356 errmsg(1,"unable to read from file %s", ff
->name
);
360 update_crc(buf
, readlen
, &ff
->crc
);
380 for (i
= 0; i
< fw_num_blocks
; i
++) {
382 if ((b
->addr
+ b
->blocklen
) > flash_size
) {
383 errmsg(0, "block at 0x%08X is too big", b
->addr
);
389 if (stat(b
->name
, &st
) < 0) {
390 errmsg(0, "stat failed on %s",b
->name
);
393 if (b
->blocklen
== 0) {
394 b
->blocklen
= flash_size
- b
->addr
;
396 if (st
.st_size
> b
->blocklen
) {
397 errmsg(0,"file %s is too big",b
->name
);
401 b
->size
= st
.st_size
;
409 process_partitions(void)
411 struct mylo_partition
*part
;
414 for (i
= 0; i
< fw_num_partitions
; i
++) {
415 part
= &fw_partitions
[i
];
417 if (part
->addr
> flash_size
) {
418 errmsg(0, "invalid partition at 0x%08X", part
->addr
);
422 if ((part
->addr
+ part
->size
) > flash_size
) {
423 errmsg(0, "partition at 0x%08X is too big", part
->addr
);
433 * routines to write data to the output file
436 write_out_data(FILE *outfile
, uint8_t *data
, size_t len
, uint32_t *crc
)
440 fwrite(data
, len
, 1, outfile
);
442 errmsg(1,"unable to write output file");
447 update_crc(data
, len
, crc
);
455 write_out_desc(FILE *outfile
, struct mylo_fw_blockdesc
*desc
, uint32_t *crc
)
457 return write_out_data(outfile
, (uint8_t *)desc
,
463 write_out_padding(FILE *outfile
, size_t len
, uint8_t padc
, uint32_t *crc
)
468 memset(buff
, padc
, buflen
);
470 buflen
= sizeof(buff
);
475 if (write_out_data(outfile
, buff
, buflen
, crc
))
486 write_out_file(FILE *outfile
, struct fw_block
*block
, uint32_t *crc
)
488 char buff
[FILE_BUF_LEN
];
489 size_t buflen
= sizeof(buff
);
495 if (block
->name
== NULL
) {
499 if ((block
->flags
& BLOCK_FLAG_HAVEHDR
) != 0) {
500 struct mylo_partition_header ph
;
502 if (get_file_crc(block
) != 0)
505 ph
.crc
= HOST_TO_LE32(block
->crc
);
506 ph
.len
= HOST_TO_LE32(block
->size
);
508 if (write_out_data(outfile
, (uint8_t *)&ph
, sizeof(ph
), crc
) != 0)
512 f
= fopen(block
->name
,"r");
514 errmsg(1,"unable to open file: %s", block
->name
);
523 /* read data from source file */
525 fread(buff
, buflen
, 1, f
);
527 errmsg(1,"unable to read from file: %s",block
->name
);
531 if (write_out_data(outfile
, buff
, buflen
, crc
) != 0)
539 /* align next block on a 4 byte boundary */
540 len
= ALIGN(len
,4) - block
->size
;
541 if (write_out_padding(outfile
, len
, 0xFF, crc
))
544 dbgmsg(1,"file %s written out", block
->name
);
550 write_out_header(FILE *outfile
, uint32_t *crc
)
552 struct mylo_fw_header hdr
;
554 memset(&hdr
, 0, sizeof(hdr
));
556 hdr
.magic
= HOST_TO_LE32(MYLO_MAGIC_FIRMWARE
);
557 hdr
.crc
= HOST_TO_LE32(fw_header
.crc
);
558 hdr
.vid
= HOST_TO_LE16(fw_header
.vid
);
559 hdr
.did
= HOST_TO_LE16(fw_header
.did
);
560 hdr
.svid
= HOST_TO_LE16(fw_header
.svid
);
561 hdr
.sdid
= HOST_TO_LE16(fw_header
.sdid
);
562 hdr
.rev
= HOST_TO_LE32(fw_header
.rev
);
563 hdr
.fwhi
= HOST_TO_LE32(fw_header
.fwhi
);
564 hdr
.fwlo
= HOST_TO_LE32(fw_header
.fwlo
);
565 hdr
.flags
= HOST_TO_LE32(fw_header
.flags
);
567 if (fseek(outfile
, 0, SEEK_SET
) != 0) {
568 errmsg(1,"fseek failed on output file");
572 return write_out_data(outfile
, (uint8_t *)&hdr
, sizeof(hdr
), crc
);
577 write_out_partitions(FILE *outfile
, uint32_t *crc
)
579 struct mylo_partition_table p
;
580 struct mylo_partition
*p1
, *p2
;
583 if (fw_num_partitions
== 0)
586 memset(&p
, 0, sizeof(p
));
588 p
.magic
= HOST_TO_LE32(MYLO_MAGIC_PARTITIONS
);
589 for (i
= 0; i
< fw_num_partitions
; i
++) {
590 p1
= &p
.partitions
[i
];
591 p2
= &fw_partitions
[i
];
592 p1
->flags
= HOST_TO_LE16(p2
->flags
);
593 p1
->type
= HOST_TO_LE16(PARTITION_TYPE_USED
);
594 p1
->addr
= HOST_TO_LE32(p2
->addr
);
595 p1
->size
= HOST_TO_LE32(p2
->size
);
596 p1
->param
= HOST_TO_LE32(p2
->param
);
599 return write_out_data(outfile
, (uint8_t *)&p
, sizeof(p
), crc
);
604 write_out_blocks(FILE *outfile
, uint32_t *crc
)
606 struct mylo_fw_blockdesc desc
;
612 * if at least one partition specified, write out block descriptor
613 * for the partition table
615 if (fw_num_partitions
> 0) {
617 desc
.type
= HOST_TO_LE32(FW_DESC_TYPE_USED
);
618 desc
.addr
= HOST_TO_LE32(0x10000);
619 desc
.dlen
= HOST_TO_LE32(sizeof(struct mylo_partition_table
));
620 desc
.blen
= HOST_TO_LE32(0x10000);
622 if (write_out_desc(outfile
, &desc
, crc
) != 0)
627 * write out block descriptors for each files
629 for (i
= 0; i
< fw_num_blocks
; i
++) {
632 /* detect block size */
634 if ((b
->flags
& BLOCK_FLAG_HAVEHDR
) != 0) {
635 dlen
+= sizeof(struct mylo_partition_header
);
638 /* round up to 4 bytes */
639 dlen
= ALIGN(dlen
, 4);
641 /* setup the descriptor */
642 desc
.type
= HOST_TO_LE32(FW_DESC_TYPE_USED
);
643 desc
.addr
= HOST_TO_LE32(b
->addr
);
644 desc
.dlen
= HOST_TO_LE32(dlen
);
645 desc
.blen
= HOST_TO_LE32(b
->blocklen
);
647 if (write_out_desc(outfile
, &desc
, crc
) != 0)
652 * write out the null block descriptor
654 memset(&desc
, 0, sizeof(desc
));
655 if (write_out_desc(outfile
, &desc
, crc
) != 0)
658 if (write_out_partitions(outfile
, crc
) != 0)
662 * write out data for each blocks
664 for (i
= 0; i
< fw_num_blocks
; i
++) {
666 if (write_out_file(outfile
, b
, crc
) != 0)
678 parse_arg(char *arg
, char *buf
, char *argv
[])
687 /* invalid argument string */
697 if (argl
>= MAX_ARG_LEN
) {
698 /* argument is too long */
699 argl
= MAX_ARG_LEN
-1;
702 memset(argv
, 0, MAX_ARG_COUNT
* sizeof(void *));
703 memcpy(buf
, arg
, argl
);
706 for (i
= 0; i
< MAX_ARG_COUNT
; i
++) {
707 tok
= strsep(ap
, ":");
712 else if (tok
[0] == '\0') {
725 required_arg(char c
, char *arg
)
727 if ((optarg
!= NULL
) && (*arg
== '-')){
728 errmsg(0,"option %c requires an argument\n", c
);
737 is_empty_arg(char *arg
)
748 parse_opt_flags(char ch
, char *arg
)
750 if (required_arg(ch
, arg
)) {
754 if (str2u32(arg
, &fw_header
.flags
) != 0) {
755 errmsg(0,"invalid firmware flags: %s", arg
);
759 dbgmsg(1, "firmware flags set to %X bytes", fw_header
.flags
);
769 parse_opt_size(char ch
, char *arg
)
771 if (required_arg(ch
, arg
)) {
775 if (str2u32(arg
, &flash_size
) != 0) {
776 errmsg(0,"invalid flash size: %s", arg
);
780 dbgmsg(1, "flash size set to %d bytes", flash_size
);
790 parse_opt_id(char ch
, char *arg
)
792 char buf
[MAX_ARG_LEN
];
793 char *argv
[MAX_ARG_COUNT
];
797 if (required_arg(ch
, arg
)) {
801 argc
= parse_arg(arg
, buf
, argv
);
803 /* processing vendor ID*/
805 if (is_empty_arg(p
)) {
806 errmsg(0,"vendor id is missing from -%c %s",ch
, arg
);
808 } else if (str2u16(p
, &fw_header
.vid
) != 0) {
809 errmsg(0,"invalid vendor id: %s", p
);
813 dbgmsg(1, "vendor id is set to 0x%04X", fw_header
.vid
);
815 /* processing device ID*/
817 if (is_empty_arg(p
)) {
818 errmsg(0,"device id is missing from -%c %s",ch
, arg
);
820 } else if (str2u16(p
, &fw_header
.did
) != 0) {
821 errmsg(0,"invalid device id: %s", p
);
825 dbgmsg(1, "device id is set to 0x%04X", fw_header
.did
);
827 /* processing sub vendor ID*/
829 if (is_empty_arg(p
)) {
830 fw_header
.svid
= fw_header
.vid
;
831 } else if (str2u16(p
, &fw_header
.svid
) != 0) {
832 errmsg(0,"invalid sub vendor id: %s", p
);
836 dbgmsg(1, "sub vendor id is set to 0x%04X", fw_header
.svid
);
838 /* processing device ID*/
840 if (is_empty_arg(p
)) {
841 fw_header
.sdid
= fw_header
.did
;
842 } else if (str2u16(p
, &fw_header
.sdid
) != 0) {
843 errmsg(0,"invalid sub device id: %s", p
);
847 dbgmsg(1, "sub device id is set to 0x%04X", fw_header
.sdid
);
849 /* processing revision */
851 if (is_empty_arg(p
)) {
853 } else if (str2u32(arg
, &fw_header
.rev
) != 0) {
854 errmsg(0,"invalid revision number: %s", p
);
858 dbgmsg(1, "board revision is set to 0x%08X", fw_header
.rev
);
868 parse_opt_block(char ch
, char *arg
)
870 char buf
[MAX_ARG_LEN
];
871 char *argv
[MAX_ARG_COUNT
];
876 if (required_arg(ch
, arg
)) {
880 if (fw_num_blocks
>= MAX_FW_BLOCKS
) {
881 errmsg(0,"too many blocks specified");
885 argc
= parse_arg(arg
, buf
, argv
);
886 dbgmsg(1,"processing block option %s, count %d", arg
, argc
);
888 b
= &fw_blocks
[fw_num_blocks
++];
890 /* processing block address */
892 if (is_empty_arg(p
)) {
893 errmsg(0,"no block address specified in %s", arg
);
895 } else if (str2u32(p
, &b
->addr
) != 0) {
896 errmsg(0,"invalid block address: %s", p
);
900 /* processing block length */
902 if (is_empty_arg(p
)) {
903 errmsg(0,"no block length specified in %s", arg
);
905 } else if (str2u32(p
, &b
->blocklen
) != 0) {
906 errmsg(0,"invalid block length: %s", p
);
911 dbgmsg(1,"empty block %s", arg
);
915 /* processing flags */
917 if (is_empty_arg(p
) == 0) {
918 for ( ; *p
!= '\0'; p
++) {
921 b
->flags
|= BLOCK_FLAG_HAVEHDR
;
924 errmsg(0, "invalid block flag \"%c\"", *p
);
930 /* processing file name */
932 if (is_empty_arg(p
)) {
933 errmsg(0,"file name missing in %s", arg
);
938 if (b
->name
== NULL
) {
939 errmsg(0,"not enough memory");
953 parse_opt_partition(char ch
, char *arg
)
955 char buf
[MAX_ARG_LEN
];
956 char *argv
[MAX_ARG_COUNT
];
960 struct mylo_partition
*part
;
962 if (required_arg(ch
, arg
)) {
966 if (fw_num_partitions
>= MYLO_MAX_PARTITIONS
) {
967 errmsg(0, "too many partitions specified");
971 part
= &fw_partitions
[fw_num_partitions
++];
973 argc
= parse_arg(arg
, buf
, argv
);
975 /* processing partition address */
977 if (is_empty_arg(p
)) {
978 errmsg(0,"partition address missing in -%c %s",ch
, arg
);
980 } else if (str2u32(p
, &part
->addr
) != 0) {
981 errmsg(0,"invalid partition address: %s", p
);
985 /* processing partition size */
987 if (is_empty_arg(p
)) {
988 errmsg(0,"partition size missing in -%c %s",ch
, arg
);
990 } else if (str2u32(p
, &part
->size
) != 0) {
991 errmsg(0,"invalid partition size: %s", p
);
995 /* processing partition flags */
997 if (is_empty_arg(p
) == 0) {
998 for ( ; *p
!= '\0'; p
++) {
1001 part
->flags
|= PARTITION_FLAG_ACTIVE
;
1004 part
->flags
|= PARTITION_FLAG_PRELOAD
;
1007 part
->flags
|= PARTITION_FLAG_HAVEHDR
;
1010 errmsg(0, "invalid partition flag \"%c\"", *p
);
1016 /* processing partition parameter */
1018 if (is_empty_arg(p
)) {
1019 /* set default partition parameter */
1021 } else if (str2u32(p
, &part
->param
) != 0) {
1022 errmsg(0,"invalid partition parameter: %s", p
);
1027 if (part
->size
== 0) {
1028 part
->size
= flash_size
- part
->addr
;
1031 /* processing file parameter */
1033 if (is_empty_arg(p
) == 0) {
1036 if (fw_num_blocks
== MAX_FW_BLOCKS
) {
1037 errmsg(0,"too many blocks specified", p
);
1040 b
= &fw_blocks
[fw_num_blocks
++];
1041 b
->name
= strdup(p
);
1042 b
->addr
= part
->addr
;
1043 b
->blocklen
= part
->size
;
1044 if (part
->flags
& PARTITION_FLAG_HAVEHDR
) {
1045 b
->flags
|= BLOCK_FLAG_HAVEHDR
;
1058 parse_opt_board(char ch
, char *arg
)
1060 struct cpx_board
*board
;
1062 if (required_arg(ch
, arg
)) {
1066 board
= find_board(arg
);
1068 errmsg(0,"invalid/unknown board specified: %s", arg
);
1072 fw_header
.vid
= board
->vid
;
1073 fw_header
.did
= board
->did
;
1074 fw_header
.svid
= board
->svid
;
1075 fw_header
.sdid
= board
->sdid
;
1077 flash_size
= board
->flash_size
;
1087 parse_opt_rev(char ch
, char *arg
)
1089 if (required_arg(ch
, arg
)) {
1093 if (str2u32(arg
, &fw_header
.rev
) != 0) {
1094 errmsg(0,"invalid revision number: %s", arg
);
1106 main(int argc
, char *argv
[])
1108 int optinvalid
= 0; /* flag for invalid option */
1110 int res
= EXIT_FAILURE
;
1115 progname
=basename(argv
[0]);
1117 memset(&fw_header
, 0, sizeof(fw_header
));
1119 /* init header defaults */
1120 fw_header
.vid
= VENID_COMPEX
;
1121 fw_header
.did
= DEVID_COMPEX_WP54G
;
1122 fw_header
.svid
= VENID_COMPEX
;
1123 fw_header
.sdid
= DEVID_COMPEX_WP54G
;
1124 fw_header
.fwhi
= 0x20000;
1125 fw_header
.fwlo
= 0x20000;
1126 fw_header
.flags
= 0;
1128 opterr
= 0; /* could not print standard getopt error messages */
1129 while ((c
= getopt(argc
, argv
, "b:B:f:hi:p:r:s:v")) != -1) {
1133 optinvalid
= parse_opt_block(c
,optarg
);
1136 optinvalid
= parse_opt_board(c
,optarg
);
1139 optinvalid
= parse_opt_flags(c
,optarg
);
1142 usage(EXIT_SUCCESS
);
1145 optinvalid
= parse_opt_id(c
,optarg
);
1148 optinvalid
= parse_opt_partition(c
,optarg
);
1151 optinvalid
= parse_opt_rev(c
,optarg
);
1154 optinvalid
= parse_opt_size(c
,optarg
);
1163 if (optinvalid
!= 0 ){
1164 errmsg(0, "invalid option: -%c", optopt
);
1169 if (optind
== argc
) {
1170 errmsg(0, "no output file specified");
1174 ofname
= argv
[optind
++];
1176 if (optind
< argc
) {
1177 errmsg(0, "invalid option: %s", argv
[optind
]);
1181 if (flash_size
== 0) {
1182 errmsg(0, "no flash size specified");
1186 if (process_files() != 0) {
1190 if (process_partitions() != 0) {
1194 outfile
= fopen(ofname
, "w");
1195 if (outfile
== NULL
) {
1196 errmsg(1, "could not open \"%s\" for writing", ofname
);
1203 if (write_out_header(outfile
, &crc
) != 0)
1206 if (write_out_blocks(outfile
, &crc
) != 0)
1209 fw_header
.crc
= crc
;
1210 if (write_out_header(outfile
, NULL
) != 0)
1213 dbgmsg(1,"Firmware file %s completed.", ofname
);
1220 if (res
!= EXIT_SUCCESS
) {