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