2 Copyright (c) 2014, Matthias Schiffer <mschiffer@universe-factory.net>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 Image generation tool for the TP-LINK SafeLoader as seen on
31 TP-LINK Pharos devices (CPE210/220/510/520)
45 #include <arpa/inet.h>
47 #include <sys/types.h>
54 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
57 #define MAX_PARTITIONS 32
59 /** An image partition table entry */
60 struct image_partition_entry
{
66 /** A flash partition table entry */
67 struct flash_partition_entry
{
73 /** Firmware layout description */
77 const char *support_list
;
80 struct flash_partition_entry partitions
[MAX_PARTITIONS
+1];
81 const char *first_sysupgrade_partition
;
82 const char *last_sysupgrade_partition
;
85 /** The content of the soft-version structure */
86 struct __attribute__((__packed__
)) soft_version
{
90 uint8_t version_major
;
91 uint8_t version_minor
;
92 uint8_t version_patch
;
102 static const uint8_t jffs2_eof_mark
[4] = {0xde, 0xad, 0xc0, 0xde};
106 Salt for the MD5 hash
108 Fortunately, TP-LINK seems to use the same salt for most devices which use
109 the new image format.
111 static const uint8_t md5_salt
[16] = {
112 0x7a, 0x2b, 0x15, 0xed,
113 0x9b, 0x98, 0x59, 0x6d,
114 0xe5, 0x04, 0xab, 0x44,
115 0xac, 0x2a, 0x9f, 0x4e,
119 /** Firmware layout table */
120 static struct device_info boards
[] = {
121 /** Firmware layout for the CPE210/220 */
124 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
127 "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
128 "CPE210(TP-LINK|UN|N300-2):1.1\r\n"
129 "CPE210(TP-LINK|US|N300-2):1.1\r\n"
130 "CPE210(TP-LINK|EU|N300-2):1.1\r\n"
131 "CPE220(TP-LINK|UN|N300-2):1.1\r\n"
132 "CPE220(TP-LINK|US|N300-2):1.1\r\n"
133 "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
134 .support_trail
= '\xff',
138 {"fs-uboot", 0x00000, 0x20000},
139 {"partition-table", 0x20000, 0x02000},
140 {"default-mac", 0x30000, 0x00020},
141 {"product-info", 0x31100, 0x00100},
142 {"signature", 0x32000, 0x00400},
143 {"os-image", 0x40000, 0x1c0000},
144 {"file-system", 0x200000, 0x5b0000},
145 {"soft-version", 0x7b0000, 0x00100},
146 {"support-list", 0x7b1000, 0x00400},
147 {"user-config", 0x7c0000, 0x10000},
148 {"default-config", 0x7d0000, 0x10000},
149 {"log", 0x7e0000, 0x10000},
150 {"radio", 0x7f0000, 0x10000},
154 .first_sysupgrade_partition
= "os-image",
155 .last_sysupgrade_partition
= "support-list",
158 /** Firmware layout for the CPE210 V2 */
161 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
164 "CPE210(TP-LINK|EU|N300-2|00000000):2.0\r\n"
165 "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n"
166 "CPE210(TP-LINK|EU|N300-2|55530000):2.0\r\n"
167 "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
168 "CPE210(TP-LINK|UN|N300-2|45550000):2.0\r\n"
169 "CPE210(TP-LINK|UN|N300-2|55530000):2.0\r\n"
170 "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
171 "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
172 "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
173 "CPE210(TP-LINK|US|N300-2):2.0\r\n",
174 .support_trail
= '\xff',
178 {"fs-uboot", 0x00000, 0x20000},
179 {"partition-table", 0x20000, 0x02000},
180 {"default-mac", 0x30000, 0x00020},
181 {"product-info", 0x31100, 0x00100},
182 {"device-info", 0x31400, 0x00400},
183 {"signature", 0x32000, 0x00400},
184 {"device-id", 0x33000, 0x00100},
185 {"os-image", 0x40000, 0x1c0000},
186 {"file-system", 0x200000, 0x5b0000},
187 {"soft-version", 0x7b0000, 0x00100},
188 {"support-list", 0x7b1000, 0x01000},
189 {"user-config", 0x7c0000, 0x10000},
190 {"default-config", 0x7d0000, 0x10000},
191 {"log", 0x7e0000, 0x10000},
192 {"radio", 0x7f0000, 0x10000},
196 .first_sysupgrade_partition
= "os-image",
197 .last_sysupgrade_partition
= "support-list",
200 /** Firmware layout for the CPE510/520 */
203 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
206 "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
207 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
208 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
209 "CPE510(TP-LINK|US|N300-5):1.1\r\n"
210 "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
211 "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
212 "CPE520(TP-LINK|US|N300-5):1.1\r\n"
213 "CPE520(TP-LINK|EU|N300-5):1.1\r\n"
214 "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
215 "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
216 "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
217 "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
218 "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
219 "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
220 "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
221 "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
222 "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
223 "CPE510(TP-LINK|US|N300-5):2.0\r\n",
224 .support_trail
= '\xff',
228 {"fs-uboot", 0x00000, 0x20000},
229 {"partition-table", 0x20000, 0x02000},
230 {"default-mac", 0x30000, 0x00020},
231 {"product-info", 0x31100, 0x00100},
232 {"signature", 0x32000, 0x00400},
233 {"os-image", 0x40000, 0x1c0000},
234 {"file-system", 0x200000, 0x5b0000},
235 {"soft-version", 0x7b0000, 0x00100},
236 {"support-list", 0x7b1000, 0x00400},
237 {"user-config", 0x7c0000, 0x10000},
238 {"default-config", 0x7d0000, 0x10000},
239 {"log", 0x7e0000, 0x10000},
240 {"radio", 0x7f0000, 0x10000},
244 .first_sysupgrade_partition
= "os-image",
245 .last_sysupgrade_partition
= "support-list",
250 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
253 "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
254 "WBS210(TP-LINK|US|N300-2):1.20\r\n"
255 "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
256 .support_trail
= '\xff',
260 {"fs-uboot", 0x00000, 0x20000},
261 {"partition-table", 0x20000, 0x02000},
262 {"default-mac", 0x30000, 0x00020},
263 {"product-info", 0x31100, 0x00100},
264 {"signature", 0x32000, 0x00400},
265 {"os-image", 0x40000, 0x1c0000},
266 {"file-system", 0x200000, 0x5b0000},
267 {"soft-version", 0x7b0000, 0x00100},
268 {"support-list", 0x7b1000, 0x00400},
269 {"user-config", 0x7c0000, 0x10000},
270 {"default-config", 0x7d0000, 0x10000},
271 {"log", 0x7e0000, 0x10000},
272 {"radio", 0x7f0000, 0x10000},
276 .first_sysupgrade_partition
= "os-image",
277 .last_sysupgrade_partition
= "support-list",
282 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
285 "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
286 "WBS510(TP-LINK|US|N300-5):1.20\r\n"
287 "WBS510(TP-LINK|EU|N300-5):1.20\r\n",
288 .support_trail
= '\xff',
292 {"fs-uboot", 0x00000, 0x20000},
293 {"partition-table", 0x20000, 0x02000},
294 {"default-mac", 0x30000, 0x00020},
295 {"product-info", 0x31100, 0x00100},
296 {"signature", 0x32000, 0x00400},
297 {"os-image", 0x40000, 0x1c0000},
298 {"file-system", 0x200000, 0x5b0000},
299 {"soft-version", 0x7b0000, 0x00100},
300 {"support-list", 0x7b1000, 0x00400},
301 {"user-config", 0x7c0000, 0x10000},
302 {"default-config", 0x7d0000, 0x10000},
303 {"log", 0x7e0000, 0x10000},
304 {"radio", 0x7f0000, 0x10000},
308 .first_sysupgrade_partition
= "os-image",
309 .last_sysupgrade_partition
= "support-list",
312 /** Firmware layout for the C2600 */
318 "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
319 .support_trail
= '\x00',
323 We use a bigger os-image partition than the stock images (and thus
324 smaller file-system), as our kernel doesn't fit in the stock firmware's
325 2 MB os-image since kernel 4.14.
328 {"SBL1", 0x00000, 0x20000},
329 {"MIBIB", 0x20000, 0x20000},
330 {"SBL2", 0x40000, 0x20000},
331 {"SBL3", 0x60000, 0x30000},
332 {"DDRCONFIG", 0x90000, 0x10000},
333 {"SSD", 0xa0000, 0x10000},
334 {"TZ", 0xb0000, 0x30000},
335 {"RPM", 0xe0000, 0x20000},
336 {"fs-uboot", 0x100000, 0x70000},
337 {"uboot-env", 0x170000, 0x40000},
338 {"radio", 0x1b0000, 0x40000},
339 {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
340 {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
341 {"default-mac", 0x1ef0000, 0x00200},
342 {"pin", 0x1ef0200, 0x00200},
343 {"product-info", 0x1ef0400, 0x0fc00},
344 {"partition-table", 0x1f00000, 0x10000},
345 {"soft-version", 0x1f10000, 0x10000},
346 {"support-list", 0x1f20000, 0x10000},
347 {"profile", 0x1f30000, 0x10000},
348 {"default-config", 0x1f40000, 0x10000},
349 {"user-config", 0x1f50000, 0x40000},
350 {"qos-db", 0x1f90000, 0x40000},
351 {"usb-config", 0x1fd0000, 0x10000},
352 {"log", 0x1fe0000, 0x20000},
356 .first_sysupgrade_partition
= "os-image",
357 .last_sysupgrade_partition
= "file-system"
360 /** Firmware layout for the C25v1 */
362 .id
= "ARCHER-C25-V1",
365 "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
366 "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
367 "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
368 .support_trail
= '\x00',
369 .soft_ver
= "soft_ver:1.0.0\n",
372 We use a bigger os-image partition than the stock images (and thus
373 smaller file-system), as our kernel doesn't fit in the stock firmware's
377 {"factory-boot", 0x00000, 0x20000},
378 {"fs-uboot", 0x20000, 0x10000},
379 {"os-image", 0x30000, 0x180000}, /* Stock: base 0x30000 size 0x100000 */
380 {"file-system", 0x1b0000, 0x620000}, /* Stock: base 0x130000 size 0x6a0000 */
381 {"user-config", 0x7d0000, 0x04000},
382 {"default-mac", 0x7e0000, 0x00100},
383 {"device-id", 0x7e0100, 0x00100},
384 {"extra-para", 0x7e0200, 0x00100},
385 {"pin", 0x7e0300, 0x00100},
386 {"support-list", 0x7e0400, 0x00400},
387 {"soft-version", 0x7e0800, 0x00400},
388 {"product-info", 0x7e0c00, 0x01400},
389 {"partition-table", 0x7e2000, 0x01000},
390 {"profile", 0x7e3000, 0x01000},
391 {"default-config", 0x7e4000, 0x04000},
392 {"merge-config", 0x7ec000, 0x02000},
393 {"qos-db", 0x7ee000, 0x02000},
394 {"radio", 0x7f0000, 0x10000},
398 .first_sysupgrade_partition
= "os-image",
399 .last_sysupgrade_partition
= "file-system",
402 /** Firmware layout for the C58v1 */
404 .id
= "ARCHER-C58-V1",
408 "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
409 "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
410 "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
411 .support_trail
= '\x00',
412 .soft_ver
= "soft_ver:1.0.0\n",
415 {"fs-uboot", 0x00000, 0x10000},
416 {"default-mac", 0x10000, 0x00200},
417 {"pin", 0x10200, 0x00200},
418 {"product-info", 0x10400, 0x00100},
419 {"partition-table", 0x10500, 0x00800},
420 {"soft-version", 0x11300, 0x00200},
421 {"support-list", 0x11500, 0x00100},
422 {"device-id", 0x11600, 0x00100},
423 {"profile", 0x11700, 0x03900},
424 {"default-config", 0x15000, 0x04000},
425 {"user-config", 0x19000, 0x04000},
426 {"os-image", 0x20000, 0x180000},
427 {"file-system", 0x1a0000, 0x648000},
428 {"certyficate", 0x7e8000, 0x08000},
429 {"radio", 0x7f0000, 0x10000},
433 .first_sysupgrade_partition
= "os-image",
434 .last_sysupgrade_partition
= "file-system",
437 /** Firmware layout for the C59v1 */
439 .id
= "ARCHER-C59-V1",
443 "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
444 "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
445 "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
446 "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
447 .support_trail
= '\x00',
448 .soft_ver
= "soft_ver:1.0.0\n",
451 {"fs-uboot", 0x00000, 0x10000},
452 {"default-mac", 0x10000, 0x00200},
453 {"pin", 0x10200, 0x00200},
454 {"device-id", 0x10400, 0x00100},
455 {"product-info", 0x10500, 0x0fb00},
456 {"os-image", 0x20000, 0x180000},
457 {"file-system", 0x1a0000, 0xcb0000},
458 {"partition-table", 0xe50000, 0x10000},
459 {"soft-version", 0xe60000, 0x10000},
460 {"support-list", 0xe70000, 0x10000},
461 {"profile", 0xe80000, 0x10000},
462 {"default-config", 0xe90000, 0x10000},
463 {"user-config", 0xea0000, 0x40000},
464 {"usb-config", 0xee0000, 0x10000},
465 {"certificate", 0xef0000, 0x10000},
466 {"qos-db", 0xf00000, 0x40000},
467 {"log", 0xfe0000, 0x10000},
468 {"radio", 0xff0000, 0x10000},
472 .first_sysupgrade_partition
= "os-image",
473 .last_sysupgrade_partition
= "file-system",
476 /** Firmware layout for the C59v2 */
478 .id
= "ARCHER-C59-V2",
482 "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
483 "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
484 "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
485 .support_trail
= '\x00',
486 .soft_ver
= "soft_ver:2.0.0 Build 20161206 rel.7303\n",
488 /** We're using a dynamic kernel/rootfs split here */
490 {"factory-boot", 0x00000, 0x20000},
491 {"fs-uboot", 0x20000, 0x10000},
492 {"default-mac", 0x30000, 0x00200},
493 {"pin", 0x30200, 0x00200},
494 {"device-id", 0x30400, 0x00100},
495 {"product-info", 0x30500, 0x0fb00},
496 {"firmware", 0x40000, 0xe10000},
497 {"partition-table", 0xe50000, 0x10000},
498 {"soft-version", 0xe60000, 0x10000},
499 {"support-list", 0xe70000, 0x10000},
500 {"profile", 0xe80000, 0x10000},
501 {"default-config", 0xe90000, 0x10000},
502 {"user-config", 0xea0000, 0x40000},
503 {"usb-config", 0xee0000, 0x10000},
504 {"certificate", 0xef0000, 0x10000},
505 {"extra-para", 0xf00000, 0x10000},
506 {"qos-db", 0xf10000, 0x30000},
507 {"log", 0xfe0000, 0x10000},
508 {"radio", 0xff0000, 0x10000},
512 .first_sysupgrade_partition
= "os-image",
513 .last_sysupgrade_partition
= "file-system",
516 /** Firmware layout for the C60v1 */
518 .id
= "ARCHER-C60-V1",
522 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
523 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
524 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
525 .support_trail
= '\x00',
526 .soft_ver
= "soft_ver:1.0.0\n",
529 {"fs-uboot", 0x00000, 0x10000},
530 {"default-mac", 0x10000, 0x00200},
531 {"pin", 0x10200, 0x00200},
532 {"product-info", 0x10400, 0x00100},
533 {"partition-table", 0x10500, 0x00800},
534 {"soft-version", 0x11300, 0x00200},
535 {"support-list", 0x11500, 0x00100},
536 {"device-id", 0x11600, 0x00100},
537 {"profile", 0x11700, 0x03900},
538 {"default-config", 0x15000, 0x04000},
539 {"user-config", 0x19000, 0x04000},
540 {"os-image", 0x20000, 0x180000},
541 {"file-system", 0x1a0000, 0x648000},
542 {"certyficate", 0x7e8000, 0x08000},
543 {"radio", 0x7f0000, 0x10000},
547 .first_sysupgrade_partition
= "os-image",
548 .last_sysupgrade_partition
= "file-system",
551 /** Firmware layout for the C60v2 */
553 .id
= "ARCHER-C60-V2",
557 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
558 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
559 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
560 .support_trail
= '\x00',
561 .soft_ver
= "soft_ver:2.0.0\n",
564 {"factory-boot", 0x00000, 0x1fb00},
565 {"default-mac", 0x1fb00, 0x00200},
566 {"pin", 0x1fd00, 0x00100},
567 {"product-info", 0x1fe00, 0x00100},
568 {"device-id", 0x1ff00, 0x00100},
569 {"fs-uboot", 0x20000, 0x10000},
570 {"os-image", 0x30000, 0x180000},
571 {"file-system", 0x1b0000, 0x620000},
572 {"soft-version", 0x7d9500, 0x00100},
573 {"support-list", 0x7d9600, 0x00100},
574 {"extra-para", 0x7d9700, 0x00100},
575 {"profile", 0x7d9800, 0x03000},
576 {"default-config", 0x7dc800, 0x03000},
577 {"partition-table", 0x7df800, 0x00800},
578 {"user-config", 0x7e0000, 0x0c000},
579 {"certificate", 0x7ec000, 0x04000},
580 {"radio", 0x7f0000, 0x10000},
584 .first_sysupgrade_partition
= "os-image",
585 .last_sysupgrade_partition
= "file-system",
588 /** Firmware layout for the C5 */
590 .id
= "ARCHER-C5-V2",
594 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
595 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
596 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
597 .support_trail
= '\x00',
601 {"fs-uboot", 0x00000, 0x40000},
602 {"os-image", 0x40000, 0x200000},
603 {"file-system", 0x240000, 0xc00000},
604 {"default-mac", 0xe40000, 0x00200},
605 {"pin", 0xe40200, 0x00200},
606 {"product-info", 0xe40400, 0x00200},
607 {"partition-table", 0xe50000, 0x10000},
608 {"soft-version", 0xe60000, 0x00200},
609 {"support-list", 0xe61000, 0x0f000},
610 {"profile", 0xe70000, 0x10000},
611 {"default-config", 0xe80000, 0x10000},
612 {"user-config", 0xe90000, 0x50000},
613 {"log", 0xee0000, 0x100000},
614 {"radio_bk", 0xfe0000, 0x10000},
615 {"radio", 0xff0000, 0x10000},
619 .first_sysupgrade_partition
= "os-image",
620 .last_sysupgrade_partition
= "file-system"
623 /** Firmware layout for the C7 */
625 .id
= "ARCHER-C7-V4",
628 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
629 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
630 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
631 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
632 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
633 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
634 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
635 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
636 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
637 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
638 .support_trail
= '\x00',
639 .soft_ver
= "soft_ver:1.0.0\n",
642 We use a bigger os-image partition than the stock images (and thus
643 smaller file-system), as our kernel doesn't fit in the stock firmware's
647 {"factory-boot", 0x00000, 0x20000},
648 {"fs-uboot", 0x20000, 0x20000},
649 {"os-image", 0x40000, 0x180000}, /* Stock: base 0x40000 size 0x120000 */
650 {"file-system", 0x1c0000, 0xd40000}, /* Stock: base 0x160000 size 0xda0000 */
651 {"default-mac", 0xf00000, 0x00200},
652 {"pin", 0xf00200, 0x00200},
653 {"device-id", 0xf00400, 0x00100},
654 {"product-info", 0xf00500, 0x0fb00},
655 {"soft-version", 0xf10000, 0x00100},
656 {"extra-para", 0xf11000, 0x01000},
657 {"support-list", 0xf12000, 0x0a000},
658 {"profile", 0xf1c000, 0x04000},
659 {"default-config", 0xf20000, 0x10000},
660 {"user-config", 0xf30000, 0x40000},
661 {"qos-db", 0xf70000, 0x40000},
662 {"certificate", 0xfb0000, 0x10000},
663 {"partition-table", 0xfc0000, 0x10000},
664 {"log", 0xfd0000, 0x20000},
665 {"radio", 0xff0000, 0x10000},
669 .first_sysupgrade_partition
= "os-image",
670 .last_sysupgrade_partition
= "file-system",
673 /** Firmware layout for the C7 v5*/
675 .id
= "ARCHER-C7-V5",
678 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
679 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n",
681 .support_trail
= '\x00',
682 .soft_ver
= "soft_ver:1.0.0\n",
685 We use a bigger os-image partition than the stock images (and thus
686 smaller file-system), as our kernel doesn't fit in the stock firmware's
690 {"factory-boot", 0x00000, 0x20000},
691 {"fs-uboot", 0x20000, 0x20000},
692 {"partition-table", 0x40000, 0x10000},
693 {"radio", 0x50000, 0x10000},
694 {"default-mac", 0x60000, 0x00200},
695 {"pin", 0x60200, 0x00200},
696 {"device-id", 0x60400, 0x00100},
697 {"product-info", 0x60500, 0x0fb00},
698 {"soft-version", 0x70000, 0x01000},
699 {"extra-para", 0x71000, 0x01000},
700 {"support-list", 0x72000, 0x0a000},
701 {"profile", 0x7c000, 0x04000},
702 {"user-config", 0x80000, 0x40000},
705 {"os-image", 0xc0000, 0x180000}, /* Stock: base 0xc0000 size 0x120000 */
706 {"file-system", 0x240000, 0xd80000}, /* Stock: base 0x1e0000 size 0xde0000 */
708 {"log", 0xfc0000, 0x20000},
709 {"certificate", 0xfe0000, 0x10000},
710 {"default-config", 0xff0000, 0x10000},
715 .first_sysupgrade_partition
= "os-image",
716 .last_sysupgrade_partition
= "file-system",
719 /** Firmware layout for the C9 */
725 "{product_name:ArcherC9,"
727 "special_id:00000000}\n",
728 .support_trail
= '\x00',
732 {"fs-uboot", 0x00000, 0x40000},
733 {"os-image", 0x40000, 0x200000},
734 {"file-system", 0x240000, 0xc00000},
735 {"default-mac", 0xe40000, 0x00200},
736 {"pin", 0xe40200, 0x00200},
737 {"product-info", 0xe40400, 0x00200},
738 {"partition-table", 0xe50000, 0x10000},
739 {"soft-version", 0xe60000, 0x00200},
740 {"support-list", 0xe61000, 0x0f000},
741 {"profile", 0xe70000, 0x10000},
742 {"default-config", 0xe80000, 0x10000},
743 {"user-config", 0xe90000, 0x50000},
744 {"log", 0xee0000, 0x100000},
745 {"radio_bk", 0xfe0000, 0x10000},
746 {"radio", 0xff0000, 0x10000},
750 .first_sysupgrade_partition
= "os-image",
751 .last_sysupgrade_partition
= "file-system"
754 /** Firmware layout for the EAP120 */
757 .vendor
= "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
760 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
761 .support_trail
= '\xff',
765 {"fs-uboot", 0x00000, 0x20000},
766 {"partition-table", 0x20000, 0x02000},
767 {"default-mac", 0x30000, 0x00020},
768 {"support-list", 0x31000, 0x00100},
769 {"product-info", 0x31100, 0x00100},
770 {"soft-version", 0x32000, 0x00100},
771 {"os-image", 0x40000, 0x180000},
772 {"file-system", 0x1c0000, 0x600000},
773 {"user-config", 0x7c0000, 0x10000},
774 {"backup-config", 0x7d0000, 0x10000},
775 {"log", 0x7e0000, 0x10000},
776 {"radio", 0x7f0000, 0x10000},
780 .first_sysupgrade_partition
= "os-image",
781 .last_sysupgrade_partition
= "file-system"
784 /** Firmware layout for the TL-WA850RE v2 */
790 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
791 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
792 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
793 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
794 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
795 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
796 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
797 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
798 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
799 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
800 .support_trail
= '\x00',
804 576KB were moved from file-system to os-image
805 in comparison to the stock image
808 {"fs-uboot", 0x00000, 0x20000},
809 {"os-image", 0x20000, 0x150000},
810 {"file-system", 0x170000, 0x240000},
811 {"partition-table", 0x3b0000, 0x02000},
812 {"default-mac", 0x3c0000, 0x00020},
813 {"pin", 0x3c0100, 0x00020},
814 {"product-info", 0x3c1000, 0x01000},
815 {"soft-version", 0x3c2000, 0x00100},
816 {"support-list", 0x3c3000, 0x01000},
817 {"profile", 0x3c4000, 0x08000},
818 {"user-config", 0x3d0000, 0x10000},
819 {"default-config", 0x3e0000, 0x10000},
820 {"radio", 0x3f0000, 0x10000},
824 .first_sysupgrade_partition
= "os-image",
825 .last_sysupgrade_partition
= "file-system"
828 /** Firmware layout for the TL-WA855RE v1 */
834 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
835 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
836 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
837 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
838 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
839 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
840 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
841 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
842 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
843 .support_trail
= '\x00',
847 {"fs-uboot", 0x00000, 0x20000},
848 {"os-image", 0x20000, 0x150000},
849 {"file-system", 0x170000, 0x240000},
850 {"partition-table", 0x3b0000, 0x02000},
851 {"default-mac", 0x3c0000, 0x00020},
852 {"pin", 0x3c0100, 0x00020},
853 {"product-info", 0x3c1000, 0x01000},
854 {"soft-version", 0x3c2000, 0x00100},
855 {"support-list", 0x3c3000, 0x01000},
856 {"profile", 0x3c4000, 0x08000},
857 {"user-config", 0x3d0000, 0x10000},
858 {"default-config", 0x3e0000, 0x10000},
859 {"radio", 0x3f0000, 0x10000},
863 .first_sysupgrade_partition
= "os-image",
864 .last_sysupgrade_partition
= "file-system"
867 /** Firmware layout for the TL-WR1043 v5 */
873 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
874 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
875 .support_trail
= '\x00',
876 .soft_ver
= "soft_ver:1.0.0\n",
878 {"factory-boot", 0x00000, 0x20000},
879 {"fs-uboot", 0x20000, 0x20000},
880 {"os-image", 0x40000, 0x180000},
881 {"file-system", 0x1c0000, 0xd40000},
882 {"default-mac", 0xf00000, 0x00200},
883 {"pin", 0xf00200, 0x00200},
884 {"device-id", 0xf00400, 0x00100},
885 {"product-info", 0xf00500, 0x0fb00},
886 {"soft-version", 0xf10000, 0x01000},
887 {"extra-para", 0xf11000, 0x01000},
888 {"support-list", 0xf12000, 0x0a000},
889 {"profile", 0xf1c000, 0x04000},
890 {"default-config", 0xf20000, 0x10000},
891 {"user-config", 0xf30000, 0x40000},
892 {"qos-db", 0xf70000, 0x40000},
893 {"certificate", 0xfb0000, 0x10000},
894 {"partition-table", 0xfc0000, 0x10000},
895 {"log", 0xfd0000, 0x20000},
896 {"radio", 0xff0000, 0x10000},
899 .first_sysupgrade_partition
= "os-image",
900 .last_sysupgrade_partition
= "file-system"
903 /** Firmware layout for the TL-WR1043 v4 */
905 .id
= "TLWR1043NDV4",
909 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
910 .support_trail
= '\x00',
913 /* We're using a dynamic kernel/rootfs split here */
915 {"fs-uboot", 0x00000, 0x20000},
916 {"firmware", 0x20000, 0xf30000},
917 {"default-mac", 0xf50000, 0x00200},
918 {"pin", 0xf50200, 0x00200},
919 {"product-info", 0xf50400, 0x0fc00},
920 {"soft-version", 0xf60000, 0x0b000},
921 {"support-list", 0xf6b000, 0x04000},
922 {"profile", 0xf70000, 0x04000},
923 {"default-config", 0xf74000, 0x0b000},
924 {"user-config", 0xf80000, 0x40000},
925 {"partition-table", 0xfc0000, 0x10000},
926 {"log", 0xfd0000, 0x20000},
927 {"radio", 0xff0000, 0x10000},
931 .first_sysupgrade_partition
= "os-image",
932 .last_sysupgrade_partition
= "file-system"
935 /** Firmware layout for the TL-WR902AC v1 */
937 .id
= "TL-WR902AC-V1",
941 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
942 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
943 .support_trail
= '\x00',
947 384KB were moved from file-system to os-image
948 in comparison to the stock image
951 {"fs-uboot", 0x00000, 0x20000},
952 {"os-image", 0x20000, 0x180000},
953 {"file-system", 0x1a0000, 0x5b0000},
954 {"default-mac", 0x750000, 0x00200},
955 {"pin", 0x750200, 0x00200},
956 {"product-info", 0x750400, 0x0fc00},
957 {"soft-version", 0x760000, 0x0b000},
958 {"support-list", 0x76b000, 0x04000},
959 {"profile", 0x770000, 0x04000},
960 {"default-config", 0x774000, 0x0b000},
961 {"user-config", 0x780000, 0x40000},
962 {"partition-table", 0x7c0000, 0x10000},
963 {"log", 0x7d0000, 0x20000},
964 {"radio", 0x7f0000, 0x10000},
968 .first_sysupgrade_partition
= "os-image",
969 .last_sysupgrade_partition
= "file-system",
972 /** Firmware layout for the TL-WR942N V1 */
978 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
979 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
980 .support_trail
= '\x00',
984 {"fs-uboot", 0x00000, 0x20000},
985 {"os-image", 0x20000, 0x180000},
986 {"file-system", 0x1a0000, 0xca0000},
987 {"default-mac", 0xe40000, 0x00200},
988 {"pin", 0xe40200, 0x00200},
989 {"product-info", 0xe40400, 0x0fc00},
990 {"partition-table", 0xe50000, 0x10000},
991 {"soft-version", 0xe60000, 0x10000},
992 {"support-list", 0xe70000, 0x10000},
993 {"profile", 0xe80000, 0x10000},
994 {"default-config", 0xe90000, 0x10000},
995 {"user-config", 0xea0000, 0x40000},
996 {"qos-db", 0xee0000, 0x40000},
997 {"certificate", 0xf20000, 0x10000},
998 {"usb-config", 0xfb0000, 0x10000},
999 {"log", 0xfc0000, 0x20000},
1000 {"radio-bk", 0xfe0000, 0x10000},
1001 {"radio", 0xff0000, 0x10000},
1005 .first_sysupgrade_partition
= "os-image",
1006 .last_sysupgrade_partition
= "file-system",
1009 /** Firmware layout for the RE350 v1 */
1015 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
1016 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
1017 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
1018 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
1019 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
1020 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
1021 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
1022 .support_trail
= '\x00',
1025 /** We're using a dynamic kernel/rootfs split here */
1027 {"fs-uboot", 0x00000, 0x20000},
1028 {"firmware", 0x20000, 0x5e0000},
1029 {"partition-table", 0x600000, 0x02000},
1030 {"default-mac", 0x610000, 0x00020},
1031 {"pin", 0x610100, 0x00020},
1032 {"product-info", 0x611100, 0x01000},
1033 {"soft-version", 0x620000, 0x01000},
1034 {"support-list", 0x621000, 0x01000},
1035 {"profile", 0x622000, 0x08000},
1036 {"user-config", 0x630000, 0x10000},
1037 {"default-config", 0x640000, 0x10000},
1038 {"radio", 0x7f0000, 0x10000},
1042 .first_sysupgrade_partition
= "os-image",
1043 .last_sysupgrade_partition
= "file-system"
1046 /** Firmware layout for the RE355 */
1052 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
1053 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
1054 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
1055 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
1056 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
1057 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
1058 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
1059 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
1060 .support_trail
= '\x00',
1064 The flash partition table for RE355;
1065 it is almost the same as the one used by the stock images,
1066 576KB were moved from file-system to os-image.
1069 {"fs-uboot", 0x00000, 0x20000},
1070 {"os-image", 0x20000, 0x180000},
1071 {"file-system", 0x1a0000, 0x460000},
1072 {"partition-table", 0x600000, 0x02000},
1073 {"default-mac", 0x610000, 0x00020},
1074 {"pin", 0x610100, 0x00020},
1075 {"product-info", 0x611100, 0x01000},
1076 {"soft-version", 0x620000, 0x01000},
1077 {"support-list", 0x621000, 0x01000},
1078 {"profile", 0x622000, 0x08000},
1079 {"user-config", 0x630000, 0x10000},
1080 {"default-config", 0x640000, 0x10000},
1081 {"radio", 0x7f0000, 0x10000},
1085 .first_sysupgrade_partition
= "os-image",
1086 .last_sysupgrade_partition
= "file-system"
1089 /** Firmware layout for the RE450 */
1095 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
1096 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
1097 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
1098 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
1099 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
1100 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
1101 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
1102 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
1103 .support_trail
= '\x00',
1107 The flash partition table for RE450;
1108 it is almost the same as the one used by the stock images,
1109 576KB were moved from file-system to os-image.
1112 {"fs-uboot", 0x00000, 0x20000},
1113 {"os-image", 0x20000, 0x180000},
1114 {"file-system", 0x1a0000, 0x460000},
1115 {"partition-table", 0x600000, 0x02000},
1116 {"default-mac", 0x610000, 0x00020},
1117 {"pin", 0x610100, 0x00020},
1118 {"product-info", 0x611100, 0x01000},
1119 {"soft-version", 0x620000, 0x01000},
1120 {"support-list", 0x621000, 0x01000},
1121 {"profile", 0x622000, 0x08000},
1122 {"user-config", 0x630000, 0x10000},
1123 {"default-config", 0x640000, 0x10000},
1124 {"radio", 0x7f0000, 0x10000},
1128 .first_sysupgrade_partition
= "os-image",
1129 .last_sysupgrade_partition
= "file-system"
1132 /** Firmware layout for the RE450 v2 */
1138 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
1139 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
1140 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
1141 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
1142 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
1143 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
1144 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
1145 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
1146 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
1147 .support_trail
= '\x00',
1150 /* We're using a dynamic kernel/rootfs split here */
1152 {"fs-uboot", 0x00000, 0x20000},
1153 {"firmware", 0x20000, 0x5e0000},
1154 {"partition-table", 0x600000, 0x02000},
1155 {"default-mac", 0x610000, 0x00020},
1156 {"pin", 0x610100, 0x00020},
1157 {"product-info", 0x611100, 0x01000},
1158 {"soft-version", 0x620000, 0x01000},
1159 {"support-list", 0x621000, 0x01000},
1160 {"profile", 0x622000, 0x08000},
1161 {"user-config", 0x630000, 0x10000},
1162 {"default-config", 0x640000, 0x10000},
1163 {"radio", 0x7f0000, 0x10000},
1168 .first_sysupgrade_partition
= "os-image",
1169 .last_sysupgrade_partition
= "file-system"
1175 #define error(_ret, _errno, _str, ...) \
1177 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
1178 strerror(_errno)); \
1184 /** Stores a uint32 as big endian */
1185 static inline void put32(uint8_t *buf
, uint32_t val
) {
1192 /** Allocates a new image partition */
1193 static struct image_partition_entry
alloc_image_partition(const char *name
, size_t len
) {
1194 struct image_partition_entry entry
= {name
, len
, malloc(len
)};
1196 error(1, errno
, "malloc");
1201 /** Frees an image partition */
1202 static void free_image_partition(struct image_partition_entry entry
) {
1206 static time_t source_date_epoch
= -1;
1207 static void set_source_date_epoch() {
1208 char *env
= getenv("SOURCE_DATE_EPOCH");
1212 source_date_epoch
= strtoull(env
, &endptr
, 10);
1213 if (errno
|| (endptr
&& *endptr
!= '\0')) {
1214 fprintf(stderr
, "Invalid SOURCE_DATE_EPOCH");
1220 /** Generates the partition-table partition */
1221 static struct image_partition_entry
make_partition_table(const struct flash_partition_entry
*p
) {
1222 struct image_partition_entry entry
= alloc_image_partition("partition-table", 0x800);
1224 char *s
= (char *)entry
.data
, *end
= (char *)(s
+entry
.size
);
1232 for (i
= 0; p
[i
].name
; i
++) {
1234 size_t w
= snprintf(s
, len
, "partition %s base 0x%05x size 0x%05x\n", p
[i
].name
, p
[i
].base
, p
[i
].size
);
1237 error(1, 0, "flash partition table overflow?");
1244 memset(s
, 0xff, end
-s
);
1250 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
1251 static inline uint8_t bcd(uint8_t v
) {
1252 return 0x10 * (v
/10) + v
%10;
1256 /** Generates the soft-version partition */
1257 static struct image_partition_entry
make_soft_version(uint32_t rev
) {
1258 struct image_partition_entry entry
= alloc_image_partition("soft-version", sizeof(struct soft_version
));
1259 struct soft_version
*s
= (struct soft_version
*)entry
.data
;
1263 if (source_date_epoch
!= -1)
1264 t
= source_date_epoch
;
1265 else if (time(&t
) == (time_t)(-1))
1266 error(1, errno
, "time");
1268 struct tm
*tm
= localtime(&t
);
1270 s
->magic
= htonl(0x0000000c);
1274 s
->version_major
= 0;
1275 s
->version_minor
= 0;
1276 s
->version_patch
= 0;
1278 s
->year_hi
= bcd((1900+tm
->tm_year
)/100);
1279 s
->year_lo
= bcd(tm
->tm_year
%100);
1280 s
->month
= bcd(tm
->tm_mon
+1);
1281 s
->day
= bcd(tm
->tm_mday
);
1282 s
->rev
= htonl(rev
);
1289 static struct image_partition_entry
make_soft_version_from_string(const char *soft_ver
) {
1290 /** String length _including_ the terminating zero byte */
1291 uint32_t ver_len
= strlen(soft_ver
) + 1;
1292 /** Partition contains 64 bit header, the version string, and one additional null byte */
1293 size_t partition_len
= 2*sizeof(uint32_t) + ver_len
+ 1;
1294 struct image_partition_entry entry
= alloc_image_partition("soft-version", partition_len
);
1296 uint32_t *len
= (uint32_t *)entry
.data
;
1297 len
[0] = htonl(ver_len
);
1299 memcpy(&len
[2], soft_ver
, ver_len
);
1301 entry
.data
[partition_len
- 1] = 0;
1306 /** Generates the support-list partition */
1307 static struct image_partition_entry
make_support_list(struct device_info
*info
) {
1308 size_t len
= strlen(info
->support_list
);
1309 struct image_partition_entry entry
= alloc_image_partition("support-list", len
+ 9);
1311 put32(entry
.data
, len
);
1312 memset(entry
.data
+4, 0, 4);
1313 memcpy(entry
.data
+8, info
->support_list
, len
);
1314 entry
.data
[len
+8] = info
->support_trail
;
1319 /** Creates a new image partition with an arbitrary name from a file */
1320 static struct image_partition_entry
read_file(const char *part_name
, const char *filename
, bool add_jffs2_eof
, struct flash_partition_entry
*file_system_partition
) {
1321 struct stat statbuf
;
1323 if (stat(filename
, &statbuf
) < 0)
1324 error(1, errno
, "unable to stat file `%s'", filename
);
1326 size_t len
= statbuf
.st_size
;
1329 if (file_system_partition
)
1330 len
= ALIGN(len
+ file_system_partition
->base
, 0x10000) + sizeof(jffs2_eof_mark
) - file_system_partition
->base
;
1332 len
= ALIGN(len
, 0x10000) + sizeof(jffs2_eof_mark
);
1334 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
1336 FILE *file
= fopen(filename
, "rb");
1338 error(1, errno
, "unable to open file `%s'", filename
);
1340 if (fread(entry
.data
, statbuf
.st_size
, 1, file
) != 1)
1341 error(1, errno
, "unable to read file `%s'", filename
);
1343 if (add_jffs2_eof
) {
1344 uint8_t *eof
= entry
.data
+ statbuf
.st_size
, *end
= entry
.data
+entry
.size
;
1346 memset(eof
, 0xff, end
- eof
- sizeof(jffs2_eof_mark
));
1347 memcpy(end
- sizeof(jffs2_eof_mark
), jffs2_eof_mark
, sizeof(jffs2_eof_mark
));
1355 /** Creates a new image partition from arbitrary data */
1356 static struct image_partition_entry
put_data(const char *part_name
, const char *datain
, size_t len
) {
1358 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
1360 memcpy(entry
.data
, datain
, len
);
1366 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
1368 Example image partition table:
1370 fwup-ptn partition-table base 0x00800 size 0x00800
1371 fwup-ptn os-image base 0x01000 size 0x113b45
1372 fwup-ptn file-system base 0x114b45 size 0x1d0004
1373 fwup-ptn support-list base 0x2e4b49 size 0x000d1
1375 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
1376 the end of the partition table is marked with a zero byte.
1378 The firmware image must contain at least the partition-table and support-list partitions
1379 to be accepted. There aren't any alignment constraints for the image partitions.
1381 The partition-table partition contains the actual flash layout; partitions
1382 from the image partition table are mapped to the corresponding flash partitions during
1383 the firmware upgrade. The support-list partition contains a list of devices supported by
1386 The base offsets in the firmware partition table are relative to the end
1387 of the vendor information block, so the partition-table partition will
1388 actually start at offset 0x1814 of the image.
1390 I think partition-table must be the first partition in the firmware image.
1392 static void put_partitions(uint8_t *buffer
, const struct flash_partition_entry
*flash_parts
, const struct image_partition_entry
*parts
) {
1394 char *image_pt
= (char *)buffer
, *end
= image_pt
+ 0x800;
1396 size_t base
= 0x800;
1397 for (i
= 0; parts
[i
].name
; i
++) {
1398 for (j
= 0; flash_parts
[j
].name
; j
++) {
1399 if (!strcmp(flash_parts
[j
].name
, parts
[i
].name
)) {
1400 if (parts
[i
].size
> flash_parts
[j
].size
)
1401 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts
[j
].name
, (unsigned)flash_parts
[j
].size
);
1406 assert(flash_parts
[j
].name
);
1408 memcpy(buffer
+ base
, parts
[i
].data
, parts
[i
].size
);
1410 size_t len
= end
-image_pt
;
1411 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
);
1414 error(1, 0, "image partition table overflow?");
1418 base
+= parts
[i
].size
;
1422 /** Generates and writes the image MD5 checksum */
1423 static void put_md5(uint8_t *md5
, uint8_t *buffer
, unsigned int len
) {
1427 MD5_Update(&ctx
, md5_salt
, (unsigned int)sizeof(md5_salt
));
1428 MD5_Update(&ctx
, buffer
, len
);
1429 MD5_Final(md5
, &ctx
);
1434 Generates the firmware image in factory format
1440 0000-0003 Image size (4 bytes, big endian)
1441 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
1442 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
1443 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
1444 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
1445 1014-1813 Image partition table (2048 bytes, padded with 0xff)
1446 1814-xxxx Firmware partitions
1448 static void * generate_factory_image(struct device_info
*info
, const struct image_partition_entry
*parts
, size_t *len
) {
1452 for (i
= 0; parts
[i
].name
; i
++)
1453 *len
+= parts
[i
].size
;
1455 uint8_t *image
= malloc(*len
);
1457 error(1, errno
, "malloc");
1459 memset(image
, 0xff, *len
);
1463 size_t vendor_len
= strlen(info
->vendor
);
1464 put32(image
+0x14, vendor_len
);
1465 memcpy(image
+0x18, info
->vendor
, vendor_len
);
1468 put_partitions(image
+ 0x1014, info
->partitions
, parts
);
1469 put_md5(image
+0x04, image
+0x14, *len
-0x14);
1475 Generates the firmware image in sysupgrade format
1477 This makes some assumptions about the provided flash and image partition tables and
1478 should be generalized when TP-LINK starts building its safeloader into hardware with
1479 different flash layouts.
1481 static void * generate_sysupgrade_image(struct device_info
*info
, const struct image_partition_entry
*image_parts
, size_t *len
) {
1483 size_t flash_first_partition_index
= 0;
1484 size_t flash_last_partition_index
= 0;
1485 const struct flash_partition_entry
*flash_first_partition
= NULL
;
1486 const struct flash_partition_entry
*flash_last_partition
= NULL
;
1487 const struct image_partition_entry
*image_last_partition
= NULL
;
1489 /** Find first and last partitions */
1490 for (i
= 0; info
->partitions
[i
].name
; i
++) {
1491 if (!strcmp(info
->partitions
[i
].name
, info
->first_sysupgrade_partition
)) {
1492 flash_first_partition
= &info
->partitions
[i
];
1493 flash_first_partition_index
= i
;
1494 } else if (!strcmp(info
->partitions
[i
].name
, info
->last_sysupgrade_partition
)) {
1495 flash_last_partition
= &info
->partitions
[i
];
1496 flash_last_partition_index
= i
;
1500 assert(flash_first_partition
&& flash_last_partition
);
1501 assert(flash_first_partition_index
< flash_last_partition_index
);
1503 /** Find last partition from image to calculate needed size */
1504 for (i
= 0; image_parts
[i
].name
; i
++) {
1505 if (!strcmp(image_parts
[i
].name
, info
->last_sysupgrade_partition
)) {
1506 image_last_partition
= &image_parts
[i
];
1511 assert(image_last_partition
);
1513 *len
= flash_last_partition
->base
- flash_first_partition
->base
+ image_last_partition
->size
;
1515 uint8_t *image
= malloc(*len
);
1517 error(1, errno
, "malloc");
1519 memset(image
, 0xff, *len
);
1521 for (i
= flash_first_partition_index
; i
<= flash_last_partition_index
; i
++) {
1522 for (j
= 0; image_parts
[j
].name
; j
++) {
1523 if (!strcmp(info
->partitions
[i
].name
, image_parts
[j
].name
)) {
1524 if (image_parts
[j
].size
> info
->partitions
[i
].size
)
1525 error(1, 0, "%s partition too big (more than %u bytes)", info
->partitions
[i
].name
, (unsigned)info
->partitions
[i
].size
);
1526 memcpy(image
+ info
->partitions
[i
].base
- flash_first_partition
->base
, image_parts
[j
].data
, image_parts
[j
].size
);
1530 assert(image_parts
[j
].name
);
1537 /** Generates an image according to a given layout and writes it to a file */
1538 static void build_image(const char *output
,
1539 const char *kernel_image
,
1540 const char *rootfs_image
,
1544 struct device_info
*info
) {
1548 struct image_partition_entry parts
[7] = {};
1550 struct flash_partition_entry
*firmware_partition
= NULL
;
1551 struct flash_partition_entry
*os_image_partition
= NULL
;
1552 struct flash_partition_entry
*file_system_partition
= NULL
;
1553 size_t firmware_partition_index
= 0;
1555 for (i
= 0; info
->partitions
[i
].name
; i
++) {
1556 if (!strcmp(info
->partitions
[i
].name
, "firmware"))
1558 firmware_partition
= &info
->partitions
[i
];
1559 firmware_partition_index
= i
;
1563 if (firmware_partition
)
1565 os_image_partition
= &info
->partitions
[firmware_partition_index
];
1566 file_system_partition
= &info
->partitions
[firmware_partition_index
+ 1];
1569 if (stat(kernel_image
, &kernel
) < 0)
1570 error(1, errno
, "unable to stat file `%s'", kernel_image
);
1572 if (kernel
.st_size
> firmware_partition
->size
)
1573 error(1, 0, "kernel overflowed firmware partition\n");
1575 for (i
= MAX_PARTITIONS
-1; i
>= firmware_partition_index
+ 1; i
--)
1576 info
->partitions
[i
+1] = info
->partitions
[i
];
1578 file_system_partition
->name
= "file-system";
1579 file_system_partition
->base
= firmware_partition
->base
+ kernel
.st_size
;
1581 /* Align partition start to erase blocks for factory images only */
1583 file_system_partition
->base
= ALIGN(firmware_partition
->base
+ kernel
.st_size
, 0x10000);
1585 file_system_partition
->size
= firmware_partition
->size
- file_system_partition
->base
;
1587 os_image_partition
->name
= "os-image";
1588 os_image_partition
->size
= kernel
.st_size
;
1591 parts
[0] = make_partition_table(info
->partitions
);
1593 parts
[1] = make_soft_version_from_string(info
->soft_ver
);
1595 parts
[1] = make_soft_version(rev
);
1597 parts
[2] = make_support_list(info
);
1598 parts
[3] = read_file("os-image", kernel_image
, false, NULL
);
1599 parts
[4] = read_file("file-system", rootfs_image
, add_jffs2_eof
, file_system_partition
);
1601 /* Some devices need the extra-para partition to accept the firmware */
1602 if (strcasecmp(info
->id
, "ARCHER-C25-V1") == 0 ||
1603 strcasecmp(info
->id
, "ARCHER-C59-V2") == 0 ||
1604 strcasecmp(info
->id
, "ARCHER-C60-V2") == 0 ||
1605 strcasecmp(info
->id
, "TLWR1043NV5") == 0) {
1606 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
1607 parts
[5] = put_data("extra-para", mdat
, 11);
1608 } else if (strcasecmp(info
->id
, "ARCHER-C7-V4") == 0 || strcasecmp(info
->id
, "ARCHER-C7-V5") == 0) {
1609 const char mdat
[11] = {0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x01, 0x00, 0x00};
1610 parts
[5] = put_data("extra-para", mdat
, 11);
1616 image
= generate_sysupgrade_image(info
, parts
, &len
);
1618 image
= generate_factory_image(info
, parts
, &len
);
1620 FILE *file
= fopen(output
, "wb");
1622 error(1, errno
, "unable to open output file");
1624 if (fwrite(image
, len
, 1, file
) != 1)
1625 error(1, 0, "unable to write output file");
1631 for (i
= 0; parts
[i
].name
; i
++)
1632 free_image_partition(parts
[i
]);
1636 static void usage(const char *argv0
) {
1638 "Usage: %s [OPTIONS...]\n"
1641 " -h show this help\n"
1643 "Create a new image:\n"
1644 " -B <board> create image for the board specified with <board>\n"
1645 " -k <file> read kernel image from the file <file>\n"
1646 " -r <file> read rootfs image from the file <file>\n"
1647 " -o <file> write output to the file <file>\n"
1648 " -V <rev> sets the revision number to <rev>\n"
1649 " -j add jffs2 end-of-filesystem markers\n"
1650 " -S create sysupgrade instead of factory image\n"
1651 "Extract an old image:\n"
1652 " -x <file> extract all oem firmware partition\n"
1653 " -d <dir> destination to extract the firmware partition\n"
1654 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
1660 static struct device_info
*find_board(const char *id
)
1662 struct device_info
*board
= NULL
;
1664 for (board
= boards
; board
->id
!= NULL
; board
++)
1665 if (strcasecmp(id
, board
->id
) == 0)
1671 static int add_flash_partition(
1672 struct flash_partition_entry
*part_list
,
1679 /* check if the list has a free entry */
1680 for (ptr
= 0; ptr
< max_entries
; ptr
++, part_list
++) {
1681 if (part_list
->name
== NULL
&&
1682 part_list
->base
== 0 &&
1683 part_list
->size
== 0)
1687 if (ptr
== max_entries
) {
1688 error(1, 0, "No free flash part entry available.");
1691 part_list
->name
= calloc(1, strlen(name
) + 1);
1692 if (!part_list
->name
) {
1693 error(1, 0, "Unable to allocate memory");
1696 memcpy((char *)part_list
->name
, name
, strlen(name
));
1697 part_list
->base
= base
;
1698 part_list
->size
= size
;
1703 /** read the partition table into struct flash_partition_entry */
1704 static int read_partition_table(
1705 FILE *file
, long offset
,
1706 struct flash_partition_entry
*entries
, size_t max_entries
,
1711 const char *parthdr
= NULL
;
1712 const char *fwuphdr
= "fwup-ptn";
1713 const char *flashhdr
= "partition";
1715 /* TODO: search for the partition table */
1725 error(1, 0, "Invalid partition table");
1728 if (fseek(file
, offset
, SEEK_SET
) < 0)
1729 error(1, errno
, "Can not seek in the firmware");
1731 if (fread(buf
, 1, 2048, file
) < 0)
1732 error(1, errno
, "Can not read fwup-ptn from the firmware");
1736 /* look for the partition header */
1737 if (memcmp(buf
, parthdr
, strlen(parthdr
)) != 0) {
1738 fprintf(stderr
, "DEBUG: can not find fwuphdr\n");
1743 end
= buf
+ sizeof(buf
);
1744 while ((ptr
+ strlen(parthdr
)) < end
&&
1745 memcmp(ptr
, parthdr
, strlen(parthdr
)) == 0) {
1749 char name
[32] = { 0 };
1751 unsigned long base
= 0;
1752 unsigned long size
= 0;
1754 end_part
= memchr(ptr
, '\n', (end
- ptr
));
1755 if (end_part
== NULL
) {
1756 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
1760 for (int i
= 0; i
<= 4; i
++) {
1761 if (end_part
<= ptr
)
1764 end_element
= memchr(ptr
, 0x20, (end_part
- ptr
));
1765 if (end_element
== NULL
) {
1766 error(1, errno
, "Ignoring the rest of the partition entries.");
1771 /* partition header */
1773 ptr
= end_element
+ 1;
1777 name_len
= (end_element
- ptr
) > 31 ? 31 : (end_element
- ptr
);
1778 strncpy(name
, ptr
, name_len
);
1779 name
[name_len
] = '\0';
1780 ptr
= end_element
+ 1;
1785 ptr
= end_element
+ 1;
1790 base
= strtoul(ptr
, NULL
, 16);
1791 ptr
= end_element
+ 1;
1796 ptr
= end_element
+ 1;
1797 /* actual size. The last element doesn't have a sepeartor */
1798 size
= strtoul(ptr
, NULL
, 16);
1799 /* the part ends with 0x09, 0x0d, 0x0a */
1801 add_flash_partition(entries
, max_entries
, name
, base
, size
);
1810 static void write_partition(
1812 size_t firmware_offset
,
1813 struct flash_partition_entry
*entry
,
1819 fseek(input_file
, entry
->base
+ firmware_offset
, SEEK_SET
);
1821 for (offset
= 0; sizeof(buf
) + offset
<= entry
->size
; offset
+= sizeof(buf
)) {
1822 if (fread(buf
, sizeof(buf
), 1, input_file
) < 0)
1823 error(1, errno
, "Can not read partition from input_file");
1825 if (fwrite(buf
, sizeof(buf
), 1, output_file
) < 0)
1826 error(1, errno
, "Can not write partition to output_file");
1828 /* write last chunk smaller than buffer */
1829 if (offset
< entry
->size
) {
1830 offset
= entry
->size
- offset
;
1831 if (fread(buf
, offset
, 1, input_file
) < 0)
1832 error(1, errno
, "Can not read partition from input_file");
1833 if (fwrite(buf
, offset
, 1, output_file
) < 0)
1834 error(1, errno
, "Can not write partition to output_file");
1838 static int extract_firmware_partition(FILE *input_file
, size_t firmware_offset
, struct flash_partition_entry
*entry
, const char *output_directory
)
1841 char output
[PATH_MAX
];
1843 snprintf(output
, PATH_MAX
, "%s/%s", output_directory
, entry
->name
);
1844 output_file
= fopen(output
, "wb+");
1845 if (output_file
== NULL
) {
1846 error(1, errno
, "Can not open output file %s", output
);
1849 write_partition(input_file
, firmware_offset
, entry
, output_file
);
1851 fclose(output_file
);
1856 /** extract all partitions from the firmware file */
1857 static int extract_firmware(const char *input
, const char *output_directory
)
1859 struct flash_partition_entry entries
[16] = { 0 };
1860 size_t max_entries
= 16;
1861 size_t firmware_offset
= 0x1014;
1864 struct stat statbuf
;
1866 /* check input file */
1867 if (stat(input
, &statbuf
)) {
1868 error(1, errno
, "Can not read input firmware %s", input
);
1871 /* check if output directory exists */
1872 if (stat(output_directory
, &statbuf
)) {
1873 error(1, errno
, "Failed to stat output directory %s", output_directory
);
1876 if ((statbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
1877 error(1, errno
, "Given output directory is not a directory %s", output_directory
);
1880 input_file
= fopen(input
, "rb");
1882 if (read_partition_table(input_file
, firmware_offset
, entries
, 16, 0) != 0) {
1883 error(1, 0, "Error can not read the partition table (fwup-ptn)");
1886 for (int i
= 0; i
< max_entries
; i
++) {
1887 if (entries
[i
].name
== NULL
&&
1888 entries
[i
].base
== 0 &&
1889 entries
[i
].size
== 0)
1892 extract_firmware_partition(input_file
, firmware_offset
, &entries
[i
], output_directory
);
1898 static struct flash_partition_entry
*find_partition(
1899 struct flash_partition_entry
*entries
, size_t max_entries
,
1900 const char *name
, const char *error_msg
)
1902 for (int i
= 0; i
< max_entries
; i
++, entries
++) {
1903 if (strcmp(entries
->name
, name
) == 0)
1907 error(1, 0, "%s", error_msg
);
1911 static void write_ff(FILE *output_file
, size_t size
)
1916 memset(buf
, 0xff, sizeof(buf
));
1918 for (offset
= 0; offset
+ sizeof(buf
) < size
; offset
+= sizeof(buf
)) {
1919 if (fwrite(buf
, sizeof(buf
), 1, output_file
) < 0)
1920 error(1, errno
, "Can not write 0xff to output_file");
1923 /* write last chunk smaller than buffer */
1924 if (offset
< size
) {
1925 offset
= size
- offset
;
1926 if (fwrite(buf
, offset
, 1, output_file
) < 0)
1927 error(1, errno
, "Can not write partition to output_file");
1931 static void convert_firmware(const char *input
, const char *output
)
1933 struct flash_partition_entry fwup
[MAX_PARTITIONS
] = { 0 };
1934 struct flash_partition_entry flash
[MAX_PARTITIONS
] = { 0 };
1935 struct flash_partition_entry
*fwup_os_image
= NULL
, *fwup_file_system
= NULL
;
1936 struct flash_partition_entry
*flash_os_image
= NULL
, *flash_file_system
= NULL
;
1937 struct flash_partition_entry
*fwup_partition_table
= NULL
;
1938 size_t firmware_offset
= 0x1014;
1939 FILE *input_file
, *output_file
;
1941 struct stat statbuf
;
1943 /* check input file */
1944 if (stat(input
, &statbuf
)) {
1945 error(1, errno
, "Can not read input firmware %s", input
);
1948 input_file
= fopen(input
, "rb");
1950 error(1, 0, "Can not open input firmware %s", input
);
1952 output_file
= fopen(output
, "wb");
1954 error(1, 0, "Can not open output firmware %s", output
);
1956 if (read_partition_table(input_file
, firmware_offset
, fwup
, MAX_PARTITIONS
, 0) != 0) {
1957 error(1, 0, "Error can not read the partition table (fwup-ptn)");
1960 fwup_os_image
= find_partition(fwup
, MAX_PARTITIONS
,
1961 "os-image", "Error can not find os-image partition (fwup)");
1962 fwup_file_system
= find_partition(fwup
, MAX_PARTITIONS
,
1963 "file-system", "Error can not find file-system partition (fwup)");
1964 fwup_partition_table
= find_partition(fwup
, MAX_PARTITIONS
,
1965 "partition-table", "Error can not find partition-table partition");
1967 /* the flash partition table has a 0x00000004 magic haeder */
1968 if (read_partition_table(input_file
, firmware_offset
+ fwup_partition_table
->base
+ 4, flash
, MAX_PARTITIONS
, 1) != 0)
1969 error(1, 0, "Error can not read the partition table (flash)");
1971 flash_os_image
= find_partition(flash
, MAX_PARTITIONS
,
1972 "os-image", "Error can not find os-image partition (flash)");
1973 flash_file_system
= find_partition(flash
, MAX_PARTITIONS
,
1974 "file-system", "Error can not find file-system partition (flash)");
1976 /* write os_image to 0x0 */
1977 write_partition(input_file
, firmware_offset
, fwup_os_image
, output_file
);
1978 write_ff(output_file
, flash_os_image
->size
- fwup_os_image
->size
);
1980 /* write file-system behind os_image */
1981 fseek(output_file
, flash_file_system
->base
- flash_os_image
->base
, SEEK_SET
);
1982 write_partition(input_file
, firmware_offset
, fwup_file_system
, output_file
);
1983 write_ff(output_file
, flash_file_system
->size
- fwup_file_system
->size
);
1985 fclose(output_file
);
1989 int main(int argc
, char *argv
[]) {
1990 const char *board
= NULL
, *kernel_image
= NULL
, *rootfs_image
= NULL
, *output
= NULL
;
1991 const char *extract_image
= NULL
, *output_directory
= NULL
, *convert_image
= NULL
;
1992 bool add_jffs2_eof
= false, sysupgrade
= false;
1994 struct device_info
*info
;
1995 set_source_date_epoch();
2000 c
= getopt(argc
, argv
, "B:k:r:o:V:jSh:x:d:z:");
2010 kernel_image
= optarg
;
2014 rootfs_image
= optarg
;
2022 sscanf(optarg
, "r%u", &rev
);
2026 add_jffs2_eof
= true;
2038 output_directory
= optarg
;
2042 extract_image
= optarg
;
2046 convert_image
= optarg
;
2055 if (extract_image
|| output_directory
) {
2057 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
2058 if (!output_directory
)
2059 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
2060 extract_firmware(extract_image
, output_directory
);
2061 } else if (convert_image
) {
2063 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
2064 convert_firmware(convert_image
, output
);
2067 error(1, 0, "no board has been specified");
2069 error(1, 0, "no kernel image has been specified");
2071 error(1, 0, "no rootfs image has been specified");
2073 error(1, 0, "no output filename has been specified");
2075 info
= find_board(board
);
2078 error(1, 0, "unsupported board %s", board
);
2080 build_image(output
, kernel_image
, rootfs_image
, rev
, add_jffs2_eof
, sysupgrade
, info
);