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