b9dfad51a6ddb5d7feac7871ed5af94fe4072f8c
[openwrt/staging/zorun.git] / tools / firmware-utils / src / tplink-safeloader.c
1 /*
2 Copyright (c) 2014, Matthias Schiffer <mschiffer@universe-factory.net>
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
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.
13
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.
24 */
25
26
27 /*
28 tplink-safeloader
29
30 Image generation tool for the TP-LINK SafeLoader as seen on
31 TP-LINK Pharos devices (CPE210/220/510/520)
32 */
33
34
35 #include <assert.h>
36 #include <errno.h>
37 #include <stdbool.h>
38 #include <stdio.h>
39 #include <stdint.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <time.h>
43 #include <unistd.h>
44
45 #include <arpa/inet.h>
46
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <limits.h>
50
51 #include "md5.h"
52
53
54 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
55
56
57 #define MAX_PARTITIONS 32
58
59 /** An image partition table entry */
60 struct image_partition_entry {
61 const char *name;
62 size_t size;
63 uint8_t *data;
64 };
65
66 /** A flash partition table entry */
67 struct flash_partition_entry {
68 char *name;
69 uint32_t base;
70 uint32_t size;
71 };
72
73 /** Partition trailing padding definitions
74 * Values 0x00 to 0xff are reserved to indicate the padding value
75 * Values from 0x100 are reserved to indicate other behaviour */
76 enum partition_trail_value {
77 PART_TRAIL_00 = 0x00,
78 PART_TRAIL_FF = 0xff,
79 PART_TRAIL_MAX = 0xff,
80 PART_TRAIL_NONE = 0x100
81 };
82
83 /** Firmware layout description */
84 struct device_info {
85 const char *id;
86 const char *vendor;
87 const char *support_list;
88 enum partition_trail_value part_trail;
89 const char *soft_ver;
90 uint32_t soft_ver_compat_level;
91 struct flash_partition_entry partitions[MAX_PARTITIONS+1];
92 const char *first_sysupgrade_partition;
93 const char *last_sysupgrade_partition;
94 };
95
96 struct __attribute__((__packed__)) meta_header {
97 uint32_t length;
98 uint32_t zero;
99 };
100
101 /** The content of the soft-version structure */
102 struct __attribute__((__packed__)) soft_version {
103 uint8_t pad1;
104 uint8_t version_major;
105 uint8_t version_minor;
106 uint8_t version_patch;
107 uint8_t year_hi;
108 uint8_t year_lo;
109 uint8_t month;
110 uint8_t day;
111 uint32_t rev;
112 uint32_t compat_level;
113 };
114
115
116 static const uint8_t jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
117
118
119 /**
120 Salt for the MD5 hash
121
122 Fortunately, TP-LINK seems to use the same salt for most devices which use
123 the new image format.
124 */
125 static const uint8_t md5_salt[16] = {
126 0x7a, 0x2b, 0x15, 0xed,
127 0x9b, 0x98, 0x59, 0x6d,
128 0xe5, 0x04, 0xab, 0x44,
129 0xac, 0x2a, 0x9f, 0x4e,
130 };
131
132
133 /** Firmware layout table */
134 static struct device_info boards[] = {
135 /** Firmware layout for the CPE210/220 V1 */
136 {
137 .id = "CPE210",
138 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
139 .support_list =
140 "SupportList:\r\n"
141 "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
142 "CPE210(TP-LINK|UN|N300-2):1.1\r\n"
143 "CPE210(TP-LINK|US|N300-2):1.1\r\n"
144 "CPE210(TP-LINK|EU|N300-2):1.1\r\n"
145 "CPE220(TP-LINK|UN|N300-2):1.1\r\n"
146 "CPE220(TP-LINK|US|N300-2):1.1\r\n"
147 "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
148 .part_trail = 0xff,
149 .soft_ver = NULL,
150
151 .partitions = {
152 {"fs-uboot", 0x00000, 0x20000},
153 {"partition-table", 0x20000, 0x02000},
154 {"default-mac", 0x30000, 0x00020},
155 {"product-info", 0x31100, 0x00100},
156 {"signature", 0x32000, 0x00400},
157 {"os-image", 0x40000, 0x300000},
158 {"file-system", 0x340000, 0x470000},
159 {"soft-version", 0x7b0000, 0x00100},
160 {"support-list", 0x7b1000, 0x00400},
161 {"user-config", 0x7c0000, 0x10000},
162 {"default-config", 0x7d0000, 0x10000},
163 {"log", 0x7e0000, 0x10000},
164 {"radio", 0x7f0000, 0x10000},
165 {NULL, 0, 0}
166 },
167
168 .first_sysupgrade_partition = "os-image",
169 .last_sysupgrade_partition = "support-list",
170 },
171
172 /** Firmware layout for the CPE210 V2 */
173 {
174 .id = "CPE210V2",
175 .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
176 .support_list =
177 "SupportList:\r\n"
178 "CPE210(TP-LINK|EU|N300-2|00000000):2.0\r\n"
179 "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n"
180 "CPE210(TP-LINK|EU|N300-2|55530000):2.0\r\n"
181 "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
182 "CPE210(TP-LINK|UN|N300-2|45550000):2.0\r\n"
183 "CPE210(TP-LINK|UN|N300-2|55530000):2.0\r\n"
184 "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
185 "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
186 "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
187 "CPE210(TP-LINK|US|N300-2):2.0\r\n",
188 .part_trail = 0xff,
189 .soft_ver = NULL,
190
191 .partitions = {
192 {"fs-uboot", 0x00000, 0x20000},
193 {"partition-table", 0x20000, 0x02000},
194 {"default-mac", 0x30000, 0x00020},
195 {"product-info", 0x31100, 0x00100},
196 {"device-info", 0x31400, 0x00400},
197 {"signature", 0x32000, 0x00400},
198 {"device-id", 0x33000, 0x00100},
199 {"firmware", 0x40000, 0x770000},
200 {"soft-version", 0x7b0000, 0x00100},
201 {"support-list", 0x7b1000, 0x01000},
202 {"user-config", 0x7c0000, 0x10000},
203 {"default-config", 0x7d0000, 0x10000},
204 {"log", 0x7e0000, 0x10000},
205 {"radio", 0x7f0000, 0x10000},
206 {NULL, 0, 0}
207 },
208
209 .first_sysupgrade_partition = "os-image",
210 .last_sysupgrade_partition = "support-list",
211 },
212
213 /** Firmware layout for the CPE210 V3 */
214 {
215 .id = "CPE210V3",
216 .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
217 .support_list =
218 "SupportList:\r\n"
219 "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
220 "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
221 "CPE210(TP-LINK|US|N300-2|55530000):3.0\r\n"
222 "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
223 "CPE210(TP-LINK|EU|N300-2):3.0\r\n"
224 "CPE210(TP-LINK|EU|N300-2|45550000):3.1\r\n"
225 "CPE210(TP-LINK|UN|N300-2|00000000):3.1\r\n"
226 "CPE210(TP-LINK|US|N300-2|55530000):3.1\r\n"
227 "CPE210(TP-LINK|EU|N300-2|45550000):3.20\r\n"
228 "CPE210(TP-LINK|UN|N300-2|00000000):3.20\r\n"
229 "CPE210(TP-LINK|US|N300-2|55530000):3.20\r\n",
230 .part_trail = 0xff,
231 .soft_ver = NULL,
232
233 .partitions = {
234 {"fs-uboot", 0x00000, 0x20000},
235 {"partition-table", 0x20000, 0x01000},
236 {"default-mac", 0x30000, 0x00020},
237 {"product-info", 0x31100, 0x00100},
238 {"device-info", 0x31400, 0x00400},
239 {"signature", 0x32000, 0x00400},
240 {"device-id", 0x33000, 0x00100},
241 {"firmware", 0x40000, 0x770000},
242 {"soft-version", 0x7b0000, 0x00100},
243 {"support-list", 0x7b1000, 0x01000},
244 {"user-config", 0x7c0000, 0x10000},
245 {"default-config", 0x7d0000, 0x10000},
246 {"log", 0x7e0000, 0x10000},
247 {"radio", 0x7f0000, 0x10000},
248 {NULL, 0, 0}
249 },
250
251 .first_sysupgrade_partition = "os-image",
252 .last_sysupgrade_partition = "support-list",
253 },
254
255 /** Firmware layout for the CPE220 V2 */
256 {
257 .id = "CPE220V2",
258 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
259 .support_list =
260 "SupportList:\r\n"
261 "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n"
262 "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n"
263 "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n"
264 "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n"
265 "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n"
266 "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n"
267 "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n"
268 "CPE220(TP-LINK|UN|N300-2):2.0\r\n"
269 "CPE220(TP-LINK|EU|N300-2):2.0\r\n"
270 "CPE220(TP-LINK|US|N300-2):2.0\r\n",
271 .part_trail = 0xff,
272 .soft_ver = NULL,
273
274 .partitions = {
275 {"fs-uboot", 0x00000, 0x20000},
276 {"partition-table", 0x20000, 0x02000},
277 {"default-mac", 0x30000, 0x00020},
278 {"product-info", 0x31100, 0x00100},
279 {"signature", 0x32000, 0x00400},
280 {"os-image", 0x40000, 0x300000},
281 {"file-system", 0x340000, 0x470000},
282 {"soft-version", 0x7b0000, 0x00100},
283 {"support-list", 0x7b1000, 0x00400},
284 {"user-config", 0x7c0000, 0x10000},
285 {"default-config", 0x7d0000, 0x10000},
286 {"log", 0x7e0000, 0x10000},
287 {"radio", 0x7f0000, 0x10000},
288 {NULL, 0, 0}
289 },
290
291 .first_sysupgrade_partition = "os-image",
292 .last_sysupgrade_partition = "support-list",
293 },
294
295 /** Firmware layout for the CPE220 V3 */
296 {
297 .id = "CPE220V3",
298 .vendor = "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n",
299 .support_list =
300 "SupportList:\r\n"
301 "CPE220(TP-LINK|EU|N300-2|00000000):3.0\r\n"
302 "CPE220(TP-LINK|EU|N300-2|45550000):3.0\r\n"
303 "CPE220(TP-LINK|EU|N300-2|55530000):3.0\r\n"
304 "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n"
305 "CPE220(TP-LINK|UN|N300-2|45550000):3.0\r\n"
306 "CPE220(TP-LINK|UN|N300-2|55530000):3.0\r\n"
307 "CPE220(TP-LINK|US|N300-2|55530000):3.0\r\n"
308 "CPE220(TP-LINK|UN|N300-2):3.0\r\n"
309 "CPE220(TP-LINK|EU|N300-2):3.0\r\n"
310 "CPE220(TP-LINK|US|N300-2):3.0\r\n",
311 .part_trail = 0xff,
312 .soft_ver = NULL,
313
314 .partitions = {
315 {"fs-uboot", 0x00000, 0x20000},
316 {"partition-table", 0x20000, 0x02000},
317 {"default-mac", 0x30000, 0x00020},
318 {"product-info", 0x31100, 0x00100},
319 {"device-info", 0x31400, 0x00400},
320 {"signature", 0x32000, 0x00400},
321 {"device-id", 0x33000, 0x00100},
322 {"firmware", 0x40000, 0x770000},
323 {"soft-version", 0x7b0000, 0x00100},
324 {"support-list", 0x7b1000, 0x01000},
325 {"user-config", 0x7c0000, 0x10000},
326 {"default-config", 0x7d0000, 0x10000},
327 {"log", 0x7e0000, 0x10000},
328 {"radio", 0x7f0000, 0x10000},
329 {NULL, 0, 0}
330 },
331
332 .first_sysupgrade_partition = "os-image",
333 .last_sysupgrade_partition = "support-list",
334 },
335
336 /** Firmware layout for the CPE510/520 V1 */
337 {
338 .id = "CPE510",
339 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
340 .support_list =
341 "SupportList:\r\n"
342 "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
343 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
344 "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
345 "CPE510(TP-LINK|US|N300-5):1.1\r\n"
346 "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
347 "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
348 "CPE520(TP-LINK|US|N300-5):1.1\r\n"
349 "CPE520(TP-LINK|EU|N300-5):1.1\r\n",
350 .part_trail = 0xff,
351 .soft_ver = NULL,
352
353 .partitions = {
354 {"fs-uboot", 0x00000, 0x20000},
355 {"partition-table", 0x20000, 0x02000},
356 {"default-mac", 0x30000, 0x00020},
357 {"product-info", 0x31100, 0x00100},
358 {"signature", 0x32000, 0x00400},
359 {"os-image", 0x40000, 0x300000},
360 {"file-system", 0x340000, 0x470000},
361 {"soft-version", 0x7b0000, 0x00100},
362 {"support-list", 0x7b1000, 0x00400},
363 {"user-config", 0x7c0000, 0x10000},
364 {"default-config", 0x7d0000, 0x10000},
365 {"log", 0x7e0000, 0x10000},
366 {"radio", 0x7f0000, 0x10000},
367 {NULL, 0, 0}
368 },
369
370 .first_sysupgrade_partition = "os-image",
371 .last_sysupgrade_partition = "support-list",
372 },
373
374 /** Firmware layout for the CPE510 V2 */
375 {
376 .id = "CPE510V2",
377 .vendor = "CPE510(TP-LINK|UN|N300-5):2.0\r\n",
378 .support_list =
379 "SupportList:\r\n"
380 "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
381 "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
382 "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
383 "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
384 "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
385 "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
386 "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n"
387 "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n"
388 "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
389 "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
390 "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
391 "CPE510(TP-LINK|US|N300-5):2.0\r\n",
392 .part_trail = 0xff,
393 .soft_ver = NULL,
394
395 .partitions = {
396 {"fs-uboot", 0x00000, 0x20000},
397 {"partition-table", 0x20000, 0x02000},
398 {"default-mac", 0x30000, 0x00020},
399 {"product-info", 0x31100, 0x00100},
400 {"signature", 0x32000, 0x00400},
401 {"os-image", 0x40000, 0x300000},
402 {"file-system", 0x340000, 0x470000},
403 {"soft-version", 0x7b0000, 0x00100},
404 {"support-list", 0x7b1000, 0x00400},
405 {"user-config", 0x7c0000, 0x10000},
406 {"default-config", 0x7d0000, 0x10000},
407 {"log", 0x7e0000, 0x10000},
408 {"radio", 0x7f0000, 0x10000},
409 {NULL, 0, 0}
410 },
411
412 .first_sysupgrade_partition = "os-image",
413 .last_sysupgrade_partition = "support-list",
414 },
415
416 /** Firmware layout for the CPE510 V3 */
417 {
418 .id = "CPE510V3",
419 .vendor = "CPE510(TP-LINK|UN|N300-5):3.0\r\n",
420 .support_list =
421 "SupportList:\r\n"
422 "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n"
423 "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n"
424 "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n"
425 "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n"
426 "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n"
427 "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n"
428 "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n"
429 "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n"
430 "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n"
431 "CPE510(TP-LINK|UN|N300-5):3.0\r\n"
432 "CPE510(TP-LINK|EU|N300-5):3.0\r\n"
433 "CPE510(TP-LINK|US|N300-5):3.0\r\n"
434 "CPE510(TP-LINK|UN|N300-5|00000000):3.20\r\n"
435 "CPE510(TP-LINK|US|N300-5|55530000):3.20\r\n"
436 "CPE510(TP-LINK|EU|N300-5|45550000):3.20\r\n",
437 .part_trail = 0xff,
438 .soft_ver = NULL,
439
440 .partitions = {
441 {"fs-uboot", 0x00000, 0x20000},
442 {"partition-table", 0x20000, 0x02000},
443 {"default-mac", 0x30000, 0x00020},
444 {"product-info", 0x31100, 0x00100},
445 {"signature", 0x32000, 0x00400},
446 {"os-image", 0x40000, 0x300000},
447 {"file-system", 0x340000, 0x470000},
448 {"soft-version", 0x7b0000, 0x00100},
449 {"support-list", 0x7b1000, 0x00400},
450 {"user-config", 0x7c0000, 0x10000},
451 {"default-config", 0x7d0000, 0x10000},
452 {"log", 0x7e0000, 0x10000},
453 {"radio", 0x7f0000, 0x10000},
454 {NULL, 0, 0}
455 },
456
457 .first_sysupgrade_partition = "os-image",
458 .last_sysupgrade_partition = "support-list",
459 },
460
461 /** Firmware layout for the CPE610V1 */
462 {
463 .id = "CPE610V1",
464 .vendor = "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n",
465 .support_list =
466 "SupportList:\r\n"
467 "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n"
468 "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n"
469 "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n"
470 "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n"
471 "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n"
472 "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n"
473 "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n"
474 "CPE610(TP-LINK|UN|N300-5):1.0\r\n"
475 "CPE610(TP-LINK|EU|N300-5):1.0\r\n"
476 "CPE610(TP-LINK|US|N300-5):1.0\r\n",
477 .part_trail = 0xff,
478 .soft_ver = NULL,
479
480 .partitions = {
481 {"fs-uboot", 0x00000, 0x20000},
482 {"partition-table", 0x20000, 0x02000},
483 {"default-mac", 0x30000, 0x00020},
484 {"product-info", 0x31100, 0x00100},
485 {"signature", 0x32000, 0x00400},
486 {"os-image", 0x40000, 0x300000},
487 {"file-system", 0x340000, 0x470000},
488 {"soft-version", 0x7b0000, 0x00100},
489 {"support-list", 0x7b1000, 0x00400},
490 {"user-config", 0x7c0000, 0x10000},
491 {"default-config", 0x7d0000, 0x10000},
492 {"log", 0x7e0000, 0x10000},
493 {"radio", 0x7f0000, 0x10000},
494 {NULL, 0, 0}
495 },
496
497 .first_sysupgrade_partition = "os-image",
498 .last_sysupgrade_partition = "support-list",
499 },
500
501 /** Firmware layout for the CPE610V2 */
502 {
503 .id = "CPE610V2",
504 .vendor = "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n",
505 .support_list =
506 "SupportList:\r\n"
507 "CPE610(TP-LINK|EU|N300-5|00000000):2.0\r\n"
508 "CPE610(TP-LINK|EU|N300-5|45550000):2.0\r\n"
509 "CPE610(TP-LINK|EU|N300-5|55530000):2.0\r\n"
510 "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n"
511 "CPE610(TP-LINK|UN|N300-5|45550000):2.0\r\n"
512 "CPE610(TP-LINK|UN|N300-5|55530000):2.0\r\n"
513 "CPE610(TP-LINK|US|N300-5|55530000):2.0\r\n"
514 "CPE610(TP-LINK|UN|N300-5):2.0\r\n"
515 "CPE610(TP-LINK|EU|N300-5):2.0\r\n"
516 "CPE610(TP-LINK|US|N300-5):2.0\r\n",
517 .part_trail = 0xff,
518 .soft_ver = NULL,
519
520 .partitions = {
521 {"fs-uboot", 0x00000, 0x20000},
522 {"partition-table", 0x20000, 0x02000},
523 {"default-mac", 0x30000, 0x00020},
524 {"product-info", 0x31100, 0x00100},
525 {"signature", 0x32000, 0x00400},
526 {"os-image", 0x40000, 0x300000},
527 {"file-system", 0x340000, 0x470000},
528 {"soft-version", 0x7b0000, 0x00100},
529 {"support-list", 0x7b1000, 0x00400},
530 {"user-config", 0x7c0000, 0x10000},
531 {"default-config", 0x7d0000, 0x10000},
532 {"log", 0x7e0000, 0x10000},
533 {"radio", 0x7f0000, 0x10000},
534 {NULL, 0, 0}
535 },
536
537 .first_sysupgrade_partition = "os-image",
538 .last_sysupgrade_partition = "support-list",
539 },
540
541 {
542 .id = "WBS210",
543 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
544 .support_list =
545 "SupportList:\r\n"
546 "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
547 "WBS210(TP-LINK|US|N300-2):1.20\r\n"
548 "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
549 .part_trail = 0xff,
550 .soft_ver = NULL,
551
552 .partitions = {
553 {"fs-uboot", 0x00000, 0x20000},
554 {"partition-table", 0x20000, 0x02000},
555 {"default-mac", 0x30000, 0x00020},
556 {"product-info", 0x31100, 0x00100},
557 {"signature", 0x32000, 0x00400},
558 {"os-image", 0x40000, 0x300000},
559 {"file-system", 0x340000, 0x470000},
560 {"soft-version", 0x7b0000, 0x00100},
561 {"support-list", 0x7b1000, 0x00400},
562 {"user-config", 0x7c0000, 0x10000},
563 {"default-config", 0x7d0000, 0x10000},
564 {"log", 0x7e0000, 0x10000},
565 {"radio", 0x7f0000, 0x10000},
566 {NULL, 0, 0}
567 },
568
569 .first_sysupgrade_partition = "os-image",
570 .last_sysupgrade_partition = "support-list",
571 },
572
573 {
574 .id = "WBS210V2",
575 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
576 .support_list =
577 "SupportList:\r\n"
578 "WBS210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
579 "WBS210(TP-LINK|US|N300-2|55530000):2.0\r\n"
580 "WBS210(TP-LINK|EU|N300-2|45550000):2.0\r\n",
581 .part_trail = 0xff,
582 .soft_ver = NULL,
583
584 .partitions = {
585 {"fs-uboot", 0x00000, 0x20000},
586 {"partition-table", 0x20000, 0x02000},
587 {"default-mac", 0x30000, 0x00020},
588 {"product-info", 0x31100, 0x00100},
589 {"signature", 0x32000, 0x00400},
590 {"os-image", 0x40000, 0x300000},
591 {"file-system", 0x340000, 0x470000},
592 {"soft-version", 0x7b0000, 0x00100},
593 {"support-list", 0x7b1000, 0x00400},
594 {"user-config", 0x7c0000, 0x10000},
595 {"default-config", 0x7d0000, 0x10000},
596 {"log", 0x7e0000, 0x10000},
597 {"radio", 0x7f0000, 0x10000},
598 {NULL, 0, 0}
599 },
600
601 .first_sysupgrade_partition = "os-image",
602 .last_sysupgrade_partition = "support-list",
603 },
604
605 {
606 .id = "WBS510",
607 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
608 .support_list =
609 "SupportList:\r\n"
610 "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
611 "WBS510(TP-LINK|US|N300-5):1.20\r\n"
612 "WBS510(TP-LINK|EU|N300-5):1.20\r\n"
613 "WBS510(TP-LINK|CA|N300-5):1.20\r\n",
614 .part_trail = 0xff,
615 .soft_ver = NULL,
616
617 .partitions = {
618 {"fs-uboot", 0x00000, 0x20000},
619 {"partition-table", 0x20000, 0x02000},
620 {"default-mac", 0x30000, 0x00020},
621 {"product-info", 0x31100, 0x00100},
622 {"signature", 0x32000, 0x00400},
623 {"os-image", 0x40000, 0x300000},
624 {"file-system", 0x340000, 0x470000},
625 {"soft-version", 0x7b0000, 0x00100},
626 {"support-list", 0x7b1000, 0x00400},
627 {"user-config", 0x7c0000, 0x10000},
628 {"default-config", 0x7d0000, 0x10000},
629 {"log", 0x7e0000, 0x10000},
630 {"radio", 0x7f0000, 0x10000},
631 {NULL, 0, 0}
632 },
633
634 .first_sysupgrade_partition = "os-image",
635 .last_sysupgrade_partition = "support-list",
636 },
637
638 {
639 .id = "WBS510V2",
640 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
641 .support_list =
642 "SupportList:\r\n"
643 "WBS510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
644 "WBS510(TP-LINK|US|N300-5|55530000):2.0\r\n"
645 "WBS510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
646 "WBS510(TP-LINK|CA|N300-5|43410000):2.0\r\n",
647 .part_trail = 0xff,
648 .soft_ver = NULL,
649
650 .partitions = {
651 {"fs-uboot", 0x00000, 0x20000},
652 {"partition-table", 0x20000, 0x02000},
653 {"default-mac", 0x30000, 0x00020},
654 {"product-info", 0x31100, 0x00100},
655 {"signature", 0x32000, 0x00400},
656 {"os-image", 0x40000, 0x300000},
657 {"file-system", 0x340000, 0x470000},
658 {"soft-version", 0x7b0000, 0x00100},
659 {"support-list", 0x7b1000, 0x00400},
660 {"user-config", 0x7c0000, 0x10000},
661 {"default-config", 0x7d0000, 0x10000},
662 {"log", 0x7e0000, 0x10000},
663 {"radio", 0x7f0000, 0x10000},
664 {NULL, 0, 0}
665 },
666
667 .first_sysupgrade_partition = "os-image",
668 .last_sysupgrade_partition = "support-list",
669 },
670
671 /** Firmware layout for the AD7200 */
672 {
673 .id = "AD7200",
674 .vendor = "",
675 .support_list =
676 "SupportList:\r\n"
677 "{product_name:Talon AD7200,product_ver:1.0.0,special_id:00000000}\r\n",
678 .part_trail = 0x00,
679 .soft_ver = NULL,
680
681 .partitions = {
682 {"SBL1", 0x00000, 0x20000},
683 {"MIBIB", 0x20000, 0x20000},
684 {"SBL2", 0x40000, 0x20000},
685 {"SBL3", 0x60000, 0x30000},
686 {"DDRCONFIG", 0x90000, 0x10000},
687 {"SSD", 0xa0000, 0x10000},
688 {"TZ", 0xb0000, 0x30000},
689 {"RPM", 0xe0000, 0x20000},
690 {"fs-uboot", 0x100000, 0x70000},
691 {"uboot-env", 0x170000, 0x40000},
692 {"radio", 0x1b0000, 0x40000},
693 {"os-image", 0x1f0000, 0x400000},
694 {"file-system", 0x5f0000, 0x1900000},
695 {"default-mac", 0x1ef0000, 0x00200},
696 {"pin", 0x1ef0200, 0x00200},
697 {"device-id", 0x1ef0400, 0x00200},
698 {"product-info", 0x1ef0600, 0x0fa00},
699 {"partition-table", 0x1f00000, 0x10000},
700 {"soft-version", 0x1f10000, 0x10000},
701 {"support-list", 0x1f20000, 0x10000},
702 {"profile", 0x1f30000, 0x10000},
703 {"default-config", 0x1f40000, 0x10000},
704 {"user-config", 0x1f50000, 0x40000},
705 {"qos-db", 0x1f90000, 0x40000},
706 {"usb-config", 0x1fd0000, 0x10000},
707 {"log", 0x1fe0000, 0x20000},
708 {NULL, 0, 0}
709 },
710
711 .first_sysupgrade_partition = "os-image",
712 .last_sysupgrade_partition = "file-system"
713 },
714
715 /** Firmware layout for the C2600 */
716 {
717 .id = "C2600",
718 .vendor = "",
719 .support_list =
720 "SupportList:\r\n"
721 "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
722 .part_trail = 0x00,
723 .soft_ver = NULL,
724
725 /**
726 We use a bigger os-image partition than the stock images (and thus
727 smaller file-system), as our kernel doesn't fit in the stock firmware's
728 2 MB os-image since kernel 4.14.
729 */
730 .partitions = {
731 {"SBL1", 0x00000, 0x20000},
732 {"MIBIB", 0x20000, 0x20000},
733 {"SBL2", 0x40000, 0x20000},
734 {"SBL3", 0x60000, 0x30000},
735 {"DDRCONFIG", 0x90000, 0x10000},
736 {"SSD", 0xa0000, 0x10000},
737 {"TZ", 0xb0000, 0x30000},
738 {"RPM", 0xe0000, 0x20000},
739 {"fs-uboot", 0x100000, 0x70000},
740 {"uboot-env", 0x170000, 0x40000},
741 {"radio", 0x1b0000, 0x40000},
742 {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
743 {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
744 {"default-mac", 0x1ef0000, 0x00200},
745 {"pin", 0x1ef0200, 0x00200},
746 {"product-info", 0x1ef0400, 0x0fc00},
747 {"partition-table", 0x1f00000, 0x10000},
748 {"soft-version", 0x1f10000, 0x10000},
749 {"support-list", 0x1f20000, 0x10000},
750 {"profile", 0x1f30000, 0x10000},
751 {"default-config", 0x1f40000, 0x10000},
752 {"user-config", 0x1f50000, 0x40000},
753 {"qos-db", 0x1f90000, 0x40000},
754 {"usb-config", 0x1fd0000, 0x10000},
755 {"log", 0x1fe0000, 0x20000},
756 {NULL, 0, 0}
757 },
758
759 .first_sysupgrade_partition = "os-image",
760 .last_sysupgrade_partition = "file-system"
761 },
762
763 /** Firmware layout for the A7-V5 */
764 {
765 .id = "ARCHER-A7-V5",
766 .support_list =
767 "SupportList:\n"
768 "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n"
769 "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n"
770 "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n"
771 "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n"
772 "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n"
773 "{product_name:Archer A7,product_ver:5.0.0,special_id:52550000}\n",
774 .part_trail = 0x00,
775 .soft_ver = "soft_ver:1.0.0\n",
776
777 /* We're using a dynamic kernel/rootfs split here */
778 .partitions = {
779 {"factory-boot", 0x00000, 0x20000},
780 {"fs-uboot", 0x20000, 0x20000},
781 {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
782 /* Stock: name file-system base 0x160000 size 0xda0000 */
783 {"default-mac", 0xf40000, 0x00200},
784 {"pin", 0xf40200, 0x00200},
785 {"device-id", 0xf40400, 0x00100},
786 {"product-info", 0xf40500, 0x0fb00},
787 {"soft-version", 0xf50000, 0x00100},
788 {"extra-para", 0xf51000, 0x01000},
789 {"support-list", 0xf52000, 0x0a000},
790 {"profile", 0xf5c000, 0x04000},
791 {"default-config", 0xf60000, 0x10000},
792 {"user-config", 0xf70000, 0x40000},
793 {"certificate", 0xfb0000, 0x10000},
794 {"partition-table", 0xfc0000, 0x10000},
795 {"log", 0xfd0000, 0x20000},
796 {"radio", 0xff0000, 0x10000},
797 {NULL, 0, 0}
798 },
799
800 .first_sysupgrade_partition = "os-image",
801 .last_sysupgrade_partition = "file-system",
802 },
803
804 /** Firmware layout for the C2v3 */
805 {
806 .id = "ARCHER-C2-V3",
807 .support_list =
808 "SupportList:\n"
809 "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n"
810 "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n"
811 "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n",
812 .part_trail = 0x00,
813 .soft_ver = "soft_ver:3.0.1\n",
814
815 /** We're using a dynamic kernel/rootfs split here */
816
817 .partitions = {
818 {"factory-boot", 0x00000, 0x20000},
819 {"fs-uboot", 0x20000, 0x10000},
820 {"firmware", 0x30000, 0x7a0000},
821 {"user-config", 0x7d0000, 0x04000},
822 {"default-mac", 0x7e0000, 0x00100},
823 {"device-id", 0x7e0100, 0x00100},
824 {"extra-para", 0x7e0200, 0x00100},
825 {"pin", 0x7e0300, 0x00100},
826 {"support-list", 0x7e0400, 0x00400},
827 {"soft-version", 0x7e0800, 0x00400},
828 {"product-info", 0x7e0c00, 0x01400},
829 {"partition-table", 0x7e2000, 0x01000},
830 {"profile", 0x7e3000, 0x01000},
831 {"default-config", 0x7e4000, 0x04000},
832 {"merge-config", 0x7ec000, 0x02000},
833 {"qos-db", 0x7ee000, 0x02000},
834 {"radio", 0x7f0000, 0x10000},
835 {NULL, 0, 0}
836 },
837
838 .first_sysupgrade_partition = "os-image",
839 .last_sysupgrade_partition = "file-system",
840 },
841
842 /** Firmware layout for the C25v1 */
843 {
844 .id = "ARCHER-C25-V1",
845 .support_list =
846 "SupportList:\n"
847 "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
848 "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
849 "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
850 .part_trail = 0x00,
851 .soft_ver = "soft_ver:1.0.0\n",
852
853 /* We're using a dynamic kernel/rootfs split here */
854 .partitions = {
855 {"factory-boot", 0x00000, 0x20000},
856 {"fs-uboot", 0x20000, 0x10000},
857 {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */
858 /* Stock: name file-system base 0x130000 size 0x6a0000 */
859 {"user-config", 0x7d0000, 0x04000},
860 {"default-mac", 0x7e0000, 0x00100},
861 {"device-id", 0x7e0100, 0x00100},
862 {"extra-para", 0x7e0200, 0x00100},
863 {"pin", 0x7e0300, 0x00100},
864 {"support-list", 0x7e0400, 0x00400},
865 {"soft-version", 0x7e0800, 0x00400},
866 {"product-info", 0x7e0c00, 0x01400},
867 {"partition-table", 0x7e2000, 0x01000},
868 {"profile", 0x7e3000, 0x01000},
869 {"default-config", 0x7e4000, 0x04000},
870 {"merge-config", 0x7ec000, 0x02000},
871 {"qos-db", 0x7ee000, 0x02000},
872 {"radio", 0x7f0000, 0x10000},
873 {NULL, 0, 0}
874 },
875
876 .first_sysupgrade_partition = "os-image",
877 .last_sysupgrade_partition = "file-system",
878 },
879
880 /** Firmware layout for the C58v1 */
881 {
882 .id = "ARCHER-C58-V1",
883 .vendor = "",
884 .support_list =
885 "SupportList:\r\n"
886 "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
887 "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
888 "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
889 .part_trail = 0x00,
890 .soft_ver = "soft_ver:1.0.0\n",
891
892 .partitions = {
893 {"fs-uboot", 0x00000, 0x10000},
894 {"default-mac", 0x10000, 0x00200},
895 {"pin", 0x10200, 0x00200},
896 {"product-info", 0x10400, 0x00100},
897 {"partition-table", 0x10500, 0x00800},
898 {"soft-version", 0x11300, 0x00200},
899 {"support-list", 0x11500, 0x00100},
900 {"device-id", 0x11600, 0x00100},
901 {"profile", 0x11700, 0x03900},
902 {"default-config", 0x15000, 0x04000},
903 {"user-config", 0x19000, 0x04000},
904 {"firmware", 0x20000, 0x7c8000},
905 {"certyficate", 0x7e8000, 0x08000},
906 {"radio", 0x7f0000, 0x10000},
907 {NULL, 0, 0}
908 },
909
910 .first_sysupgrade_partition = "os-image",
911 .last_sysupgrade_partition = "file-system",
912 },
913
914 /** Firmware layout for the C59v1 */
915 {
916 .id = "ARCHER-C59-V1",
917 .vendor = "",
918 .support_list =
919 "SupportList:\r\n"
920 "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
921 "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
922 "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
923 "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
924 .part_trail = 0x00,
925 .soft_ver = "soft_ver:1.0.0\n",
926
927 /* We're using a dynamic kernel/rootfs split here */
928 .partitions = {
929 {"fs-uboot", 0x00000, 0x10000},
930 {"default-mac", 0x10000, 0x00200},
931 {"pin", 0x10200, 0x00200},
932 {"device-id", 0x10400, 0x00100},
933 {"product-info", 0x10500, 0x0fb00},
934 {"firmware", 0x20000, 0xe30000},
935 {"partition-table", 0xe50000, 0x10000},
936 {"soft-version", 0xe60000, 0x10000},
937 {"support-list", 0xe70000, 0x10000},
938 {"profile", 0xe80000, 0x10000},
939 {"default-config", 0xe90000, 0x10000},
940 {"user-config", 0xea0000, 0x40000},
941 {"usb-config", 0xee0000, 0x10000},
942 {"certificate", 0xef0000, 0x10000},
943 {"qos-db", 0xf00000, 0x40000},
944 {"log", 0xfe0000, 0x10000},
945 {"radio", 0xff0000, 0x10000},
946 {NULL, 0, 0}
947 },
948
949 .first_sysupgrade_partition = "os-image",
950 .last_sysupgrade_partition = "file-system",
951 },
952
953 /** Firmware layout for the C59v2 */
954 {
955 .id = "ARCHER-C59-V2",
956 .vendor = "",
957 .support_list =
958 "SupportList:\r\n"
959 "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
960 "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
961 "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
962 .part_trail = 0x00,
963 .soft_ver = "soft_ver:2.0.0 Build 20161206 rel.7303\n",
964
965 /** We're using a dynamic kernel/rootfs split here */
966 .partitions = {
967 {"factory-boot", 0x00000, 0x20000},
968 {"fs-uboot", 0x20000, 0x10000},
969 {"default-mac", 0x30000, 0x00200},
970 {"pin", 0x30200, 0x00200},
971 {"device-id", 0x30400, 0x00100},
972 {"product-info", 0x30500, 0x0fb00},
973 {"firmware", 0x40000, 0xe10000},
974 {"partition-table", 0xe50000, 0x10000},
975 {"soft-version", 0xe60000, 0x10000},
976 {"support-list", 0xe70000, 0x10000},
977 {"profile", 0xe80000, 0x10000},
978 {"default-config", 0xe90000, 0x10000},
979 {"user-config", 0xea0000, 0x40000},
980 {"usb-config", 0xee0000, 0x10000},
981 {"certificate", 0xef0000, 0x10000},
982 {"extra-para", 0xf00000, 0x10000},
983 {"qos-db", 0xf10000, 0x30000},
984 {"log", 0xfe0000, 0x10000},
985 {"radio", 0xff0000, 0x10000},
986 {NULL, 0, 0}
987 },
988
989 .first_sysupgrade_partition = "os-image",
990 .last_sysupgrade_partition = "file-system",
991 },
992
993 /** Firmware layout for the Archer C6 v2 (EU/RU/JP) */
994 {
995 .id = "ARCHER-C6-V2",
996 .vendor = "",
997 .support_list =
998 "SupportList:\r\n"
999 "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n"
1000 "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
1001 "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
1002 .part_trail = 0x00,
1003 .soft_ver = "soft_ver:1.9.1\n",
1004
1005 .partitions = {
1006 {"fs-uboot", 0x00000, 0x20000},
1007 {"default-mac", 0x20000, 0x00200},
1008 {"pin", 0x20200, 0x00100},
1009 {"product-info", 0x20300, 0x00200},
1010 {"device-id", 0x20500, 0x0fb00},
1011 {"firmware", 0x30000, 0x7a9400},
1012 {"soft-version", 0x7d9400, 0x00100},
1013 {"extra-para", 0x7d9500, 0x00100},
1014 {"support-list", 0x7d9600, 0x00200},
1015 {"profile", 0x7d9800, 0x03000},
1016 {"default-config", 0x7dc800, 0x03000},
1017 {"partition-table", 0x7df800, 0x00800},
1018 {"user-config", 0x7e0000, 0x0c000},
1019 {"certificate", 0x7ec000, 0x04000},
1020 {"radio", 0x7f0000, 0x10000},
1021 {NULL, 0, 0}
1022 },
1023
1024 .first_sysupgrade_partition = "os-image",
1025 .last_sysupgrade_partition = "file-system",
1026 },
1027
1028 /** Firmware layout for the Archer C6 v2 (US) and A6 v2 (US/TW) */
1029 {
1030 .id = "ARCHER-C6-V2-US",
1031 .vendor = "",
1032 .support_list =
1033 "SupportList:\n"
1034 "{product_name:Archer A6,product_ver:2.0.0,special_id:55530000}\n"
1035 "{product_name:Archer A6,product_ver:2.0.0,special_id:54570000}\n"
1036 "{product_name:Archer C6,product_ver:2.0.0,special_id:55530000}\n",
1037 .part_trail = 0x00,
1038 .soft_ver = "soft_ver:1.9.1\n",
1039
1040 .partitions = {
1041 {"factory-boot", 0x00000, 0x20000},
1042 {"default-mac", 0x20000, 0x00200},
1043 {"pin", 0x20200, 0x00100},
1044 {"product-info", 0x20300, 0x00200},
1045 {"device-id", 0x20500, 0x0fb00},
1046 {"fs-uboot", 0x30000, 0x20000},
1047 {"firmware", 0x50000, 0xf89400},
1048 {"soft-version", 0xfd9400, 0x00100},
1049 {"extra-para", 0xfd9500, 0x00100},
1050 {"support-list", 0xfd9600, 0x00200},
1051 {"profile", 0xfd9800, 0x03000},
1052 {"default-config", 0xfdc800, 0x03000},
1053 {"partition-table", 0xfdf800, 0x00800},
1054 {"user-config", 0xfe0000, 0x0c000},
1055 {"certificate", 0xfec000, 0x04000},
1056 {"radio", 0xff0000, 0x10000},
1057 {NULL, 0, 0}
1058 },
1059 .first_sysupgrade_partition = "os-image",
1060 .last_sysupgrade_partition = "file-system",
1061 },
1062
1063 /** Firmware layout for the C60v1 */
1064 {
1065 .id = "ARCHER-C60-V1",
1066 .vendor = "",
1067 .support_list =
1068 "SupportList:\r\n"
1069 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
1070 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
1071 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
1072 .part_trail = 0x00,
1073 .soft_ver = "soft_ver:1.0.0\n",
1074
1075 .partitions = {
1076 {"fs-uboot", 0x00000, 0x10000},
1077 {"default-mac", 0x10000, 0x00200},
1078 {"pin", 0x10200, 0x00200},
1079 {"product-info", 0x10400, 0x00100},
1080 {"partition-table", 0x10500, 0x00800},
1081 {"soft-version", 0x11300, 0x00200},
1082 {"support-list", 0x11500, 0x00100},
1083 {"device-id", 0x11600, 0x00100},
1084 {"profile", 0x11700, 0x03900},
1085 {"default-config", 0x15000, 0x04000},
1086 {"user-config", 0x19000, 0x04000},
1087 {"firmware", 0x20000, 0x7c8000},
1088 {"certyficate", 0x7e8000, 0x08000},
1089 {"radio", 0x7f0000, 0x10000},
1090 {NULL, 0, 0}
1091 },
1092
1093 .first_sysupgrade_partition = "os-image",
1094 .last_sysupgrade_partition = "file-system",
1095 },
1096
1097 /** Firmware layout for the C60v2 */
1098 {
1099 .id = "ARCHER-C60-V2",
1100 .vendor = "",
1101 .support_list =
1102 "SupportList:\r\n"
1103 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
1104 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
1105 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
1106 .part_trail = 0x00,
1107 .soft_ver = "soft_ver:2.0.0\n",
1108
1109 .partitions = {
1110 {"factory-boot", 0x00000, 0x1fb00},
1111 {"default-mac", 0x1fb00, 0x00200},
1112 {"pin", 0x1fd00, 0x00100},
1113 {"product-info", 0x1fe00, 0x00100},
1114 {"device-id", 0x1ff00, 0x00100},
1115 {"fs-uboot", 0x20000, 0x10000},
1116 {"firmware", 0x30000, 0x7a0000},
1117 {"soft-version", 0x7d9500, 0x00100},
1118 {"support-list", 0x7d9600, 0x00100},
1119 {"extra-para", 0x7d9700, 0x00100},
1120 {"profile", 0x7d9800, 0x03000},
1121 {"default-config", 0x7dc800, 0x03000},
1122 {"partition-table", 0x7df800, 0x00800},
1123 {"user-config", 0x7e0000, 0x0c000},
1124 {"certificate", 0x7ec000, 0x04000},
1125 {"radio", 0x7f0000, 0x10000},
1126 {NULL, 0, 0}
1127 },
1128
1129 .first_sysupgrade_partition = "os-image",
1130 .last_sysupgrade_partition = "file-system",
1131 },
1132
1133 /** Firmware layout for the C60v3 */
1134 {
1135 .id = "ARCHER-C60-V3",
1136 .vendor = "",
1137 .support_list =
1138 "SupportList:\r\n"
1139 "{product_name:Archer C60,product_ver:3.0.0,special_id:42520000}\r\n"
1140 "{product_name:Archer C60,product_ver:3.0.0,special_id:45550000}\r\n"
1141 "{product_name:Archer C60,product_ver:3.0.0,special_id:55530000}\r\n",
1142 .part_trail = 0x00,
1143 .soft_ver = "soft_ver:3.0.0\n",
1144
1145 .partitions = {
1146 {"factory-boot", 0x00000, 0x1fb00},
1147 {"default-mac", 0x1fb00, 0x00200},
1148 {"pin", 0x1fd00, 0x00100},
1149 {"product-info", 0x1fe00, 0x00100},
1150 {"device-id", 0x1ff00, 0x00100},
1151 {"fs-uboot", 0x20000, 0x10000},
1152 {"firmware", 0x30000, 0x7a0000},
1153 {"soft-version", 0x7d9500, 0x00100},
1154 {"support-list", 0x7d9600, 0x00100},
1155 {"extra-para", 0x7d9700, 0x00100},
1156 {"profile", 0x7d9800, 0x03000},
1157 {"default-config", 0x7dc800, 0x03000},
1158 {"partition-table", 0x7df800, 0x00800},
1159 {"user-config", 0x7e0000, 0x0c000},
1160 {"certificate", 0x7ec000, 0x04000},
1161 {"radio", 0x7f0000, 0x10000},
1162 {NULL, 0, 0}
1163 },
1164
1165 .first_sysupgrade_partition = "os-image",
1166 .last_sysupgrade_partition = "file-system",
1167 },
1168
1169 /** Firmware layout for the C5 */
1170 {
1171 .id = "ARCHER-C5-V2",
1172 .vendor = "",
1173 .support_list =
1174 "SupportList:\r\n"
1175 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
1176 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
1177 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
1178 .part_trail = 0x00,
1179 .soft_ver = NULL,
1180
1181 .partitions = {
1182 {"fs-uboot", 0x00000, 0x40000},
1183 {"os-image", 0x40000, 0x200000},
1184 {"file-system", 0x240000, 0xc00000},
1185 {"default-mac", 0xe40000, 0x00200},
1186 {"pin", 0xe40200, 0x00200},
1187 {"product-info", 0xe40400, 0x00200},
1188 {"partition-table", 0xe50000, 0x10000},
1189 {"soft-version", 0xe60000, 0x00200},
1190 {"support-list", 0xe61000, 0x0f000},
1191 {"profile", 0xe70000, 0x10000},
1192 {"default-config", 0xe80000, 0x10000},
1193 {"user-config", 0xe90000, 0x50000},
1194 {"log", 0xee0000, 0x100000},
1195 {"radio_bk", 0xfe0000, 0x10000},
1196 {"radio", 0xff0000, 0x10000},
1197 {NULL, 0, 0}
1198 },
1199
1200 .first_sysupgrade_partition = "os-image",
1201 .last_sysupgrade_partition = "file-system"
1202 },
1203
1204 /** Firmware layout for the C7 */
1205 {
1206 .id = "ARCHER-C7-V4",
1207 .support_list =
1208 "SupportList:\n"
1209 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
1210 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
1211 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
1212 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
1213 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
1214 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
1215 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
1216 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
1217 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
1218 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
1219 .part_trail = 0x00,
1220 .soft_ver = "soft_ver:1.0.0\n",
1221
1222 /* We're using a dynamic kernel/rootfs split here */
1223 .partitions = {
1224 {"factory-boot", 0x00000, 0x20000},
1225 {"fs-uboot", 0x20000, 0x20000},
1226 {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
1227 /* Stock: name file-system base 0x160000 size 0xda0000 */
1228 {"default-mac", 0xf00000, 0x00200},
1229 {"pin", 0xf00200, 0x00200},
1230 {"device-id", 0xf00400, 0x00100},
1231 {"product-info", 0xf00500, 0x0fb00},
1232 {"soft-version", 0xf10000, 0x00100},
1233 {"extra-para", 0xf11000, 0x01000},
1234 {"support-list", 0xf12000, 0x0a000},
1235 {"profile", 0xf1c000, 0x04000},
1236 {"default-config", 0xf20000, 0x10000},
1237 {"user-config", 0xf30000, 0x40000},
1238 {"qos-db", 0xf70000, 0x40000},
1239 {"certificate", 0xfb0000, 0x10000},
1240 {"partition-table", 0xfc0000, 0x10000},
1241 {"log", 0xfd0000, 0x20000},
1242 {"radio", 0xff0000, 0x10000},
1243 {NULL, 0, 0}
1244 },
1245
1246 .first_sysupgrade_partition = "os-image",
1247 .last_sysupgrade_partition = "file-system",
1248 },
1249
1250 /** Firmware layout for the C7 v5*/
1251 {
1252 .id = "ARCHER-C7-V5",
1253 .support_list =
1254 "SupportList:\n"
1255 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1256 "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1257 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1258 "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1259 "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1260 "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1261 "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1262 "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1263
1264 .part_trail = 0x00,
1265 .soft_ver = "soft_ver:1.0.0\n",
1266
1267 /* We're using a dynamic kernel/rootfs split here */
1268 .partitions = {
1269 {"factory-boot", 0x00000, 0x20000},
1270 {"fs-uboot", 0x20000, 0x20000},
1271 {"partition-table", 0x40000, 0x10000},
1272 {"radio", 0x50000, 0x10000},
1273 {"default-mac", 0x60000, 0x00200},
1274 {"pin", 0x60200, 0x00200},
1275 {"device-id", 0x60400, 0x00100},
1276 {"product-info", 0x60500, 0x0fb00},
1277 {"soft-version", 0x70000, 0x01000},
1278 {"extra-para", 0x71000, 0x01000},
1279 {"support-list", 0x72000, 0x0a000},
1280 {"profile", 0x7c000, 0x04000},
1281 {"user-config", 0x80000, 0x40000},
1282
1283
1284 {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */
1285 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1286
1287 {"log", 0xfc0000, 0x20000},
1288 {"certificate", 0xfe0000, 0x10000},
1289 {"default-config", 0xff0000, 0x10000},
1290 {NULL, 0, 0}
1291
1292 },
1293
1294 .first_sysupgrade_partition = "os-image",
1295 .last_sysupgrade_partition = "file-system",
1296 },
1297
1298 /** Firmware layout for the C9 */
1299 {
1300 .id = "ARCHERC9",
1301 .vendor = "",
1302 .support_list =
1303 "SupportList:\n"
1304 "{product_name:ArcherC9,"
1305 "product_ver:1.0.0,"
1306 "special_id:00000000}\n",
1307 .part_trail = 0x00,
1308 .soft_ver = NULL,
1309
1310 .partitions = {
1311 {"fs-uboot", 0x00000, 0x40000},
1312 {"os-image", 0x40000, 0x200000},
1313 {"file-system", 0x240000, 0xc00000},
1314 {"default-mac", 0xe40000, 0x00200},
1315 {"pin", 0xe40200, 0x00200},
1316 {"product-info", 0xe40400, 0x00200},
1317 {"partition-table", 0xe50000, 0x10000},
1318 {"soft-version", 0xe60000, 0x00200},
1319 {"support-list", 0xe61000, 0x0f000},
1320 {"profile", 0xe70000, 0x10000},
1321 {"default-config", 0xe80000, 0x10000},
1322 {"user-config", 0xe90000, 0x50000},
1323 {"log", 0xee0000, 0x100000},
1324 {"radio_bk", 0xfe0000, 0x10000},
1325 {"radio", 0xff0000, 0x10000},
1326 {NULL, 0, 0}
1327 },
1328
1329 .first_sysupgrade_partition = "os-image",
1330 .last_sysupgrade_partition = "file-system"
1331 },
1332
1333 /** Firmware layout for the EAP120 */
1334 {
1335 .id = "EAP120",
1336 .vendor = "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1337 .support_list =
1338 "SupportList:\r\n"
1339 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1340 .part_trail = 0xff,
1341 .soft_ver = NULL,
1342
1343 .partitions = {
1344 {"fs-uboot", 0x00000, 0x20000},
1345 {"partition-table", 0x20000, 0x02000},
1346 {"default-mac", 0x30000, 0x00020},
1347 {"support-list", 0x31000, 0x00100},
1348 {"product-info", 0x31100, 0x00100},
1349 {"soft-version", 0x32000, 0x00100},
1350 {"os-image", 0x40000, 0x180000},
1351 {"file-system", 0x1c0000, 0x600000},
1352 {"user-config", 0x7c0000, 0x10000},
1353 {"backup-config", 0x7d0000, 0x10000},
1354 {"log", 0x7e0000, 0x10000},
1355 {"radio", 0x7f0000, 0x10000},
1356 {NULL, 0, 0}
1357 },
1358
1359 .first_sysupgrade_partition = "os-image",
1360 .last_sysupgrade_partition = "file-system"
1361 },
1362
1363 /** Firmware layout for the EAP225-Outdoor v1 */
1364 {
1365 .id = "EAP225-OUTDOOR-V1",
1366 .support_list =
1367 "SupportList:\r\n"
1368 "EAP225-Outdoor(TP-Link|UN|AC1200-D):1.0\r\n",
1369 .part_trail = PART_TRAIL_NONE,
1370 .soft_ver = NULL,
1371 .soft_ver_compat_level = 1,
1372
1373 .partitions = {
1374 {"fs-uboot", 0x00000, 0x20000},
1375 {"partition-table", 0x20000, 0x02000},
1376 {"default-mac", 0x30000, 0x01000},
1377 {"support-list", 0x31000, 0x00100},
1378 {"product-info", 0x31100, 0x00400},
1379 {"soft-version", 0x32000, 0x00100},
1380 {"firmware", 0x40000, 0xd80000},
1381 {"user-config", 0xdc0000, 0x30000},
1382 {"mutil-log", 0xf30000, 0x80000},
1383 {"oops", 0xfb0000, 0x40000},
1384 {"radio", 0xff0000, 0x10000},
1385 {NULL, 0, 0}
1386 },
1387
1388 .first_sysupgrade_partition = "os-image",
1389 .last_sysupgrade_partition = "file-system"
1390 },
1391
1392 /** Firmware layout for the EAP225 v3 */
1393 {
1394 .id = "EAP225-V3",
1395 .support_list =
1396 "SupportList:\r\n"
1397 "EAP225(TP-Link|UN|AC1350-D):3.0\r\n",
1398 .part_trail = PART_TRAIL_NONE,
1399 .soft_ver = NULL,
1400 .soft_ver_compat_level = 1,
1401
1402 .partitions = {
1403 {"fs-uboot", 0x00000, 0x20000},
1404 {"partition-table", 0x20000, 0x02000},
1405 {"default-mac", 0x30000, 0x01000},
1406 {"support-list", 0x31000, 0x00100},
1407 {"product-info", 0x31100, 0x00400},
1408 {"soft-version", 0x32000, 0x00100},
1409 {"firmware", 0x40000, 0xd80000},
1410 {"user-config", 0xdc0000, 0x30000},
1411 {"mutil-log", 0xf30000, 0x80000},
1412 {"oops", 0xfb0000, 0x40000},
1413 {"radio", 0xff0000, 0x10000},
1414 {NULL, 0, 0}
1415 },
1416
1417 .first_sysupgrade_partition = "os-image",
1418 .last_sysupgrade_partition = "file-system"
1419 },
1420
1421 /** Firmware layout for the EAP225-Wall v2 */
1422 {
1423 .id = "EAP225-WALL-V2",
1424 .support_list =
1425 "SupportList:\r\n"
1426 "EAP225-Wall(TP-Link|UN|AC1200-D):2.0\r\n",
1427 .part_trail = PART_TRAIL_NONE,
1428 .soft_ver = NULL,
1429 .soft_ver_compat_level = 1,
1430
1431 .partitions = {
1432 {"fs-uboot", 0x00000, 0x20000},
1433 {"partition-table", 0x20000, 0x02000},
1434 {"default-mac", 0x30000, 0x01000},
1435 {"support-list", 0x31000, 0x00100},
1436 {"product-info", 0x31100, 0x00400},
1437 {"soft-version", 0x32000, 0x00100},
1438 {"firmware", 0x40000, 0xd80000},
1439 {"user-config", 0xdc0000, 0x30000},
1440 {"mutil-log", 0xf30000, 0x80000},
1441 {"oops", 0xfb0000, 0x40000},
1442 {"radio", 0xff0000, 0x10000},
1443 {NULL, 0, 0}
1444 },
1445
1446 .first_sysupgrade_partition = "os-image",
1447 .last_sysupgrade_partition = "file-system"
1448 },
1449
1450 /** Firmware layout for the EAP245 v1 */
1451 {
1452 .id = "EAP245-V1",
1453 .support_list =
1454 "SupportList:\r\n"
1455 "EAP245(TP-LINK|UN|AC1750-D):1.0\r\n",
1456 .part_trail = PART_TRAIL_NONE,
1457 .soft_ver = NULL,
1458
1459 .partitions = {
1460 {"fs-uboot", 0x00000, 0x20000},
1461 {"partition-table", 0x20000, 0x02000},
1462 {"default-mac", 0x30000, 0x01000},
1463 {"support-list", 0x31000, 0x00100},
1464 {"product-info", 0x31100, 0x00400},
1465 {"soft-version", 0x32000, 0x00100},
1466 {"firmware", 0x40000, 0xd80000},
1467 {"user-config", 0xdc0000, 0x30000},
1468 {"radio", 0xff0000, 0x10000},
1469 {NULL, 0, 0}
1470 },
1471
1472 .first_sysupgrade_partition = "os-image",
1473 .last_sysupgrade_partition = "file-system"
1474 },
1475
1476 /** Firmware layout for the EAP245 v3 */
1477 {
1478 .id = "EAP245-V3",
1479 .support_list =
1480 "SupportList:\r\n"
1481 "EAP245(TP-Link|UN|AC1750-D):3.0\r\n",
1482 .part_trail = PART_TRAIL_NONE,
1483 .soft_ver = NULL,
1484 .soft_ver_compat_level = 1,
1485
1486 /** Firmware partition with dynamic kernel/rootfs split */
1487 .partitions = {
1488 {"factroy-boot", 0x00000, 0x40000},
1489 {"fs-uboot", 0x40000, 0x40000},
1490 {"partition-table", 0x80000, 0x10000},
1491 {"default-mac", 0x90000, 0x01000},
1492 {"support-list", 0x91000, 0x00100},
1493 {"product-info", 0x91100, 0x00400},
1494 {"soft-version", 0x92000, 0x00100},
1495 {"radio", 0xa0000, 0x10000},
1496 {"extra-para", 0xb0000, 0x10000},
1497 {"firmware", 0xc0000, 0xe40000},
1498 {"config", 0xf00000, 0x30000},
1499 {"mutil-log", 0xf30000, 0x80000},
1500 {"oops", 0xfb0000, 0x40000},
1501 {NULL, 0, 0}
1502 },
1503
1504 .first_sysupgrade_partition = "os-image",
1505 .last_sysupgrade_partition = "file-system"
1506 },
1507
1508 /** Firmware layout for the TL-WA850RE v2 */
1509 {
1510 .id = "TLWA850REV2",
1511 .vendor = "",
1512 .support_list =
1513 "SupportList:\n"
1514 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1515 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1516 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1517 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1518 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1519 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1520 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1521 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1522 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1523 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1524 .part_trail = 0x00,
1525 .soft_ver = NULL,
1526
1527 /**
1528 576KB were moved from file-system to os-image
1529 in comparison to the stock image
1530 */
1531 .partitions = {
1532 {"fs-uboot", 0x00000, 0x20000},
1533 {"firmware", 0x20000, 0x390000},
1534 {"partition-table", 0x3b0000, 0x02000},
1535 {"default-mac", 0x3c0000, 0x00020},
1536 {"pin", 0x3c0100, 0x00020},
1537 {"product-info", 0x3c1000, 0x01000},
1538 {"soft-version", 0x3c2000, 0x00100},
1539 {"support-list", 0x3c3000, 0x01000},
1540 {"profile", 0x3c4000, 0x08000},
1541 {"user-config", 0x3d0000, 0x10000},
1542 {"default-config", 0x3e0000, 0x10000},
1543 {"radio", 0x3f0000, 0x10000},
1544 {NULL, 0, 0}
1545 },
1546
1547 .first_sysupgrade_partition = "os-image",
1548 .last_sysupgrade_partition = "file-system"
1549 },
1550
1551 /** Firmware layout for the TL-WA855RE v1 */
1552 {
1553 .id = "TLWA855REV1",
1554 .vendor = "",
1555 .support_list =
1556 "SupportList:\n"
1557 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1558 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1559 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1560 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1561 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1562 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1563 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1564 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1565 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1566 .part_trail = 0x00,
1567 .soft_ver = NULL,
1568
1569 .partitions = {
1570 {"fs-uboot", 0x00000, 0x20000},
1571 {"os-image", 0x20000, 0x150000},
1572 {"file-system", 0x170000, 0x240000},
1573 {"partition-table", 0x3b0000, 0x02000},
1574 {"default-mac", 0x3c0000, 0x00020},
1575 {"pin", 0x3c0100, 0x00020},
1576 {"product-info", 0x3c1000, 0x01000},
1577 {"soft-version", 0x3c2000, 0x00100},
1578 {"support-list", 0x3c3000, 0x01000},
1579 {"profile", 0x3c4000, 0x08000},
1580 {"user-config", 0x3d0000, 0x10000},
1581 {"default-config", 0x3e0000, 0x10000},
1582 {"radio", 0x3f0000, 0x10000},
1583 {NULL, 0, 0}
1584 },
1585
1586 .first_sysupgrade_partition = "os-image",
1587 .last_sysupgrade_partition = "file-system"
1588 },
1589
1590 /** Firmware layout for the TL-WPA8630P v2 (EU)*/
1591 {
1592 .id = "TL-WPA8630P-V2.0-EU",
1593 .vendor = "",
1594 .support_list =
1595 "SupportList:\n"
1596 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
1597 .part_trail = 0x00,
1598 .soft_ver = NULL,
1599
1600 .partitions = {
1601 {"factory-uboot", 0x00000, 0x20000},
1602 {"fs-uboot", 0x20000, 0x20000},
1603 {"firmware", 0x40000, 0x5e0000},
1604 {"partition-table", 0x620000, 0x02000},
1605 {"default-mac", 0x630000, 0x00020},
1606 {"pin", 0x630100, 0x00020},
1607 {"device-id", 0x630200, 0x00030},
1608 {"product-info", 0x631100, 0x01000},
1609 {"extra-para", 0x632100, 0x01000},
1610 {"soft-version", 0x640000, 0x01000},
1611 {"support-list", 0x641000, 0x01000},
1612 {"profile", 0x642000, 0x08000},
1613 {"user-config", 0x650000, 0x10000},
1614 {"default-config", 0x660000, 0x10000},
1615 {"default-nvm", 0x670000, 0xc0000},
1616 {"default-pib", 0x730000, 0x40000},
1617 {"radio", 0x7f0000, 0x10000},
1618 {NULL, 0, 0}
1619 },
1620
1621 .first_sysupgrade_partition = "os-image",
1622 .last_sysupgrade_partition = "file-system"
1623 },
1624
1625 /** Firmware layout for the TL-WPA8630P v2 (INT)*/
1626 {
1627 .id = "TL-WPA8630P-V2-INT",
1628 .vendor = "",
1629 .support_list =
1630 "SupportList:\n"
1631 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
1632 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
1633 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
1634 .part_trail = 0x00,
1635 .soft_ver = NULL,
1636
1637 .partitions = {
1638 {"factory-uboot", 0x00000, 0x20000},
1639 {"fs-uboot", 0x20000, 0x20000},
1640 {"firmware", 0x40000, 0x5e0000},
1641 {"partition-table", 0x620000, 0x02000},
1642 {"extra-para", 0x632100, 0x01000},
1643 {"soft-version", 0x640000, 0x01000},
1644 {"support-list", 0x641000, 0x01000},
1645 {"profile", 0x642000, 0x08000},
1646 {"user-config", 0x650000, 0x10000},
1647 {"default-config", 0x660000, 0x10000},
1648 {"default-nvm", 0x670000, 0xc0000},
1649 {"default-pib", 0x730000, 0x40000},
1650 {"default-mac", 0x7e0000, 0x00020},
1651 {"pin", 0x7e0100, 0x00020},
1652 {"device-id", 0x7e0200, 0x00030},
1653 {"product-info", 0x7e1100, 0x01000},
1654 {"radio", 0x7f0000, 0x10000},
1655 {NULL, 0, 0}
1656 },
1657
1658 .first_sysupgrade_partition = "os-image",
1659 .last_sysupgrade_partition = "file-system"
1660 },
1661
1662 /** Firmware layout for the TL-WPA8630P v2.1 (EU)*/
1663 {
1664 .id = "TL-WPA8630P-V2.1-EU",
1665 .vendor = "",
1666 .support_list =
1667 "SupportList:\n"
1668 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n",
1669 .part_trail = 0x00,
1670 .soft_ver = NULL,
1671
1672 .partitions = {
1673 {"factory-uboot", 0x00000, 0x20000},
1674 {"fs-uboot", 0x20000, 0x20000},
1675 {"firmware", 0x40000, 0x5e0000},
1676 {"extra-para", 0x680000, 0x01000},
1677 {"product-info", 0x690000, 0x01000},
1678 {"partition-table", 0x6a0000, 0x02000},
1679 {"soft-version", 0x6b0000, 0x01000},
1680 {"support-list", 0x6b1000, 0x01000},
1681 {"profile", 0x6b2000, 0x08000},
1682 {"user-config", 0x6c0000, 0x10000},
1683 {"default-config", 0x6d0000, 0x10000},
1684 {"default-nvm", 0x6e0000, 0xc0000},
1685 {"default-pib", 0x7a0000, 0x40000},
1686 {"default-mac", 0x7e0000, 0x00020},
1687 {"pin", 0x7e0100, 0x00020},
1688 {"device-id", 0x7e0200, 0x00030},
1689 {"radio", 0x7f0000, 0x10000},
1690 {NULL, 0, 0}
1691 },
1692
1693 .first_sysupgrade_partition = "os-image",
1694 .last_sysupgrade_partition = "file-system"
1695 },
1696
1697 /** Firmware layout for the TL-WR1043 v5 */
1698 {
1699 .id = "TLWR1043NV5",
1700 .vendor = "",
1701 .support_list =
1702 "SupportList:\n"
1703 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1704 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1705 .part_trail = 0x00,
1706 .soft_ver = "soft_ver:1.0.0\n",
1707 .partitions = {
1708 {"factory-boot", 0x00000, 0x20000},
1709 {"fs-uboot", 0x20000, 0x20000},
1710 {"firmware", 0x40000, 0xec0000},
1711 {"default-mac", 0xf00000, 0x00200},
1712 {"pin", 0xf00200, 0x00200},
1713 {"device-id", 0xf00400, 0x00100},
1714 {"product-info", 0xf00500, 0x0fb00},
1715 {"soft-version", 0xf10000, 0x01000},
1716 {"extra-para", 0xf11000, 0x01000},
1717 {"support-list", 0xf12000, 0x0a000},
1718 {"profile", 0xf1c000, 0x04000},
1719 {"default-config", 0xf20000, 0x10000},
1720 {"user-config", 0xf30000, 0x40000},
1721 {"qos-db", 0xf70000, 0x40000},
1722 {"certificate", 0xfb0000, 0x10000},
1723 {"partition-table", 0xfc0000, 0x10000},
1724 {"log", 0xfd0000, 0x20000},
1725 {"radio", 0xff0000, 0x10000},
1726 {NULL, 0, 0}
1727 },
1728 .first_sysupgrade_partition = "os-image",
1729 .last_sysupgrade_partition = "file-system"
1730 },
1731
1732 /** Firmware layout for the TL-WR1043 v4 */
1733 {
1734 .id = "TLWR1043NDV4",
1735 .vendor = "",
1736 .support_list =
1737 "SupportList:\n"
1738 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1739 .part_trail = 0x00,
1740 .soft_ver = NULL,
1741
1742 /* We're using a dynamic kernel/rootfs split here */
1743 .partitions = {
1744 {"fs-uboot", 0x00000, 0x20000},
1745 {"firmware", 0x20000, 0xf30000},
1746 {"default-mac", 0xf50000, 0x00200},
1747 {"pin", 0xf50200, 0x00200},
1748 {"product-info", 0xf50400, 0x0fc00},
1749 {"soft-version", 0xf60000, 0x0b000},
1750 {"support-list", 0xf6b000, 0x04000},
1751 {"profile", 0xf70000, 0x04000},
1752 {"default-config", 0xf74000, 0x0b000},
1753 {"user-config", 0xf80000, 0x40000},
1754 {"partition-table", 0xfc0000, 0x10000},
1755 {"log", 0xfd0000, 0x20000},
1756 {"radio", 0xff0000, 0x10000},
1757 {NULL, 0, 0}
1758 },
1759
1760 .first_sysupgrade_partition = "os-image",
1761 .last_sysupgrade_partition = "file-system"
1762 },
1763
1764 /** Firmware layout for the TL-WR902AC v1 */
1765 {
1766 .id = "TL-WR902AC-V1",
1767 .vendor = "",
1768 .support_list =
1769 "SupportList:\n"
1770 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1771 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1772 .part_trail = 0x00,
1773 .soft_ver = NULL,
1774
1775 /**
1776 384KB were moved from file-system to os-image
1777 in comparison to the stock image
1778 */
1779 .partitions = {
1780 {"fs-uboot", 0x00000, 0x20000},
1781 {"firmware", 0x20000, 0x730000},
1782 {"default-mac", 0x750000, 0x00200},
1783 {"pin", 0x750200, 0x00200},
1784 {"product-info", 0x750400, 0x0fc00},
1785 {"soft-version", 0x760000, 0x0b000},
1786 {"support-list", 0x76b000, 0x04000},
1787 {"profile", 0x770000, 0x04000},
1788 {"default-config", 0x774000, 0x0b000},
1789 {"user-config", 0x780000, 0x40000},
1790 {"partition-table", 0x7c0000, 0x10000},
1791 {"log", 0x7d0000, 0x20000},
1792 {"radio", 0x7f0000, 0x10000},
1793 {NULL, 0, 0}
1794 },
1795
1796 .first_sysupgrade_partition = "os-image",
1797 .last_sysupgrade_partition = "file-system",
1798 },
1799
1800 /** Firmware layout for the TL-WR942N V1 */
1801 {
1802 .id = "TLWR942NV1",
1803 .vendor = "",
1804 .support_list =
1805 "SupportList:\r\n"
1806 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1807 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1808 .part_trail = 0x00,
1809 .soft_ver = NULL,
1810
1811 .partitions = {
1812 {"fs-uboot", 0x00000, 0x20000},
1813 {"firmware", 0x20000, 0xe20000},
1814 {"default-mac", 0xe40000, 0x00200},
1815 {"pin", 0xe40200, 0x00200},
1816 {"product-info", 0xe40400, 0x0fc00},
1817 {"partition-table", 0xe50000, 0x10000},
1818 {"soft-version", 0xe60000, 0x10000},
1819 {"support-list", 0xe70000, 0x10000},
1820 {"profile", 0xe80000, 0x10000},
1821 {"default-config", 0xe90000, 0x10000},
1822 {"user-config", 0xea0000, 0x40000},
1823 {"qos-db", 0xee0000, 0x40000},
1824 {"certificate", 0xf20000, 0x10000},
1825 {"usb-config", 0xfb0000, 0x10000},
1826 {"log", 0xfc0000, 0x20000},
1827 {"radio-bk", 0xfe0000, 0x10000},
1828 {"radio", 0xff0000, 0x10000},
1829 {NULL, 0, 0}
1830 },
1831
1832 .first_sysupgrade_partition = "os-image",
1833 .last_sysupgrade_partition = "file-system",
1834 },
1835
1836 /** Firmware layout for the RE200 v2 */
1837 {
1838 .id = "RE200-V2",
1839 .vendor = "",
1840 .support_list =
1841 "SupportList:\n"
1842 "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
1843 "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
1844 "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
1845 "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
1846 "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
1847 "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
1848 "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
1849 "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
1850 "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
1851 "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
1852 "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
1853 "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
1854 "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
1855 .part_trail = 0x00,
1856 .soft_ver = NULL,
1857
1858 .partitions = {
1859 {"fs-uboot", 0x00000, 0x20000},
1860 {"firmware", 0x20000, 0x7a0000},
1861 {"partition-table", 0x7c0000, 0x02000},
1862 {"default-mac", 0x7c2000, 0x00020},
1863 {"pin", 0x7c2100, 0x00020},
1864 {"product-info", 0x7c3100, 0x01000},
1865 {"soft-version", 0x7c4200, 0x01000},
1866 {"support-list", 0x7c5200, 0x01000},
1867 {"profile", 0x7c6200, 0x08000},
1868 {"config-info", 0x7ce200, 0x00400},
1869 {"user-config", 0x7d0000, 0x10000},
1870 {"default-config", 0x7e0000, 0x10000},
1871 {"radio", 0x7f0000, 0x10000},
1872 {NULL, 0, 0}
1873 },
1874
1875 .first_sysupgrade_partition = "os-image",
1876 .last_sysupgrade_partition = "file-system"
1877 },
1878
1879 /** Firmware layout for the RE200 v3 */
1880 {
1881 .id = "RE200-V3",
1882 .vendor = "",
1883 .support_list =
1884 "SupportList:\n"
1885 "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
1886 "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
1887 "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
1888 "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
1889 "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
1890 "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
1891 "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
1892 "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
1893 "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
1894 "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
1895 "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
1896 "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
1897 "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
1898 "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
1899 .part_trail = 0x00,
1900 .soft_ver = NULL,
1901
1902 .partitions = {
1903 {"fs-uboot", 0x00000, 0x20000},
1904 {"firmware", 0x20000, 0x7a0000},
1905 {"partition-table", 0x7c0000, 0x02000},
1906 {"default-mac", 0x7c2000, 0x00020},
1907 {"pin", 0x7c2100, 0x00020},
1908 {"product-info", 0x7c3100, 0x01000},
1909 {"soft-version", 0x7c4200, 0x01000},
1910 {"support-list", 0x7c5200, 0x01000},
1911 {"profile", 0x7c6200, 0x08000},
1912 {"config-info", 0x7ce200, 0x00400},
1913 {"user-config", 0x7d0000, 0x10000},
1914 {"default-config", 0x7e0000, 0x10000},
1915 {"radio", 0x7f0000, 0x10000},
1916 {NULL, 0, 0}
1917 },
1918
1919 .first_sysupgrade_partition = "os-image",
1920 .last_sysupgrade_partition = "file-system"
1921 },
1922
1923 /** Firmware layout for the RE200 v4 */
1924 {
1925 .id = "RE200-V4",
1926 .vendor = "",
1927 .support_list =
1928 "SupportList:\n"
1929 "{product_name:RE200,product_ver:4.0.0,special_id:00000000}\n"
1930 "{product_name:RE200,product_ver:4.0.0,special_id:45550000}\n"
1931 "{product_name:RE200,product_ver:4.0.0,special_id:4A500000}\n"
1932 "{product_name:RE200,product_ver:4.0.0,special_id:4B520000}\n"
1933 "{product_name:RE200,product_ver:4.0.0,special_id:43410000}\n"
1934 "{product_name:RE200,product_ver:4.0.0,special_id:41550000}\n"
1935 "{product_name:RE200,product_ver:4.0.0,special_id:42520000}\n"
1936 "{product_name:RE200,product_ver:4.0.0,special_id:55530000}\n"
1937 "{product_name:RE200,product_ver:4.0.0,special_id:41520000}\n"
1938 "{product_name:RE200,product_ver:4.0.0,special_id:52550000}\n"
1939 "{product_name:RE200,product_ver:4.0.0,special_id:54570000}\n"
1940 "{product_name:RE200,product_ver:4.0.0,special_id:45530000}\n"
1941 "{product_name:RE200,product_ver:4.0.0,special_id:49440000}\n"
1942 "{product_name:RE200,product_ver:4.0.0,special_id:45470000}\n",
1943 .part_trail = 0x00,
1944 .soft_ver = "soft_ver:1.1.0\n",
1945
1946 .partitions = {
1947 {"fs-uboot", 0x00000, 0x20000},
1948 {"firmware", 0x20000, 0x7a0000},
1949 {"partition-table", 0x7c0000, 0x02000},
1950 {"default-mac", 0x7c2000, 0x00020},
1951 {"pin", 0x7c2100, 0x00020},
1952 {"product-info", 0x7c3100, 0x01000},
1953 {"soft-version", 0x7c4200, 0x01000},
1954 {"support-list", 0x7c5200, 0x01000},
1955 {"profile", 0x7c6200, 0x08000},
1956 {"config-info", 0x7ce200, 0x00400},
1957 {"user-config", 0x7d0000, 0x10000},
1958 {"default-config", 0x7e0000, 0x10000},
1959 {"radio", 0x7f0000, 0x10000},
1960 {NULL, 0, 0}
1961 },
1962
1963 .first_sysupgrade_partition = "os-image",
1964 .last_sysupgrade_partition = "file-system"
1965 },
1966
1967 /** Firmware layout for the RE220 v2 */
1968 {
1969 .id = "RE220-V2",
1970 .vendor = "",
1971 .support_list =
1972 "SupportList:\n"
1973 "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
1974 "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
1975 "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
1976 "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
1977 "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
1978 "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
1979 "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
1980 "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
1981 "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
1982 "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
1983 "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
1984 "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
1985 "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
1986 .part_trail = 0x00,
1987 .soft_ver = NULL,
1988
1989 .partitions = {
1990 {"fs-uboot", 0x00000, 0x20000},
1991 {"firmware", 0x20000, 0x7a0000},
1992 {"partition-table", 0x7c0000, 0x02000},
1993 {"default-mac", 0x7c2000, 0x00020},
1994 {"pin", 0x7c2100, 0x00020},
1995 {"product-info", 0x7c3100, 0x01000},
1996 {"soft-version", 0x7c4200, 0x01000},
1997 {"support-list", 0x7c5200, 0x01000},
1998 {"profile", 0x7c6200, 0x08000},
1999 {"config-info", 0x7ce200, 0x00400},
2000 {"user-config", 0x7d0000, 0x10000},
2001 {"default-config", 0x7e0000, 0x10000},
2002 {"radio", 0x7f0000, 0x10000},
2003 {NULL, 0, 0}
2004 },
2005
2006 .first_sysupgrade_partition = "os-image",
2007 .last_sysupgrade_partition = "file-system"
2008 },
2009
2010 /** Firmware layout for the RE305 v1 */
2011 {
2012 .id = "RE305-V1",
2013 .vendor = "",
2014 .support_list =
2015 "SupportList:\n"
2016 "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
2017 "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
2018 "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
2019 "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
2020 "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
2021 "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
2022 "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
2023 .part_trail = 0x00,
2024 .soft_ver = NULL,
2025
2026 .partitions = {
2027 {"fs-uboot", 0x00000, 0x20000},
2028 {"firmware", 0x20000, 0x5e0000},
2029 {"partition-table", 0x600000, 0x02000},
2030 {"default-mac", 0x610000, 0x00020},
2031 {"pin", 0x610100, 0x00020},
2032 {"product-info", 0x611100, 0x01000},
2033 {"soft-version", 0x620000, 0x01000},
2034 {"support-list", 0x621000, 0x01000},
2035 {"profile", 0x622000, 0x08000},
2036 {"user-config", 0x630000, 0x10000},
2037 {"default-config", 0x640000, 0x10000},
2038 {"radio", 0x7f0000, 0x10000},
2039 {NULL, 0, 0}
2040 },
2041
2042 .first_sysupgrade_partition = "os-image",
2043 .last_sysupgrade_partition = "file-system"
2044 },
2045
2046 /** Firmware layout for the RE350 v1 */
2047 {
2048 .id = "RE350-V1",
2049 .vendor = "",
2050 .support_list =
2051 "SupportList:\n"
2052 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
2053 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
2054 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
2055 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
2056 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
2057 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
2058 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
2059 .part_trail = 0x00,
2060 .soft_ver = NULL,
2061
2062 /** We're using a dynamic kernel/rootfs split here */
2063 .partitions = {
2064 {"fs-uboot", 0x00000, 0x20000},
2065 {"firmware", 0x20000, 0x5e0000},
2066 {"partition-table", 0x600000, 0x02000},
2067 {"default-mac", 0x610000, 0x00020},
2068 {"pin", 0x610100, 0x00020},
2069 {"product-info", 0x611100, 0x01000},
2070 {"soft-version", 0x620000, 0x01000},
2071 {"support-list", 0x621000, 0x01000},
2072 {"profile", 0x622000, 0x08000},
2073 {"user-config", 0x630000, 0x10000},
2074 {"default-config", 0x640000, 0x10000},
2075 {"radio", 0x7f0000, 0x10000},
2076 {NULL, 0, 0}
2077 },
2078
2079 .first_sysupgrade_partition = "os-image",
2080 .last_sysupgrade_partition = "file-system"
2081 },
2082
2083 /** Firmware layout for the RE350K v1 */
2084 {
2085 .id = "RE350K-V1",
2086 .vendor = "",
2087 .support_list =
2088 "SupportList:\n"
2089 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
2090 .part_trail = 0x00,
2091 .soft_ver = NULL,
2092
2093 /** We're using a dynamic kernel/rootfs split here */
2094 .partitions = {
2095 {"fs-uboot", 0x00000, 0x20000},
2096 {"firmware", 0x20000, 0xd70000},
2097 {"partition-table", 0xd90000, 0x02000},
2098 {"default-mac", 0xda0000, 0x00020},
2099 {"pin", 0xda0100, 0x00020},
2100 {"product-info", 0xda1100, 0x01000},
2101 {"soft-version", 0xdb0000, 0x01000},
2102 {"support-list", 0xdb1000, 0x01000},
2103 {"profile", 0xdb2000, 0x08000},
2104 {"user-config", 0xdc0000, 0x10000},
2105 {"default-config", 0xdd0000, 0x10000},
2106 {"device-id", 0xde0000, 0x00108},
2107 {"radio", 0xff0000, 0x10000},
2108 {NULL, 0, 0}
2109 },
2110
2111 .first_sysupgrade_partition = "os-image",
2112 .last_sysupgrade_partition = "file-system"
2113 },
2114
2115 /** Firmware layout for the RE355 */
2116 {
2117 .id = "RE355",
2118 .vendor = "",
2119 .support_list =
2120 "SupportList:\r\n"
2121 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
2122 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
2123 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
2124 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
2125 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
2126 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
2127 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
2128 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
2129 .part_trail = 0x00,
2130 .soft_ver = NULL,
2131
2132 /* We're using a dynamic kernel/rootfs split here */
2133 .partitions = {
2134 {"fs-uboot", 0x00000, 0x20000},
2135 {"firmware", 0x20000, 0x5e0000},
2136 {"partition-table", 0x600000, 0x02000},
2137 {"default-mac", 0x610000, 0x00020},
2138 {"pin", 0x610100, 0x00020},
2139 {"product-info", 0x611100, 0x01000},
2140 {"soft-version", 0x620000, 0x01000},
2141 {"support-list", 0x621000, 0x01000},
2142 {"profile", 0x622000, 0x08000},
2143 {"user-config", 0x630000, 0x10000},
2144 {"default-config", 0x640000, 0x10000},
2145 {"radio", 0x7f0000, 0x10000},
2146 {NULL, 0, 0}
2147 },
2148
2149 .first_sysupgrade_partition = "os-image",
2150 .last_sysupgrade_partition = "file-system"
2151 },
2152
2153 /** Firmware layout for the RE450 */
2154 {
2155 .id = "RE450",
2156 .vendor = "",
2157 .support_list =
2158 "SupportList:\r\n"
2159 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
2160 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
2161 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
2162 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
2163 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
2164 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
2165 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
2166 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
2167 .part_trail = 0x00,
2168 .soft_ver = NULL,
2169
2170 /** We're using a dynamic kernel/rootfs split here */
2171 .partitions = {
2172 {"fs-uboot", 0x00000, 0x20000},
2173 {"firmware", 0x20000, 0x5e0000},
2174 {"partition-table", 0x600000, 0x02000},
2175 {"default-mac", 0x610000, 0x00020},
2176 {"pin", 0x610100, 0x00020},
2177 {"product-info", 0x611100, 0x01000},
2178 {"soft-version", 0x620000, 0x01000},
2179 {"support-list", 0x621000, 0x01000},
2180 {"profile", 0x622000, 0x08000},
2181 {"user-config", 0x630000, 0x10000},
2182 {"default-config", 0x640000, 0x10000},
2183 {"radio", 0x7f0000, 0x10000},
2184 {NULL, 0, 0}
2185 },
2186
2187 .first_sysupgrade_partition = "os-image",
2188 .last_sysupgrade_partition = "file-system"
2189 },
2190
2191 /** Firmware layout for the RE450 v2 */
2192 {
2193 .id = "RE450-V2",
2194 .vendor = "",
2195 .support_list =
2196 "SupportList:\r\n"
2197 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
2198 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
2199 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
2200 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
2201 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
2202 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
2203 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
2204 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
2205 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
2206 .part_trail = 0x00,
2207 .soft_ver = NULL,
2208
2209 /* We're using a dynamic kernel/rootfs split here */
2210 .partitions = {
2211 {"fs-uboot", 0x00000, 0x20000},
2212 {"firmware", 0x20000, 0x5e0000},
2213 {"partition-table", 0x600000, 0x02000},
2214 {"default-mac", 0x610000, 0x00020},
2215 {"pin", 0x610100, 0x00020},
2216 {"product-info", 0x611100, 0x01000},
2217 {"soft-version", 0x620000, 0x01000},
2218 {"support-list", 0x621000, 0x01000},
2219 {"profile", 0x622000, 0x08000},
2220 {"user-config", 0x630000, 0x10000},
2221 {"default-config", 0x640000, 0x10000},
2222 {"radio", 0x7f0000, 0x10000},
2223 {NULL, 0, 0}
2224 },
2225
2226 .first_sysupgrade_partition = "os-image",
2227 .last_sysupgrade_partition = "file-system"
2228 },
2229
2230 /** Firmware layout for the RE450 v3 */
2231 {
2232 .id = "RE450-V3",
2233 .vendor = "",
2234 .support_list =
2235 "SupportList:\r\n"
2236 "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
2237 "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
2238 "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
2239 "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
2240 "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
2241 "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
2242 "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
2243 "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
2244 "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
2245 .part_trail = 0x00,
2246 .soft_ver = NULL,
2247
2248 /* We're using a dynamic kernel/rootfs split here */
2249 .partitions = {
2250 {"fs-uboot", 0x00000, 0x20000},
2251 {"default-mac", 0x20000, 0x00020},
2252 {"pin", 0x20020, 0x00020},
2253 {"product-info", 0x21000, 0x01000},
2254 {"partition-table", 0x22000, 0x02000},
2255 {"soft-version", 0x24000, 0x01000},
2256 {"support-list", 0x25000, 0x01000},
2257 {"profile", 0x26000, 0x08000},
2258 {"user-config", 0x2e000, 0x10000},
2259 {"default-config", 0x3e000, 0x10000},
2260 {"config-info", 0x4e000, 0x00400},
2261 {"firmware", 0x50000, 0x7a0000},
2262 {"radio", 0x7f0000, 0x10000},
2263 {NULL, 0, 0}
2264 },
2265
2266 .first_sysupgrade_partition = "os-image",
2267 .last_sysupgrade_partition = "file-system"
2268 },
2269
2270 /** Firmware layout for the RE500 */
2271 {
2272 .id = "RE500-V1",
2273 .vendor = "",
2274 .support_list =
2275 "SupportList:\r\n"
2276 "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
2277 "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
2278 "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
2279 "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
2280 "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
2281 "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
2282 "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
2283 .part_trail = 0x00,
2284 .soft_ver = NULL,
2285
2286 /* We're using a dynamic kernel/rootfs split here */
2287 .partitions = {
2288 {"fs-uboot", 0x00000, 0x20000},
2289 {"firmware", 0x20000, 0xde0000},
2290 {"partition-table", 0xe00000, 0x02000},
2291 {"default-mac", 0xe10000, 0x00020},
2292 {"pin", 0xe10100, 0x00020},
2293 {"product-info", 0xe11100, 0x01000},
2294 {"soft-version", 0xe20000, 0x01000},
2295 {"support-list", 0xe21000, 0x01000},
2296 {"profile", 0xe22000, 0x08000},
2297 {"user-config", 0xe30000, 0x10000},
2298 {"default-config", 0xe40000, 0x10000},
2299 {"radio", 0xff0000, 0x10000},
2300 {NULL, 0, 0}
2301 },
2302
2303 .first_sysupgrade_partition = "os-image",
2304 .last_sysupgrade_partition = "file-system"
2305 },
2306
2307 /** Firmware layout for the RE650 */
2308 {
2309 .id = "RE650-V1",
2310 .vendor = "",
2311 .support_list =
2312 "SupportList:\r\n"
2313 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
2314 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
2315 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
2316 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
2317 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
2318 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
2319 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
2320 .part_trail = 0x00,
2321 .soft_ver = NULL,
2322
2323 /* We're using a dynamic kernel/rootfs split here */
2324 .partitions = {
2325 {"fs-uboot", 0x00000, 0x20000},
2326 {"firmware", 0x20000, 0xde0000},
2327 {"partition-table", 0xe00000, 0x02000},
2328 {"default-mac", 0xe10000, 0x00020},
2329 {"pin", 0xe10100, 0x00020},
2330 {"product-info", 0xe11100, 0x01000},
2331 {"soft-version", 0xe20000, 0x01000},
2332 {"support-list", 0xe21000, 0x01000},
2333 {"profile", 0xe22000, 0x08000},
2334 {"user-config", 0xe30000, 0x10000},
2335 {"default-config", 0xe40000, 0x10000},
2336 {"radio", 0xff0000, 0x10000},
2337 {NULL, 0, 0}
2338 },
2339
2340 .first_sysupgrade_partition = "os-image",
2341 .last_sysupgrade_partition = "file-system"
2342 },
2343
2344 {}
2345 };
2346
2347 #define error(_ret, _errno, _str, ...) \
2348 do { \
2349 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
2350 strerror(_errno)); \
2351 if (_ret) \
2352 exit(_ret); \
2353 } while (0)
2354
2355
2356 /** Stores a uint32 as big endian */
2357 static inline void put32(uint8_t *buf, uint32_t val) {
2358 buf[0] = val >> 24;
2359 buf[1] = val >> 16;
2360 buf[2] = val >> 8;
2361 buf[3] = val;
2362 }
2363
2364 static inline bool meta_partition_should_pad(enum partition_trail_value pv)
2365 {
2366 return (pv >= 0) && (pv <= PART_TRAIL_MAX);
2367 }
2368
2369 /** Allocate a padded meta partition with a correctly initialised header
2370 * If the `data` pointer is NULL, then the required space is only allocated,
2371 * otherwise `data_len` bytes will be copied from `data` into the partition
2372 * entry. */
2373 static struct image_partition_entry init_meta_partition_entry(
2374 const char *name, const void *data, uint32_t data_len,
2375 enum partition_trail_value pad_value)
2376 {
2377 uint32_t total_len = sizeof(struct meta_header) + data_len;
2378 if (meta_partition_should_pad(pad_value))
2379 total_len += 1;
2380
2381 struct image_partition_entry entry = {
2382 .name = name,
2383 .size = total_len,
2384 .data = malloc(total_len)
2385 };
2386 if (!entry.data)
2387 error(1, errno, "failed to allocate meta partition entry");
2388
2389 struct meta_header *header = (struct meta_header *)entry.data;
2390 header->length = htonl(data_len);
2391 header->zero = 0;
2392
2393 if (data)
2394 memcpy(entry.data+sizeof(*header), data, data_len);
2395
2396 if (meta_partition_should_pad(pad_value))
2397 entry.data[total_len - 1] = (uint8_t) pad_value;
2398
2399 return entry;
2400 }
2401
2402 /** Allocates a new image partition */
2403 static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
2404 struct image_partition_entry entry = {name, len, malloc(len)};
2405 if (!entry.data)
2406 error(1, errno, "malloc");
2407
2408 return entry;
2409 }
2410
2411 /** Frees an image partition */
2412 static void free_image_partition(struct image_partition_entry entry) {
2413 free(entry.data);
2414 }
2415
2416 static time_t source_date_epoch = -1;
2417 static void set_source_date_epoch() {
2418 char *env = getenv("SOURCE_DATE_EPOCH");
2419 char *endptr = env;
2420 errno = 0;
2421 if (env && *env) {
2422 source_date_epoch = strtoull(env, &endptr, 10);
2423 if (errno || (endptr && *endptr != '\0')) {
2424 fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
2425 exit(1);
2426 }
2427 }
2428 }
2429
2430 /** Generates the partition-table partition */
2431 static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
2432 struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
2433
2434 char *s = (char *)entry.data, *end = (char *)(s+entry.size);
2435
2436 *(s++) = 0x00;
2437 *(s++) = 0x04;
2438 *(s++) = 0x00;
2439 *(s++) = 0x00;
2440
2441 size_t i;
2442 for (i = 0; p[i].name; i++) {
2443 size_t len = end-s;
2444 size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n", p[i].name, p[i].base, p[i].size);
2445
2446 if (w > len-1)
2447 error(1, 0, "flash partition table overflow?");
2448
2449 s += w;
2450 }
2451
2452 s++;
2453
2454 memset(s, 0xff, end-s);
2455
2456 return entry;
2457 }
2458
2459
2460 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
2461 static inline uint8_t bcd(uint8_t v) {
2462 return 0x10 * (v/10) + v%10;
2463 }
2464
2465
2466 /** Generates the soft-version partition */
2467 static struct image_partition_entry make_soft_version(
2468 const struct device_info *info, uint32_t rev)
2469 {
2470 /** If an info string is provided, use this instead of
2471 * the structured data, and include the null-termination */
2472 if (info->soft_ver) {
2473 uint32_t len = strlen(info->soft_ver) + 1;
2474 return init_meta_partition_entry("soft-version",
2475 info->soft_ver, len, info->part_trail);
2476 }
2477
2478 time_t t;
2479
2480 if (source_date_epoch != -1)
2481 t = source_date_epoch;
2482 else if (time(&t) == (time_t)(-1))
2483 error(1, errno, "time");
2484
2485 struct tm *tm = gmtime(&t);
2486
2487 struct soft_version s = {
2488 .pad1 = 0xff,
2489
2490 .version_major = 0,
2491 .version_minor = 0,
2492 .version_patch = 0,
2493
2494 .year_hi = bcd((1900+tm->tm_year)/100),
2495 .year_lo = bcd(tm->tm_year%100),
2496 .month = bcd(tm->tm_mon+1),
2497 .day = bcd(tm->tm_mday),
2498
2499 .compat_level = htonl(info->soft_ver_compat_level)
2500 };
2501
2502 if (info->soft_ver_compat_level == 0)
2503 return init_meta_partition_entry("soft-version", &s,
2504 (uint8_t *)(&s.compat_level) - (uint8_t *)(&s),
2505 info->part_trail);
2506 else
2507 return init_meta_partition_entry("soft-version", &s,
2508 sizeof(s), info->part_trail);
2509 }
2510
2511 /** Generates the support-list partition */
2512 static struct image_partition_entry make_support_list(
2513 const struct device_info *info)
2514 {
2515 uint32_t len = strlen(info->support_list);
2516 return init_meta_partition_entry("support-list", info->support_list,
2517 len, info->part_trail);
2518 }
2519
2520 /** Partition with extra-para data */
2521 static struct image_partition_entry make_extra_para(
2522 const struct device_info *info, const uint8_t *extra_para, size_t len)
2523 {
2524 return init_meta_partition_entry("extra-para", extra_para, len,
2525 info->part_trail);
2526 }
2527
2528 /** Creates a new image partition with an arbitrary name from a file */
2529 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) {
2530 struct stat statbuf;
2531
2532 if (stat(filename, &statbuf) < 0)
2533 error(1, errno, "unable to stat file `%s'", filename);
2534
2535 size_t len = statbuf.st_size;
2536
2537 if (add_jffs2_eof) {
2538 if (file_system_partition)
2539 len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base;
2540 else
2541 len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
2542 }
2543
2544 struct image_partition_entry entry = alloc_image_partition(part_name, len);
2545
2546 FILE *file = fopen(filename, "rb");
2547 if (!file)
2548 error(1, errno, "unable to open file `%s'", filename);
2549
2550 if (fread(entry.data, statbuf.st_size, 1, file) != 1)
2551 error(1, errno, "unable to read file `%s'", filename);
2552
2553 if (add_jffs2_eof) {
2554 uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
2555
2556 memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
2557 memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
2558 }
2559
2560 fclose(file);
2561
2562 return entry;
2563 }
2564
2565 /**
2566 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
2567
2568 Example image partition table:
2569
2570 fwup-ptn partition-table base 0x00800 size 0x00800
2571 fwup-ptn os-image base 0x01000 size 0x113b45
2572 fwup-ptn file-system base 0x114b45 size 0x1d0004
2573 fwup-ptn support-list base 0x2e4b49 size 0x000d1
2574
2575 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
2576 the end of the partition table is marked with a zero byte.
2577
2578 The firmware image must contain at least the partition-table and support-list partitions
2579 to be accepted. There aren't any alignment constraints for the image partitions.
2580
2581 The partition-table partition contains the actual flash layout; partitions
2582 from the image partition table are mapped to the corresponding flash partitions during
2583 the firmware upgrade. The support-list partition contains a list of devices supported by
2584 the firmware image.
2585
2586 The base offsets in the firmware partition table are relative to the end
2587 of the vendor information block, so the partition-table partition will
2588 actually start at offset 0x1814 of the image.
2589
2590 I think partition-table must be the first partition in the firmware image.
2591 */
2592 static void put_partitions(uint8_t *buffer, const struct flash_partition_entry *flash_parts, const struct image_partition_entry *parts) {
2593 size_t i, j;
2594 char *image_pt = (char *)buffer, *end = image_pt + 0x800;
2595
2596 size_t base = 0x800;
2597 for (i = 0; parts[i].name; i++) {
2598 for (j = 0; flash_parts[j].name; j++) {
2599 if (!strcmp(flash_parts[j].name, parts[i].name)) {
2600 if (parts[i].size > flash_parts[j].size)
2601 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts[j].name, (unsigned)flash_parts[j].size);
2602 break;
2603 }
2604 }
2605
2606 assert(flash_parts[j].name);
2607
2608 memcpy(buffer + base, parts[i].data, parts[i].size);
2609
2610 size_t len = end-image_pt;
2611 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);
2612
2613 if (w > len-1)
2614 error(1, 0, "image partition table overflow?");
2615
2616 image_pt += w;
2617
2618 base += parts[i].size;
2619 }
2620 }
2621
2622 /** Generates and writes the image MD5 checksum */
2623 static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
2624 MD5_CTX ctx;
2625
2626 MD5_Init(&ctx);
2627 MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
2628 MD5_Update(&ctx, buffer, len);
2629 MD5_Final(md5, &ctx);
2630 }
2631
2632
2633 /**
2634 Generates the firmware image in factory format
2635
2636 Image format:
2637
2638 Bytes (hex) Usage
2639 ----------- -----
2640 0000-0003 Image size (4 bytes, big endian)
2641 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
2642 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
2643 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
2644 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
2645 1014-1813 Image partition table (2048 bytes, padded with 0xff)
2646 1814-xxxx Firmware partitions
2647 */
2648 static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) {
2649 *len = 0x1814;
2650
2651 size_t i;
2652 for (i = 0; parts[i].name; i++)
2653 *len += parts[i].size;
2654
2655 uint8_t *image = malloc(*len);
2656 if (!image)
2657 error(1, errno, "malloc");
2658
2659 memset(image, 0xff, *len);
2660 put32(image, *len);
2661
2662 if (info->vendor) {
2663 size_t vendor_len = strlen(info->vendor);
2664 put32(image+0x14, vendor_len);
2665 memcpy(image+0x18, info->vendor, vendor_len);
2666 }
2667
2668 put_partitions(image + 0x1014, info->partitions, parts);
2669 put_md5(image+0x04, image+0x14, *len-0x14);
2670
2671 return image;
2672 }
2673
2674 /**
2675 Generates the firmware image in sysupgrade format
2676
2677 This makes some assumptions about the provided flash and image partition tables and
2678 should be generalized when TP-LINK starts building its safeloader into hardware with
2679 different flash layouts.
2680 */
2681 static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) {
2682 size_t i, j;
2683 size_t flash_first_partition_index = 0;
2684 size_t flash_last_partition_index = 0;
2685 const struct flash_partition_entry *flash_first_partition = NULL;
2686 const struct flash_partition_entry *flash_last_partition = NULL;
2687 const struct image_partition_entry *image_last_partition = NULL;
2688
2689 /** Find first and last partitions */
2690 for (i = 0; info->partitions[i].name; i++) {
2691 if (!strcmp(info->partitions[i].name, info->first_sysupgrade_partition)) {
2692 flash_first_partition = &info->partitions[i];
2693 flash_first_partition_index = i;
2694 } else if (!strcmp(info->partitions[i].name, info->last_sysupgrade_partition)) {
2695 flash_last_partition = &info->partitions[i];
2696 flash_last_partition_index = i;
2697 }
2698 }
2699
2700 assert(flash_first_partition && flash_last_partition);
2701 assert(flash_first_partition_index < flash_last_partition_index);
2702
2703 /** Find last partition from image to calculate needed size */
2704 for (i = 0; image_parts[i].name; i++) {
2705 if (!strcmp(image_parts[i].name, info->last_sysupgrade_partition)) {
2706 image_last_partition = &image_parts[i];
2707 break;
2708 }
2709 }
2710
2711 assert(image_last_partition);
2712
2713 *len = flash_last_partition->base - flash_first_partition->base + image_last_partition->size;
2714
2715 uint8_t *image = malloc(*len);
2716 if (!image)
2717 error(1, errno, "malloc");
2718
2719 memset(image, 0xff, *len);
2720
2721 for (i = flash_first_partition_index; i <= flash_last_partition_index; i++) {
2722 for (j = 0; image_parts[j].name; j++) {
2723 if (!strcmp(info->partitions[i].name, image_parts[j].name)) {
2724 if (image_parts[j].size > info->partitions[i].size)
2725 error(1, 0, "%s partition too big (more than %u bytes)", info->partitions[i].name, (unsigned)info->partitions[i].size);
2726 memcpy(image + info->partitions[i].base - flash_first_partition->base, image_parts[j].data, image_parts[j].size);
2727 break;
2728 }
2729
2730 assert(image_parts[j].name);
2731 }
2732 }
2733
2734 return image;
2735 }
2736
2737 /** Generates an image according to a given layout and writes it to a file */
2738 static void build_image(const char *output,
2739 const char *kernel_image,
2740 const char *rootfs_image,
2741 uint32_t rev,
2742 bool add_jffs2_eof,
2743 bool sysupgrade,
2744 struct device_info *info) {
2745
2746 size_t i;
2747
2748 struct image_partition_entry parts[7] = {};
2749
2750 struct flash_partition_entry *firmware_partition = NULL;
2751 struct flash_partition_entry *os_image_partition = NULL;
2752 struct flash_partition_entry *file_system_partition = NULL;
2753 size_t firmware_partition_index = 0;
2754
2755 for (i = 0; info->partitions[i].name; i++) {
2756 if (!strcmp(info->partitions[i].name, "firmware"))
2757 {
2758 firmware_partition = &info->partitions[i];
2759 firmware_partition_index = i;
2760 }
2761 }
2762
2763 if (firmware_partition)
2764 {
2765 os_image_partition = &info->partitions[firmware_partition_index];
2766 file_system_partition = &info->partitions[firmware_partition_index + 1];
2767
2768 struct stat kernel;
2769 if (stat(kernel_image, &kernel) < 0)
2770 error(1, errno, "unable to stat file `%s'", kernel_image);
2771
2772 if (kernel.st_size > firmware_partition->size)
2773 error(1, 0, "kernel overflowed firmware partition\n");
2774
2775 for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--)
2776 info->partitions[i+1] = info->partitions[i];
2777
2778 file_system_partition->name = "file-system";
2779 file_system_partition->base = firmware_partition->base + kernel.st_size;
2780
2781 /* Align partition start to erase blocks for factory images only */
2782 if (!sysupgrade)
2783 file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000);
2784
2785 file_system_partition->size = firmware_partition->size - file_system_partition->base;
2786
2787 os_image_partition->name = "os-image";
2788 os_image_partition->size = kernel.st_size;
2789 }
2790
2791 parts[0] = make_partition_table(info->partitions);
2792 parts[1] = make_soft_version(info, rev);
2793 parts[2] = make_support_list(info);
2794 parts[3] = read_file("os-image", kernel_image, false, NULL);
2795 parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition);
2796
2797 /* Some devices need the extra-para partition to accept the firmware */
2798 if (strcasecmp(info->id, "ARCHER-A7-V5") == 0 ||
2799 strcasecmp(info->id, "ARCHER-C2-V3") == 0 ||
2800 strcasecmp(info->id, "ARCHER-C7-V4") == 0 ||
2801 strcasecmp(info->id, "ARCHER-C7-V5") == 0 ||
2802 strcasecmp(info->id, "ARCHER-C25-V1") == 0 ||
2803 strcasecmp(info->id, "ARCHER-C59-V2") == 0 ||
2804 strcasecmp(info->id, "ARCHER-C60-V2") == 0 ||
2805 strcasecmp(info->id, "ARCHER-C60-V3") == 0 ||
2806 strcasecmp(info->id, "TLWR1043NV5") == 0) {
2807 const uint8_t extra_para[2] = {0x01, 0x00};
2808 parts[5] = make_extra_para(info, extra_para,
2809 sizeof(extra_para));
2810 } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0) {
2811 const uint8_t extra_para[2] = {0x00, 0x01};
2812 parts[5] = make_extra_para(info, extra_para,
2813 sizeof(extra_para));
2814 } else if (strcasecmp(info->id, "ARCHER-C6-V2-US") == 0 ||
2815 strcasecmp(info->id, "EAP245-V3") == 0) {
2816 const uint8_t extra_para[2] = {0x01, 0x01};
2817 parts[5] = make_extra_para(info, extra_para,
2818 sizeof(extra_para));
2819 }
2820
2821 size_t len;
2822 void *image;
2823 if (sysupgrade)
2824 image = generate_sysupgrade_image(info, parts, &len);
2825 else
2826 image = generate_factory_image(info, parts, &len);
2827
2828 FILE *file = fopen(output, "wb");
2829 if (!file)
2830 error(1, errno, "unable to open output file");
2831
2832 if (fwrite(image, len, 1, file) != 1)
2833 error(1, 0, "unable to write output file");
2834
2835 fclose(file);
2836
2837 free(image);
2838
2839 for (i = 0; parts[i].name; i++)
2840 free_image_partition(parts[i]);
2841 }
2842
2843 /** Usage output */
2844 static void usage(const char *argv0) {
2845 fprintf(stderr,
2846 "Usage: %s [OPTIONS...]\n"
2847 "\n"
2848 "Options:\n"
2849 " -h show this help\n"
2850 "\n"
2851 "Create a new image:\n"
2852 " -B <board> create image for the board specified with <board>\n"
2853 " -k <file> read kernel image from the file <file>\n"
2854 " -r <file> read rootfs image from the file <file>\n"
2855 " -o <file> write output to the file <file>\n"
2856 " -V <rev> sets the revision number to <rev>\n"
2857 " -j add jffs2 end-of-filesystem markers\n"
2858 " -S create sysupgrade instead of factory image\n"
2859 "Extract an old image:\n"
2860 " -x <file> extract all oem firmware partition\n"
2861 " -d <dir> destination to extract the firmware partition\n"
2862 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
2863 argv0
2864 );
2865 };
2866
2867
2868 static struct device_info *find_board(const char *id)
2869 {
2870 struct device_info *board = NULL;
2871
2872 for (board = boards; board->id != NULL; board++)
2873 if (strcasecmp(id, board->id) == 0)
2874 return board;
2875
2876 return NULL;
2877 }
2878
2879 static int add_flash_partition(
2880 struct flash_partition_entry *part_list,
2881 size_t max_entries,
2882 const char *name,
2883 unsigned long base,
2884 unsigned long size)
2885 {
2886 size_t ptr;
2887 /* check if the list has a free entry */
2888 for (ptr = 0; ptr < max_entries; ptr++, part_list++) {
2889 if (part_list->name == NULL &&
2890 part_list->base == 0 &&
2891 part_list->size == 0)
2892 break;
2893 }
2894
2895 if (ptr == max_entries) {
2896 error(1, 0, "No free flash part entry available.");
2897 }
2898
2899 part_list->name = calloc(1, strlen(name) + 1);
2900 if (!part_list->name) {
2901 error(1, 0, "Unable to allocate memory");
2902 }
2903
2904 memcpy((char *)part_list->name, name, strlen(name));
2905 part_list->base = base;
2906 part_list->size = size;
2907
2908 return 0;
2909 }
2910
2911 /** read the partition table into struct flash_partition_entry */
2912 static int read_partition_table(
2913 FILE *file, long offset,
2914 struct flash_partition_entry *entries, size_t max_entries,
2915 int type)
2916 {
2917 char buf[2048];
2918 char *ptr, *end;
2919 const char *parthdr = NULL;
2920 const char *fwuphdr = "fwup-ptn";
2921 const char *flashhdr = "partition";
2922
2923 /* TODO: search for the partition table */
2924
2925 switch(type) {
2926 case 0:
2927 parthdr = fwuphdr;
2928 break;
2929 case 1:
2930 parthdr = flashhdr;
2931 break;
2932 default:
2933 error(1, 0, "Invalid partition table");
2934 }
2935
2936 if (fseek(file, offset, SEEK_SET) < 0)
2937 error(1, errno, "Can not seek in the firmware");
2938
2939 if (fread(buf, 2048, 1, file) != 1)
2940 error(1, errno, "Can not read fwup-ptn from the firmware");
2941
2942 buf[2047] = '\0';
2943
2944 /* look for the partition header */
2945 if (memcmp(buf, parthdr, strlen(parthdr)) != 0) {
2946 fprintf(stderr, "DEBUG: can not find fwuphdr\n");
2947 return 1;
2948 }
2949
2950 ptr = buf;
2951 end = buf + sizeof(buf);
2952 while ((ptr + strlen(parthdr)) < end &&
2953 memcmp(ptr, parthdr, strlen(parthdr)) == 0) {
2954 char *end_part;
2955 char *end_element;
2956
2957 char name[32] = { 0 };
2958 int name_len = 0;
2959 unsigned long base = 0;
2960 unsigned long size = 0;
2961
2962 end_part = memchr(ptr, '\n', (end - ptr));
2963 if (end_part == NULL) {
2964 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
2965 break;
2966 }
2967
2968 for (int i = 0; i <= 4; i++) {
2969 if (end_part <= ptr)
2970 break;
2971
2972 end_element = memchr(ptr, 0x20, (end_part - ptr));
2973 if (end_element == NULL) {
2974 error(1, errno, "Ignoring the rest of the partition entries.");
2975 break;
2976 }
2977
2978 switch (i) {
2979 /* partition header */
2980 case 0:
2981 ptr = end_element + 1;
2982 continue;
2983 /* name */
2984 case 1:
2985 name_len = (end_element - ptr) > 31 ? 31 : (end_element - ptr);
2986 strncpy(name, ptr, name_len);
2987 name[name_len] = '\0';
2988 ptr = end_element + 1;
2989 continue;
2990
2991 /* string "base" */
2992 case 2:
2993 ptr = end_element + 1;
2994 continue;
2995
2996 /* actual base */
2997 case 3:
2998 base = strtoul(ptr, NULL, 16);
2999 ptr = end_element + 1;
3000 continue;
3001
3002 /* string "size" */
3003 case 4:
3004 ptr = end_element + 1;
3005 /* actual size. The last element doesn't have a sepeartor */
3006 size = strtoul(ptr, NULL, 16);
3007 /* the part ends with 0x09, 0x0d, 0x0a */
3008 ptr = end_part + 1;
3009 add_flash_partition(entries, max_entries, name, base, size);
3010 continue;
3011 }
3012 }
3013 }
3014
3015 return 0;
3016 }
3017
3018 static void write_partition(
3019 FILE *input_file,
3020 size_t firmware_offset,
3021 struct flash_partition_entry *entry,
3022 FILE *output_file)
3023 {
3024 char buf[4096];
3025 size_t offset;
3026
3027 fseek(input_file, entry->base + firmware_offset, SEEK_SET);
3028
3029 for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) {
3030 if (fread(buf, sizeof(buf), 1, input_file) != 1)
3031 error(1, errno, "Can not read partition from input_file");
3032
3033 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3034 error(1, errno, "Can not write partition to output_file");
3035 }
3036 /* write last chunk smaller than buffer */
3037 if (offset < entry->size) {
3038 offset = entry->size - offset;
3039 if (fread(buf, offset, 1, input_file) != 1)
3040 error(1, errno, "Can not read partition from input_file");
3041 if (fwrite(buf, offset, 1, output_file) != 1)
3042 error(1, errno, "Can not write partition to output_file");
3043 }
3044 }
3045
3046 static int extract_firmware_partition(FILE *input_file, size_t firmware_offset, struct flash_partition_entry *entry, const char *output_directory)
3047 {
3048 FILE *output_file;
3049 char output[PATH_MAX];
3050
3051 snprintf(output, PATH_MAX, "%s/%s", output_directory, entry->name);
3052 output_file = fopen(output, "wb+");
3053 if (output_file == NULL) {
3054 error(1, errno, "Can not open output file %s", output);
3055 }
3056
3057 write_partition(input_file, firmware_offset, entry, output_file);
3058
3059 fclose(output_file);
3060
3061 return 0;
3062 }
3063
3064 /** extract all partitions from the firmware file */
3065 static int extract_firmware(const char *input, const char *output_directory)
3066 {
3067 struct flash_partition_entry entries[16] = { 0 };
3068 size_t max_entries = 16;
3069 size_t firmware_offset = 0x1014;
3070 FILE *input_file;
3071
3072 struct stat statbuf;
3073
3074 /* check input file */
3075 if (stat(input, &statbuf)) {
3076 error(1, errno, "Can not read input firmware %s", input);
3077 }
3078
3079 /* check if output directory exists */
3080 if (stat(output_directory, &statbuf)) {
3081 error(1, errno, "Failed to stat output directory %s", output_directory);
3082 }
3083
3084 if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
3085 error(1, errno, "Given output directory is not a directory %s", output_directory);
3086 }
3087
3088 input_file = fopen(input, "rb");
3089
3090 if (read_partition_table(input_file, firmware_offset, entries, 16, 0) != 0) {
3091 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3092 }
3093
3094 for (size_t i = 0; i < max_entries; i++) {
3095 if (entries[i].name == NULL &&
3096 entries[i].base == 0 &&
3097 entries[i].size == 0)
3098 continue;
3099
3100 extract_firmware_partition(input_file, firmware_offset, &entries[i], output_directory);
3101 }
3102
3103 return 0;
3104 }
3105
3106 static struct flash_partition_entry *find_partition(
3107 struct flash_partition_entry *entries, size_t max_entries,
3108 const char *name, const char *error_msg)
3109 {
3110 for (size_t i = 0; i < max_entries; i++, entries++) {
3111 if (strcmp(entries->name, name) == 0)
3112 return entries;
3113 }
3114
3115 error(1, 0, "%s", error_msg);
3116 return NULL;
3117 }
3118
3119 static void write_ff(FILE *output_file, size_t size)
3120 {
3121 char buf[4096];
3122 size_t offset;
3123
3124 memset(buf, 0xff, sizeof(buf));
3125
3126 for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) {
3127 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3128 error(1, errno, "Can not write 0xff to output_file");
3129 }
3130
3131 /* write last chunk smaller than buffer */
3132 if (offset < size) {
3133 offset = size - offset;
3134 if (fwrite(buf, offset, 1, output_file) != 1)
3135 error(1, errno, "Can not write partition to output_file");
3136 }
3137 }
3138
3139 static void convert_firmware(const char *input, const char *output)
3140 {
3141 struct flash_partition_entry fwup[MAX_PARTITIONS] = { 0 };
3142 struct flash_partition_entry flash[MAX_PARTITIONS] = { 0 };
3143 struct flash_partition_entry *fwup_os_image = NULL, *fwup_file_system = NULL;
3144 struct flash_partition_entry *flash_os_image = NULL, *flash_file_system = NULL;
3145 struct flash_partition_entry *fwup_partition_table = NULL;
3146 size_t firmware_offset = 0x1014;
3147 FILE *input_file, *output_file;
3148
3149 struct stat statbuf;
3150
3151 /* check input file */
3152 if (stat(input, &statbuf)) {
3153 error(1, errno, "Can not read input firmware %s", input);
3154 }
3155
3156 input_file = fopen(input, "rb");
3157 if (!input_file)
3158 error(1, 0, "Can not open input firmware %s", input);
3159
3160 output_file = fopen(output, "wb");
3161 if (!output_file)
3162 error(1, 0, "Can not open output firmware %s", output);
3163
3164 if (read_partition_table(input_file, firmware_offset, fwup, MAX_PARTITIONS, 0) != 0) {
3165 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3166 }
3167
3168 fwup_os_image = find_partition(fwup, MAX_PARTITIONS,
3169 "os-image", "Error can not find os-image partition (fwup)");
3170 fwup_file_system = find_partition(fwup, MAX_PARTITIONS,
3171 "file-system", "Error can not find file-system partition (fwup)");
3172 fwup_partition_table = find_partition(fwup, MAX_PARTITIONS,
3173 "partition-table", "Error can not find partition-table partition");
3174
3175 /* the flash partition table has a 0x00000004 magic haeder */
3176 if (read_partition_table(input_file, firmware_offset + fwup_partition_table->base + 4, flash, MAX_PARTITIONS, 1) != 0)
3177 error(1, 0, "Error can not read the partition table (flash)");
3178
3179 flash_os_image = find_partition(flash, MAX_PARTITIONS,
3180 "os-image", "Error can not find os-image partition (flash)");
3181 flash_file_system = find_partition(flash, MAX_PARTITIONS,
3182 "file-system", "Error can not find file-system partition (flash)");
3183
3184 /* write os_image to 0x0 */
3185 write_partition(input_file, firmware_offset, fwup_os_image, output_file);
3186 write_ff(output_file, flash_os_image->size - fwup_os_image->size);
3187
3188 /* write file-system behind os_image */
3189 fseek(output_file, flash_file_system->base - flash_os_image->base, SEEK_SET);
3190 write_partition(input_file, firmware_offset, fwup_file_system, output_file);
3191 write_ff(output_file, flash_file_system->size - fwup_file_system->size);
3192
3193 fclose(output_file);
3194 fclose(input_file);
3195 }
3196
3197 int main(int argc, char *argv[]) {
3198 const char *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
3199 const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL;
3200 bool add_jffs2_eof = false, sysupgrade = false;
3201 unsigned rev = 0;
3202 struct device_info *info;
3203 set_source_date_epoch();
3204
3205 while (true) {
3206 int c;
3207
3208 c = getopt(argc, argv, "B:k:r:o:V:jSh:x:d:z:");
3209 if (c == -1)
3210 break;
3211
3212 switch (c) {
3213 case 'B':
3214 board = optarg;
3215 break;
3216
3217 case 'k':
3218 kernel_image = optarg;
3219 break;
3220
3221 case 'r':
3222 rootfs_image = optarg;
3223 break;
3224
3225 case 'o':
3226 output = optarg;
3227 break;
3228
3229 case 'V':
3230 sscanf(optarg, "r%u", &rev);
3231 break;
3232
3233 case 'j':
3234 add_jffs2_eof = true;
3235 break;
3236
3237 case 'S':
3238 sysupgrade = true;
3239 break;
3240
3241 case 'h':
3242 usage(argv[0]);
3243 return 0;
3244
3245 case 'd':
3246 output_directory = optarg;
3247 break;
3248
3249 case 'x':
3250 extract_image = optarg;
3251 break;
3252
3253 case 'z':
3254 convert_image = optarg;
3255 break;
3256
3257 default:
3258 usage(argv[0]);
3259 return 1;
3260 }
3261 }
3262
3263 if (extract_image || output_directory) {
3264 if (!extract_image)
3265 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
3266 if (!output_directory)
3267 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
3268 extract_firmware(extract_image, output_directory);
3269 } else if (convert_image) {
3270 if (!output)
3271 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
3272 convert_firmware(convert_image, output);
3273 } else {
3274 if (!board)
3275 error(1, 0, "no board has been specified");
3276 if (!kernel_image)
3277 error(1, 0, "no kernel image has been specified");
3278 if (!rootfs_image)
3279 error(1, 0, "no rootfs image has been specified");
3280 if (!output)
3281 error(1, 0, "no output filename has been specified");
3282
3283 info = find_board(board);
3284
3285 if (info == NULL)
3286 error(1, 0, "unsupported board %s", board);
3287
3288 build_image(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, info);
3289 }
3290
3291 return 0;
3292 }