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