firmware-utils: tplink-safeloader: replace BSD-2-Clause boilerplate with SPDX
[project/firmware-utils.git] / 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-WA850RE v2 */
1623 {
1624 .id = "TLWA850REV2",
1625 .vendor = "",
1626 .support_list =
1627 "SupportList:\n"
1628 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1629 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1630 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1631 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1632 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1633 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1634 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1635 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1636 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1637 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1638 .part_trail = 0x00,
1639 .soft_ver = NULL,
1640
1641 /**
1642 576KB were moved from file-system to os-image
1643 in comparison to the stock image
1644 */
1645 .partitions = {
1646 {"fs-uboot", 0x00000, 0x20000},
1647 {"firmware", 0x20000, 0x390000},
1648 {"partition-table", 0x3b0000, 0x02000},
1649 {"default-mac", 0x3c0000, 0x00020},
1650 {"pin", 0x3c0100, 0x00020},
1651 {"product-info", 0x3c1000, 0x01000},
1652 {"soft-version", 0x3c2000, 0x00100},
1653 {"support-list", 0x3c3000, 0x01000},
1654 {"profile", 0x3c4000, 0x08000},
1655 {"user-config", 0x3d0000, 0x10000},
1656 {"default-config", 0x3e0000, 0x10000},
1657 {"radio", 0x3f0000, 0x10000},
1658 {NULL, 0, 0}
1659 },
1660
1661 .first_sysupgrade_partition = "os-image",
1662 .last_sysupgrade_partition = "file-system"
1663 },
1664
1665 /** Firmware layout for the TL-WA855RE v1 */
1666 {
1667 .id = "TLWA855REV1",
1668 .vendor = "",
1669 .support_list =
1670 "SupportList:\n"
1671 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1672 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1673 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1674 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1675 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1676 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1677 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1678 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1679 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1680 .part_trail = 0x00,
1681 .soft_ver = NULL,
1682
1683 .partitions = {
1684 {"fs-uboot", 0x00000, 0x20000},
1685 {"os-image", 0x20000, 0x150000},
1686 {"file-system", 0x170000, 0x240000},
1687 {"partition-table", 0x3b0000, 0x02000},
1688 {"default-mac", 0x3c0000, 0x00020},
1689 {"pin", 0x3c0100, 0x00020},
1690 {"product-info", 0x3c1000, 0x01000},
1691 {"soft-version", 0x3c2000, 0x00100},
1692 {"support-list", 0x3c3000, 0x01000},
1693 {"profile", 0x3c4000, 0x08000},
1694 {"user-config", 0x3d0000, 0x10000},
1695 {"default-config", 0x3e0000, 0x10000},
1696 {"radio", 0x3f0000, 0x10000},
1697 {NULL, 0, 0}
1698 },
1699
1700 .first_sysupgrade_partition = "os-image",
1701 .last_sysupgrade_partition = "file-system"
1702 },
1703
1704 /** Firmware layout for the TL-WPA8630P v2 (EU)*/
1705 {
1706 .id = "TL-WPA8630P-V2.0-EU",
1707 .vendor = "",
1708 .support_list =
1709 "SupportList:\n"
1710 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
1711 .part_trail = 0x00,
1712 .soft_ver = NULL,
1713
1714 .partitions = {
1715 {"factory-uboot", 0x00000, 0x20000},
1716 {"fs-uboot", 0x20000, 0x20000},
1717 {"firmware", 0x40000, 0x5e0000},
1718 {"partition-table", 0x620000, 0x02000},
1719 {"default-mac", 0x630000, 0x00020},
1720 {"pin", 0x630100, 0x00020},
1721 {"device-id", 0x630200, 0x00030},
1722 {"product-info", 0x631100, 0x01000},
1723 {"extra-para", 0x632100, 0x01000},
1724 {"soft-version", 0x640000, 0x01000},
1725 {"support-list", 0x641000, 0x01000},
1726 {"profile", 0x642000, 0x08000},
1727 {"user-config", 0x650000, 0x10000},
1728 {"default-config", 0x660000, 0x10000},
1729 {"default-nvm", 0x670000, 0xc0000},
1730 {"default-pib", 0x730000, 0x40000},
1731 {"radio", 0x7f0000, 0x10000},
1732 {NULL, 0, 0}
1733 },
1734
1735 .first_sysupgrade_partition = "os-image",
1736 .last_sysupgrade_partition = "file-system"
1737 },
1738
1739 /** Firmware layout for the TL-WPA8630P v2 (INT)*/
1740 {
1741 .id = "TL-WPA8630P-V2-INT",
1742 .vendor = "",
1743 .support_list =
1744 "SupportList:\n"
1745 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
1746 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
1747 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
1748 .part_trail = 0x00,
1749 .soft_ver = NULL,
1750
1751 .partitions = {
1752 {"factory-uboot", 0x00000, 0x20000},
1753 {"fs-uboot", 0x20000, 0x20000},
1754 {"firmware", 0x40000, 0x5e0000},
1755 {"partition-table", 0x620000, 0x02000},
1756 {"extra-para", 0x632100, 0x01000},
1757 {"soft-version", 0x640000, 0x01000},
1758 {"support-list", 0x641000, 0x01000},
1759 {"profile", 0x642000, 0x08000},
1760 {"user-config", 0x650000, 0x10000},
1761 {"default-config", 0x660000, 0x10000},
1762 {"default-nvm", 0x670000, 0xc0000},
1763 {"default-pib", 0x730000, 0x40000},
1764 {"default-mac", 0x7e0000, 0x00020},
1765 {"pin", 0x7e0100, 0x00020},
1766 {"device-id", 0x7e0200, 0x00030},
1767 {"product-info", 0x7e1100, 0x01000},
1768 {"radio", 0x7f0000, 0x10000},
1769 {NULL, 0, 0}
1770 },
1771
1772 .first_sysupgrade_partition = "os-image",
1773 .last_sysupgrade_partition = "file-system"
1774 },
1775
1776 /** Firmware layout for the TL-WPA8630P v2.1 (EU)*/
1777 {
1778 .id = "TL-WPA8630P-V2.1-EU",
1779 .vendor = "",
1780 .support_list =
1781 "SupportList:\n"
1782 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n",
1783 .part_trail = 0x00,
1784 .soft_ver = NULL,
1785
1786 .partitions = {
1787 {"factory-uboot", 0x00000, 0x20000},
1788 {"fs-uboot", 0x20000, 0x20000},
1789 {"firmware", 0x40000, 0x5e0000},
1790 {"extra-para", 0x680000, 0x01000},
1791 {"product-info", 0x690000, 0x01000},
1792 {"partition-table", 0x6a0000, 0x02000},
1793 {"soft-version", 0x6b0000, 0x01000},
1794 {"support-list", 0x6b1000, 0x01000},
1795 {"profile", 0x6b2000, 0x08000},
1796 {"user-config", 0x6c0000, 0x10000},
1797 {"default-config", 0x6d0000, 0x10000},
1798 {"default-nvm", 0x6e0000, 0xc0000},
1799 {"default-pib", 0x7a0000, 0x40000},
1800 {"default-mac", 0x7e0000, 0x00020},
1801 {"pin", 0x7e0100, 0x00020},
1802 {"device-id", 0x7e0200, 0x00030},
1803 {"radio", 0x7f0000, 0x10000},
1804 {NULL, 0, 0}
1805 },
1806
1807 .first_sysupgrade_partition = "os-image",
1808 .last_sysupgrade_partition = "file-system"
1809 },
1810
1811 /** Firmware layout for the TL-WR1043 v5 */
1812 {
1813 .id = "TLWR1043NV5",
1814 .vendor = "",
1815 .support_list =
1816 "SupportList:\n"
1817 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1818 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1819 .part_trail = 0x00,
1820 .soft_ver = "soft_ver:1.0.0\n",
1821 .partitions = {
1822 {"factory-boot", 0x00000, 0x20000},
1823 {"fs-uboot", 0x20000, 0x20000},
1824 {"firmware", 0x40000, 0xec0000},
1825 {"default-mac", 0xf00000, 0x00200},
1826 {"pin", 0xf00200, 0x00200},
1827 {"device-id", 0xf00400, 0x00100},
1828 {"product-info", 0xf00500, 0x0fb00},
1829 {"soft-version", 0xf10000, 0x01000},
1830 {"extra-para", 0xf11000, 0x01000},
1831 {"support-list", 0xf12000, 0x0a000},
1832 {"profile", 0xf1c000, 0x04000},
1833 {"default-config", 0xf20000, 0x10000},
1834 {"user-config", 0xf30000, 0x40000},
1835 {"qos-db", 0xf70000, 0x40000},
1836 {"certificate", 0xfb0000, 0x10000},
1837 {"partition-table", 0xfc0000, 0x10000},
1838 {"log", 0xfd0000, 0x20000},
1839 {"radio", 0xff0000, 0x10000},
1840 {NULL, 0, 0}
1841 },
1842 .first_sysupgrade_partition = "os-image",
1843 .last_sysupgrade_partition = "file-system"
1844 },
1845
1846 /** Firmware layout for the TL-WR1043 v4 */
1847 {
1848 .id = "TLWR1043NDV4",
1849 .vendor = "",
1850 .support_list =
1851 "SupportList:\n"
1852 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1853 .part_trail = 0x00,
1854 .soft_ver = NULL,
1855
1856 /* We're using a dynamic kernel/rootfs split here */
1857 .partitions = {
1858 {"fs-uboot", 0x00000, 0x20000},
1859 {"firmware", 0x20000, 0xf30000},
1860 {"default-mac", 0xf50000, 0x00200},
1861 {"pin", 0xf50200, 0x00200},
1862 {"product-info", 0xf50400, 0x0fc00},
1863 {"soft-version", 0xf60000, 0x0b000},
1864 {"support-list", 0xf6b000, 0x04000},
1865 {"profile", 0xf70000, 0x04000},
1866 {"default-config", 0xf74000, 0x0b000},
1867 {"user-config", 0xf80000, 0x40000},
1868 {"partition-table", 0xfc0000, 0x10000},
1869 {"log", 0xfd0000, 0x20000},
1870 {"radio", 0xff0000, 0x10000},
1871 {NULL, 0, 0}
1872 },
1873
1874 .first_sysupgrade_partition = "os-image",
1875 .last_sysupgrade_partition = "file-system"
1876 },
1877
1878 /** Firmware layout for the TL-WR902AC v1 */
1879 {
1880 .id = "TL-WR902AC-V1",
1881 .vendor = "",
1882 .support_list =
1883 "SupportList:\n"
1884 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1885 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1886 .part_trail = 0x00,
1887 .soft_ver = NULL,
1888
1889 /**
1890 384KB were moved from file-system to os-image
1891 in comparison to the stock image
1892 */
1893 .partitions = {
1894 {"fs-uboot", 0x00000, 0x20000},
1895 {"firmware", 0x20000, 0x730000},
1896 {"default-mac", 0x750000, 0x00200},
1897 {"pin", 0x750200, 0x00200},
1898 {"product-info", 0x750400, 0x0fc00},
1899 {"soft-version", 0x760000, 0x0b000},
1900 {"support-list", 0x76b000, 0x04000},
1901 {"profile", 0x770000, 0x04000},
1902 {"default-config", 0x774000, 0x0b000},
1903 {"user-config", 0x780000, 0x40000},
1904 {"partition-table", 0x7c0000, 0x10000},
1905 {"log", 0x7d0000, 0x20000},
1906 {"radio", 0x7f0000, 0x10000},
1907 {NULL, 0, 0}
1908 },
1909
1910 .first_sysupgrade_partition = "os-image",
1911 .last_sysupgrade_partition = "file-system",
1912 },
1913
1914 /** Firmware layout for the TL-WR941HP v1 */
1915 {
1916 .id = "TL-WR941HP-V1",
1917 .vendor = "",
1918 .support_list =
1919 "SupportList:\n"
1920 "{product_name:TL-WR941HP,product_ver:1.0.0,special_id:00000000}\n",
1921 .part_trail = 0x00,
1922 .soft_ver = NULL,
1923
1924 .partitions = {
1925 {"fs-uboot", 0x00000, 0x20000},
1926 {"firmware", 0x20000, 0x730000},
1927 {"default-mac", 0x750000, 0x00200},
1928 {"pin", 0x750200, 0x00200},
1929 {"product-info", 0x750400, 0x0fc00},
1930 {"soft-version", 0x760000, 0x0b000},
1931 {"support-list", 0x76b000, 0x04000},
1932 {"profile", 0x770000, 0x04000},
1933 {"default-config", 0x774000, 0x0b000},
1934 {"user-config", 0x780000, 0x40000},
1935 {"partition-table", 0x7c0000, 0x10000},
1936 {"log", 0x7d0000, 0x20000},
1937 {"radio", 0x7f0000, 0x10000},
1938 {NULL, 0, 0}
1939 },
1940
1941 .first_sysupgrade_partition = "os-image",
1942 .last_sysupgrade_partition = "file-system",
1943 },
1944
1945 /** Firmware layout for the TL-WR942N V1 */
1946 {
1947 .id = "TLWR942NV1",
1948 .vendor = "",
1949 .support_list =
1950 "SupportList:\r\n"
1951 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1952 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1953 .part_trail = 0x00,
1954 .soft_ver = NULL,
1955
1956 .partitions = {
1957 {"fs-uboot", 0x00000, 0x20000},
1958 {"firmware", 0x20000, 0xe20000},
1959 {"default-mac", 0xe40000, 0x00200},
1960 {"pin", 0xe40200, 0x00200},
1961 {"product-info", 0xe40400, 0x0fc00},
1962 {"partition-table", 0xe50000, 0x10000},
1963 {"soft-version", 0xe60000, 0x10000},
1964 {"support-list", 0xe70000, 0x10000},
1965 {"profile", 0xe80000, 0x10000},
1966 {"default-config", 0xe90000, 0x10000},
1967 {"user-config", 0xea0000, 0x40000},
1968 {"qos-db", 0xee0000, 0x40000},
1969 {"certificate", 0xf20000, 0x10000},
1970 {"usb-config", 0xfb0000, 0x10000},
1971 {"log", 0xfc0000, 0x20000},
1972 {"radio-bk", 0xfe0000, 0x10000},
1973 {"radio", 0xff0000, 0x10000},
1974 {NULL, 0, 0}
1975 },
1976
1977 .first_sysupgrade_partition = "os-image",
1978 .last_sysupgrade_partition = "file-system",
1979 },
1980
1981 /** Firmware layout for the RE200 v2 */
1982 {
1983 .id = "RE200-V2",
1984 .vendor = "",
1985 .support_list =
1986 "SupportList:\n"
1987 "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
1988 "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
1989 "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
1990 "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
1991 "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
1992 "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
1993 "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
1994 "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
1995 "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
1996 "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
1997 "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
1998 "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
1999 "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
2000 .part_trail = 0x00,
2001 .soft_ver = NULL,
2002
2003 .partitions = {
2004 {"fs-uboot", 0x00000, 0x20000},
2005 {"firmware", 0x20000, 0x7a0000},
2006 {"partition-table", 0x7c0000, 0x02000},
2007 {"default-mac", 0x7c2000, 0x00020},
2008 {"pin", 0x7c2100, 0x00020},
2009 {"product-info", 0x7c3100, 0x01000},
2010 {"soft-version", 0x7c4200, 0x01000},
2011 {"support-list", 0x7c5200, 0x01000},
2012 {"profile", 0x7c6200, 0x08000},
2013 {"config-info", 0x7ce200, 0x00400},
2014 {"user-config", 0x7d0000, 0x10000},
2015 {"default-config", 0x7e0000, 0x10000},
2016 {"radio", 0x7f0000, 0x10000},
2017 {NULL, 0, 0}
2018 },
2019
2020 .first_sysupgrade_partition = "os-image",
2021 .last_sysupgrade_partition = "file-system"
2022 },
2023
2024 /** Firmware layout for the RE200 v3 */
2025 {
2026 .id = "RE200-V3",
2027 .vendor = "",
2028 .support_list =
2029 "SupportList:\n"
2030 "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
2031 "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
2032 "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
2033 "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
2034 "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
2035 "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
2036 "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
2037 "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
2038 "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
2039 "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
2040 "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
2041 "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
2042 "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
2043 "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
2044 .part_trail = 0x00,
2045 .soft_ver = NULL,
2046
2047 .partitions = {
2048 {"fs-uboot", 0x00000, 0x20000},
2049 {"firmware", 0x20000, 0x7a0000},
2050 {"partition-table", 0x7c0000, 0x02000},
2051 {"default-mac", 0x7c2000, 0x00020},
2052 {"pin", 0x7c2100, 0x00020},
2053 {"product-info", 0x7c3100, 0x01000},
2054 {"soft-version", 0x7c4200, 0x01000},
2055 {"support-list", 0x7c5200, 0x01000},
2056 {"profile", 0x7c6200, 0x08000},
2057 {"config-info", 0x7ce200, 0x00400},
2058 {"user-config", 0x7d0000, 0x10000},
2059 {"default-config", 0x7e0000, 0x10000},
2060 {"radio", 0x7f0000, 0x10000},
2061 {NULL, 0, 0}
2062 },
2063
2064 .first_sysupgrade_partition = "os-image",
2065 .last_sysupgrade_partition = "file-system"
2066 },
2067
2068 /** Firmware layout for the RE200 v4 */
2069 {
2070 .id = "RE200-V4",
2071 .vendor = "",
2072 .support_list =
2073 "SupportList:\n"
2074 "{product_name:RE200,product_ver:4.0.0,special_id:00000000}\n"
2075 "{product_name:RE200,product_ver:4.0.0,special_id:45550000}\n"
2076 "{product_name:RE200,product_ver:4.0.0,special_id:4A500000}\n"
2077 "{product_name:RE200,product_ver:4.0.0,special_id:4B520000}\n"
2078 "{product_name:RE200,product_ver:4.0.0,special_id:43410000}\n"
2079 "{product_name:RE200,product_ver:4.0.0,special_id:41550000}\n"
2080 "{product_name:RE200,product_ver:4.0.0,special_id:42520000}\n"
2081 "{product_name:RE200,product_ver:4.0.0,special_id:55530000}\n"
2082 "{product_name:RE200,product_ver:4.0.0,special_id:41520000}\n"
2083 "{product_name:RE200,product_ver:4.0.0,special_id:52550000}\n"
2084 "{product_name:RE200,product_ver:4.0.0,special_id:54570000}\n"
2085 "{product_name:RE200,product_ver:4.0.0,special_id:45530000}\n"
2086 "{product_name:RE200,product_ver:4.0.0,special_id:49440000}\n"
2087 "{product_name:RE200,product_ver:4.0.0,special_id:45470000}\n",
2088 .part_trail = 0x00,
2089 .soft_ver = "soft_ver:1.1.0\n",
2090
2091 .partitions = {
2092 {"fs-uboot", 0x00000, 0x20000},
2093 {"firmware", 0x20000, 0x7a0000},
2094 {"partition-table", 0x7c0000, 0x02000},
2095 {"default-mac", 0x7c2000, 0x00020},
2096 {"pin", 0x7c2100, 0x00020},
2097 {"product-info", 0x7c3100, 0x01000},
2098 {"soft-version", 0x7c4200, 0x01000},
2099 {"support-list", 0x7c5200, 0x01000},
2100 {"profile", 0x7c6200, 0x08000},
2101 {"config-info", 0x7ce200, 0x00400},
2102 {"user-config", 0x7d0000, 0x10000},
2103 {"default-config", 0x7e0000, 0x10000},
2104 {"radio", 0x7f0000, 0x10000},
2105 {NULL, 0, 0}
2106 },
2107
2108 .first_sysupgrade_partition = "os-image",
2109 .last_sysupgrade_partition = "file-system"
2110 },
2111
2112 /** Firmware layout for the RE220 v2 */
2113 {
2114 .id = "RE220-V2",
2115 .vendor = "",
2116 .support_list =
2117 "SupportList:\n"
2118 "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
2119 "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
2120 "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
2121 "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
2122 "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
2123 "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
2124 "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
2125 "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
2126 "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
2127 "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
2128 "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
2129 "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
2130 "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
2131 .part_trail = 0x00,
2132 .soft_ver = NULL,
2133
2134 .partitions = {
2135 {"fs-uboot", 0x00000, 0x20000},
2136 {"firmware", 0x20000, 0x7a0000},
2137 {"partition-table", 0x7c0000, 0x02000},
2138 {"default-mac", 0x7c2000, 0x00020},
2139 {"pin", 0x7c2100, 0x00020},
2140 {"product-info", 0x7c3100, 0x01000},
2141 {"soft-version", 0x7c4200, 0x01000},
2142 {"support-list", 0x7c5200, 0x01000},
2143 {"profile", 0x7c6200, 0x08000},
2144 {"config-info", 0x7ce200, 0x00400},
2145 {"user-config", 0x7d0000, 0x10000},
2146 {"default-config", 0x7e0000, 0x10000},
2147 {"radio", 0x7f0000, 0x10000},
2148 {NULL, 0, 0}
2149 },
2150
2151 .first_sysupgrade_partition = "os-image",
2152 .last_sysupgrade_partition = "file-system"
2153 },
2154
2155 /** Firmware layout for the RE305 v1 */
2156 {
2157 .id = "RE305-V1",
2158 .vendor = "",
2159 .support_list =
2160 "SupportList:\n"
2161 "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
2162 "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
2163 "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
2164 "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
2165 "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
2166 "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
2167 "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
2168 .part_trail = 0x00,
2169 .soft_ver = NULL,
2170
2171 .partitions = {
2172 {"fs-uboot", 0x00000, 0x20000},
2173 {"firmware", 0x20000, 0x5e0000},
2174 {"partition-table", 0x600000, 0x02000},
2175 {"default-mac", 0x610000, 0x00020},
2176 {"pin", 0x610100, 0x00020},
2177 {"product-info", 0x611100, 0x01000},
2178 {"soft-version", 0x620000, 0x01000},
2179 {"support-list", 0x621000, 0x01000},
2180 {"profile", 0x622000, 0x08000},
2181 {"user-config", 0x630000, 0x10000},
2182 {"default-config", 0x640000, 0x10000},
2183 {"radio", 0x7f0000, 0x10000},
2184 {NULL, 0, 0}
2185 },
2186
2187 .first_sysupgrade_partition = "os-image",
2188 .last_sysupgrade_partition = "file-system"
2189 },
2190
2191 /** Firmware layout for the RE350 v1 */
2192 {
2193 .id = "RE350-V1",
2194 .vendor = "",
2195 .support_list =
2196 "SupportList:\n"
2197 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
2198 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
2199 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
2200 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
2201 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
2202 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
2203 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
2204 .part_trail = 0x00,
2205 .soft_ver = NULL,
2206
2207 /** We're using a dynamic kernel/rootfs split here */
2208 .partitions = {
2209 {"fs-uboot", 0x00000, 0x20000},
2210 {"firmware", 0x20000, 0x5e0000},
2211 {"partition-table", 0x600000, 0x02000},
2212 {"default-mac", 0x610000, 0x00020},
2213 {"pin", 0x610100, 0x00020},
2214 {"product-info", 0x611100, 0x01000},
2215 {"soft-version", 0x620000, 0x01000},
2216 {"support-list", 0x621000, 0x01000},
2217 {"profile", 0x622000, 0x08000},
2218 {"user-config", 0x630000, 0x10000},
2219 {"default-config", 0x640000, 0x10000},
2220 {"radio", 0x7f0000, 0x10000},
2221 {NULL, 0, 0}
2222 },
2223
2224 .first_sysupgrade_partition = "os-image",
2225 .last_sysupgrade_partition = "file-system"
2226 },
2227
2228 /** Firmware layout for the RE350K v1 */
2229 {
2230 .id = "RE350K-V1",
2231 .vendor = "",
2232 .support_list =
2233 "SupportList:\n"
2234 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
2235 .part_trail = 0x00,
2236 .soft_ver = NULL,
2237
2238 /** We're using a dynamic kernel/rootfs split here */
2239 .partitions = {
2240 {"fs-uboot", 0x00000, 0x20000},
2241 {"firmware", 0x20000, 0xd70000},
2242 {"partition-table", 0xd90000, 0x02000},
2243 {"default-mac", 0xda0000, 0x00020},
2244 {"pin", 0xda0100, 0x00020},
2245 {"product-info", 0xda1100, 0x01000},
2246 {"soft-version", 0xdb0000, 0x01000},
2247 {"support-list", 0xdb1000, 0x01000},
2248 {"profile", 0xdb2000, 0x08000},
2249 {"user-config", 0xdc0000, 0x10000},
2250 {"default-config", 0xdd0000, 0x10000},
2251 {"device-id", 0xde0000, 0x00108},
2252 {"radio", 0xff0000, 0x10000},
2253 {NULL, 0, 0}
2254 },
2255
2256 .first_sysupgrade_partition = "os-image",
2257 .last_sysupgrade_partition = "file-system"
2258 },
2259
2260 /** Firmware layout for the RE355 */
2261 {
2262 .id = "RE355",
2263 .vendor = "",
2264 .support_list =
2265 "SupportList:\r\n"
2266 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
2267 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
2268 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
2269 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
2270 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
2271 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
2272 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
2273 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
2274 .part_trail = 0x00,
2275 .soft_ver = NULL,
2276
2277 /* We're using a dynamic kernel/rootfs split here */
2278 .partitions = {
2279 {"fs-uboot", 0x00000, 0x20000},
2280 {"firmware", 0x20000, 0x5e0000},
2281 {"partition-table", 0x600000, 0x02000},
2282 {"default-mac", 0x610000, 0x00020},
2283 {"pin", 0x610100, 0x00020},
2284 {"product-info", 0x611100, 0x01000},
2285 {"soft-version", 0x620000, 0x01000},
2286 {"support-list", 0x621000, 0x01000},
2287 {"profile", 0x622000, 0x08000},
2288 {"user-config", 0x630000, 0x10000},
2289 {"default-config", 0x640000, 0x10000},
2290 {"radio", 0x7f0000, 0x10000},
2291 {NULL, 0, 0}
2292 },
2293
2294 .first_sysupgrade_partition = "os-image",
2295 .last_sysupgrade_partition = "file-system"
2296 },
2297
2298 /** Firmware layout for the RE450 */
2299 {
2300 .id = "RE450",
2301 .vendor = "",
2302 .support_list =
2303 "SupportList:\r\n"
2304 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
2305 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
2306 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
2307 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
2308 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
2309 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
2310 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
2311 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
2312 .part_trail = 0x00,
2313 .soft_ver = NULL,
2314
2315 /** We're using a dynamic kernel/rootfs split here */
2316 .partitions = {
2317 {"fs-uboot", 0x00000, 0x20000},
2318 {"firmware", 0x20000, 0x5e0000},
2319 {"partition-table", 0x600000, 0x02000},
2320 {"default-mac", 0x610000, 0x00020},
2321 {"pin", 0x610100, 0x00020},
2322 {"product-info", 0x611100, 0x01000},
2323 {"soft-version", 0x620000, 0x01000},
2324 {"support-list", 0x621000, 0x01000},
2325 {"profile", 0x622000, 0x08000},
2326 {"user-config", 0x630000, 0x10000},
2327 {"default-config", 0x640000, 0x10000},
2328 {"radio", 0x7f0000, 0x10000},
2329 {NULL, 0, 0}
2330 },
2331
2332 .first_sysupgrade_partition = "os-image",
2333 .last_sysupgrade_partition = "file-system"
2334 },
2335
2336 /** Firmware layout for the RE450 v2 */
2337 {
2338 .id = "RE450-V2",
2339 .vendor = "",
2340 .support_list =
2341 "SupportList:\r\n"
2342 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
2343 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
2344 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
2345 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
2346 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
2347 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
2348 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
2349 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
2350 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
2351 .part_trail = 0x00,
2352 .soft_ver = NULL,
2353
2354 /* We're using a dynamic kernel/rootfs split here */
2355 .partitions = {
2356 {"fs-uboot", 0x00000, 0x20000},
2357 {"firmware", 0x20000, 0x5e0000},
2358 {"partition-table", 0x600000, 0x02000},
2359 {"default-mac", 0x610000, 0x00020},
2360 {"pin", 0x610100, 0x00020},
2361 {"product-info", 0x611100, 0x01000},
2362 {"soft-version", 0x620000, 0x01000},
2363 {"support-list", 0x621000, 0x01000},
2364 {"profile", 0x622000, 0x08000},
2365 {"user-config", 0x630000, 0x10000},
2366 {"default-config", 0x640000, 0x10000},
2367 {"radio", 0x7f0000, 0x10000},
2368 {NULL, 0, 0}
2369 },
2370
2371 .first_sysupgrade_partition = "os-image",
2372 .last_sysupgrade_partition = "file-system"
2373 },
2374
2375 /** Firmware layout for the RE450 v3 */
2376 {
2377 .id = "RE450-V3",
2378 .vendor = "",
2379 .support_list =
2380 "SupportList:\r\n"
2381 "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
2382 "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
2383 "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
2384 "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
2385 "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
2386 "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
2387 "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
2388 "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
2389 "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
2390 .part_trail = 0x00,
2391 .soft_ver = NULL,
2392
2393 /* We're using a dynamic kernel/rootfs split here */
2394 .partitions = {
2395 {"fs-uboot", 0x00000, 0x20000},
2396 {"default-mac", 0x20000, 0x00020},
2397 {"pin", 0x20020, 0x00020},
2398 {"product-info", 0x21000, 0x01000},
2399 {"partition-table", 0x22000, 0x02000},
2400 {"soft-version", 0x24000, 0x01000},
2401 {"support-list", 0x25000, 0x01000},
2402 {"profile", 0x26000, 0x08000},
2403 {"user-config", 0x2e000, 0x10000},
2404 {"default-config", 0x3e000, 0x10000},
2405 {"config-info", 0x4e000, 0x00400},
2406 {"firmware", 0x50000, 0x7a0000},
2407 {"radio", 0x7f0000, 0x10000},
2408 {NULL, 0, 0}
2409 },
2410
2411 .first_sysupgrade_partition = "os-image",
2412 .last_sysupgrade_partition = "file-system"
2413 },
2414
2415 /** Firmware layout for the RE455 v1 */
2416 {
2417 .id = "RE455-V1",
2418 .vendor = "",
2419 .support_list =
2420 "SupportList:\r\n"
2421 "{product_name:RE455,product_ver:1.0.0,special_id:00000000}\r\n"
2422 "{product_name:RE455,product_ver:1.0.0,special_id:55530000}\r\n"
2423 "{product_name:RE455,product_ver:1.0.0,special_id:45550000}\r\n"
2424 "{product_name:RE455,product_ver:1.0.0,special_id:4A500000}\r\n"
2425 "{product_name:RE455,product_ver:1.0.0,special_id:43410000}\r\n"
2426 "{product_name:RE455,product_ver:1.0.0,special_id:41550000}\r\n"
2427 "{product_name:RE455,product_ver:1.0.0,special_id:41530000}\r\n"
2428 "{product_name:RE455,product_ver:1.0.0,special_id:4B520000}\r\n"
2429 "{product_name:RE455,product_ver:1.0.0,special_id:42520000}\r\n",
2430 .part_trail = 0x00,
2431 .soft_ver = NULL,
2432
2433 /* We're using a dynamic kernel/rootfs split here */
2434 .partitions = {
2435 {"fs-uboot", 0x00000, 0x20000},
2436 {"default-mac", 0x20000, 0x00020},
2437 {"pin", 0x20020, 0x00020},
2438 {"product-info", 0x21000, 0x01000},
2439 {"partition-table", 0x22000, 0x02000},
2440 {"soft-version", 0x24000, 0x01000},
2441 {"support-list", 0x25000, 0x01000},
2442 {"profile", 0x26000, 0x08000},
2443 {"user-config", 0x2e000, 0x10000},
2444 {"default-config", 0x3e000, 0x10000},
2445 {"config-info", 0x4e000, 0x00400},
2446 {"firmware", 0x50000, 0x7a0000},
2447 {"radio", 0x7f0000, 0x10000},
2448 {NULL, 0, 0}
2449 },
2450
2451 .first_sysupgrade_partition = "os-image",
2452 .last_sysupgrade_partition = "file-system"
2453 },
2454
2455 /** Firmware layout for the RE500 */
2456 {
2457 .id = "RE500-V1",
2458 .vendor = "",
2459 .support_list =
2460 "SupportList:\r\n"
2461 "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
2462 "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
2463 "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
2464 "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
2465 "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
2466 "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
2467 "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
2468 .part_trail = 0x00,
2469 .soft_ver = NULL,
2470
2471 /* We're using a dynamic kernel/rootfs split here */
2472 .partitions = {
2473 {"fs-uboot", 0x00000, 0x20000},
2474 {"firmware", 0x20000, 0xde0000},
2475 {"partition-table", 0xe00000, 0x02000},
2476 {"default-mac", 0xe10000, 0x00020},
2477 {"pin", 0xe10100, 0x00020},
2478 {"product-info", 0xe11100, 0x01000},
2479 {"soft-version", 0xe20000, 0x01000},
2480 {"support-list", 0xe21000, 0x01000},
2481 {"profile", 0xe22000, 0x08000},
2482 {"user-config", 0xe30000, 0x10000},
2483 {"default-config", 0xe40000, 0x10000},
2484 {"radio", 0xff0000, 0x10000},
2485 {NULL, 0, 0}
2486 },
2487
2488 .first_sysupgrade_partition = "os-image",
2489 .last_sysupgrade_partition = "file-system"
2490 },
2491
2492 /** Firmware layout for the RE650 */
2493 {
2494 .id = "RE650-V1",
2495 .vendor = "",
2496 .support_list =
2497 "SupportList:\r\n"
2498 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
2499 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
2500 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
2501 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
2502 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
2503 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
2504 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
2505 .part_trail = 0x00,
2506 .soft_ver = NULL,
2507
2508 /* We're using a dynamic kernel/rootfs split here */
2509 .partitions = {
2510 {"fs-uboot", 0x00000, 0x20000},
2511 {"firmware", 0x20000, 0xde0000},
2512 {"partition-table", 0xe00000, 0x02000},
2513 {"default-mac", 0xe10000, 0x00020},
2514 {"pin", 0xe10100, 0x00020},
2515 {"product-info", 0xe11100, 0x01000},
2516 {"soft-version", 0xe20000, 0x01000},
2517 {"support-list", 0xe21000, 0x01000},
2518 {"profile", 0xe22000, 0x08000},
2519 {"user-config", 0xe30000, 0x10000},
2520 {"default-config", 0xe40000, 0x10000},
2521 {"radio", 0xff0000, 0x10000},
2522 {NULL, 0, 0}
2523 },
2524
2525 .first_sysupgrade_partition = "os-image",
2526 .last_sysupgrade_partition = "file-system"
2527 },
2528
2529 {}
2530 };
2531
2532 #define error(_ret, _errno, _str, ...) \
2533 do { \
2534 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
2535 strerror(_errno)); \
2536 if (_ret) \
2537 exit(_ret); \
2538 } while (0)
2539
2540
2541 /** Stores a uint32 as big endian */
2542 static inline void put32(uint8_t *buf, uint32_t val) {
2543 buf[0] = val >> 24;
2544 buf[1] = val >> 16;
2545 buf[2] = val >> 8;
2546 buf[3] = val;
2547 }
2548
2549 static inline bool meta_partition_should_pad(enum partition_trail_value pv)
2550 {
2551 return (pv >= 0) && (pv <= PART_TRAIL_MAX);
2552 }
2553
2554 /** Allocate a padded meta partition with a correctly initialised header
2555 * If the `data` pointer is NULL, then the required space is only allocated,
2556 * otherwise `data_len` bytes will be copied from `data` into the partition
2557 * entry. */
2558 static struct image_partition_entry init_meta_partition_entry(
2559 const char *name, const void *data, uint32_t data_len,
2560 enum partition_trail_value pad_value)
2561 {
2562 uint32_t total_len = sizeof(struct meta_header) + data_len;
2563 if (meta_partition_should_pad(pad_value))
2564 total_len += 1;
2565
2566 struct image_partition_entry entry = {
2567 .name = name,
2568 .size = total_len,
2569 .data = malloc(total_len)
2570 };
2571 if (!entry.data)
2572 error(1, errno, "failed to allocate meta partition entry");
2573
2574 struct meta_header *header = (struct meta_header *)entry.data;
2575 header->length = htonl(data_len);
2576 header->zero = 0;
2577
2578 if (data)
2579 memcpy(entry.data+sizeof(*header), data, data_len);
2580
2581 if (meta_partition_should_pad(pad_value))
2582 entry.data[total_len - 1] = (uint8_t) pad_value;
2583
2584 return entry;
2585 }
2586
2587 /** Allocates a new image partition */
2588 static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
2589 struct image_partition_entry entry = {name, len, malloc(len)};
2590 if (!entry.data)
2591 error(1, errno, "malloc");
2592
2593 return entry;
2594 }
2595
2596 /** Frees an image partition */
2597 static void free_image_partition(struct image_partition_entry entry) {
2598 free(entry.data);
2599 }
2600
2601 static time_t source_date_epoch = -1;
2602 static void set_source_date_epoch() {
2603 char *env = getenv("SOURCE_DATE_EPOCH");
2604 char *endptr = env;
2605 errno = 0;
2606 if (env && *env) {
2607 source_date_epoch = strtoull(env, &endptr, 10);
2608 if (errno || (endptr && *endptr != '\0')) {
2609 fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
2610 exit(1);
2611 }
2612 }
2613 }
2614
2615 /** Generates the partition-table partition */
2616 static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
2617 struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
2618
2619 char *s = (char *)entry.data, *end = (char *)(s+entry.size);
2620
2621 *(s++) = 0x00;
2622 *(s++) = 0x04;
2623 *(s++) = 0x00;
2624 *(s++) = 0x00;
2625
2626 size_t i;
2627 for (i = 0; p[i].name; i++) {
2628 size_t len = end-s;
2629 size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n", p[i].name, p[i].base, p[i].size);
2630
2631 if (w > len-1)
2632 error(1, 0, "flash partition table overflow?");
2633
2634 s += w;
2635 }
2636
2637 s++;
2638
2639 memset(s, 0xff, end-s);
2640
2641 return entry;
2642 }
2643
2644
2645 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
2646 static inline uint8_t bcd(uint8_t v) {
2647 return 0x10 * (v/10) + v%10;
2648 }
2649
2650
2651 /** Generates the soft-version partition */
2652 static struct image_partition_entry make_soft_version(
2653 const struct device_info *info, uint32_t rev)
2654 {
2655 /** If an info string is provided, use this instead of
2656 * the structured data, and include the null-termination */
2657 if (info->soft_ver) {
2658 uint32_t len = strlen(info->soft_ver) + 1;
2659 return init_meta_partition_entry("soft-version",
2660 info->soft_ver, len, info->part_trail);
2661 }
2662
2663 time_t t;
2664
2665 if (source_date_epoch != -1)
2666 t = source_date_epoch;
2667 else if (time(&t) == (time_t)(-1))
2668 error(1, errno, "time");
2669
2670 struct tm *tm = gmtime(&t);
2671
2672 struct soft_version s = {
2673 .pad1 = 0xff,
2674
2675 .version_major = 0,
2676 .version_minor = 0,
2677 .version_patch = 0,
2678
2679 .year_hi = bcd((1900+tm->tm_year)/100),
2680 .year_lo = bcd(tm->tm_year%100),
2681 .month = bcd(tm->tm_mon+1),
2682 .day = bcd(tm->tm_mday),
2683
2684 .compat_level = htonl(info->soft_ver_compat_level)
2685 };
2686
2687 if (info->soft_ver_compat_level == 0)
2688 return init_meta_partition_entry("soft-version", &s,
2689 (uint8_t *)(&s.compat_level) - (uint8_t *)(&s),
2690 info->part_trail);
2691 else
2692 return init_meta_partition_entry("soft-version", &s,
2693 sizeof(s), info->part_trail);
2694 }
2695
2696 /** Generates the support-list partition */
2697 static struct image_partition_entry make_support_list(
2698 const struct device_info *info)
2699 {
2700 uint32_t len = strlen(info->support_list);
2701 return init_meta_partition_entry("support-list", info->support_list,
2702 len, info->part_trail);
2703 }
2704
2705 /** Partition with extra-para data */
2706 static struct image_partition_entry make_extra_para(
2707 const struct device_info *info, const uint8_t *extra_para, size_t len)
2708 {
2709 return init_meta_partition_entry("extra-para", extra_para, len,
2710 info->part_trail);
2711 }
2712
2713 /** Creates a new image partition with an arbitrary name from a file */
2714 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) {
2715 struct stat statbuf;
2716
2717 if (stat(filename, &statbuf) < 0)
2718 error(1, errno, "unable to stat file `%s'", filename);
2719
2720 size_t len = statbuf.st_size;
2721
2722 if (add_jffs2_eof) {
2723 if (file_system_partition)
2724 len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base;
2725 else
2726 len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
2727 }
2728
2729 struct image_partition_entry entry = alloc_image_partition(part_name, len);
2730
2731 FILE *file = fopen(filename, "rb");
2732 if (!file)
2733 error(1, errno, "unable to open file `%s'", filename);
2734
2735 if (fread(entry.data, statbuf.st_size, 1, file) != 1)
2736 error(1, errno, "unable to read file `%s'", filename);
2737
2738 if (add_jffs2_eof) {
2739 uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
2740
2741 memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
2742 memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
2743 }
2744
2745 fclose(file);
2746
2747 return entry;
2748 }
2749
2750 /**
2751 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
2752
2753 Example image partition table:
2754
2755 fwup-ptn partition-table base 0x00800 size 0x00800
2756 fwup-ptn os-image base 0x01000 size 0x113b45
2757 fwup-ptn file-system base 0x114b45 size 0x1d0004
2758 fwup-ptn support-list base 0x2e4b49 size 0x000d1
2759
2760 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
2761 the end of the partition table is marked with a zero byte.
2762
2763 The firmware image must contain at least the partition-table and support-list partitions
2764 to be accepted. There aren't any alignment constraints for the image partitions.
2765
2766 The partition-table partition contains the actual flash layout; partitions
2767 from the image partition table are mapped to the corresponding flash partitions during
2768 the firmware upgrade. The support-list partition contains a list of devices supported by
2769 the firmware image.
2770
2771 The base offsets in the firmware partition table are relative to the end
2772 of the vendor information block, so the partition-table partition will
2773 actually start at offset 0x1814 of the image.
2774
2775 I think partition-table must be the first partition in the firmware image.
2776 */
2777 static void put_partitions(uint8_t *buffer, const struct flash_partition_entry *flash_parts, const struct image_partition_entry *parts) {
2778 size_t i, j;
2779 char *image_pt = (char *)buffer, *end = image_pt + 0x800;
2780
2781 size_t base = 0x800;
2782 for (i = 0; parts[i].name; i++) {
2783 for (j = 0; flash_parts[j].name; j++) {
2784 if (!strcmp(flash_parts[j].name, parts[i].name)) {
2785 if (parts[i].size > flash_parts[j].size)
2786 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts[j].name, (unsigned)flash_parts[j].size);
2787 break;
2788 }
2789 }
2790
2791 assert(flash_parts[j].name);
2792
2793 memcpy(buffer + base, parts[i].data, parts[i].size);
2794
2795 size_t len = end-image_pt;
2796 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);
2797
2798 if (w > len-1)
2799 error(1, 0, "image partition table overflow?");
2800
2801 image_pt += w;
2802
2803 base += parts[i].size;
2804 }
2805 }
2806
2807 /** Generates and writes the image MD5 checksum */
2808 static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
2809 MD5_CTX ctx;
2810
2811 MD5_Init(&ctx);
2812 MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
2813 MD5_Update(&ctx, buffer, len);
2814 MD5_Final(md5, &ctx);
2815 }
2816
2817
2818 /**
2819 Generates the firmware image in factory format
2820
2821 Image format:
2822
2823 Bytes (hex) Usage
2824 ----------- -----
2825 0000-0003 Image size (4 bytes, big endian)
2826 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
2827 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
2828 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
2829 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
2830 1014-1813 Image partition table (2048 bytes, padded with 0xff)
2831 1814-xxxx Firmware partitions
2832 */
2833 static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) {
2834 *len = 0x1814;
2835
2836 size_t i;
2837 for (i = 0; parts[i].name; i++)
2838 *len += parts[i].size;
2839
2840 uint8_t *image = malloc(*len);
2841 if (!image)
2842 error(1, errno, "malloc");
2843
2844 memset(image, 0xff, *len);
2845 put32(image, *len);
2846
2847 if (info->vendor) {
2848 size_t vendor_len = strlen(info->vendor);
2849 put32(image+0x14, vendor_len);
2850 memcpy(image+0x18, info->vendor, vendor_len);
2851 }
2852
2853 put_partitions(image + 0x1014, info->partitions, parts);
2854 put_md5(image+0x04, image+0x14, *len-0x14);
2855
2856 return image;
2857 }
2858
2859 /**
2860 Generates the firmware image in sysupgrade format
2861
2862 This makes some assumptions about the provided flash and image partition tables and
2863 should be generalized when TP-LINK starts building its safeloader into hardware with
2864 different flash layouts.
2865 */
2866 static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) {
2867 size_t i, j;
2868 size_t flash_first_partition_index = 0;
2869 size_t flash_last_partition_index = 0;
2870 const struct flash_partition_entry *flash_first_partition = NULL;
2871 const struct flash_partition_entry *flash_last_partition = NULL;
2872 const struct image_partition_entry *image_last_partition = NULL;
2873
2874 /** Find first and last partitions */
2875 for (i = 0; info->partitions[i].name; i++) {
2876 if (!strcmp(info->partitions[i].name, info->first_sysupgrade_partition)) {
2877 flash_first_partition = &info->partitions[i];
2878 flash_first_partition_index = i;
2879 } else if (!strcmp(info->partitions[i].name, info->last_sysupgrade_partition)) {
2880 flash_last_partition = &info->partitions[i];
2881 flash_last_partition_index = i;
2882 }
2883 }
2884
2885 assert(flash_first_partition && flash_last_partition);
2886 assert(flash_first_partition_index < flash_last_partition_index);
2887
2888 /** Find last partition from image to calculate needed size */
2889 for (i = 0; image_parts[i].name; i++) {
2890 if (!strcmp(image_parts[i].name, info->last_sysupgrade_partition)) {
2891 image_last_partition = &image_parts[i];
2892 break;
2893 }
2894 }
2895
2896 assert(image_last_partition);
2897
2898 *len = flash_last_partition->base - flash_first_partition->base + image_last_partition->size;
2899
2900 uint8_t *image = malloc(*len);
2901 if (!image)
2902 error(1, errno, "malloc");
2903
2904 memset(image, 0xff, *len);
2905
2906 for (i = flash_first_partition_index; i <= flash_last_partition_index; i++) {
2907 for (j = 0; image_parts[j].name; j++) {
2908 if (!strcmp(info->partitions[i].name, image_parts[j].name)) {
2909 if (image_parts[j].size > info->partitions[i].size)
2910 error(1, 0, "%s partition too big (more than %u bytes)", info->partitions[i].name, (unsigned)info->partitions[i].size);
2911 memcpy(image + info->partitions[i].base - flash_first_partition->base, image_parts[j].data, image_parts[j].size);
2912 break;
2913 }
2914
2915 assert(image_parts[j].name);
2916 }
2917 }
2918
2919 return image;
2920 }
2921
2922 /** Generates an image according to a given layout and writes it to a file */
2923 static void build_image(const char *output,
2924 const char *kernel_image,
2925 const char *rootfs_image,
2926 uint32_t rev,
2927 bool add_jffs2_eof,
2928 bool sysupgrade,
2929 struct device_info *info) {
2930
2931 size_t i;
2932
2933 struct image_partition_entry parts[7] = {};
2934
2935 struct flash_partition_entry *firmware_partition = NULL;
2936 struct flash_partition_entry *os_image_partition = NULL;
2937 struct flash_partition_entry *file_system_partition = NULL;
2938 size_t firmware_partition_index = 0;
2939
2940 for (i = 0; info->partitions[i].name; i++) {
2941 if (!strcmp(info->partitions[i].name, "firmware"))
2942 {
2943 firmware_partition = &info->partitions[i];
2944 firmware_partition_index = i;
2945 }
2946 }
2947
2948 if (firmware_partition)
2949 {
2950 os_image_partition = &info->partitions[firmware_partition_index];
2951 file_system_partition = &info->partitions[firmware_partition_index + 1];
2952
2953 struct stat kernel;
2954 if (stat(kernel_image, &kernel) < 0)
2955 error(1, errno, "unable to stat file `%s'", kernel_image);
2956
2957 if (kernel.st_size > firmware_partition->size)
2958 error(1, 0, "kernel overflowed firmware partition\n");
2959
2960 for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--)
2961 info->partitions[i+1] = info->partitions[i];
2962
2963 file_system_partition->name = "file-system";
2964 file_system_partition->base = firmware_partition->base + kernel.st_size;
2965
2966 /* Align partition start to erase blocks for factory images only */
2967 if (!sysupgrade)
2968 file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000);
2969
2970 file_system_partition->size = firmware_partition->size - file_system_partition->base;
2971
2972 os_image_partition->name = "os-image";
2973 os_image_partition->size = kernel.st_size;
2974 }
2975
2976 parts[0] = make_partition_table(info->partitions);
2977 parts[1] = make_soft_version(info, rev);
2978 parts[2] = make_support_list(info);
2979 parts[3] = read_file("os-image", kernel_image, false, NULL);
2980 parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition);
2981
2982 /* Some devices need the extra-para partition to accept the firmware */
2983 if (strcasecmp(info->id, "ARCHER-A6-V3") == 0 ||
2984 strcasecmp(info->id, "ARCHER-A7-V5") == 0 ||
2985 strcasecmp(info->id, "ARCHER-C2-V3") == 0 ||
2986 strcasecmp(info->id, "ARCHER-C7-V4") == 0 ||
2987 strcasecmp(info->id, "ARCHER-C7-V5") == 0 ||
2988 strcasecmp(info->id, "ARCHER-C25-V1") == 0 ||
2989 strcasecmp(info->id, "ARCHER-C59-V2") == 0 ||
2990 strcasecmp(info->id, "ARCHER-C60-V2") == 0 ||
2991 strcasecmp(info->id, "ARCHER-C60-V3") == 0 ||
2992 strcasecmp(info->id, "ARCHER-C6U-V1") == 0 ||
2993 strcasecmp(info->id, "ARCHER-C6-V3") == 0 ||
2994 strcasecmp(info->id, "TLWR1043NV5") == 0) {
2995 const uint8_t extra_para[2] = {0x01, 0x00};
2996 parts[5] = make_extra_para(info, extra_para,
2997 sizeof(extra_para));
2998 } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0) {
2999 const uint8_t extra_para[2] = {0x00, 0x01};
3000 parts[5] = make_extra_para(info, extra_para,
3001 sizeof(extra_para));
3002 } else if (strcasecmp(info->id, "ARCHER-C6-V2-US") == 0 ||
3003 strcasecmp(info->id, "EAP245-V3") == 0) {
3004 const uint8_t extra_para[2] = {0x01, 0x01};
3005 parts[5] = make_extra_para(info, extra_para,
3006 sizeof(extra_para));
3007 }
3008
3009 size_t len;
3010 void *image;
3011 if (sysupgrade)
3012 image = generate_sysupgrade_image(info, parts, &len);
3013 else
3014 image = generate_factory_image(info, parts, &len);
3015
3016 FILE *file = fopen(output, "wb");
3017 if (!file)
3018 error(1, errno, "unable to open output file");
3019
3020 if (fwrite(image, len, 1, file) != 1)
3021 error(1, 0, "unable to write output file");
3022
3023 fclose(file);
3024
3025 free(image);
3026
3027 for (i = 0; parts[i].name; i++)
3028 free_image_partition(parts[i]);
3029 }
3030
3031 /** Usage output */
3032 static void usage(const char *argv0) {
3033 fprintf(stderr,
3034 "Usage: %s [OPTIONS...]\n"
3035 "\n"
3036 "Options:\n"
3037 " -h show this help\n"
3038 "\n"
3039 "Info about an image:\n"
3040 " -i <file> input file to read from\n"
3041 "Create a new image:\n"
3042 " -B <board> create image for the board specified with <board>\n"
3043 " -k <file> read kernel image from the file <file>\n"
3044 " -r <file> read rootfs image from the file <file>\n"
3045 " -o <file> write output to the file <file>\n"
3046 " -V <rev> sets the revision number to <rev>\n"
3047 " -j add jffs2 end-of-filesystem markers\n"
3048 " -S create sysupgrade instead of factory image\n"
3049 "Extract an old image:\n"
3050 " -x <file> extract all oem firmware partition\n"
3051 " -d <dir> destination to extract the firmware partition\n"
3052 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
3053 argv0
3054 );
3055 };
3056
3057
3058 static struct device_info *find_board(const char *id)
3059 {
3060 struct device_info *board = NULL;
3061
3062 for (board = boards; board->id != NULL; board++)
3063 if (strcasecmp(id, board->id) == 0)
3064 return board;
3065
3066 return NULL;
3067 }
3068
3069 static int add_flash_partition(
3070 struct flash_partition_entry *part_list,
3071 size_t max_entries,
3072 const char *name,
3073 unsigned long base,
3074 unsigned long size)
3075 {
3076 size_t ptr;
3077 /* check if the list has a free entry */
3078 for (ptr = 0; ptr < max_entries; ptr++, part_list++) {
3079 if (part_list->name == NULL &&
3080 part_list->base == 0 &&
3081 part_list->size == 0)
3082 break;
3083 }
3084
3085 if (ptr == max_entries) {
3086 error(1, 0, "No free flash part entry available.");
3087 }
3088
3089 part_list->name = calloc(1, strlen(name) + 1);
3090 if (!part_list->name) {
3091 error(1, 0, "Unable to allocate memory");
3092 }
3093
3094 memcpy((char *)part_list->name, name, strlen(name));
3095 part_list->base = base;
3096 part_list->size = size;
3097
3098 return 0;
3099 }
3100
3101 /** read the partition table into struct flash_partition_entry */
3102 static int read_partition_table(
3103 FILE *file, long offset,
3104 struct flash_partition_entry *entries, size_t max_entries,
3105 int type)
3106 {
3107 char buf[2048];
3108 char *ptr, *end;
3109 const char *parthdr = NULL;
3110 const char *fwuphdr = "fwup-ptn";
3111 const char *flashhdr = "partition";
3112
3113 /* TODO: search for the partition table */
3114
3115 switch(type) {
3116 case 0:
3117 parthdr = fwuphdr;
3118 break;
3119 case 1:
3120 parthdr = flashhdr;
3121 break;
3122 default:
3123 error(1, 0, "Invalid partition table");
3124 }
3125
3126 if (fseek(file, offset, SEEK_SET) < 0)
3127 error(1, errno, "Can not seek in the firmware");
3128
3129 if (fread(buf, 2048, 1, file) != 1)
3130 error(1, errno, "Can not read fwup-ptn from the firmware");
3131
3132 buf[2047] = '\0';
3133
3134 /* look for the partition header */
3135 if (memcmp(buf, parthdr, strlen(parthdr)) != 0) {
3136 fprintf(stderr, "DEBUG: can not find fwuphdr\n");
3137 return 1;
3138 }
3139
3140 ptr = buf;
3141 end = buf + sizeof(buf);
3142 while ((ptr + strlen(parthdr)) < end &&
3143 memcmp(ptr, parthdr, strlen(parthdr)) == 0) {
3144 char *end_part;
3145 char *end_element;
3146
3147 char name[32] = { 0 };
3148 int name_len = 0;
3149 unsigned long base = 0;
3150 unsigned long size = 0;
3151
3152 end_part = memchr(ptr, '\n', (end - ptr));
3153 if (end_part == NULL) {
3154 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
3155 break;
3156 }
3157
3158 for (int i = 0; i <= 4; i++) {
3159 if (end_part <= ptr)
3160 break;
3161
3162 end_element = memchr(ptr, 0x20, (end_part - ptr));
3163 if (end_element == NULL) {
3164 error(1, errno, "Ignoring the rest of the partition entries.");
3165 break;
3166 }
3167
3168 switch (i) {
3169 /* partition header */
3170 case 0:
3171 ptr = end_element + 1;
3172 continue;
3173 /* name */
3174 case 1:
3175 name_len = (end_element - ptr) > 31 ? 31 : (end_element - ptr);
3176 strncpy(name, ptr, name_len);
3177 name[name_len] = '\0';
3178 ptr = end_element + 1;
3179 continue;
3180
3181 /* string "base" */
3182 case 2:
3183 ptr = end_element + 1;
3184 continue;
3185
3186 /* actual base */
3187 case 3:
3188 base = strtoul(ptr, NULL, 16);
3189 ptr = end_element + 1;
3190 continue;
3191
3192 /* string "size" */
3193 case 4:
3194 ptr = end_element + 1;
3195 /* actual size. The last element doesn't have a sepeartor */
3196 size = strtoul(ptr, NULL, 16);
3197 /* the part ends with 0x09, 0x0d, 0x0a */
3198 ptr = end_part + 1;
3199 add_flash_partition(entries, max_entries, name, base, size);
3200 continue;
3201 }
3202 }
3203 }
3204
3205 return 0;
3206 }
3207
3208 static void write_partition(
3209 FILE *input_file,
3210 size_t firmware_offset,
3211 struct flash_partition_entry *entry,
3212 FILE *output_file)
3213 {
3214 char buf[4096];
3215 size_t offset;
3216
3217 fseek(input_file, entry->base + firmware_offset, SEEK_SET);
3218
3219 for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) {
3220 if (fread(buf, sizeof(buf), 1, input_file) != 1)
3221 error(1, errno, "Can not read partition from input_file");
3222
3223 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3224 error(1, errno, "Can not write partition to output_file");
3225 }
3226 /* write last chunk smaller than buffer */
3227 if (offset < entry->size) {
3228 offset = entry->size - offset;
3229 if (fread(buf, offset, 1, input_file) != 1)
3230 error(1, errno, "Can not read partition from input_file");
3231 if (fwrite(buf, offset, 1, output_file) != 1)
3232 error(1, errno, "Can not write partition to output_file");
3233 }
3234 }
3235
3236 static int extract_firmware_partition(FILE *input_file, size_t firmware_offset, struct flash_partition_entry *entry, const char *output_directory)
3237 {
3238 FILE *output_file;
3239 char output[PATH_MAX];
3240
3241 snprintf(output, PATH_MAX, "%s/%s", output_directory, entry->name);
3242 output_file = fopen(output, "wb+");
3243 if (output_file == NULL) {
3244 error(1, errno, "Can not open output file %s", output);
3245 }
3246
3247 write_partition(input_file, firmware_offset, entry, output_file);
3248
3249 fclose(output_file);
3250
3251 return 0;
3252 }
3253
3254 /** extract all partitions from the firmware file */
3255 static int extract_firmware(const char *input, const char *output_directory)
3256 {
3257 struct flash_partition_entry entries[16] = { 0 };
3258 size_t max_entries = 16;
3259 size_t firmware_offset = 0x1014;
3260 FILE *input_file;
3261
3262 struct stat statbuf;
3263
3264 /* check input file */
3265 if (stat(input, &statbuf)) {
3266 error(1, errno, "Can not read input firmware %s", input);
3267 }
3268
3269 /* check if output directory exists */
3270 if (stat(output_directory, &statbuf)) {
3271 error(1, errno, "Failed to stat output directory %s", output_directory);
3272 }
3273
3274 if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
3275 error(1, errno, "Given output directory is not a directory %s", output_directory);
3276 }
3277
3278 input_file = fopen(input, "rb");
3279
3280 if (read_partition_table(input_file, firmware_offset, entries, 16, 0) != 0) {
3281 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3282 }
3283
3284 for (size_t i = 0; i < max_entries; i++) {
3285 if (entries[i].name == NULL &&
3286 entries[i].base == 0 &&
3287 entries[i].size == 0)
3288 continue;
3289
3290 extract_firmware_partition(input_file, firmware_offset, &entries[i], output_directory);
3291 }
3292
3293 return 0;
3294 }
3295
3296 static struct flash_partition_entry *find_partition(
3297 struct flash_partition_entry *entries, size_t max_entries,
3298 const char *name, const char *error_msg)
3299 {
3300 for (size_t i = 0; i < max_entries; i++, entries++) {
3301 if (strcmp(entries->name, name) == 0)
3302 return entries;
3303 }
3304
3305 if (error_msg) {
3306 error(1, 0, "%s", error_msg);
3307 }
3308
3309 return NULL;
3310 }
3311
3312 static int firmware_info(const char *input)
3313 {
3314 struct flash_partition_entry pointers[MAX_PARTITIONS] = { };
3315 struct flash_partition_entry *e;
3316 FILE *fp;
3317 int i;
3318
3319 fp = fopen(input, "r");
3320
3321 if (read_partition_table(fp, 0x1014, pointers, MAX_PARTITIONS, 0)) {
3322 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3323 }
3324
3325 printf("Firmware image partitions:\n");
3326 printf("%-8s %-8s %s\n", "base", "size", "name");
3327 for (i = 0; i < MAX_PARTITIONS; i++) {
3328 e = &pointers[i];
3329
3330 if (!e->name && !e->base && !e->size)
3331 continue;
3332
3333 printf("%08x %08x %s\n", e->base, e->size, e->name ? e->name : "");
3334 }
3335
3336 e = find_partition(pointers, MAX_PARTITIONS, "soft-version", NULL);
3337 if (e) {
3338 size_t data_len = e->size - sizeof(struct meta_header);
3339 char *buf = malloc(data_len);
3340 struct soft_version *s;
3341 bool isstr;
3342 int i;
3343
3344 if (!buf)
3345 error(1, errno, "Failed to alloc buffer");
3346
3347 if (fseek(fp, 0x1014 + e->base + sizeof(struct meta_header), SEEK_SET))
3348 error(1, errno, "Can not seek in the firmware");
3349
3350 if (fread(buf, data_len, 1, fp) != 1)
3351 error(1, errno, "Can not read fwup-ptn data from the firmware");
3352
3353 /* Check for string ignoring padding character */
3354 isstr = true;
3355 for (i = 0; i < data_len - 1; i++) {
3356 if (!isascii(buf[i])) {
3357 isstr = false;
3358 break;
3359 }
3360 }
3361
3362 printf("\n[Software version]\n");
3363 if (isstr) {
3364 fwrite(buf, data_len, 1, stdout);
3365 putchar('\n');
3366 } else if (data_len >= offsetof(struct soft_version, rev)) {
3367 s = (struct soft_version *)buf;
3368
3369 printf("Version: %d.%d.%d\n", s->version_major, s->version_minor, s->version_patch);
3370 printf("Date: %02x%02x-%02x-%02x\n", s->year_hi, s->year_lo, s->month, s->day);
3371 } else {
3372 printf("Failed to parse data\n");
3373 }
3374
3375 free(buf);
3376 }
3377
3378 e = find_partition(pointers, MAX_PARTITIONS, "support-list", NULL);
3379 if (e) {
3380 char buf[128];
3381 size_t length;
3382 size_t bytes;
3383
3384 if (fseek(fp, 0x1014 + e->base + sizeof(struct meta_header), SEEK_SET))
3385 error(1, errno, "Can not seek in the firmware");
3386
3387 printf("\n[Support list]\n");
3388 for (length = e->size - sizeof(struct meta_header); length; length -= bytes) {
3389 bytes = fread(buf, 1, length > sizeof(buf) ? sizeof(buf) : length, fp);
3390 if (bytes <= 0)
3391 error(1, errno, "Can not read fwup-ptn data from the firmware");
3392
3393 puts(buf);
3394 }
3395 }
3396
3397 e = find_partition(pointers, MAX_PARTITIONS, "partition-table", NULL);
3398 if (e) {
3399 struct flash_partition_entry parts[MAX_PARTITIONS] = { };
3400
3401 if (read_partition_table(fp, 0x1014 + e->base + 4, parts, MAX_PARTITIONS, 1)) {
3402 error(1, 0, "Error can not read the partition table (partition)");
3403 }
3404
3405 printf("\n[Partition table]\n");
3406 printf("%-8s %-8s %s\n", "base", "size", "name");
3407 for (i = 0; i < MAX_PARTITIONS; i++) {
3408 e = &parts[i];
3409
3410 if (!e->name && !e->base && !e->size)
3411 continue;
3412
3413 printf("%08x %08x %s\n", e->base, e->size, e->name ? e->name : "");
3414 }
3415 }
3416
3417 fclose(fp);
3418
3419 return 0;
3420 }
3421
3422 static void write_ff(FILE *output_file, size_t size)
3423 {
3424 char buf[4096];
3425 size_t offset;
3426
3427 memset(buf, 0xff, sizeof(buf));
3428
3429 for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) {
3430 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3431 error(1, errno, "Can not write 0xff to output_file");
3432 }
3433
3434 /* write last chunk smaller than buffer */
3435 if (offset < size) {
3436 offset = size - offset;
3437 if (fwrite(buf, offset, 1, output_file) != 1)
3438 error(1, errno, "Can not write partition to output_file");
3439 }
3440 }
3441
3442 static void convert_firmware(const char *input, const char *output)
3443 {
3444 struct flash_partition_entry fwup[MAX_PARTITIONS] = { 0 };
3445 struct flash_partition_entry flash[MAX_PARTITIONS] = { 0 };
3446 struct flash_partition_entry *fwup_os_image = NULL, *fwup_file_system = NULL;
3447 struct flash_partition_entry *flash_os_image = NULL, *flash_file_system = NULL;
3448 struct flash_partition_entry *fwup_partition_table = NULL;
3449 size_t firmware_offset = 0x1014;
3450 FILE *input_file, *output_file;
3451
3452 struct stat statbuf;
3453
3454 /* check input file */
3455 if (stat(input, &statbuf)) {
3456 error(1, errno, "Can not read input firmware %s", input);
3457 }
3458
3459 input_file = fopen(input, "rb");
3460 if (!input_file)
3461 error(1, 0, "Can not open input firmware %s", input);
3462
3463 output_file = fopen(output, "wb");
3464 if (!output_file)
3465 error(1, 0, "Can not open output firmware %s", output);
3466
3467 if (read_partition_table(input_file, firmware_offset, fwup, MAX_PARTITIONS, 0) != 0) {
3468 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3469 }
3470
3471 fwup_os_image = find_partition(fwup, MAX_PARTITIONS,
3472 "os-image", "Error can not find os-image partition (fwup)");
3473 fwup_file_system = find_partition(fwup, MAX_PARTITIONS,
3474 "file-system", "Error can not find file-system partition (fwup)");
3475 fwup_partition_table = find_partition(fwup, MAX_PARTITIONS,
3476 "partition-table", "Error can not find partition-table partition");
3477
3478 /* the flash partition table has a 0x00000004 magic haeder */
3479 if (read_partition_table(input_file, firmware_offset + fwup_partition_table->base + 4, flash, MAX_PARTITIONS, 1) != 0)
3480 error(1, 0, "Error can not read the partition table (flash)");
3481
3482 flash_os_image = find_partition(flash, MAX_PARTITIONS,
3483 "os-image", "Error can not find os-image partition (flash)");
3484 flash_file_system = find_partition(flash, MAX_PARTITIONS,
3485 "file-system", "Error can not find file-system partition (flash)");
3486
3487 /* write os_image to 0x0 */
3488 write_partition(input_file, firmware_offset, fwup_os_image, output_file);
3489 write_ff(output_file, flash_os_image->size - fwup_os_image->size);
3490
3491 /* write file-system behind os_image */
3492 fseek(output_file, flash_file_system->base - flash_os_image->base, SEEK_SET);
3493 write_partition(input_file, firmware_offset, fwup_file_system, output_file);
3494 write_ff(output_file, flash_file_system->size - fwup_file_system->size);
3495
3496 fclose(output_file);
3497 fclose(input_file);
3498 }
3499
3500 int main(int argc, char *argv[]) {
3501 const char *info_image = NULL, *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
3502 const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL;
3503 bool add_jffs2_eof = false, sysupgrade = false;
3504 unsigned rev = 0;
3505 struct device_info *info;
3506 set_source_date_epoch();
3507
3508 while (true) {
3509 int c;
3510
3511 c = getopt(argc, argv, "i:B:k:r:o:V:jSh:x:d:z:");
3512 if (c == -1)
3513 break;
3514
3515 switch (c) {
3516 case 'i':
3517 info_image = optarg;
3518 break;
3519
3520 case 'B':
3521 board = optarg;
3522 break;
3523
3524 case 'k':
3525 kernel_image = optarg;
3526 break;
3527
3528 case 'r':
3529 rootfs_image = optarg;
3530 break;
3531
3532 case 'o':
3533 output = optarg;
3534 break;
3535
3536 case 'V':
3537 sscanf(optarg, "r%u", &rev);
3538 break;
3539
3540 case 'j':
3541 add_jffs2_eof = true;
3542 break;
3543
3544 case 'S':
3545 sysupgrade = true;
3546 break;
3547
3548 case 'h':
3549 usage(argv[0]);
3550 return 0;
3551
3552 case 'd':
3553 output_directory = optarg;
3554 break;
3555
3556 case 'x':
3557 extract_image = optarg;
3558 break;
3559
3560 case 'z':
3561 convert_image = optarg;
3562 break;
3563
3564 default:
3565 usage(argv[0]);
3566 return 1;
3567 }
3568 }
3569
3570 if (info_image) {
3571 firmware_info(info_image);
3572 } else if (extract_image || output_directory) {
3573 if (!extract_image)
3574 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
3575 if (!output_directory)
3576 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
3577 extract_firmware(extract_image, output_directory);
3578 } else if (convert_image) {
3579 if (!output)
3580 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
3581 convert_firmware(convert_image, output);
3582 } else {
3583 if (!board)
3584 error(1, 0, "no board has been specified");
3585 if (!kernel_image)
3586 error(1, 0, "no kernel image has been specified");
3587 if (!rootfs_image)
3588 error(1, 0, "no rootfs image has been specified");
3589 if (!output)
3590 error(1, 0, "no output filename has been specified");
3591
3592 info = find_board(board);
3593
3594 if (info == NULL)
3595 error(1, 0, "unsupported board %s", board);
3596
3597 build_image(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, info);
3598 }
3599
3600 return 0;
3601 }