2 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
4 * This tool was based on:
5 * TP-Link WR941 V2 firmware checksum fixing tool.
6 * Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
18 #include <unistd.h> /* for unlink() */
20 #include <getopt.h> /* for getopt() */
25 #include <arpa/inet.h>
26 #include <netinet/in.h>
30 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
32 #define HEADER_VERSION_V1 0x01000000
33 #define HWID_TL_MR10U_V1 0x00100101
34 #define HWID_TL_MR13U_V1 0x00130101
35 #define HWID_TL_MR3020_V1 0x30200001
36 #define HWID_TL_MR3220_V1 0x32200001
37 #define HWID_TL_MR3220_V2 0x32200002
38 #define HWID_TL_MR3420_V1 0x34200001
39 #define HWID_TL_MR3420_V2 0x34200002
40 #define HWID_TL_WA701N_V1 0x07010001
41 #define HWID_TL_WA7510N_V1 0x75100001
42 #define HWID_TL_WA801ND_V1 0x08010001
43 #define HWID_TL_WA830RE_V1 0x08300010
44 #define HWID_TL_WA830RE_V2 0x08300002
45 #define HWID_TL_WA901ND_V1 0x09010001
46 #define HWID_TL_WA901ND_V2 0x09010002
47 #define HWID_TL_WDR4900_V1 0x49000001
48 #define HWID_TL_WR703N_V1 0x07030101
49 #define HWID_TL_WR720N_V3 0x07200103
50 #define HWID_TL_WR741ND_V1 0x07410001
51 #define HWID_TL_WR741ND_V4 0x07410004
52 #define HWID_TL_WR740N_V1 0x07400001
53 #define HWID_TL_WR740N_V3 0x07400003
54 #define HWID_TL_WR743ND_V1 0x07430001
55 #define HWID_TL_WR743ND_V2 0x07430002
56 #define HWID_TL_WR841N_V1_5 0x08410002
57 #define HWID_TL_WR841ND_V3 0x08410003
58 #define HWID_TL_WR841ND_V5 0x08410005
59 #define HWID_TL_WR841ND_V7 0x08410007
60 #define HWID_TL_WR941ND_V2 0x09410002
61 #define HWID_TL_WR941ND_V4 0x09410004
62 #define HWID_TL_WR1043ND_V1 0x10430001
63 #define HWID_TL_WR1041N_V2 0x10410002
64 #define HWID_TL_WR2543N_V1 0x25430001
69 char *file_name; /* name of the file */
70 uint32_t file_size; /* length of the file */
74 uint32_t version; /* header version */
77 uint32_t hw_id; /* hardware id */
78 uint32_t hw_rev; /* hardware revision */
80 uint8_t md5sum1[MD5SUM_LEN];
82 uint8_t md5sum2[MD5SUM_LEN];
84 uint32_t kernel_la; /* kernel load address */
85 uint32_t kernel_ep; /* kernel entry point */
86 uint32_t fw_length; /* total length of the firmware */
87 uint32_t kernel_ofs; /* kernel data offset */
88 uint32_t kernel_len; /* kernel data length */
89 uint32_t rootfs_ofs; /* rootfs data offset */
90 uint32_t rootfs_len; /* rootfs data length */
91 uint32_t boot_ofs; /* bootloader data offset */
92 uint32_t boot_len; /* bootloader data length */
97 } __attribute__ ((packed));
118 static char *progname;
119 static char *vendor = "TP-LINK Technologies";
120 static char *version = "ver. 1.0";
121 static char *fw_ver = "0.0.0";
123 static char *board_id;
124 static struct board_info *board;
125 static char *layout_id;
126 static struct flash_layout *layout;
127 static char *opt_hw_id;
128 static uint32_t hw_id;
129 static char *opt_hw_rev;
130 static uint32_t hw_rev;
131 static int fw_ver_lo;
132 static int fw_ver_mid;
133 static int fw_ver_hi;
134 static struct file_info kernel_info;
135 static uint32_t kernel_la = 0;
136 static uint32_t kernel_ep = 0;
137 static uint32_t kernel_len = 0;
138 static struct file_info rootfs_info;
139 static uint32_t rootfs_ofs = 0;
140 static uint32_t rootfs_align;
141 static struct file_info boot_info;
143 static int strip_padding;
144 static int add_jffs2_eof;
145 static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
147 static struct file_info inspect_info;
148 static int extract = 0;
150 char md5salt_normal[MD5SUM_LEN] = {
151 0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
152 0xdd, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x38,
155 char md5salt_boot[MD5SUM_LEN] = {
156 0x8c, 0xef, 0x33, 0x5b, 0xd5, 0xc5, 0xce, 0xfa,
157 0xa7, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,
160 static struct flash_layout layouts[] = {
163 .fw_max_len = 0x3c0000,
164 .kernel_la = 0x80060000,
165 .kernel_ep = 0x80060000,
166 .rootfs_ofs = 0x140000,
169 .fw_max_len = 0x3c0000,
170 .kernel_la = 0x80060000,
171 .kernel_ep = 0x80060000,
172 .rootfs_ofs = 0x100000,
175 .fw_max_len = 0x7c0000,
176 .kernel_la = 0x80060000,
177 .kernel_ep = 0x80060000,
178 .rootfs_ofs = 0x140000,
181 .fw_max_len = 0x7c0000,
182 .kernel_la = 0x80060000,
183 .kernel_ep = 0x80060000,
184 .rootfs_ofs = 0x100000,
187 .fw_max_len = 0xf80000,
188 .kernel_la = 0x00000000,
189 .kernel_ep = 0xc0000000,
190 .rootfs_ofs = 0x2a0000,
192 /* terminating entry */
196 static struct board_info boards[] = {
199 .hw_id = HWID_TL_MR10U_V1,
201 .layout_id = "4Mlzma",
204 .hw_id = HWID_TL_MR13U_V1,
206 .layout_id = "4Mlzma",
209 .hw_id = HWID_TL_MR3020_V1,
211 .layout_id = "4Mlzma",
214 .hw_id = HWID_TL_MR3220_V1,
219 .hw_id = HWID_TL_MR3220_V2,
221 .layout_id = "4Mlzma",
224 .hw_id = HWID_TL_MR3420_V1,
229 .hw_id = HWID_TL_MR3420_V2,
231 .layout_id = "4Mlzma",
234 .hw_id = HWID_TL_WA701N_V1,
239 .hw_id = HWID_TL_WA7510N_V1,
243 .id = "TL-WA801NDv1",
244 .hw_id = HWID_TL_WA801ND_V1,
248 .id = "TL-WA830REv1",
249 .hw_id = HWID_TL_WA830RE_V1,
253 .id = "TL-WA830REv2",
254 .hw_id = HWID_TL_WA830RE_V2,
258 .id = "TL-WA901NDv1",
259 .hw_id = HWID_TL_WA901ND_V1,
263 .id = "TL-WA901NDv2",
264 .hw_id = HWID_TL_WA901ND_V2,
268 .id = "TL-WDR4900v1",
269 .hw_id = HWID_TL_WDR4900_V1,
271 .layout_id = "16Mppc",
273 .id = "TL-WR741NDv1",
274 .hw_id = HWID_TL_WR741ND_V1,
278 .id = "TL-WR741NDv4",
279 .hw_id = HWID_TL_WR741ND_V4,
281 .layout_id = "4Mlzma",
284 .hw_id = HWID_TL_WR740N_V1,
289 .hw_id = HWID_TL_WR740N_V3,
293 .id = "TL-WR743NDv1",
294 .hw_id = HWID_TL_WR743ND_V1,
298 .id = "TL-WR743NDv2",
299 .hw_id = HWID_TL_WR743ND_V2,
301 .layout_id = "4Mlzma",
303 .id = "TL-WR841Nv1.5",
304 .hw_id = HWID_TL_WR841N_V1_5,
308 .id = "TL-WR841NDv3",
309 .hw_id = HWID_TL_WR841ND_V3,
313 .id = "TL-WR841NDv5",
314 .hw_id = HWID_TL_WR841ND_V5,
318 .id = "TL-WR841NDv7",
319 .hw_id = HWID_TL_WR841ND_V7,
323 .id = "TL-WR941NDv2",
324 .hw_id = HWID_TL_WR941ND_V2,
328 .id = "TL-WR941NDv4",
329 .hw_id = HWID_TL_WR941ND_V4,
333 .id = "TL-WR1041Nv2",
334 .hw_id = HWID_TL_WR1041N_V2,
336 .layout_id = "4Mlzma",
338 .id = "TL-WR1043NDv1",
339 .hw_id = HWID_TL_WR1043ND_V1,
343 .id = "TL-WR2543Nv1",
344 .hw_id = HWID_TL_WR2543N_V1,
346 .layout_id = "8Mlzma",
349 .hw_id = HWID_TL_WR703N_V1,
351 .layout_id = "4Mlzma",
354 .hw_id = HWID_TL_WR720N_V3,
356 .layout_id = "4Mlzma",
358 /* terminating entry */
365 #define ERR(fmt, ...) do { \
367 fprintf(stderr, "[%s] *** error: " fmt "\n", \
368 progname, ## __VA_ARGS__ ); \
371 #define ERRS(fmt, ...) do { \
374 fprintf(stderr, "[%s] *** error: " fmt "\n", \
375 progname, ## __VA_ARGS__, strerror(save)); \
378 #define DBG(fmt, ...) do { \
379 fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
382 static struct board_info *find_board(char *id)
384 struct board_info *ret;
385 struct board_info *board;
388 for (board = boards; board->id != NULL; board++){
389 if (strcasecmp(id, board->id) == 0) {
398 static struct board_info *find_board_by_hwid(uint32_t hw_id)
400 struct board_info *board;
402 for (board = boards; board->id != NULL; board++) {
403 if (hw_id == board->hw_id)
410 static struct flash_layout *find_layout(char *id)
412 struct flash_layout *ret;
413 struct flash_layout *l;
416 for (l = layouts; l->id != NULL; l++){
417 if (strcasecmp(id, l->id) == 0) {
426 static void usage(int status)
428 FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
429 struct board_info *board;
431 fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
435 " -B <board> create image for the board specified with <board>\n"
436 " -c use combined kernel image\n"
437 " -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
438 " -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
439 " -H <hwid> use hardware id specified with <hwid>\n"
440 " -W <hwrev> use hardware revision specified with <hwrev>\n"
441 " -F <id> use flash layout specified with <id>\n"
442 " -k <file> read kernel image from the file <file>\n"
443 " -r <file> read rootfs image from the file <file>\n"
444 " -a <align> align the rootfs start on an <align> bytes boundary\n"
445 " -R <offset> overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n"
446 " -o <file> write output to the file <file>\n"
447 " -s strip padding from the end of the image\n"
448 " -j add jffs2 end-of-filesystem markers\n"
449 " -N <vendor> set image vendor to <vendor>\n"
450 " -V <version> set image version to <version>\n"
451 " -v <version> set firmware version to <version>\n"
452 " -i <file> inspect given firmware file <file>\n"
453 " -x extract kernel and rootfs while inspecting (requires -i)\n"
454 " -h show this screen\n"
460 static int get_md5(char *data, int size, char *md5)
465 MD5_Update(&ctx, data, size);
466 MD5_Final(md5, &ctx);
469 static int get_file_stat(struct file_info *fdata)
474 if (fdata->file_name == NULL)
477 res = stat(fdata->file_name, &st);
479 ERRS("stat failed on %s", fdata->file_name);
483 fdata->file_size = st.st_size;
487 static int read_to_buf(struct file_info *fdata, char *buf)
490 int ret = EXIT_FAILURE;
492 f = fopen(fdata->file_name, "r");
494 ERRS("could not open \"%s\" for reading", fdata->file_name);
499 fread(buf, fdata->file_size, 1, f);
501 ERRS("unable to read from file \"%s\"", fdata->file_name);
513 static int check_options(void)
517 if (inspect_info.file_name) {
518 ret = get_file_stat(&inspect_info);
523 } else if (extract) {
524 ERR("no firmware for inspection specified");
528 if (board_id == NULL && opt_hw_id == NULL) {
529 ERR("either board or hardware id must be specified");
534 board = find_board(board_id);
536 ERR("unknown/unsupported board id \"%s\"", board_id);
539 if (layout_id == NULL)
540 layout_id = board->layout_id;
542 hw_id = board->hw_id;
543 hw_rev = board->hw_rev;
545 if (layout_id == NULL) {
546 ERR("flash layout is not specified");
549 hw_id = strtoul(opt_hw_id, NULL, 0);
552 hw_rev = strtoul(opt_hw_rev, NULL, 0);
557 layout = find_layout(layout_id);
558 if (layout == NULL) {
559 ERR("unknown flash layout \"%s\"", layout_id);
564 kernel_la = layout->kernel_la;
566 kernel_ep = layout->kernel_ep;
568 rootfs_ofs = layout->rootfs_ofs;
570 if (kernel_info.file_name == NULL) {
571 ERR("no kernel image specified");
575 ret = get_file_stat(&kernel_info);
579 kernel_len = kernel_info.file_size;
582 if (kernel_info.file_size >
583 layout->fw_max_len - sizeof(struct fw_header)) {
584 ERR("kernel image is too big");
588 if (rootfs_info.file_name == NULL) {
589 ERR("no rootfs image specified");
593 ret = get_file_stat(&rootfs_info);
598 kernel_len += sizeof(struct fw_header);
599 kernel_len = ALIGN(kernel_len, rootfs_align);
600 kernel_len -= sizeof(struct fw_header);
602 DBG("kernel length aligned to %u", kernel_len);
604 if (kernel_len + rootfs_info.file_size >
605 layout->fw_max_len - sizeof(struct fw_header)) {
606 ERR("images are too big");
610 if (kernel_info.file_size >
611 rootfs_ofs - sizeof(struct fw_header)) {
612 ERR("kernel image is too big");
616 if (rootfs_info.file_size >
617 (layout->fw_max_len - rootfs_ofs)) {
618 ERR("rootfs image is too big");
624 if (ofname == NULL) {
625 ERR("no output file specified");
629 ret = sscanf(fw_ver, "%d.%d.%d", &fw_ver_hi, &fw_ver_mid, &fw_ver_lo);
631 ERR("invalid firmware version '%s'", fw_ver);
638 static void fill_header(char *buf, int len)
640 struct fw_header *hdr = (struct fw_header *)buf;
642 memset(hdr, 0, sizeof(struct fw_header));
644 hdr->version = htonl(HEADER_VERSION_V1);
645 strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name));
646 strncpy(hdr->fw_version, version, sizeof(hdr->fw_version));
647 hdr->hw_id = htonl(hw_id);
648 hdr->hw_rev = htonl(hw_rev);
650 if (boot_info.file_size == 0)
651 memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));
653 memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1));
655 hdr->kernel_la = htonl(kernel_la);
656 hdr->kernel_ep = htonl(kernel_ep);
657 hdr->fw_length = htonl(layout->fw_max_len);
658 hdr->kernel_ofs = htonl(sizeof(struct fw_header));
659 hdr->kernel_len = htonl(kernel_len);
661 hdr->rootfs_ofs = htonl(rootfs_ofs);
662 hdr->rootfs_len = htonl(rootfs_info.file_size);
665 hdr->ver_hi = htons(fw_ver_hi);
666 hdr->ver_mid = htons(fw_ver_mid);
667 hdr->ver_lo = htons(fw_ver_lo);
669 get_md5(buf, len, hdr->md5sum1);
672 static int pad_jffs2(char *buf, int currlen)
678 pad_mask = (64 * 1024);
679 while ((len < layout->fw_max_len) && (pad_mask != 0)) {
683 for (i = 10; i < 32; i++) {
689 len = ALIGN(len, mask);
691 for (i = 10; i < 32; i++) {
693 if ((len & (mask - 1)) == 0)
697 for (i = 0; i < sizeof(jffs2_eof_mark); i++)
698 buf[len + i] = jffs2_eof_mark[i];
700 len += sizeof(jffs2_eof_mark);
706 static int write_fw(char *data, int len)
709 int ret = EXIT_FAILURE;
711 f = fopen(ofname, "w");
713 ERRS("could not open \"%s\" for writing", ofname);
718 fwrite(data, len, 1, f);
720 ERRS("unable to write output file");
724 DBG("firmware file \"%s\" completed", ofname);
731 if (ret != EXIT_SUCCESS) {
738 static int build_fw(void)
743 int ret = EXIT_FAILURE;
746 buflen = layout->fw_max_len;
748 buf = malloc(buflen);
750 ERR("no memory for buffer\n");
754 memset(buf, 0xff, buflen);
755 p = buf + sizeof(struct fw_header);
756 ret = read_to_buf(&kernel_info, p);
760 writelen = sizeof(struct fw_header) + kernel_len;
766 p = buf + rootfs_ofs;
768 ret = read_to_buf(&rootfs_info, p);
773 writelen += rootfs_info.file_size;
775 writelen = rootfs_ofs + rootfs_info.file_size;
778 writelen = pad_jffs2(buf, writelen);
784 fill_header(buf, writelen);
785 ret = write_fw(buf, writelen);
797 /* Helper functions to inspect_fw() representing different output formats */
798 static inline void inspect_fw_pstr(char *label, char *str)
800 printf("%-23s: %s\n", label, str);
803 static inline void inspect_fw_phex(char *label, uint32_t val)
805 printf("%-23s: 0x%08x\n", label, val);
808 static inline void inspect_fw_phexpost(char *label,
809 uint32_t val, char *post)
811 printf("%-23s: 0x%08x (%s)\n", label, val, post);
814 static inline void inspect_fw_phexdef(char *label,
815 uint32_t val, uint32_t defval)
817 printf("%-23s: 0x%08x ", label, val);
820 printf("(== OpenWrt default)\n");
822 printf("(OpenWrt default: 0x%08x)\n", defval);
825 static inline void inspect_fw_phexexp(char *label,
826 uint32_t val, uint32_t expval)
828 printf("%-23s: 0x%08x ", label, val);
833 printf("(expected: 0x%08x)\n", expval);
836 static inline void inspect_fw_phexdec(char *label, uint32_t val)
838 printf("%-23s: 0x%08x / %8u bytes\n", label, val, val);
841 static inline void inspect_fw_phexdecdef(char *label,
842 uint32_t val, uint32_t defval)
844 printf("%-23s: 0x%08x / %8u bytes ", label, val, val);
847 printf("(== OpenWrt default)\n");
849 printf("(OpenWrt default: 0x%08x)\n", defval);
852 static inline void inspect_fw_pmd5sum(char *label, uint8_t *val, char *text)
856 printf("%-23s:", label);
857 for (i=0; i<MD5SUM_LEN; i++)
858 printf(" %02x", val[i]);
859 printf(" %s\n", text);
862 static int inspect_fw(void)
865 struct fw_header *hdr;
866 uint8_t md5sum[MD5SUM_LEN];
867 struct board_info *board;
868 int ret = EXIT_FAILURE;
870 buf = malloc(inspect_info.file_size);
872 ERR("no memory for buffer!\n");
876 ret = read_to_buf(&inspect_info, buf);
879 hdr = (struct fw_header *)buf;
881 inspect_fw_pstr("File name", inspect_info.file_name);
882 inspect_fw_phexdec("File size", inspect_info.file_size);
884 if (ntohl(hdr->version) != HEADER_VERSION_V1) {
885 ERR("file does not seem to have V1 header!\n");
889 inspect_fw_phexdec("Version 1 Header size", sizeof(struct fw_header));
891 if (ntohl(hdr->unk1) != 0)
892 inspect_fw_phexdec("Unknown value 1", hdr->unk1);
894 memcpy(md5sum, hdr->md5sum1, sizeof(md5sum));
895 if (ntohl(hdr->boot_len) == 0)
896 memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));
898 memcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum));
899 get_md5(buf, inspect_info.file_size, hdr->md5sum1);
901 if (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) {
902 inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(*ERROR*)");
903 inspect_fw_pmd5sum(" --> expected", hdr->md5sum1, "");
905 inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(ok)");
907 if (ntohl(hdr->unk2) != 0)
908 inspect_fw_phexdec("Unknown value 2", hdr->unk2);
909 inspect_fw_pmd5sum("Header MD5Sum2", hdr->md5sum2,
910 "(purpose yet unknown, unchecked here)");
911 if (ntohl(hdr->unk3) != 0)
912 inspect_fw_phexdec("Unknown value 3", hdr->unk3);
916 inspect_fw_pstr("Vendor name", hdr->vendor_name);
917 inspect_fw_pstr("Firmware version", hdr->fw_version);
918 board = find_board_by_hwid(ntohl(hdr->hw_id));
920 layout = find_layout(board->layout_id);
921 inspect_fw_phexpost("Hardware ID",
922 ntohl(hdr->hw_id), board->id);
923 inspect_fw_phexexp("Hardware Revision",
924 ntohl(hdr->hw_rev), board->hw_rev);
926 inspect_fw_phexpost("Hardware ID",
927 ntohl(hdr->hw_id), "unknown");
928 inspect_fw_phex("Hardware Revision",
934 inspect_fw_phexdec("Kernel data offset",
935 ntohl(hdr->kernel_ofs));
936 inspect_fw_phexdec("Kernel data length",
937 ntohl(hdr->kernel_len));
939 inspect_fw_phexdef("Kernel load address",
940 ntohl(hdr->kernel_la),
941 layout ? layout->kernel_la : 0xffffffff);
942 inspect_fw_phexdef("Kernel entry point",
943 ntohl(hdr->kernel_ep),
944 layout ? layout->kernel_ep : 0xffffffff);
945 inspect_fw_phexdecdef("Rootfs data offset",
946 ntohl(hdr->rootfs_ofs),
947 layout ? layout->rootfs_ofs : 0xffffffff);
949 inspect_fw_phex("Kernel load address",
950 ntohl(hdr->kernel_la));
951 inspect_fw_phex("Kernel entry point",
952 ntohl(hdr->kernel_ep));
953 inspect_fw_phexdec("Rootfs data offset",
954 ntohl(hdr->rootfs_ofs));
956 inspect_fw_phexdec("Rootfs data length",
957 ntohl(hdr->rootfs_len));
958 inspect_fw_phexdec("Boot loader data offset",
959 ntohl(hdr->boot_ofs));
960 inspect_fw_phexdec("Boot loader data length",
961 ntohl(hdr->boot_len));
962 inspect_fw_phexdec("Total firmware length",
963 ntohl(hdr->fw_length));
971 filename = malloc(strlen(inspect_info.file_name) + 8);
972 sprintf(filename, "%s-kernel", inspect_info.file_name);
973 printf("Extracting kernel to \"%s\"...\n", filename);
974 fp = fopen(filename, "w");
976 if (!fwrite(buf + ntohl(hdr->kernel_ofs),
977 ntohl(hdr->kernel_len), 1, fp)) {
978 ERR("error in fwrite(): %s", strerror(errno));
982 ERR("error in fopen(): %s", strerror(errno));
986 filename = malloc(strlen(inspect_info.file_name) + 8);
987 sprintf(filename, "%s-rootfs", inspect_info.file_name);
988 printf("Extracting rootfs to \"%s\"...\n", filename);
989 fp = fopen(filename, "w");
991 if (!fwrite(buf + ntohl(hdr->rootfs_ofs),
992 ntohl(hdr->rootfs_len), 1, fp)) {
993 ERR("error in fwrite(): %s", strerror(errno));
997 ERR("error in fopen(): %s", strerror(errno));
1008 int main(int argc, char *argv[])
1010 int ret = EXIT_FAILURE;
1015 progname = basename(argv[0]);
1020 c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:");
1026 sscanf(optarg, "0x%x", &rootfs_align);
1035 sscanf(optarg, "0x%x", &kernel_ep);
1041 opt_hw_rev = optarg;
1044 sscanf(optarg, "0x%x", &kernel_la);
1059 kernel_info.file_name = optarg;
1062 rootfs_info.file_name = optarg;
1065 sscanf(optarg, "0x%x", &rootfs_ofs);
1074 inspect_info.file_name = optarg;
1083 usage(EXIT_SUCCESS);
1086 usage(EXIT_FAILURE);
1091 ret = check_options();
1095 if (!inspect_info.file_name)