mktplinkfw2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  3. *
  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>
  7. *
  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.
  11. *
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdint.h>
  16. #include <string.h>
  17. #include <unistd.h> /* for unlink() */
  18. #include <libgen.h>
  19. #include <getopt.h> /* for getopt() */
  20. #include <stdarg.h>
  21. #include <errno.h>
  22. #include <stdbool.h>
  23. #include <endian.h>
  24. #include <sys/stat.h>
  25. #include <arpa/inet.h>
  26. #include <netinet/in.h>
  27. #include "md5.h"
  28. #include "mktplinkfw-lib.h"
  29. struct fw_header {
  30. uint32_t version; /* 0x00: header version */
  31. char fw_version[48]; /* 0x04: fw version string */
  32. uint32_t hw_id; /* 0x34: hardware id */
  33. uint32_t hw_rev; /* 0x38: FIXME: hardware revision? */
  34. uint32_t hw_ver_add; /* 0x3c: additional hardware version */
  35. uint8_t md5sum1[MD5SUM_LEN]; /* 0x40 */
  36. uint32_t unk2; /* 0x50: 0x00000000 */
  37. uint8_t md5sum2[MD5SUM_LEN]; /* 0x54 */
  38. uint32_t unk3; /* 0x64: 0xffffffff */
  39. uint32_t kernel_la; /* 0x68: kernel load address */
  40. uint32_t kernel_ep; /* 0x6c: kernel entry point */
  41. uint32_t fw_length; /* 0x70: total length of the image */
  42. uint32_t kernel_ofs; /* 0x74: kernel data offset */
  43. uint32_t kernel_len; /* 0x78: kernel data length */
  44. uint32_t rootfs_ofs; /* 0x7c: rootfs data offset */
  45. uint32_t rootfs_len; /* 0x80: rootfs data length */
  46. uint32_t boot_ofs; /* 0x84: bootloader offset */
  47. uint32_t boot_len; /* 0x88: bootloader length */
  48. uint16_t unk4; /* 0x8c: 0x55aa */
  49. uint8_t sver_hi; /* 0x8e */
  50. uint8_t sver_lo; /* 0x8f */
  51. uint8_t unk5; /* 0x90: magic: 0xa5 */
  52. uint8_t ver_hi; /* 0x91 */
  53. uint8_t ver_mid; /* 0x92 */
  54. uint8_t ver_lo; /* 0x93 */
  55. uint8_t pad[364];
  56. } __attribute__ ((packed));
  57. #define FLAG_LE_KERNEL_LA_EP 0x00000001 /* Little-endian used for kernel load address & entry point */
  58. struct board_info {
  59. char *id;
  60. uint32_t hw_id;
  61. uint32_t hw_rev;
  62. uint32_t hw_ver_add;
  63. char *layout_id;
  64. uint32_t hdr_ver;
  65. uint32_t flags;
  66. };
  67. /*
  68. * Globals
  69. */
  70. char *ofname;
  71. char *progname;
  72. static char *vendor = "TP-LINK Technologies";
  73. static char *version = "ver. 1.0";
  74. static char *fw_ver = "0.0.0";
  75. static char *sver = "1.0";
  76. static uint32_t hdr_ver = 2;
  77. static struct board_info custom_board;
  78. static struct board_info *board;
  79. static char *layout_id;
  80. struct flash_layout *layout;
  81. static char *opt_hw_id;
  82. static char *opt_hw_rev;
  83. static char *opt_hw_ver_add;
  84. static int fw_ver_lo;
  85. static int fw_ver_mid;
  86. static int fw_ver_hi;
  87. static int sver_lo;
  88. static int sver_hi;
  89. struct file_info kernel_info;
  90. static uint32_t kernel_la = 0;
  91. static uint32_t kernel_ep = 0;
  92. uint32_t kernel_len = 0;
  93. struct file_info rootfs_info;
  94. uint32_t rootfs_ofs = 0;
  95. uint32_t rootfs_align;
  96. static struct file_info boot_info;
  97. int combined;
  98. int strip_padding;
  99. int add_jffs2_eof;
  100. static struct file_info inspect_info;
  101. static int extract = 0;
  102. char md5salt_normal[MD5SUM_LEN] = {
  103. 0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
  104. 0xdc, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x37,
  105. };
  106. char md5salt_boot[MD5SUM_LEN] = {
  107. 0x8c, 0xef, 0x33, 0x5f, 0xd5, 0xc5, 0xce, 0xfa,
  108. 0xac, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,
  109. };
  110. static struct flash_layout layouts[] = {
  111. {
  112. .id = "4Mmtk",
  113. .fw_max_len = 0x3d0000,
  114. .kernel_la = 0x80000000,
  115. .kernel_ep = 0x80000000,
  116. .rootfs_ofs = 0x140000,
  117. }, {
  118. .id = "8Mltq",
  119. .fw_max_len = 0x7a0000,
  120. .kernel_la = 0x80002000,
  121. .kernel_ep = 0x80002000,
  122. .rootfs_ofs = 0x140000,
  123. }, {
  124. .id = "16Mltq",
  125. .fw_max_len = 0xf90000,
  126. .kernel_la = 0x80002000,
  127. .kernel_ep = 0x800061b0,
  128. .rootfs_ofs = 0x140000,
  129. }, {
  130. .id = "8Mmtk",
  131. .fw_max_len = 0x7a0000,
  132. .kernel_la = 0x80000000,
  133. .kernel_ep = 0x80000000,
  134. .rootfs_ofs = 0x140000,
  135. }, {
  136. .id = "8MSUmtk", /* Split U-Boot OS */
  137. .fw_max_len = 0x770000,
  138. .kernel_la = 0x80000000,
  139. .kernel_ep = 0x80000000,
  140. .rootfs_ofs = 0x140000,
  141. }, {
  142. .id = "8MLmtk",
  143. .fw_max_len = 0x7b0000,
  144. .kernel_la = 0x80000000,
  145. .kernel_ep = 0x80000000,
  146. .rootfs_ofs = 0x140000,
  147. }, {
  148. .id = "8Mqca",
  149. .fw_max_len = 0x7a0000,
  150. .kernel_la = 0x80060000,
  151. .kernel_ep = 0x80060000,
  152. .rootfs_ofs = 0x140000,
  153. }, {
  154. .id = "16Mqca",
  155. .fw_max_len = 0xf90000,
  156. .kernel_la = 0x80060000,
  157. .kernel_ep = 0x80060000,
  158. .rootfs_ofs = 0x140000,
  159. }, {
  160. /* terminating entry */
  161. }
  162. };
  163. static void usage(int status)
  164. {
  165. FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
  166. struct board_info *board;
  167. fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
  168. fprintf(stream,
  169. "\n"
  170. "Options:\n"
  171. " -c use combined kernel image\n"
  172. " -e swap endianness in kernel load address and entry point\n"
  173. " -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
  174. " -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
  175. " -H <hwid> use hardware id specified with <hwid>\n"
  176. " -W <hwrev> use hardware revision specified with <hwrev>\n"
  177. " -w <hwveradd> use additional hardware version specified with <hwveradd>\n"
  178. " -F <id> use flash layout specified with <id>\n"
  179. " -k <file> read kernel image from the file <file>\n"
  180. " -r <file> read rootfs image from the file <file>\n"
  181. " -a <align> align the rootfs start on an <align> bytes boundary\n"
  182. " -R <offset> overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n"
  183. " -o <file> write output to the file <file>\n"
  184. " -s strip padding from the end of the image\n"
  185. " -j add jffs2 end-of-filesystem markers\n"
  186. " -N <vendor> set image vendor to <vendor>\n"
  187. " -T <version> set header version to <version>\n"
  188. " -V <version> set image version to <version>\n"
  189. " -v <version> set firmware version to <version>\n"
  190. " -y <version> set secondary version to <version>\n"
  191. " -i <file> inspect given firmware file <file>\n"
  192. " -x extract kernel and rootfs while inspecting (requires -i)\n"
  193. " -h show this screen\n"
  194. );
  195. exit(status);
  196. }
  197. static int check_options(void)
  198. {
  199. int ret;
  200. if (inspect_info.file_name) {
  201. ret = get_file_stat(&inspect_info);
  202. if (ret)
  203. return ret;
  204. return 0;
  205. } else if (extract) {
  206. ERR("no firmware for inspection specified");
  207. return -1;
  208. }
  209. if (opt_hw_id == NULL) {
  210. ERR("hardware id must be specified");
  211. return -1;
  212. }
  213. board = &custom_board;
  214. if (layout_id == NULL) {
  215. ERR("flash layout is not specified");
  216. return -1;
  217. }
  218. board->hw_id = strtoul(opt_hw_id, NULL, 0);
  219. board->hw_rev = 1;
  220. board->hw_ver_add = 0;
  221. if (opt_hw_rev)
  222. board->hw_rev = strtoul(opt_hw_rev, NULL, 0);
  223. if (opt_hw_ver_add)
  224. board->hw_ver_add = strtoul(opt_hw_ver_add, NULL, 0);
  225. layout = find_layout(layouts, layout_id);
  226. if (layout == NULL) {
  227. ERR("unknown flash layout \"%s\"", layout_id);
  228. return -1;
  229. }
  230. if (!kernel_la)
  231. kernel_la = layout->kernel_la;
  232. if (!kernel_ep)
  233. kernel_ep = layout->kernel_ep;
  234. if (!rootfs_ofs)
  235. rootfs_ofs = layout->rootfs_ofs;
  236. if (kernel_info.file_name == NULL) {
  237. ERR("no kernel image specified");
  238. return -1;
  239. }
  240. ret = get_file_stat(&kernel_info);
  241. if (ret)
  242. return ret;
  243. kernel_len = kernel_info.file_size;
  244. if (combined) {
  245. if (kernel_info.file_size >
  246. layout->fw_max_len - sizeof(struct fw_header)) {
  247. ERR("kernel image is too big");
  248. return -1;
  249. }
  250. } else {
  251. if (rootfs_info.file_name == NULL) {
  252. ERR("no rootfs image specified");
  253. return -1;
  254. }
  255. ret = get_file_stat(&rootfs_info);
  256. if (ret)
  257. return ret;
  258. if (rootfs_align) {
  259. kernel_len += sizeof(struct fw_header);
  260. rootfs_ofs = ALIGN(kernel_len, rootfs_align);
  261. kernel_len -= sizeof(struct fw_header);
  262. DBG("rootfs offset aligned to 0x%u", rootfs_ofs);
  263. if (kernel_len + rootfs_info.file_size >
  264. layout->fw_max_len - sizeof(struct fw_header)) {
  265. ERR("images are too big");
  266. return -1;
  267. }
  268. } else {
  269. if (kernel_info.file_size >
  270. rootfs_ofs - sizeof(struct fw_header)) {
  271. ERR("kernel image is too big");
  272. return -1;
  273. }
  274. if (rootfs_info.file_size >
  275. (layout->fw_max_len - rootfs_ofs)) {
  276. ERR("rootfs image is too big");
  277. return -1;
  278. }
  279. }
  280. }
  281. if (ofname == NULL) {
  282. ERR("no output file specified");
  283. return -1;
  284. }
  285. ret = sscanf(fw_ver, "%d.%d.%d", &fw_ver_hi, &fw_ver_mid, &fw_ver_lo);
  286. if (ret != 3) {
  287. ERR("invalid firmware version '%s'", fw_ver);
  288. return -1;
  289. }
  290. ret = sscanf(sver, "%d.%d", &sver_hi, &sver_lo);
  291. if (ret != 2) {
  292. ERR("invalid secondary version '%s'", sver);
  293. return -1;
  294. }
  295. return 0;
  296. }
  297. void fill_header(char *buf, int len)
  298. {
  299. struct fw_header *hdr = (struct fw_header *)buf;
  300. unsigned ver_len;
  301. memset(hdr, '\xff', sizeof(struct fw_header));
  302. hdr->version = htonl(bswap_32(hdr_ver));
  303. ver_len = strlen(version);
  304. if (ver_len > (sizeof(hdr->fw_version) - 1))
  305. ver_len = sizeof(hdr->fw_version) - 1;
  306. memcpy(hdr->fw_version, version, ver_len);
  307. hdr->fw_version[ver_len] = 0;
  308. hdr->hw_id = htonl(board->hw_id);
  309. hdr->hw_rev = htonl(board->hw_rev);
  310. hdr->hw_ver_add = htonl(board->hw_ver_add);
  311. if (boot_info.file_size == 0) {
  312. memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));
  313. hdr->boot_ofs = htonl(0);
  314. hdr->boot_len = htonl(0);
  315. } else {
  316. memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1));
  317. hdr->boot_ofs = htonl(rootfs_ofs + rootfs_info.file_size);
  318. hdr->boot_len = htonl(rootfs_info.file_size);
  319. }
  320. hdr->kernel_la = htonl(kernel_la);
  321. hdr->kernel_ep = htonl(kernel_ep);
  322. hdr->fw_length = htonl(layout->fw_max_len);
  323. hdr->kernel_ofs = htonl(sizeof(struct fw_header));
  324. hdr->kernel_len = htonl(kernel_len);
  325. if (!combined) {
  326. hdr->rootfs_ofs = htonl(rootfs_ofs);
  327. hdr->rootfs_len = htonl(rootfs_info.file_size);
  328. }
  329. hdr->boot_ofs = htonl(0);
  330. hdr->boot_len = htonl(boot_info.file_size);
  331. hdr->unk2 = htonl(0);
  332. hdr->unk3 = htonl(0xffffffff);
  333. hdr->unk4 = htons(0x55aa);
  334. hdr->unk5 = 0xa5;
  335. hdr->sver_hi = sver_hi;
  336. hdr->sver_lo = sver_lo;
  337. hdr->ver_hi = fw_ver_hi;
  338. hdr->ver_mid = fw_ver_mid;
  339. hdr->ver_lo = fw_ver_lo;
  340. if (board->flags & FLAG_LE_KERNEL_LA_EP) {
  341. hdr->kernel_la = bswap_32(hdr->kernel_la);
  342. hdr->kernel_ep = bswap_32(hdr->kernel_ep);
  343. }
  344. get_md5(buf, len, hdr->md5sum1);
  345. }
  346. static int inspect_fw(void)
  347. {
  348. char *buf;
  349. struct fw_header *hdr;
  350. uint8_t md5sum[MD5SUM_LEN];
  351. struct board_info *board;
  352. int ret = EXIT_FAILURE;
  353. buf = malloc(inspect_info.file_size);
  354. if (!buf) {
  355. ERR("no memory for buffer!\n");
  356. goto out;
  357. }
  358. ret = read_to_buf(&inspect_info, buf);
  359. if (ret)
  360. goto out_free_buf;
  361. hdr = (struct fw_header *)buf;
  362. board = &custom_board;
  363. if (board->flags & FLAG_LE_KERNEL_LA_EP) {
  364. hdr->kernel_la = bswap_32(hdr->kernel_la);
  365. hdr->kernel_ep = bswap_32(hdr->kernel_ep);
  366. }
  367. inspect_fw_pstr("File name", inspect_info.file_name);
  368. inspect_fw_phexdec("File size", inspect_info.file_size);
  369. switch(bswap_32(ntohl(hdr->version))) {
  370. case 2:
  371. case 3:
  372. break;
  373. default:
  374. ERR("file does not seem to have V2/V3 header!\n");
  375. goto out_free_buf;
  376. }
  377. inspect_fw_phexdec("Version 2 Header size", sizeof(struct fw_header));
  378. memcpy(md5sum, hdr->md5sum1, sizeof(md5sum));
  379. if (ntohl(hdr->boot_len) == 0)
  380. memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));
  381. else
  382. memcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum));
  383. get_md5(buf, inspect_info.file_size, hdr->md5sum1);
  384. if (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) {
  385. inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(*ERROR*)");
  386. inspect_fw_pmd5sum(" --> expected", hdr->md5sum1, "");
  387. } else {
  388. inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(ok)");
  389. }
  390. if (ntohl(hdr->unk2) != 0)
  391. inspect_fw_phexdec("Unknown value 2", hdr->unk2);
  392. inspect_fw_pmd5sum("Header MD5Sum2", hdr->md5sum2,
  393. "(purpose yet unknown, unchecked here)");
  394. if (ntohl(hdr->unk3) != 0xffffffff)
  395. inspect_fw_phexdec("Unknown value 3", hdr->unk3);
  396. if (ntohs(hdr->unk4) != 0x55aa)
  397. inspect_fw_phexdec("Unknown value 4", hdr->unk4);
  398. if (hdr->unk5 != 0xa5)
  399. inspect_fw_phexdec("Unknown value 5", hdr->unk5);
  400. printf("\n");
  401. inspect_fw_pstr("Firmware version", hdr->fw_version);
  402. inspect_fw_phex("Hardware ID", ntohl(hdr->hw_id));
  403. inspect_fw_phex("Hardware Revision",
  404. ntohl(hdr->hw_rev));
  405. inspect_fw_phex("Additional HW Version",
  406. ntohl(hdr->hw_ver_add));
  407. printf("%-23s: %d.%d.%d-%d.%d\n", "Software version",
  408. hdr->ver_hi, hdr->ver_mid, hdr->ver_lo,
  409. hdr->sver_hi, hdr->sver_lo);
  410. printf("\n");
  411. inspect_fw_phexdec("Kernel data offset",
  412. ntohl(hdr->kernel_ofs));
  413. inspect_fw_phexdec("Kernel data length",
  414. ntohl(hdr->kernel_len));
  415. inspect_fw_phex("Kernel load address",
  416. ntohl(hdr->kernel_la));
  417. inspect_fw_phex("Kernel entry point",
  418. ntohl(hdr->kernel_ep));
  419. inspect_fw_phexdec("Rootfs data offset",
  420. ntohl(hdr->rootfs_ofs));
  421. inspect_fw_phexdec("Rootfs data length",
  422. ntohl(hdr->rootfs_len));
  423. inspect_fw_phexdec("Boot loader data offset",
  424. ntohl(hdr->boot_ofs));
  425. inspect_fw_phexdec("Boot loader data length",
  426. ntohl(hdr->boot_len));
  427. inspect_fw_phexdec("Total firmware length",
  428. ntohl(hdr->fw_length));
  429. if (extract) {
  430. FILE *fp;
  431. char *filename;
  432. printf("\n");
  433. filename = malloc(strlen(inspect_info.file_name) + 8);
  434. sprintf(filename, "%s-kernel", inspect_info.file_name);
  435. printf("Extracting kernel to \"%s\"...\n", filename);
  436. fp = fopen(filename, "w");
  437. if (fp) {
  438. if (!fwrite(buf + ntohl(hdr->kernel_ofs),
  439. ntohl(hdr->kernel_len), 1, fp)) {
  440. ERR("error in fwrite(): %s", strerror(errno));
  441. }
  442. fclose(fp);
  443. } else {
  444. ERR("error in fopen(): %s", strerror(errno));
  445. }
  446. free(filename);
  447. filename = malloc(strlen(inspect_info.file_name) + 8);
  448. sprintf(filename, "%s-rootfs", inspect_info.file_name);
  449. printf("Extracting rootfs to \"%s\"...\n", filename);
  450. fp = fopen(filename, "w");
  451. if (fp) {
  452. if (!fwrite(buf + ntohl(hdr->rootfs_ofs),
  453. ntohl(hdr->rootfs_len), 1, fp)) {
  454. ERR("error in fwrite(): %s", strerror(errno));
  455. }
  456. fclose(fp);
  457. } else {
  458. ERR("error in fopen(): %s", strerror(errno));
  459. }
  460. free(filename);
  461. }
  462. out_free_buf:
  463. free(buf);
  464. out:
  465. return ret;
  466. }
  467. int main(int argc, char *argv[])
  468. {
  469. int ret = EXIT_FAILURE;
  470. progname = basename(argv[0]);
  471. while ( 1 ) {
  472. int c;
  473. c = getopt(argc, argv, "a:H:E:F:L:V:N:W:w:ci:k:r:R:o:xhsjv:y:T:e");
  474. if (c == -1)
  475. break;
  476. switch (c) {
  477. case 'a':
  478. sscanf(optarg, "0x%x", &rootfs_align);
  479. break;
  480. case 'H':
  481. opt_hw_id = optarg;
  482. break;
  483. case 'E':
  484. sscanf(optarg, "0x%x", &kernel_ep);
  485. break;
  486. case 'F':
  487. layout_id = optarg;
  488. break;
  489. case 'W':
  490. opt_hw_rev = optarg;
  491. break;
  492. case 'w':
  493. opt_hw_ver_add = optarg;
  494. break;
  495. case 'L':
  496. sscanf(optarg, "0x%x", &kernel_la);
  497. break;
  498. case 'V':
  499. version = optarg;
  500. break;
  501. case 'v':
  502. fw_ver = optarg;
  503. break;
  504. case 'y':
  505. sver = optarg;
  506. break;
  507. case 'N':
  508. vendor = optarg;
  509. break;
  510. case 'c':
  511. combined++;
  512. break;
  513. case 'k':
  514. kernel_info.file_name = optarg;
  515. break;
  516. case 'r':
  517. rootfs_info.file_name = optarg;
  518. break;
  519. case 'R':
  520. sscanf(optarg, "0x%x", &rootfs_ofs);
  521. break;
  522. case 'o':
  523. ofname = optarg;
  524. break;
  525. case 's':
  526. strip_padding = 1;
  527. break;
  528. case 'i':
  529. inspect_info.file_name = optarg;
  530. break;
  531. case 'j':
  532. add_jffs2_eof = 1;
  533. break;
  534. case 'x':
  535. extract = 1;
  536. break;
  537. case 'T':
  538. hdr_ver = atoi(optarg);
  539. break;
  540. case 'e':
  541. custom_board.flags = FLAG_LE_KERNEL_LA_EP;
  542. break;
  543. case 'h':
  544. usage(EXIT_SUCCESS);
  545. break;
  546. default:
  547. usage(EXIT_FAILURE);
  548. break;
  549. }
  550. }
  551. ret = check_options();
  552. if (ret)
  553. goto out;
  554. if (!inspect_info.file_name)
  555. ret = build_fw(sizeof(struct fw_header));
  556. else
  557. ret = inspect_fw();
  558. out:
  559. return ret;
  560. }