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