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)
47 #include <arpa/inet.h>
49 #include <sys/types.h>
56 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
59 #define MAX_PARTITIONS 32
61 /** An image partition table entry */
62 struct image_partition_entry
{
68 /** A flash partition table entry */
69 struct flash_partition_entry
{
75 /** Partition trailing padding definitions
76 * Values 0x00 to 0xff are reserved to indicate the padding value
77 * Values from 0x100 are reserved to indicate other behaviour */
78 enum partition_trail_value
{
81 PART_TRAIL_MAX
= 0xff,
82 PART_TRAIL_NONE
= 0x100
85 /** Firmware layout description */
89 const char *support_list
;
90 enum partition_trail_value part_trail
;
92 uint32_t soft_ver_compat_level
;
93 struct flash_partition_entry partitions
[MAX_PARTITIONS
+1];
94 const char *first_sysupgrade_partition
;
95 const char *last_sysupgrade_partition
;
98 struct __attribute__((__packed__
)) meta_header
{
103 /** The content of the soft-version structure */
104 struct __attribute__((__packed__
)) soft_version
{
106 uint8_t version_major
;
107 uint8_t version_minor
;
108 uint8_t version_patch
;
114 uint32_t compat_level
;
118 static const uint8_t jffs2_eof_mark
[4] = {0xde, 0xad, 0xc0, 0xde};
122 Salt for the MD5 hash
124 Fortunately, TP-LINK seems to use the same salt for most devices which use
125 the new image format.
127 static const uint8_t md5_salt
[16] = {
128 0x7a, 0x2b, 0x15, 0xed,
129 0x9b, 0x98, 0x59, 0x6d,
130 0xe5, 0x04, 0xab, 0x44,
131 0xac, 0x2a, 0x9f, 0x4e,
135 /** Firmware layout table */
136 static struct device_info boards
[] = {
137 /** Firmware layout for the CPE210/220 V1 */
140 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
143 "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
144 "CPE210(TP-LINK|UN|N300-2):1.1\r\n"
145 "CPE210(TP-LINK|US|N300-2):1.1\r\n"
146 "CPE210(TP-LINK|EU|N300-2):1.1\r\n"
147 "CPE220(TP-LINK|UN|N300-2):1.1\r\n"
148 "CPE220(TP-LINK|US|N300-2):1.1\r\n"
149 "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
154 {"fs-uboot", 0x00000, 0x20000},
155 {"partition-table", 0x20000, 0x02000},
156 {"default-mac", 0x30000, 0x00020},
157 {"product-info", 0x31100, 0x00100},
158 {"signature", 0x32000, 0x00400},
159 {"os-image", 0x40000, 0x300000},
160 {"file-system", 0x340000, 0x470000},
161 {"soft-version", 0x7b0000, 0x00100},
162 {"support-list", 0x7b1000, 0x00400},
163 {"user-config", 0x7c0000, 0x10000},
164 {"default-config", 0x7d0000, 0x10000},
165 {"log", 0x7e0000, 0x10000},
166 {"radio", 0x7f0000, 0x10000},
170 .first_sysupgrade_partition
= "os-image",
171 .last_sysupgrade_partition
= "support-list",
174 /** Firmware layout for the CPE210 V2 */
177 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
180 "CPE210(TP-LINK|EU|N300-2|00000000):2.0\r\n"
181 "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n"
182 "CPE210(TP-LINK|EU|N300-2|55530000):2.0\r\n"
183 "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
184 "CPE210(TP-LINK|UN|N300-2|45550000):2.0\r\n"
185 "CPE210(TP-LINK|UN|N300-2|55530000):2.0\r\n"
186 "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
187 "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
188 "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
189 "CPE210(TP-LINK|US|N300-2):2.0\r\n",
194 {"fs-uboot", 0x00000, 0x20000},
195 {"partition-table", 0x20000, 0x02000},
196 {"default-mac", 0x30000, 0x00020},
197 {"product-info", 0x31100, 0x00100},
198 {"device-info", 0x31400, 0x00400},
199 {"signature", 0x32000, 0x00400},
200 {"device-id", 0x33000, 0x00100},
201 {"firmware", 0x40000, 0x770000},
202 {"soft-version", 0x7b0000, 0x00100},
203 {"support-list", 0x7b1000, 0x01000},
204 {"user-config", 0x7c0000, 0x10000},
205 {"default-config", 0x7d0000, 0x10000},
206 {"log", 0x7e0000, 0x10000},
207 {"radio", 0x7f0000, 0x10000},
211 .first_sysupgrade_partition
= "os-image",
212 .last_sysupgrade_partition
= "support-list",
215 /** Firmware layout for the CPE210 V3 */
218 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
221 "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
222 "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
223 "CPE210(TP-LINK|US|N300-2|55530000):3.0\r\n"
224 "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
225 "CPE210(TP-LINK|EU|N300-2):3.0\r\n"
226 "CPE210(TP-LINK|EU|N300-2|45550000):3.1\r\n"
227 "CPE210(TP-LINK|UN|N300-2|00000000):3.1\r\n"
228 "CPE210(TP-LINK|US|N300-2|55530000):3.1\r\n"
229 "CPE210(TP-LINK|EU|N300-2|45550000):3.20\r\n"
230 "CPE210(TP-LINK|UN|N300-2|00000000):3.20\r\n"
231 "CPE210(TP-LINK|US|N300-2|55530000):3.20\r\n",
236 {"fs-uboot", 0x00000, 0x20000},
237 {"partition-table", 0x20000, 0x01000},
238 {"default-mac", 0x30000, 0x00020},
239 {"product-info", 0x31100, 0x00100},
240 {"device-info", 0x31400, 0x00400},
241 {"signature", 0x32000, 0x00400},
242 {"device-id", 0x33000, 0x00100},
243 {"firmware", 0x40000, 0x770000},
244 {"soft-version", 0x7b0000, 0x00100},
245 {"support-list", 0x7b1000, 0x01000},
246 {"user-config", 0x7c0000, 0x10000},
247 {"default-config", 0x7d0000, 0x10000},
248 {"log", 0x7e0000, 0x10000},
249 {"radio", 0x7f0000, 0x10000},
253 .first_sysupgrade_partition
= "os-image",
254 .last_sysupgrade_partition
= "support-list",
257 /** Firmware layout for the CPE220 V2 */
260 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
263 "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n"
264 "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n"
265 "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n"
266 "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n"
267 "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n"
268 "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n"
269 "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n"
270 "CPE220(TP-LINK|UN|N300-2):2.0\r\n"
271 "CPE220(TP-LINK|EU|N300-2):2.0\r\n"
272 "CPE220(TP-LINK|US|N300-2):2.0\r\n",
277 {"fs-uboot", 0x00000, 0x20000},
278 {"partition-table", 0x20000, 0x02000},
279 {"default-mac", 0x30000, 0x00020},
280 {"product-info", 0x31100, 0x00100},
281 {"signature", 0x32000, 0x00400},
282 {"os-image", 0x40000, 0x300000},
283 {"file-system", 0x340000, 0x470000},
284 {"soft-version", 0x7b0000, 0x00100},
285 {"support-list", 0x7b1000, 0x00400},
286 {"user-config", 0x7c0000, 0x10000},
287 {"default-config", 0x7d0000, 0x10000},
288 {"log", 0x7e0000, 0x10000},
289 {"radio", 0x7f0000, 0x10000},
293 .first_sysupgrade_partition
= "os-image",
294 .last_sysupgrade_partition
= "support-list",
297 /** Firmware layout for the CPE220 V3 */
300 .vendor
= "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n",
303 "CPE220(TP-LINK|EU|N300-2|00000000):3.0\r\n"
304 "CPE220(TP-LINK|EU|N300-2|45550000):3.0\r\n"
305 "CPE220(TP-LINK|EU|N300-2|55530000):3.0\r\n"
306 "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n"
307 "CPE220(TP-LINK|UN|N300-2|45550000):3.0\r\n"
308 "CPE220(TP-LINK|UN|N300-2|55530000):3.0\r\n"
309 "CPE220(TP-LINK|US|N300-2|55530000):3.0\r\n"
310 "CPE220(TP-LINK|UN|N300-2):3.0\r\n"
311 "CPE220(TP-LINK|EU|N300-2):3.0\r\n"
312 "CPE220(TP-LINK|US|N300-2):3.0\r\n",
317 {"fs-uboot", 0x00000, 0x20000},
318 {"partition-table", 0x20000, 0x02000},
319 {"default-mac", 0x30000, 0x00020},
320 {"product-info", 0x31100, 0x00100},
321 {"device-info", 0x31400, 0x00400},
322 {"signature", 0x32000, 0x00400},
323 {"device-id", 0x33000, 0x00100},
324 {"firmware", 0x40000, 0x770000},
325 {"soft-version", 0x7b0000, 0x00100},
326 {"support-list", 0x7b1000, 0x01000},
327 {"user-config", 0x7c0000, 0x10000},
328 {"default-config", 0x7d0000, 0x10000},
329 {"log", 0x7e0000, 0x10000},
330 {"radio", 0x7f0000, 0x10000},
334 .first_sysupgrade_partition
= "os-image",
335 .last_sysupgrade_partition
= "support-list",
338 /** Firmware layout for the CPE510/520 V1 */
341 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
344 "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
345 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
346 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
347 "CPE510(TP-LINK|US|N300-5):1.1\r\n"
348 "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
349 "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
350 "CPE520(TP-LINK|US|N300-5):1.1\r\n"
351 "CPE520(TP-LINK|EU|N300-5):1.1\r\n",
356 {"fs-uboot", 0x00000, 0x20000},
357 {"partition-table", 0x20000, 0x02000},
358 {"default-mac", 0x30000, 0x00020},
359 {"product-info", 0x31100, 0x00100},
360 {"signature", 0x32000, 0x00400},
361 {"os-image", 0x40000, 0x300000},
362 {"file-system", 0x340000, 0x470000},
363 {"soft-version", 0x7b0000, 0x00100},
364 {"support-list", 0x7b1000, 0x00400},
365 {"user-config", 0x7c0000, 0x10000},
366 {"default-config", 0x7d0000, 0x10000},
367 {"log", 0x7e0000, 0x10000},
368 {"radio", 0x7f0000, 0x10000},
372 .first_sysupgrade_partition
= "os-image",
373 .last_sysupgrade_partition
= "support-list",
376 /** Firmware layout for the CPE510 V2 */
379 .vendor
= "CPE510(TP-LINK|UN|N300-5):2.0\r\n",
382 "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
383 "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
384 "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
385 "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
386 "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
387 "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
388 "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n"
389 "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n"
390 "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
391 "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
392 "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
393 "CPE510(TP-LINK|US|N300-5):2.0\r\n",
398 {"fs-uboot", 0x00000, 0x20000},
399 {"partition-table", 0x20000, 0x02000},
400 {"default-mac", 0x30000, 0x00020},
401 {"product-info", 0x31100, 0x00100},
402 {"signature", 0x32000, 0x00400},
403 {"os-image", 0x40000, 0x300000},
404 {"file-system", 0x340000, 0x470000},
405 {"soft-version", 0x7b0000, 0x00100},
406 {"support-list", 0x7b1000, 0x00400},
407 {"user-config", 0x7c0000, 0x10000},
408 {"default-config", 0x7d0000, 0x10000},
409 {"log", 0x7e0000, 0x10000},
410 {"radio", 0x7f0000, 0x10000},
414 .first_sysupgrade_partition
= "os-image",
415 .last_sysupgrade_partition
= "support-list",
418 /** Firmware layout for the CPE510 V3 */
421 .vendor
= "CPE510(TP-LINK|UN|N300-5):3.0\r\n",
424 "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n"
425 "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n"
426 "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n"
427 "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n"
428 "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n"
429 "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n"
430 "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n"
431 "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n"
432 "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n"
433 "CPE510(TP-LINK|UN|N300-5):3.0\r\n"
434 "CPE510(TP-LINK|EU|N300-5):3.0\r\n"
435 "CPE510(TP-LINK|US|N300-5):3.0\r\n"
436 "CPE510(TP-LINK|UN|N300-5|00000000):3.20\r\n"
437 "CPE510(TP-LINK|US|N300-5|55530000):3.20\r\n"
438 "CPE510(TP-LINK|EU|N300-5|45550000):3.20\r\n",
443 {"fs-uboot", 0x00000, 0x20000},
444 {"partition-table", 0x20000, 0x02000},
445 {"default-mac", 0x30000, 0x00020},
446 {"product-info", 0x31100, 0x00100},
447 {"signature", 0x32000, 0x00400},
448 {"os-image", 0x40000, 0x300000},
449 {"file-system", 0x340000, 0x470000},
450 {"soft-version", 0x7b0000, 0x00100},
451 {"support-list", 0x7b1000, 0x00400},
452 {"user-config", 0x7c0000, 0x10000},
453 {"default-config", 0x7d0000, 0x10000},
454 {"log", 0x7e0000, 0x10000},
455 {"radio", 0x7f0000, 0x10000},
459 .first_sysupgrade_partition
= "os-image",
460 .last_sysupgrade_partition
= "support-list",
463 /** Firmware layout for the CPE610V1 */
466 .vendor
= "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n",
469 "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n"
470 "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n"
471 "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n"
472 "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n"
473 "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n"
474 "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n"
475 "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n"
476 "CPE610(TP-LINK|UN|N300-5):1.0\r\n"
477 "CPE610(TP-LINK|EU|N300-5):1.0\r\n"
478 "CPE610(TP-LINK|US|N300-5):1.0\r\n",
483 {"fs-uboot", 0x00000, 0x20000},
484 {"partition-table", 0x20000, 0x02000},
485 {"default-mac", 0x30000, 0x00020},
486 {"product-info", 0x31100, 0x00100},
487 {"signature", 0x32000, 0x00400},
488 {"os-image", 0x40000, 0x300000},
489 {"file-system", 0x340000, 0x470000},
490 {"soft-version", 0x7b0000, 0x00100},
491 {"support-list", 0x7b1000, 0x00400},
492 {"user-config", 0x7c0000, 0x10000},
493 {"default-config", 0x7d0000, 0x10000},
494 {"log", 0x7e0000, 0x10000},
495 {"radio", 0x7f0000, 0x10000},
499 .first_sysupgrade_partition
= "os-image",
500 .last_sysupgrade_partition
= "support-list",
503 /** Firmware layout for the CPE610V2 */
506 .vendor
= "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n",
509 "CPE610(TP-LINK|EU|N300-5|00000000):2.0\r\n"
510 "CPE610(TP-LINK|EU|N300-5|45550000):2.0\r\n"
511 "CPE610(TP-LINK|EU|N300-5|55530000):2.0\r\n"
512 "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n"
513 "CPE610(TP-LINK|UN|N300-5|45550000):2.0\r\n"
514 "CPE610(TP-LINK|UN|N300-5|55530000):2.0\r\n"
515 "CPE610(TP-LINK|US|N300-5|55530000):2.0\r\n"
516 "CPE610(TP-LINK|UN|N300-5):2.0\r\n"
517 "CPE610(TP-LINK|EU|N300-5):2.0\r\n"
518 "CPE610(TP-LINK|US|N300-5):2.0\r\n",
523 {"fs-uboot", 0x00000, 0x20000},
524 {"partition-table", 0x20000, 0x02000},
525 {"default-mac", 0x30000, 0x00020},
526 {"product-info", 0x31100, 0x00100},
527 {"signature", 0x32000, 0x00400},
528 {"os-image", 0x40000, 0x300000},
529 {"file-system", 0x340000, 0x470000},
530 {"soft-version", 0x7b0000, 0x00100},
531 {"support-list", 0x7b1000, 0x00400},
532 {"user-config", 0x7c0000, 0x10000},
533 {"default-config", 0x7d0000, 0x10000},
534 {"log", 0x7e0000, 0x10000},
535 {"radio", 0x7f0000, 0x10000},
539 .first_sysupgrade_partition
= "os-image",
540 .last_sysupgrade_partition
= "support-list",
545 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
548 "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
549 "WBS210(TP-LINK|US|N300-2):1.20\r\n"
550 "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
555 {"fs-uboot", 0x00000, 0x20000},
556 {"partition-table", 0x20000, 0x02000},
557 {"default-mac", 0x30000, 0x00020},
558 {"product-info", 0x31100, 0x00100},
559 {"signature", 0x32000, 0x00400},
560 {"os-image", 0x40000, 0x300000},
561 {"file-system", 0x340000, 0x470000},
562 {"soft-version", 0x7b0000, 0x00100},
563 {"support-list", 0x7b1000, 0x00400},
564 {"user-config", 0x7c0000, 0x10000},
565 {"default-config", 0x7d0000, 0x10000},
566 {"log", 0x7e0000, 0x10000},
567 {"radio", 0x7f0000, 0x10000},
571 .first_sysupgrade_partition
= "os-image",
572 .last_sysupgrade_partition
= "support-list",
577 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
580 "WBS210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
581 "WBS210(TP-LINK|US|N300-2|55530000):2.0\r\n"
582 "WBS210(TP-LINK|EU|N300-2|45550000):2.0\r\n",
587 {"fs-uboot", 0x00000, 0x20000},
588 {"partition-table", 0x20000, 0x02000},
589 {"default-mac", 0x30000, 0x00020},
590 {"product-info", 0x31100, 0x00100},
591 {"signature", 0x32000, 0x00400},
592 {"os-image", 0x40000, 0x300000},
593 {"file-system", 0x340000, 0x470000},
594 {"soft-version", 0x7b0000, 0x00100},
595 {"support-list", 0x7b1000, 0x00400},
596 {"user-config", 0x7c0000, 0x10000},
597 {"default-config", 0x7d0000, 0x10000},
598 {"log", 0x7e0000, 0x10000},
599 {"radio", 0x7f0000, 0x10000},
603 .first_sysupgrade_partition
= "os-image",
604 .last_sysupgrade_partition
= "support-list",
609 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
612 "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
613 "WBS510(TP-LINK|US|N300-5):1.20\r\n"
614 "WBS510(TP-LINK|EU|N300-5):1.20\r\n"
615 "WBS510(TP-LINK|CA|N300-5):1.20\r\n",
620 {"fs-uboot", 0x00000, 0x20000},
621 {"partition-table", 0x20000, 0x02000},
622 {"default-mac", 0x30000, 0x00020},
623 {"product-info", 0x31100, 0x00100},
624 {"signature", 0x32000, 0x00400},
625 {"os-image", 0x40000, 0x300000},
626 {"file-system", 0x340000, 0x470000},
627 {"soft-version", 0x7b0000, 0x00100},
628 {"support-list", 0x7b1000, 0x00400},
629 {"user-config", 0x7c0000, 0x10000},
630 {"default-config", 0x7d0000, 0x10000},
631 {"log", 0x7e0000, 0x10000},
632 {"radio", 0x7f0000, 0x10000},
636 .first_sysupgrade_partition
= "os-image",
637 .last_sysupgrade_partition
= "support-list",
642 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
645 "WBS510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
646 "WBS510(TP-LINK|US|N300-5|55530000):2.0\r\n"
647 "WBS510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
648 "WBS510(TP-LINK|CA|N300-5|43410000):2.0\r\n",
653 {"fs-uboot", 0x00000, 0x20000},
654 {"partition-table", 0x20000, 0x02000},
655 {"default-mac", 0x30000, 0x00020},
656 {"product-info", 0x31100, 0x00100},
657 {"signature", 0x32000, 0x00400},
658 {"os-image", 0x40000, 0x300000},
659 {"file-system", 0x340000, 0x470000},
660 {"soft-version", 0x7b0000, 0x00100},
661 {"support-list", 0x7b1000, 0x00400},
662 {"user-config", 0x7c0000, 0x10000},
663 {"default-config", 0x7d0000, 0x10000},
664 {"log", 0x7e0000, 0x10000},
665 {"radio", 0x7f0000, 0x10000},
669 .first_sysupgrade_partition
= "os-image",
670 .last_sysupgrade_partition
= "support-list",
673 /** Firmware layout for the AD7200 */
679 "{product_name:AD7200,product_ver:1.0.0,special_id:00000000}\r\n",
684 {"SBL1", 0x00000, 0x20000},
685 {"MIBIB", 0x20000, 0x20000},
686 {"SBL2", 0x40000, 0x20000},
687 {"SBL3", 0x60000, 0x30000},
688 {"DDRCONFIG", 0x90000, 0x10000},
689 {"SSD", 0xa0000, 0x10000},
690 {"TZ", 0xb0000, 0x30000},
691 {"RPM", 0xe0000, 0x20000},
692 {"fs-uboot", 0x100000, 0x70000},
693 {"uboot-env", 0x170000, 0x40000},
694 {"radio", 0x1b0000, 0x40000},
695 {"os-image", 0x1f0000, 0x400000},
696 {"file-system", 0x5f0000, 0x1900000},
697 {"default-mac", 0x1ef0000, 0x00200},
698 {"pin", 0x1ef0200, 0x00200},
699 {"device-id", 0x1ef0400, 0x00200},
700 {"product-info", 0x1ef0600, 0x0fa00},
701 {"partition-table", 0x1f00000, 0x10000},
702 {"soft-version", 0x1f10000, 0x10000},
703 {"support-list", 0x1f20000, 0x10000},
704 {"profile", 0x1f30000, 0x10000},
705 {"default-config", 0x1f40000, 0x10000},
706 {"user-config", 0x1f50000, 0x40000},
707 {"qos-db", 0x1f90000, 0x40000},
708 {"usb-config", 0x1fd0000, 0x10000},
709 {"log", 0x1fe0000, 0x20000},
713 .first_sysupgrade_partition
= "os-image",
714 .last_sysupgrade_partition
= "file-system"
717 /** Firmware layout for the C2600 */
723 "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
728 We use a bigger os-image partition than the stock images (and thus
729 smaller file-system), as our kernel doesn't fit in the stock firmware's
730 2 MB os-image since kernel 4.14.
733 {"SBL1", 0x00000, 0x20000},
734 {"MIBIB", 0x20000, 0x20000},
735 {"SBL2", 0x40000, 0x20000},
736 {"SBL3", 0x60000, 0x30000},
737 {"DDRCONFIG", 0x90000, 0x10000},
738 {"SSD", 0xa0000, 0x10000},
739 {"TZ", 0xb0000, 0x30000},
740 {"RPM", 0xe0000, 0x20000},
741 {"fs-uboot", 0x100000, 0x70000},
742 {"uboot-env", 0x170000, 0x40000},
743 {"radio", 0x1b0000, 0x40000},
744 {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
745 {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
746 {"default-mac", 0x1ef0000, 0x00200},
747 {"pin", 0x1ef0200, 0x00200},
748 {"product-info", 0x1ef0400, 0x0fc00},
749 {"partition-table", 0x1f00000, 0x10000},
750 {"soft-version", 0x1f10000, 0x10000},
751 {"support-list", 0x1f20000, 0x10000},
752 {"profile", 0x1f30000, 0x10000},
753 {"default-config", 0x1f40000, 0x10000},
754 {"user-config", 0x1f50000, 0x40000},
755 {"qos-db", 0x1f90000, 0x40000},
756 {"usb-config", 0x1fd0000, 0x10000},
757 {"log", 0x1fe0000, 0x20000},
761 .first_sysupgrade_partition
= "os-image",
762 .last_sysupgrade_partition
= "file-system"
765 /** Firmware layout for the A7-V5 */
767 .id
= "ARCHER-A7-V5",
770 "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n"
771 "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n"
772 "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n"
773 "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n"
774 "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n"
775 "{product_name:Archer A7,product_ver:5.0.0,special_id:52550000}\n",
777 .soft_ver
= "soft_ver:1.0.0\n",
779 /* We're using a dynamic kernel/rootfs split here */
781 {"factory-boot", 0x00000, 0x20000},
782 {"fs-uboot", 0x20000, 0x20000},
783 {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
784 /* Stock: name file-system base 0x160000 size 0xda0000 */
785 {"default-mac", 0xf40000, 0x00200},
786 {"pin", 0xf40200, 0x00200},
787 {"device-id", 0xf40400, 0x00100},
788 {"product-info", 0xf40500, 0x0fb00},
789 {"soft-version", 0xf50000, 0x00100},
790 {"extra-para", 0xf51000, 0x01000},
791 {"support-list", 0xf52000, 0x0a000},
792 {"profile", 0xf5c000, 0x04000},
793 {"default-config", 0xf60000, 0x10000},
794 {"user-config", 0xf70000, 0x40000},
795 {"certificate", 0xfb0000, 0x10000},
796 {"partition-table", 0xfc0000, 0x10000},
797 {"log", 0xfd0000, 0x20000},
798 {"radio", 0xff0000, 0x10000},
802 .first_sysupgrade_partition
= "os-image",
803 .last_sysupgrade_partition
= "file-system",
806 /** Firmware layout for the C2v3 */
808 .id
= "ARCHER-C2-V3",
811 "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n"
812 "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n"
813 "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n",
815 .soft_ver
= "soft_ver:3.0.1\n",
817 /** We're using a dynamic kernel/rootfs split here */
820 {"factory-boot", 0x00000, 0x20000},
821 {"fs-uboot", 0x20000, 0x10000},
822 {"firmware", 0x30000, 0x7a0000},
823 {"user-config", 0x7d0000, 0x04000},
824 {"default-mac", 0x7e0000, 0x00100},
825 {"device-id", 0x7e0100, 0x00100},
826 {"extra-para", 0x7e0200, 0x00100},
827 {"pin", 0x7e0300, 0x00100},
828 {"support-list", 0x7e0400, 0x00400},
829 {"soft-version", 0x7e0800, 0x00400},
830 {"product-info", 0x7e0c00, 0x01400},
831 {"partition-table", 0x7e2000, 0x01000},
832 {"profile", 0x7e3000, 0x01000},
833 {"default-config", 0x7e4000, 0x04000},
834 {"merge-config", 0x7ec000, 0x02000},
835 {"qos-db", 0x7ee000, 0x02000},
836 {"radio", 0x7f0000, 0x10000},
840 .first_sysupgrade_partition
= "os-image",
841 .last_sysupgrade_partition
= "file-system",
844 /** Firmware layout for the C25v1 */
846 .id
= "ARCHER-C25-V1",
849 "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
850 "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
851 "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
853 .soft_ver
= "soft_ver:1.0.0\n",
855 /* We're using a dynamic kernel/rootfs split here */
857 {"factory-boot", 0x00000, 0x20000},
858 {"fs-uboot", 0x20000, 0x10000},
859 {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */
860 /* Stock: name file-system base 0x130000 size 0x6a0000 */
861 {"user-config", 0x7d0000, 0x04000},
862 {"default-mac", 0x7e0000, 0x00100},
863 {"device-id", 0x7e0100, 0x00100},
864 {"extra-para", 0x7e0200, 0x00100},
865 {"pin", 0x7e0300, 0x00100},
866 {"support-list", 0x7e0400, 0x00400},
867 {"soft-version", 0x7e0800, 0x00400},
868 {"product-info", 0x7e0c00, 0x01400},
869 {"partition-table", 0x7e2000, 0x01000},
870 {"profile", 0x7e3000, 0x01000},
871 {"default-config", 0x7e4000, 0x04000},
872 {"merge-config", 0x7ec000, 0x02000},
873 {"qos-db", 0x7ee000, 0x02000},
874 {"radio", 0x7f0000, 0x10000},
878 .first_sysupgrade_partition
= "os-image",
879 .last_sysupgrade_partition
= "file-system",
882 /** Firmware layout for the C58v1 */
884 .id
= "ARCHER-C58-V1",
888 "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
889 "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
890 "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
892 .soft_ver
= "soft_ver:1.0.0\n",
895 {"fs-uboot", 0x00000, 0x10000},
896 {"default-mac", 0x10000, 0x00200},
897 {"pin", 0x10200, 0x00200},
898 {"product-info", 0x10400, 0x00100},
899 {"partition-table", 0x10500, 0x00800},
900 {"soft-version", 0x11300, 0x00200},
901 {"support-list", 0x11500, 0x00100},
902 {"device-id", 0x11600, 0x00100},
903 {"profile", 0x11700, 0x03900},
904 {"default-config", 0x15000, 0x04000},
905 {"user-config", 0x19000, 0x04000},
906 {"firmware", 0x20000, 0x7c8000},
907 {"certyficate", 0x7e8000, 0x08000},
908 {"radio", 0x7f0000, 0x10000},
912 .first_sysupgrade_partition
= "os-image",
913 .last_sysupgrade_partition
= "file-system",
916 /** Firmware layout for the C59v1 */
918 .id
= "ARCHER-C59-V1",
922 "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
923 "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
924 "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
925 "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
927 .soft_ver
= "soft_ver:1.0.0\n",
929 /* We're using a dynamic kernel/rootfs split here */
931 {"fs-uboot", 0x00000, 0x10000},
932 {"default-mac", 0x10000, 0x00200},
933 {"pin", 0x10200, 0x00200},
934 {"device-id", 0x10400, 0x00100},
935 {"product-info", 0x10500, 0x0fb00},
936 {"firmware", 0x20000, 0xe30000},
937 {"partition-table", 0xe50000, 0x10000},
938 {"soft-version", 0xe60000, 0x10000},
939 {"support-list", 0xe70000, 0x10000},
940 {"profile", 0xe80000, 0x10000},
941 {"default-config", 0xe90000, 0x10000},
942 {"user-config", 0xea0000, 0x40000},
943 {"usb-config", 0xee0000, 0x10000},
944 {"certificate", 0xef0000, 0x10000},
945 {"qos-db", 0xf00000, 0x40000},
946 {"log", 0xfe0000, 0x10000},
947 {"radio", 0xff0000, 0x10000},
951 .first_sysupgrade_partition
= "os-image",
952 .last_sysupgrade_partition
= "file-system",
955 /** Firmware layout for the C59v2 */
957 .id
= "ARCHER-C59-V2",
961 "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
962 "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
963 "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
965 .soft_ver
= "soft_ver:2.0.0 Build 20161206 rel.7303\n",
967 /** We're using a dynamic kernel/rootfs split here */
969 {"factory-boot", 0x00000, 0x20000},
970 {"fs-uboot", 0x20000, 0x10000},
971 {"default-mac", 0x30000, 0x00200},
972 {"pin", 0x30200, 0x00200},
973 {"device-id", 0x30400, 0x00100},
974 {"product-info", 0x30500, 0x0fb00},
975 {"firmware", 0x40000, 0xe10000},
976 {"partition-table", 0xe50000, 0x10000},
977 {"soft-version", 0xe60000, 0x10000},
978 {"support-list", 0xe70000, 0x10000},
979 {"profile", 0xe80000, 0x10000},
980 {"default-config", 0xe90000, 0x10000},
981 {"user-config", 0xea0000, 0x40000},
982 {"usb-config", 0xee0000, 0x10000},
983 {"certificate", 0xef0000, 0x10000},
984 {"extra-para", 0xf00000, 0x10000},
985 {"qos-db", 0xf10000, 0x30000},
986 {"log", 0xfe0000, 0x10000},
987 {"radio", 0xff0000, 0x10000},
991 .first_sysupgrade_partition
= "os-image",
992 .last_sysupgrade_partition
= "file-system",
995 /** Firmware layout for the Archer C6 v2 (EU/RU/JP) */
997 .id
= "ARCHER-C6-V2",
1001 "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n"
1002 "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
1003 "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
1005 .soft_ver
= "soft_ver:1.9.1\n",
1008 {"fs-uboot", 0x00000, 0x20000},
1009 {"default-mac", 0x20000, 0x00200},
1010 {"pin", 0x20200, 0x00100},
1011 {"product-info", 0x20300, 0x00200},
1012 {"device-id", 0x20500, 0x0fb00},
1013 {"firmware", 0x30000, 0x7a9400},
1014 {"soft-version", 0x7d9400, 0x00100},
1015 {"extra-para", 0x7d9500, 0x00100},
1016 {"support-list", 0x7d9600, 0x00200},
1017 {"profile", 0x7d9800, 0x03000},
1018 {"default-config", 0x7dc800, 0x03000},
1019 {"partition-table", 0x7df800, 0x00800},
1020 {"user-config", 0x7e0000, 0x0c000},
1021 {"certificate", 0x7ec000, 0x04000},
1022 {"radio", 0x7f0000, 0x10000},
1026 .first_sysupgrade_partition
= "os-image",
1027 .last_sysupgrade_partition
= "file-system",
1030 /** Firmware layout for the Archer C6 v2 (US) and A6 v2 (US/TW) */
1032 .id
= "ARCHER-C6-V2-US",
1036 "{product_name:Archer A6,product_ver:2.0.0,special_id:55530000}\n"
1037 "{product_name:Archer A6,product_ver:2.0.0,special_id:54570000}\n"
1038 "{product_name:Archer C6,product_ver:2.0.0,special_id:55530000}\n",
1040 .soft_ver
= "soft_ver:1.9.1\n",
1043 {"factory-boot", 0x00000, 0x20000},
1044 {"default-mac", 0x20000, 0x00200},
1045 {"pin", 0x20200, 0x00100},
1046 {"product-info", 0x20300, 0x00200},
1047 {"device-id", 0x20500, 0x0fb00},
1048 {"fs-uboot", 0x30000, 0x20000},
1049 {"firmware", 0x50000, 0xf89400},
1050 {"soft-version", 0xfd9400, 0x00100},
1051 {"extra-para", 0xfd9500, 0x00100},
1052 {"support-list", 0xfd9600, 0x00200},
1053 {"profile", 0xfd9800, 0x03000},
1054 {"default-config", 0xfdc800, 0x03000},
1055 {"partition-table", 0xfdf800, 0x00800},
1056 {"user-config", 0xfe0000, 0x0c000},
1057 {"certificate", 0xfec000, 0x04000},
1058 {"radio", 0xff0000, 0x10000},
1061 .first_sysupgrade_partition
= "os-image",
1062 .last_sysupgrade_partition
= "file-system",
1065 /** Firmware layout for the C60v1 */
1067 .id
= "ARCHER-C60-V1",
1071 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
1072 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
1073 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
1075 .soft_ver
= "soft_ver:1.0.0\n",
1078 {"fs-uboot", 0x00000, 0x10000},
1079 {"default-mac", 0x10000, 0x00200},
1080 {"pin", 0x10200, 0x00200},
1081 {"product-info", 0x10400, 0x00100},
1082 {"partition-table", 0x10500, 0x00800},
1083 {"soft-version", 0x11300, 0x00200},
1084 {"support-list", 0x11500, 0x00100},
1085 {"device-id", 0x11600, 0x00100},
1086 {"profile", 0x11700, 0x03900},
1087 {"default-config", 0x15000, 0x04000},
1088 {"user-config", 0x19000, 0x04000},
1089 {"firmware", 0x20000, 0x7c8000},
1090 {"certyficate", 0x7e8000, 0x08000},
1091 {"radio", 0x7f0000, 0x10000},
1095 .first_sysupgrade_partition
= "os-image",
1096 .last_sysupgrade_partition
= "file-system",
1099 /** Firmware layout for the C60v2 */
1101 .id
= "ARCHER-C60-V2",
1105 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
1106 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
1107 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
1109 .soft_ver
= "soft_ver:2.0.0\n",
1112 {"factory-boot", 0x00000, 0x1fb00},
1113 {"default-mac", 0x1fb00, 0x00200},
1114 {"pin", 0x1fd00, 0x00100},
1115 {"product-info", 0x1fe00, 0x00100},
1116 {"device-id", 0x1ff00, 0x00100},
1117 {"fs-uboot", 0x20000, 0x10000},
1118 {"firmware", 0x30000, 0x7a0000},
1119 {"soft-version", 0x7d9500, 0x00100},
1120 {"support-list", 0x7d9600, 0x00100},
1121 {"extra-para", 0x7d9700, 0x00100},
1122 {"profile", 0x7d9800, 0x03000},
1123 {"default-config", 0x7dc800, 0x03000},
1124 {"partition-table", 0x7df800, 0x00800},
1125 {"user-config", 0x7e0000, 0x0c000},
1126 {"certificate", 0x7ec000, 0x04000},
1127 {"radio", 0x7f0000, 0x10000},
1131 .first_sysupgrade_partition
= "os-image",
1132 .last_sysupgrade_partition
= "file-system",
1135 /** Firmware layout for the C60v3 */
1137 .id
= "ARCHER-C60-V3",
1141 "{product_name:Archer C60,product_ver:3.0.0,special_id:42520000}\r\n"
1142 "{product_name:Archer C60,product_ver:3.0.0,special_id:45550000}\r\n"
1143 "{product_name:Archer C60,product_ver:3.0.0,special_id:55530000}\r\n",
1145 .soft_ver
= "soft_ver:3.0.0\n",
1148 {"factory-boot", 0x00000, 0x1fb00},
1149 {"default-mac", 0x1fb00, 0x00200},
1150 {"pin", 0x1fd00, 0x00100},
1151 {"product-info", 0x1fe00, 0x00100},
1152 {"device-id", 0x1ff00, 0x00100},
1153 {"fs-uboot", 0x20000, 0x10000},
1154 {"firmware", 0x30000, 0x7a0000},
1155 {"soft-version", 0x7d9500, 0x00100},
1156 {"support-list", 0x7d9600, 0x00100},
1157 {"extra-para", 0x7d9700, 0x00100},
1158 {"profile", 0x7d9800, 0x03000},
1159 {"default-config", 0x7dc800, 0x03000},
1160 {"partition-table", 0x7df800, 0x00800},
1161 {"user-config", 0x7e0000, 0x0c000},
1162 {"certificate", 0x7ec000, 0x04000},
1163 {"radio", 0x7f0000, 0x10000},
1167 .first_sysupgrade_partition
= "os-image",
1168 .last_sysupgrade_partition
= "file-system",
1171 /** Firmware layout for the C5 */
1173 .id
= "ARCHER-C5-V2",
1177 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
1178 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
1179 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
1184 {"fs-uboot", 0x00000, 0x40000},
1185 {"os-image", 0x40000, 0x200000},
1186 {"file-system", 0x240000, 0xc00000},
1187 {"default-mac", 0xe40000, 0x00200},
1188 {"pin", 0xe40200, 0x00200},
1189 {"product-info", 0xe40400, 0x00200},
1190 {"partition-table", 0xe50000, 0x10000},
1191 {"soft-version", 0xe60000, 0x00200},
1192 {"support-list", 0xe61000, 0x0f000},
1193 {"profile", 0xe70000, 0x10000},
1194 {"default-config", 0xe80000, 0x10000},
1195 {"user-config", 0xe90000, 0x50000},
1196 {"log", 0xee0000, 0x100000},
1197 {"radio_bk", 0xfe0000, 0x10000},
1198 {"radio", 0xff0000, 0x10000},
1202 .first_sysupgrade_partition
= "os-image",
1203 .last_sysupgrade_partition
= "file-system"
1206 /** Firmware layout for the C7 */
1208 .id
= "ARCHER-C7-V4",
1211 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
1212 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
1213 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
1214 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
1215 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
1216 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
1217 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
1218 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
1219 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
1220 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
1222 .soft_ver
= "soft_ver:1.0.0\n",
1224 /* We're using a dynamic kernel/rootfs split here */
1226 {"factory-boot", 0x00000, 0x20000},
1227 {"fs-uboot", 0x20000, 0x20000},
1228 {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
1229 /* Stock: name file-system base 0x160000 size 0xda0000 */
1230 {"default-mac", 0xf00000, 0x00200},
1231 {"pin", 0xf00200, 0x00200},
1232 {"device-id", 0xf00400, 0x00100},
1233 {"product-info", 0xf00500, 0x0fb00},
1234 {"soft-version", 0xf10000, 0x00100},
1235 {"extra-para", 0xf11000, 0x01000},
1236 {"support-list", 0xf12000, 0x0a000},
1237 {"profile", 0xf1c000, 0x04000},
1238 {"default-config", 0xf20000, 0x10000},
1239 {"user-config", 0xf30000, 0x40000},
1240 {"qos-db", 0xf70000, 0x40000},
1241 {"certificate", 0xfb0000, 0x10000},
1242 {"partition-table", 0xfc0000, 0x10000},
1243 {"log", 0xfd0000, 0x20000},
1244 {"radio", 0xff0000, 0x10000},
1248 .first_sysupgrade_partition
= "os-image",
1249 .last_sysupgrade_partition
= "file-system",
1252 /** Firmware layout for the C7 v5*/
1254 .id
= "ARCHER-C7-V5",
1257 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1258 "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1259 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1260 "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1261 "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1262 "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1263 "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1264 "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1267 .soft_ver
= "soft_ver:7.0.0\n",
1269 /* We're using a dynamic kernel/rootfs split here */
1271 {"factory-boot", 0x00000, 0x20000},
1272 {"fs-uboot", 0x20000, 0x20000},
1273 {"partition-table", 0x40000, 0x10000},
1274 {"radio", 0x50000, 0x10000},
1275 {"default-mac", 0x60000, 0x00200},
1276 {"pin", 0x60200, 0x00200},
1277 {"device-id", 0x60400, 0x00100},
1278 {"product-info", 0x60500, 0x0fb00},
1279 {"soft-version", 0x70000, 0x01000},
1280 {"extra-para", 0x71000, 0x01000},
1281 {"support-list", 0x72000, 0x0a000},
1282 {"profile", 0x7c000, 0x04000},
1283 {"user-config", 0x80000, 0x40000},
1286 {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */
1287 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1289 {"log", 0xfc0000, 0x20000},
1290 {"certificate", 0xfe0000, 0x10000},
1291 {"default-config", 0xff0000, 0x10000},
1296 .first_sysupgrade_partition
= "os-image",
1297 .last_sysupgrade_partition
= "file-system",
1300 /** Firmware layout for the C9 */
1306 "{product_name:ArcherC9,"
1307 "product_ver:1.0.0,"
1308 "special_id:00000000}\n",
1313 {"fs-uboot", 0x00000, 0x40000},
1314 {"os-image", 0x40000, 0x200000},
1315 {"file-system", 0x240000, 0xc00000},
1316 {"default-mac", 0xe40000, 0x00200},
1317 {"pin", 0xe40200, 0x00200},
1318 {"product-info", 0xe40400, 0x00200},
1319 {"partition-table", 0xe50000, 0x10000},
1320 {"soft-version", 0xe60000, 0x00200},
1321 {"support-list", 0xe61000, 0x0f000},
1322 {"profile", 0xe70000, 0x10000},
1323 {"default-config", 0xe80000, 0x10000},
1324 {"user-config", 0xe90000, 0x50000},
1325 {"log", 0xee0000, 0x100000},
1326 {"radio_bk", 0xfe0000, 0x10000},
1327 {"radio", 0xff0000, 0x10000},
1331 .first_sysupgrade_partition
= "os-image",
1332 .last_sysupgrade_partition
= "file-system"
1335 /** Firmware layout for the EAP120 */
1338 .vendor
= "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1341 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1346 {"fs-uboot", 0x00000, 0x20000},
1347 {"partition-table", 0x20000, 0x02000},
1348 {"default-mac", 0x30000, 0x00020},
1349 {"support-list", 0x31000, 0x00100},
1350 {"product-info", 0x31100, 0x00100},
1351 {"soft-version", 0x32000, 0x00100},
1352 {"os-image", 0x40000, 0x180000},
1353 {"file-system", 0x1c0000, 0x600000},
1354 {"user-config", 0x7c0000, 0x10000},
1355 {"backup-config", 0x7d0000, 0x10000},
1356 {"log", 0x7e0000, 0x10000},
1357 {"radio", 0x7f0000, 0x10000},
1361 .first_sysupgrade_partition
= "os-image",
1362 .last_sysupgrade_partition
= "file-system"
1365 /** Firmware layout for the EAP225-Outdoor v1 */
1367 .id
= "EAP225-OUTDOOR-V1",
1370 "EAP225-Outdoor(TP-Link|UN|AC1200-D):1.0\r\n",
1371 .part_trail
= PART_TRAIL_NONE
,
1373 .soft_ver_compat_level
= 1,
1376 {"fs-uboot", 0x00000, 0x20000},
1377 {"partition-table", 0x20000, 0x02000},
1378 {"default-mac", 0x30000, 0x01000},
1379 {"support-list", 0x31000, 0x00100},
1380 {"product-info", 0x31100, 0x00400},
1381 {"soft-version", 0x32000, 0x00100},
1382 {"firmware", 0x40000, 0xd80000},
1383 {"user-config", 0xdc0000, 0x30000},
1384 {"mutil-log", 0xf30000, 0x80000},
1385 {"oops", 0xfb0000, 0x40000},
1386 {"radio", 0xff0000, 0x10000},
1390 .first_sysupgrade_partition
= "os-image",
1391 .last_sysupgrade_partition
= "file-system"
1394 /** Firmware layout for the EAP225 v3 */
1399 "EAP225(TP-Link|UN|AC1350-D):3.0\r\n",
1400 .part_trail
= PART_TRAIL_NONE
,
1402 .soft_ver_compat_level
= 1,
1405 {"fs-uboot", 0x00000, 0x20000},
1406 {"partition-table", 0x20000, 0x02000},
1407 {"default-mac", 0x30000, 0x01000},
1408 {"support-list", 0x31000, 0x00100},
1409 {"product-info", 0x31100, 0x00400},
1410 {"soft-version", 0x32000, 0x00100},
1411 {"firmware", 0x40000, 0xd80000},
1412 {"user-config", 0xdc0000, 0x30000},
1413 {"mutil-log", 0xf30000, 0x80000},
1414 {"oops", 0xfb0000, 0x40000},
1415 {"radio", 0xff0000, 0x10000},
1419 .first_sysupgrade_partition
= "os-image",
1420 .last_sysupgrade_partition
= "file-system"
1423 /** Firmware layout for the EAP225-Wall v2 */
1425 .id
= "EAP225-WALL-V2",
1428 "EAP225-Wall(TP-Link|UN|AC1200-D):2.0\r\n",
1429 .part_trail
= PART_TRAIL_NONE
,
1431 .soft_ver_compat_level
= 1,
1434 {"fs-uboot", 0x00000, 0x20000},
1435 {"partition-table", 0x20000, 0x02000},
1436 {"default-mac", 0x30000, 0x01000},
1437 {"support-list", 0x31000, 0x00100},
1438 {"product-info", 0x31100, 0x00400},
1439 {"soft-version", 0x32000, 0x00100},
1440 {"firmware", 0x40000, 0xd80000},
1441 {"user-config", 0xdc0000, 0x30000},
1442 {"mutil-log", 0xf30000, 0x80000},
1443 {"oops", 0xfb0000, 0x40000},
1444 {"radio", 0xff0000, 0x10000},
1448 .first_sysupgrade_partition
= "os-image",
1449 .last_sysupgrade_partition
= "file-system"
1452 /** Firmware layout for the EAP235-Wall v1 */
1454 .id
= "EAP235-WALL-V1",
1457 "EAP235-Wall(TP-Link|UN|AC1200-D):1.0\r\n",
1458 .part_trail
= PART_TRAIL_NONE
,
1460 .soft_ver_compat_level
= 1,
1463 {"fs-uboot", 0x00000, 0x80000},
1464 {"partition-table", 0x80000, 0x02000},
1465 {"default-mac", 0x90000, 0x01000},
1466 {"support-list", 0x91000, 0x00100},
1467 {"product-info", 0x91100, 0x00400},
1468 {"soft-version", 0x92000, 0x00100},
1469 {"firmware", 0xa0000, 0xd20000},
1470 {"user-config", 0xdc0000, 0x30000},
1471 {"mutil-log", 0xf30000, 0x80000},
1472 {"oops", 0xfb0000, 0x40000},
1473 {"radio", 0xff0000, 0x10000},
1477 .first_sysupgrade_partition
= "os-image",
1478 .last_sysupgrade_partition
= "file-system"
1481 /** Firmware layout for the EAP245 v1 */
1486 "EAP245(TP-LINK|UN|AC1750-D):1.0\r\n",
1487 .part_trail
= PART_TRAIL_NONE
,
1491 {"fs-uboot", 0x00000, 0x20000},
1492 {"partition-table", 0x20000, 0x02000},
1493 {"default-mac", 0x30000, 0x01000},
1494 {"support-list", 0x31000, 0x00100},
1495 {"product-info", 0x31100, 0x00400},
1496 {"soft-version", 0x32000, 0x00100},
1497 {"firmware", 0x40000, 0xd80000},
1498 {"user-config", 0xdc0000, 0x30000},
1499 {"radio", 0xff0000, 0x10000},
1503 .first_sysupgrade_partition
= "os-image",
1504 .last_sysupgrade_partition
= "file-system"
1507 /** Firmware layout for the EAP245 v3 */
1512 "EAP245(TP-Link|UN|AC1750-D):3.0\r\n",
1513 .part_trail
= PART_TRAIL_NONE
,
1515 .soft_ver_compat_level
= 1,
1517 /** Firmware partition with dynamic kernel/rootfs split */
1519 {"factroy-boot", 0x00000, 0x40000},
1520 {"fs-uboot", 0x40000, 0x40000},
1521 {"partition-table", 0x80000, 0x10000},
1522 {"default-mac", 0x90000, 0x01000},
1523 {"support-list", 0x91000, 0x00100},
1524 {"product-info", 0x91100, 0x00400},
1525 {"soft-version", 0x92000, 0x00100},
1526 {"radio", 0xa0000, 0x10000},
1527 {"extra-para", 0xb0000, 0x10000},
1528 {"firmware", 0xc0000, 0xe40000},
1529 {"config", 0xf00000, 0x30000},
1530 {"mutil-log", 0xf30000, 0x80000},
1531 {"oops", 0xfb0000, 0x40000},
1535 .first_sysupgrade_partition
= "os-image",
1536 .last_sysupgrade_partition
= "file-system"
1539 /** Firmware layout for the TL-WA850RE v2 */
1541 .id
= "TLWA850REV2",
1545 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1546 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1547 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1548 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1549 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1550 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1551 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1552 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1553 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1554 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1559 576KB were moved from file-system to os-image
1560 in comparison to the stock image
1563 {"fs-uboot", 0x00000, 0x20000},
1564 {"firmware", 0x20000, 0x390000},
1565 {"partition-table", 0x3b0000, 0x02000},
1566 {"default-mac", 0x3c0000, 0x00020},
1567 {"pin", 0x3c0100, 0x00020},
1568 {"product-info", 0x3c1000, 0x01000},
1569 {"soft-version", 0x3c2000, 0x00100},
1570 {"support-list", 0x3c3000, 0x01000},
1571 {"profile", 0x3c4000, 0x08000},
1572 {"user-config", 0x3d0000, 0x10000},
1573 {"default-config", 0x3e0000, 0x10000},
1574 {"radio", 0x3f0000, 0x10000},
1578 .first_sysupgrade_partition
= "os-image",
1579 .last_sysupgrade_partition
= "file-system"
1582 /** Firmware layout for the TL-WA855RE v1 */
1584 .id
= "TLWA855REV1",
1588 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1589 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1590 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1591 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1592 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1593 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1594 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1595 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1596 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1601 {"fs-uboot", 0x00000, 0x20000},
1602 {"os-image", 0x20000, 0x150000},
1603 {"file-system", 0x170000, 0x240000},
1604 {"partition-table", 0x3b0000, 0x02000},
1605 {"default-mac", 0x3c0000, 0x00020},
1606 {"pin", 0x3c0100, 0x00020},
1607 {"product-info", 0x3c1000, 0x01000},
1608 {"soft-version", 0x3c2000, 0x00100},
1609 {"support-list", 0x3c3000, 0x01000},
1610 {"profile", 0x3c4000, 0x08000},
1611 {"user-config", 0x3d0000, 0x10000},
1612 {"default-config", 0x3e0000, 0x10000},
1613 {"radio", 0x3f0000, 0x10000},
1617 .first_sysupgrade_partition
= "os-image",
1618 .last_sysupgrade_partition
= "file-system"
1621 /** Firmware layout for the TL-WPA8630P v2 (EU)*/
1623 .id
= "TL-WPA8630P-V2.0-EU",
1627 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
1632 {"factory-uboot", 0x00000, 0x20000},
1633 {"fs-uboot", 0x20000, 0x20000},
1634 {"firmware", 0x40000, 0x5e0000},
1635 {"partition-table", 0x620000, 0x02000},
1636 {"default-mac", 0x630000, 0x00020},
1637 {"pin", 0x630100, 0x00020},
1638 {"device-id", 0x630200, 0x00030},
1639 {"product-info", 0x631100, 0x01000},
1640 {"extra-para", 0x632100, 0x01000},
1641 {"soft-version", 0x640000, 0x01000},
1642 {"support-list", 0x641000, 0x01000},
1643 {"profile", 0x642000, 0x08000},
1644 {"user-config", 0x650000, 0x10000},
1645 {"default-config", 0x660000, 0x10000},
1646 {"default-nvm", 0x670000, 0xc0000},
1647 {"default-pib", 0x730000, 0x40000},
1648 {"radio", 0x7f0000, 0x10000},
1652 .first_sysupgrade_partition
= "os-image",
1653 .last_sysupgrade_partition
= "file-system"
1656 /** Firmware layout for the TL-WPA8630P v2 (INT)*/
1658 .id
= "TL-WPA8630P-V2-INT",
1662 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
1663 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
1664 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
1669 {"factory-uboot", 0x00000, 0x20000},
1670 {"fs-uboot", 0x20000, 0x20000},
1671 {"firmware", 0x40000, 0x5e0000},
1672 {"partition-table", 0x620000, 0x02000},
1673 {"extra-para", 0x632100, 0x01000},
1674 {"soft-version", 0x640000, 0x01000},
1675 {"support-list", 0x641000, 0x01000},
1676 {"profile", 0x642000, 0x08000},
1677 {"user-config", 0x650000, 0x10000},
1678 {"default-config", 0x660000, 0x10000},
1679 {"default-nvm", 0x670000, 0xc0000},
1680 {"default-pib", 0x730000, 0x40000},
1681 {"default-mac", 0x7e0000, 0x00020},
1682 {"pin", 0x7e0100, 0x00020},
1683 {"device-id", 0x7e0200, 0x00030},
1684 {"product-info", 0x7e1100, 0x01000},
1685 {"radio", 0x7f0000, 0x10000},
1689 .first_sysupgrade_partition
= "os-image",
1690 .last_sysupgrade_partition
= "file-system"
1693 /** Firmware layout for the TL-WPA8630P v2.1 (EU)*/
1695 .id
= "TL-WPA8630P-V2.1-EU",
1699 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n",
1704 {"factory-uboot", 0x00000, 0x20000},
1705 {"fs-uboot", 0x20000, 0x20000},
1706 {"firmware", 0x40000, 0x5e0000},
1707 {"extra-para", 0x680000, 0x01000},
1708 {"product-info", 0x690000, 0x01000},
1709 {"partition-table", 0x6a0000, 0x02000},
1710 {"soft-version", 0x6b0000, 0x01000},
1711 {"support-list", 0x6b1000, 0x01000},
1712 {"profile", 0x6b2000, 0x08000},
1713 {"user-config", 0x6c0000, 0x10000},
1714 {"default-config", 0x6d0000, 0x10000},
1715 {"default-nvm", 0x6e0000, 0xc0000},
1716 {"default-pib", 0x7a0000, 0x40000},
1717 {"default-mac", 0x7e0000, 0x00020},
1718 {"pin", 0x7e0100, 0x00020},
1719 {"device-id", 0x7e0200, 0x00030},
1720 {"radio", 0x7f0000, 0x10000},
1724 .first_sysupgrade_partition
= "os-image",
1725 .last_sysupgrade_partition
= "file-system"
1728 /** Firmware layout for the TL-WR1043 v5 */
1730 .id
= "TLWR1043NV5",
1734 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1735 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1737 .soft_ver
= "soft_ver:1.0.0\n",
1739 {"factory-boot", 0x00000, 0x20000},
1740 {"fs-uboot", 0x20000, 0x20000},
1741 {"firmware", 0x40000, 0xec0000},
1742 {"default-mac", 0xf00000, 0x00200},
1743 {"pin", 0xf00200, 0x00200},
1744 {"device-id", 0xf00400, 0x00100},
1745 {"product-info", 0xf00500, 0x0fb00},
1746 {"soft-version", 0xf10000, 0x01000},
1747 {"extra-para", 0xf11000, 0x01000},
1748 {"support-list", 0xf12000, 0x0a000},
1749 {"profile", 0xf1c000, 0x04000},
1750 {"default-config", 0xf20000, 0x10000},
1751 {"user-config", 0xf30000, 0x40000},
1752 {"qos-db", 0xf70000, 0x40000},
1753 {"certificate", 0xfb0000, 0x10000},
1754 {"partition-table", 0xfc0000, 0x10000},
1755 {"log", 0xfd0000, 0x20000},
1756 {"radio", 0xff0000, 0x10000},
1759 .first_sysupgrade_partition
= "os-image",
1760 .last_sysupgrade_partition
= "file-system"
1763 /** Firmware layout for the TL-WR1043 v4 */
1765 .id
= "TLWR1043NDV4",
1769 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1773 /* We're using a dynamic kernel/rootfs split here */
1775 {"fs-uboot", 0x00000, 0x20000},
1776 {"firmware", 0x20000, 0xf30000},
1777 {"default-mac", 0xf50000, 0x00200},
1778 {"pin", 0xf50200, 0x00200},
1779 {"product-info", 0xf50400, 0x0fc00},
1780 {"soft-version", 0xf60000, 0x0b000},
1781 {"support-list", 0xf6b000, 0x04000},
1782 {"profile", 0xf70000, 0x04000},
1783 {"default-config", 0xf74000, 0x0b000},
1784 {"user-config", 0xf80000, 0x40000},
1785 {"partition-table", 0xfc0000, 0x10000},
1786 {"log", 0xfd0000, 0x20000},
1787 {"radio", 0xff0000, 0x10000},
1791 .first_sysupgrade_partition
= "os-image",
1792 .last_sysupgrade_partition
= "file-system"
1795 /** Firmware layout for the TL-WR902AC v1 */
1797 .id
= "TL-WR902AC-V1",
1801 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1802 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1807 384KB were moved from file-system to os-image
1808 in comparison to the stock image
1811 {"fs-uboot", 0x00000, 0x20000},
1812 {"firmware", 0x20000, 0x730000},
1813 {"default-mac", 0x750000, 0x00200},
1814 {"pin", 0x750200, 0x00200},
1815 {"product-info", 0x750400, 0x0fc00},
1816 {"soft-version", 0x760000, 0x0b000},
1817 {"support-list", 0x76b000, 0x04000},
1818 {"profile", 0x770000, 0x04000},
1819 {"default-config", 0x774000, 0x0b000},
1820 {"user-config", 0x780000, 0x40000},
1821 {"partition-table", 0x7c0000, 0x10000},
1822 {"log", 0x7d0000, 0x20000},
1823 {"radio", 0x7f0000, 0x10000},
1827 .first_sysupgrade_partition
= "os-image",
1828 .last_sysupgrade_partition
= "file-system",
1831 /** Firmware layout for the TL-WR942N V1 */
1837 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1838 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1843 {"fs-uboot", 0x00000, 0x20000},
1844 {"firmware", 0x20000, 0xe20000},
1845 {"default-mac", 0xe40000, 0x00200},
1846 {"pin", 0xe40200, 0x00200},
1847 {"product-info", 0xe40400, 0x0fc00},
1848 {"partition-table", 0xe50000, 0x10000},
1849 {"soft-version", 0xe60000, 0x10000},
1850 {"support-list", 0xe70000, 0x10000},
1851 {"profile", 0xe80000, 0x10000},
1852 {"default-config", 0xe90000, 0x10000},
1853 {"user-config", 0xea0000, 0x40000},
1854 {"qos-db", 0xee0000, 0x40000},
1855 {"certificate", 0xf20000, 0x10000},
1856 {"usb-config", 0xfb0000, 0x10000},
1857 {"log", 0xfc0000, 0x20000},
1858 {"radio-bk", 0xfe0000, 0x10000},
1859 {"radio", 0xff0000, 0x10000},
1863 .first_sysupgrade_partition
= "os-image",
1864 .last_sysupgrade_partition
= "file-system",
1867 /** Firmware layout for the RE200 v2 */
1873 "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
1874 "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
1875 "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
1876 "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
1877 "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
1878 "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
1879 "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
1880 "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
1881 "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
1882 "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
1883 "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
1884 "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
1885 "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
1890 {"fs-uboot", 0x00000, 0x20000},
1891 {"firmware", 0x20000, 0x7a0000},
1892 {"partition-table", 0x7c0000, 0x02000},
1893 {"default-mac", 0x7c2000, 0x00020},
1894 {"pin", 0x7c2100, 0x00020},
1895 {"product-info", 0x7c3100, 0x01000},
1896 {"soft-version", 0x7c4200, 0x01000},
1897 {"support-list", 0x7c5200, 0x01000},
1898 {"profile", 0x7c6200, 0x08000},
1899 {"config-info", 0x7ce200, 0x00400},
1900 {"user-config", 0x7d0000, 0x10000},
1901 {"default-config", 0x7e0000, 0x10000},
1902 {"radio", 0x7f0000, 0x10000},
1906 .first_sysupgrade_partition
= "os-image",
1907 .last_sysupgrade_partition
= "file-system"
1910 /** Firmware layout for the RE200 v3 */
1916 "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
1917 "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
1918 "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
1919 "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
1920 "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
1921 "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
1922 "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
1923 "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
1924 "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
1925 "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
1926 "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
1927 "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
1928 "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
1929 "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
1934 {"fs-uboot", 0x00000, 0x20000},
1935 {"firmware", 0x20000, 0x7a0000},
1936 {"partition-table", 0x7c0000, 0x02000},
1937 {"default-mac", 0x7c2000, 0x00020},
1938 {"pin", 0x7c2100, 0x00020},
1939 {"product-info", 0x7c3100, 0x01000},
1940 {"soft-version", 0x7c4200, 0x01000},
1941 {"support-list", 0x7c5200, 0x01000},
1942 {"profile", 0x7c6200, 0x08000},
1943 {"config-info", 0x7ce200, 0x00400},
1944 {"user-config", 0x7d0000, 0x10000},
1945 {"default-config", 0x7e0000, 0x10000},
1946 {"radio", 0x7f0000, 0x10000},
1950 .first_sysupgrade_partition
= "os-image",
1951 .last_sysupgrade_partition
= "file-system"
1954 /** Firmware layout for the RE200 v4 */
1960 "{product_name:RE200,product_ver:4.0.0,special_id:00000000}\n"
1961 "{product_name:RE200,product_ver:4.0.0,special_id:45550000}\n"
1962 "{product_name:RE200,product_ver:4.0.0,special_id:4A500000}\n"
1963 "{product_name:RE200,product_ver:4.0.0,special_id:4B520000}\n"
1964 "{product_name:RE200,product_ver:4.0.0,special_id:43410000}\n"
1965 "{product_name:RE200,product_ver:4.0.0,special_id:41550000}\n"
1966 "{product_name:RE200,product_ver:4.0.0,special_id:42520000}\n"
1967 "{product_name:RE200,product_ver:4.0.0,special_id:55530000}\n"
1968 "{product_name:RE200,product_ver:4.0.0,special_id:41520000}\n"
1969 "{product_name:RE200,product_ver:4.0.0,special_id:52550000}\n"
1970 "{product_name:RE200,product_ver:4.0.0,special_id:54570000}\n"
1971 "{product_name:RE200,product_ver:4.0.0,special_id:45530000}\n"
1972 "{product_name:RE200,product_ver:4.0.0,special_id:49440000}\n"
1973 "{product_name:RE200,product_ver:4.0.0,special_id:45470000}\n",
1975 .soft_ver
= "soft_ver:1.1.0\n",
1978 {"fs-uboot", 0x00000, 0x20000},
1979 {"firmware", 0x20000, 0x7a0000},
1980 {"partition-table", 0x7c0000, 0x02000},
1981 {"default-mac", 0x7c2000, 0x00020},
1982 {"pin", 0x7c2100, 0x00020},
1983 {"product-info", 0x7c3100, 0x01000},
1984 {"soft-version", 0x7c4200, 0x01000},
1985 {"support-list", 0x7c5200, 0x01000},
1986 {"profile", 0x7c6200, 0x08000},
1987 {"config-info", 0x7ce200, 0x00400},
1988 {"user-config", 0x7d0000, 0x10000},
1989 {"default-config", 0x7e0000, 0x10000},
1990 {"radio", 0x7f0000, 0x10000},
1994 .first_sysupgrade_partition
= "os-image",
1995 .last_sysupgrade_partition
= "file-system"
1998 /** Firmware layout for the RE220 v2 */
2004 "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
2005 "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
2006 "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
2007 "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
2008 "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
2009 "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
2010 "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
2011 "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
2012 "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
2013 "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
2014 "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
2015 "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
2016 "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
2021 {"fs-uboot", 0x00000, 0x20000},
2022 {"firmware", 0x20000, 0x7a0000},
2023 {"partition-table", 0x7c0000, 0x02000},
2024 {"default-mac", 0x7c2000, 0x00020},
2025 {"pin", 0x7c2100, 0x00020},
2026 {"product-info", 0x7c3100, 0x01000},
2027 {"soft-version", 0x7c4200, 0x01000},
2028 {"support-list", 0x7c5200, 0x01000},
2029 {"profile", 0x7c6200, 0x08000},
2030 {"config-info", 0x7ce200, 0x00400},
2031 {"user-config", 0x7d0000, 0x10000},
2032 {"default-config", 0x7e0000, 0x10000},
2033 {"radio", 0x7f0000, 0x10000},
2037 .first_sysupgrade_partition
= "os-image",
2038 .last_sysupgrade_partition
= "file-system"
2041 /** Firmware layout for the RE305 v1 */
2047 "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
2048 "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
2049 "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
2050 "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
2051 "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
2052 "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
2053 "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
2058 {"fs-uboot", 0x00000, 0x20000},
2059 {"firmware", 0x20000, 0x5e0000},
2060 {"partition-table", 0x600000, 0x02000},
2061 {"default-mac", 0x610000, 0x00020},
2062 {"pin", 0x610100, 0x00020},
2063 {"product-info", 0x611100, 0x01000},
2064 {"soft-version", 0x620000, 0x01000},
2065 {"support-list", 0x621000, 0x01000},
2066 {"profile", 0x622000, 0x08000},
2067 {"user-config", 0x630000, 0x10000},
2068 {"default-config", 0x640000, 0x10000},
2069 {"radio", 0x7f0000, 0x10000},
2073 .first_sysupgrade_partition
= "os-image",
2074 .last_sysupgrade_partition
= "file-system"
2077 /** Firmware layout for the RE350 v1 */
2083 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
2084 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
2085 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
2086 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
2087 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
2088 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
2089 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
2093 /** We're using a dynamic kernel/rootfs split here */
2095 {"fs-uboot", 0x00000, 0x20000},
2096 {"firmware", 0x20000, 0x5e0000},
2097 {"partition-table", 0x600000, 0x02000},
2098 {"default-mac", 0x610000, 0x00020},
2099 {"pin", 0x610100, 0x00020},
2100 {"product-info", 0x611100, 0x01000},
2101 {"soft-version", 0x620000, 0x01000},
2102 {"support-list", 0x621000, 0x01000},
2103 {"profile", 0x622000, 0x08000},
2104 {"user-config", 0x630000, 0x10000},
2105 {"default-config", 0x640000, 0x10000},
2106 {"radio", 0x7f0000, 0x10000},
2110 .first_sysupgrade_partition
= "os-image",
2111 .last_sysupgrade_partition
= "file-system"
2114 /** Firmware layout for the RE350K v1 */
2120 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
2124 /** We're using a dynamic kernel/rootfs split here */
2126 {"fs-uboot", 0x00000, 0x20000},
2127 {"firmware", 0x20000, 0xd70000},
2128 {"partition-table", 0xd90000, 0x02000},
2129 {"default-mac", 0xda0000, 0x00020},
2130 {"pin", 0xda0100, 0x00020},
2131 {"product-info", 0xda1100, 0x01000},
2132 {"soft-version", 0xdb0000, 0x01000},
2133 {"support-list", 0xdb1000, 0x01000},
2134 {"profile", 0xdb2000, 0x08000},
2135 {"user-config", 0xdc0000, 0x10000},
2136 {"default-config", 0xdd0000, 0x10000},
2137 {"device-id", 0xde0000, 0x00108},
2138 {"radio", 0xff0000, 0x10000},
2142 .first_sysupgrade_partition
= "os-image",
2143 .last_sysupgrade_partition
= "file-system"
2146 /** Firmware layout for the RE355 */
2152 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
2153 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
2154 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
2155 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
2156 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
2157 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
2158 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
2159 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
2163 /* We're using a dynamic kernel/rootfs split here */
2165 {"fs-uboot", 0x00000, 0x20000},
2166 {"firmware", 0x20000, 0x5e0000},
2167 {"partition-table", 0x600000, 0x02000},
2168 {"default-mac", 0x610000, 0x00020},
2169 {"pin", 0x610100, 0x00020},
2170 {"product-info", 0x611100, 0x01000},
2171 {"soft-version", 0x620000, 0x01000},
2172 {"support-list", 0x621000, 0x01000},
2173 {"profile", 0x622000, 0x08000},
2174 {"user-config", 0x630000, 0x10000},
2175 {"default-config", 0x640000, 0x10000},
2176 {"radio", 0x7f0000, 0x10000},
2180 .first_sysupgrade_partition
= "os-image",
2181 .last_sysupgrade_partition
= "file-system"
2184 /** Firmware layout for the RE450 */
2190 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
2191 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
2192 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
2193 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
2194 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
2195 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
2196 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
2197 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
2201 /** We're using a dynamic kernel/rootfs split here */
2203 {"fs-uboot", 0x00000, 0x20000},
2204 {"firmware", 0x20000, 0x5e0000},
2205 {"partition-table", 0x600000, 0x02000},
2206 {"default-mac", 0x610000, 0x00020},
2207 {"pin", 0x610100, 0x00020},
2208 {"product-info", 0x611100, 0x01000},
2209 {"soft-version", 0x620000, 0x01000},
2210 {"support-list", 0x621000, 0x01000},
2211 {"profile", 0x622000, 0x08000},
2212 {"user-config", 0x630000, 0x10000},
2213 {"default-config", 0x640000, 0x10000},
2214 {"radio", 0x7f0000, 0x10000},
2218 .first_sysupgrade_partition
= "os-image",
2219 .last_sysupgrade_partition
= "file-system"
2222 /** Firmware layout for the RE450 v2 */
2228 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
2229 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
2230 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
2231 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
2232 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
2233 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
2234 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
2235 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
2236 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
2240 /* We're using a dynamic kernel/rootfs split here */
2242 {"fs-uboot", 0x00000, 0x20000},
2243 {"firmware", 0x20000, 0x5e0000},
2244 {"partition-table", 0x600000, 0x02000},
2245 {"default-mac", 0x610000, 0x00020},
2246 {"pin", 0x610100, 0x00020},
2247 {"product-info", 0x611100, 0x01000},
2248 {"soft-version", 0x620000, 0x01000},
2249 {"support-list", 0x621000, 0x01000},
2250 {"profile", 0x622000, 0x08000},
2251 {"user-config", 0x630000, 0x10000},
2252 {"default-config", 0x640000, 0x10000},
2253 {"radio", 0x7f0000, 0x10000},
2257 .first_sysupgrade_partition
= "os-image",
2258 .last_sysupgrade_partition
= "file-system"
2261 /** Firmware layout for the RE450 v3 */
2267 "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
2268 "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
2269 "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
2270 "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
2271 "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
2272 "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
2273 "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
2274 "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
2275 "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
2279 /* We're using a dynamic kernel/rootfs split here */
2281 {"fs-uboot", 0x00000, 0x20000},
2282 {"default-mac", 0x20000, 0x00020},
2283 {"pin", 0x20020, 0x00020},
2284 {"product-info", 0x21000, 0x01000},
2285 {"partition-table", 0x22000, 0x02000},
2286 {"soft-version", 0x24000, 0x01000},
2287 {"support-list", 0x25000, 0x01000},
2288 {"profile", 0x26000, 0x08000},
2289 {"user-config", 0x2e000, 0x10000},
2290 {"default-config", 0x3e000, 0x10000},
2291 {"config-info", 0x4e000, 0x00400},
2292 {"firmware", 0x50000, 0x7a0000},
2293 {"radio", 0x7f0000, 0x10000},
2297 .first_sysupgrade_partition
= "os-image",
2298 .last_sysupgrade_partition
= "file-system"
2301 /** Firmware layout for the RE500 */
2307 "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
2308 "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
2309 "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
2310 "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
2311 "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
2312 "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
2313 "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
2317 /* We're using a dynamic kernel/rootfs split here */
2319 {"fs-uboot", 0x00000, 0x20000},
2320 {"firmware", 0x20000, 0xde0000},
2321 {"partition-table", 0xe00000, 0x02000},
2322 {"default-mac", 0xe10000, 0x00020},
2323 {"pin", 0xe10100, 0x00020},
2324 {"product-info", 0xe11100, 0x01000},
2325 {"soft-version", 0xe20000, 0x01000},
2326 {"support-list", 0xe21000, 0x01000},
2327 {"profile", 0xe22000, 0x08000},
2328 {"user-config", 0xe30000, 0x10000},
2329 {"default-config", 0xe40000, 0x10000},
2330 {"radio", 0xff0000, 0x10000},
2334 .first_sysupgrade_partition
= "os-image",
2335 .last_sysupgrade_partition
= "file-system"
2338 /** Firmware layout for the RE650 */
2344 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
2345 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
2346 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
2347 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
2348 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
2349 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
2350 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
2354 /* We're using a dynamic kernel/rootfs split here */
2356 {"fs-uboot", 0x00000, 0x20000},
2357 {"firmware", 0x20000, 0xde0000},
2358 {"partition-table", 0xe00000, 0x02000},
2359 {"default-mac", 0xe10000, 0x00020},
2360 {"pin", 0xe10100, 0x00020},
2361 {"product-info", 0xe11100, 0x01000},
2362 {"soft-version", 0xe20000, 0x01000},
2363 {"support-list", 0xe21000, 0x01000},
2364 {"profile", 0xe22000, 0x08000},
2365 {"user-config", 0xe30000, 0x10000},
2366 {"default-config", 0xe40000, 0x10000},
2367 {"radio", 0xff0000, 0x10000},
2371 .first_sysupgrade_partition
= "os-image",
2372 .last_sysupgrade_partition
= "file-system"
2378 #define error(_ret, _errno, _str, ...) \
2380 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
2381 strerror(_errno)); \
2387 /** Stores a uint32 as big endian */
2388 static inline void put32(uint8_t *buf
, uint32_t val
) {
2395 static inline bool meta_partition_should_pad(enum partition_trail_value pv
)
2397 return (pv
>= 0) && (pv
<= PART_TRAIL_MAX
);
2400 /** Allocate a padded meta partition with a correctly initialised header
2401 * If the `data` pointer is NULL, then the required space is only allocated,
2402 * otherwise `data_len` bytes will be copied from `data` into the partition
2404 static struct image_partition_entry
init_meta_partition_entry(
2405 const char *name
, const void *data
, uint32_t data_len
,
2406 enum partition_trail_value pad_value
)
2408 uint32_t total_len
= sizeof(struct meta_header
) + data_len
;
2409 if (meta_partition_should_pad(pad_value
))
2412 struct image_partition_entry entry
= {
2415 .data
= malloc(total_len
)
2418 error(1, errno
, "failed to allocate meta partition entry");
2420 struct meta_header
*header
= (struct meta_header
*)entry
.data
;
2421 header
->length
= htonl(data_len
);
2425 memcpy(entry
.data
+sizeof(*header
), data
, data_len
);
2427 if (meta_partition_should_pad(pad_value
))
2428 entry
.data
[total_len
- 1] = (uint8_t) pad_value
;
2433 /** Allocates a new image partition */
2434 static struct image_partition_entry
alloc_image_partition(const char *name
, size_t len
) {
2435 struct image_partition_entry entry
= {name
, len
, malloc(len
)};
2437 error(1, errno
, "malloc");
2442 /** Frees an image partition */
2443 static void free_image_partition(struct image_partition_entry entry
) {
2447 static time_t source_date_epoch
= -1;
2448 static void set_source_date_epoch() {
2449 char *env
= getenv("SOURCE_DATE_EPOCH");
2453 source_date_epoch
= strtoull(env
, &endptr
, 10);
2454 if (errno
|| (endptr
&& *endptr
!= '\0')) {
2455 fprintf(stderr
, "Invalid SOURCE_DATE_EPOCH");
2461 /** Generates the partition-table partition */
2462 static struct image_partition_entry
make_partition_table(const struct flash_partition_entry
*p
) {
2463 struct image_partition_entry entry
= alloc_image_partition("partition-table", 0x800);
2465 char *s
= (char *)entry
.data
, *end
= (char *)(s
+entry
.size
);
2473 for (i
= 0; p
[i
].name
; i
++) {
2475 size_t w
= snprintf(s
, len
, "partition %s base 0x%05x size 0x%05x\n", p
[i
].name
, p
[i
].base
, p
[i
].size
);
2478 error(1, 0, "flash partition table overflow?");
2485 memset(s
, 0xff, end
-s
);
2491 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
2492 static inline uint8_t bcd(uint8_t v
) {
2493 return 0x10 * (v
/10) + v
%10;
2497 /** Generates the soft-version partition */
2498 static struct image_partition_entry
make_soft_version(
2499 const struct device_info
*info
, uint32_t rev
)
2501 /** If an info string is provided, use this instead of
2502 * the structured data, and include the null-termination */
2503 if (info
->soft_ver
) {
2504 uint32_t len
= strlen(info
->soft_ver
) + 1;
2505 return init_meta_partition_entry("soft-version",
2506 info
->soft_ver
, len
, info
->part_trail
);
2511 if (source_date_epoch
!= -1)
2512 t
= source_date_epoch
;
2513 else if (time(&t
) == (time_t)(-1))
2514 error(1, errno
, "time");
2516 struct tm
*tm
= gmtime(&t
);
2518 struct soft_version s
= {
2525 .year_hi
= bcd((1900+tm
->tm_year
)/100),
2526 .year_lo
= bcd(tm
->tm_year
%100),
2527 .month
= bcd(tm
->tm_mon
+1),
2528 .day
= bcd(tm
->tm_mday
),
2530 .compat_level
= htonl(info
->soft_ver_compat_level
)
2533 if (info
->soft_ver_compat_level
== 0)
2534 return init_meta_partition_entry("soft-version", &s
,
2535 (uint8_t *)(&s
.compat_level
) - (uint8_t *)(&s
),
2538 return init_meta_partition_entry("soft-version", &s
,
2539 sizeof(s
), info
->part_trail
);
2542 /** Generates the support-list partition */
2543 static struct image_partition_entry
make_support_list(
2544 const struct device_info
*info
)
2546 uint32_t len
= strlen(info
->support_list
);
2547 return init_meta_partition_entry("support-list", info
->support_list
,
2548 len
, info
->part_trail
);
2551 /** Partition with extra-para data */
2552 static struct image_partition_entry
make_extra_para(
2553 const struct device_info
*info
, const uint8_t *extra_para
, size_t len
)
2555 return init_meta_partition_entry("extra-para", extra_para
, len
,
2559 /** Creates a new image partition with an arbitrary name from a file */
2560 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
) {
2561 struct stat statbuf
;
2563 if (stat(filename
, &statbuf
) < 0)
2564 error(1, errno
, "unable to stat file `%s'", filename
);
2566 size_t len
= statbuf
.st_size
;
2568 if (add_jffs2_eof
) {
2569 if (file_system_partition
)
2570 len
= ALIGN(len
+ file_system_partition
->base
, 0x10000) + sizeof(jffs2_eof_mark
) - file_system_partition
->base
;
2572 len
= ALIGN(len
, 0x10000) + sizeof(jffs2_eof_mark
);
2575 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
2577 FILE *file
= fopen(filename
, "rb");
2579 error(1, errno
, "unable to open file `%s'", filename
);
2581 if (fread(entry
.data
, statbuf
.st_size
, 1, file
) != 1)
2582 error(1, errno
, "unable to read file `%s'", filename
);
2584 if (add_jffs2_eof
) {
2585 uint8_t *eof
= entry
.data
+ statbuf
.st_size
, *end
= entry
.data
+entry
.size
;
2587 memset(eof
, 0xff, end
- eof
- sizeof(jffs2_eof_mark
));
2588 memcpy(end
- sizeof(jffs2_eof_mark
), jffs2_eof_mark
, sizeof(jffs2_eof_mark
));
2597 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
2599 Example image partition table:
2601 fwup-ptn partition-table base 0x00800 size 0x00800
2602 fwup-ptn os-image base 0x01000 size 0x113b45
2603 fwup-ptn file-system base 0x114b45 size 0x1d0004
2604 fwup-ptn support-list base 0x2e4b49 size 0x000d1
2606 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
2607 the end of the partition table is marked with a zero byte.
2609 The firmware image must contain at least the partition-table and support-list partitions
2610 to be accepted. There aren't any alignment constraints for the image partitions.
2612 The partition-table partition contains the actual flash layout; partitions
2613 from the image partition table are mapped to the corresponding flash partitions during
2614 the firmware upgrade. The support-list partition contains a list of devices supported by
2617 The base offsets in the firmware partition table are relative to the end
2618 of the vendor information block, so the partition-table partition will
2619 actually start at offset 0x1814 of the image.
2621 I think partition-table must be the first partition in the firmware image.
2623 static void put_partitions(uint8_t *buffer
, const struct flash_partition_entry
*flash_parts
, const struct image_partition_entry
*parts
) {
2625 char *image_pt
= (char *)buffer
, *end
= image_pt
+ 0x800;
2627 size_t base
= 0x800;
2628 for (i
= 0; parts
[i
].name
; i
++) {
2629 for (j
= 0; flash_parts
[j
].name
; j
++) {
2630 if (!strcmp(flash_parts
[j
].name
, parts
[i
].name
)) {
2631 if (parts
[i
].size
> flash_parts
[j
].size
)
2632 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts
[j
].name
, (unsigned)flash_parts
[j
].size
);
2637 assert(flash_parts
[j
].name
);
2639 memcpy(buffer
+ base
, parts
[i
].data
, parts
[i
].size
);
2641 size_t len
= end
-image_pt
;
2642 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
);
2645 error(1, 0, "image partition table overflow?");
2649 base
+= parts
[i
].size
;
2653 /** Generates and writes the image MD5 checksum */
2654 static void put_md5(uint8_t *md5
, uint8_t *buffer
, unsigned int len
) {
2658 MD5_Update(&ctx
, md5_salt
, (unsigned int)sizeof(md5_salt
));
2659 MD5_Update(&ctx
, buffer
, len
);
2660 MD5_Final(md5
, &ctx
);
2665 Generates the firmware image in factory format
2671 0000-0003 Image size (4 bytes, big endian)
2672 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
2673 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
2674 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
2675 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
2676 1014-1813 Image partition table (2048 bytes, padded with 0xff)
2677 1814-xxxx Firmware partitions
2679 static void * generate_factory_image(struct device_info
*info
, const struct image_partition_entry
*parts
, size_t *len
) {
2683 for (i
= 0; parts
[i
].name
; i
++)
2684 *len
+= parts
[i
].size
;
2686 uint8_t *image
= malloc(*len
);
2688 error(1, errno
, "malloc");
2690 memset(image
, 0xff, *len
);
2694 size_t vendor_len
= strlen(info
->vendor
);
2695 put32(image
+0x14, vendor_len
);
2696 memcpy(image
+0x18, info
->vendor
, vendor_len
);
2699 put_partitions(image
+ 0x1014, info
->partitions
, parts
);
2700 put_md5(image
+0x04, image
+0x14, *len
-0x14);
2706 Generates the firmware image in sysupgrade format
2708 This makes some assumptions about the provided flash and image partition tables and
2709 should be generalized when TP-LINK starts building its safeloader into hardware with
2710 different flash layouts.
2712 static void * generate_sysupgrade_image(struct device_info
*info
, const struct image_partition_entry
*image_parts
, size_t *len
) {
2714 size_t flash_first_partition_index
= 0;
2715 size_t flash_last_partition_index
= 0;
2716 const struct flash_partition_entry
*flash_first_partition
= NULL
;
2717 const struct flash_partition_entry
*flash_last_partition
= NULL
;
2718 const struct image_partition_entry
*image_last_partition
= NULL
;
2720 /** Find first and last partitions */
2721 for (i
= 0; info
->partitions
[i
].name
; i
++) {
2722 if (!strcmp(info
->partitions
[i
].name
, info
->first_sysupgrade_partition
)) {
2723 flash_first_partition
= &info
->partitions
[i
];
2724 flash_first_partition_index
= i
;
2725 } else if (!strcmp(info
->partitions
[i
].name
, info
->last_sysupgrade_partition
)) {
2726 flash_last_partition
= &info
->partitions
[i
];
2727 flash_last_partition_index
= i
;
2731 assert(flash_first_partition
&& flash_last_partition
);
2732 assert(flash_first_partition_index
< flash_last_partition_index
);
2734 /** Find last partition from image to calculate needed size */
2735 for (i
= 0; image_parts
[i
].name
; i
++) {
2736 if (!strcmp(image_parts
[i
].name
, info
->last_sysupgrade_partition
)) {
2737 image_last_partition
= &image_parts
[i
];
2742 assert(image_last_partition
);
2744 *len
= flash_last_partition
->base
- flash_first_partition
->base
+ image_last_partition
->size
;
2746 uint8_t *image
= malloc(*len
);
2748 error(1, errno
, "malloc");
2750 memset(image
, 0xff, *len
);
2752 for (i
= flash_first_partition_index
; i
<= flash_last_partition_index
; i
++) {
2753 for (j
= 0; image_parts
[j
].name
; j
++) {
2754 if (!strcmp(info
->partitions
[i
].name
, image_parts
[j
].name
)) {
2755 if (image_parts
[j
].size
> info
->partitions
[i
].size
)
2756 error(1, 0, "%s partition too big (more than %u bytes)", info
->partitions
[i
].name
, (unsigned)info
->partitions
[i
].size
);
2757 memcpy(image
+ info
->partitions
[i
].base
- flash_first_partition
->base
, image_parts
[j
].data
, image_parts
[j
].size
);
2761 assert(image_parts
[j
].name
);
2768 /** Generates an image according to a given layout and writes it to a file */
2769 static void build_image(const char *output
,
2770 const char *kernel_image
,
2771 const char *rootfs_image
,
2775 struct device_info
*info
) {
2779 struct image_partition_entry parts
[7] = {};
2781 struct flash_partition_entry
*firmware_partition
= NULL
;
2782 struct flash_partition_entry
*os_image_partition
= NULL
;
2783 struct flash_partition_entry
*file_system_partition
= NULL
;
2784 size_t firmware_partition_index
= 0;
2786 for (i
= 0; info
->partitions
[i
].name
; i
++) {
2787 if (!strcmp(info
->partitions
[i
].name
, "firmware"))
2789 firmware_partition
= &info
->partitions
[i
];
2790 firmware_partition_index
= i
;
2794 if (firmware_partition
)
2796 os_image_partition
= &info
->partitions
[firmware_partition_index
];
2797 file_system_partition
= &info
->partitions
[firmware_partition_index
+ 1];
2800 if (stat(kernel_image
, &kernel
) < 0)
2801 error(1, errno
, "unable to stat file `%s'", kernel_image
);
2803 if (kernel
.st_size
> firmware_partition
->size
)
2804 error(1, 0, "kernel overflowed firmware partition\n");
2806 for (i
= MAX_PARTITIONS
-1; i
>= firmware_partition_index
+ 1; i
--)
2807 info
->partitions
[i
+1] = info
->partitions
[i
];
2809 file_system_partition
->name
= "file-system";
2810 file_system_partition
->base
= firmware_partition
->base
+ kernel
.st_size
;
2812 /* Align partition start to erase blocks for factory images only */
2814 file_system_partition
->base
= ALIGN(firmware_partition
->base
+ kernel
.st_size
, 0x10000);
2816 file_system_partition
->size
= firmware_partition
->size
- file_system_partition
->base
;
2818 os_image_partition
->name
= "os-image";
2819 os_image_partition
->size
= kernel
.st_size
;
2822 parts
[0] = make_partition_table(info
->partitions
);
2823 parts
[1] = make_soft_version(info
, rev
);
2824 parts
[2] = make_support_list(info
);
2825 parts
[3] = read_file("os-image", kernel_image
, false, NULL
);
2826 parts
[4] = read_file("file-system", rootfs_image
, add_jffs2_eof
, file_system_partition
);
2828 /* Some devices need the extra-para partition to accept the firmware */
2829 if (strcasecmp(info
->id
, "ARCHER-A7-V5") == 0 ||
2830 strcasecmp(info
->id
, "ARCHER-C2-V3") == 0 ||
2831 strcasecmp(info
->id
, "ARCHER-C7-V4") == 0 ||
2832 strcasecmp(info
->id
, "ARCHER-C7-V5") == 0 ||
2833 strcasecmp(info
->id
, "ARCHER-C25-V1") == 0 ||
2834 strcasecmp(info
->id
, "ARCHER-C59-V2") == 0 ||
2835 strcasecmp(info
->id
, "ARCHER-C60-V2") == 0 ||
2836 strcasecmp(info
->id
, "ARCHER-C60-V3") == 0 ||
2837 strcasecmp(info
->id
, "TLWR1043NV5") == 0) {
2838 const uint8_t extra_para
[2] = {0x01, 0x00};
2839 parts
[5] = make_extra_para(info
, extra_para
,
2840 sizeof(extra_para
));
2841 } else if (strcasecmp(info
->id
, "ARCHER-C6-V2") == 0) {
2842 const uint8_t extra_para
[2] = {0x00, 0x01};
2843 parts
[5] = make_extra_para(info
, extra_para
,
2844 sizeof(extra_para
));
2845 } else if (strcasecmp(info
->id
, "ARCHER-C6-V2-US") == 0 ||
2846 strcasecmp(info
->id
, "EAP245-V3") == 0) {
2847 const uint8_t extra_para
[2] = {0x01, 0x01};
2848 parts
[5] = make_extra_para(info
, extra_para
,
2849 sizeof(extra_para
));
2855 image
= generate_sysupgrade_image(info
, parts
, &len
);
2857 image
= generate_factory_image(info
, parts
, &len
);
2859 FILE *file
= fopen(output
, "wb");
2861 error(1, errno
, "unable to open output file");
2863 if (fwrite(image
, len
, 1, file
) != 1)
2864 error(1, 0, "unable to write output file");
2870 for (i
= 0; parts
[i
].name
; i
++)
2871 free_image_partition(parts
[i
]);
2875 static void usage(const char *argv0
) {
2877 "Usage: %s [OPTIONS...]\n"
2880 " -h show this help\n"
2882 "Info about an image:\n"
2883 " -i <file> input file to read from\n"
2884 "Create a new image:\n"
2885 " -B <board> create image for the board specified with <board>\n"
2886 " -k <file> read kernel image from the file <file>\n"
2887 " -r <file> read rootfs image from the file <file>\n"
2888 " -o <file> write output to the file <file>\n"
2889 " -V <rev> sets the revision number to <rev>\n"
2890 " -j add jffs2 end-of-filesystem markers\n"
2891 " -S create sysupgrade instead of factory image\n"
2892 "Extract an old image:\n"
2893 " -x <file> extract all oem firmware partition\n"
2894 " -d <dir> destination to extract the firmware partition\n"
2895 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
2901 static struct device_info
*find_board(const char *id
)
2903 struct device_info
*board
= NULL
;
2905 for (board
= boards
; board
->id
!= NULL
; board
++)
2906 if (strcasecmp(id
, board
->id
) == 0)
2912 static int add_flash_partition(
2913 struct flash_partition_entry
*part_list
,
2920 /* check if the list has a free entry */
2921 for (ptr
= 0; ptr
< max_entries
; ptr
++, part_list
++) {
2922 if (part_list
->name
== NULL
&&
2923 part_list
->base
== 0 &&
2924 part_list
->size
== 0)
2928 if (ptr
== max_entries
) {
2929 error(1, 0, "No free flash part entry available.");
2932 part_list
->name
= calloc(1, strlen(name
) + 1);
2933 if (!part_list
->name
) {
2934 error(1, 0, "Unable to allocate memory");
2937 memcpy((char *)part_list
->name
, name
, strlen(name
));
2938 part_list
->base
= base
;
2939 part_list
->size
= size
;
2944 /** read the partition table into struct flash_partition_entry */
2945 static int read_partition_table(
2946 FILE *file
, long offset
,
2947 struct flash_partition_entry
*entries
, size_t max_entries
,
2952 const char *parthdr
= NULL
;
2953 const char *fwuphdr
= "fwup-ptn";
2954 const char *flashhdr
= "partition";
2956 /* TODO: search for the partition table */
2966 error(1, 0, "Invalid partition table");
2969 if (fseek(file
, offset
, SEEK_SET
) < 0)
2970 error(1, errno
, "Can not seek in the firmware");
2972 if (fread(buf
, 2048, 1, file
) != 1)
2973 error(1, errno
, "Can not read fwup-ptn from the firmware");
2977 /* look for the partition header */
2978 if (memcmp(buf
, parthdr
, strlen(parthdr
)) != 0) {
2979 fprintf(stderr
, "DEBUG: can not find fwuphdr\n");
2984 end
= buf
+ sizeof(buf
);
2985 while ((ptr
+ strlen(parthdr
)) < end
&&
2986 memcmp(ptr
, parthdr
, strlen(parthdr
)) == 0) {
2990 char name
[32] = { 0 };
2992 unsigned long base
= 0;
2993 unsigned long size
= 0;
2995 end_part
= memchr(ptr
, '\n', (end
- ptr
));
2996 if (end_part
== NULL
) {
2997 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
3001 for (int i
= 0; i
<= 4; i
++) {
3002 if (end_part
<= ptr
)
3005 end_element
= memchr(ptr
, 0x20, (end_part
- ptr
));
3006 if (end_element
== NULL
) {
3007 error(1, errno
, "Ignoring the rest of the partition entries.");
3012 /* partition header */
3014 ptr
= end_element
+ 1;
3018 name_len
= (end_element
- ptr
) > 31 ? 31 : (end_element
- ptr
);
3019 strncpy(name
, ptr
, name_len
);
3020 name
[name_len
] = '\0';
3021 ptr
= end_element
+ 1;
3026 ptr
= end_element
+ 1;
3031 base
= strtoul(ptr
, NULL
, 16);
3032 ptr
= end_element
+ 1;
3037 ptr
= end_element
+ 1;
3038 /* actual size. The last element doesn't have a sepeartor */
3039 size
= strtoul(ptr
, NULL
, 16);
3040 /* the part ends with 0x09, 0x0d, 0x0a */
3042 add_flash_partition(entries
, max_entries
, name
, base
, size
);
3051 static void write_partition(
3053 size_t firmware_offset
,
3054 struct flash_partition_entry
*entry
,
3060 fseek(input_file
, entry
->base
+ firmware_offset
, SEEK_SET
);
3062 for (offset
= 0; sizeof(buf
) + offset
<= entry
->size
; offset
+= sizeof(buf
)) {
3063 if (fread(buf
, sizeof(buf
), 1, input_file
) != 1)
3064 error(1, errno
, "Can not read partition from input_file");
3066 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
3067 error(1, errno
, "Can not write partition to output_file");
3069 /* write last chunk smaller than buffer */
3070 if (offset
< entry
->size
) {
3071 offset
= entry
->size
- offset
;
3072 if (fread(buf
, offset
, 1, input_file
) != 1)
3073 error(1, errno
, "Can not read partition from input_file");
3074 if (fwrite(buf
, offset
, 1, output_file
) != 1)
3075 error(1, errno
, "Can not write partition to output_file");
3079 static int extract_firmware_partition(FILE *input_file
, size_t firmware_offset
, struct flash_partition_entry
*entry
, const char *output_directory
)
3082 char output
[PATH_MAX
];
3084 snprintf(output
, PATH_MAX
, "%s/%s", output_directory
, entry
->name
);
3085 output_file
= fopen(output
, "wb+");
3086 if (output_file
== NULL
) {
3087 error(1, errno
, "Can not open output file %s", output
);
3090 write_partition(input_file
, firmware_offset
, entry
, output_file
);
3092 fclose(output_file
);
3097 /** extract all partitions from the firmware file */
3098 static int extract_firmware(const char *input
, const char *output_directory
)
3100 struct flash_partition_entry entries
[16] = { 0 };
3101 size_t max_entries
= 16;
3102 size_t firmware_offset
= 0x1014;
3105 struct stat statbuf
;
3107 /* check input file */
3108 if (stat(input
, &statbuf
)) {
3109 error(1, errno
, "Can not read input firmware %s", input
);
3112 /* check if output directory exists */
3113 if (stat(output_directory
, &statbuf
)) {
3114 error(1, errno
, "Failed to stat output directory %s", output_directory
);
3117 if ((statbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
3118 error(1, errno
, "Given output directory is not a directory %s", output_directory
);
3121 input_file
= fopen(input
, "rb");
3123 if (read_partition_table(input_file
, firmware_offset
, entries
, 16, 0) != 0) {
3124 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3127 for (size_t i
= 0; i
< max_entries
; i
++) {
3128 if (entries
[i
].name
== NULL
&&
3129 entries
[i
].base
== 0 &&
3130 entries
[i
].size
== 0)
3133 extract_firmware_partition(input_file
, firmware_offset
, &entries
[i
], output_directory
);
3139 static struct flash_partition_entry
*find_partition(
3140 struct flash_partition_entry
*entries
, size_t max_entries
,
3141 const char *name
, const char *error_msg
)
3143 for (size_t i
= 0; i
< max_entries
; i
++, entries
++) {
3144 if (strcmp(entries
->name
, name
) == 0)
3149 error(1, 0, "%s", error_msg
);
3155 static int firmware_info(const char *input
)
3157 struct flash_partition_entry pointers
[MAX_PARTITIONS
] = { };
3158 struct flash_partition_entry
*e
;
3162 fp
= fopen(input
, "r");
3164 if (read_partition_table(fp
, 0x1014, pointers
, MAX_PARTITIONS
, 0)) {
3165 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3168 printf("Firmware image partitions:\n");
3169 printf("%-8s %-8s %s\n", "base", "size", "name");
3170 for (i
= 0; i
< MAX_PARTITIONS
; i
++) {
3173 if (!e
->name
&& !e
->base
&& !e
->size
)
3176 printf("%08x %08x %s\n", e
->base
, e
->size
, e
->name
? e
->name
: "");
3179 e
= find_partition(pointers
, MAX_PARTITIONS
, "soft-version", NULL
);
3181 size_t data_len
= e
->size
- sizeof(struct meta_header
);
3182 char *buf
= malloc(data_len
);
3183 struct soft_version
*s
;
3188 error(1, errno
, "Failed to alloc buffer");
3190 if (fseek(fp
, 0x1014 + e
->base
+ sizeof(struct meta_header
), SEEK_SET
))
3191 error(1, errno
, "Can not seek in the firmware");
3193 if (fread(buf
, data_len
, 1, fp
) != 1)
3194 error(1, errno
, "Can not read fwup-ptn data from the firmware");
3196 /* Check for string ignoring padding character */
3198 for (i
= 0; i
< data_len
- 1; i
++) {
3199 if (!isascii(buf
[i
])) {
3205 printf("\n[Software version]\n");
3207 fwrite(buf
, data_len
, 1, stdout
);
3209 } else if (data_len
>= offsetof(struct soft_version
, rev
)) {
3210 s
= (struct soft_version
*)buf
;
3212 printf("Version: %d.%d.%d\n", s
->version_major
, s
->version_minor
, s
->version_patch
);
3213 printf("Date: %02x%02x-%02x-%02x\n", s
->year_hi
, s
->year_lo
, s
->month
, s
->day
);
3215 printf("Failed to parse data\n");
3221 e
= find_partition(pointers
, MAX_PARTITIONS
, "support-list", NULL
);
3227 if (fseek(fp
, 0x1014 + e
->base
+ sizeof(struct meta_header
), SEEK_SET
))
3228 error(1, errno
, "Can not seek in the firmware");
3230 printf("\n[Support list]\n");
3231 for (length
= e
->size
- sizeof(struct meta_header
); length
; length
-= bytes
) {
3232 bytes
= fread(buf
, 1, length
> sizeof(buf
) ? sizeof(buf
) : length
, fp
);
3234 error(1, errno
, "Can not read fwup-ptn data from the firmware");
3240 e
= find_partition(pointers
, MAX_PARTITIONS
, "partition-table", NULL
);
3242 struct flash_partition_entry parts
[MAX_PARTITIONS
] = { };
3244 if (read_partition_table(fp
, 0x1014 + e
->base
+ 4, parts
, MAX_PARTITIONS
, 1)) {
3245 error(1, 0, "Error can not read the partition table (partition)");
3248 printf("\n[Partition table]\n");
3249 printf("%-8s %-8s %s\n", "base", "size", "name");
3250 for (i
= 0; i
< MAX_PARTITIONS
; i
++) {
3253 if (!e
->name
&& !e
->base
&& !e
->size
)
3256 printf("%08x %08x %s\n", e
->base
, e
->size
, e
->name
? e
->name
: "");
3265 static void write_ff(FILE *output_file
, size_t size
)
3270 memset(buf
, 0xff, sizeof(buf
));
3272 for (offset
= 0; offset
+ sizeof(buf
) < size
; offset
+= sizeof(buf
)) {
3273 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
3274 error(1, errno
, "Can not write 0xff to output_file");
3277 /* write last chunk smaller than buffer */
3278 if (offset
< size
) {
3279 offset
= size
- offset
;
3280 if (fwrite(buf
, offset
, 1, output_file
) != 1)
3281 error(1, errno
, "Can not write partition to output_file");
3285 static void convert_firmware(const char *input
, const char *output
)
3287 struct flash_partition_entry fwup
[MAX_PARTITIONS
] = { 0 };
3288 struct flash_partition_entry flash
[MAX_PARTITIONS
] = { 0 };
3289 struct flash_partition_entry
*fwup_os_image
= NULL
, *fwup_file_system
= NULL
;
3290 struct flash_partition_entry
*flash_os_image
= NULL
, *flash_file_system
= NULL
;
3291 struct flash_partition_entry
*fwup_partition_table
= NULL
;
3292 size_t firmware_offset
= 0x1014;
3293 FILE *input_file
, *output_file
;
3295 struct stat statbuf
;
3297 /* check input file */
3298 if (stat(input
, &statbuf
)) {
3299 error(1, errno
, "Can not read input firmware %s", input
);
3302 input_file
= fopen(input
, "rb");
3304 error(1, 0, "Can not open input firmware %s", input
);
3306 output_file
= fopen(output
, "wb");
3308 error(1, 0, "Can not open output firmware %s", output
);
3310 if (read_partition_table(input_file
, firmware_offset
, fwup
, MAX_PARTITIONS
, 0) != 0) {
3311 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3314 fwup_os_image
= find_partition(fwup
, MAX_PARTITIONS
,
3315 "os-image", "Error can not find os-image partition (fwup)");
3316 fwup_file_system
= find_partition(fwup
, MAX_PARTITIONS
,
3317 "file-system", "Error can not find file-system partition (fwup)");
3318 fwup_partition_table
= find_partition(fwup
, MAX_PARTITIONS
,
3319 "partition-table", "Error can not find partition-table partition");
3321 /* the flash partition table has a 0x00000004 magic haeder */
3322 if (read_partition_table(input_file
, firmware_offset
+ fwup_partition_table
->base
+ 4, flash
, MAX_PARTITIONS
, 1) != 0)
3323 error(1, 0, "Error can not read the partition table (flash)");
3325 flash_os_image
= find_partition(flash
, MAX_PARTITIONS
,
3326 "os-image", "Error can not find os-image partition (flash)");
3327 flash_file_system
= find_partition(flash
, MAX_PARTITIONS
,
3328 "file-system", "Error can not find file-system partition (flash)");
3330 /* write os_image to 0x0 */
3331 write_partition(input_file
, firmware_offset
, fwup_os_image
, output_file
);
3332 write_ff(output_file
, flash_os_image
->size
- fwup_os_image
->size
);
3334 /* write file-system behind os_image */
3335 fseek(output_file
, flash_file_system
->base
- flash_os_image
->base
, SEEK_SET
);
3336 write_partition(input_file
, firmware_offset
, fwup_file_system
, output_file
);
3337 write_ff(output_file
, flash_file_system
->size
- fwup_file_system
->size
);
3339 fclose(output_file
);
3343 int main(int argc
, char *argv
[]) {
3344 const char *info_image
= NULL
, *board
= NULL
, *kernel_image
= NULL
, *rootfs_image
= NULL
, *output
= NULL
;
3345 const char *extract_image
= NULL
, *output_directory
= NULL
, *convert_image
= NULL
;
3346 bool add_jffs2_eof
= false, sysupgrade
= false;
3348 struct device_info
*info
;
3349 set_source_date_epoch();
3354 c
= getopt(argc
, argv
, "i:B:k:r:o:V:jSh:x:d:z:");
3360 info_image
= optarg
;
3368 kernel_image
= optarg
;
3372 rootfs_image
= optarg
;
3380 sscanf(optarg
, "r%u", &rev
);
3384 add_jffs2_eof
= true;
3396 output_directory
= optarg
;
3400 extract_image
= optarg
;
3404 convert_image
= optarg
;
3414 firmware_info(info_image
);
3415 } else if (extract_image
|| output_directory
) {
3417 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
3418 if (!output_directory
)
3419 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
3420 extract_firmware(extract_image
, output_directory
);
3421 } else if (convert_image
) {
3423 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
3424 convert_firmware(convert_image
, output
);
3427 error(1, 0, "no board has been specified");
3429 error(1, 0, "no kernel image has been specified");
3431 error(1, 0, "no rootfs image has been specified");
3433 error(1, 0, "no output filename has been specified");
3435 info
= find_board(board
);
3438 error(1, 0, "unsupported board %s", board
);
3440 build_image(output
, kernel_image
, rootfs_image
, rev
, add_jffs2_eof
, sysupgrade
, info
);