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 V1 */
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, 0x200000},
144 {"file-system", 0x240000, 0x570000},
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 {"firmware", 0x40000, 0x770000},
186 {"soft-version", 0x7b0000, 0x00100},
187 {"support-list", 0x7b1000, 0x01000},
188 {"user-config", 0x7c0000, 0x10000},
189 {"default-config", 0x7d0000, 0x10000},
190 {"log", 0x7e0000, 0x10000},
191 {"radio", 0x7f0000, 0x10000},
195 .first_sysupgrade_partition
= "os-image",
196 .last_sysupgrade_partition
= "support-list",
199 /** Firmware layout for the CPE210 V3 */
202 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
205 "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
206 "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
207 "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
208 "CPE210(TP-LINK|EU|N300-2):3.0\r\n",
209 .support_trail
= '\xff',
213 {"fs-uboot", 0x00000, 0x20000},
214 {"partition-table", 0x20000, 0x01000},
215 {"default-mac", 0x30000, 0x00020},
216 {"product-info", 0x31100, 0x00100},
217 {"device-info", 0x31400, 0x00400},
218 {"signature", 0x32000, 0x00400},
219 {"device-id", 0x33000, 0x00100},
220 {"firmware", 0x40000, 0x770000},
221 {"soft-version", 0x7b0000, 0x00100},
222 {"support-list", 0x7b1000, 0x01000},
223 {"user-config", 0x7c0000, 0x10000},
224 {"default-config", 0x7d0000, 0x10000},
225 {"log", 0x7e0000, 0x10000},
226 {"radio", 0x7f0000, 0x10000},
230 .first_sysupgrade_partition
= "os-image",
231 .last_sysupgrade_partition
= "support-list",
234 /** Firmware layout for the CPE220 V2 */
237 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
240 "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n"
241 "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n"
242 "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n"
243 "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n"
244 "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n"
245 "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n"
246 "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n"
247 "CPE220(TP-LINK|UN|N300-2):2.0\r\n"
248 "CPE220(TP-LINK|EU|N300-2):2.0\r\n"
249 "CPE220(TP-LINK|US|N300-2):2.0\r\n",
250 .support_trail
= '\xff',
254 {"fs-uboot", 0x00000, 0x20000},
255 {"partition-table", 0x20000, 0x02000},
256 {"default-mac", 0x30000, 0x00020},
257 {"product-info", 0x31100, 0x00100},
258 {"signature", 0x32000, 0x00400},
259 {"os-image", 0x40000, 0x200000},
260 {"file-system", 0x240000, 0x570000},
261 {"soft-version", 0x7b0000, 0x00100},
262 {"support-list", 0x7b1000, 0x00400},
263 {"user-config", 0x7c0000, 0x10000},
264 {"default-config", 0x7d0000, 0x10000},
265 {"log", 0x7e0000, 0x10000},
266 {"radio", 0x7f0000, 0x10000},
270 .first_sysupgrade_partition
= "os-image",
271 .last_sysupgrade_partition
= "support-list",
274 /** Firmware layout for the CPE510/520 V1 */
277 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
280 "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
281 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
282 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
283 "CPE510(TP-LINK|US|N300-5):1.1\r\n"
284 "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
285 "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
286 "CPE520(TP-LINK|US|N300-5):1.1\r\n"
287 "CPE520(TP-LINK|EU|N300-5):1.1\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, 0x200000},
298 {"file-system", 0x240000, 0x570000},
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 CPE510 V2 */
315 .vendor
= "CPE510(TP-LINK|UN|N300-5):2.0\r\n",
318 "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
319 "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
320 "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
321 "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
322 "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
323 "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
324 "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n"
325 "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n"
326 "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
327 "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
328 "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
329 "CPE510(TP-LINK|US|N300-5):2.0\r\n",
330 .support_trail
= '\xff',
334 {"fs-uboot", 0x00000, 0x20000},
335 {"partition-table", 0x20000, 0x02000},
336 {"default-mac", 0x30000, 0x00020},
337 {"product-info", 0x31100, 0x00100},
338 {"signature", 0x32000, 0x00400},
339 {"os-image", 0x40000, 0x200000},
340 {"file-system", 0x240000, 0x570000},
341 {"soft-version", 0x7b0000, 0x00100},
342 {"support-list", 0x7b1000, 0x00400},
343 {"user-config", 0x7c0000, 0x10000},
344 {"default-config", 0x7d0000, 0x10000},
345 {"log", 0x7e0000, 0x10000},
346 {"radio", 0x7f0000, 0x10000},
350 .first_sysupgrade_partition
= "os-image",
351 .last_sysupgrade_partition
= "support-list",
354 /** Firmware layout for the CPE510 V3 */
357 .vendor
= "CPE510(TP-LINK|UN|N300-5):3.0\r\n",
360 "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n"
361 "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n"
362 "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n"
363 "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n"
364 "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n"
365 "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n"
366 "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n"
367 "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n"
368 "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n"
369 "CPE510(TP-LINK|UN|N300-5):3.0\r\n"
370 "CPE510(TP-LINK|EU|N300-5):3.0\r\n"
371 "CPE510(TP-LINK|US|N300-5):3.0\r\n",
372 .support_trail
= '\xff',
376 {"fs-uboot", 0x00000, 0x20000},
377 {"partition-table", 0x20000, 0x02000},
378 {"default-mac", 0x30000, 0x00020},
379 {"product-info", 0x31100, 0x00100},
380 {"signature", 0x32000, 0x00400},
381 {"os-image", 0x40000, 0x200000},
382 {"file-system", 0x240000, 0x570000},
383 {"soft-version", 0x7b0000, 0x00100},
384 {"support-list", 0x7b1000, 0x00400},
385 {"user-config", 0x7c0000, 0x10000},
386 {"default-config", 0x7d0000, 0x10000},
387 {"log", 0x7e0000, 0x10000},
388 {"radio", 0x7f0000, 0x10000},
392 .first_sysupgrade_partition
= "os-image",
393 .last_sysupgrade_partition
= "support-list",
396 /** Firmware layout for the CPE610V1 */
399 .vendor
= "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n",
402 "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n"
403 "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n"
404 "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n"
405 "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n"
406 "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n"
407 "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n"
408 "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n"
409 "CPE610(TP-LINK|UN|N300-5):1.0\r\n"
410 "CPE610(TP-LINK|EU|N300-5):1.0\r\n"
411 "CPE610(TP-LINK|US|N300-5):1.0\r\n",
412 .support_trail
= '\xff',
416 {"fs-uboot", 0x00000, 0x20000},
417 {"partition-table", 0x20000, 0x02000},
418 {"default-mac", 0x30000, 0x00020},
419 {"product-info", 0x31100, 0x00100},
420 {"signature", 0x32000, 0x00400},
421 {"os-image", 0x40000, 0x200000},
422 {"file-system", 0x240000, 0x570000},
423 {"soft-version", 0x7b0000, 0x00100},
424 {"support-list", 0x7b1000, 0x00400},
425 {"user-config", 0x7c0000, 0x10000},
426 {"default-config", 0x7d0000, 0x10000},
427 {"log", 0x7e0000, 0x10000},
428 {"radio", 0x7f0000, 0x10000},
432 .first_sysupgrade_partition
= "os-image",
433 .last_sysupgrade_partition
= "support-list",
438 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
441 "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
442 "WBS210(TP-LINK|US|N300-2):1.20\r\n"
443 "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
444 .support_trail
= '\xff',
448 {"fs-uboot", 0x00000, 0x20000},
449 {"partition-table", 0x20000, 0x02000},
450 {"default-mac", 0x30000, 0x00020},
451 {"product-info", 0x31100, 0x00100},
452 {"signature", 0x32000, 0x00400},
453 {"os-image", 0x40000, 0x200000},
454 {"file-system", 0x240000, 0x570000},
455 {"soft-version", 0x7b0000, 0x00100},
456 {"support-list", 0x7b1000, 0x00400},
457 {"user-config", 0x7c0000, 0x10000},
458 {"default-config", 0x7d0000, 0x10000},
459 {"log", 0x7e0000, 0x10000},
460 {"radio", 0x7f0000, 0x10000},
464 .first_sysupgrade_partition
= "os-image",
465 .last_sysupgrade_partition
= "support-list",
470 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
473 "WBS210(TP-LINK|UN|N300-2|00000000):2.00\r\n"
474 "WBS210(TP-LINK|US|N300-2|55530000):2.00\r\n"
475 "WBS210(TP-LINK|EU|N300-2|45550000):2.00\r\n",
476 .support_trail
= '\xff',
480 {"fs-uboot", 0x00000, 0x20000},
481 {"partition-table", 0x20000, 0x02000},
482 {"default-mac", 0x30000, 0x00020},
483 {"product-info", 0x31100, 0x00100},
484 {"signature", 0x32000, 0x00400},
485 {"os-image", 0x40000, 0x200000},
486 {"file-system", 0x240000, 0x570000},
487 {"soft-version", 0x7b0000, 0x00100},
488 {"support-list", 0x7b1000, 0x00400},
489 {"user-config", 0x7c0000, 0x10000},
490 {"default-config", 0x7d0000, 0x10000},
491 {"log", 0x7e0000, 0x10000},
492 {"radio", 0x7f0000, 0x10000},
496 .first_sysupgrade_partition
= "os-image",
497 .last_sysupgrade_partition
= "support-list",
502 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
505 "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
506 "WBS510(TP-LINK|US|N300-5):1.20\r\n"
507 "WBS510(TP-LINK|EU|N300-5):1.20\r\n",
508 .support_trail
= '\xff',
512 {"fs-uboot", 0x00000, 0x20000},
513 {"partition-table", 0x20000, 0x02000},
514 {"default-mac", 0x30000, 0x00020},
515 {"product-info", 0x31100, 0x00100},
516 {"signature", 0x32000, 0x00400},
517 {"os-image", 0x40000, 0x200000},
518 {"file-system", 0x240000, 0x570000},
519 {"soft-version", 0x7b0000, 0x00100},
520 {"support-list", 0x7b1000, 0x00400},
521 {"user-config", 0x7c0000, 0x10000},
522 {"default-config", 0x7d0000, 0x10000},
523 {"log", 0x7e0000, 0x10000},
524 {"radio", 0x7f0000, 0x10000},
528 .first_sysupgrade_partition
= "os-image",
529 .last_sysupgrade_partition
= "support-list",
532 /** Firmware layout for the C2600 */
538 "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
539 .support_trail
= '\x00',
543 We use a bigger os-image partition than the stock images (and thus
544 smaller file-system), as our kernel doesn't fit in the stock firmware's
545 2 MB os-image since kernel 4.14.
548 {"SBL1", 0x00000, 0x20000},
549 {"MIBIB", 0x20000, 0x20000},
550 {"SBL2", 0x40000, 0x20000},
551 {"SBL3", 0x60000, 0x30000},
552 {"DDRCONFIG", 0x90000, 0x10000},
553 {"SSD", 0xa0000, 0x10000},
554 {"TZ", 0xb0000, 0x30000},
555 {"RPM", 0xe0000, 0x20000},
556 {"fs-uboot", 0x100000, 0x70000},
557 {"uboot-env", 0x170000, 0x40000},
558 {"radio", 0x1b0000, 0x40000},
559 {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
560 {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
561 {"default-mac", 0x1ef0000, 0x00200},
562 {"pin", 0x1ef0200, 0x00200},
563 {"product-info", 0x1ef0400, 0x0fc00},
564 {"partition-table", 0x1f00000, 0x10000},
565 {"soft-version", 0x1f10000, 0x10000},
566 {"support-list", 0x1f20000, 0x10000},
567 {"profile", 0x1f30000, 0x10000},
568 {"default-config", 0x1f40000, 0x10000},
569 {"user-config", 0x1f50000, 0x40000},
570 {"qos-db", 0x1f90000, 0x40000},
571 {"usb-config", 0x1fd0000, 0x10000},
572 {"log", 0x1fe0000, 0x20000},
576 .first_sysupgrade_partition
= "os-image",
577 .last_sysupgrade_partition
= "file-system"
580 /** Firmware layout for the A7-V5 */
582 .id
= "ARCHER-A7-V5",
585 "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n"
586 "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n"
587 "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n"
588 "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n"
589 "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n",
590 .support_trail
= '\x00',
591 .soft_ver
= "soft_ver:1.0.0\n",
593 /* We're using a dynamic kernel/rootfs split here */
595 {"factory-boot", 0x00000, 0x20000},
596 {"fs-uboot", 0x20000, 0x20000},
597 {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
598 /* Stock: name file-system base 0x160000 size 0xda0000 */
599 {"default-mac", 0xf40000, 0x00200},
600 {"pin", 0xf40200, 0x00200},
601 {"device-id", 0xf40400, 0x00100},
602 {"product-info", 0xf40500, 0x0fb00},
603 {"soft-version", 0xf50000, 0x00100},
604 {"extra-para", 0xf51000, 0x01000},
605 {"support-list", 0xf52000, 0x0a000},
606 {"profile", 0xf5c000, 0x04000},
607 {"default-config", 0xf60000, 0x10000},
608 {"user-config", 0xf70000, 0x40000},
609 {"certificate", 0xfb0000, 0x10000},
610 {"partition-table", 0xfc0000, 0x10000},
611 {"log", 0xfd0000, 0x20000},
612 {"radio", 0xff0000, 0x10000},
616 .first_sysupgrade_partition
= "os-image",
617 .last_sysupgrade_partition
= "file-system",
620 /** Firmware layout for the C2v3 */
622 .id
= "ARCHER-C2-V3",
625 "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n"
626 "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n"
627 "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n",
628 .support_trail
= '\x00',
629 .soft_ver
= "soft_ver:3.0.1\n",
631 /** We're using a dynamic kernel/rootfs split here */
634 {"factory-boot", 0x00000, 0x20000},
635 {"fs-uboot", 0x20000, 0x10000},
636 {"firmware", 0x30000, 0x7a0000},
637 {"user-config", 0x7d0000, 0x04000},
638 {"default-mac", 0x7e0000, 0x00100},
639 {"device-id", 0x7e0100, 0x00100},
640 {"extra-para", 0x7e0200, 0x00100},
641 {"pin", 0x7e0300, 0x00100},
642 {"support-list", 0x7e0400, 0x00400},
643 {"soft-version", 0x7e0800, 0x00400},
644 {"product-info", 0x7e0c00, 0x01400},
645 {"partition-table", 0x7e2000, 0x01000},
646 {"profile", 0x7e3000, 0x01000},
647 {"default-config", 0x7e4000, 0x04000},
648 {"merge-config", 0x7ec000, 0x02000},
649 {"qos-db", 0x7ee000, 0x02000},
650 {"radio", 0x7f0000, 0x10000},
654 .first_sysupgrade_partition
= "os-image",
655 .last_sysupgrade_partition
= "file-system",
658 /** Firmware layout for the C25v1 */
660 .id
= "ARCHER-C25-V1",
663 "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
664 "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
665 "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
666 .support_trail
= '\x00',
667 .soft_ver
= "soft_ver:1.0.0\n",
669 /* We're using a dynamic kernel/rootfs split here */
671 {"factory-boot", 0x00000, 0x20000},
672 {"fs-uboot", 0x20000, 0x10000},
673 {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */
674 /* Stock: name file-system base 0x130000 size 0x6a0000 */
675 {"user-config", 0x7d0000, 0x04000},
676 {"default-mac", 0x7e0000, 0x00100},
677 {"device-id", 0x7e0100, 0x00100},
678 {"extra-para", 0x7e0200, 0x00100},
679 {"pin", 0x7e0300, 0x00100},
680 {"support-list", 0x7e0400, 0x00400},
681 {"soft-version", 0x7e0800, 0x00400},
682 {"product-info", 0x7e0c00, 0x01400},
683 {"partition-table", 0x7e2000, 0x01000},
684 {"profile", 0x7e3000, 0x01000},
685 {"default-config", 0x7e4000, 0x04000},
686 {"merge-config", 0x7ec000, 0x02000},
687 {"qos-db", 0x7ee000, 0x02000},
688 {"radio", 0x7f0000, 0x10000},
692 .first_sysupgrade_partition
= "os-image",
693 .last_sysupgrade_partition
= "file-system",
696 /** Firmware layout for the C58v1 */
698 .id
= "ARCHER-C58-V1",
702 "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
703 "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
704 "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
705 .support_trail
= '\x00',
706 .soft_ver
= "soft_ver:1.0.0\n",
709 {"fs-uboot", 0x00000, 0x10000},
710 {"default-mac", 0x10000, 0x00200},
711 {"pin", 0x10200, 0x00200},
712 {"product-info", 0x10400, 0x00100},
713 {"partition-table", 0x10500, 0x00800},
714 {"soft-version", 0x11300, 0x00200},
715 {"support-list", 0x11500, 0x00100},
716 {"device-id", 0x11600, 0x00100},
717 {"profile", 0x11700, 0x03900},
718 {"default-config", 0x15000, 0x04000},
719 {"user-config", 0x19000, 0x04000},
720 {"firmware", 0x20000, 0x7c8000},
721 {"certyficate", 0x7e8000, 0x08000},
722 {"radio", 0x7f0000, 0x10000},
726 .first_sysupgrade_partition
= "os-image",
727 .last_sysupgrade_partition
= "file-system",
730 /** Firmware layout for the C59v1 */
732 .id
= "ARCHER-C59-V1",
736 "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
737 "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
738 "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
739 "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
740 .support_trail
= '\x00',
741 .soft_ver
= "soft_ver:1.0.0\n",
743 /* We're using a dynamic kernel/rootfs split here */
745 {"fs-uboot", 0x00000, 0x10000},
746 {"default-mac", 0x10000, 0x00200},
747 {"pin", 0x10200, 0x00200},
748 {"device-id", 0x10400, 0x00100},
749 {"product-info", 0x10500, 0x0fb00},
750 {"firmware", 0x20000, 0xe30000},
751 {"partition-table", 0xe50000, 0x10000},
752 {"soft-version", 0xe60000, 0x10000},
753 {"support-list", 0xe70000, 0x10000},
754 {"profile", 0xe80000, 0x10000},
755 {"default-config", 0xe90000, 0x10000},
756 {"user-config", 0xea0000, 0x40000},
757 {"usb-config", 0xee0000, 0x10000},
758 {"certificate", 0xef0000, 0x10000},
759 {"qos-db", 0xf00000, 0x40000},
760 {"log", 0xfe0000, 0x10000},
761 {"radio", 0xff0000, 0x10000},
765 .first_sysupgrade_partition
= "os-image",
766 .last_sysupgrade_partition
= "file-system",
769 /** Firmware layout for the C59v2 */
771 .id
= "ARCHER-C59-V2",
775 "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
776 "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
777 "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
778 .support_trail
= '\x00',
779 .soft_ver
= "soft_ver:2.0.0 Build 20161206 rel.7303\n",
781 /** We're using a dynamic kernel/rootfs split here */
783 {"factory-boot", 0x00000, 0x20000},
784 {"fs-uboot", 0x20000, 0x10000},
785 {"default-mac", 0x30000, 0x00200},
786 {"pin", 0x30200, 0x00200},
787 {"device-id", 0x30400, 0x00100},
788 {"product-info", 0x30500, 0x0fb00},
789 {"firmware", 0x40000, 0xe10000},
790 {"partition-table", 0xe50000, 0x10000},
791 {"soft-version", 0xe60000, 0x10000},
792 {"support-list", 0xe70000, 0x10000},
793 {"profile", 0xe80000, 0x10000},
794 {"default-config", 0xe90000, 0x10000},
795 {"user-config", 0xea0000, 0x40000},
796 {"usb-config", 0xee0000, 0x10000},
797 {"certificate", 0xef0000, 0x10000},
798 {"extra-para", 0xf00000, 0x10000},
799 {"qos-db", 0xf10000, 0x30000},
800 {"log", 0xfe0000, 0x10000},
801 {"radio", 0xff0000, 0x10000},
805 .first_sysupgrade_partition
= "os-image",
806 .last_sysupgrade_partition
= "file-system",
809 /** Firmware layout for the C6v2 */
811 .id
= "ARCHER-C6-V2",
815 "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n"
816 "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
817 "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
818 .support_trail
= '\x00',
819 .soft_ver
= "soft_ver:1.0.0\n",
822 {"fs-uboot", 0x00000, 0x20000},
823 {"default-mac", 0x20000, 0x00200},
824 {"pin", 0x20200, 0x00100},
825 {"product-info", 0x20300, 0x00200},
826 {"device-id", 0x20500, 0x0fb00},
827 {"firmware", 0x30000, 0x7a9400},
828 {"soft-version", 0x7d9400, 0x00100},
829 {"extra-para", 0x7d9500, 0x00100},
830 {"support-list", 0x7d9600, 0x00200},
831 {"profile", 0x7d9800, 0x03000},
832 {"default-config", 0x7dc800, 0x03000},
833 {"partition-table", 0x7df800, 0x00800},
834 {"user-config", 0x7e0000, 0x0c000},
835 {"certificate", 0x7ec000, 0x04000},
836 {"radio", 0x7f0000, 0x10000},
840 .first_sysupgrade_partition
= "os-image",
841 .last_sysupgrade_partition
= "file-system",
845 /** Firmware layout for the C60v1 */
847 .id
= "ARCHER-C60-V1",
851 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
852 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
853 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
854 .support_trail
= '\x00',
855 .soft_ver
= "soft_ver:1.0.0\n",
858 {"fs-uboot", 0x00000, 0x10000},
859 {"default-mac", 0x10000, 0x00200},
860 {"pin", 0x10200, 0x00200},
861 {"product-info", 0x10400, 0x00100},
862 {"partition-table", 0x10500, 0x00800},
863 {"soft-version", 0x11300, 0x00200},
864 {"support-list", 0x11500, 0x00100},
865 {"device-id", 0x11600, 0x00100},
866 {"profile", 0x11700, 0x03900},
867 {"default-config", 0x15000, 0x04000},
868 {"user-config", 0x19000, 0x04000},
869 {"firmware", 0x20000, 0x7c8000},
870 {"certyficate", 0x7e8000, 0x08000},
871 {"radio", 0x7f0000, 0x10000},
875 .first_sysupgrade_partition
= "os-image",
876 .last_sysupgrade_partition
= "file-system",
879 /** Firmware layout for the C60v2 */
881 .id
= "ARCHER-C60-V2",
885 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
886 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
887 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
888 .support_trail
= '\x00',
889 .soft_ver
= "soft_ver:2.0.0\n",
892 {"factory-boot", 0x00000, 0x1fb00},
893 {"default-mac", 0x1fb00, 0x00200},
894 {"pin", 0x1fd00, 0x00100},
895 {"product-info", 0x1fe00, 0x00100},
896 {"device-id", 0x1ff00, 0x00100},
897 {"fs-uboot", 0x20000, 0x10000},
898 {"firmware", 0x30000, 0x7a0000},
899 {"soft-version", 0x7d9500, 0x00100},
900 {"support-list", 0x7d9600, 0x00100},
901 {"extra-para", 0x7d9700, 0x00100},
902 {"profile", 0x7d9800, 0x03000},
903 {"default-config", 0x7dc800, 0x03000},
904 {"partition-table", 0x7df800, 0x00800},
905 {"user-config", 0x7e0000, 0x0c000},
906 {"certificate", 0x7ec000, 0x04000},
907 {"radio", 0x7f0000, 0x10000},
911 .first_sysupgrade_partition
= "os-image",
912 .last_sysupgrade_partition
= "file-system",
915 /** Firmware layout for the C5 */
917 .id
= "ARCHER-C5-V2",
921 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
922 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
923 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
924 .support_trail
= '\x00',
928 {"fs-uboot", 0x00000, 0x40000},
929 {"os-image", 0x40000, 0x200000},
930 {"file-system", 0x240000, 0xc00000},
931 {"default-mac", 0xe40000, 0x00200},
932 {"pin", 0xe40200, 0x00200},
933 {"product-info", 0xe40400, 0x00200},
934 {"partition-table", 0xe50000, 0x10000},
935 {"soft-version", 0xe60000, 0x00200},
936 {"support-list", 0xe61000, 0x0f000},
937 {"profile", 0xe70000, 0x10000},
938 {"default-config", 0xe80000, 0x10000},
939 {"user-config", 0xe90000, 0x50000},
940 {"log", 0xee0000, 0x100000},
941 {"radio_bk", 0xfe0000, 0x10000},
942 {"radio", 0xff0000, 0x10000},
946 .first_sysupgrade_partition
= "os-image",
947 .last_sysupgrade_partition
= "file-system"
950 /** Firmware layout for the C7 */
952 .id
= "ARCHER-C7-V4",
955 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
956 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
957 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
958 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
959 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
960 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
961 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
962 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
963 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
964 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
965 .support_trail
= '\x00',
966 .soft_ver
= "soft_ver:1.0.0\n",
968 /* We're using a dynamic kernel/rootfs split here */
970 {"factory-boot", 0x00000, 0x20000},
971 {"fs-uboot", 0x20000, 0x20000},
972 {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
973 /* Stock: name file-system base 0x160000 size 0xda0000 */
974 {"default-mac", 0xf00000, 0x00200},
975 {"pin", 0xf00200, 0x00200},
976 {"device-id", 0xf00400, 0x00100},
977 {"product-info", 0xf00500, 0x0fb00},
978 {"soft-version", 0xf10000, 0x00100},
979 {"extra-para", 0xf11000, 0x01000},
980 {"support-list", 0xf12000, 0x0a000},
981 {"profile", 0xf1c000, 0x04000},
982 {"default-config", 0xf20000, 0x10000},
983 {"user-config", 0xf30000, 0x40000},
984 {"qos-db", 0xf70000, 0x40000},
985 {"certificate", 0xfb0000, 0x10000},
986 {"partition-table", 0xfc0000, 0x10000},
987 {"log", 0xfd0000, 0x20000},
988 {"radio", 0xff0000, 0x10000},
992 .first_sysupgrade_partition
= "os-image",
993 .last_sysupgrade_partition
= "file-system",
996 /** Firmware layout for the C7 v5*/
998 .id
= "ARCHER-C7-V5",
1001 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1002 "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1003 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1004 "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1005 "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1006 "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1007 "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1008 "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1010 .support_trail
= '\x00',
1011 .soft_ver
= "soft_ver:1.0.0\n",
1013 /* We're using a dynamic kernel/rootfs split here */
1015 {"factory-boot", 0x00000, 0x20000},
1016 {"fs-uboot", 0x20000, 0x20000},
1017 {"partition-table", 0x40000, 0x10000},
1018 {"radio", 0x50000, 0x10000},
1019 {"default-mac", 0x60000, 0x00200},
1020 {"pin", 0x60200, 0x00200},
1021 {"device-id", 0x60400, 0x00100},
1022 {"product-info", 0x60500, 0x0fb00},
1023 {"soft-version", 0x70000, 0x01000},
1024 {"extra-para", 0x71000, 0x01000},
1025 {"support-list", 0x72000, 0x0a000},
1026 {"profile", 0x7c000, 0x04000},
1027 {"user-config", 0x80000, 0x40000},
1030 {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */
1031 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1033 {"log", 0xfc0000, 0x20000},
1034 {"certificate", 0xfe0000, 0x10000},
1035 {"default-config", 0xff0000, 0x10000},
1040 .first_sysupgrade_partition
= "os-image",
1041 .last_sysupgrade_partition
= "file-system",
1044 /** Firmware layout for the C9 */
1050 "{product_name:ArcherC9,"
1051 "product_ver:1.0.0,"
1052 "special_id:00000000}\n",
1053 .support_trail
= '\x00',
1057 {"fs-uboot", 0x00000, 0x40000},
1058 {"os-image", 0x40000, 0x200000},
1059 {"file-system", 0x240000, 0xc00000},
1060 {"default-mac", 0xe40000, 0x00200},
1061 {"pin", 0xe40200, 0x00200},
1062 {"product-info", 0xe40400, 0x00200},
1063 {"partition-table", 0xe50000, 0x10000},
1064 {"soft-version", 0xe60000, 0x00200},
1065 {"support-list", 0xe61000, 0x0f000},
1066 {"profile", 0xe70000, 0x10000},
1067 {"default-config", 0xe80000, 0x10000},
1068 {"user-config", 0xe90000, 0x50000},
1069 {"log", 0xee0000, 0x100000},
1070 {"radio_bk", 0xfe0000, 0x10000},
1071 {"radio", 0xff0000, 0x10000},
1075 .first_sysupgrade_partition
= "os-image",
1076 .last_sysupgrade_partition
= "file-system"
1079 /** Firmware layout for the EAP120 */
1082 .vendor
= "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1085 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1086 .support_trail
= '\xff',
1090 {"fs-uboot", 0x00000, 0x20000},
1091 {"partition-table", 0x20000, 0x02000},
1092 {"default-mac", 0x30000, 0x00020},
1093 {"support-list", 0x31000, 0x00100},
1094 {"product-info", 0x31100, 0x00100},
1095 {"soft-version", 0x32000, 0x00100},
1096 {"os-image", 0x40000, 0x180000},
1097 {"file-system", 0x1c0000, 0x600000},
1098 {"user-config", 0x7c0000, 0x10000},
1099 {"backup-config", 0x7d0000, 0x10000},
1100 {"log", 0x7e0000, 0x10000},
1101 {"radio", 0x7f0000, 0x10000},
1105 .first_sysupgrade_partition
= "os-image",
1106 .last_sysupgrade_partition
= "file-system"
1109 /** Firmware layout for the TL-WA850RE v2 */
1111 .id
= "TLWA850REV2",
1115 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1116 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1117 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1118 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1119 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1120 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1121 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1122 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1123 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1124 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1125 .support_trail
= '\x00',
1129 576KB were moved from file-system to os-image
1130 in comparison to the stock image
1133 {"fs-uboot", 0x00000, 0x20000},
1134 {"os-image", 0x20000, 0x150000},
1135 {"file-system", 0x170000, 0x240000},
1136 {"partition-table", 0x3b0000, 0x02000},
1137 {"default-mac", 0x3c0000, 0x00020},
1138 {"pin", 0x3c0100, 0x00020},
1139 {"product-info", 0x3c1000, 0x01000},
1140 {"soft-version", 0x3c2000, 0x00100},
1141 {"support-list", 0x3c3000, 0x01000},
1142 {"profile", 0x3c4000, 0x08000},
1143 {"user-config", 0x3d0000, 0x10000},
1144 {"default-config", 0x3e0000, 0x10000},
1145 {"radio", 0x3f0000, 0x10000},
1149 .first_sysupgrade_partition
= "os-image",
1150 .last_sysupgrade_partition
= "file-system"
1153 /** Firmware layout for the TL-WA855RE v1 */
1155 .id
= "TLWA855REV1",
1159 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1160 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1161 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1162 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1163 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1164 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1165 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1166 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1167 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1168 .support_trail
= '\x00',
1172 {"fs-uboot", 0x00000, 0x20000},
1173 {"os-image", 0x20000, 0x150000},
1174 {"file-system", 0x170000, 0x240000},
1175 {"partition-table", 0x3b0000, 0x02000},
1176 {"default-mac", 0x3c0000, 0x00020},
1177 {"pin", 0x3c0100, 0x00020},
1178 {"product-info", 0x3c1000, 0x01000},
1179 {"soft-version", 0x3c2000, 0x00100},
1180 {"support-list", 0x3c3000, 0x01000},
1181 {"profile", 0x3c4000, 0x08000},
1182 {"user-config", 0x3d0000, 0x10000},
1183 {"default-config", 0x3e0000, 0x10000},
1184 {"radio", 0x3f0000, 0x10000},
1188 .first_sysupgrade_partition
= "os-image",
1189 .last_sysupgrade_partition
= "file-system"
1192 /** Firmware layout for the TL-WR1043 v5 */
1194 .id
= "TLWR1043NV5",
1198 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1199 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1200 .support_trail
= '\x00',
1201 .soft_ver
= "soft_ver:1.0.0\n",
1203 {"factory-boot", 0x00000, 0x20000},
1204 {"fs-uboot", 0x20000, 0x20000},
1205 {"firmware", 0x40000, 0xec0000},
1206 {"default-mac", 0xf00000, 0x00200},
1207 {"pin", 0xf00200, 0x00200},
1208 {"device-id", 0xf00400, 0x00100},
1209 {"product-info", 0xf00500, 0x0fb00},
1210 {"soft-version", 0xf10000, 0x01000},
1211 {"extra-para", 0xf11000, 0x01000},
1212 {"support-list", 0xf12000, 0x0a000},
1213 {"profile", 0xf1c000, 0x04000},
1214 {"default-config", 0xf20000, 0x10000},
1215 {"user-config", 0xf30000, 0x40000},
1216 {"qos-db", 0xf70000, 0x40000},
1217 {"certificate", 0xfb0000, 0x10000},
1218 {"partition-table", 0xfc0000, 0x10000},
1219 {"log", 0xfd0000, 0x20000},
1220 {"radio", 0xff0000, 0x10000},
1223 .first_sysupgrade_partition
= "os-image",
1224 .last_sysupgrade_partition
= "file-system"
1227 /** Firmware layout for the TL-WR1043 v4 */
1229 .id
= "TLWR1043NDV4",
1233 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1234 .support_trail
= '\x00',
1237 /* We're using a dynamic kernel/rootfs split here */
1239 {"fs-uboot", 0x00000, 0x20000},
1240 {"firmware", 0x20000, 0xf30000},
1241 {"default-mac", 0xf50000, 0x00200},
1242 {"pin", 0xf50200, 0x00200},
1243 {"product-info", 0xf50400, 0x0fc00},
1244 {"soft-version", 0xf60000, 0x0b000},
1245 {"support-list", 0xf6b000, 0x04000},
1246 {"profile", 0xf70000, 0x04000},
1247 {"default-config", 0xf74000, 0x0b000},
1248 {"user-config", 0xf80000, 0x40000},
1249 {"partition-table", 0xfc0000, 0x10000},
1250 {"log", 0xfd0000, 0x20000},
1251 {"radio", 0xff0000, 0x10000},
1255 .first_sysupgrade_partition
= "os-image",
1256 .last_sysupgrade_partition
= "file-system"
1259 /** Firmware layout for the TL-WR902AC v1 */
1261 .id
= "TL-WR902AC-V1",
1265 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1266 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1267 .support_trail
= '\x00',
1271 384KB were moved from file-system to os-image
1272 in comparison to the stock image
1275 {"fs-uboot", 0x00000, 0x20000},
1276 {"firmware", 0x20000, 0x730000},
1277 {"default-mac", 0x750000, 0x00200},
1278 {"pin", 0x750200, 0x00200},
1279 {"product-info", 0x750400, 0x0fc00},
1280 {"soft-version", 0x760000, 0x0b000},
1281 {"support-list", 0x76b000, 0x04000},
1282 {"profile", 0x770000, 0x04000},
1283 {"default-config", 0x774000, 0x0b000},
1284 {"user-config", 0x780000, 0x40000},
1285 {"partition-table", 0x7c0000, 0x10000},
1286 {"log", 0x7d0000, 0x20000},
1287 {"radio", 0x7f0000, 0x10000},
1291 .first_sysupgrade_partition
= "os-image",
1292 .last_sysupgrade_partition
= "file-system",
1295 /** Firmware layout for the TL-WR942N V1 */
1301 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1302 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1303 .support_trail
= '\x00',
1307 {"fs-uboot", 0x00000, 0x20000},
1308 {"firmware", 0x20000, 0xe20000},
1309 {"default-mac", 0xe40000, 0x00200},
1310 {"pin", 0xe40200, 0x00200},
1311 {"product-info", 0xe40400, 0x0fc00},
1312 {"partition-table", 0xe50000, 0x10000},
1313 {"soft-version", 0xe60000, 0x10000},
1314 {"support-list", 0xe70000, 0x10000},
1315 {"profile", 0xe80000, 0x10000},
1316 {"default-config", 0xe90000, 0x10000},
1317 {"user-config", 0xea0000, 0x40000},
1318 {"qos-db", 0xee0000, 0x40000},
1319 {"certificate", 0xf20000, 0x10000},
1320 {"usb-config", 0xfb0000, 0x10000},
1321 {"log", 0xfc0000, 0x20000},
1322 {"radio-bk", 0xfe0000, 0x10000},
1323 {"radio", 0xff0000, 0x10000},
1327 .first_sysupgrade_partition
= "os-image",
1328 .last_sysupgrade_partition
= "file-system",
1331 /** Firmware layout for the RE350 v1 */
1337 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
1338 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
1339 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
1340 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
1341 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
1342 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
1343 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
1344 .support_trail
= '\x00',
1347 /** We're using a dynamic kernel/rootfs split here */
1349 {"fs-uboot", 0x00000, 0x20000},
1350 {"firmware", 0x20000, 0x5e0000},
1351 {"partition-table", 0x600000, 0x02000},
1352 {"default-mac", 0x610000, 0x00020},
1353 {"pin", 0x610100, 0x00020},
1354 {"product-info", 0x611100, 0x01000},
1355 {"soft-version", 0x620000, 0x01000},
1356 {"support-list", 0x621000, 0x01000},
1357 {"profile", 0x622000, 0x08000},
1358 {"user-config", 0x630000, 0x10000},
1359 {"default-config", 0x640000, 0x10000},
1360 {"radio", 0x7f0000, 0x10000},
1364 .first_sysupgrade_partition
= "os-image",
1365 .last_sysupgrade_partition
= "file-system"
1368 /** Firmware layout for the RE350K v1 */
1374 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
1375 .support_trail
= '\x00',
1378 /** We're using a dynamic kernel/rootfs split here */
1380 {"fs-uboot", 0x00000, 0x20000},
1381 {"firmware", 0x20000, 0xd70000},
1382 {"partition-table", 0xd90000, 0x02000},
1383 {"default-mac", 0xda0000, 0x00020},
1384 {"pin", 0xda0100, 0x00020},
1385 {"product-info", 0xda1100, 0x01000},
1386 {"soft-version", 0xdb0000, 0x01000},
1387 {"support-list", 0xdb1000, 0x01000},
1388 {"profile", 0xdb2000, 0x08000},
1389 {"user-config", 0xdc0000, 0x10000},
1390 {"default-config", 0xdd0000, 0x10000},
1391 {"device-id", 0xde0000, 0x00108},
1392 {"radio", 0xff0000, 0x10000},
1396 .first_sysupgrade_partition
= "os-image",
1397 .last_sysupgrade_partition
= "file-system"
1400 /** Firmware layout for the RE355 */
1406 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
1407 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
1408 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
1409 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
1410 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
1411 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
1412 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
1413 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
1414 .support_trail
= '\x00',
1417 /* We're using a dynamic kernel/rootfs split here */
1419 {"fs-uboot", 0x00000, 0x20000},
1420 {"firmware", 0x20000, 0x5e0000},
1421 {"partition-table", 0x600000, 0x02000},
1422 {"default-mac", 0x610000, 0x00020},
1423 {"pin", 0x610100, 0x00020},
1424 {"product-info", 0x611100, 0x01000},
1425 {"soft-version", 0x620000, 0x01000},
1426 {"support-list", 0x621000, 0x01000},
1427 {"profile", 0x622000, 0x08000},
1428 {"user-config", 0x630000, 0x10000},
1429 {"default-config", 0x640000, 0x10000},
1430 {"radio", 0x7f0000, 0x10000},
1434 .first_sysupgrade_partition
= "os-image",
1435 .last_sysupgrade_partition
= "file-system"
1438 /** Firmware layout for the RE450 */
1444 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
1445 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
1446 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
1447 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
1448 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
1449 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
1450 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
1451 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
1452 .support_trail
= '\x00',
1455 /** We're using a dynamic kernel/rootfs split here */
1457 {"fs-uboot", 0x00000, 0x20000},
1458 {"firmware", 0x20000, 0x5e0000},
1459 {"partition-table", 0x600000, 0x02000},
1460 {"default-mac", 0x610000, 0x00020},
1461 {"pin", 0x610100, 0x00020},
1462 {"product-info", 0x611100, 0x01000},
1463 {"soft-version", 0x620000, 0x01000},
1464 {"support-list", 0x621000, 0x01000},
1465 {"profile", 0x622000, 0x08000},
1466 {"user-config", 0x630000, 0x10000},
1467 {"default-config", 0x640000, 0x10000},
1468 {"radio", 0x7f0000, 0x10000},
1472 .first_sysupgrade_partition
= "os-image",
1473 .last_sysupgrade_partition
= "file-system"
1476 /** Firmware layout for the RE450 v2 */
1482 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
1483 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
1484 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
1485 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
1486 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
1487 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
1488 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
1489 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
1490 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
1491 .support_trail
= '\x00',
1494 /* We're using a dynamic kernel/rootfs split here */
1496 {"fs-uboot", 0x00000, 0x20000},
1497 {"firmware", 0x20000, 0x5e0000},
1498 {"partition-table", 0x600000, 0x02000},
1499 {"default-mac", 0x610000, 0x00020},
1500 {"pin", 0x610100, 0x00020},
1501 {"product-info", 0x611100, 0x01000},
1502 {"soft-version", 0x620000, 0x01000},
1503 {"support-list", 0x621000, 0x01000},
1504 {"profile", 0x622000, 0x08000},
1505 {"user-config", 0x630000, 0x10000},
1506 {"default-config", 0x640000, 0x10000},
1507 {"radio", 0x7f0000, 0x10000},
1512 .first_sysupgrade_partition
= "os-image",
1513 .last_sysupgrade_partition
= "file-system"
1516 /** Firmware layout for the RE650 */
1522 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
1523 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
1524 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
1525 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
1526 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
1527 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
1528 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
1529 .support_trail
= '\x00',
1532 /* We're using a dynamic kernel/rootfs split here */
1534 {"fs-uboot", 0x00000, 0x20000},
1535 {"firmware", 0x20000, 0xde0000},
1536 {"partition-table", 0xe00000, 0x02000},
1537 {"default-mac", 0xe10000, 0x00020},
1538 {"pin", 0xe10100, 0x00020},
1539 {"product-info", 0xe11100, 0x01000},
1540 {"soft-version", 0xe20000, 0x01000},
1541 {"support-list", 0xe21000, 0x01000},
1542 {"profile", 0xe22000, 0x08000},
1543 {"user-config", 0xe30000, 0x10000},
1544 {"default-config", 0xe40000, 0x10000},
1545 {"radio", 0xff0000, 0x10000},
1549 .first_sysupgrade_partition
= "os-image",
1550 .last_sysupgrade_partition
= "file-system"
1556 #define error(_ret, _errno, _str, ...) \
1558 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
1559 strerror(_errno)); \
1565 /** Stores a uint32 as big endian */
1566 static inline void put32(uint8_t *buf
, uint32_t val
) {
1573 /** Allocates a new image partition */
1574 static struct image_partition_entry
alloc_image_partition(const char *name
, size_t len
) {
1575 struct image_partition_entry entry
= {name
, len
, malloc(len
)};
1577 error(1, errno
, "malloc");
1582 /** Frees an image partition */
1583 static void free_image_partition(struct image_partition_entry entry
) {
1587 static time_t source_date_epoch
= -1;
1588 static void set_source_date_epoch() {
1589 char *env
= getenv("SOURCE_DATE_EPOCH");
1593 source_date_epoch
= strtoull(env
, &endptr
, 10);
1594 if (errno
|| (endptr
&& *endptr
!= '\0')) {
1595 fprintf(stderr
, "Invalid SOURCE_DATE_EPOCH");
1601 /** Generates the partition-table partition */
1602 static struct image_partition_entry
make_partition_table(const struct flash_partition_entry
*p
) {
1603 struct image_partition_entry entry
= alloc_image_partition("partition-table", 0x800);
1605 char *s
= (char *)entry
.data
, *end
= (char *)(s
+entry
.size
);
1613 for (i
= 0; p
[i
].name
; i
++) {
1615 size_t w
= snprintf(s
, len
, "partition %s base 0x%05x size 0x%05x\n", p
[i
].name
, p
[i
].base
, p
[i
].size
);
1618 error(1, 0, "flash partition table overflow?");
1625 memset(s
, 0xff, end
-s
);
1631 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
1632 static inline uint8_t bcd(uint8_t v
) {
1633 return 0x10 * (v
/10) + v
%10;
1637 /** Generates the soft-version partition */
1638 static struct image_partition_entry
make_soft_version(uint32_t rev
) {
1639 struct image_partition_entry entry
= alloc_image_partition("soft-version", sizeof(struct soft_version
));
1640 struct soft_version
*s
= (struct soft_version
*)entry
.data
;
1644 if (source_date_epoch
!= -1)
1645 t
= source_date_epoch
;
1646 else if (time(&t
) == (time_t)(-1))
1647 error(1, errno
, "time");
1649 struct tm
*tm
= localtime(&t
);
1651 s
->magic
= htonl(0x0000000c);
1655 s
->version_major
= 0;
1656 s
->version_minor
= 0;
1657 s
->version_patch
= 0;
1659 s
->year_hi
= bcd((1900+tm
->tm_year
)/100);
1660 s
->year_lo
= bcd(tm
->tm_year
%100);
1661 s
->month
= bcd(tm
->tm_mon
+1);
1662 s
->day
= bcd(tm
->tm_mday
);
1663 s
->rev
= htonl(rev
);
1670 static struct image_partition_entry
make_soft_version_from_string(const char *soft_ver
) {
1671 /** String length _including_ the terminating zero byte */
1672 uint32_t ver_len
= strlen(soft_ver
) + 1;
1673 /** Partition contains 64 bit header, the version string, and one additional null byte */
1674 size_t partition_len
= 2*sizeof(uint32_t) + ver_len
+ 1;
1675 struct image_partition_entry entry
= alloc_image_partition("soft-version", partition_len
);
1677 uint32_t *len
= (uint32_t *)entry
.data
;
1678 len
[0] = htonl(ver_len
);
1680 memcpy(&len
[2], soft_ver
, ver_len
);
1682 entry
.data
[partition_len
- 1] = 0;
1687 /** Generates the support-list partition */
1688 static struct image_partition_entry
make_support_list(struct device_info
*info
) {
1689 size_t len
= strlen(info
->support_list
);
1690 struct image_partition_entry entry
= alloc_image_partition("support-list", len
+ 9);
1692 put32(entry
.data
, len
);
1693 memset(entry
.data
+4, 0, 4);
1694 memcpy(entry
.data
+8, info
->support_list
, len
);
1695 entry
.data
[len
+8] = info
->support_trail
;
1700 /** Creates a new image partition with an arbitrary name from a file */
1701 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
) {
1702 struct stat statbuf
;
1704 if (stat(filename
, &statbuf
) < 0)
1705 error(1, errno
, "unable to stat file `%s'", filename
);
1707 size_t len
= statbuf
.st_size
;
1709 if (add_jffs2_eof
) {
1710 if (file_system_partition
)
1711 len
= ALIGN(len
+ file_system_partition
->base
, 0x10000) + sizeof(jffs2_eof_mark
) - file_system_partition
->base
;
1713 len
= ALIGN(len
, 0x10000) + sizeof(jffs2_eof_mark
);
1716 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
1718 FILE *file
= fopen(filename
, "rb");
1720 error(1, errno
, "unable to open file `%s'", filename
);
1722 if (fread(entry
.data
, statbuf
.st_size
, 1, file
) != 1)
1723 error(1, errno
, "unable to read file `%s'", filename
);
1725 if (add_jffs2_eof
) {
1726 uint8_t *eof
= entry
.data
+ statbuf
.st_size
, *end
= entry
.data
+entry
.size
;
1728 memset(eof
, 0xff, end
- eof
- sizeof(jffs2_eof_mark
));
1729 memcpy(end
- sizeof(jffs2_eof_mark
), jffs2_eof_mark
, sizeof(jffs2_eof_mark
));
1737 /** Creates a new image partition from arbitrary data */
1738 static struct image_partition_entry
put_data(const char *part_name
, const char *datain
, size_t len
) {
1740 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
1742 memcpy(entry
.data
, datain
, len
);
1748 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
1750 Example image partition table:
1752 fwup-ptn partition-table base 0x00800 size 0x00800
1753 fwup-ptn os-image base 0x01000 size 0x113b45
1754 fwup-ptn file-system base 0x114b45 size 0x1d0004
1755 fwup-ptn support-list base 0x2e4b49 size 0x000d1
1757 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
1758 the end of the partition table is marked with a zero byte.
1760 The firmware image must contain at least the partition-table and support-list partitions
1761 to be accepted. There aren't any alignment constraints for the image partitions.
1763 The partition-table partition contains the actual flash layout; partitions
1764 from the image partition table are mapped to the corresponding flash partitions during
1765 the firmware upgrade. The support-list partition contains a list of devices supported by
1768 The base offsets in the firmware partition table are relative to the end
1769 of the vendor information block, so the partition-table partition will
1770 actually start at offset 0x1814 of the image.
1772 I think partition-table must be the first partition in the firmware image.
1774 static void put_partitions(uint8_t *buffer
, const struct flash_partition_entry
*flash_parts
, const struct image_partition_entry
*parts
) {
1776 char *image_pt
= (char *)buffer
, *end
= image_pt
+ 0x800;
1778 size_t base
= 0x800;
1779 for (i
= 0; parts
[i
].name
; i
++) {
1780 for (j
= 0; flash_parts
[j
].name
; j
++) {
1781 if (!strcmp(flash_parts
[j
].name
, parts
[i
].name
)) {
1782 if (parts
[i
].size
> flash_parts
[j
].size
)
1783 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts
[j
].name
, (unsigned)flash_parts
[j
].size
);
1788 assert(flash_parts
[j
].name
);
1790 memcpy(buffer
+ base
, parts
[i
].data
, parts
[i
].size
);
1792 size_t len
= end
-image_pt
;
1793 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
);
1796 error(1, 0, "image partition table overflow?");
1800 base
+= parts
[i
].size
;
1804 /** Generates and writes the image MD5 checksum */
1805 static void put_md5(uint8_t *md5
, uint8_t *buffer
, unsigned int len
) {
1809 MD5_Update(&ctx
, md5_salt
, (unsigned int)sizeof(md5_salt
));
1810 MD5_Update(&ctx
, buffer
, len
);
1811 MD5_Final(md5
, &ctx
);
1816 Generates the firmware image in factory format
1822 0000-0003 Image size (4 bytes, big endian)
1823 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
1824 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
1825 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
1826 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
1827 1014-1813 Image partition table (2048 bytes, padded with 0xff)
1828 1814-xxxx Firmware partitions
1830 static void * generate_factory_image(struct device_info
*info
, const struct image_partition_entry
*parts
, size_t *len
) {
1834 for (i
= 0; parts
[i
].name
; i
++)
1835 *len
+= parts
[i
].size
;
1837 uint8_t *image
= malloc(*len
);
1839 error(1, errno
, "malloc");
1841 memset(image
, 0xff, *len
);
1845 size_t vendor_len
= strlen(info
->vendor
);
1846 put32(image
+0x14, vendor_len
);
1847 memcpy(image
+0x18, info
->vendor
, vendor_len
);
1850 put_partitions(image
+ 0x1014, info
->partitions
, parts
);
1851 put_md5(image
+0x04, image
+0x14, *len
-0x14);
1857 Generates the firmware image in sysupgrade format
1859 This makes some assumptions about the provided flash and image partition tables and
1860 should be generalized when TP-LINK starts building its safeloader into hardware with
1861 different flash layouts.
1863 static void * generate_sysupgrade_image(struct device_info
*info
, const struct image_partition_entry
*image_parts
, size_t *len
) {
1865 size_t flash_first_partition_index
= 0;
1866 size_t flash_last_partition_index
= 0;
1867 const struct flash_partition_entry
*flash_first_partition
= NULL
;
1868 const struct flash_partition_entry
*flash_last_partition
= NULL
;
1869 const struct image_partition_entry
*image_last_partition
= NULL
;
1871 /** Find first and last partitions */
1872 for (i
= 0; info
->partitions
[i
].name
; i
++) {
1873 if (!strcmp(info
->partitions
[i
].name
, info
->first_sysupgrade_partition
)) {
1874 flash_first_partition
= &info
->partitions
[i
];
1875 flash_first_partition_index
= i
;
1876 } else if (!strcmp(info
->partitions
[i
].name
, info
->last_sysupgrade_partition
)) {
1877 flash_last_partition
= &info
->partitions
[i
];
1878 flash_last_partition_index
= i
;
1882 assert(flash_first_partition
&& flash_last_partition
);
1883 assert(flash_first_partition_index
< flash_last_partition_index
);
1885 /** Find last partition from image to calculate needed size */
1886 for (i
= 0; image_parts
[i
].name
; i
++) {
1887 if (!strcmp(image_parts
[i
].name
, info
->last_sysupgrade_partition
)) {
1888 image_last_partition
= &image_parts
[i
];
1893 assert(image_last_partition
);
1895 *len
= flash_last_partition
->base
- flash_first_partition
->base
+ image_last_partition
->size
;
1897 uint8_t *image
= malloc(*len
);
1899 error(1, errno
, "malloc");
1901 memset(image
, 0xff, *len
);
1903 for (i
= flash_first_partition_index
; i
<= flash_last_partition_index
; i
++) {
1904 for (j
= 0; image_parts
[j
].name
; j
++) {
1905 if (!strcmp(info
->partitions
[i
].name
, image_parts
[j
].name
)) {
1906 if (image_parts
[j
].size
> info
->partitions
[i
].size
)
1907 error(1, 0, "%s partition too big (more than %u bytes)", info
->partitions
[i
].name
, (unsigned)info
->partitions
[i
].size
);
1908 memcpy(image
+ info
->partitions
[i
].base
- flash_first_partition
->base
, image_parts
[j
].data
, image_parts
[j
].size
);
1912 assert(image_parts
[j
].name
);
1919 /** Generates an image according to a given layout and writes it to a file */
1920 static void build_image(const char *output
,
1921 const char *kernel_image
,
1922 const char *rootfs_image
,
1926 struct device_info
*info
) {
1930 struct image_partition_entry parts
[7] = {};
1932 struct flash_partition_entry
*firmware_partition
= NULL
;
1933 struct flash_partition_entry
*os_image_partition
= NULL
;
1934 struct flash_partition_entry
*file_system_partition
= NULL
;
1935 size_t firmware_partition_index
= 0;
1937 for (i
= 0; info
->partitions
[i
].name
; i
++) {
1938 if (!strcmp(info
->partitions
[i
].name
, "firmware"))
1940 firmware_partition
= &info
->partitions
[i
];
1941 firmware_partition_index
= i
;
1945 if (firmware_partition
)
1947 os_image_partition
= &info
->partitions
[firmware_partition_index
];
1948 file_system_partition
= &info
->partitions
[firmware_partition_index
+ 1];
1951 if (stat(kernel_image
, &kernel
) < 0)
1952 error(1, errno
, "unable to stat file `%s'", kernel_image
);
1954 if (kernel
.st_size
> firmware_partition
->size
)
1955 error(1, 0, "kernel overflowed firmware partition\n");
1957 for (i
= MAX_PARTITIONS
-1; i
>= firmware_partition_index
+ 1; i
--)
1958 info
->partitions
[i
+1] = info
->partitions
[i
];
1960 file_system_partition
->name
= "file-system";
1961 file_system_partition
->base
= firmware_partition
->base
+ kernel
.st_size
;
1963 /* Align partition start to erase blocks for factory images only */
1965 file_system_partition
->base
= ALIGN(firmware_partition
->base
+ kernel
.st_size
, 0x10000);
1967 file_system_partition
->size
= firmware_partition
->size
- file_system_partition
->base
;
1969 os_image_partition
->name
= "os-image";
1970 os_image_partition
->size
= kernel
.st_size
;
1973 parts
[0] = make_partition_table(info
->partitions
);
1975 parts
[1] = make_soft_version_from_string(info
->soft_ver
);
1977 parts
[1] = make_soft_version(rev
);
1979 parts
[2] = make_support_list(info
);
1980 parts
[3] = read_file("os-image", kernel_image
, false, NULL
);
1981 parts
[4] = read_file("file-system", rootfs_image
, add_jffs2_eof
, file_system_partition
);
1983 /* Some devices need the extra-para partition to accept the firmware */
1984 if (strcasecmp(info
->id
, "ARCHER-C2-V3") == 0 ||
1985 strcasecmp(info
->id
, "ARCHER-C25-V1") == 0 ||
1986 strcasecmp(info
->id
, "ARCHER-C59-V2") == 0 ||
1987 strcasecmp(info
->id
, "ARCHER-C60-V2") == 0 ||
1988 strcasecmp(info
->id
, "TLWR1043NV5") == 0) {
1989 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
1990 parts
[5] = put_data("extra-para", mdat
, 11);
1991 } else if (strcasecmp(info
->id
, "ARCHER-A7-V5") == 0 || strcasecmp(info
->id
, "ARCHER-C7-V4") == 0 || strcasecmp(info
->id
, "ARCHER-C7-V5") == 0) {
1992 const char mdat
[11] = {0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x01, 0x00, 0x00};
1993 parts
[5] = put_data("extra-para", mdat
, 11);
1994 } else if (strcasecmp(info
->id
, "ARCHER-C6-V2") == 0) {
1995 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
1996 parts
[5] = put_data("extra-para", mdat
, 11);
2002 image
= generate_sysupgrade_image(info
, parts
, &len
);
2004 image
= generate_factory_image(info
, parts
, &len
);
2006 FILE *file
= fopen(output
, "wb");
2008 error(1, errno
, "unable to open output file");
2010 if (fwrite(image
, len
, 1, file
) != 1)
2011 error(1, 0, "unable to write output file");
2017 for (i
= 0; parts
[i
].name
; i
++)
2018 free_image_partition(parts
[i
]);
2022 static void usage(const char *argv0
) {
2024 "Usage: %s [OPTIONS...]\n"
2027 " -h show this help\n"
2029 "Create a new image:\n"
2030 " -B <board> create image for the board specified with <board>\n"
2031 " -k <file> read kernel image from the file <file>\n"
2032 " -r <file> read rootfs image from the file <file>\n"
2033 " -o <file> write output to the file <file>\n"
2034 " -V <rev> sets the revision number to <rev>\n"
2035 " -j add jffs2 end-of-filesystem markers\n"
2036 " -S create sysupgrade instead of factory image\n"
2037 "Extract an old image:\n"
2038 " -x <file> extract all oem firmware partition\n"
2039 " -d <dir> destination to extract the firmware partition\n"
2040 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
2046 static struct device_info
*find_board(const char *id
)
2048 struct device_info
*board
= NULL
;
2050 for (board
= boards
; board
->id
!= NULL
; board
++)
2051 if (strcasecmp(id
, board
->id
) == 0)
2057 static int add_flash_partition(
2058 struct flash_partition_entry
*part_list
,
2065 /* check if the list has a free entry */
2066 for (ptr
= 0; ptr
< max_entries
; ptr
++, part_list
++) {
2067 if (part_list
->name
== NULL
&&
2068 part_list
->base
== 0 &&
2069 part_list
->size
== 0)
2073 if (ptr
== max_entries
) {
2074 error(1, 0, "No free flash part entry available.");
2077 part_list
->name
= calloc(1, strlen(name
) + 1);
2078 if (!part_list
->name
) {
2079 error(1, 0, "Unable to allocate memory");
2082 memcpy((char *)part_list
->name
, name
, strlen(name
));
2083 part_list
->base
= base
;
2084 part_list
->size
= size
;
2089 /** read the partition table into struct flash_partition_entry */
2090 static int read_partition_table(
2091 FILE *file
, long offset
,
2092 struct flash_partition_entry
*entries
, size_t max_entries
,
2097 const char *parthdr
= NULL
;
2098 const char *fwuphdr
= "fwup-ptn";
2099 const char *flashhdr
= "partition";
2101 /* TODO: search for the partition table */
2111 error(1, 0, "Invalid partition table");
2114 if (fseek(file
, offset
, SEEK_SET
) < 0)
2115 error(1, errno
, "Can not seek in the firmware");
2117 if (fread(buf
, 2048, 1, file
) != 1)
2118 error(1, errno
, "Can not read fwup-ptn from the firmware");
2122 /* look for the partition header */
2123 if (memcmp(buf
, parthdr
, strlen(parthdr
)) != 0) {
2124 fprintf(stderr
, "DEBUG: can not find fwuphdr\n");
2129 end
= buf
+ sizeof(buf
);
2130 while ((ptr
+ strlen(parthdr
)) < end
&&
2131 memcmp(ptr
, parthdr
, strlen(parthdr
)) == 0) {
2135 char name
[32] = { 0 };
2137 unsigned long base
= 0;
2138 unsigned long size
= 0;
2140 end_part
= memchr(ptr
, '\n', (end
- ptr
));
2141 if (end_part
== NULL
) {
2142 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
2146 for (int i
= 0; i
<= 4; i
++) {
2147 if (end_part
<= ptr
)
2150 end_element
= memchr(ptr
, 0x20, (end_part
- ptr
));
2151 if (end_element
== NULL
) {
2152 error(1, errno
, "Ignoring the rest of the partition entries.");
2157 /* partition header */
2159 ptr
= end_element
+ 1;
2163 name_len
= (end_element
- ptr
) > 31 ? 31 : (end_element
- ptr
);
2164 strncpy(name
, ptr
, name_len
);
2165 name
[name_len
] = '\0';
2166 ptr
= end_element
+ 1;
2171 ptr
= end_element
+ 1;
2176 base
= strtoul(ptr
, NULL
, 16);
2177 ptr
= end_element
+ 1;
2182 ptr
= end_element
+ 1;
2183 /* actual size. The last element doesn't have a sepeartor */
2184 size
= strtoul(ptr
, NULL
, 16);
2185 /* the part ends with 0x09, 0x0d, 0x0a */
2187 add_flash_partition(entries
, max_entries
, name
, base
, size
);
2196 static void write_partition(
2198 size_t firmware_offset
,
2199 struct flash_partition_entry
*entry
,
2205 fseek(input_file
, entry
->base
+ firmware_offset
, SEEK_SET
);
2207 for (offset
= 0; sizeof(buf
) + offset
<= entry
->size
; offset
+= sizeof(buf
)) {
2208 if (fread(buf
, sizeof(buf
), 1, input_file
) != 1)
2209 error(1, errno
, "Can not read partition from input_file");
2211 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
2212 error(1, errno
, "Can not write partition to output_file");
2214 /* write last chunk smaller than buffer */
2215 if (offset
< entry
->size
) {
2216 offset
= entry
->size
- offset
;
2217 if (fread(buf
, offset
, 1, input_file
) != 1)
2218 error(1, errno
, "Can not read partition from input_file");
2219 if (fwrite(buf
, offset
, 1, output_file
) != 1)
2220 error(1, errno
, "Can not write partition to output_file");
2224 static int extract_firmware_partition(FILE *input_file
, size_t firmware_offset
, struct flash_partition_entry
*entry
, const char *output_directory
)
2227 char output
[PATH_MAX
];
2229 snprintf(output
, PATH_MAX
, "%s/%s", output_directory
, entry
->name
);
2230 output_file
= fopen(output
, "wb+");
2231 if (output_file
== NULL
) {
2232 error(1, errno
, "Can not open output file %s", output
);
2235 write_partition(input_file
, firmware_offset
, entry
, output_file
);
2237 fclose(output_file
);
2242 /** extract all partitions from the firmware file */
2243 static int extract_firmware(const char *input
, const char *output_directory
)
2245 struct flash_partition_entry entries
[16] = { 0 };
2246 size_t max_entries
= 16;
2247 size_t firmware_offset
= 0x1014;
2250 struct stat statbuf
;
2252 /* check input file */
2253 if (stat(input
, &statbuf
)) {
2254 error(1, errno
, "Can not read input firmware %s", input
);
2257 /* check if output directory exists */
2258 if (stat(output_directory
, &statbuf
)) {
2259 error(1, errno
, "Failed to stat output directory %s", output_directory
);
2262 if ((statbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
2263 error(1, errno
, "Given output directory is not a directory %s", output_directory
);
2266 input_file
= fopen(input
, "rb");
2268 if (read_partition_table(input_file
, firmware_offset
, entries
, 16, 0) != 0) {
2269 error(1, 0, "Error can not read the partition table (fwup-ptn)");
2272 for (size_t i
= 0; i
< max_entries
; i
++) {
2273 if (entries
[i
].name
== NULL
&&
2274 entries
[i
].base
== 0 &&
2275 entries
[i
].size
== 0)
2278 extract_firmware_partition(input_file
, firmware_offset
, &entries
[i
], output_directory
);
2284 static struct flash_partition_entry
*find_partition(
2285 struct flash_partition_entry
*entries
, size_t max_entries
,
2286 const char *name
, const char *error_msg
)
2288 for (size_t i
= 0; i
< max_entries
; i
++, entries
++) {
2289 if (strcmp(entries
->name
, name
) == 0)
2293 error(1, 0, "%s", error_msg
);
2297 static void write_ff(FILE *output_file
, size_t size
)
2302 memset(buf
, 0xff, sizeof(buf
));
2304 for (offset
= 0; offset
+ sizeof(buf
) < size
; offset
+= sizeof(buf
)) {
2305 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
2306 error(1, errno
, "Can not write 0xff to output_file");
2309 /* write last chunk smaller than buffer */
2310 if (offset
< size
) {
2311 offset
= size
- offset
;
2312 if (fwrite(buf
, offset
, 1, output_file
) != 1)
2313 error(1, errno
, "Can not write partition to output_file");
2317 static void convert_firmware(const char *input
, const char *output
)
2319 struct flash_partition_entry fwup
[MAX_PARTITIONS
] = { 0 };
2320 struct flash_partition_entry flash
[MAX_PARTITIONS
] = { 0 };
2321 struct flash_partition_entry
*fwup_os_image
= NULL
, *fwup_file_system
= NULL
;
2322 struct flash_partition_entry
*flash_os_image
= NULL
, *flash_file_system
= NULL
;
2323 struct flash_partition_entry
*fwup_partition_table
= NULL
;
2324 size_t firmware_offset
= 0x1014;
2325 FILE *input_file
, *output_file
;
2327 struct stat statbuf
;
2329 /* check input file */
2330 if (stat(input
, &statbuf
)) {
2331 error(1, errno
, "Can not read input firmware %s", input
);
2334 input_file
= fopen(input
, "rb");
2336 error(1, 0, "Can not open input firmware %s", input
);
2338 output_file
= fopen(output
, "wb");
2340 error(1, 0, "Can not open output firmware %s", output
);
2342 if (read_partition_table(input_file
, firmware_offset
, fwup
, MAX_PARTITIONS
, 0) != 0) {
2343 error(1, 0, "Error can not read the partition table (fwup-ptn)");
2346 fwup_os_image
= find_partition(fwup
, MAX_PARTITIONS
,
2347 "os-image", "Error can not find os-image partition (fwup)");
2348 fwup_file_system
= find_partition(fwup
, MAX_PARTITIONS
,
2349 "file-system", "Error can not find file-system partition (fwup)");
2350 fwup_partition_table
= find_partition(fwup
, MAX_PARTITIONS
,
2351 "partition-table", "Error can not find partition-table partition");
2353 /* the flash partition table has a 0x00000004 magic haeder */
2354 if (read_partition_table(input_file
, firmware_offset
+ fwup_partition_table
->base
+ 4, flash
, MAX_PARTITIONS
, 1) != 0)
2355 error(1, 0, "Error can not read the partition table (flash)");
2357 flash_os_image
= find_partition(flash
, MAX_PARTITIONS
,
2358 "os-image", "Error can not find os-image partition (flash)");
2359 flash_file_system
= find_partition(flash
, MAX_PARTITIONS
,
2360 "file-system", "Error can not find file-system partition (flash)");
2362 /* write os_image to 0x0 */
2363 write_partition(input_file
, firmware_offset
, fwup_os_image
, output_file
);
2364 write_ff(output_file
, flash_os_image
->size
- fwup_os_image
->size
);
2366 /* write file-system behind os_image */
2367 fseek(output_file
, flash_file_system
->base
- flash_os_image
->base
, SEEK_SET
);
2368 write_partition(input_file
, firmware_offset
, fwup_file_system
, output_file
);
2369 write_ff(output_file
, flash_file_system
->size
- fwup_file_system
->size
);
2371 fclose(output_file
);
2375 int main(int argc
, char *argv
[]) {
2376 const char *board
= NULL
, *kernel_image
= NULL
, *rootfs_image
= NULL
, *output
= NULL
;
2377 const char *extract_image
= NULL
, *output_directory
= NULL
, *convert_image
= NULL
;
2378 bool add_jffs2_eof
= false, sysupgrade
= false;
2380 struct device_info
*info
;
2381 set_source_date_epoch();
2386 c
= getopt(argc
, argv
, "B:k:r:o:V:jSh:x:d:z:");
2396 kernel_image
= optarg
;
2400 rootfs_image
= optarg
;
2408 sscanf(optarg
, "r%u", &rev
);
2412 add_jffs2_eof
= true;
2424 output_directory
= optarg
;
2428 extract_image
= optarg
;
2432 convert_image
= optarg
;
2441 if (extract_image
|| output_directory
) {
2443 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
2444 if (!output_directory
)
2445 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
2446 extract_firmware(extract_image
, output_directory
);
2447 } else if (convert_image
) {
2449 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
2450 convert_firmware(convert_image
, output
);
2453 error(1, 0, "no board has been specified");
2455 error(1, 0, "no kernel image has been specified");
2457 error(1, 0, "no rootfs image has been specified");
2459 error(1, 0, "no output filename has been specified");
2461 info
= find_board(board
);
2464 error(1, 0, "unsupported board %s", board
);
2466 build_image(output
, kernel_image
, rootfs_image
, rev
, add_jffs2_eof
, sysupgrade
, info
);