0005-firmware-utils-add-new-tool-tplink-safeloader-for-the-new-TP-LINK-Pharos-devices-CPE210-220-510-520.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Wed, 26 Nov 2014 19:57:39 +0100
  3. Subject: firmware-utils: add new tool tplink-safeloader for the new TP-LINK Pharos devices (CPE210/220/510/520)
  4. The new TP-LINK Pharos series uses a new bootloader, the "TP-LINK Safeloader".
  5. It uses an advanced firmware image format, containing an image partition table
  6. and a flash partition table (and image partitions are mapped to the
  7. corresponding flash partitions). The exact image format is documented in the
  8. source code.
  9. Furthermore, the bootloader expects the kernel image as an ELF executable.
  10. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  11. diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
  12. index 4bb53cb..3f9eb56 100644
  13. --- a/tools/firmware-utils/Makefile
  14. +++ b/tools/firmware-utils/Makefile
  15. @@ -41,6 +41,7 @@ define Host/Compile
  16. $(call cc,mkplanexfw sha1)
  17. $(call cc,mktplinkfw md5)
  18. $(call cc,mktplinkfw2 md5)
  19. + $(call cc,tplink-safeloader md5, -Wall)
  20. $(call cc,pc1crypt)
  21. $(call cc,osbridge-crc)
  22. $(call cc,wrt400n cyg_crc32)
  23. diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
  24. new file mode 100644
  25. index 0000000..23d703f
  26. --- /dev/null
  27. +++ b/tools/firmware-utils/src/tplink-safeloader.c
  28. @@ -0,0 +1,538 @@
  29. +/*
  30. + Copyright (c) 2014, Matthias Schiffer <mschiffer@universe-factory.net>
  31. + All rights reserved.
  32. +
  33. + Redistribution and use in source and binary forms, with or without
  34. + modification, are permitted provided that the following conditions are met:
  35. +
  36. + 1. Redistributions of source code must retain the above copyright notice,
  37. + this list of conditions and the following disclaimer.
  38. + 2. Redistributions in binary form must reproduce the above copyright notice,
  39. + this list of conditions and the following disclaimer in the documentation
  40. + and/or other materials provided with the distribution.
  41. +
  42. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  43. + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44. + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  45. + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  46. + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  48. + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  50. + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  51. + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. +*/
  53. +
  54. +
  55. +/*
  56. + tplink-safeloader
  57. +
  58. + Image generation tool for the TP-LINK SafeLoader as seen on
  59. + TP-LINK Pharos devices (CPE210/220/510/520)
  60. +*/
  61. +
  62. +
  63. +#include <assert.h>
  64. +#include <errno.h>
  65. +#include <error.h>
  66. +#include <stdbool.h>
  67. +#include <stdio.h>
  68. +#include <stdint.h>
  69. +#include <stdlib.h>
  70. +#include <string.h>
  71. +#include <time.h>
  72. +#include <unistd.h>
  73. +
  74. +#include <arpa/inet.h>
  75. +
  76. +#include <sys/types.h>
  77. +#include <sys/stat.h>
  78. +
  79. +#include "md5.h"
  80. +
  81. +
  82. +#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
  83. +
  84. +
  85. +/** An image partition table entry */
  86. +struct image_partition_entry {
  87. + const char *name;
  88. + size_t size;
  89. + uint8_t *data;
  90. +};
  91. +
  92. +/** A flash partition table entry */
  93. +struct flash_partition_entry {
  94. + const char *name;
  95. + uint32_t base;
  96. + uint32_t size;
  97. +};
  98. +
  99. +
  100. +/** The content of the soft-version structure */
  101. +struct __attribute__((__packed__)) soft_version {
  102. + uint32_t magic;
  103. + uint32_t zero;
  104. + uint8_t pad1;
  105. + uint8_t version_major;
  106. + uint8_t version_minor;
  107. + uint8_t version_patch;
  108. + uint8_t year_hi;
  109. + uint8_t year_lo;
  110. + uint8_t month;
  111. + uint8_t day;
  112. + uint32_t rev;
  113. + uint8_t pad2;
  114. +};
  115. +
  116. +
  117. +static const uint8_t jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
  118. +
  119. +
  120. +/**
  121. + Salt for the MD5 hash
  122. +
  123. + Fortunately, TP-LINK seems to use the same salt for most devices which use
  124. + the new image format.
  125. +*/
  126. +static const uint8_t md5_salt[16] = {
  127. + 0x7a, 0x2b, 0x15, 0xed,
  128. + 0x9b, 0x98, 0x59, 0x6d,
  129. + 0xe5, 0x04, 0xab, 0x44,
  130. + 0xac, 0x2a, 0x9f, 0x4e,
  131. +};
  132. +
  133. +
  134. +/** Vendor information for CPE210/220/510/520 */
  135. +static const unsigned char cpe510_vendor[] = "\x00\x00\x00\x1f""CPE510(TP-LINK|UN|N300-5):1.0\r\n";
  136. +
  137. +
  138. +/**
  139. + The flash partition table for CPE210/220/510/520;
  140. + it is the same as the one used by the stock images.
  141. +*/
  142. +static const struct flash_partition_entry cpe510_partitions[] = {
  143. + {"fs-uboot", 0x00000, 0x20000},
  144. + {"partition-table", 0x20000, 0x02000},
  145. + {"default-mac", 0x30000, 0x00020},
  146. + {"product-info", 0x31100, 0x00100},
  147. + {"signature", 0x32000, 0x00400},
  148. + {"os-image", 0x40000, 0x170000},
  149. + {"soft-version", 0x1b0000, 0x00100},
  150. + {"support-list", 0x1b1000, 0x00400},
  151. + {"file-system", 0x1c0000, 0x600000},
  152. + {"user-config", 0x7c0000, 0x10000},
  153. + {"default-config", 0x7d0000, 0x10000},
  154. + {"log", 0x7e0000, 0x10000},
  155. + {"radio", 0x7f0000, 0x10000},
  156. + {NULL, 0, 0}
  157. +};
  158. +
  159. +/**
  160. + The support list for CPE210/220/510/520
  161. +
  162. + The stock images also contain strings for two more devices: BS510 and BS210.
  163. + At the moment, there exists no public information about these devices.
  164. +*/
  165. +static const unsigned char cpe510_support_list[] =
  166. + "\x00\x00\x00\xc8\x00\x00\x00\x00"
  167. + "SupportList:\r\n"
  168. + "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
  169. + "CPE520(TP-LINK|UN|N300-5):1.0\r\n"
  170. + "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
  171. + "CPE220(TP-LINK|UN|N300-2):1.0\r\n"
  172. + "\r\n\xff";
  173. +
  174. +
  175. +/** Allocates a new image partition */
  176. +struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
  177. + struct image_partition_entry entry = {name, len, malloc(len)};
  178. + if (!entry.data)
  179. + error(1, errno, "malloc");
  180. +
  181. + return entry;
  182. +}
  183. +
  184. +/** Frees an image partition */
  185. +void free_image_partition(struct image_partition_entry entry) {
  186. + free(entry.data);
  187. +}
  188. +
  189. +/** Generates the partition-table partition */
  190. +struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
  191. + struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
  192. +
  193. + char *s = (char *)entry.data, *end = (char *)(s+entry.size);
  194. +
  195. + *(s++) = 0x00;
  196. + *(s++) = 0x04;
  197. + *(s++) = 0x00;
  198. + *(s++) = 0x00;
  199. +
  200. + size_t i;
  201. + for (i = 0; p[i].name; i++) {
  202. + size_t len = end-s;
  203. + size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n", p[i].name, p[i].base, p[i].size);
  204. +
  205. + if (w > len-1)
  206. + error(1, 0, "flash partition table overflow?");
  207. +
  208. + s += w;
  209. + }
  210. +
  211. + s++;
  212. +
  213. + memset(s, 0xff, end-s);
  214. +
  215. + return entry;
  216. +}
  217. +
  218. +
  219. +/** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
  220. +static inline uint8_t bcd(uint8_t v) {
  221. + return 0x10 * (v/10) + v%10;
  222. +}
  223. +
  224. +
  225. +/** Generates the soft-version partition */
  226. +struct image_partition_entry make_soft_version(uint32_t rev) {
  227. + struct image_partition_entry entry = alloc_image_partition("soft-version", sizeof(struct soft_version));
  228. + struct soft_version *s = (struct soft_version *)entry.data;
  229. +
  230. + time_t t;
  231. + if (time(&t) == (time_t)(-1))
  232. + error(1, errno, "time");
  233. +
  234. + struct tm *tm = localtime(&t);
  235. +
  236. + s->magic = htonl(0x0000000c);
  237. + s->zero = 0;
  238. + s->pad1 = 0xff;
  239. +
  240. + s->version_major = 0;
  241. + s->version_minor = 0;
  242. + s->version_patch = 0;
  243. +
  244. + s->year_hi = bcd((1900+tm->tm_year)/100);
  245. + s->year_lo = bcd(tm->tm_year%100);
  246. + s->month = bcd(tm->tm_mon+1);
  247. + s->day = bcd(tm->tm_mday);
  248. + s->rev = htonl(rev);
  249. +
  250. + s->pad2 = 0xff;
  251. +
  252. + return entry;
  253. +}
  254. +
  255. +/** Generates the support-list partition */
  256. +struct image_partition_entry make_support_list(const unsigned char *support_list, size_t len) {
  257. + struct image_partition_entry entry = alloc_image_partition("support-list", len);
  258. + memcpy(entry.data, support_list, len);
  259. + return entry;
  260. +}
  261. +
  262. +/** Creates a new image partition with an arbitrary name from a file */
  263. +struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) {
  264. + struct stat statbuf;
  265. +
  266. + if (stat(filename, &statbuf) < 0)
  267. + error(1, errno, "unable to stat file `%s'", filename);
  268. +
  269. + size_t len = statbuf.st_size;
  270. +
  271. + if (add_jffs2_eof)
  272. + len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
  273. +
  274. + struct image_partition_entry entry = alloc_image_partition(part_name, len);
  275. +
  276. + FILE *file = fopen(filename, "rb");
  277. + if (!file)
  278. + error(1, errno, "unable to open file `%s'", filename);
  279. +
  280. + if (fread(entry.data, statbuf.st_size, 1, file) != 1)
  281. + error(1, errno, "unable to read file `%s'", filename);
  282. +
  283. + if (add_jffs2_eof) {
  284. + uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
  285. +
  286. + memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
  287. + memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
  288. + }
  289. +
  290. + fclose(file);
  291. +
  292. + return entry;
  293. +}
  294. +
  295. +
  296. +/**
  297. + Copies a list of image partitions into an image buffer and generates the image partition table while doing so
  298. +
  299. + Example image partition table:
  300. +
  301. + fwup-ptn partition-table base 0x00800 size 0x00800
  302. + fwup-ptn os-image base 0x01000 size 0x113b45
  303. + fwup-ptn file-system base 0x114b45 size 0x1d0004
  304. + fwup-ptn support-list base 0x2e4b49 size 0x000d1
  305. +
  306. + Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
  307. + the end of the partition table is marked with a zero byte.
  308. +
  309. + The firmware image must contain at least the partition-table and support-list partitions
  310. + to be accepted. There aren't any alignment constraints for the image partitions.
  311. +
  312. + The partition-table partition contains the actual flash layout; partitions
  313. + from the image partition table are mapped to the corresponding flash partitions during
  314. + the firmware upgrade. The support-list partition contains a list of devices supported by
  315. + the firmware image.
  316. +
  317. + The base offsets in the firmware partition table are relative to the end
  318. + of the vendor information block, so the partition-table partition will
  319. + actually start at offset 0x1814 of the image.
  320. +
  321. + I think partition-table must be the first partition in the firmware image.
  322. +*/
  323. +void put_partitions(uint8_t *buffer, const struct image_partition_entry *parts) {
  324. + size_t i;
  325. + char *image_pt = (char *)buffer, *end = image_pt + 0x800;
  326. +
  327. + size_t base = 0x800;
  328. + for (i = 0; parts[i].name; i++) {
  329. + memcpy(buffer + base, parts[i].data, parts[i].size);
  330. +
  331. + size_t len = end-image_pt;
  332. + size_t w = snprintf(image_pt, len, "fwup-ptn %s base 0x%05x size 0x%05x\t\r\n", parts[i].name, (unsigned)base, (unsigned)parts[i].size);
  333. +
  334. + if (w > len-1)
  335. + error(1, 0, "image partition table overflow?");
  336. +
  337. + image_pt += w;
  338. +
  339. + base += parts[i].size;
  340. + }
  341. +
  342. + image_pt++;
  343. +
  344. + memset(image_pt, 0xff, end-image_pt);
  345. +}
  346. +
  347. +/** Generates and writes the image MD5 checksum */
  348. +void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
  349. + MD5_CTX ctx;
  350. +
  351. + MD5_Init(&ctx);
  352. + MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
  353. + MD5_Update(&ctx, buffer, len);
  354. + MD5_Final(md5, &ctx);
  355. +}
  356. +
  357. +
  358. +/**
  359. + Generates the firmware image in factory format
  360. +
  361. + Image format:
  362. +
  363. + Bytes (hex) Usage
  364. + ----------- -----
  365. + 0000-0003 Image size (4 bytes, big endian)
  366. + 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
  367. + 0014-1013 Vendor information (4096 bytes, padded with 0xff; there seem to be older
  368. + (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
  369. + 1014-1813 Image partition table (2048 bytes, padded with 0xff)
  370. + 1814-xxxx Firmware partitions
  371. +*/
  372. +void * generate_factory_image(const unsigned char *vendor, size_t vendor_len, const struct image_partition_entry *parts, size_t *len) {
  373. + *len = 0x1814;
  374. +
  375. + size_t i;
  376. + for (i = 0; parts[i].name; i++)
  377. + *len += parts[i].size;
  378. +
  379. + uint8_t *image = malloc(*len);
  380. + if (!image)
  381. + error(1, errno, "malloc");
  382. +
  383. + image[0] = *len >> 24;
  384. + image[1] = *len >> 16;
  385. + image[2] = *len >> 8;
  386. + image[3] = *len;
  387. +
  388. + memcpy(image+0x14, vendor, vendor_len);
  389. + memset(image+0x14+vendor_len, 0xff, 4096-vendor_len);
  390. +
  391. + put_partitions(image + 0x1014, parts);
  392. + put_md5(image+0x04, image+0x14, *len-0x14);
  393. +
  394. + return image;
  395. +}
  396. +
  397. +/**
  398. + Generates the firmware image in sysupgrade format
  399. +
  400. + This makes some assumptions about the provided flash and image partition tables and
  401. + should be generalized when TP-LINK starts building its safeloader into hardware with
  402. + different flash layouts.
  403. +*/
  404. +void * generate_sysupgrade_image(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
  405. + const struct flash_partition_entry *flash_os_image = &flash_parts[5];
  406. + const struct flash_partition_entry *flash_soft_version = &flash_parts[6];
  407. + const struct flash_partition_entry *flash_support_list = &flash_parts[7];
  408. + const struct flash_partition_entry *flash_file_system = &flash_parts[8];
  409. +
  410. + const struct image_partition_entry *image_os_image = &image_parts[3];
  411. + const struct image_partition_entry *image_soft_version = &image_parts[1];
  412. + const struct image_partition_entry *image_support_list = &image_parts[2];
  413. + const struct image_partition_entry *image_file_system = &image_parts[4];
  414. +
  415. + assert(strcmp(flash_os_image->name, "os-image") == 0);
  416. + assert(strcmp(flash_soft_version->name, "soft-version") == 0);
  417. + assert(strcmp(flash_support_list->name, "support-list") == 0);
  418. + assert(strcmp(flash_file_system->name, "file-system") == 0);
  419. +
  420. + assert(strcmp(image_os_image->name, "os-image") == 0);
  421. + assert(strcmp(image_soft_version->name, "soft-version") == 0);
  422. + assert(strcmp(image_support_list->name, "support-list") == 0);
  423. + assert(strcmp(image_file_system->name, "file-system") == 0);
  424. +
  425. + if (image_os_image->size > flash_os_image->size)
  426. + error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
  427. + if (image_file_system->size > flash_file_system->size)
  428. + error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
  429. +
  430. + *len = flash_file_system->base - flash_os_image->base + image_file_system->size;
  431. +
  432. + uint8_t *image = malloc(*len);
  433. + if (!image)
  434. + error(1, errno, "malloc");
  435. +
  436. + memset(image, 0xff, *len);
  437. +
  438. + memcpy(image, image_os_image->data, image_os_image->size);
  439. + memcpy(image + flash_soft_version->base - flash_os_image->base, image_soft_version->data, image_soft_version->size);
  440. + memcpy(image + flash_support_list->base - flash_os_image->base, image_support_list->data, image_support_list->size);
  441. + memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
  442. +
  443. + return image;
  444. +}
  445. +
  446. +
  447. +/** Generates an image for CPE210/220/510/520 and writes it to a file */
  448. +static void do_cpe510(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
  449. + struct image_partition_entry parts[6] = {};
  450. +
  451. + parts[0] = make_partition_table(cpe510_partitions);
  452. + parts[1] = make_soft_version(rev);
  453. + parts[2] = make_support_list(cpe510_support_list, sizeof(cpe510_support_list)-1);
  454. + parts[3] = read_file("os-image", kernel_image, false);
  455. + parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
  456. +
  457. + size_t len;
  458. + void *image;
  459. + if (sysupgrade)
  460. + image = generate_sysupgrade_image(cpe510_partitions, parts, &len);
  461. + else
  462. + image = generate_factory_image(cpe510_vendor, sizeof(cpe510_vendor)-1, parts, &len);
  463. +
  464. + FILE *file = fopen(output, "wb");
  465. + if (!file)
  466. + error(1, errno, "unable to open output file");
  467. +
  468. + if (fwrite(image, len, 1, file) != 1)
  469. + error(1, 0, "unable to write output file");
  470. +
  471. + fclose(file);
  472. +
  473. + free(image);
  474. +
  475. + size_t i;
  476. + for (i = 0; parts[i].name; i++)
  477. + free_image_partition(parts[i]);
  478. +}
  479. +
  480. +
  481. +/** Usage output */
  482. +void usage(const char *argv0) {
  483. + fprintf(stderr,
  484. + "Usage: %s [OPTIONS...]\n"
  485. + "\n"
  486. + "Options:\n"
  487. + " -B <board> create image for the board specified with <board>\n"
  488. + " -k <file> read kernel image from the file <file>\n"
  489. + " -r <file> read rootfs image from the file <file>\n"
  490. + " -o <file> write output to the file <file>\n"
  491. + " -V <rev> sets the revision number to <rev>\n"
  492. + " -j add jffs2 end-of-filesystem markers\n"
  493. + " -S create sysupgrade instead of factory image\n"
  494. + " -h show this help\n",
  495. + argv0
  496. + );
  497. +};
  498. +
  499. +
  500. +int main(int argc, char *argv[]) {
  501. + const char *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
  502. + bool add_jffs2_eof = false, sysupgrade = false;
  503. + unsigned rev = 0;
  504. +
  505. + while (true) {
  506. + int c;
  507. +
  508. + c = getopt(argc, argv, "B:k:r:o:V:jSh");
  509. + if (c == -1)
  510. + break;
  511. +
  512. + switch (c) {
  513. + case 'B':
  514. + board = optarg;
  515. + break;
  516. +
  517. + case 'k':
  518. + kernel_image = optarg;
  519. + break;
  520. +
  521. + case 'r':
  522. + rootfs_image = optarg;
  523. + break;
  524. +
  525. + case 'o':
  526. + output = optarg;
  527. + break;
  528. +
  529. + case 'V':
  530. + sscanf(optarg, "r%u", &rev);
  531. + break;
  532. +
  533. + case 'j':
  534. + add_jffs2_eof = true;
  535. + break;
  536. +
  537. + case 'S':
  538. + sysupgrade = true;
  539. + break;
  540. +
  541. + case 'h':
  542. + usage(argv[0]);
  543. + return 0;
  544. +
  545. + default:
  546. + usage(argv[0]);
  547. + return 1;
  548. + }
  549. + }
  550. +
  551. + if (!board)
  552. + error(1, 0, "no board has been specified");
  553. + if (!kernel_image)
  554. + error(1, 0, "no kernel image has been specified");
  555. + if (!rootfs_image)
  556. + error(1, 0, "no rootfs image has been specified");
  557. + if (!output)
  558. + error(1, 0, "no output filename has been specified");
  559. +
  560. + if (strcmp(board, "CPE510") == 0)
  561. + do_cpe510(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
  562. + else
  563. + error(1, 0, "unsupported board %s", board);
  564. +
  565. + return 0;
  566. +}