d586b9cbd83c385d618cebc4e999b569338177a0
[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 Archer C6U v1 */
1101 {
1102 .id = "ARCHER-C6U-V1",
1103 .vendor = "",
1104 .support_list =
1105 "SupportList:\n"
1106 "{product_name:Archer C6U,product_ver:1.0.0,special_id:45550000}\n",
1107 .part_trail = 0x00,
1108 .soft_ver = "soft_ver:1.0.2\n",
1109
1110 .partitions = {
1111 {"fs-uboot", 0x00000, 0x40000},
1112 {"firmware", 0x40000, 0xf60000},
1113 {"default-mac", 0xfa0000, 0x00200},
1114 {"pin", 0xfa0200, 0x00100},
1115 {"device-id", 0xfa0300, 0x00100},
1116 {"product-info", 0xfa0400, 0x0fc00},
1117 {"default-config", 0xfb0000, 0x08000},
1118 {"ap-def-config", 0xfb8000, 0x08000},
1119 {"user-config", 0xfc0000, 0x0c000},
1120 {"certificate", 0xfcc000, 0x04000},
1121 {"ap-config", 0xfd0000, 0x08000},
1122 {"router-config", 0xfd8000, 0x08000},
1123 {"partition-table", 0xfe0000, 0x00800},
1124 {"soft-version", 0xfe0800, 0x00100},
1125 {"support-list", 0xfe0900, 0x00200},
1126 {"profile", 0xfe0b00, 0x03000},
1127 {"extra-para", 0xfe3b00, 0x00100},
1128 {"radio", 0xff0000, 0x10000},
1129 {NULL, 0, 0}
1130 },
1131 .first_sysupgrade_partition = "os-image",
1132 .last_sysupgrade_partition = "file-system",
1133 },
1134 /** Firmware layout for the C60v1 */
1135 {
1136 .id = "ARCHER-C60-V1",
1137 .vendor = "",
1138 .support_list =
1139 "SupportList:\r\n"
1140 "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
1141 "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
1142 "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
1143 .part_trail = 0x00,
1144 .soft_ver = "soft_ver:1.0.0\n",
1145
1146 .partitions = {
1147 {"fs-uboot", 0x00000, 0x10000},
1148 {"default-mac", 0x10000, 0x00200},
1149 {"pin", 0x10200, 0x00200},
1150 {"product-info", 0x10400, 0x00100},
1151 {"partition-table", 0x10500, 0x00800},
1152 {"soft-version", 0x11300, 0x00200},
1153 {"support-list", 0x11500, 0x00100},
1154 {"device-id", 0x11600, 0x00100},
1155 {"profile", 0x11700, 0x03900},
1156 {"default-config", 0x15000, 0x04000},
1157 {"user-config", 0x19000, 0x04000},
1158 {"firmware", 0x20000, 0x7c8000},
1159 {"certyficate", 0x7e8000, 0x08000},
1160 {"radio", 0x7f0000, 0x10000},
1161 {NULL, 0, 0}
1162 },
1163
1164 .first_sysupgrade_partition = "os-image",
1165 .last_sysupgrade_partition = "file-system",
1166 },
1167
1168 /** Firmware layout for the C60v2 */
1169 {
1170 .id = "ARCHER-C60-V2",
1171 .vendor = "",
1172 .support_list =
1173 "SupportList:\r\n"
1174 "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
1175 "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
1176 "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
1177 .part_trail = 0x00,
1178 .soft_ver = "soft_ver:2.0.0\n",
1179
1180 .partitions = {
1181 {"factory-boot", 0x00000, 0x1fb00},
1182 {"default-mac", 0x1fb00, 0x00200},
1183 {"pin", 0x1fd00, 0x00100},
1184 {"product-info", 0x1fe00, 0x00100},
1185 {"device-id", 0x1ff00, 0x00100},
1186 {"fs-uboot", 0x20000, 0x10000},
1187 {"firmware", 0x30000, 0x7a0000},
1188 {"soft-version", 0x7d9500, 0x00100},
1189 {"support-list", 0x7d9600, 0x00100},
1190 {"extra-para", 0x7d9700, 0x00100},
1191 {"profile", 0x7d9800, 0x03000},
1192 {"default-config", 0x7dc800, 0x03000},
1193 {"partition-table", 0x7df800, 0x00800},
1194 {"user-config", 0x7e0000, 0x0c000},
1195 {"certificate", 0x7ec000, 0x04000},
1196 {"radio", 0x7f0000, 0x10000},
1197 {NULL, 0, 0}
1198 },
1199
1200 .first_sysupgrade_partition = "os-image",
1201 .last_sysupgrade_partition = "file-system",
1202 },
1203
1204 /** Firmware layout for the C60v3 */
1205 {
1206 .id = "ARCHER-C60-V3",
1207 .vendor = "",
1208 .support_list =
1209 "SupportList:\r\n"
1210 "{product_name:Archer C60,product_ver:3.0.0,special_id:42520000}\r\n"
1211 "{product_name:Archer C60,product_ver:3.0.0,special_id:45550000}\r\n"
1212 "{product_name:Archer C60,product_ver:3.0.0,special_id:55530000}\r\n",
1213 .part_trail = 0x00,
1214 .soft_ver = "soft_ver:3.0.0\n",
1215
1216 .partitions = {
1217 {"factory-boot", 0x00000, 0x1fb00},
1218 {"default-mac", 0x1fb00, 0x00200},
1219 {"pin", 0x1fd00, 0x00100},
1220 {"product-info", 0x1fe00, 0x00100},
1221 {"device-id", 0x1ff00, 0x00100},
1222 {"fs-uboot", 0x20000, 0x10000},
1223 {"firmware", 0x30000, 0x7a0000},
1224 {"soft-version", 0x7d9500, 0x00100},
1225 {"support-list", 0x7d9600, 0x00100},
1226 {"extra-para", 0x7d9700, 0x00100},
1227 {"profile", 0x7d9800, 0x03000},
1228 {"default-config", 0x7dc800, 0x03000},
1229 {"partition-table", 0x7df800, 0x00800},
1230 {"user-config", 0x7e0000, 0x0c000},
1231 {"certificate", 0x7ec000, 0x04000},
1232 {"radio", 0x7f0000, 0x10000},
1233 {NULL, 0, 0}
1234 },
1235
1236 .first_sysupgrade_partition = "os-image",
1237 .last_sysupgrade_partition = "file-system",
1238 },
1239
1240 /** Firmware layout for the C5 */
1241 {
1242 .id = "ARCHER-C5-V2",
1243 .vendor = "",
1244 .support_list =
1245 "SupportList:\r\n"
1246 "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
1247 "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
1248 "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
1249 .part_trail = 0x00,
1250 .soft_ver = NULL,
1251
1252 .partitions = {
1253 {"fs-uboot", 0x00000, 0x40000},
1254 {"os-image", 0x40000, 0x200000},
1255 {"file-system", 0x240000, 0xc00000},
1256 {"default-mac", 0xe40000, 0x00200},
1257 {"pin", 0xe40200, 0x00200},
1258 {"product-info", 0xe40400, 0x00200},
1259 {"partition-table", 0xe50000, 0x10000},
1260 {"soft-version", 0xe60000, 0x00200},
1261 {"support-list", 0xe61000, 0x0f000},
1262 {"profile", 0xe70000, 0x10000},
1263 {"default-config", 0xe80000, 0x10000},
1264 {"user-config", 0xe90000, 0x50000},
1265 {"log", 0xee0000, 0x100000},
1266 {"radio_bk", 0xfe0000, 0x10000},
1267 {"radio", 0xff0000, 0x10000},
1268 {NULL, 0, 0}
1269 },
1270
1271 .first_sysupgrade_partition = "os-image",
1272 .last_sysupgrade_partition = "file-system"
1273 },
1274
1275 /** Firmware layout for the C7 */
1276 {
1277 .id = "ARCHER-C7-V4",
1278 .support_list =
1279 "SupportList:\n"
1280 "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
1281 "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
1282 "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
1283 "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
1284 "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
1285 "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
1286 "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
1287 "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
1288 "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
1289 "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
1290 .part_trail = 0x00,
1291 .soft_ver = "soft_ver:1.0.0\n",
1292
1293 /* We're using a dynamic kernel/rootfs split here */
1294 .partitions = {
1295 {"factory-boot", 0x00000, 0x20000},
1296 {"fs-uboot", 0x20000, 0x20000},
1297 {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */
1298 /* Stock: name file-system base 0x160000 size 0xda0000 */
1299 {"default-mac", 0xf00000, 0x00200},
1300 {"pin", 0xf00200, 0x00200},
1301 {"device-id", 0xf00400, 0x00100},
1302 {"product-info", 0xf00500, 0x0fb00},
1303 {"soft-version", 0xf10000, 0x00100},
1304 {"extra-para", 0xf11000, 0x01000},
1305 {"support-list", 0xf12000, 0x0a000},
1306 {"profile", 0xf1c000, 0x04000},
1307 {"default-config", 0xf20000, 0x10000},
1308 {"user-config", 0xf30000, 0x40000},
1309 {"qos-db", 0xf70000, 0x40000},
1310 {"certificate", 0xfb0000, 0x10000},
1311 {"partition-table", 0xfc0000, 0x10000},
1312 {"log", 0xfd0000, 0x20000},
1313 {"radio", 0xff0000, 0x10000},
1314 {NULL, 0, 0}
1315 },
1316
1317 .first_sysupgrade_partition = "os-image",
1318 .last_sysupgrade_partition = "file-system",
1319 },
1320
1321 /** Firmware layout for the C7 v5*/
1322 {
1323 .id = "ARCHER-C7-V5",
1324 .support_list =
1325 "SupportList:\n"
1326 "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1327 "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1328 "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1329 "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1330 "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1331 "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1332 "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1333 "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1334
1335 .part_trail = 0x00,
1336 .soft_ver = "soft_ver:7.0.0\n",
1337
1338 /* We're using a dynamic kernel/rootfs split here */
1339 .partitions = {
1340 {"factory-boot", 0x00000, 0x20000},
1341 {"fs-uboot", 0x20000, 0x20000},
1342 {"partition-table", 0x40000, 0x10000},
1343 {"radio", 0x50000, 0x10000},
1344 {"default-mac", 0x60000, 0x00200},
1345 {"pin", 0x60200, 0x00200},
1346 {"device-id", 0x60400, 0x00100},
1347 {"product-info", 0x60500, 0x0fb00},
1348 {"soft-version", 0x70000, 0x01000},
1349 {"extra-para", 0x71000, 0x01000},
1350 {"support-list", 0x72000, 0x0a000},
1351 {"profile", 0x7c000, 0x04000},
1352 {"user-config", 0x80000, 0x40000},
1353
1354
1355 {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */
1356 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1357
1358 {"log", 0xfc0000, 0x20000},
1359 {"certificate", 0xfe0000, 0x10000},
1360 {"default-config", 0xff0000, 0x10000},
1361 {NULL, 0, 0}
1362
1363 },
1364
1365 .first_sysupgrade_partition = "os-image",
1366 .last_sysupgrade_partition = "file-system",
1367 },
1368
1369 /** Firmware layout for the C9 */
1370 {
1371 .id = "ARCHERC9",
1372 .vendor = "",
1373 .support_list =
1374 "SupportList:\n"
1375 "{product_name:ArcherC9,"
1376 "product_ver:1.0.0,"
1377 "special_id:00000000}\n",
1378 .part_trail = 0x00,
1379 .soft_ver = NULL,
1380
1381 .partitions = {
1382 {"fs-uboot", 0x00000, 0x40000},
1383 {"os-image", 0x40000, 0x200000},
1384 {"file-system", 0x240000, 0xc00000},
1385 {"default-mac", 0xe40000, 0x00200},
1386 {"pin", 0xe40200, 0x00200},
1387 {"product-info", 0xe40400, 0x00200},
1388 {"partition-table", 0xe50000, 0x10000},
1389 {"soft-version", 0xe60000, 0x00200},
1390 {"support-list", 0xe61000, 0x0f000},
1391 {"profile", 0xe70000, 0x10000},
1392 {"default-config", 0xe80000, 0x10000},
1393 {"user-config", 0xe90000, 0x50000},
1394 {"log", 0xee0000, 0x100000},
1395 {"radio_bk", 0xfe0000, 0x10000},
1396 {"radio", 0xff0000, 0x10000},
1397 {NULL, 0, 0}
1398 },
1399
1400 .first_sysupgrade_partition = "os-image",
1401 .last_sysupgrade_partition = "file-system"
1402 },
1403
1404 /** Firmware layout for the EAP120 */
1405 {
1406 .id = "EAP120",
1407 .vendor = "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1408 .support_list =
1409 "SupportList:\r\n"
1410 "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1411 .part_trail = 0xff,
1412 .soft_ver = NULL,
1413
1414 .partitions = {
1415 {"fs-uboot", 0x00000, 0x20000},
1416 {"partition-table", 0x20000, 0x02000},
1417 {"default-mac", 0x30000, 0x00020},
1418 {"support-list", 0x31000, 0x00100},
1419 {"product-info", 0x31100, 0x00100},
1420 {"soft-version", 0x32000, 0x00100},
1421 {"os-image", 0x40000, 0x180000},
1422 {"file-system", 0x1c0000, 0x600000},
1423 {"user-config", 0x7c0000, 0x10000},
1424 {"backup-config", 0x7d0000, 0x10000},
1425 {"log", 0x7e0000, 0x10000},
1426 {"radio", 0x7f0000, 0x10000},
1427 {NULL, 0, 0}
1428 },
1429
1430 .first_sysupgrade_partition = "os-image",
1431 .last_sysupgrade_partition = "file-system"
1432 },
1433
1434 /** Firmware layout for the EAP225-Outdoor v1 */
1435 {
1436 .id = "EAP225-OUTDOOR-V1",
1437 .support_list =
1438 "SupportList:\r\n"
1439 "EAP225-Outdoor(TP-Link|UN|AC1200-D):1.0\r\n",
1440 .part_trail = PART_TRAIL_NONE,
1441 .soft_ver = NULL,
1442 .soft_ver_compat_level = 1,
1443
1444 .partitions = {
1445 {"fs-uboot", 0x00000, 0x20000},
1446 {"partition-table", 0x20000, 0x02000},
1447 {"default-mac", 0x30000, 0x01000},
1448 {"support-list", 0x31000, 0x00100},
1449 {"product-info", 0x31100, 0x00400},
1450 {"soft-version", 0x32000, 0x00100},
1451 {"firmware", 0x40000, 0xd80000},
1452 {"user-config", 0xdc0000, 0x30000},
1453 {"mutil-log", 0xf30000, 0x80000},
1454 {"oops", 0xfb0000, 0x40000},
1455 {"radio", 0xff0000, 0x10000},
1456 {NULL, 0, 0}
1457 },
1458
1459 .first_sysupgrade_partition = "os-image",
1460 .last_sysupgrade_partition = "file-system"
1461 },
1462
1463 /** Firmware layout for the EAP225 v3 */
1464 {
1465 .id = "EAP225-V3",
1466 .support_list =
1467 "SupportList:\r\n"
1468 "EAP225(TP-Link|UN|AC1350-D):3.0\r\n",
1469 .part_trail = PART_TRAIL_NONE,
1470 .soft_ver = NULL,
1471 .soft_ver_compat_level = 1,
1472
1473 .partitions = {
1474 {"fs-uboot", 0x00000, 0x20000},
1475 {"partition-table", 0x20000, 0x02000},
1476 {"default-mac", 0x30000, 0x01000},
1477 {"support-list", 0x31000, 0x00100},
1478 {"product-info", 0x31100, 0x00400},
1479 {"soft-version", 0x32000, 0x00100},
1480 {"firmware", 0x40000, 0xd80000},
1481 {"user-config", 0xdc0000, 0x30000},
1482 {"mutil-log", 0xf30000, 0x80000},
1483 {"oops", 0xfb0000, 0x40000},
1484 {"radio", 0xff0000, 0x10000},
1485 {NULL, 0, 0}
1486 },
1487
1488 .first_sysupgrade_partition = "os-image",
1489 .last_sysupgrade_partition = "file-system"
1490 },
1491
1492 /** Firmware layout for the EAP225-Wall v2 */
1493 {
1494 .id = "EAP225-WALL-V2",
1495 .support_list =
1496 "SupportList:\r\n"
1497 "EAP225-Wall(TP-Link|UN|AC1200-D):2.0\r\n",
1498 .part_trail = PART_TRAIL_NONE,
1499 .soft_ver = NULL,
1500 .soft_ver_compat_level = 1,
1501
1502 .partitions = {
1503 {"fs-uboot", 0x00000, 0x20000},
1504 {"partition-table", 0x20000, 0x02000},
1505 {"default-mac", 0x30000, 0x01000},
1506 {"support-list", 0x31000, 0x00100},
1507 {"product-info", 0x31100, 0x00400},
1508 {"soft-version", 0x32000, 0x00100},
1509 {"firmware", 0x40000, 0xd80000},
1510 {"user-config", 0xdc0000, 0x30000},
1511 {"mutil-log", 0xf30000, 0x80000},
1512 {"oops", 0xfb0000, 0x40000},
1513 {"radio", 0xff0000, 0x10000},
1514 {NULL, 0, 0}
1515 },
1516
1517 .first_sysupgrade_partition = "os-image",
1518 .last_sysupgrade_partition = "file-system"
1519 },
1520
1521 /** Firmware layout for the EAP235-Wall v1 */
1522 {
1523 .id = "EAP235-WALL-V1",
1524 .support_list =
1525 "SupportList:\r\n"
1526 "EAP235-Wall(TP-Link|UN|AC1200-D):1.0\r\n",
1527 .part_trail = PART_TRAIL_NONE,
1528 .soft_ver = NULL,
1529 .soft_ver_compat_level = 1,
1530
1531 .partitions = {
1532 {"fs-uboot", 0x00000, 0x80000},
1533 {"partition-table", 0x80000, 0x02000},
1534 {"default-mac", 0x90000, 0x01000},
1535 {"support-list", 0x91000, 0x00100},
1536 {"product-info", 0x91100, 0x00400},
1537 {"soft-version", 0x92000, 0x00100},
1538 {"firmware", 0xa0000, 0xd20000},
1539 {"user-config", 0xdc0000, 0x30000},
1540 {"mutil-log", 0xf30000, 0x80000},
1541 {"oops", 0xfb0000, 0x40000},
1542 {"radio", 0xff0000, 0x10000},
1543 {NULL, 0, 0}
1544 },
1545
1546 .first_sysupgrade_partition = "os-image",
1547 .last_sysupgrade_partition = "file-system"
1548 },
1549
1550 /** Firmware layout for the EAP245 v1 */
1551 {
1552 .id = "EAP245-V1",
1553 .support_list =
1554 "SupportList:\r\n"
1555 "EAP245(TP-LINK|UN|AC1750-D):1.0\r\n",
1556 .part_trail = PART_TRAIL_NONE,
1557 .soft_ver = NULL,
1558
1559 .partitions = {
1560 {"fs-uboot", 0x00000, 0x20000},
1561 {"partition-table", 0x20000, 0x02000},
1562 {"default-mac", 0x30000, 0x01000},
1563 {"support-list", 0x31000, 0x00100},
1564 {"product-info", 0x31100, 0x00400},
1565 {"soft-version", 0x32000, 0x00100},
1566 {"firmware", 0x40000, 0xd80000},
1567 {"user-config", 0xdc0000, 0x30000},
1568 {"radio", 0xff0000, 0x10000},
1569 {NULL, 0, 0}
1570 },
1571
1572 .first_sysupgrade_partition = "os-image",
1573 .last_sysupgrade_partition = "file-system"
1574 },
1575
1576 /** Firmware layout for the EAP245 v3 */
1577 {
1578 .id = "EAP245-V3",
1579 .support_list =
1580 "SupportList:\r\n"
1581 "EAP245(TP-Link|UN|AC1750-D):3.0\r\n",
1582 .part_trail = PART_TRAIL_NONE,
1583 .soft_ver = NULL,
1584 .soft_ver_compat_level = 1,
1585
1586 /** Firmware partition with dynamic kernel/rootfs split */
1587 .partitions = {
1588 {"factroy-boot", 0x00000, 0x40000},
1589 {"fs-uboot", 0x40000, 0x40000},
1590 {"partition-table", 0x80000, 0x10000},
1591 {"default-mac", 0x90000, 0x01000},
1592 {"support-list", 0x91000, 0x00100},
1593 {"product-info", 0x91100, 0x00400},
1594 {"soft-version", 0x92000, 0x00100},
1595 {"radio", 0xa0000, 0x10000},
1596 {"extra-para", 0xb0000, 0x10000},
1597 {"firmware", 0xc0000, 0xe40000},
1598 {"config", 0xf00000, 0x30000},
1599 {"mutil-log", 0xf30000, 0x80000},
1600 {"oops", 0xfb0000, 0x40000},
1601 {NULL, 0, 0}
1602 },
1603
1604 .first_sysupgrade_partition = "os-image",
1605 .last_sysupgrade_partition = "file-system"
1606 },
1607
1608 /** Firmware layout for the TL-WA850RE v2 */
1609 {
1610 .id = "TLWA850REV2",
1611 .vendor = "",
1612 .support_list =
1613 "SupportList:\n"
1614 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
1615 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
1616 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
1617 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
1618 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
1619 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
1620 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
1621 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
1622 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
1623 "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
1624 .part_trail = 0x00,
1625 .soft_ver = NULL,
1626
1627 /**
1628 576KB were moved from file-system to os-image
1629 in comparison to the stock image
1630 */
1631 .partitions = {
1632 {"fs-uboot", 0x00000, 0x20000},
1633 {"firmware", 0x20000, 0x390000},
1634 {"partition-table", 0x3b0000, 0x02000},
1635 {"default-mac", 0x3c0000, 0x00020},
1636 {"pin", 0x3c0100, 0x00020},
1637 {"product-info", 0x3c1000, 0x01000},
1638 {"soft-version", 0x3c2000, 0x00100},
1639 {"support-list", 0x3c3000, 0x01000},
1640 {"profile", 0x3c4000, 0x08000},
1641 {"user-config", 0x3d0000, 0x10000},
1642 {"default-config", 0x3e0000, 0x10000},
1643 {"radio", 0x3f0000, 0x10000},
1644 {NULL, 0, 0}
1645 },
1646
1647 .first_sysupgrade_partition = "os-image",
1648 .last_sysupgrade_partition = "file-system"
1649 },
1650
1651 /** Firmware layout for the TL-WA855RE v1 */
1652 {
1653 .id = "TLWA855REV1",
1654 .vendor = "",
1655 .support_list =
1656 "SupportList:\n"
1657 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
1658 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
1659 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
1660 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
1661 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
1662 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
1663 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
1664 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
1665 "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
1666 .part_trail = 0x00,
1667 .soft_ver = NULL,
1668
1669 .partitions = {
1670 {"fs-uboot", 0x00000, 0x20000},
1671 {"os-image", 0x20000, 0x150000},
1672 {"file-system", 0x170000, 0x240000},
1673 {"partition-table", 0x3b0000, 0x02000},
1674 {"default-mac", 0x3c0000, 0x00020},
1675 {"pin", 0x3c0100, 0x00020},
1676 {"product-info", 0x3c1000, 0x01000},
1677 {"soft-version", 0x3c2000, 0x00100},
1678 {"support-list", 0x3c3000, 0x01000},
1679 {"profile", 0x3c4000, 0x08000},
1680 {"user-config", 0x3d0000, 0x10000},
1681 {"default-config", 0x3e0000, 0x10000},
1682 {"radio", 0x3f0000, 0x10000},
1683 {NULL, 0, 0}
1684 },
1685
1686 .first_sysupgrade_partition = "os-image",
1687 .last_sysupgrade_partition = "file-system"
1688 },
1689
1690 /** Firmware layout for the TL-WPA8630P v2 (EU)*/
1691 {
1692 .id = "TL-WPA8630P-V2.0-EU",
1693 .vendor = "",
1694 .support_list =
1695 "SupportList:\n"
1696 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
1697 .part_trail = 0x00,
1698 .soft_ver = NULL,
1699
1700 .partitions = {
1701 {"factory-uboot", 0x00000, 0x20000},
1702 {"fs-uboot", 0x20000, 0x20000},
1703 {"firmware", 0x40000, 0x5e0000},
1704 {"partition-table", 0x620000, 0x02000},
1705 {"default-mac", 0x630000, 0x00020},
1706 {"pin", 0x630100, 0x00020},
1707 {"device-id", 0x630200, 0x00030},
1708 {"product-info", 0x631100, 0x01000},
1709 {"extra-para", 0x632100, 0x01000},
1710 {"soft-version", 0x640000, 0x01000},
1711 {"support-list", 0x641000, 0x01000},
1712 {"profile", 0x642000, 0x08000},
1713 {"user-config", 0x650000, 0x10000},
1714 {"default-config", 0x660000, 0x10000},
1715 {"default-nvm", 0x670000, 0xc0000},
1716 {"default-pib", 0x730000, 0x40000},
1717 {"radio", 0x7f0000, 0x10000},
1718 {NULL, 0, 0}
1719 },
1720
1721 .first_sysupgrade_partition = "os-image",
1722 .last_sysupgrade_partition = "file-system"
1723 },
1724
1725 /** Firmware layout for the TL-WPA8630P v2 (INT)*/
1726 {
1727 .id = "TL-WPA8630P-V2-INT",
1728 .vendor = "",
1729 .support_list =
1730 "SupportList:\n"
1731 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
1732 "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
1733 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
1734 .part_trail = 0x00,
1735 .soft_ver = NULL,
1736
1737 .partitions = {
1738 {"factory-uboot", 0x00000, 0x20000},
1739 {"fs-uboot", 0x20000, 0x20000},
1740 {"firmware", 0x40000, 0x5e0000},
1741 {"partition-table", 0x620000, 0x02000},
1742 {"extra-para", 0x632100, 0x01000},
1743 {"soft-version", 0x640000, 0x01000},
1744 {"support-list", 0x641000, 0x01000},
1745 {"profile", 0x642000, 0x08000},
1746 {"user-config", 0x650000, 0x10000},
1747 {"default-config", 0x660000, 0x10000},
1748 {"default-nvm", 0x670000, 0xc0000},
1749 {"default-pib", 0x730000, 0x40000},
1750 {"default-mac", 0x7e0000, 0x00020},
1751 {"pin", 0x7e0100, 0x00020},
1752 {"device-id", 0x7e0200, 0x00030},
1753 {"product-info", 0x7e1100, 0x01000},
1754 {"radio", 0x7f0000, 0x10000},
1755 {NULL, 0, 0}
1756 },
1757
1758 .first_sysupgrade_partition = "os-image",
1759 .last_sysupgrade_partition = "file-system"
1760 },
1761
1762 /** Firmware layout for the TL-WPA8630P v2.1 (EU)*/
1763 {
1764 .id = "TL-WPA8630P-V2.1-EU",
1765 .vendor = "",
1766 .support_list =
1767 "SupportList:\n"
1768 "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n",
1769 .part_trail = 0x00,
1770 .soft_ver = NULL,
1771
1772 .partitions = {
1773 {"factory-uboot", 0x00000, 0x20000},
1774 {"fs-uboot", 0x20000, 0x20000},
1775 {"firmware", 0x40000, 0x5e0000},
1776 {"extra-para", 0x680000, 0x01000},
1777 {"product-info", 0x690000, 0x01000},
1778 {"partition-table", 0x6a0000, 0x02000},
1779 {"soft-version", 0x6b0000, 0x01000},
1780 {"support-list", 0x6b1000, 0x01000},
1781 {"profile", 0x6b2000, 0x08000},
1782 {"user-config", 0x6c0000, 0x10000},
1783 {"default-config", 0x6d0000, 0x10000},
1784 {"default-nvm", 0x6e0000, 0xc0000},
1785 {"default-pib", 0x7a0000, 0x40000},
1786 {"default-mac", 0x7e0000, 0x00020},
1787 {"pin", 0x7e0100, 0x00020},
1788 {"device-id", 0x7e0200, 0x00030},
1789 {"radio", 0x7f0000, 0x10000},
1790 {NULL, 0, 0}
1791 },
1792
1793 .first_sysupgrade_partition = "os-image",
1794 .last_sysupgrade_partition = "file-system"
1795 },
1796
1797 /** Firmware layout for the TL-WR1043 v5 */
1798 {
1799 .id = "TLWR1043NV5",
1800 .vendor = "",
1801 .support_list =
1802 "SupportList:\n"
1803 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
1804 "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
1805 .part_trail = 0x00,
1806 .soft_ver = "soft_ver:1.0.0\n",
1807 .partitions = {
1808 {"factory-boot", 0x00000, 0x20000},
1809 {"fs-uboot", 0x20000, 0x20000},
1810 {"firmware", 0x40000, 0xec0000},
1811 {"default-mac", 0xf00000, 0x00200},
1812 {"pin", 0xf00200, 0x00200},
1813 {"device-id", 0xf00400, 0x00100},
1814 {"product-info", 0xf00500, 0x0fb00},
1815 {"soft-version", 0xf10000, 0x01000},
1816 {"extra-para", 0xf11000, 0x01000},
1817 {"support-list", 0xf12000, 0x0a000},
1818 {"profile", 0xf1c000, 0x04000},
1819 {"default-config", 0xf20000, 0x10000},
1820 {"user-config", 0xf30000, 0x40000},
1821 {"qos-db", 0xf70000, 0x40000},
1822 {"certificate", 0xfb0000, 0x10000},
1823 {"partition-table", 0xfc0000, 0x10000},
1824 {"log", 0xfd0000, 0x20000},
1825 {"radio", 0xff0000, 0x10000},
1826 {NULL, 0, 0}
1827 },
1828 .first_sysupgrade_partition = "os-image",
1829 .last_sysupgrade_partition = "file-system"
1830 },
1831
1832 /** Firmware layout for the TL-WR1043 v4 */
1833 {
1834 .id = "TLWR1043NDV4",
1835 .vendor = "",
1836 .support_list =
1837 "SupportList:\n"
1838 "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
1839 .part_trail = 0x00,
1840 .soft_ver = NULL,
1841
1842 /* We're using a dynamic kernel/rootfs split here */
1843 .partitions = {
1844 {"fs-uboot", 0x00000, 0x20000},
1845 {"firmware", 0x20000, 0xf30000},
1846 {"default-mac", 0xf50000, 0x00200},
1847 {"pin", 0xf50200, 0x00200},
1848 {"product-info", 0xf50400, 0x0fc00},
1849 {"soft-version", 0xf60000, 0x0b000},
1850 {"support-list", 0xf6b000, 0x04000},
1851 {"profile", 0xf70000, 0x04000},
1852 {"default-config", 0xf74000, 0x0b000},
1853 {"user-config", 0xf80000, 0x40000},
1854 {"partition-table", 0xfc0000, 0x10000},
1855 {"log", 0xfd0000, 0x20000},
1856 {"radio", 0xff0000, 0x10000},
1857 {NULL, 0, 0}
1858 },
1859
1860 .first_sysupgrade_partition = "os-image",
1861 .last_sysupgrade_partition = "file-system"
1862 },
1863
1864 /** Firmware layout for the TL-WR902AC v1 */
1865 {
1866 .id = "TL-WR902AC-V1",
1867 .vendor = "",
1868 .support_list =
1869 "SupportList:\n"
1870 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
1871 "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
1872 .part_trail = 0x00,
1873 .soft_ver = NULL,
1874
1875 /**
1876 384KB were moved from file-system to os-image
1877 in comparison to the stock image
1878 */
1879 .partitions = {
1880 {"fs-uboot", 0x00000, 0x20000},
1881 {"firmware", 0x20000, 0x730000},
1882 {"default-mac", 0x750000, 0x00200},
1883 {"pin", 0x750200, 0x00200},
1884 {"product-info", 0x750400, 0x0fc00},
1885 {"soft-version", 0x760000, 0x0b000},
1886 {"support-list", 0x76b000, 0x04000},
1887 {"profile", 0x770000, 0x04000},
1888 {"default-config", 0x774000, 0x0b000},
1889 {"user-config", 0x780000, 0x40000},
1890 {"partition-table", 0x7c0000, 0x10000},
1891 {"log", 0x7d0000, 0x20000},
1892 {"radio", 0x7f0000, 0x10000},
1893 {NULL, 0, 0}
1894 },
1895
1896 .first_sysupgrade_partition = "os-image",
1897 .last_sysupgrade_partition = "file-system",
1898 },
1899
1900 /** Firmware layout for the TL-WR942N V1 */
1901 {
1902 .id = "TLWR942NV1",
1903 .vendor = "",
1904 .support_list =
1905 "SupportList:\r\n"
1906 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
1907 "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
1908 .part_trail = 0x00,
1909 .soft_ver = NULL,
1910
1911 .partitions = {
1912 {"fs-uboot", 0x00000, 0x20000},
1913 {"firmware", 0x20000, 0xe20000},
1914 {"default-mac", 0xe40000, 0x00200},
1915 {"pin", 0xe40200, 0x00200},
1916 {"product-info", 0xe40400, 0x0fc00},
1917 {"partition-table", 0xe50000, 0x10000},
1918 {"soft-version", 0xe60000, 0x10000},
1919 {"support-list", 0xe70000, 0x10000},
1920 {"profile", 0xe80000, 0x10000},
1921 {"default-config", 0xe90000, 0x10000},
1922 {"user-config", 0xea0000, 0x40000},
1923 {"qos-db", 0xee0000, 0x40000},
1924 {"certificate", 0xf20000, 0x10000},
1925 {"usb-config", 0xfb0000, 0x10000},
1926 {"log", 0xfc0000, 0x20000},
1927 {"radio-bk", 0xfe0000, 0x10000},
1928 {"radio", 0xff0000, 0x10000},
1929 {NULL, 0, 0}
1930 },
1931
1932 .first_sysupgrade_partition = "os-image",
1933 .last_sysupgrade_partition = "file-system",
1934 },
1935
1936 /** Firmware layout for the RE200 v2 */
1937 {
1938 .id = "RE200-V2",
1939 .vendor = "",
1940 .support_list =
1941 "SupportList:\n"
1942 "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
1943 "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
1944 "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
1945 "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
1946 "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
1947 "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
1948 "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
1949 "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
1950 "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
1951 "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
1952 "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
1953 "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
1954 "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
1955 .part_trail = 0x00,
1956 .soft_ver = NULL,
1957
1958 .partitions = {
1959 {"fs-uboot", 0x00000, 0x20000},
1960 {"firmware", 0x20000, 0x7a0000},
1961 {"partition-table", 0x7c0000, 0x02000},
1962 {"default-mac", 0x7c2000, 0x00020},
1963 {"pin", 0x7c2100, 0x00020},
1964 {"product-info", 0x7c3100, 0x01000},
1965 {"soft-version", 0x7c4200, 0x01000},
1966 {"support-list", 0x7c5200, 0x01000},
1967 {"profile", 0x7c6200, 0x08000},
1968 {"config-info", 0x7ce200, 0x00400},
1969 {"user-config", 0x7d0000, 0x10000},
1970 {"default-config", 0x7e0000, 0x10000},
1971 {"radio", 0x7f0000, 0x10000},
1972 {NULL, 0, 0}
1973 },
1974
1975 .first_sysupgrade_partition = "os-image",
1976 .last_sysupgrade_partition = "file-system"
1977 },
1978
1979 /** Firmware layout for the RE200 v3 */
1980 {
1981 .id = "RE200-V3",
1982 .vendor = "",
1983 .support_list =
1984 "SupportList:\n"
1985 "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
1986 "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
1987 "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
1988 "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
1989 "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
1990 "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
1991 "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
1992 "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
1993 "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
1994 "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
1995 "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
1996 "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
1997 "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
1998 "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
1999 .part_trail = 0x00,
2000 .soft_ver = NULL,
2001
2002 .partitions = {
2003 {"fs-uboot", 0x00000, 0x20000},
2004 {"firmware", 0x20000, 0x7a0000},
2005 {"partition-table", 0x7c0000, 0x02000},
2006 {"default-mac", 0x7c2000, 0x00020},
2007 {"pin", 0x7c2100, 0x00020},
2008 {"product-info", 0x7c3100, 0x01000},
2009 {"soft-version", 0x7c4200, 0x01000},
2010 {"support-list", 0x7c5200, 0x01000},
2011 {"profile", 0x7c6200, 0x08000},
2012 {"config-info", 0x7ce200, 0x00400},
2013 {"user-config", 0x7d0000, 0x10000},
2014 {"default-config", 0x7e0000, 0x10000},
2015 {"radio", 0x7f0000, 0x10000},
2016 {NULL, 0, 0}
2017 },
2018
2019 .first_sysupgrade_partition = "os-image",
2020 .last_sysupgrade_partition = "file-system"
2021 },
2022
2023 /** Firmware layout for the RE200 v4 */
2024 {
2025 .id = "RE200-V4",
2026 .vendor = "",
2027 .support_list =
2028 "SupportList:\n"
2029 "{product_name:RE200,product_ver:4.0.0,special_id:00000000}\n"
2030 "{product_name:RE200,product_ver:4.0.0,special_id:45550000}\n"
2031 "{product_name:RE200,product_ver:4.0.0,special_id:4A500000}\n"
2032 "{product_name:RE200,product_ver:4.0.0,special_id:4B520000}\n"
2033 "{product_name:RE200,product_ver:4.0.0,special_id:43410000}\n"
2034 "{product_name:RE200,product_ver:4.0.0,special_id:41550000}\n"
2035 "{product_name:RE200,product_ver:4.0.0,special_id:42520000}\n"
2036 "{product_name:RE200,product_ver:4.0.0,special_id:55530000}\n"
2037 "{product_name:RE200,product_ver:4.0.0,special_id:41520000}\n"
2038 "{product_name:RE200,product_ver:4.0.0,special_id:52550000}\n"
2039 "{product_name:RE200,product_ver:4.0.0,special_id:54570000}\n"
2040 "{product_name:RE200,product_ver:4.0.0,special_id:45530000}\n"
2041 "{product_name:RE200,product_ver:4.0.0,special_id:49440000}\n"
2042 "{product_name:RE200,product_ver:4.0.0,special_id:45470000}\n",
2043 .part_trail = 0x00,
2044 .soft_ver = "soft_ver:1.1.0\n",
2045
2046 .partitions = {
2047 {"fs-uboot", 0x00000, 0x20000},
2048 {"firmware", 0x20000, 0x7a0000},
2049 {"partition-table", 0x7c0000, 0x02000},
2050 {"default-mac", 0x7c2000, 0x00020},
2051 {"pin", 0x7c2100, 0x00020},
2052 {"product-info", 0x7c3100, 0x01000},
2053 {"soft-version", 0x7c4200, 0x01000},
2054 {"support-list", 0x7c5200, 0x01000},
2055 {"profile", 0x7c6200, 0x08000},
2056 {"config-info", 0x7ce200, 0x00400},
2057 {"user-config", 0x7d0000, 0x10000},
2058 {"default-config", 0x7e0000, 0x10000},
2059 {"radio", 0x7f0000, 0x10000},
2060 {NULL, 0, 0}
2061 },
2062
2063 .first_sysupgrade_partition = "os-image",
2064 .last_sysupgrade_partition = "file-system"
2065 },
2066
2067 /** Firmware layout for the RE220 v2 */
2068 {
2069 .id = "RE220-V2",
2070 .vendor = "",
2071 .support_list =
2072 "SupportList:\n"
2073 "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
2074 "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
2075 "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
2076 "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
2077 "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
2078 "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
2079 "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
2080 "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
2081 "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
2082 "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
2083 "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
2084 "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
2085 "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
2086 .part_trail = 0x00,
2087 .soft_ver = NULL,
2088
2089 .partitions = {
2090 {"fs-uboot", 0x00000, 0x20000},
2091 {"firmware", 0x20000, 0x7a0000},
2092 {"partition-table", 0x7c0000, 0x02000},
2093 {"default-mac", 0x7c2000, 0x00020},
2094 {"pin", 0x7c2100, 0x00020},
2095 {"product-info", 0x7c3100, 0x01000},
2096 {"soft-version", 0x7c4200, 0x01000},
2097 {"support-list", 0x7c5200, 0x01000},
2098 {"profile", 0x7c6200, 0x08000},
2099 {"config-info", 0x7ce200, 0x00400},
2100 {"user-config", 0x7d0000, 0x10000},
2101 {"default-config", 0x7e0000, 0x10000},
2102 {"radio", 0x7f0000, 0x10000},
2103 {NULL, 0, 0}
2104 },
2105
2106 .first_sysupgrade_partition = "os-image",
2107 .last_sysupgrade_partition = "file-system"
2108 },
2109
2110 /** Firmware layout for the RE305 v1 */
2111 {
2112 .id = "RE305-V1",
2113 .vendor = "",
2114 .support_list =
2115 "SupportList:\n"
2116 "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
2117 "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
2118 "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
2119 "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
2120 "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
2121 "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
2122 "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
2123 .part_trail = 0x00,
2124 .soft_ver = NULL,
2125
2126 .partitions = {
2127 {"fs-uboot", 0x00000, 0x20000},
2128 {"firmware", 0x20000, 0x5e0000},
2129 {"partition-table", 0x600000, 0x02000},
2130 {"default-mac", 0x610000, 0x00020},
2131 {"pin", 0x610100, 0x00020},
2132 {"product-info", 0x611100, 0x01000},
2133 {"soft-version", 0x620000, 0x01000},
2134 {"support-list", 0x621000, 0x01000},
2135 {"profile", 0x622000, 0x08000},
2136 {"user-config", 0x630000, 0x10000},
2137 {"default-config", 0x640000, 0x10000},
2138 {"radio", 0x7f0000, 0x10000},
2139 {NULL, 0, 0}
2140 },
2141
2142 .first_sysupgrade_partition = "os-image",
2143 .last_sysupgrade_partition = "file-system"
2144 },
2145
2146 /** Firmware layout for the RE350 v1 */
2147 {
2148 .id = "RE350-V1",
2149 .vendor = "",
2150 .support_list =
2151 "SupportList:\n"
2152 "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
2153 "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
2154 "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
2155 "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
2156 "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
2157 "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
2158 "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
2159 .part_trail = 0x00,
2160 .soft_ver = NULL,
2161
2162 /** We're using a dynamic kernel/rootfs split here */
2163 .partitions = {
2164 {"fs-uboot", 0x00000, 0x20000},
2165 {"firmware", 0x20000, 0x5e0000},
2166 {"partition-table", 0x600000, 0x02000},
2167 {"default-mac", 0x610000, 0x00020},
2168 {"pin", 0x610100, 0x00020},
2169 {"product-info", 0x611100, 0x01000},
2170 {"soft-version", 0x620000, 0x01000},
2171 {"support-list", 0x621000, 0x01000},
2172 {"profile", 0x622000, 0x08000},
2173 {"user-config", 0x630000, 0x10000},
2174 {"default-config", 0x640000, 0x10000},
2175 {"radio", 0x7f0000, 0x10000},
2176 {NULL, 0, 0}
2177 },
2178
2179 .first_sysupgrade_partition = "os-image",
2180 .last_sysupgrade_partition = "file-system"
2181 },
2182
2183 /** Firmware layout for the RE350K v1 */
2184 {
2185 .id = "RE350K-V1",
2186 .vendor = "",
2187 .support_list =
2188 "SupportList:\n"
2189 "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
2190 .part_trail = 0x00,
2191 .soft_ver = NULL,
2192
2193 /** We're using a dynamic kernel/rootfs split here */
2194 .partitions = {
2195 {"fs-uboot", 0x00000, 0x20000},
2196 {"firmware", 0x20000, 0xd70000},
2197 {"partition-table", 0xd90000, 0x02000},
2198 {"default-mac", 0xda0000, 0x00020},
2199 {"pin", 0xda0100, 0x00020},
2200 {"product-info", 0xda1100, 0x01000},
2201 {"soft-version", 0xdb0000, 0x01000},
2202 {"support-list", 0xdb1000, 0x01000},
2203 {"profile", 0xdb2000, 0x08000},
2204 {"user-config", 0xdc0000, 0x10000},
2205 {"default-config", 0xdd0000, 0x10000},
2206 {"device-id", 0xde0000, 0x00108},
2207 {"radio", 0xff0000, 0x10000},
2208 {NULL, 0, 0}
2209 },
2210
2211 .first_sysupgrade_partition = "os-image",
2212 .last_sysupgrade_partition = "file-system"
2213 },
2214
2215 /** Firmware layout for the RE355 */
2216 {
2217 .id = "RE355",
2218 .vendor = "",
2219 .support_list =
2220 "SupportList:\r\n"
2221 "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
2222 "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
2223 "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
2224 "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
2225 "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
2226 "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
2227 "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
2228 "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
2229 .part_trail = 0x00,
2230 .soft_ver = NULL,
2231
2232 /* We're using a dynamic kernel/rootfs split here */
2233 .partitions = {
2234 {"fs-uboot", 0x00000, 0x20000},
2235 {"firmware", 0x20000, 0x5e0000},
2236 {"partition-table", 0x600000, 0x02000},
2237 {"default-mac", 0x610000, 0x00020},
2238 {"pin", 0x610100, 0x00020},
2239 {"product-info", 0x611100, 0x01000},
2240 {"soft-version", 0x620000, 0x01000},
2241 {"support-list", 0x621000, 0x01000},
2242 {"profile", 0x622000, 0x08000},
2243 {"user-config", 0x630000, 0x10000},
2244 {"default-config", 0x640000, 0x10000},
2245 {"radio", 0x7f0000, 0x10000},
2246 {NULL, 0, 0}
2247 },
2248
2249 .first_sysupgrade_partition = "os-image",
2250 .last_sysupgrade_partition = "file-system"
2251 },
2252
2253 /** Firmware layout for the RE450 */
2254 {
2255 .id = "RE450",
2256 .vendor = "",
2257 .support_list =
2258 "SupportList:\r\n"
2259 "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
2260 "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
2261 "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
2262 "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
2263 "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
2264 "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
2265 "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
2266 "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
2267 .part_trail = 0x00,
2268 .soft_ver = NULL,
2269
2270 /** We're using a dynamic kernel/rootfs split here */
2271 .partitions = {
2272 {"fs-uboot", 0x00000, 0x20000},
2273 {"firmware", 0x20000, 0x5e0000},
2274 {"partition-table", 0x600000, 0x02000},
2275 {"default-mac", 0x610000, 0x00020},
2276 {"pin", 0x610100, 0x00020},
2277 {"product-info", 0x611100, 0x01000},
2278 {"soft-version", 0x620000, 0x01000},
2279 {"support-list", 0x621000, 0x01000},
2280 {"profile", 0x622000, 0x08000},
2281 {"user-config", 0x630000, 0x10000},
2282 {"default-config", 0x640000, 0x10000},
2283 {"radio", 0x7f0000, 0x10000},
2284 {NULL, 0, 0}
2285 },
2286
2287 .first_sysupgrade_partition = "os-image",
2288 .last_sysupgrade_partition = "file-system"
2289 },
2290
2291 /** Firmware layout for the RE450 v2 */
2292 {
2293 .id = "RE450-V2",
2294 .vendor = "",
2295 .support_list =
2296 "SupportList:\r\n"
2297 "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
2298 "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
2299 "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
2300 "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
2301 "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
2302 "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
2303 "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
2304 "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
2305 "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
2306 .part_trail = 0x00,
2307 .soft_ver = NULL,
2308
2309 /* We're using a dynamic kernel/rootfs split here */
2310 .partitions = {
2311 {"fs-uboot", 0x00000, 0x20000},
2312 {"firmware", 0x20000, 0x5e0000},
2313 {"partition-table", 0x600000, 0x02000},
2314 {"default-mac", 0x610000, 0x00020},
2315 {"pin", 0x610100, 0x00020},
2316 {"product-info", 0x611100, 0x01000},
2317 {"soft-version", 0x620000, 0x01000},
2318 {"support-list", 0x621000, 0x01000},
2319 {"profile", 0x622000, 0x08000},
2320 {"user-config", 0x630000, 0x10000},
2321 {"default-config", 0x640000, 0x10000},
2322 {"radio", 0x7f0000, 0x10000},
2323 {NULL, 0, 0}
2324 },
2325
2326 .first_sysupgrade_partition = "os-image",
2327 .last_sysupgrade_partition = "file-system"
2328 },
2329
2330 /** Firmware layout for the RE450 v3 */
2331 {
2332 .id = "RE450-V3",
2333 .vendor = "",
2334 .support_list =
2335 "SupportList:\r\n"
2336 "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
2337 "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
2338 "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
2339 "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
2340 "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
2341 "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
2342 "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
2343 "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
2344 "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
2345 .part_trail = 0x00,
2346 .soft_ver = NULL,
2347
2348 /* We're using a dynamic kernel/rootfs split here */
2349 .partitions = {
2350 {"fs-uboot", 0x00000, 0x20000},
2351 {"default-mac", 0x20000, 0x00020},
2352 {"pin", 0x20020, 0x00020},
2353 {"product-info", 0x21000, 0x01000},
2354 {"partition-table", 0x22000, 0x02000},
2355 {"soft-version", 0x24000, 0x01000},
2356 {"support-list", 0x25000, 0x01000},
2357 {"profile", 0x26000, 0x08000},
2358 {"user-config", 0x2e000, 0x10000},
2359 {"default-config", 0x3e000, 0x10000},
2360 {"config-info", 0x4e000, 0x00400},
2361 {"firmware", 0x50000, 0x7a0000},
2362 {"radio", 0x7f0000, 0x10000},
2363 {NULL, 0, 0}
2364 },
2365
2366 .first_sysupgrade_partition = "os-image",
2367 .last_sysupgrade_partition = "file-system"
2368 },
2369
2370 /** Firmware layout for the RE500 */
2371 {
2372 .id = "RE500-V1",
2373 .vendor = "",
2374 .support_list =
2375 "SupportList:\r\n"
2376 "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
2377 "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
2378 "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
2379 "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
2380 "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
2381 "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
2382 "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
2383 .part_trail = 0x00,
2384 .soft_ver = NULL,
2385
2386 /* We're using a dynamic kernel/rootfs split here */
2387 .partitions = {
2388 {"fs-uboot", 0x00000, 0x20000},
2389 {"firmware", 0x20000, 0xde0000},
2390 {"partition-table", 0xe00000, 0x02000},
2391 {"default-mac", 0xe10000, 0x00020},
2392 {"pin", 0xe10100, 0x00020},
2393 {"product-info", 0xe11100, 0x01000},
2394 {"soft-version", 0xe20000, 0x01000},
2395 {"support-list", 0xe21000, 0x01000},
2396 {"profile", 0xe22000, 0x08000},
2397 {"user-config", 0xe30000, 0x10000},
2398 {"default-config", 0xe40000, 0x10000},
2399 {"radio", 0xff0000, 0x10000},
2400 {NULL, 0, 0}
2401 },
2402
2403 .first_sysupgrade_partition = "os-image",
2404 .last_sysupgrade_partition = "file-system"
2405 },
2406
2407 /** Firmware layout for the RE650 */
2408 {
2409 .id = "RE650-V1",
2410 .vendor = "",
2411 .support_list =
2412 "SupportList:\r\n"
2413 "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
2414 "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
2415 "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
2416 "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
2417 "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
2418 "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
2419 "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
2420 .part_trail = 0x00,
2421 .soft_ver = NULL,
2422
2423 /* We're using a dynamic kernel/rootfs split here */
2424 .partitions = {
2425 {"fs-uboot", 0x00000, 0x20000},
2426 {"firmware", 0x20000, 0xde0000},
2427 {"partition-table", 0xe00000, 0x02000},
2428 {"default-mac", 0xe10000, 0x00020},
2429 {"pin", 0xe10100, 0x00020},
2430 {"product-info", 0xe11100, 0x01000},
2431 {"soft-version", 0xe20000, 0x01000},
2432 {"support-list", 0xe21000, 0x01000},
2433 {"profile", 0xe22000, 0x08000},
2434 {"user-config", 0xe30000, 0x10000},
2435 {"default-config", 0xe40000, 0x10000},
2436 {"radio", 0xff0000, 0x10000},
2437 {NULL, 0, 0}
2438 },
2439
2440 .first_sysupgrade_partition = "os-image",
2441 .last_sysupgrade_partition = "file-system"
2442 },
2443
2444 {}
2445 };
2446
2447 #define error(_ret, _errno, _str, ...) \
2448 do { \
2449 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
2450 strerror(_errno)); \
2451 if (_ret) \
2452 exit(_ret); \
2453 } while (0)
2454
2455
2456 /** Stores a uint32 as big endian */
2457 static inline void put32(uint8_t *buf, uint32_t val) {
2458 buf[0] = val >> 24;
2459 buf[1] = val >> 16;
2460 buf[2] = val >> 8;
2461 buf[3] = val;
2462 }
2463
2464 static inline bool meta_partition_should_pad(enum partition_trail_value pv)
2465 {
2466 return (pv >= 0) && (pv <= PART_TRAIL_MAX);
2467 }
2468
2469 /** Allocate a padded meta partition with a correctly initialised header
2470 * If the `data` pointer is NULL, then the required space is only allocated,
2471 * otherwise `data_len` bytes will be copied from `data` into the partition
2472 * entry. */
2473 static struct image_partition_entry init_meta_partition_entry(
2474 const char *name, const void *data, uint32_t data_len,
2475 enum partition_trail_value pad_value)
2476 {
2477 uint32_t total_len = sizeof(struct meta_header) + data_len;
2478 if (meta_partition_should_pad(pad_value))
2479 total_len += 1;
2480
2481 struct image_partition_entry entry = {
2482 .name = name,
2483 .size = total_len,
2484 .data = malloc(total_len)
2485 };
2486 if (!entry.data)
2487 error(1, errno, "failed to allocate meta partition entry");
2488
2489 struct meta_header *header = (struct meta_header *)entry.data;
2490 header->length = htonl(data_len);
2491 header->zero = 0;
2492
2493 if (data)
2494 memcpy(entry.data+sizeof(*header), data, data_len);
2495
2496 if (meta_partition_should_pad(pad_value))
2497 entry.data[total_len - 1] = (uint8_t) pad_value;
2498
2499 return entry;
2500 }
2501
2502 /** Allocates a new image partition */
2503 static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
2504 struct image_partition_entry entry = {name, len, malloc(len)};
2505 if (!entry.data)
2506 error(1, errno, "malloc");
2507
2508 return entry;
2509 }
2510
2511 /** Frees an image partition */
2512 static void free_image_partition(struct image_partition_entry entry) {
2513 free(entry.data);
2514 }
2515
2516 static time_t source_date_epoch = -1;
2517 static void set_source_date_epoch() {
2518 char *env = getenv("SOURCE_DATE_EPOCH");
2519 char *endptr = env;
2520 errno = 0;
2521 if (env && *env) {
2522 source_date_epoch = strtoull(env, &endptr, 10);
2523 if (errno || (endptr && *endptr != '\0')) {
2524 fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
2525 exit(1);
2526 }
2527 }
2528 }
2529
2530 /** Generates the partition-table partition */
2531 static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
2532 struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
2533
2534 char *s = (char *)entry.data, *end = (char *)(s+entry.size);
2535
2536 *(s++) = 0x00;
2537 *(s++) = 0x04;
2538 *(s++) = 0x00;
2539 *(s++) = 0x00;
2540
2541 size_t i;
2542 for (i = 0; p[i].name; i++) {
2543 size_t len = end-s;
2544 size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n", p[i].name, p[i].base, p[i].size);
2545
2546 if (w > len-1)
2547 error(1, 0, "flash partition table overflow?");
2548
2549 s += w;
2550 }
2551
2552 s++;
2553
2554 memset(s, 0xff, end-s);
2555
2556 return entry;
2557 }
2558
2559
2560 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
2561 static inline uint8_t bcd(uint8_t v) {
2562 return 0x10 * (v/10) + v%10;
2563 }
2564
2565
2566 /** Generates the soft-version partition */
2567 static struct image_partition_entry make_soft_version(
2568 const struct device_info *info, uint32_t rev)
2569 {
2570 /** If an info string is provided, use this instead of
2571 * the structured data, and include the null-termination */
2572 if (info->soft_ver) {
2573 uint32_t len = strlen(info->soft_ver) + 1;
2574 return init_meta_partition_entry("soft-version",
2575 info->soft_ver, len, info->part_trail);
2576 }
2577
2578 time_t t;
2579
2580 if (source_date_epoch != -1)
2581 t = source_date_epoch;
2582 else if (time(&t) == (time_t)(-1))
2583 error(1, errno, "time");
2584
2585 struct tm *tm = gmtime(&t);
2586
2587 struct soft_version s = {
2588 .pad1 = 0xff,
2589
2590 .version_major = 0,
2591 .version_minor = 0,
2592 .version_patch = 0,
2593
2594 .year_hi = bcd((1900+tm->tm_year)/100),
2595 .year_lo = bcd(tm->tm_year%100),
2596 .month = bcd(tm->tm_mon+1),
2597 .day = bcd(tm->tm_mday),
2598
2599 .compat_level = htonl(info->soft_ver_compat_level)
2600 };
2601
2602 if (info->soft_ver_compat_level == 0)
2603 return init_meta_partition_entry("soft-version", &s,
2604 (uint8_t *)(&s.compat_level) - (uint8_t *)(&s),
2605 info->part_trail);
2606 else
2607 return init_meta_partition_entry("soft-version", &s,
2608 sizeof(s), info->part_trail);
2609 }
2610
2611 /** Generates the support-list partition */
2612 static struct image_partition_entry make_support_list(
2613 const struct device_info *info)
2614 {
2615 uint32_t len = strlen(info->support_list);
2616 return init_meta_partition_entry("support-list", info->support_list,
2617 len, info->part_trail);
2618 }
2619
2620 /** Partition with extra-para data */
2621 static struct image_partition_entry make_extra_para(
2622 const struct device_info *info, const uint8_t *extra_para, size_t len)
2623 {
2624 return init_meta_partition_entry("extra-para", extra_para, len,
2625 info->part_trail);
2626 }
2627
2628 /** Creates a new image partition with an arbitrary name from a file */
2629 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) {
2630 struct stat statbuf;
2631
2632 if (stat(filename, &statbuf) < 0)
2633 error(1, errno, "unable to stat file `%s'", filename);
2634
2635 size_t len = statbuf.st_size;
2636
2637 if (add_jffs2_eof) {
2638 if (file_system_partition)
2639 len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base;
2640 else
2641 len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
2642 }
2643
2644 struct image_partition_entry entry = alloc_image_partition(part_name, len);
2645
2646 FILE *file = fopen(filename, "rb");
2647 if (!file)
2648 error(1, errno, "unable to open file `%s'", filename);
2649
2650 if (fread(entry.data, statbuf.st_size, 1, file) != 1)
2651 error(1, errno, "unable to read file `%s'", filename);
2652
2653 if (add_jffs2_eof) {
2654 uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
2655
2656 memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
2657 memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
2658 }
2659
2660 fclose(file);
2661
2662 return entry;
2663 }
2664
2665 /**
2666 Copies a list of image partitions into an image buffer and generates the image partition table while doing so
2667
2668 Example image partition table:
2669
2670 fwup-ptn partition-table base 0x00800 size 0x00800
2671 fwup-ptn os-image base 0x01000 size 0x113b45
2672 fwup-ptn file-system base 0x114b45 size 0x1d0004
2673 fwup-ptn support-list base 0x2e4b49 size 0x000d1
2674
2675 Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
2676 the end of the partition table is marked with a zero byte.
2677
2678 The firmware image must contain at least the partition-table and support-list partitions
2679 to be accepted. There aren't any alignment constraints for the image partitions.
2680
2681 The partition-table partition contains the actual flash layout; partitions
2682 from the image partition table are mapped to the corresponding flash partitions during
2683 the firmware upgrade. The support-list partition contains a list of devices supported by
2684 the firmware image.
2685
2686 The base offsets in the firmware partition table are relative to the end
2687 of the vendor information block, so the partition-table partition will
2688 actually start at offset 0x1814 of the image.
2689
2690 I think partition-table must be the first partition in the firmware image.
2691 */
2692 static void put_partitions(uint8_t *buffer, const struct flash_partition_entry *flash_parts, const struct image_partition_entry *parts) {
2693 size_t i, j;
2694 char *image_pt = (char *)buffer, *end = image_pt + 0x800;
2695
2696 size_t base = 0x800;
2697 for (i = 0; parts[i].name; i++) {
2698 for (j = 0; flash_parts[j].name; j++) {
2699 if (!strcmp(flash_parts[j].name, parts[i].name)) {
2700 if (parts[i].size > flash_parts[j].size)
2701 error(1, 0, "%s partition too big (more than %u bytes)", flash_parts[j].name, (unsigned)flash_parts[j].size);
2702 break;
2703 }
2704 }
2705
2706 assert(flash_parts[j].name);
2707
2708 memcpy(buffer + base, parts[i].data, parts[i].size);
2709
2710 size_t len = end-image_pt;
2711 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);
2712
2713 if (w > len-1)
2714 error(1, 0, "image partition table overflow?");
2715
2716 image_pt += w;
2717
2718 base += parts[i].size;
2719 }
2720 }
2721
2722 /** Generates and writes the image MD5 checksum */
2723 static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
2724 MD5_CTX ctx;
2725
2726 MD5_Init(&ctx);
2727 MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
2728 MD5_Update(&ctx, buffer, len);
2729 MD5_Final(md5, &ctx);
2730 }
2731
2732
2733 /**
2734 Generates the firmware image in factory format
2735
2736 Image format:
2737
2738 Bytes (hex) Usage
2739 ----------- -----
2740 0000-0003 Image size (4 bytes, big endian)
2741 0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
2742 0014-0017 Vendor information length (without padding) (4 bytes, big endian)
2743 0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
2744 (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
2745 1014-1813 Image partition table (2048 bytes, padded with 0xff)
2746 1814-xxxx Firmware partitions
2747 */
2748 static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) {
2749 *len = 0x1814;
2750
2751 size_t i;
2752 for (i = 0; parts[i].name; i++)
2753 *len += parts[i].size;
2754
2755 uint8_t *image = malloc(*len);
2756 if (!image)
2757 error(1, errno, "malloc");
2758
2759 memset(image, 0xff, *len);
2760 put32(image, *len);
2761
2762 if (info->vendor) {
2763 size_t vendor_len = strlen(info->vendor);
2764 put32(image+0x14, vendor_len);
2765 memcpy(image+0x18, info->vendor, vendor_len);
2766 }
2767
2768 put_partitions(image + 0x1014, info->partitions, parts);
2769 put_md5(image+0x04, image+0x14, *len-0x14);
2770
2771 return image;
2772 }
2773
2774 /**
2775 Generates the firmware image in sysupgrade format
2776
2777 This makes some assumptions about the provided flash and image partition tables and
2778 should be generalized when TP-LINK starts building its safeloader into hardware with
2779 different flash layouts.
2780 */
2781 static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) {
2782 size_t i, j;
2783 size_t flash_first_partition_index = 0;
2784 size_t flash_last_partition_index = 0;
2785 const struct flash_partition_entry *flash_first_partition = NULL;
2786 const struct flash_partition_entry *flash_last_partition = NULL;
2787 const struct image_partition_entry *image_last_partition = NULL;
2788
2789 /** Find first and last partitions */
2790 for (i = 0; info->partitions[i].name; i++) {
2791 if (!strcmp(info->partitions[i].name, info->first_sysupgrade_partition)) {
2792 flash_first_partition = &info->partitions[i];
2793 flash_first_partition_index = i;
2794 } else if (!strcmp(info->partitions[i].name, info->last_sysupgrade_partition)) {
2795 flash_last_partition = &info->partitions[i];
2796 flash_last_partition_index = i;
2797 }
2798 }
2799
2800 assert(flash_first_partition && flash_last_partition);
2801 assert(flash_first_partition_index < flash_last_partition_index);
2802
2803 /** Find last partition from image to calculate needed size */
2804 for (i = 0; image_parts[i].name; i++) {
2805 if (!strcmp(image_parts[i].name, info->last_sysupgrade_partition)) {
2806 image_last_partition = &image_parts[i];
2807 break;
2808 }
2809 }
2810
2811 assert(image_last_partition);
2812
2813 *len = flash_last_partition->base - flash_first_partition->base + image_last_partition->size;
2814
2815 uint8_t *image = malloc(*len);
2816 if (!image)
2817 error(1, errno, "malloc");
2818
2819 memset(image, 0xff, *len);
2820
2821 for (i = flash_first_partition_index; i <= flash_last_partition_index; i++) {
2822 for (j = 0; image_parts[j].name; j++) {
2823 if (!strcmp(info->partitions[i].name, image_parts[j].name)) {
2824 if (image_parts[j].size > info->partitions[i].size)
2825 error(1, 0, "%s partition too big (more than %u bytes)", info->partitions[i].name, (unsigned)info->partitions[i].size);
2826 memcpy(image + info->partitions[i].base - flash_first_partition->base, image_parts[j].data, image_parts[j].size);
2827 break;
2828 }
2829
2830 assert(image_parts[j].name);
2831 }
2832 }
2833
2834 return image;
2835 }
2836
2837 /** Generates an image according to a given layout and writes it to a file */
2838 static void build_image(const char *output,
2839 const char *kernel_image,
2840 const char *rootfs_image,
2841 uint32_t rev,
2842 bool add_jffs2_eof,
2843 bool sysupgrade,
2844 struct device_info *info) {
2845
2846 size_t i;
2847
2848 struct image_partition_entry parts[7] = {};
2849
2850 struct flash_partition_entry *firmware_partition = NULL;
2851 struct flash_partition_entry *os_image_partition = NULL;
2852 struct flash_partition_entry *file_system_partition = NULL;
2853 size_t firmware_partition_index = 0;
2854
2855 for (i = 0; info->partitions[i].name; i++) {
2856 if (!strcmp(info->partitions[i].name, "firmware"))
2857 {
2858 firmware_partition = &info->partitions[i];
2859 firmware_partition_index = i;
2860 }
2861 }
2862
2863 if (firmware_partition)
2864 {
2865 os_image_partition = &info->partitions[firmware_partition_index];
2866 file_system_partition = &info->partitions[firmware_partition_index + 1];
2867
2868 struct stat kernel;
2869 if (stat(kernel_image, &kernel) < 0)
2870 error(1, errno, "unable to stat file `%s'", kernel_image);
2871
2872 if (kernel.st_size > firmware_partition->size)
2873 error(1, 0, "kernel overflowed firmware partition\n");
2874
2875 for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--)
2876 info->partitions[i+1] = info->partitions[i];
2877
2878 file_system_partition->name = "file-system";
2879 file_system_partition->base = firmware_partition->base + kernel.st_size;
2880
2881 /* Align partition start to erase blocks for factory images only */
2882 if (!sysupgrade)
2883 file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000);
2884
2885 file_system_partition->size = firmware_partition->size - file_system_partition->base;
2886
2887 os_image_partition->name = "os-image";
2888 os_image_partition->size = kernel.st_size;
2889 }
2890
2891 parts[0] = make_partition_table(info->partitions);
2892 parts[1] = make_soft_version(info, rev);
2893 parts[2] = make_support_list(info);
2894 parts[3] = read_file("os-image", kernel_image, false, NULL);
2895 parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition);
2896
2897 /* Some devices need the extra-para partition to accept the firmware */
2898 if (strcasecmp(info->id, "ARCHER-A6-V3") == 0 ||
2899 strcasecmp(info->id, "ARCHER-A7-V5") == 0 ||
2900 strcasecmp(info->id, "ARCHER-C2-V3") == 0 ||
2901 strcasecmp(info->id, "ARCHER-C7-V4") == 0 ||
2902 strcasecmp(info->id, "ARCHER-C7-V5") == 0 ||
2903 strcasecmp(info->id, "ARCHER-C25-V1") == 0 ||
2904 strcasecmp(info->id, "ARCHER-C59-V2") == 0 ||
2905 strcasecmp(info->id, "ARCHER-C60-V2") == 0 ||
2906 strcasecmp(info->id, "ARCHER-C60-V3") == 0 ||
2907 strcasecmp(info->id, "ARCHER-C6U-V1") == 0 ||
2908 strcasecmp(info->id, "TLWR1043NV5") == 0) {
2909 const uint8_t extra_para[2] = {0x01, 0x00};
2910 parts[5] = make_extra_para(info, extra_para,
2911 sizeof(extra_para));
2912 } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0) {
2913 const uint8_t extra_para[2] = {0x00, 0x01};
2914 parts[5] = make_extra_para(info, extra_para,
2915 sizeof(extra_para));
2916 } else if (strcasecmp(info->id, "ARCHER-C6-V2-US") == 0 ||
2917 strcasecmp(info->id, "EAP245-V3") == 0) {
2918 const uint8_t extra_para[2] = {0x01, 0x01};
2919 parts[5] = make_extra_para(info, extra_para,
2920 sizeof(extra_para));
2921 }
2922
2923 size_t len;
2924 void *image;
2925 if (sysupgrade)
2926 image = generate_sysupgrade_image(info, parts, &len);
2927 else
2928 image = generate_factory_image(info, parts, &len);
2929
2930 FILE *file = fopen(output, "wb");
2931 if (!file)
2932 error(1, errno, "unable to open output file");
2933
2934 if (fwrite(image, len, 1, file) != 1)
2935 error(1, 0, "unable to write output file");
2936
2937 fclose(file);
2938
2939 free(image);
2940
2941 for (i = 0; parts[i].name; i++)
2942 free_image_partition(parts[i]);
2943 }
2944
2945 /** Usage output */
2946 static void usage(const char *argv0) {
2947 fprintf(stderr,
2948 "Usage: %s [OPTIONS...]\n"
2949 "\n"
2950 "Options:\n"
2951 " -h show this help\n"
2952 "\n"
2953 "Create a new image:\n"
2954 " -B <board> create image for the board specified with <board>\n"
2955 " -k <file> read kernel image from the file <file>\n"
2956 " -r <file> read rootfs image from the file <file>\n"
2957 " -o <file> write output to the file <file>\n"
2958 " -V <rev> sets the revision number to <rev>\n"
2959 " -j add jffs2 end-of-filesystem markers\n"
2960 " -S create sysupgrade instead of factory image\n"
2961 "Extract an old image:\n"
2962 " -x <file> extract all oem firmware partition\n"
2963 " -d <dir> destination to extract the firmware partition\n"
2964 " -z <file> convert an oem firmware into a sysupgade file. Use -o for output file\n",
2965 argv0
2966 );
2967 };
2968
2969
2970 static struct device_info *find_board(const char *id)
2971 {
2972 struct device_info *board = NULL;
2973
2974 for (board = boards; board->id != NULL; board++)
2975 if (strcasecmp(id, board->id) == 0)
2976 return board;
2977
2978 return NULL;
2979 }
2980
2981 static int add_flash_partition(
2982 struct flash_partition_entry *part_list,
2983 size_t max_entries,
2984 const char *name,
2985 unsigned long base,
2986 unsigned long size)
2987 {
2988 size_t ptr;
2989 /* check if the list has a free entry */
2990 for (ptr = 0; ptr < max_entries; ptr++, part_list++) {
2991 if (part_list->name == NULL &&
2992 part_list->base == 0 &&
2993 part_list->size == 0)
2994 break;
2995 }
2996
2997 if (ptr == max_entries) {
2998 error(1, 0, "No free flash part entry available.");
2999 }
3000
3001 part_list->name = calloc(1, strlen(name) + 1);
3002 if (!part_list->name) {
3003 error(1, 0, "Unable to allocate memory");
3004 }
3005
3006 memcpy((char *)part_list->name, name, strlen(name));
3007 part_list->base = base;
3008 part_list->size = size;
3009
3010 return 0;
3011 }
3012
3013 /** read the partition table into struct flash_partition_entry */
3014 static int read_partition_table(
3015 FILE *file, long offset,
3016 struct flash_partition_entry *entries, size_t max_entries,
3017 int type)
3018 {
3019 char buf[2048];
3020 char *ptr, *end;
3021 const char *parthdr = NULL;
3022 const char *fwuphdr = "fwup-ptn";
3023 const char *flashhdr = "partition";
3024
3025 /* TODO: search for the partition table */
3026
3027 switch(type) {
3028 case 0:
3029 parthdr = fwuphdr;
3030 break;
3031 case 1:
3032 parthdr = flashhdr;
3033 break;
3034 default:
3035 error(1, 0, "Invalid partition table");
3036 }
3037
3038 if (fseek(file, offset, SEEK_SET) < 0)
3039 error(1, errno, "Can not seek in the firmware");
3040
3041 if (fread(buf, 2048, 1, file) != 1)
3042 error(1, errno, "Can not read fwup-ptn from the firmware");
3043
3044 buf[2047] = '\0';
3045
3046 /* look for the partition header */
3047 if (memcmp(buf, parthdr, strlen(parthdr)) != 0) {
3048 fprintf(stderr, "DEBUG: can not find fwuphdr\n");
3049 return 1;
3050 }
3051
3052 ptr = buf;
3053 end = buf + sizeof(buf);
3054 while ((ptr + strlen(parthdr)) < end &&
3055 memcmp(ptr, parthdr, strlen(parthdr)) == 0) {
3056 char *end_part;
3057 char *end_element;
3058
3059 char name[32] = { 0 };
3060 int name_len = 0;
3061 unsigned long base = 0;
3062 unsigned long size = 0;
3063
3064 end_part = memchr(ptr, '\n', (end - ptr));
3065 if (end_part == NULL) {
3066 /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
3067 break;
3068 }
3069
3070 for (int i = 0; i <= 4; i++) {
3071 if (end_part <= ptr)
3072 break;
3073
3074 end_element = memchr(ptr, 0x20, (end_part - ptr));
3075 if (end_element == NULL) {
3076 error(1, errno, "Ignoring the rest of the partition entries.");
3077 break;
3078 }
3079
3080 switch (i) {
3081 /* partition header */
3082 case 0:
3083 ptr = end_element + 1;
3084 continue;
3085 /* name */
3086 case 1:
3087 name_len = (end_element - ptr) > 31 ? 31 : (end_element - ptr);
3088 strncpy(name, ptr, name_len);
3089 name[name_len] = '\0';
3090 ptr = end_element + 1;
3091 continue;
3092
3093 /* string "base" */
3094 case 2:
3095 ptr = end_element + 1;
3096 continue;
3097
3098 /* actual base */
3099 case 3:
3100 base = strtoul(ptr, NULL, 16);
3101 ptr = end_element + 1;
3102 continue;
3103
3104 /* string "size" */
3105 case 4:
3106 ptr = end_element + 1;
3107 /* actual size. The last element doesn't have a sepeartor */
3108 size = strtoul(ptr, NULL, 16);
3109 /* the part ends with 0x09, 0x0d, 0x0a */
3110 ptr = end_part + 1;
3111 add_flash_partition(entries, max_entries, name, base, size);
3112 continue;
3113 }
3114 }
3115 }
3116
3117 return 0;
3118 }
3119
3120 static void write_partition(
3121 FILE *input_file,
3122 size_t firmware_offset,
3123 struct flash_partition_entry *entry,
3124 FILE *output_file)
3125 {
3126 char buf[4096];
3127 size_t offset;
3128
3129 fseek(input_file, entry->base + firmware_offset, SEEK_SET);
3130
3131 for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) {
3132 if (fread(buf, sizeof(buf), 1, input_file) != 1)
3133 error(1, errno, "Can not read partition from input_file");
3134
3135 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3136 error(1, errno, "Can not write partition to output_file");
3137 }
3138 /* write last chunk smaller than buffer */
3139 if (offset < entry->size) {
3140 offset = entry->size - offset;
3141 if (fread(buf, offset, 1, input_file) != 1)
3142 error(1, errno, "Can not read partition from input_file");
3143 if (fwrite(buf, offset, 1, output_file) != 1)
3144 error(1, errno, "Can not write partition to output_file");
3145 }
3146 }
3147
3148 static int extract_firmware_partition(FILE *input_file, size_t firmware_offset, struct flash_partition_entry *entry, const char *output_directory)
3149 {
3150 FILE *output_file;
3151 char output[PATH_MAX];
3152
3153 snprintf(output, PATH_MAX, "%s/%s", output_directory, entry->name);
3154 output_file = fopen(output, "wb+");
3155 if (output_file == NULL) {
3156 error(1, errno, "Can not open output file %s", output);
3157 }
3158
3159 write_partition(input_file, firmware_offset, entry, output_file);
3160
3161 fclose(output_file);
3162
3163 return 0;
3164 }
3165
3166 /** extract all partitions from the firmware file */
3167 static int extract_firmware(const char *input, const char *output_directory)
3168 {
3169 struct flash_partition_entry entries[16] = { 0 };
3170 size_t max_entries = 16;
3171 size_t firmware_offset = 0x1014;
3172 FILE *input_file;
3173
3174 struct stat statbuf;
3175
3176 /* check input file */
3177 if (stat(input, &statbuf)) {
3178 error(1, errno, "Can not read input firmware %s", input);
3179 }
3180
3181 /* check if output directory exists */
3182 if (stat(output_directory, &statbuf)) {
3183 error(1, errno, "Failed to stat output directory %s", output_directory);
3184 }
3185
3186 if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
3187 error(1, errno, "Given output directory is not a directory %s", output_directory);
3188 }
3189
3190 input_file = fopen(input, "rb");
3191
3192 if (read_partition_table(input_file, firmware_offset, entries, 16, 0) != 0) {
3193 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3194 }
3195
3196 for (size_t i = 0; i < max_entries; i++) {
3197 if (entries[i].name == NULL &&
3198 entries[i].base == 0 &&
3199 entries[i].size == 0)
3200 continue;
3201
3202 extract_firmware_partition(input_file, firmware_offset, &entries[i], output_directory);
3203 }
3204
3205 return 0;
3206 }
3207
3208 static struct flash_partition_entry *find_partition(
3209 struct flash_partition_entry *entries, size_t max_entries,
3210 const char *name, const char *error_msg)
3211 {
3212 for (size_t i = 0; i < max_entries; i++, entries++) {
3213 if (strcmp(entries->name, name) == 0)
3214 return entries;
3215 }
3216
3217 error(1, 0, "%s", error_msg);
3218 return NULL;
3219 }
3220
3221 static void write_ff(FILE *output_file, size_t size)
3222 {
3223 char buf[4096];
3224 size_t offset;
3225
3226 memset(buf, 0xff, sizeof(buf));
3227
3228 for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) {
3229 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
3230 error(1, errno, "Can not write 0xff to output_file");
3231 }
3232
3233 /* write last chunk smaller than buffer */
3234 if (offset < size) {
3235 offset = size - offset;
3236 if (fwrite(buf, offset, 1, output_file) != 1)
3237 error(1, errno, "Can not write partition to output_file");
3238 }
3239 }
3240
3241 static void convert_firmware(const char *input, const char *output)
3242 {
3243 struct flash_partition_entry fwup[MAX_PARTITIONS] = { 0 };
3244 struct flash_partition_entry flash[MAX_PARTITIONS] = { 0 };
3245 struct flash_partition_entry *fwup_os_image = NULL, *fwup_file_system = NULL;
3246 struct flash_partition_entry *flash_os_image = NULL, *flash_file_system = NULL;
3247 struct flash_partition_entry *fwup_partition_table = NULL;
3248 size_t firmware_offset = 0x1014;
3249 FILE *input_file, *output_file;
3250
3251 struct stat statbuf;
3252
3253 /* check input file */
3254 if (stat(input, &statbuf)) {
3255 error(1, errno, "Can not read input firmware %s", input);
3256 }
3257
3258 input_file = fopen(input, "rb");
3259 if (!input_file)
3260 error(1, 0, "Can not open input firmware %s", input);
3261
3262 output_file = fopen(output, "wb");
3263 if (!output_file)
3264 error(1, 0, "Can not open output firmware %s", output);
3265
3266 if (read_partition_table(input_file, firmware_offset, fwup, MAX_PARTITIONS, 0) != 0) {
3267 error(1, 0, "Error can not read the partition table (fwup-ptn)");
3268 }
3269
3270 fwup_os_image = find_partition(fwup, MAX_PARTITIONS,
3271 "os-image", "Error can not find os-image partition (fwup)");
3272 fwup_file_system = find_partition(fwup, MAX_PARTITIONS,
3273 "file-system", "Error can not find file-system partition (fwup)");
3274 fwup_partition_table = find_partition(fwup, MAX_PARTITIONS,
3275 "partition-table", "Error can not find partition-table partition");
3276
3277 /* the flash partition table has a 0x00000004 magic haeder */
3278 if (read_partition_table(input_file, firmware_offset + fwup_partition_table->base + 4, flash, MAX_PARTITIONS, 1) != 0)
3279 error(1, 0, "Error can not read the partition table (flash)");
3280
3281 flash_os_image = find_partition(flash, MAX_PARTITIONS,
3282 "os-image", "Error can not find os-image partition (flash)");
3283 flash_file_system = find_partition(flash, MAX_PARTITIONS,
3284 "file-system", "Error can not find file-system partition (flash)");
3285
3286 /* write os_image to 0x0 */
3287 write_partition(input_file, firmware_offset, fwup_os_image, output_file);
3288 write_ff(output_file, flash_os_image->size - fwup_os_image->size);
3289
3290 /* write file-system behind os_image */
3291 fseek(output_file, flash_file_system->base - flash_os_image->base, SEEK_SET);
3292 write_partition(input_file, firmware_offset, fwup_file_system, output_file);
3293 write_ff(output_file, flash_file_system->size - fwup_file_system->size);
3294
3295 fclose(output_file);
3296 fclose(input_file);
3297 }
3298
3299 int main(int argc, char *argv[]) {
3300 const char *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
3301 const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL;
3302 bool add_jffs2_eof = false, sysupgrade = false;
3303 unsigned rev = 0;
3304 struct device_info *info;
3305 set_source_date_epoch();
3306
3307 while (true) {
3308 int c;
3309
3310 c = getopt(argc, argv, "B:k:r:o:V:jSh:x:d:z:");
3311 if (c == -1)
3312 break;
3313
3314 switch (c) {
3315 case 'B':
3316 board = optarg;
3317 break;
3318
3319 case 'k':
3320 kernel_image = optarg;
3321 break;
3322
3323 case 'r':
3324 rootfs_image = optarg;
3325 break;
3326
3327 case 'o':
3328 output = optarg;
3329 break;
3330
3331 case 'V':
3332 sscanf(optarg, "r%u", &rev);
3333 break;
3334
3335 case 'j':
3336 add_jffs2_eof = true;
3337 break;
3338
3339 case 'S':
3340 sysupgrade = true;
3341 break;
3342
3343 case 'h':
3344 usage(argv[0]);
3345 return 0;
3346
3347 case 'd':
3348 output_directory = optarg;
3349 break;
3350
3351 case 'x':
3352 extract_image = optarg;
3353 break;
3354
3355 case 'z':
3356 convert_image = optarg;
3357 break;
3358
3359 default:
3360 usage(argv[0]);
3361 return 1;
3362 }
3363 }
3364
3365 if (extract_image || output_directory) {
3366 if (!extract_image)
3367 error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
3368 if (!output_directory)
3369 error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
3370 extract_firmware(extract_image, output_directory);
3371 } else if (convert_image) {
3372 if (!output)
3373 error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
3374 convert_firmware(convert_image, output);
3375 } else {
3376 if (!board)
3377 error(1, 0, "no board has been specified");
3378 if (!kernel_image)
3379 error(1, 0, "no kernel image has been specified");
3380 if (!rootfs_image)
3381 error(1, 0, "no rootfs image has been specified");
3382 if (!output)
3383 error(1, 0, "no output filename has been specified");
3384
3385 info = find_board(board);
3386
3387 if (info == NULL)
3388 error(1, 0, "unsupported board %s", board);
3389
3390 build_image(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, info);
3391 }
3392
3393 return 0;
3394 }