2 Copyright (c) 2014, Matthias Schiffer <mschiffer@universe-factory.net>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 Image generation tool for the TP-LINK SafeLoader as seen on
31 TP-LINK Pharos devices (CPE210/220/510/520)
45 #include <arpa/inet.h>
47 #include <sys/types.h>
54 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
57 #define MAX_PARTITIONS 32
59 /** An image partition table entry */
60 struct image_partition_entry
{
66 /** A flash partition table entry */
67 struct flash_partition_entry
{
73 /** Firmware layout description */
77 const char *support_list
;
80 uint32_t soft_ver_compat_level
;
81 struct flash_partition_entry partitions
[MAX_PARTITIONS
+1];
82 const char *first_sysupgrade_partition
;
83 const char *last_sysupgrade_partition
;
86 /** The content of the soft-version structure */
87 struct __attribute__((__packed__
)) soft_version
{
91 uint8_t version_major
;
92 uint8_t version_minor
;
93 uint8_t version_patch
;
102 static const uint8_t jffs2_eof_mark
[4] = {0xde, 0xad, 0xc0, 0xde};
106 Salt for the MD5 hash
108 Fortunately, TP-LINK seems to use the same salt for most devices which use
109 the new image format.
111 static const uint8_t md5_salt
[16] = {
112 0x7a, 0x2b, 0x15, 0xed,
113 0x9b, 0x98, 0x59, 0x6d,
114 0xe5, 0x04, 0xab, 0x44,
115 0xac, 0x2a, 0x9f, 0x4e,
119 /** Firmware layout table */
120 static struct device_info boards
[] = {
121 /** Firmware layout for the CPE210/220 V1 */
124 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
127 "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
128 "CPE210(TP-LINK|UN|N300-2):1.1\r\n"
129 "CPE210(TP-LINK|US|N300-2):1.1\r\n"
130 "CPE210(TP-LINK|EU|N300-2):1.1\r\n"
131 "CPE220(TP-LINK|UN|N300-2):1.1\r\n"
132 "CPE220(TP-LINK|US|N300-2):1.1\r\n"
133 "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
134 .support_trail
= '\xff',
138 {"fs-uboot", 0x00000, 0x20000},
139 {"partition-table", 0x20000, 0x02000},
140 {"default-mac", 0x30000, 0x00020},
141 {"product-info", 0x31100, 0x00100},
142 {"signature", 0x32000, 0x00400},
143 {"os-image", 0x40000, 0x300000},
144 {"file-system", 0x340000, 0x470000},
145 {"soft-version", 0x7b0000, 0x00100},
146 {"support-list", 0x7b1000, 0x00400},
147 {"user-config", 0x7c0000, 0x10000},
148 {"default-config", 0x7d0000, 0x10000},
149 {"log", 0x7e0000, 0x10000},
150 {"radio", 0x7f0000, 0x10000},
154 .first_sysupgrade_partition
= "os-image",
155 .last_sysupgrade_partition
= "support-list",
158 /** Firmware layout for the CPE210 V2 */
161 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
164 "CPE210(TP-LINK|EU|N300-2|00000000):2.0\r\n"
165 "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n"
166 "CPE210(TP-LINK|EU|N300-2|55530000):2.0\r\n"
167 "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
168 "CPE210(TP-LINK|UN|N300-2|45550000):2.0\r\n"
169 "CPE210(TP-LINK|UN|N300-2|55530000):2.0\r\n"
170 "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
171 "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
172 "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
173 "CPE210(TP-LINK|US|N300-2):2.0\r\n",
174 .support_trail
= '\xff',
178 {"fs-uboot", 0x00000, 0x20000},
179 {"partition-table", 0x20000, 0x02000},
180 {"default-mac", 0x30000, 0x00020},
181 {"product-info", 0x31100, 0x00100},
182 {"device-info", 0x31400, 0x00400},
183 {"signature", 0x32000, 0x00400},
184 {"device-id", 0x33000, 0x00100},
185 {"firmware", 0x40000, 0x770000},
186 {"soft-version", 0x7b0000, 0x00100},
187 {"support-list", 0x7b1000, 0x01000},
188 {"user-config", 0x7c0000, 0x10000},
189 {"default-config", 0x7d0000, 0x10000},
190 {"log", 0x7e0000, 0x10000},
191 {"radio", 0x7f0000, 0x10000},
195 .first_sysupgrade_partition
= "os-image",
196 .last_sysupgrade_partition
= "support-list",
199 /** Firmware layout for the CPE210 V3 */
202 .vendor
= "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
205 "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
206 "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
207 "CPE210(TP-LINK|US|N300-2|55530000):3.0\r\n"
208 "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
209 "CPE210(TP-LINK|EU|N300-2):3.0\r\n"
210 "CPE210(TP-LINK|EU|N300-2|45550000):3.1\r\n"
211 "CPE210(TP-LINK|UN|N300-2|00000000):3.1\r\n"
212 "CPE210(TP-LINK|US|N300-2|55530000):3.1\r\n"
213 "CPE210(TP-LINK|EU|N300-2|45550000):3.20\r\n"
214 "CPE210(TP-LINK|UN|N300-2|00000000):3.20\r\n"
215 "CPE210(TP-LINK|US|N300-2|55530000):3.20\r\n",
216 .support_trail
= '\xff',
220 {"fs-uboot", 0x00000, 0x20000},
221 {"partition-table", 0x20000, 0x01000},
222 {"default-mac", 0x30000, 0x00020},
223 {"product-info", 0x31100, 0x00100},
224 {"device-info", 0x31400, 0x00400},
225 {"signature", 0x32000, 0x00400},
226 {"device-id", 0x33000, 0x00100},
227 {"firmware", 0x40000, 0x770000},
228 {"soft-version", 0x7b0000, 0x00100},
229 {"support-list", 0x7b1000, 0x01000},
230 {"user-config", 0x7c0000, 0x10000},
231 {"default-config", 0x7d0000, 0x10000},
232 {"log", 0x7e0000, 0x10000},
233 {"radio", 0x7f0000, 0x10000},
237 .first_sysupgrade_partition
= "os-image",
238 .last_sysupgrade_partition
= "support-list",
241 /** Firmware layout for the CPE220 V2 */
244 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
247 "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n"
248 "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n"
249 "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n"
250 "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n"
251 "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n"
252 "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n"
253 "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n"
254 "CPE220(TP-LINK|UN|N300-2):2.0\r\n"
255 "CPE220(TP-LINK|EU|N300-2):2.0\r\n"
256 "CPE220(TP-LINK|US|N300-2):2.0\r\n",
257 .support_trail
= '\xff',
261 {"fs-uboot", 0x00000, 0x20000},
262 {"partition-table", 0x20000, 0x02000},
263 {"default-mac", 0x30000, 0x00020},
264 {"product-info", 0x31100, 0x00100},
265 {"signature", 0x32000, 0x00400},
266 {"os-image", 0x40000, 0x300000},
267 {"file-system", 0x340000, 0x470000},
268 {"soft-version", 0x7b0000, 0x00100},
269 {"support-list", 0x7b1000, 0x00400},
270 {"user-config", 0x7c0000, 0x10000},
271 {"default-config", 0x7d0000, 0x10000},
272 {"log", 0x7e0000, 0x10000},
273 {"radio", 0x7f0000, 0x10000},
277 .first_sysupgrade_partition
= "os-image",
278 .last_sysupgrade_partition
= "support-list",
281 /** Firmware layout for the CPE220 V3 */
284 .vendor
= "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n",
287 "CPE220(TP-LINK|EU|N300-2|00000000):3.0\r\n"
288 "CPE220(TP-LINK|EU|N300-2|45550000):3.0\r\n"
289 "CPE220(TP-LINK|EU|N300-2|55530000):3.0\r\n"
290 "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n"
291 "CPE220(TP-LINK|UN|N300-2|45550000):3.0\r\n"
292 "CPE220(TP-LINK|UN|N300-2|55530000):3.0\r\n"
293 "CPE220(TP-LINK|US|N300-2|55530000):3.0\r\n"
294 "CPE220(TP-LINK|UN|N300-2):3.0\r\n"
295 "CPE220(TP-LINK|EU|N300-2):3.0\r\n"
296 "CPE220(TP-LINK|US|N300-2):3.0\r\n",
297 .support_trail
= '\xff',
301 {"fs-uboot", 0x00000, 0x20000},
302 {"partition-table", 0x20000, 0x02000},
303 {"default-mac", 0x30000, 0x00020},
304 {"product-info", 0x31100, 0x00100},
305 {"device-info", 0x31400, 0x00400},
306 {"signature", 0x32000, 0x00400},
307 {"device-id", 0x33000, 0x00100},
308 {"firmware", 0x40000, 0x770000},
309 {"soft-version", 0x7b0000, 0x00100},
310 {"support-list", 0x7b1000, 0x01000},
311 {"user-config", 0x7c0000, 0x10000},
312 {"default-config", 0x7d0000, 0x10000},
313 {"log", 0x7e0000, 0x10000},
314 {"radio", 0x7f0000, 0x10000},
318 .first_sysupgrade_partition
= "os-image",
319 .last_sysupgrade_partition
= "support-list",
322 /** Firmware layout for the CPE510/520 V1 */
325 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
328 "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
329 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
330 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
331 "CPE510(TP-LINK|US|N300-5):1.1\r\n"
332 "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
333 "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
334 "CPE520(TP-LINK|US|N300-5):1.1\r\n"
335 "CPE520(TP-LINK|EU|N300-5):1.1\r\n",
336 .support_trail
= '\xff',
340 {"fs-uboot", 0x00000, 0x20000},
341 {"partition-table", 0x20000, 0x02000},
342 {"default-mac", 0x30000, 0x00020},
343 {"product-info", 0x31100, 0x00100},
344 {"signature", 0x32000, 0x00400},
345 {"os-image", 0x40000, 0x300000},
346 {"file-system", 0x340000, 0x470000},
347 {"soft-version", 0x7b0000, 0x00100},
348 {"support-list", 0x7b1000, 0x00400},
349 {"user-config", 0x7c0000, 0x10000},
350 {"default-config", 0x7d0000, 0x10000},
351 {"log", 0x7e0000, 0x10000},
352 {"radio", 0x7f0000, 0x10000},
356 .first_sysupgrade_partition
= "os-image",
357 .last_sysupgrade_partition
= "support-list",
360 /** Firmware layout for the CPE510 V2 */
363 .vendor
= "CPE510(TP-LINK|UN|N300-5):2.0\r\n",
366 "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
367 "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
368 "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
369 "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
370 "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
371 "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
372 "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n"
373 "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n"
374 "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
375 "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
376 "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
377 "CPE510(TP-LINK|US|N300-5):2.0\r\n",
378 .support_trail
= '\xff',
382 {"fs-uboot", 0x00000, 0x20000},
383 {"partition-table", 0x20000, 0x02000},
384 {"default-mac", 0x30000, 0x00020},
385 {"product-info", 0x31100, 0x00100},
386 {"signature", 0x32000, 0x00400},
387 {"os-image", 0x40000, 0x300000},
388 {"file-system", 0x340000, 0x470000},
389 {"soft-version", 0x7b0000, 0x00100},
390 {"support-list", 0x7b1000, 0x00400},
391 {"user-config", 0x7c0000, 0x10000},
392 {"default-config", 0x7d0000, 0x10000},
393 {"log", 0x7e0000, 0x10000},
394 {"radio", 0x7f0000, 0x10000},
398 .first_sysupgrade_partition
= "os-image",
399 .last_sysupgrade_partition
= "support-list",
402 /** Firmware layout for the CPE510 V3 */
405 .vendor
= "CPE510(TP-LINK|UN|N300-5):3.0\r\n",
408 "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n"
409 "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n"
410 "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n"
411 "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n"
412 "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n"
413 "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n"
414 "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n"
415 "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n"
416 "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n"
417 "CPE510(TP-LINK|UN|N300-5):3.0\r\n"
418 "CPE510(TP-LINK|EU|N300-5):3.0\r\n"
419 "CPE510(TP-LINK|US|N300-5):3.0\r\n",
420 .support_trail
= '\xff',
424 {"fs-uboot", 0x00000, 0x20000},
425 {"partition-table", 0x20000, 0x02000},
426 {"default-mac", 0x30000, 0x00020},
427 {"product-info", 0x31100, 0x00100},
428 {"signature", 0x32000, 0x00400},
429 {"os-image", 0x40000, 0x300000},
430 {"file-system", 0x340000, 0x470000},
431 {"soft-version", 0x7b0000, 0x00100},
432 {"support-list", 0x7b1000, 0x00400},
433 {"user-config", 0x7c0000, 0x10000},
434 {"default-config", 0x7d0000, 0x10000},
435 {"log", 0x7e0000, 0x10000},
436 {"radio", 0x7f0000, 0x10000},
440 .first_sysupgrade_partition
= "os-image",
441 .last_sysupgrade_partition
= "support-list",
444 /** Firmware layout for the CPE610V1 */
447 .vendor
= "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n",
450 "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n"
451 "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n"
452 "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n"
453 "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n"
454 "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n"
455 "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n"
456 "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n"
457 "CPE610(TP-LINK|UN|N300-5):1.0\r\n"
458 "CPE610(TP-LINK|EU|N300-5):1.0\r\n"
459 "CPE610(TP-LINK|US|N300-5):1.0\r\n",
460 .support_trail
= '\xff',
464 {"fs-uboot", 0x00000, 0x20000},
465 {"partition-table", 0x20000, 0x02000},
466 {"default-mac", 0x30000, 0x00020},
467 {"product-info", 0x31100, 0x00100},
468 {"signature", 0x32000, 0x00400},
469 {"os-image", 0x40000, 0x300000},
470 {"file-system", 0x340000, 0x470000},
471 {"soft-version", 0x7b0000, 0x00100},
472 {"support-list", 0x7b1000, 0x00400},
473 {"user-config", 0x7c0000, 0x10000},
474 {"default-config", 0x7d0000, 0x10000},
475 {"log", 0x7e0000, 0x10000},
476 {"radio", 0x7f0000, 0x10000},
480 .first_sysupgrade_partition
= "os-image",
481 .last_sysupgrade_partition
= "support-list",
484 /** Firmware layout for the CPE610V2 */
487 .vendor
= "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n",
490 "CPE610(TP-LINK|EU|N300-5|00000000):2.0\r\n"
491 "CPE610(TP-LINK|EU|N300-5|45550000):2.0\r\n"
492 "CPE610(TP-LINK|EU|N300-5|55530000):2.0\r\n"
493 "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n"
494 "CPE610(TP-LINK|UN|N300-5|45550000):2.0\r\n"
495 "CPE610(TP-LINK|UN|N300-5|55530000):2.0\r\n"
496 "CPE610(TP-LINK|US|N300-5|55530000):2.0\r\n"
497 "CPE610(TP-LINK|UN|N300-5):2.0\r\n"
498 "CPE610(TP-LINK|EU|N300-5):2.0\r\n"
499 "CPE610(TP-LINK|US|N300-5):2.0\r\n",
500 .support_trail
= '\xff',
504 {"fs-uboot", 0x00000, 0x20000},
505 {"partition-table", 0x20000, 0x02000},
506 {"default-mac", 0x30000, 0x00020},
507 {"product-info", 0x31100, 0x00100},
508 {"signature", 0x32000, 0x00400},
509 {"os-image", 0x40000, 0x300000},
510 {"file-system", 0x340000, 0x470000},
511 {"soft-version", 0x7b0000, 0x00100},
512 {"support-list", 0x7b1000, 0x00400},
513 {"user-config", 0x7c0000, 0x10000},
514 {"default-config", 0x7d0000, 0x10000},
515 {"log", 0x7e0000, 0x10000},
516 {"radio", 0x7f0000, 0x10000},
520 .first_sysupgrade_partition
= "os-image",
521 .last_sysupgrade_partition
= "support-list",
526 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
529 "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
530 "WBS210(TP-LINK|US|N300-2):1.20\r\n"
531 "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
532 .support_trail
= '\xff',
536 {"fs-uboot", 0x00000, 0x20000},
537 {"partition-table", 0x20000, 0x02000},
538 {"default-mac", 0x30000, 0x00020},
539 {"product-info", 0x31100, 0x00100},
540 {"signature", 0x32000, 0x00400},
541 {"os-image", 0x40000, 0x300000},
542 {"file-system", 0x340000, 0x470000},
543 {"soft-version", 0x7b0000, 0x00100},
544 {"support-list", 0x7b1000, 0x00400},
545 {"user-config", 0x7c0000, 0x10000},
546 {"default-config", 0x7d0000, 0x10000},
547 {"log", 0x7e0000, 0x10000},
548 {"radio", 0x7f0000, 0x10000},
552 .first_sysupgrade_partition
= "os-image",
553 .last_sysupgrade_partition
= "support-list",
558 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
561 "WBS210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
562 "WBS210(TP-LINK|US|N300-2|55530000):2.0\r\n"
563 "WBS210(TP-LINK|EU|N300-2|45550000):2.0\r\n",
564 .support_trail
= '\xff',
568 {"fs-uboot", 0x00000, 0x20000},
569 {"partition-table", 0x20000, 0x02000},
570 {"default-mac", 0x30000, 0x00020},
571 {"product-info", 0x31100, 0x00100},
572 {"signature", 0x32000, 0x00400},
573 {"os-image", 0x40000, 0x300000},
574 {"file-system", 0x340000, 0x470000},
575 {"soft-version", 0x7b0000, 0x00100},
576 {"support-list", 0x7b1000, 0x00400},
577 {"user-config", 0x7c0000, 0x10000},
578 {"default-config", 0x7d0000, 0x10000},
579 {"log", 0x7e0000, 0x10000},
580 {"radio", 0x7f0000, 0x10000},
584 .first_sysupgrade_partition
= "os-image",
585 .last_sysupgrade_partition
= "support-list",
590 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
593 "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
594 "WBS510(TP-LINK|US|N300-5):1.20\r\n"
595 "WBS510(TP-LINK|EU|N300-5):1.20\r\n"
596 "WBS510(TP-LINK|CA|N300-5):1.20\r\n",
597 .support_trail
= '\xff',
601 {"fs-uboot", 0x00000, 0x20000},
602 {"partition-table", 0x20000, 0x02000},
603 {"default-mac", 0x30000, 0x00020},
604 {"product-info", 0x31100, 0x00100},
605 {"signature", 0x32000, 0x00400},
606 {"os-image", 0x40000, 0x300000},
607 {"file-system", 0x340000, 0x470000},
608 {"soft-version", 0x7b0000, 0x00100},
609 {"support-list", 0x7b1000, 0x00400},
610 {"user-config", 0x7c0000, 0x10000},
611 {"default-config", 0x7d0000, 0x10000},
612 {"log", 0x7e0000, 0x10000},
613 {"radio", 0x7f0000, 0x10000},
617 .first_sysupgrade_partition
= "os-image",
618 .last_sysupgrade_partition
= "support-list",
623 .vendor
= "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
626 "WBS510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
627 "WBS510(TP-LINK|US|N300-5|55530000):2.0\r\n"
628 "WBS510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
629 "WBS510(TP-LINK|CA|N300-5|43410000):2.0\r\n",
630 .support_trail
= '\xff',
634 {"fs-uboot", 0x00000, 0x20000},
635 {"partition-table", 0x20000, 0x02000},
636 {"default-mac", 0x30000, 0x00020},
637 {"product-info", 0x31100, 0x00100},
638 {"signature", 0x32000, 0x00400},
639 {"os-image", 0x40000, 0x300000},
640 {"file-system", 0x340000, 0x470000},
641 {"soft-version", 0x7b0000, 0x00100},
642 {"support-list", 0x7b1000, 0x00400},
643 {"user-config", 0x7c0000, 0x10000},
644 {"default-config", 0x7d0000, 0x10000},
645 {"log", 0x7e0000, 0x10000},
646 {"radio", 0x7f0000, 0x10000},
650 .first_sysupgrade_partition
= "os-image",
651 .last_sysupgrade_partition
= "support-list",
654 /** Firmware layout for the C2600 */
660 "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
661 .support_trail
= '\x00',
665 We use a bigger os-image partition than the stock images (and thus
666 smaller file-system), as our kernel doesn't fit in the stock firmware's
667 2 MB os-image since kernel 4.14.
670 {"SBL1", 0x00000, 0x20000},
671 {"MIBIB", 0x20000, 0x20000},
672 {"SBL2", 0x40000, 0x20000},
673 {"SBL3", 0x60000, 0x30000},
674 {"DDRCONFIG", 0x90000, 0x10000},
675 {"SSD", 0xa0000, 0x10000},
676 {"TZ", 0xb0000, 0x30000},
677 {"RPM", 0xe0000, 0x20000},
678 {"fs-uboot", 0x100000, 0x70000},
679 {"uboot-env", 0x170000, 0x40000},
680 {"radio", 0x1b0000, 0x40000},
681 {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
682 {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
683 {"default-mac", 0x1ef0000, 0x00200},
684 {"pin", 0x1ef0200, 0x00200},
685 {"product-info", 0x1ef0400, 0x0fc00},
686 {"partition-table", 0x1f00000, 0x10000},
687 {"soft-version", 0x1f10000, 0x10000},
688 {"support-list", 0x1f20000, 0x10000},
689 {"profile", 0x1f30000, 0x10000},
690 {"default-config", 0x1f40000, 0x10000},
691 {"user-config", 0x1f50000, 0x40000},
692 {"qos-db", 0x1f90000, 0x40000},
693 {"usb-config", 0x1fd0000, 0x10000},
694 {"log", 0x1fe0000, 0x20000},
698 .first_sysupgrade_partition
= "os-image",
699 .last_sysupgrade_partition
= "file-system"
702 /** Firmware layout for the A7-V5 */
704 .id
= "ARCHER-A7-V5",
707 "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n"
708 "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n"
709 "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n"
710 "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n"
711 "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n",
712 .support_trail
= '\x00',
713 .soft_ver
= "soft_ver:1.0.0\n",
715 /* We're using a dynamic kernel/rootfs split here */
717 {"factory-boot", 0x00000, 0x20000},
718 {"fs-uboot", 0x20000, 0x20000},
719 {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
720 /* Stock: name file-system base 0x160000 size 0xda0000 */
721 {"default-mac", 0xf40000, 0x00200},
722 {"pin", 0xf40200, 0x00200},
723 {"device-id", 0xf40400, 0x00100},
724 {"product-info", 0xf40500, 0x0fb00},
725 {"soft-version", 0xf50000, 0x00100},
726 {"extra-para", 0xf51000, 0x01000},
727 {"support-list", 0xf52000, 0x0a000},
728 {"profile", 0xf5c000, 0x04000},
729 {"default-config", 0xf60000, 0x10000},
730 {"user-config", 0xf70000, 0x40000},
731 {"certificate", 0xfb0000, 0x10000},
732 {"partition-table", 0xfc0000, 0x10000},
733 {"log", 0xfd0000, 0x20000},
734 {"radio", 0xff0000, 0x10000},
738 .first_sysupgrade_partition
= "os-image",
739 .last_sysupgrade_partition
= "file-system",
742 /** Firmware layout for the C2v3 */
744 .id
= "ARCHER-C2-V3",
747 "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n"
748 "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n"
749 "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n",
750 .support_trail
= '\x00',
751 .soft_ver
= "soft_ver:3.0.1\n",
753 /** We're using a dynamic kernel/rootfs split here */
756 {"factory-boot", 0x00000, 0x20000},
757 {"fs-uboot", 0x20000, 0x10000},
758 {"firmware", 0x30000, 0x7a0000},
759 {"user-config", 0x7d0000, 0x04000},
760 {"default-mac", 0x7e0000, 0x00100},
761 {"device-id", 0x7e0100, 0x00100},
762 {"extra-para", 0x7e0200, 0x00100},
763 {"pin", 0x7e0300, 0x00100},
764 {"support-list", 0x7e0400, 0x00400},
765 {"soft-version", 0x7e0800, 0x00400},
766 {"product-info", 0x7e0c00, 0x01400},
767 {"partition-table", 0x7e2000, 0x01000},
768 {"profile", 0x7e3000, 0x01000},
769 {"default-config", 0x7e4000, 0x04000},
770 {"merge-config", 0x7ec000, 0x02000},
771 {"qos-db", 0x7ee000, 0x02000},
772 {"radio", 0x7f0000, 0x10000},
776 .first_sysupgrade_partition
= "os-image",
777 .last_sysupgrade_partition
= "file-system",
780 /** Firmware layout for the C25v1 */
782 .id
= "ARCHER-C25-V1",
785 "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
786 "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
787 "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
788 .support_trail
= '\x00',
789 .soft_ver
= "soft_ver:1.0.0\n",
791 /* We're using a dynamic kernel/rootfs split here */
793 {"factory-boot", 0x00000, 0x20000},
794 {"fs-uboot", 0x20000, 0x10000},
795 {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */
796 /* Stock: name file-system base 0x130000 size 0x6a0000 */
797 {"user-config", 0x7d0000, 0x04000},
798 {"default-mac", 0x7e0000, 0x00100},
799 {"device-id", 0x7e0100, 0x00100},
800 {"extra-para", 0x7e0200, 0x00100},
801 {"pin", 0x7e0300, 0x00100},
802 {"support-list", 0x7e0400, 0x00400},
803 {"soft-version", 0x7e0800, 0x00400},
804 {"product-info", 0x7e0c00, 0x01400},
805 {"partition-table", 0x7e2000, 0x01000},
806 {"profile", 0x7e3000, 0x01000},
807 {"default-config", 0x7e4000, 0x04000},
808 {"merge-config", 0x7ec000, 0x02000},
809 {"qos-db", 0x7ee000, 0x02000},
810 {"radio", 0x7f0000, 0x10000},
814 .first_sysupgrade_partition
= "os-image",
815 .last_sysupgrade_partition
= "file-system",
818 /** Firmware layout for the C58v1 */
820 .id
= "ARCHER-C58-V1",
824 "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
825 "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
826 "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
827 .support_trail
= '\x00',
828 .soft_ver
= "soft_ver:1.0.0\n",
831 {"fs-uboot", 0x00000, 0x10000},
832 {"default-mac", 0x10000, 0x00200},
833 {"pin", 0x10200, 0x00200},
834 {"product-info", 0x10400, 0x00100},
835 {"partition-table", 0x10500, 0x00800},
836 {"soft-version", 0x11300, 0x00200},
837 {"support-list", 0x11500, 0x00100},
838 {"device-id", 0x11600, 0x00100},
839 {"profile", 0x11700, 0x03900},
840 {"default-config", 0x15000, 0x04000},
841 {"user-config", 0x19000, 0x04000},
842 {"firmware", 0x20000, 0x7c8000},
843 {"certyficate", 0x7e8000, 0x08000},
844 {"radio", 0x7f0000, 0x10000},
848 .first_sysupgrade_partition
= "os-image",
849 .last_sysupgrade_partition
= "file-system",
852 /** Firmware layout for the C59v1 */
854 .id
= "ARCHER-C59-V1",
858 "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
859 "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
860 "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
861 "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
862 .support_trail
= '\x00',
863 .soft_ver
= "soft_ver:1.0.0\n",
865 /* We're using a dynamic kernel/rootfs split here */
867 {"fs-uboot", 0x00000, 0x10000},
868 {"default-mac", 0x10000, 0x00200},
869 {"pin", 0x10200, 0x00200},
870 {"device-id", 0x10400, 0x00100},
871 {"product-info", 0x10500, 0x0fb00},
872 {"firmware", 0x20000, 0xe30000},
873 {"partition-table", 0xe50000, 0x10000},
874 {"soft-version", 0xe60000, 0x10000},
875 {"support-list", 0xe70000, 0x10000},
876 {"profile", 0xe80000, 0x10000},
877 {"default-config", 0xe90000, 0x10000},
878 {"user-config", 0xea0000, 0x40000},
879 {"usb-config", 0xee0000, 0x10000},
880 {"certificate", 0xef0000, 0x10000},
881 {"qos-db", 0xf00000, 0x40000},
882 {"log", 0xfe0000, 0x10000},
883 {"radio", 0xff0000, 0x10000},
887 .first_sysupgrade_partition
= "os-image",
888 .last_sysupgrade_partition
= "file-system",
891 /** Firmware layout for the C59v2 */
893 .id
= "ARCHER-C59-V2",
897 "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
898 "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
899 "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
900 .support_trail
= '\x00',
901 .soft_ver
= "soft_ver:2.0.0 Build 20161206 rel.7303\n",
903 /** We're using a dynamic kernel/rootfs split here */
905 {"factory-boot", 0x00000, 0x20000},
906 {"fs-uboot", 0x20000, 0x10000},
907 {"default-mac", 0x30000, 0x00200},
908 {"pin", 0x30200, 0x00200},
909 {"device-id", 0x30400, 0x00100},
910 {"product-info", 0x30500, 0x0fb00},
911 {"firmware", 0x40000, 0xe10000},
912 {"partition-table", 0xe50000, 0x10000},
913 {"soft-version", 0xe60000, 0x10000},
914 {"support-list", 0xe70000, 0x10000},
915 {"profile", 0xe80000, 0x10000},
916 {"default-config", 0xe90000, 0x10000},
917 {"user-config", 0xea0000, 0x40000},
918 {"usb-config", 0xee0000, 0x10000},
919 {"certificate", 0xef0000, 0x10000},
920 {"extra-para", 0xf00000, 0x10000},
921 {"qos-db", 0xf10000, 0x30000},
922 {"log", 0xfe0000, 0x10000},
923 {"radio", 0xff0000, 0x10000},
927 .first_sysupgrade_partition
= "os-image",
928 .last_sysupgrade_partition
= "file-system",
931 /** Firmware layout for the Archer C6 v2 (EU/RU/JP) */
933 .id
= "ARCHER-C6-V2",
937 "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n"
938 "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
939 "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
940 .support_trail
= '\x00',
941 .soft_ver
= "soft_ver:1.9.1\n",
944 {"fs-uboot", 0x00000, 0x20000},
945 {"default-mac", 0x20000, 0x00200},
946 {"pin", 0x20200, 0x00100},
947 {"product-info", 0x20300, 0x00200},
948 {"device-id", 0x20500, 0x0fb00},
949 {"firmware", 0x30000, 0x7a9400},
950 {"soft-version", 0x7d9400, 0x00100},
951 {"extra-para", 0x7d9500, 0x00100},
952 {"support-list", 0x7d9600, 0x00200},
953 {"profile", 0x7d9800, 0x03000},
954 {"default-config", 0x7dc800, 0x03000},
955 {"partition-table", 0x7df800, 0x00800},
956 {"user-config", 0x7e0000, 0x0c000},
957 {"certificate", 0x7ec000, 0x04000},
958 {"radio", 0x7f0000, 0x10000},
962 .first_sysupgrade_partition
= "os-image",
963 .last_sysupgrade_partition
= "file-system",
966 /** Firmware layout for the Archer C6 v2 (US) and A6 v2 (US/TW) */
968 .id
= "ARCHER-C6-V2-US",
972 "{product_name:Archer A6,product_ver:2.0.0,special_id:55530000}\n"
973 "{product_name:Archer A6,product_ver:2.0.0,special_id:54570000}\n"
974 "{product_name:Archer C6,product_ver:2.0.0,special_id:55530000}\n",
975 .support_trail
= '\x00',
976 .soft_ver
= "soft_ver:1.9.1\n",
979 {"factory-boot", 0x00000, 0x20000},
980 {"default-mac", 0x20000, 0x00200},
981 {"pin", 0x20200, 0x00100},
982 {"product-info", 0x20300, 0x00200},
983 {"device-id", 0x20500, 0x0fb00},
984 {"fs-uboot", 0x30000, 0x20000},
985 {"firmware", 0x50000, 0xf89400},
986 {"soft-version", 0xfd9400, 0x00100},
987 {"extra-para", 0xfd9500, 0x00100},
988 {"support-list", 0xfd9600, 0x00200},
989 {"profile", 0xfd9800, 0x03000},
990 {"default-config", 0xfdc800, 0x03000},
991 {"partition-table", 0xfdf800, 0x00800},
992 {"user-config", 0xfe0000, 0x0c000},
993 {"certificate", 0xfec000, 0x04000},
994 {"radio", 0xff0000, 0x10000},
997 .first_sysupgrade_partition
= "os-image",
998 .last_sysupgrade_partition
= "file-system",
1001 /** Firmware layout for the C60v1 */
1003 .id
= "ARCHER-C60-V1",
1007 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
1008 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
1009 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
1010 .support_trail
= '\x00',
1011 .soft_ver
= "soft_ver:1.0.0\n",
1014 {"fs-uboot", 0x00000, 0x10000},
1015 {"default-mac", 0x10000, 0x00200},
1016 {"pin", 0x10200, 0x00200},
1017 {"product-info", 0x10400, 0x00100},
1018 {"partition-table", 0x10500, 0x00800},
1019 {"soft-version", 0x11300, 0x00200},
1020 {"support-list", 0x11500, 0x00100},
1021 {"device-id", 0x11600, 0x00100},
1022 {"profile", 0x11700, 0x03900},
1023 {"default-config", 0x15000, 0x04000},
1024 {"user-config", 0x19000, 0x04000},
1025 {"firmware", 0x20000, 0x7c8000},
1026 {"certyficate", 0x7e8000, 0x08000},
1027 {"radio", 0x7f0000, 0x10000},
1031 .first_sysupgrade_partition
= "os-image",
1032 .last_sysupgrade_partition
= "file-system",
1035 /** Firmware layout for the C60v2 */
1037 .id
= "ARCHER-C60-V2",
1041 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
1042 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
1043 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
1044 .support_trail
= '\x00',
1045 .soft_ver
= "soft_ver:2.0.0\n",
1048 {"factory-boot", 0x00000, 0x1fb00},
1049 {"default-mac", 0x1fb00, 0x00200},
1050 {"pin", 0x1fd00, 0x00100},
1051 {"product-info", 0x1fe00, 0x00100},
1052 {"device-id", 0x1ff00, 0x00100},
1053 {"fs-uboot", 0x20000, 0x10000},
1054 {"firmware", 0x30000, 0x7a0000},
1055 {"soft-version", 0x7d9500, 0x00100},
1056 {"support-list", 0x7d9600, 0x00100},
1057 {"extra-para", 0x7d9700, 0x00100},
1058 {"profile", 0x7d9800, 0x03000},
1059 {"default-config", 0x7dc800, 0x03000},
1060 {"partition-table", 0x7df800, 0x00800},
1061 {"user-config", 0x7e0000, 0x0c000},
1062 {"certificate", 0x7ec000, 0x04000},
1063 {"radio", 0x7f0000, 0x10000},
1067 .first_sysupgrade_partition
= "os-image",
1068 .last_sysupgrade_partition
= "file-system",
1071 /** Firmware layout for the C60v3 */
1073 .id
= "ARCHER-C60-V3",
1077 "{product_name:Archer C60,product_ver:3.0.0,special_id:42520000}\r\n"
1078 "{product_name:Archer C60,product_ver:3.0.0,special_id:45550000}\r\n"
1079 "{product_name:Archer C60,product_ver:3.0.0,special_id:55530000}\r\n",
1080 .support_trail
= '\x00',
1081 .soft_ver
= "soft_ver:3.0.0\n",
1084 {"factory-boot", 0x00000, 0x1fb00},
1085 {"default-mac", 0x1fb00, 0x00200},
1086 {"pin", 0x1fd00, 0x00100},
1087 {"product-info", 0x1fe00, 0x00100},
1088 {"device-id", 0x1ff00, 0x00100},
1089 {"fs-uboot", 0x20000, 0x10000},
1090 {"firmware", 0x30000, 0x7a0000},
1091 {"soft-version", 0x7d9500, 0x00100},
1092 {"support-list", 0x7d9600, 0x00100},
1093 {"extra-para", 0x7d9700, 0x00100},
1094 {"profile", 0x7d9800, 0x03000},
1095 {"default-config", 0x7dc800, 0x03000},
1096 {"partition-table", 0x7df800, 0x00800},
1097 {"user-config", 0x7e0000, 0x0c000},
1098 {"certificate", 0x7ec000, 0x04000},
1099 {"radio", 0x7f0000, 0x10000},
1103 .first_sysupgrade_partition
= "os-image",
1104 .last_sysupgrade_partition
= "file-system",
1107 /** Firmware layout for the C5 */
1109 .id
= "ARCHER-C5-V2",
1113 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
1114 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
1115 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
1116 .support_trail
= '\x00',
1120 {"fs-uboot", 0x00000, 0x40000},
1121 {"os-image", 0x40000, 0x200000},
1122 {"file-system", 0x240000, 0xc00000},
1123 {"default-mac", 0xe40000, 0x00200},
1124 {"pin", 0xe40200, 0x00200},
1125 {"product-info", 0xe40400, 0x00200},
1126 {"partition-table", 0xe50000, 0x10000},
1127 {"soft-version", 0xe60000, 0x00200},
1128 {"support-list", 0xe61000, 0x0f000},
1129 {"profile", 0xe70000, 0x10000},
1130 {"default-config", 0xe80000, 0x10000},
1131 {"user-config", 0xe90000, 0x50000},
1132 {"log", 0xee0000, 0x100000},
1133 {"radio_bk", 0xfe0000, 0x10000},
1134 {"radio", 0xff0000, 0x10000},
1138 .first_sysupgrade_partition
= "os-image",
1139 .last_sysupgrade_partition
= "file-system"
1142 /** Firmware layout for the C7 */
1144 .id
= "ARCHER-C7-V4",
1147 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
1148 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
1149 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
1150 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
1151 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
1152 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
1153 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
1154 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
1155 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
1156 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
1157 .support_trail
= '\x00',
1158 .soft_ver
= "soft_ver:1.0.0\n",
1160 /* We're using a dynamic kernel/rootfs split here */
1162 {"factory-boot", 0x00000, 0x20000},
1163 {"fs-uboot", 0x20000, 0x20000},
1164 {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
1165 /* Stock: name file-system base 0x160000 size 0xda0000 */
1166 {"default-mac", 0xf00000, 0x00200},
1167 {"pin", 0xf00200, 0x00200},
1168 {"device-id", 0xf00400, 0x00100},
1169 {"product-info", 0xf00500, 0x0fb00},
1170 {"soft-version", 0xf10000, 0x00100},
1171 {"extra-para", 0xf11000, 0x01000},
1172 {"support-list", 0xf12000, 0x0a000},
1173 {"profile", 0xf1c000, 0x04000},
1174 {"default-config", 0xf20000, 0x10000},
1175 {"user-config", 0xf30000, 0x40000},
1176 {"qos-db", 0xf70000, 0x40000},
1177 {"certificate", 0xfb0000, 0x10000},
1178 {"partition-table", 0xfc0000, 0x10000},
1179 {"log", 0xfd0000, 0x20000},
1180 {"radio", 0xff0000, 0x10000},
1184 .first_sysupgrade_partition
= "os-image",
1185 .last_sysupgrade_partition
= "file-system",
1188 /** Firmware layout for the C7 v5*/
1190 .id
= "ARCHER-C7-V5",
1193 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1194 "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1195 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1196 "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1197 "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1198 "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1199 "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1200 "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1202 .support_trail
= '\x00',
1203 .soft_ver
= "soft_ver:1.0.0\n",
1205 /* We're using a dynamic kernel/rootfs split here */
1207 {"factory-boot", 0x00000, 0x20000},
1208 {"fs-uboot", 0x20000, 0x20000},
1209 {"partition-table", 0x40000, 0x10000},
1210 {"radio", 0x50000, 0x10000},
1211 {"default-mac", 0x60000, 0x00200},
1212 {"pin", 0x60200, 0x00200},
1213 {"device-id", 0x60400, 0x00100},
1214 {"product-info", 0x60500, 0x0fb00},
1215 {"soft-version", 0x70000, 0x01000},
1216 {"extra-para", 0x71000, 0x01000},
1217 {"support-list", 0x72000, 0x0a000},
1218 {"profile", 0x7c000, 0x04000},
1219 {"user-config", 0x80000, 0x40000},
1222 {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */
1223 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1225 {"log", 0xfc0000, 0x20000},
1226 {"certificate", 0xfe0000, 0x10000},
1227 {"default-config", 0xff0000, 0x10000},
1232 .first_sysupgrade_partition
= "os-image",
1233 .last_sysupgrade_partition
= "file-system",
1236 /** Firmware layout for the C9 */
1242 "{product_name:ArcherC9,"
1243 "product_ver:1.0.0,"
1244 "special_id:00000000}\n",
1245 .support_trail
= '\x00',
1249 {"fs-uboot", 0x00000, 0x40000},
1250 {"os-image", 0x40000, 0x200000},
1251 {"file-system", 0x240000, 0xc00000},
1252 {"default-mac", 0xe40000, 0x00200},
1253 {"pin", 0xe40200, 0x00200},
1254 {"product-info", 0xe40400, 0x00200},
1255 {"partition-table", 0xe50000, 0x10000},
1256 {"soft-version", 0xe60000, 0x00200},
1257 {"support-list", 0xe61000, 0x0f000},
1258 {"profile", 0xe70000, 0x10000},
1259 {"default-config", 0xe80000, 0x10000},
1260 {"user-config", 0xe90000, 0x50000},
1261 {"log", 0xee0000, 0x100000},
1262 {"radio_bk", 0xfe0000, 0x10000},
1263 {"radio", 0xff0000, 0x10000},
1267 .first_sysupgrade_partition
= "os-image",
1268 .last_sysupgrade_partition
= "file-system"
1271 /** Firmware layout for the EAP120 */
1274 .vendor
= "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1277 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1278 .support_trail
= '\xff',
1282 {"fs-uboot", 0x00000, 0x20000},
1283 {"partition-table", 0x20000, 0x02000},
1284 {"default-mac", 0x30000, 0x00020},
1285 {"support-list", 0x31000, 0x00100},
1286 {"product-info", 0x31100, 0x00100},
1287 {"soft-version", 0x32000, 0x00100},
1288 {"os-image", 0x40000, 0x180000},
1289 {"file-system", 0x1c0000, 0x600000},
1290 {"user-config", 0x7c0000, 0x10000},
1291 {"backup-config", 0x7d0000, 0x10000},
1292 {"log", 0x7e0000, 0x10000},
1293 {"radio", 0x7f0000, 0x10000},
1297 .first_sysupgrade_partition
= "os-image",
1298 .last_sysupgrade_partition
= "file-system"
1301 /** Firmware layout for the EAP225-Wall v2 */
1303 .id
= "EAP225-WALL-V2",
1306 "EAP225-Wall(TP-Link|UN|AC1200-D):2.0\r\n",
1307 .support_trail
= '\xff',
1309 .soft_ver_compat_level
= 1,
1312 {"fs-uboot", 0x00000, 0x20000},
1313 {"partition-table", 0x20000, 0x02000},
1314 {"default-mac", 0x30000, 0x01000},
1315 {"support-list", 0x31000, 0x00100},
1316 {"product-info", 0x31100, 0x00400},
1317 {"soft-version", 0x32000, 0x00100},
1318 {"firmware", 0x40000, 0xd80000},
1319 {"user-config", 0xdc0000, 0x30000},
1320 {"mutil-log", 0xf30000, 0x80000},
1321 {"oops", 0xfb0000, 0x40000},
1322 {"radio", 0xff0000, 0x10000},
1326 .first_sysupgrade_partition
= "os-image",
1327 .last_sysupgrade_partition
= "file-system"
1330 /** Firmware layout for the EAP245 v3 */
1335 "EAP245(TP-Link|UN|AC1750-D):3.0\r\n",
1336 .support_trail
= '\xff',
1338 .soft_ver_compat_level
= 1,
1340 /** Firmware partition with dynamic kernel/rootfs split */
1342 {"factroy-boot", 0x00000, 0x40000},
1343 {"fs-uboot", 0x40000, 0x40000},
1344 {"partition-table", 0x80000, 0x10000},
1345 {"default-mac", 0x90000, 0x01000},
1346 {"support-list", 0x91000, 0x00100},
1347 {"product-info", 0x91100, 0x00400},
1348 {"soft-version", 0x92000, 0x00100},
1349 {"radio", 0xa0000, 0x10000},
1350 {"extra-para", 0xb0000, 0x10000},
1351 {"firmware", 0xc0000, 0xe40000},
1352 {"config", 0xf00000, 0x30000},
1353 {"mutil-log", 0xf30000, 0x80000},
1354 {"oops", 0xfb0000, 0x40000},
1358 .first_sysupgrade_partition
= "os-image",
1359 .last_sysupgrade_partition
= "file-system"
1362 /** Firmware layout for the TL-WA850RE v2 */
1364 .id
= "TLWA850REV2",
1368 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1369 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1370 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1371 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1372 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1373 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1374 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1375 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1376 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1377 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1378 .support_trail
= '\x00',
1382 576KB were moved from file-system to os-image
1383 in comparison to the stock image
1386 {"fs-uboot", 0x00000, 0x20000},
1387 {"firmware", 0x20000, 0x390000},
1388 {"partition-table", 0x3b0000, 0x02000},
1389 {"default-mac", 0x3c0000, 0x00020},
1390 {"pin", 0x3c0100, 0x00020},
1391 {"product-info", 0x3c1000, 0x01000},
1392 {"soft-version", 0x3c2000, 0x00100},
1393 {"support-list", 0x3c3000, 0x01000},
1394 {"profile", 0x3c4000, 0x08000},
1395 {"user-config", 0x3d0000, 0x10000},
1396 {"default-config", 0x3e0000, 0x10000},
1397 {"radio", 0x3f0000, 0x10000},
1401 .first_sysupgrade_partition
= "os-image",
1402 .last_sysupgrade_partition
= "file-system"
1405 /** Firmware layout for the TL-WA855RE v1 */
1407 .id
= "TLWA855REV1",
1411 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1412 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1413 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1414 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1415 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1416 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1417 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1418 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1419 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1420 .support_trail
= '\x00',
1424 {"fs-uboot", 0x00000, 0x20000},
1425 {"os-image", 0x20000, 0x150000},
1426 {"file-system", 0x170000, 0x240000},
1427 {"partition-table", 0x3b0000, 0x02000},
1428 {"default-mac", 0x3c0000, 0x00020},
1429 {"pin", 0x3c0100, 0x00020},
1430 {"product-info", 0x3c1000, 0x01000},
1431 {"soft-version", 0x3c2000, 0x00100},
1432 {"support-list", 0x3c3000, 0x01000},
1433 {"profile", 0x3c4000, 0x08000},
1434 {"user-config", 0x3d0000, 0x10000},
1435 {"default-config", 0x3e0000, 0x10000},
1436 {"radio", 0x3f0000, 0x10000},
1440 .first_sysupgrade_partition
= "os-image",
1441 .last_sysupgrade_partition
= "file-system"
1444 /** Firmware layout for the TL-WPA8630P v2 (EU)*/
1446 .id
= "TL-WPA8630P-V2-EU",
1450 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
1451 .support_trail
= '\x00',
1455 {"factory-uboot", 0x00000, 0x20000},
1456 {"fs-uboot", 0x20000, 0x20000},
1457 {"firmware", 0x40000, 0x5e0000},
1458 {"partition-table", 0x620000, 0x02000},
1459 {"default-mac", 0x630000, 0x00020},
1460 {"pin", 0x630100, 0x00020},
1461 {"device-id", 0x630200, 0x00030},
1462 {"product-info", 0x631100, 0x01000},
1463 {"extra-para", 0x632100, 0x01000},
1464 {"soft-version", 0x640000, 0x01000},
1465 {"support-list", 0x641000, 0x01000},
1466 {"profile", 0x642000, 0x08000},
1467 {"user-config", 0x650000, 0x10000},
1468 {"default-config", 0x660000, 0x10000},
1469 {"default-nvm", 0x670000, 0xc0000},
1470 {"default-pib", 0x730000, 0x40000},
1471 {"radio", 0x7f0000, 0x10000},
1475 .first_sysupgrade_partition
= "os-image",
1476 .last_sysupgrade_partition
= "file-system"
1479 /** Firmware layout for the TL-WPA8630P v2 (INT)*/
1481 .id
= "TL-WPA8630P-V2-INT",
1485 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
1486 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
1487 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
1488 .support_trail
= '\x00',
1492 {"factory-uboot", 0x00000, 0x20000},
1493 {"fs-uboot", 0x20000, 0x20000},
1494 {"firmware", 0x40000, 0x5e0000},
1495 {"partition-table", 0x620000, 0x02000},
1496 {"extra-para", 0x632100, 0x01000},
1497 {"soft-version", 0x640000, 0x01000},
1498 {"support-list", 0x641000, 0x01000},
1499 {"profile", 0x642000, 0x08000},
1500 {"user-config", 0x650000, 0x10000},
1501 {"default-config", 0x660000, 0x10000},
1502 {"default-nvm", 0x670000, 0xc0000},
1503 {"default-pib", 0x730000, 0x40000},
1504 {"default-mac", 0x7e0000, 0x00020},
1505 {"pin", 0x7e0100, 0x00020},
1506 {"device-id", 0x7e0200, 0x00030},
1507 {"product-info", 0x7e1100, 0x01000},
1508 {"radio", 0x7f0000, 0x10000},
1512 .first_sysupgrade_partition
= "os-image",
1513 .last_sysupgrade_partition
= "file-system"
1516 /** Firmware layout for the TL-WR1043 v5 */
1518 .id
= "TLWR1043NV5",
1522 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1523 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1524 .support_trail
= '\x00',
1525 .soft_ver
= "soft_ver:1.0.0\n",
1527 {"factory-boot", 0x00000, 0x20000},
1528 {"fs-uboot", 0x20000, 0x20000},
1529 {"firmware", 0x40000, 0xec0000},
1530 {"default-mac", 0xf00000, 0x00200},
1531 {"pin", 0xf00200, 0x00200},
1532 {"device-id", 0xf00400, 0x00100},
1533 {"product-info", 0xf00500, 0x0fb00},
1534 {"soft-version", 0xf10000, 0x01000},
1535 {"extra-para", 0xf11000, 0x01000},
1536 {"support-list", 0xf12000, 0x0a000},
1537 {"profile", 0xf1c000, 0x04000},
1538 {"default-config", 0xf20000, 0x10000},
1539 {"user-config", 0xf30000, 0x40000},
1540 {"qos-db", 0xf70000, 0x40000},
1541 {"certificate", 0xfb0000, 0x10000},
1542 {"partition-table", 0xfc0000, 0x10000},
1543 {"log", 0xfd0000, 0x20000},
1544 {"radio", 0xff0000, 0x10000},
1547 .first_sysupgrade_partition
= "os-image",
1548 .last_sysupgrade_partition
= "file-system"
1551 /** Firmware layout for the TL-WR1043 v4 */
1553 .id
= "TLWR1043NDV4",
1557 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1558 .support_trail
= '\x00',
1561 /* We're using a dynamic kernel/rootfs split here */
1563 {"fs-uboot", 0x00000, 0x20000},
1564 {"firmware", 0x20000, 0xf30000},
1565 {"default-mac", 0xf50000, 0x00200},
1566 {"pin", 0xf50200, 0x00200},
1567 {"product-info", 0xf50400, 0x0fc00},
1568 {"soft-version", 0xf60000, 0x0b000},
1569 {"support-list", 0xf6b000, 0x04000},
1570 {"profile", 0xf70000, 0x04000},
1571 {"default-config", 0xf74000, 0x0b000},
1572 {"user-config", 0xf80000, 0x40000},
1573 {"partition-table", 0xfc0000, 0x10000},
1574 {"log", 0xfd0000, 0x20000},
1575 {"radio", 0xff0000, 0x10000},
1579 .first_sysupgrade_partition
= "os-image",
1580 .last_sysupgrade_partition
= "file-system"
1583 /** Firmware layout for the TL-WR902AC v1 */
1585 .id
= "TL-WR902AC-V1",
1589 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1590 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1591 .support_trail
= '\x00',
1595 384KB were moved from file-system to os-image
1596 in comparison to the stock image
1599 {"fs-uboot", 0x00000, 0x20000},
1600 {"firmware", 0x20000, 0x730000},
1601 {"default-mac", 0x750000, 0x00200},
1602 {"pin", 0x750200, 0x00200},
1603 {"product-info", 0x750400, 0x0fc00},
1604 {"soft-version", 0x760000, 0x0b000},
1605 {"support-list", 0x76b000, 0x04000},
1606 {"profile", 0x770000, 0x04000},
1607 {"default-config", 0x774000, 0x0b000},
1608 {"user-config", 0x780000, 0x40000},
1609 {"partition-table", 0x7c0000, 0x10000},
1610 {"log", 0x7d0000, 0x20000},
1611 {"radio", 0x7f0000, 0x10000},
1615 .first_sysupgrade_partition
= "os-image",
1616 .last_sysupgrade_partition
= "file-system",
1619 /** Firmware layout for the TL-WR942N V1 */
1625 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1626 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1627 .support_trail
= '\x00',
1631 {"fs-uboot", 0x00000, 0x20000},
1632 {"firmware", 0x20000, 0xe20000},
1633 {"default-mac", 0xe40000, 0x00200},
1634 {"pin", 0xe40200, 0x00200},
1635 {"product-info", 0xe40400, 0x0fc00},
1636 {"partition-table", 0xe50000, 0x10000},
1637 {"soft-version", 0xe60000, 0x10000},
1638 {"support-list", 0xe70000, 0x10000},
1639 {"profile", 0xe80000, 0x10000},
1640 {"default-config", 0xe90000, 0x10000},
1641 {"user-config", 0xea0000, 0x40000},
1642 {"qos-db", 0xee0000, 0x40000},
1643 {"certificate", 0xf20000, 0x10000},
1644 {"usb-config", 0xfb0000, 0x10000},
1645 {"log", 0xfc0000, 0x20000},
1646 {"radio-bk", 0xfe0000, 0x10000},
1647 {"radio", 0xff0000, 0x10000},
1651 .first_sysupgrade_partition
= "os-image",
1652 .last_sysupgrade_partition
= "file-system",
1655 /** Firmware layout for the RE200 v2 */
1661 "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
1662 "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
1663 "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
1664 "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
1665 "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
1666 "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
1667 "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
1668 "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
1669 "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
1670 "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
1671 "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
1672 "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
1673 "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
1674 .support_trail
= '\x00',
1678 {"fs-uboot", 0x00000, 0x20000},
1679 {"firmware", 0x20000, 0x7a0000},
1680 {"partition-table", 0x7c0000, 0x02000},
1681 {"default-mac", 0x7c2000, 0x00020},
1682 {"pin", 0x7c2100, 0x00020},
1683 {"product-info", 0x7c3100, 0x01000},
1684 {"soft-version", 0x7c4200, 0x01000},
1685 {"support-list", 0x7c5200, 0x01000},
1686 {"profile", 0x7c6200, 0x08000},
1687 {"config-info", 0x7ce200, 0x00400},
1688 {"user-config", 0x7d0000, 0x10000},
1689 {"default-config", 0x7e0000, 0x10000},
1690 {"radio", 0x7f0000, 0x10000},
1694 .first_sysupgrade_partition
= "os-image",
1695 .last_sysupgrade_partition
= "file-system"
1698 /** Firmware layout for the RE200 v3 */
1704 "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
1705 "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
1706 "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
1707 "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
1708 "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
1709 "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
1710 "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
1711 "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
1712 "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
1713 "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
1714 "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
1715 "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
1716 "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
1717 "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
1718 .support_trail
= '\x00',
1722 {"fs-uboot", 0x00000, 0x20000},
1723 {"firmware", 0x20000, 0x7a0000},
1724 {"partition-table", 0x7c0000, 0x02000},
1725 {"default-mac", 0x7c2000, 0x00020},
1726 {"pin", 0x7c2100, 0x00020},
1727 {"product-info", 0x7c3100, 0x01000},
1728 {"soft-version", 0x7c4200, 0x01000},
1729 {"support-list", 0x7c5200, 0x01000},
1730 {"profile", 0x7c6200, 0x08000},
1731 {"config-info", 0x7ce200, 0x00400},
1732 {"user-config", 0x7d0000, 0x10000},
1733 {"default-config", 0x7e0000, 0x10000},
1734 {"radio", 0x7f0000, 0x10000},
1738 .first_sysupgrade_partition
= "os-image",
1739 .last_sysupgrade_partition
= "file-system"
1742 /** Firmware layout for the RE220 v2 */
1748 "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
1749 "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
1750 "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
1751 "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
1752 "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
1753 "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
1754 "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
1755 "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
1756 "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
1757 "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
1758 "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
1759 "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
1760 "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
1761 .support_trail
= '\x00',
1765 {"fs-uboot", 0x00000, 0x20000},
1766 {"firmware", 0x20000, 0x7a0000},
1767 {"partition-table", 0x7c0000, 0x02000},
1768 {"default-mac", 0x7c2000, 0x00020},
1769 {"pin", 0x7c2100, 0x00020},
1770 {"product-info", 0x7c3100, 0x01000},
1771 {"soft-version", 0x7c4200, 0x01000},
1772 {"support-list", 0x7c5200, 0x01000},
1773 {"profile", 0x7c6200, 0x08000},
1774 {"config-info", 0x7ce200, 0x00400},
1775 {"user-config", 0x7d0000, 0x10000},
1776 {"default-config", 0x7e0000, 0x10000},
1777 {"radio", 0x7f0000, 0x10000},
1781 .first_sysupgrade_partition
= "os-image",
1782 .last_sysupgrade_partition
= "file-system"
1785 /** Firmware layout for the RE305 v1 */
1791 "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
1792 "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
1793 "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
1794 "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
1795 "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
1796 "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
1797 "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
1798 .support_trail
= '\x00',
1802 {"fs-uboot", 0x00000, 0x20000},
1803 {"firmware", 0x20000, 0x5e0000},
1804 {"partition-table", 0x600000, 0x02000},
1805 {"default-mac", 0x610000, 0x00020},
1806 {"pin", 0x610100, 0x00020},
1807 {"product-info", 0x611100, 0x01000},
1808 {"soft-version", 0x620000, 0x01000},
1809 {"support-list", 0x621000, 0x01000},
1810 {"profile", 0x622000, 0x08000},
1811 {"user-config", 0x630000, 0x10000},
1812 {"default-config", 0x640000, 0x10000},
1813 {"radio", 0x7f0000, 0x10000},
1817 .first_sysupgrade_partition
= "os-image",
1818 .last_sysupgrade_partition
= "file-system"
1821 /** Firmware layout for the RE350 v1 */
1827 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
1828 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
1829 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
1830 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
1831 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
1832 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
1833 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
1834 .support_trail
= '\x00',
1837 /** We're using a dynamic kernel/rootfs split here */
1839 {"fs-uboot", 0x00000, 0x20000},
1840 {"firmware", 0x20000, 0x5e0000},
1841 {"partition-table", 0x600000, 0x02000},
1842 {"default-mac", 0x610000, 0x00020},
1843 {"pin", 0x610100, 0x00020},
1844 {"product-info", 0x611100, 0x01000},
1845 {"soft-version", 0x620000, 0x01000},
1846 {"support-list", 0x621000, 0x01000},
1847 {"profile", 0x622000, 0x08000},
1848 {"user-config", 0x630000, 0x10000},
1849 {"default-config", 0x640000, 0x10000},
1850 {"radio", 0x7f0000, 0x10000},
1854 .first_sysupgrade_partition
= "os-image",
1855 .last_sysupgrade_partition
= "file-system"
1858 /** Firmware layout for the RE350K v1 */
1864 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
1865 .support_trail
= '\x00',
1868 /** We're using a dynamic kernel/rootfs split here */
1870 {"fs-uboot", 0x00000, 0x20000},
1871 {"firmware", 0x20000, 0xd70000},
1872 {"partition-table", 0xd90000, 0x02000},
1873 {"default-mac", 0xda0000, 0x00020},
1874 {"pin", 0xda0100, 0x00020},
1875 {"product-info", 0xda1100, 0x01000},
1876 {"soft-version", 0xdb0000, 0x01000},
1877 {"support-list", 0xdb1000, 0x01000},
1878 {"profile", 0xdb2000, 0x08000},
1879 {"user-config", 0xdc0000, 0x10000},
1880 {"default-config", 0xdd0000, 0x10000},
1881 {"device-id", 0xde0000, 0x00108},
1882 {"radio", 0xff0000, 0x10000},
1886 .first_sysupgrade_partition
= "os-image",
1887 .last_sysupgrade_partition
= "file-system"
1890 /** Firmware layout for the RE355 */
1896 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
1897 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
1898 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
1899 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
1900 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
1901 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
1902 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
1903 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
1904 .support_trail
= '\x00',
1907 /* We're using a dynamic kernel/rootfs split here */
1909 {"fs-uboot", 0x00000, 0x20000},
1910 {"firmware", 0x20000, 0x5e0000},
1911 {"partition-table", 0x600000, 0x02000},
1912 {"default-mac", 0x610000, 0x00020},
1913 {"pin", 0x610100, 0x00020},
1914 {"product-info", 0x611100, 0x01000},
1915 {"soft-version", 0x620000, 0x01000},
1916 {"support-list", 0x621000, 0x01000},
1917 {"profile", 0x622000, 0x08000},
1918 {"user-config", 0x630000, 0x10000},
1919 {"default-config", 0x640000, 0x10000},
1920 {"radio", 0x7f0000, 0x10000},
1924 .first_sysupgrade_partition
= "os-image",
1925 .last_sysupgrade_partition
= "file-system"
1928 /** Firmware layout for the RE450 */
1934 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
1935 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
1936 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
1937 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
1938 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
1939 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
1940 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
1941 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
1942 .support_trail
= '\x00',
1945 /** We're using a dynamic kernel/rootfs split here */
1947 {"fs-uboot", 0x00000, 0x20000},
1948 {"firmware", 0x20000, 0x5e0000},
1949 {"partition-table", 0x600000, 0x02000},
1950 {"default-mac", 0x610000, 0x00020},
1951 {"pin", 0x610100, 0x00020},
1952 {"product-info", 0x611100, 0x01000},
1953 {"soft-version", 0x620000, 0x01000},
1954 {"support-list", 0x621000, 0x01000},
1955 {"profile", 0x622000, 0x08000},
1956 {"user-config", 0x630000, 0x10000},
1957 {"default-config", 0x640000, 0x10000},
1958 {"radio", 0x7f0000, 0x10000},
1962 .first_sysupgrade_partition
= "os-image",
1963 .last_sysupgrade_partition
= "file-system"
1966 /** Firmware layout for the RE450 v2 */
1972 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
1973 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
1974 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
1975 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
1976 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
1977 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
1978 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
1979 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
1980 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
1981 .support_trail
= '\x00',
1984 /* We're using a dynamic kernel/rootfs split here */
1986 {"fs-uboot", 0x00000, 0x20000},
1987 {"firmware", 0x20000, 0x5e0000},
1988 {"partition-table", 0x600000, 0x02000},
1989 {"default-mac", 0x610000, 0x00020},
1990 {"pin", 0x610100, 0x00020},
1991 {"product-info", 0x611100, 0x01000},
1992 {"soft-version", 0x620000, 0x01000},
1993 {"support-list", 0x621000, 0x01000},
1994 {"profile", 0x622000, 0x08000},
1995 {"user-config", 0x630000, 0x10000},
1996 {"default-config", 0x640000, 0x10000},
1997 {"radio", 0x7f0000, 0x10000},
2001 .first_sysupgrade_partition
= "os-image",
2002 .last_sysupgrade_partition
= "file-system"
2005 /** Firmware layout for the RE450 v3 */
2011 "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
2012 "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
2013 "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
2014 "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
2015 "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
2016 "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
2017 "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
2018 "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
2019 "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
2020 .support_trail
= '\x00',
2023 /* We're using a dynamic kernel/rootfs split here */
2025 {"fs-uboot", 0x00000, 0x20000},
2026 {"default-mac", 0x20000, 0x00020},
2027 {"pin", 0x20020, 0x00020},
2028 {"product-info", 0x21000, 0x01000},
2029 {"partition-table", 0x22000, 0x02000},
2030 {"soft-version", 0x24000, 0x01000},
2031 {"support-list", 0x25000, 0x01000},
2032 {"profile", 0x26000, 0x08000},
2033 {"user-config", 0x2e000, 0x10000},
2034 {"default-config", 0x3e000, 0x10000},
2035 {"config-info", 0x4e000, 0x00400},
2036 {"firmware", 0x50000, 0x7a0000},
2037 {"radio", 0x7f0000, 0x10000},
2041 .first_sysupgrade_partition
= "os-image",
2042 .last_sysupgrade_partition
= "file-system"
2045 /** Firmware layout for the RE500 */
2051 "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
2052 "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
2053 "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
2054 "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
2055 "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
2056 "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
2057 "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
2058 .support_trail
= '\x00',
2061 /* We're using a dynamic kernel/rootfs split here */
2063 {"fs-uboot", 0x00000, 0x20000},
2064 {"firmware", 0x20000, 0xde0000},
2065 {"partition-table", 0xe00000, 0x02000},
2066 {"default-mac", 0xe10000, 0x00020},
2067 {"pin", 0xe10100, 0x00020},
2068 {"product-info", 0xe11100, 0x01000},
2069 {"soft-version", 0xe20000, 0x01000},
2070 {"support-list", 0xe21000, 0x01000},
2071 {"profile", 0xe22000, 0x08000},
2072 {"user-config", 0xe30000, 0x10000},
2073 {"default-config", 0xe40000, 0x10000},
2074 {"radio", 0xff0000, 0x10000},
2078 .first_sysupgrade_partition
= "os-image",
2079 .last_sysupgrade_partition
= "file-system"
2082 /** Firmware layout for the RE650 */
2088 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
2089 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
2090 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
2091 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
2092 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
2093 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
2094 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
2095 .support_trail
= '\x00',
2098 /* We're using a dynamic kernel/rootfs split here */
2100 {"fs-uboot", 0x00000, 0x20000},
2101 {"firmware", 0x20000, 0xde0000},
2102 {"partition-table", 0xe00000, 0x02000},
2103 {"default-mac", 0xe10000, 0x00020},
2104 {"pin", 0xe10100, 0x00020},
2105 {"product-info", 0xe11100, 0x01000},
2106 {"soft-version", 0xe20000, 0x01000},
2107 {"support-list", 0xe21000, 0x01000},
2108 {"profile", 0xe22000, 0x08000},
2109 {"user-config", 0xe30000, 0x10000},
2110 {"default-config", 0xe40000, 0x10000},
2111 {"radio", 0xff0000, 0x10000},
2115 .first_sysupgrade_partition
= "os-image",
2116 .last_sysupgrade_partition
= "file-system"
2122 #define error(_ret, _errno, _str, ...) \
2124 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
2125 strerror(_errno)); \
2131 /** Stores a uint32 as big endian */
2132 static inline void put32(uint8_t *buf
, uint32_t val
) {
2139 /** Allocates a new image partition */
2140 static struct image_partition_entry
alloc_image_partition(const char *name
, size_t len
) {
2141 struct image_partition_entry entry
= {name
, len
, malloc(len
)};
2143 error(1, errno
, "malloc");
2148 /** Frees an image partition */
2149 static void free_image_partition(struct image_partition_entry entry
) {
2153 static time_t source_date_epoch
= -1;
2154 static void set_source_date_epoch() {
2155 char *env
= getenv("SOURCE_DATE_EPOCH");
2159 source_date_epoch
= strtoull(env
, &endptr
, 10);
2160 if (errno
|| (endptr
&& *endptr
!= '\0')) {
2161 fprintf(stderr
, "Invalid SOURCE_DATE_EPOCH");
2167 /** Generates the partition-table partition */
2168 static struct image_partition_entry
make_partition_table(const struct flash_partition_entry
*p
) {
2169 struct image_partition_entry entry
= alloc_image_partition("partition-table", 0x800);
2171 char *s
= (char *)entry
.data
, *end
= (char *)(s
+entry
.size
);
2179 for (i
= 0; p
[i
].name
; i
++) {
2181 size_t w
= snprintf(s
, len
, "partition %s base 0x%05x size 0x%05x\n", p
[i
].name
, p
[i
].base
, p
[i
].size
);
2184 error(1, 0, "flash partition table overflow?");
2191 memset(s
, 0xff, end
-s
);
2197 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
2198 static inline uint8_t bcd(uint8_t v
) {
2199 return 0x10 * (v
/10) + v
%10;
2203 /** Generates the soft-version partition */
2204 static struct image_partition_entry
make_soft_version(struct device_info
*info
, uint32_t rev
) {
2205 size_t part_len
= sizeof(struct soft_version
);
2206 if (info
->soft_ver_compat_level
> 0)
2207 part_len
+= sizeof(uint32_t);
2209 struct image_partition_entry entry
=
2210 alloc_image_partition("soft-version", part_len
+1);
2211 struct soft_version
*s
= (struct soft_version
*)entry
.data
;
2215 if (source_date_epoch
!= -1)
2216 t
= source_date_epoch
;
2217 else if (time(&t
) == (time_t)(-1))
2218 error(1, errno
, "time");
2220 struct tm
*tm
= gmtime(&t
);
2222 /* Partition contents size, minus 8 byte header and trailing byte */
2223 s
->data_len
= htonl(entry
.size
-9);
2227 s
->version_major
= 0;
2228 s
->version_minor
= 0;
2229 s
->version_patch
= 0;
2231 s
->year_hi
= bcd((1900+tm
->tm_year
)/100);
2232 s
->year_lo
= bcd(tm
->tm_year
%100);
2233 s
->month
= bcd(tm
->tm_mon
+1);
2234 s
->day
= bcd(tm
->tm_mday
);
2235 s
->rev
= htonl(rev
);
2237 if (info
->soft_ver_compat_level
> 0)
2238 *(uint32_t *)(entry
.data
+ sizeof(struct soft_version
)) =
2239 htonl(info
->soft_ver_compat_level
);
2241 entry
.data
[entry
.size
-1] = 0xff;
2246 static struct image_partition_entry
make_soft_version_from_string(const char *soft_ver
) {
2247 /** String length _including_ the terminating zero byte */
2248 uint32_t ver_len
= strlen(soft_ver
) + 1;
2249 /** Partition contains 64 bit header, the version string, and one additional null byte */
2250 size_t partition_len
= 2*sizeof(uint32_t) + ver_len
+ 1;
2251 struct image_partition_entry entry
= alloc_image_partition("soft-version", partition_len
);
2253 uint32_t *len
= (uint32_t *)entry
.data
;
2254 len
[0] = htonl(ver_len
);
2256 memcpy(&len
[2], soft_ver
, ver_len
);
2258 entry
.data
[partition_len
- 1] = 0;
2263 /** Generates the support-list partition */
2264 static struct image_partition_entry
make_support_list(struct device_info
*info
) {
2265 size_t len
= strlen(info
->support_list
);
2266 struct image_partition_entry entry
= alloc_image_partition("support-list", len
+ 9);
2268 put32(entry
.data
, len
);
2269 memset(entry
.data
+4, 0, 4);
2270 memcpy(entry
.data
+8, info
->support_list
, len
);
2271 entry
.data
[len
+8] = info
->support_trail
;
2276 /** Creates a new image partition with an arbitrary name from a file */
2277 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
) {
2278 struct stat statbuf
;
2280 if (stat(filename
, &statbuf
) < 0)
2281 error(1, errno
, "unable to stat file `%s'", filename
);
2283 size_t len
= statbuf
.st_size
;
2285 if (add_jffs2_eof
) {
2286 if (file_system_partition
)
2287 len
= ALIGN(len
+ file_system_partition
->base
, 0x10000) + sizeof(jffs2_eof_mark
) - file_system_partition
->base
;
2289 len
= ALIGN(len
, 0x10000) + sizeof(jffs2_eof_mark
);
2292 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
2294 FILE *file
= fopen(filename
, "rb");
2296 error(1, errno
, "unable to open file `%s'", filename
);
2298 if (fread(entry
.data
, statbuf
.st_size
, 1, file
) != 1)
2299 error(1, errno
, "unable to read file `%s'", filename
);
2301 if (add_jffs2_eof
) {
2302 uint8_t *eof
= entry
.data
+ statbuf
.st_size
, *end
= entry
.data
+entry
.size
;
2304 memset(eof
, 0xff, end
- eof
- sizeof(jffs2_eof_mark
));
2305 memcpy(end
- sizeof(jffs2_eof_mark
), jffs2_eof_mark
, sizeof(jffs2_eof_mark
));
2313 /** Creates a new image partition from arbitrary data */
2314 static struct image_partition_entry
put_data(const char *part_name
, const char *datain
, size_t len
) {
2316 struct image_partition_entry entry
= alloc_image_partition(part_name
, len
);
2318 memcpy(entry
.data
, datain
, len
);
2324 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
2326 Example image partition table:
2328 fwup-ptn partition-table base 0x00800 size 0x00800
2329 fwup-ptn os-image base 0x01000 size 0x113b45
2330 fwup-ptn file-system base 0x114b45 size 0x1d0004
2331 fwup-ptn support-list base 0x2e4b49 size 0x000d1
2333 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
2334 the end of the partition table is marked with a zero byte.
2336 The firmware image must contain at least the partition-table and support-list partitions
2337 to be accepted. There aren't any alignment constraints for the image partitions.
2339 The partition-table partition contains the actual flash layout; partitions
2340 from the image partition table are mapped to the corresponding flash partitions during
2341 the firmware upgrade. The support-list partition contains a list of devices supported by
2344 The base offsets in the firmware partition table are relative to the end
2345 of the vendor information block, so the partition-table partition will
2346 actually start at offset 0x1814 of the image.
2348 I think partition-table must be the first partition in the firmware image.
2350 static void put_partitions(uint8_t *buffer
, const struct flash_partition_entry
*flash_parts
, const struct image_partition_entry
*parts
) {
2352 char *image_pt
= (char *)buffer
, *end
= image_pt
+ 0x800;
2354 size_t base
= 0x800;
2355 for (i
= 0; parts
[i
].name
; i
++) {
2356 for (j
= 0; flash_parts
[j
].name
; j
++) {
2357 if (!strcmp(flash_parts
[j
].name
, parts
[i
].name
)) {
2358 if (parts
[i
].size
> flash_parts
[j
].size
)
2359 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts
[j
].name
, (unsigned)flash_parts
[j
].size
);
2364 assert(flash_parts
[j
].name
);
2366 memcpy(buffer
+ base
, parts
[i
].data
, parts
[i
].size
);
2368 size_t len
= end
-image_pt
;
2369 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
);
2372 error(1, 0, "image partition table overflow?");
2376 base
+= parts
[i
].size
;
2380 /** Generates and writes the image MD5 checksum */
2381 static void put_md5(uint8_t *md5
, uint8_t *buffer
, unsigned int len
) {
2385 MD5_Update(&ctx
, md5_salt
, (unsigned int)sizeof(md5_salt
));
2386 MD5_Update(&ctx
, buffer
, len
);
2387 MD5_Final(md5
, &ctx
);
2392 Generates the firmware image in factory format
2398 0000-0003 Image size (4 bytes, big endian)
2399 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
2400 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
2401 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
2402 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
2403 1014-1813 Image partition table (2048 bytes, padded with 0xff)
2404 1814-xxxx Firmware partitions
2406 static void * generate_factory_image(struct device_info
*info
, const struct image_partition_entry
*parts
, size_t *len
) {
2410 for (i
= 0; parts
[i
].name
; i
++)
2411 *len
+= parts
[i
].size
;
2413 uint8_t *image
= malloc(*len
);
2415 error(1, errno
, "malloc");
2417 memset(image
, 0xff, *len
);
2421 size_t vendor_len
= strlen(info
->vendor
);
2422 put32(image
+0x14, vendor_len
);
2423 memcpy(image
+0x18, info
->vendor
, vendor_len
);
2426 put_partitions(image
+ 0x1014, info
->partitions
, parts
);
2427 put_md5(image
+0x04, image
+0x14, *len
-0x14);
2433 Generates the firmware image in sysupgrade format
2435 This makes some assumptions about the provided flash and image partition tables and
2436 should be generalized when TP-LINK starts building its safeloader into hardware with
2437 different flash layouts.
2439 static void * generate_sysupgrade_image(struct device_info
*info
, const struct image_partition_entry
*image_parts
, size_t *len
) {
2441 size_t flash_first_partition_index
= 0;
2442 size_t flash_last_partition_index
= 0;
2443 const struct flash_partition_entry
*flash_first_partition
= NULL
;
2444 const struct flash_partition_entry
*flash_last_partition
= NULL
;
2445 const struct image_partition_entry
*image_last_partition
= NULL
;
2447 /** Find first and last partitions */
2448 for (i
= 0; info
->partitions
[i
].name
; i
++) {
2449 if (!strcmp(info
->partitions
[i
].name
, info
->first_sysupgrade_partition
)) {
2450 flash_first_partition
= &info
->partitions
[i
];
2451 flash_first_partition_index
= i
;
2452 } else if (!strcmp(info
->partitions
[i
].name
, info
->last_sysupgrade_partition
)) {
2453 flash_last_partition
= &info
->partitions
[i
];
2454 flash_last_partition_index
= i
;
2458 assert(flash_first_partition
&& flash_last_partition
);
2459 assert(flash_first_partition_index
< flash_last_partition_index
);
2461 /** Find last partition from image to calculate needed size */
2462 for (i
= 0; image_parts
[i
].name
; i
++) {
2463 if (!strcmp(image_parts
[i
].name
, info
->last_sysupgrade_partition
)) {
2464 image_last_partition
= &image_parts
[i
];
2469 assert(image_last_partition
);
2471 *len
= flash_last_partition
->base
- flash_first_partition
->base
+ image_last_partition
->size
;
2473 uint8_t *image
= malloc(*len
);
2475 error(1, errno
, "malloc");
2477 memset(image
, 0xff, *len
);
2479 for (i
= flash_first_partition_index
; i
<= flash_last_partition_index
; i
++) {
2480 for (j
= 0; image_parts
[j
].name
; j
++) {
2481 if (!strcmp(info
->partitions
[i
].name
, image_parts
[j
].name
)) {
2482 if (image_parts
[j
].size
> info
->partitions
[i
].size
)
2483 error(1, 0, "%s partition too big (more than %u bytes)", info
->partitions
[i
].name
, (unsigned)info
->partitions
[i
].size
);
2484 memcpy(image
+ info
->partitions
[i
].base
- flash_first_partition
->base
, image_parts
[j
].data
, image_parts
[j
].size
);
2488 assert(image_parts
[j
].name
);
2495 /** Generates an image according to a given layout and writes it to a file */
2496 static void build_image(const char *output
,
2497 const char *kernel_image
,
2498 const char *rootfs_image
,
2502 struct device_info
*info
) {
2506 struct image_partition_entry parts
[7] = {};
2508 struct flash_partition_entry
*firmware_partition
= NULL
;
2509 struct flash_partition_entry
*os_image_partition
= NULL
;
2510 struct flash_partition_entry
*file_system_partition
= NULL
;
2511 size_t firmware_partition_index
= 0;
2513 for (i
= 0; info
->partitions
[i
].name
; i
++) {
2514 if (!strcmp(info
->partitions
[i
].name
, "firmware"))
2516 firmware_partition
= &info
->partitions
[i
];
2517 firmware_partition_index
= i
;
2521 if (firmware_partition
)
2523 os_image_partition
= &info
->partitions
[firmware_partition_index
];
2524 file_system_partition
= &info
->partitions
[firmware_partition_index
+ 1];
2527 if (stat(kernel_image
, &kernel
) < 0)
2528 error(1, errno
, "unable to stat file `%s'", kernel_image
);
2530 if (kernel
.st_size
> firmware_partition
->size
)
2531 error(1, 0, "kernel overflowed firmware partition\n");
2533 for (i
= MAX_PARTITIONS
-1; i
>= firmware_partition_index
+ 1; i
--)
2534 info
->partitions
[i
+1] = info
->partitions
[i
];
2536 file_system_partition
->name
= "file-system";
2537 file_system_partition
->base
= firmware_partition
->base
+ kernel
.st_size
;
2539 /* Align partition start to erase blocks for factory images only */
2541 file_system_partition
->base
= ALIGN(firmware_partition
->base
+ kernel
.st_size
, 0x10000);
2543 file_system_partition
->size
= firmware_partition
->size
- file_system_partition
->base
;
2545 os_image_partition
->name
= "os-image";
2546 os_image_partition
->size
= kernel
.st_size
;
2549 parts
[0] = make_partition_table(info
->partitions
);
2551 parts
[1] = make_soft_version_from_string(info
->soft_ver
);
2553 parts
[1] = make_soft_version(info
, rev
);
2555 parts
[2] = make_support_list(info
);
2556 parts
[3] = read_file("os-image", kernel_image
, false, NULL
);
2557 parts
[4] = read_file("file-system", rootfs_image
, add_jffs2_eof
, file_system_partition
);
2559 /* Some devices need the extra-para partition to accept the firmware */
2560 if (strcasecmp(info
->id
, "ARCHER-C2-V3") == 0 ||
2561 strcasecmp(info
->id
, "ARCHER-C25-V1") == 0 ||
2562 strcasecmp(info
->id
, "ARCHER-C59-V2") == 0 ||
2563 strcasecmp(info
->id
, "ARCHER-C60-V2") == 0 ||
2564 strcasecmp(info
->id
, "ARCHER-C60-V3") == 0 ||
2565 strcasecmp(info
->id
, "TLWR1043NV5") == 0) {
2566 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
2567 parts
[5] = put_data("extra-para", mdat
, 11);
2568 } else if (strcasecmp(info
->id
, "ARCHER-A7-V5") == 0 || strcasecmp(info
->id
, "ARCHER-C7-V4") == 0 || strcasecmp(info
->id
, "ARCHER-C7-V5") == 0) {
2569 const char mdat
[11] = {0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x01, 0x00, 0x00};
2570 parts
[5] = put_data("extra-para", mdat
, 11);
2571 } else if (strcasecmp(info
->id
, "ARCHER-C6-V2") == 0) {
2572 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
2573 parts
[5] = put_data("extra-para", mdat
, 11);
2574 } else if (strcasecmp(info
->id
, "ARCHER-C6-V2-US") == 0) {
2575 const char mdat
[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00};
2576 parts
[5] = put_data("extra-para", mdat
, 11);
2577 } else if (strcasecmp(info
->id
, "EAP245-V3") == 0) {
2578 const char mdat
[10] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
2579 parts
[5] = put_data("extra-para", mdat
, 10);
2585 image
= generate_sysupgrade_image(info
, parts
, &len
);
2587 image
= generate_factory_image(info
, parts
, &len
);
2589 FILE *file
= fopen(output
, "wb");
2591 error(1, errno
, "unable to open output file");
2593 if (fwrite(image
, len
, 1, file
) != 1)
2594 error(1, 0, "unable to write output file");
2600 for (i
= 0; parts
[i
].name
; i
++)
2601 free_image_partition(parts
[i
]);
2605 static void usage(const char *argv0
) {
2607 "Usage: %s [OPTIONS...]\n"
2610 " -h show this help\n"
2612 "Create a new image:\n"
2613 " -B <board> create image for the board specified with <board>\n"
2614 " -k <file> read kernel image from the file <file>\n"
2615 " -r <file> read rootfs image from the file <file>\n"
2616 " -o <file> write output to the file <file>\n"
2617 " -V <rev> sets the revision number to <rev>\n"
2618 " -j add jffs2 end-of-filesystem markers\n"
2619 " -S create sysupgrade instead of factory image\n"
2620 "Extract an old image:\n"
2621 " -x <file> extract all oem firmware partition\n"
2622 " -d <dir> destination to extract the firmware partition\n"
2623 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
2629 static struct device_info
*find_board(const char *id
)
2631 struct device_info
*board
= NULL
;
2633 for (board
= boards
; board
->id
!= NULL
; board
++)
2634 if (strcasecmp(id
, board
->id
) == 0)
2640 static int add_flash_partition(
2641 struct flash_partition_entry
*part_list
,
2648 /* check if the list has a free entry */
2649 for (ptr
= 0; ptr
< max_entries
; ptr
++, part_list
++) {
2650 if (part_list
->name
== NULL
&&
2651 part_list
->base
== 0 &&
2652 part_list
->size
== 0)
2656 if (ptr
== max_entries
) {
2657 error(1, 0, "No free flash part entry available.");
2660 part_list
->name
= calloc(1, strlen(name
) + 1);
2661 if (!part_list
->name
) {
2662 error(1, 0, "Unable to allocate memory");
2665 memcpy((char *)part_list
->name
, name
, strlen(name
));
2666 part_list
->base
= base
;
2667 part_list
->size
= size
;
2672 /** read the partition table into struct flash_partition_entry */
2673 static int read_partition_table(
2674 FILE *file
, long offset
,
2675 struct flash_partition_entry
*entries
, size_t max_entries
,
2680 const char *parthdr
= NULL
;
2681 const char *fwuphdr
= "fwup-ptn";
2682 const char *flashhdr
= "partition";
2684 /* TODO: search for the partition table */
2694 error(1, 0, "Invalid partition table");
2697 if (fseek(file
, offset
, SEEK_SET
) < 0)
2698 error(1, errno
, "Can not seek in the firmware");
2700 if (fread(buf
, 2048, 1, file
) != 1)
2701 error(1, errno
, "Can not read fwup-ptn from the firmware");
2705 /* look for the partition header */
2706 if (memcmp(buf
, parthdr
, strlen(parthdr
)) != 0) {
2707 fprintf(stderr
, "DEBUG: can not find fwuphdr\n");
2712 end
= buf
+ sizeof(buf
);
2713 while ((ptr
+ strlen(parthdr
)) < end
&&
2714 memcmp(ptr
, parthdr
, strlen(parthdr
)) == 0) {
2718 char name
[32] = { 0 };
2720 unsigned long base
= 0;
2721 unsigned long size
= 0;
2723 end_part
= memchr(ptr
, '\n', (end
- ptr
));
2724 if (end_part
== NULL
) {
2725 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
2729 for (int i
= 0; i
<= 4; i
++) {
2730 if (end_part
<= ptr
)
2733 end_element
= memchr(ptr
, 0x20, (end_part
- ptr
));
2734 if (end_element
== NULL
) {
2735 error(1, errno
, "Ignoring the rest of the partition entries.");
2740 /* partition header */
2742 ptr
= end_element
+ 1;
2746 name_len
= (end_element
- ptr
) > 31 ? 31 : (end_element
- ptr
);
2747 strncpy(name
, ptr
, name_len
);
2748 name
[name_len
] = '\0';
2749 ptr
= end_element
+ 1;
2754 ptr
= end_element
+ 1;
2759 base
= strtoul(ptr
, NULL
, 16);
2760 ptr
= end_element
+ 1;
2765 ptr
= end_element
+ 1;
2766 /* actual size. The last element doesn't have a sepeartor */
2767 size
= strtoul(ptr
, NULL
, 16);
2768 /* the part ends with 0x09, 0x0d, 0x0a */
2770 add_flash_partition(entries
, max_entries
, name
, base
, size
);
2779 static void write_partition(
2781 size_t firmware_offset
,
2782 struct flash_partition_entry
*entry
,
2788 fseek(input_file
, entry
->base
+ firmware_offset
, SEEK_SET
);
2790 for (offset
= 0; sizeof(buf
) + offset
<= entry
->size
; offset
+= sizeof(buf
)) {
2791 if (fread(buf
, sizeof(buf
), 1, input_file
) != 1)
2792 error(1, errno
, "Can not read partition from input_file");
2794 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
2795 error(1, errno
, "Can not write partition to output_file");
2797 /* write last chunk smaller than buffer */
2798 if (offset
< entry
->size
) {
2799 offset
= entry
->size
- offset
;
2800 if (fread(buf
, offset
, 1, input_file
) != 1)
2801 error(1, errno
, "Can not read partition from input_file");
2802 if (fwrite(buf
, offset
, 1, output_file
) != 1)
2803 error(1, errno
, "Can not write partition to output_file");
2807 static int extract_firmware_partition(FILE *input_file
, size_t firmware_offset
, struct flash_partition_entry
*entry
, const char *output_directory
)
2810 char output
[PATH_MAX
];
2812 snprintf(output
, PATH_MAX
, "%s/%s", output_directory
, entry
->name
);
2813 output_file
= fopen(output
, "wb+");
2814 if (output_file
== NULL
) {
2815 error(1, errno
, "Can not open output file %s", output
);
2818 write_partition(input_file
, firmware_offset
, entry
, output_file
);
2820 fclose(output_file
);
2825 /** extract all partitions from the firmware file */
2826 static int extract_firmware(const char *input
, const char *output_directory
)
2828 struct flash_partition_entry entries
[16] = { 0 };
2829 size_t max_entries
= 16;
2830 size_t firmware_offset
= 0x1014;
2833 struct stat statbuf
;
2835 /* check input file */
2836 if (stat(input
, &statbuf
)) {
2837 error(1, errno
, "Can not read input firmware %s", input
);
2840 /* check if output directory exists */
2841 if (stat(output_directory
, &statbuf
)) {
2842 error(1, errno
, "Failed to stat output directory %s", output_directory
);
2845 if ((statbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
2846 error(1, errno
, "Given output directory is not a directory %s", output_directory
);
2849 input_file
= fopen(input
, "rb");
2851 if (read_partition_table(input_file
, firmware_offset
, entries
, 16, 0) != 0) {
2852 error(1, 0, "Error can not read the partition table (fwup-ptn)");
2855 for (size_t i
= 0; i
< max_entries
; i
++) {
2856 if (entries
[i
].name
== NULL
&&
2857 entries
[i
].base
== 0 &&
2858 entries
[i
].size
== 0)
2861 extract_firmware_partition(input_file
, firmware_offset
, &entries
[i
], output_directory
);
2867 static struct flash_partition_entry
*find_partition(
2868 struct flash_partition_entry
*entries
, size_t max_entries
,
2869 const char *name
, const char *error_msg
)
2871 for (size_t i
= 0; i
< max_entries
; i
++, entries
++) {
2872 if (strcmp(entries
->name
, name
) == 0)
2876 error(1, 0, "%s", error_msg
);
2880 static void write_ff(FILE *output_file
, size_t size
)
2885 memset(buf
, 0xff, sizeof(buf
));
2887 for (offset
= 0; offset
+ sizeof(buf
) < size
; offset
+= sizeof(buf
)) {
2888 if (fwrite(buf
, sizeof(buf
), 1, output_file
) != 1)
2889 error(1, errno
, "Can not write 0xff to output_file");
2892 /* write last chunk smaller than buffer */
2893 if (offset
< size
) {
2894 offset
= size
- offset
;
2895 if (fwrite(buf
, offset
, 1, output_file
) != 1)
2896 error(1, errno
, "Can not write partition to output_file");
2900 static void convert_firmware(const char *input
, const char *output
)
2902 struct flash_partition_entry fwup
[MAX_PARTITIONS
] = { 0 };
2903 struct flash_partition_entry flash
[MAX_PARTITIONS
] = { 0 };
2904 struct flash_partition_entry
*fwup_os_image
= NULL
, *fwup_file_system
= NULL
;
2905 struct flash_partition_entry
*flash_os_image
= NULL
, *flash_file_system
= NULL
;
2906 struct flash_partition_entry
*fwup_partition_table
= NULL
;
2907 size_t firmware_offset
= 0x1014;
2908 FILE *input_file
, *output_file
;
2910 struct stat statbuf
;
2912 /* check input file */
2913 if (stat(input
, &statbuf
)) {
2914 error(1, errno
, "Can not read input firmware %s", input
);
2917 input_file
= fopen(input
, "rb");
2919 error(1, 0, "Can not open input firmware %s", input
);
2921 output_file
= fopen(output
, "wb");
2923 error(1, 0, "Can not open output firmware %s", output
);
2925 if (read_partition_table(input_file
, firmware_offset
, fwup
, MAX_PARTITIONS
, 0) != 0) {
2926 error(1, 0, "Error can not read the partition table (fwup-ptn)");
2929 fwup_os_image
= find_partition(fwup
, MAX_PARTITIONS
,
2930 "os-image", "Error can not find os-image partition (fwup)");
2931 fwup_file_system
= find_partition(fwup
, MAX_PARTITIONS
,
2932 "file-system", "Error can not find file-system partition (fwup)");
2933 fwup_partition_table
= find_partition(fwup
, MAX_PARTITIONS
,
2934 "partition-table", "Error can not find partition-table partition");
2936 /* the flash partition table has a 0x00000004 magic haeder */
2937 if (read_partition_table(input_file
, firmware_offset
+ fwup_partition_table
->base
+ 4, flash
, MAX_PARTITIONS
, 1) != 0)
2938 error(1, 0, "Error can not read the partition table (flash)");
2940 flash_os_image
= find_partition(flash
, MAX_PARTITIONS
,
2941 "os-image", "Error can not find os-image partition (flash)");
2942 flash_file_system
= find_partition(flash
, MAX_PARTITIONS
,
2943 "file-system", "Error can not find file-system partition (flash)");
2945 /* write os_image to 0x0 */
2946 write_partition(input_file
, firmware_offset
, fwup_os_image
, output_file
);
2947 write_ff(output_file
, flash_os_image
->size
- fwup_os_image
->size
);
2949 /* write file-system behind os_image */
2950 fseek(output_file
, flash_file_system
->base
- flash_os_image
->base
, SEEK_SET
);
2951 write_partition(input_file
, firmware_offset
, fwup_file_system
, output_file
);
2952 write_ff(output_file
, flash_file_system
->size
- fwup_file_system
->size
);
2954 fclose(output_file
);
2958 int main(int argc
, char *argv
[]) {
2959 const char *board
= NULL
, *kernel_image
= NULL
, *rootfs_image
= NULL
, *output
= NULL
;
2960 const char *extract_image
= NULL
, *output_directory
= NULL
, *convert_image
= NULL
;
2961 bool add_jffs2_eof
= false, sysupgrade
= false;
2963 struct device_info
*info
;
2964 set_source_date_epoch();
2969 c
= getopt(argc
, argv
, "B:k:r:o:V:jSh:x:d:z:");
2979 kernel_image
= optarg
;
2983 rootfs_image
= optarg
;
2991 sscanf(optarg
, "r%u", &rev
);
2995 add_jffs2_eof
= true;
3007 output_directory
= optarg
;
3011 extract_image
= optarg
;
3015 convert_image
= optarg
;
3024 if (extract_image
|| output_directory
) {
3026 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
3027 if (!output_directory
)
3028 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
3029 extract_firmware(extract_image
, output_directory
);
3030 } else if (convert_image
) {
3032 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
3033 convert_firmware(convert_image
, output
);
3036 error(1, 0, "no board has been specified");
3038 error(1, 0, "no kernel image has been specified");
3040 error(1, 0, "no rootfs image has been specified");
3042 error(1, 0, "no output filename has been specified");
3044 info
= find_board(board
);
3047 error(1, 0, "unsupported board %s", board
);
3049 build_image(output
, kernel_image
, rootfs_image
, rev
, add_jffs2_eof
, sysupgrade
, info
);