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