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