• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/firmware-utils/src/tplink-safeloader.c

  1 // SPDX-License-Identifier: BSD-2-Clause
  2 /*
  3   Copyright (c) 2014, Matthias Schiffer <mschiffer@universe-factory.net>
  4   All rights reserved.
  5 */
  6 
  7 
  8 /*
  9    tplink-safeloader
 10 
 11    Image generation tool for the TP-LINK SafeLoader as seen on
 12    TP-LINK Pharos devices (CPE210/220/510/520)
 13 */
 14 
 15 
 16 #include <assert.h>
 17 #include <ctype.h>
 18 #include <errno.h>
 19 #include <stdbool.h>
 20 #include <stddef.h>
 21 #include <stdio.h>
 22 #include <stdint.h>
 23 #include <stdlib.h>
 24 #include <string.h>
 25 #include <time.h>
 26 #include <unistd.h>
 27 
 28 #include <arpa/inet.h>
 29 
 30 #include <sys/types.h>
 31 #include <sys/stat.h>
 32 #include <limits.h>
 33 
 34 #include "md5.h"
 35 
 36 
 37 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
 38 
 39 
 40 #define MAX_PARTITIONS  32
 41 
 42 /** An image partition table entry */
 43 struct image_partition_entry {
 44         const char *name;
 45         size_t size;
 46         uint8_t *data;
 47 };
 48 
 49 /** A flash partition table entry */
 50 struct flash_partition_entry {
 51         const char *name;
 52         uint32_t base;
 53         uint32_t size;
 54 };
 55 
 56 /** Flash partition names table entry */
 57 struct factory_partition_names {
 58         const char *partition_table;
 59         const char *soft_ver;
 60         const char *os_image;
 61         const char *support_list;
 62         const char *file_system;
 63         const char *extra_para;
 64 };
 65 
 66 /** Partition trailing padding definitions
 67  * Values 0x00 to 0xff are reserved to indicate the padding value
 68  * Values from 0x100 are reserved to indicate other behaviour */
 69 enum partition_trail_value {
 70         PART_TRAIL_00   = 0x00,
 71         PART_TRAIL_FF   = 0xff,
 72         PART_TRAIL_MAX  = 0xff,
 73         PART_TRAIL_NONE = 0x100
 74 };
 75 
 76 /** soft-version value overwrite types
 77  * The default (for an uninitialised soft_ver field) is to use the numerical
 78  * version number "0.0.0"
 79  */
 80 enum soft_ver_type {
 81         SOFT_VER_TYPE_NUMERIC = 0,
 82         SOFT_VER_TYPE_TEXT = 1,
 83 };
 84 
 85 /** Firmware layout description */
 86 struct device_info {
 87         const char *id;
 88         const char *vendor;
 89         const char *support_list;
 90         enum partition_trail_value part_trail;
 91         struct {
 92                 enum soft_ver_type type;
 93                 union {
 94                         const char *text;
 95                         uint8_t num[3];
 96                 };
 97         } soft_ver;
 98         uint32_t soft_ver_compat_level;
 99         struct flash_partition_entry partitions[MAX_PARTITIONS+1];
100         const char *first_sysupgrade_partition;
101         const char *last_sysupgrade_partition;
102         struct factory_partition_names partition_names;
103 };
104 
105 #define SOFT_VER_TEXT(_t) {.type = SOFT_VER_TYPE_TEXT, .text = _t}
106 #define SOFT_VER_NUMERIC(_maj, _min, _patch) {  \
107                 .type = SOFT_VER_TYPE_NUMERIC,          \
108                 .num = {_maj, _min, _patch}}
109 #define SOFT_VER_DEFAULT SOFT_VER_NUMERIC(0, 0, 0)
110 
111 struct __attribute__((__packed__)) meta_header {
112         uint32_t length;
113         uint32_t zero;
114 };
115 
116 /** The content of the soft-version structure */
117 struct __attribute__((__packed__)) soft_version {
118         uint8_t pad1;
119         uint8_t version_major;
120         uint8_t version_minor;
121         uint8_t version_patch;
122         uint8_t year_hi;
123         uint8_t year_lo;
124         uint8_t month;
125         uint8_t day;
126         uint32_t rev;
127         uint32_t compat_level;
128 };
129 
130 /*
131  * Safeloader image type
132  *   Safeloader images contain a 0x14 byte preamble with image size (big endian
133  *   UINT32) and md5 checksum (16 bytes).
134  *
135  * SAFEFLOADER_TYPE_DEFAULT
136  *   Standard preamble with size including preamble length, and checksum.
137  *   Header of 0x1000 bytes, contents of which are not specified.
138  *   Payload starts at offset 0x1014.
139  *
140  * SAFELOADER_TYPE_VENDOR
141  *   Standard preamble with size including preamble length, and checksum.
142  *   Header contains up to 0x1000 bytes of vendor data, starting with a big endian
143  *   UINT32 size, followed by that number of bytes containing (text) data.
144  *   Padded with 0xFF. Payload starts at offset 0x1014.
145  *
146  * SAFELOADER_TYPE_CLOUD
147  *   Standard preamble with size including preamble length, and checksum.
148  *   Followed by the 'fw-type:Cloud' string and some (unknown) data.
149  *   Payload starts at offset 0x1014.
150  *
151  * SAFELOADER_TYPE_QNEW
152  *   Reversed order preamble, with (apparent) md5 checksum before the image
153  *   size. The size does not include the preamble length.
154  *   Header starts with 0x3C bytes, starting with the string '?NEW' (format not
155  *   understood). Then another 0x1000 bytes follow, with the data payload
156  *   starting at 0x1050.
157  */
158 enum safeloader_image_type {
159         SAFELOADER_TYPE_DEFAULT,
160         SAFELOADER_TYPE_VENDOR,
161         SAFELOADER_TYPE_CLOUD,
162         SAFELOADER_TYPE_QNEW,
163 };
164 
165 /* Internal representation of safeloader image data */
166 struct safeloader_image_info {
167         enum safeloader_image_type type;
168         size_t payload_offset;
169         struct flash_partition_entry entries[MAX_PARTITIONS];
170 };
171 
172 #define SAFELOADER_PREAMBLE_SIZE        0x14
173 #define SAFELOADER_HEADER_SIZE          0x1000
174 #define SAFELOADER_PAYLOAD_OFFSET       (SAFELOADER_PREAMBLE_SIZE + SAFELOADER_HEADER_SIZE)
175 
176 #define SAFELOADER_QNEW_HEADER_SIZE     0x3C
177 #define SAFELOADER_QNEW_PAYLOAD_OFFSET  \
178         (SAFELOADER_PREAMBLE_SIZE + SAFELOADER_QNEW_HEADER_SIZE + SAFELOADER_HEADER_SIZE)
179 
180 #define SAFELOADER_PAYLOAD_TABLE_SIZE   0x800
181 
182 static const uint8_t jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
183 
184 
185 /**
186    Salt for the MD5 hash
187 
188    Fortunately, TP-LINK seems to use the same salt for most devices which use
189    the new image format.
190 */
191 static const uint8_t md5_salt[16] = {
192         0x7a, 0x2b, 0x15, 0xed,
193         0x9b, 0x98, 0x59, 0x6d,
194         0xe5, 0x04, 0xab, 0x44,
195         0xac, 0x2a, 0x9f, 0x4e,
196 };
197 
198 
199 /** Firmware layout table */
200 static struct device_info boards[] = {
201         /** Firmware layout for the CPE210/220 V1 */
202         {
203                 .id     = "CPE210",
204                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
205                 .support_list =
206                         "SupportList:\r\n"
207                         "CPE210(TP-LINK|UN|N300-2):1.0\r\n"
208                         "CPE210(TP-LINK|UN|N300-2):1.1\r\n"
209                         "CPE210(TP-LINK|US|N300-2):1.1\r\n"
210                         "CPE210(TP-LINK|EU|N300-2):1.1\r\n"
211                         "CPE220(TP-LINK|UN|N300-2):1.1\r\n"
212                         "CPE220(TP-LINK|US|N300-2):1.1\r\n"
213                         "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
214                 .part_trail = 0xff,
215                 .soft_ver = SOFT_VER_DEFAULT,
216 
217                 .partitions = {
218                         {"fs-uboot", 0x00000, 0x20000},
219                         {"partition-table", 0x20000, 0x02000},
220                         {"default-mac", 0x30000, 0x00020},
221                         {"product-info", 0x31100, 0x00100},
222                         {"signature", 0x32000, 0x00400},
223                         {"firmware", 0x40000, 0x770000},
224                         {"soft-version", 0x7b0000, 0x00100},
225                         {"support-list", 0x7b1000, 0x00400},
226                         {"user-config", 0x7c0000, 0x10000},
227                         {"default-config", 0x7d0000, 0x10000},
228                         {"log", 0x7e0000, 0x10000},
229                         {"radio", 0x7f0000, 0x10000},
230                         {NULL, 0, 0}
231                 },
232 
233                 .first_sysupgrade_partition = "os-image",
234                 .last_sysupgrade_partition = "support-list",
235         },
236 
237         /** Firmware layout for the CPE210 V2 */
238         {
239                 .id     = "CPE210V2",
240                 .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
241                 .support_list =
242                         "SupportList:\r\n"
243                         "CPE210(TP-LINK|EU|N300-2|00000000):2.0\r\n"
244                         "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n"
245                         "CPE210(TP-LINK|EU|N300-2|55530000):2.0\r\n"
246                         "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
247                         "CPE210(TP-LINK|UN|N300-2|45550000):2.0\r\n"
248                         "CPE210(TP-LINK|UN|N300-2|55530000):2.0\r\n"
249                         "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
250                         "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
251                         "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
252                         "CPE210(TP-LINK|US|N300-2):2.0\r\n",
253                 .part_trail = 0xff,
254                 .soft_ver = SOFT_VER_DEFAULT,
255 
256                 .partitions = {
257                         {"fs-uboot", 0x00000, 0x20000},
258                         {"partition-table", 0x20000, 0x02000},
259                         {"default-mac", 0x30000, 0x00020},
260                         {"product-info", 0x31100, 0x00100},
261                         {"device-info", 0x31400, 0x00400},
262                         {"signature", 0x32000, 0x00400},
263                         {"device-id", 0x33000, 0x00100},
264                         {"firmware", 0x40000, 0x770000},
265                         {"soft-version", 0x7b0000, 0x00100},
266                         {"support-list", 0x7b1000, 0x01000},
267                         {"user-config", 0x7c0000, 0x10000},
268                         {"default-config", 0x7d0000, 0x10000},
269                         {"log", 0x7e0000, 0x10000},
270                         {"radio", 0x7f0000, 0x10000},
271                         {NULL, 0, 0}
272                 },
273 
274                 .first_sysupgrade_partition = "os-image",
275                 .last_sysupgrade_partition = "support-list",
276         },
277 
278         /** Firmware layout for the CPE210 V3 */
279         {
280                 .id     = "CPE210V3",
281                 .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
282                 .support_list =
283                         "SupportList:\r\n"
284                         "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
285                         "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
286                         "CPE210(TP-LINK|US|N300-2|55530000):3.0\r\n"
287                         "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
288                         "CPE210(TP-LINK|EU|N300-2):3.0\r\n"
289                         "CPE210(TP-LINK|EU|N300-2|45550000):3.1\r\n"
290                         "CPE210(TP-LINK|UN|N300-2|00000000):3.1\r\n"
291                         "CPE210(TP-LINK|US|N300-2|55530000):3.1\r\n"
292                         "CPE210(TP-LINK|EU|N300-2|45550000):3.20\r\n"
293                         "CPE210(TP-LINK|UN|N300-2|00000000):3.20\r\n"
294                         "CPE210(TP-LINK|US|N300-2|55530000):3.20\r\n",
295                 .part_trail = 0xff,
296                 .soft_ver = SOFT_VER_DEFAULT,
297 
298                 .partitions = {
299                         {"fs-uboot", 0x00000, 0x20000},
300                         {"partition-table", 0x20000, 0x01000},
301                         {"default-mac", 0x30000, 0x00020},
302                         {"product-info", 0x31100, 0x00100},
303                         {"device-info", 0x31400, 0x00400},
304                         {"signature", 0x32000, 0x00400},
305                         {"device-id", 0x33000, 0x00100},
306                         {"firmware", 0x40000, 0x770000},
307                         {"soft-version", 0x7b0000, 0x00100},
308                         {"support-list", 0x7b1000, 0x01000},
309                         {"user-config", 0x7c0000, 0x10000},
310                         {"default-config", 0x7d0000, 0x10000},
311                         {"log", 0x7e0000, 0x10000},
312                         {"radio", 0x7f0000, 0x10000},
313                         {NULL, 0, 0}
314                 },
315 
316                 .first_sysupgrade_partition = "os-image",
317                 .last_sysupgrade_partition = "support-list",
318         },
319 
320         /** Firmware layout for the CPE220 V2 */
321         {
322                 .id     = "CPE220V2",
323                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
324                 .support_list =
325                         "SupportList:\r\n"
326                         "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n"
327                         "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n"
328                         "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n"
329                         "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n"
330                         "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n"
331                         "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n"
332                         "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n"
333                         "CPE220(TP-LINK|UN|N300-2):2.0\r\n"
334                         "CPE220(TP-LINK|EU|N300-2):2.0\r\n"
335                         "CPE220(TP-LINK|US|N300-2):2.0\r\n",
336                 .part_trail = 0xff,
337                 .soft_ver = SOFT_VER_DEFAULT,
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                         {"firmware", 0x40000, 0x770000},
346                         {"soft-version", 0x7b0000, 0x00100},
347                         {"support-list", 0x7b1000, 0x00400},
348                         {"user-config", 0x7c0000, 0x10000},
349                         {"default-config", 0x7d0000, 0x10000},
350                         {"log", 0x7e0000, 0x10000},
351                         {"radio", 0x7f0000, 0x10000},
352                         {NULL, 0, 0}
353                 },
354 
355                 .first_sysupgrade_partition = "os-image",
356                 .last_sysupgrade_partition = "support-list",
357         },
358 
359         /** Firmware layout for the CPE220 V3 */
360         {
361                 .id     = "CPE220V3",
362                 .vendor = "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n",
363                 .support_list =
364                         "SupportList:\r\n"
365                         "CPE220(TP-LINK|EU|N300-2|00000000):3.0\r\n"
366                         "CPE220(TP-LINK|EU|N300-2|45550000):3.0\r\n"
367                         "CPE220(TP-LINK|EU|N300-2|55530000):3.0\r\n"
368                         "CPE220(TP-LINK|UN|N300-2|00000000):3.0\r\n"
369                         "CPE220(TP-LINK|UN|N300-2|45550000):3.0\r\n"
370                         "CPE220(TP-LINK|UN|N300-2|55530000):3.0\r\n"
371                         "CPE220(TP-LINK|US|N300-2|55530000):3.0\r\n"
372                         "CPE220(TP-LINK|UN|N300-2):3.0\r\n"
373                         "CPE220(TP-LINK|EU|N300-2):3.0\r\n"
374                         "CPE220(TP-LINK|US|N300-2):3.0\r\n",
375                 .part_trail = 0xff,
376                 .soft_ver = SOFT_VER_DEFAULT,
377 
378                 .partitions = {
379                         {"fs-uboot", 0x00000, 0x20000},
380                         {"partition-table", 0x20000, 0x02000},
381                         {"default-mac", 0x30000, 0x00020},
382                         {"product-info", 0x31100, 0x00100},
383                         {"device-info", 0x31400, 0x00400},
384                         {"signature", 0x32000, 0x00400},
385                         {"device-id", 0x33000, 0x00100},
386                         {"firmware", 0x40000, 0x770000},
387                         {"soft-version", 0x7b0000, 0x00100},
388                         {"support-list", 0x7b1000, 0x01000},
389                         {"user-config", 0x7c0000, 0x10000},
390                         {"default-config", 0x7d0000, 0x10000},
391                         {"log", 0x7e0000, 0x10000},
392                         {"radio", 0x7f0000, 0x10000},
393                         {NULL, 0, 0}
394                 },
395 
396                 .first_sysupgrade_partition = "os-image",
397                 .last_sysupgrade_partition = "support-list",
398         },
399 
400         /** Firmware layout for the CPE510/520 V1 */
401         {
402                 .id     = "CPE510",
403                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
404                 .support_list =
405                         "SupportList:\r\n"
406                         "CPE510(TP-LINK|UN|N300-5):1.0\r\n"
407                         "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
408                         "CPE510(TP-LINK|UN|N300-5):1.1\r\n"
409                         "CPE510(TP-LINK|US|N300-5):1.1\r\n"
410                         "CPE510(TP-LINK|CA|N300-5):1.1\r\n"
411                         "CPE510(TP-LINK|EU|N300-5):1.1\r\n"
412                         "CPE520(TP-LINK|UN|N300-5):1.1\r\n"
413                         "CPE520(TP-LINK|US|N300-5):1.1\r\n"
414                         "CPE520(TP-LINK|EU|N300-5):1.1\r\n",
415                 .part_trail = 0xff,
416                 .soft_ver = SOFT_VER_DEFAULT,
417 
418                 .partitions = {
419                         {"fs-uboot", 0x00000, 0x20000},
420                         {"partition-table", 0x20000, 0x02000},
421                         {"default-mac", 0x30000, 0x00020},
422                         {"product-info", 0x31100, 0x00100},
423                         {"signature", 0x32000, 0x00400},
424                         {"firmware", 0x40000, 0x770000},
425                         {"soft-version", 0x7b0000, 0x00100},
426                         {"support-list", 0x7b1000, 0x00400},
427                         {"user-config", 0x7c0000, 0x10000},
428                         {"default-config", 0x7d0000, 0x10000},
429                         {"log", 0x7e0000, 0x10000},
430                         {"radio", 0x7f0000, 0x10000},
431                         {NULL, 0, 0}
432                 },
433 
434                 .first_sysupgrade_partition = "os-image",
435                 .last_sysupgrade_partition = "support-list",
436         },
437 
438         /** Firmware layout for the CPE510 V2 */
439         {
440                 .id     = "CPE510V2",
441                 .vendor = "CPE510(TP-LINK|UN|N300-5):2.0\r\n",
442                 .support_list =
443                         "SupportList:\r\n"
444                         "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n"
445                         "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
446                         "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n"
447                         "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
448                         "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n"
449                         "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n"
450                         "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n"
451                         "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n"
452                         "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n"
453                         "CPE510(TP-LINK|UN|N300-5):2.0\r\n"
454                         "CPE510(TP-LINK|EU|N300-5):2.0\r\n"
455                         "CPE510(TP-LINK|US|N300-5):2.0\r\n",
456                 .part_trail = 0xff,
457                 .soft_ver = SOFT_VER_DEFAULT,
458 
459                 .partitions = {
460                         {"fs-uboot", 0x00000, 0x20000},
461                         {"partition-table", 0x20000, 0x02000},
462                         {"default-mac", 0x30000, 0x00020},
463                         {"product-info", 0x31100, 0x00100},
464                         {"signature", 0x32000, 0x00400},
465                         {"firmware", 0x40000, 0x770000},
466                         {"soft-version", 0x7b0000, 0x00100},
467                         {"support-list", 0x7b1000, 0x00400},
468                         {"user-config", 0x7c0000, 0x10000},
469                         {"default-config", 0x7d0000, 0x10000},
470                         {"log", 0x7e0000, 0x10000},
471                         {"radio", 0x7f0000, 0x10000},
472                         {NULL, 0, 0}
473                 },
474 
475                 .first_sysupgrade_partition = "os-image",
476                 .last_sysupgrade_partition = "support-list",
477         },
478 
479         /** Firmware layout for the CPE510 V3 */
480         {
481                 .id     = "CPE510V3",
482                 .vendor = "CPE510(TP-LINK|UN|N300-5):3.0\r\n",
483                 .support_list =
484                         "SupportList:\r\n"
485                         "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n"
486                         "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n"
487                         "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n"
488                         "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n"
489                         "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n"
490                         "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n"
491                         "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n"
492                         "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n"
493                         "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n"
494                         "CPE510(TP-LINK|UN|N300-5):3.0\r\n"
495                         "CPE510(TP-LINK|EU|N300-5):3.0\r\n"
496                         "CPE510(TP-LINK|US|N300-5):3.0\r\n"
497                         "CPE510(TP-LINK|UN|N300-5|00000000):3.20\r\n"
498                         "CPE510(TP-LINK|US|N300-5|55530000):3.20\r\n"
499                         "CPE510(TP-LINK|EU|N300-5|45550000):3.20\r\n",
500                 .part_trail = 0xff,
501                 .soft_ver = SOFT_VER_DEFAULT,
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                         {"firmware", 0x40000, 0x770000},
510                         {"soft-version", 0x7b0000, 0x00100},
511                         {"support-list", 0x7b1000, 0x00400},
512                         {"user-config", 0x7c0000, 0x10000},
513                         {"default-config", 0x7d0000, 0x10000},
514                         {"log", 0x7e0000, 0x10000},
515                         {"radio", 0x7f0000, 0x10000},
516                         {NULL, 0, 0}
517                 },
518 
519                 .first_sysupgrade_partition = "os-image",
520                 .last_sysupgrade_partition = "support-list",
521         },
522 
523         /** Firmware layout for the CPE605V1 */
524         {
525                 .id     = "CPE605V1",
526                 .vendor = "CPE605(TP-LINK|UN|N150-5):1.0\r\n",
527                 .support_list =
528                         "SupportList:\r\n"
529                         "CPE605(TP-LINK|UN|N150-5|00000000):1.0\r\n"
530                         "CPE605(TP-LINK|EU|N150-5|45550000):1.0\r\n"
531                         "CPE605(TP-LINK|US|N150-5|55530000):1.0\r\n",
532                 .part_trail = 0x00,
533                 .soft_ver = SOFT_VER_DEFAULT,
534 
535                 .partitions = {
536                         {"fs-uboot", 0x00000, 0x20000},
537                         {"partition-table", 0x20000, 0x02000},
538                         {"default-mac", 0x30000, 0x00020},
539                         {"serial-number", 0x30100, 0x00020},
540                         {"product-info", 0x31100, 0x00100},
541                         {"device-info", 0x31400, 0x00400},
542                         {"signature", 0x32000, 0x00400},
543                         {"device-id", 0x33000, 0x00100},
544                         {"firmware", 0x40000, 0x770000},
545                         {"soft-version", 0x7b0000, 0x00100},
546                         {"support-list", 0x7b1000, 0x01000},
547                         {"user-config", 0x7c0000, 0x10000},
548                         {"default-config", 0x7d0000, 0x10000},
549                         {"log", 0x7e0000, 0x10000},
550                         {"radio", 0x7f0000, 0x10000},
551                         {NULL, 0, 0}
552                 },
553 
554                 .first_sysupgrade_partition = "os-image",
555                 .last_sysupgrade_partition = "support-list",
556         },
557 
558         /** Firmware layout for the CPE610V1 */
559         {
560                 .id     = "CPE610V1",
561                 .vendor = "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n",
562                 .support_list =
563                         "SupportList:\r\n"
564                         "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n"
565                         "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n"
566                         "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n"
567                         "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n"
568                         "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n"
569                         "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n"
570                         "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n"
571                         "CPE610(TP-LINK|UN|N300-5):1.0\r\n"
572                         "CPE610(TP-LINK|EU|N300-5):1.0\r\n"
573                         "CPE610(TP-LINK|US|N300-5):1.0\r\n",
574                 .part_trail = 0xff,
575                 .soft_ver = SOFT_VER_DEFAULT,
576 
577                 .partitions = {
578                         {"fs-uboot", 0x00000, 0x20000},
579                         {"partition-table", 0x20000, 0x02000},
580                         {"default-mac", 0x30000, 0x00020},
581                         {"product-info", 0x31100, 0x00100},
582                         {"signature", 0x32000, 0x00400},
583                         {"firmware", 0x40000, 0x770000},
584                         {"soft-version", 0x7b0000, 0x00100},
585                         {"support-list", 0x7b1000, 0x00400},
586                         {"user-config", 0x7c0000, 0x10000},
587                         {"default-config", 0x7d0000, 0x10000},
588                         {"log", 0x7e0000, 0x10000},
589                         {"radio", 0x7f0000, 0x10000},
590                         {NULL, 0, 0}
591                 },
592 
593                 .first_sysupgrade_partition = "os-image",
594                 .last_sysupgrade_partition = "support-list",
595         },
596 
597         /** Firmware layout for the CPE610V2 */
598         {
599                 .id     = "CPE610V2",
600                 .vendor = "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n",
601                 .support_list =
602                         "SupportList:\r\n"
603                         "CPE610(TP-LINK|EU|N300-5|00000000):2.0\r\n"
604                         "CPE610(TP-LINK|EU|N300-5|45550000):2.0\r\n"
605                         "CPE610(TP-LINK|EU|N300-5|55530000):2.0\r\n"
606                         "CPE610(TP-LINK|UN|N300-5|00000000):2.0\r\n"
607                         "CPE610(TP-LINK|UN|N300-5|45550000):2.0\r\n"
608                         "CPE610(TP-LINK|UN|N300-5|55530000):2.0\r\n"
609                         "CPE610(TP-LINK|US|N300-5|55530000):2.0\r\n"
610                         "CPE610(TP-LINK|UN|N300-5):2.0\r\n"
611                         "CPE610(TP-LINK|EU|N300-5):2.0\r\n"
612                         "CPE610(TP-LINK|US|N300-5):2.0\r\n",
613                 .part_trail = 0xff,
614                 .soft_ver = SOFT_VER_DEFAULT,
615 
616                 .partitions = {
617                         {"fs-uboot", 0x00000, 0x20000},
618                         {"partition-table", 0x20000, 0x02000},
619                         {"default-mac", 0x30000, 0x00020},
620                         {"product-info", 0x31100, 0x00100},
621                         {"signature", 0x32000, 0x00400},
622                         {"firmware", 0x40000, 0x770000},
623                         {"soft-version", 0x7b0000, 0x00100},
624                         {"support-list", 0x7b1000, 0x00400},
625                         {"user-config", 0x7c0000, 0x10000},
626                         {"default-config", 0x7d0000, 0x10000},
627                         {"log", 0x7e0000, 0x10000},
628                         {"radio", 0x7f0000, 0x10000},
629                         {NULL, 0, 0}
630                 },
631 
632                 .first_sysupgrade_partition = "os-image",
633                 .last_sysupgrade_partition = "support-list",
634         },
635         /** Firmware layout for the CPE710 V1 */
636         {
637                 .id     = "CPE710V1",
638                 .vendor = "CPE710(TP-LINK|UN|AC866-5|00000000):1.0\r\n",
639                 .support_list =
640                         "SupportList:\r\n"
641                         "CPE710(TP-LINK|UN|AC866-5|00000000):1.0\r\n"
642                         "CPE710(TP-LINK|EU|AC866-5|45550000):1.0\r\n"
643                         "CPE710(TP-LINK|US|AC866-5|55530000):1.0\r\n"
644                         "CPE710(TP-LINK|UN|AC866-5):1.0\r\n"
645                         "CPE710(TP-LINK|EU|AC866-5):1.0\r\n"
646                         "CPE710(TP-LINK|US|AC866-5):1.0\r\n",
647                 .part_trail = 0xff,
648                 .soft_ver = SOFT_VER_DEFAULT,
649 
650                 .partitions = {
651                         {"fs-uboot", 0x00000, 0x50000},
652                         {"partition-table", 0x50000, 0x02000},
653                         {"default-mac", 0x60000, 0x00020},
654                         {"serial-number", 0x60100, 0x00020},
655                         {"product-info", 0x61100, 0x00100},
656                         {"device-info", 0x61400, 0x00400},
657                         {"signature", 0x62000, 0x00400},
658                         {"device-id", 0x63000, 0x00100},
659                         {"firmware", 0x70000, 0xf40000},
660                         {"soft-version", 0xfb0000, 0x00100},
661                         {"support-list", 0xfb1000, 0x01000},
662                         {"user-config", 0xfc0000, 0x10000},
663                         {"default-config", 0xfd0000, 0x10000},
664                         {"log", 0xfe0000, 0x10000},
665                         {"radio", 0xff0000, 0x10000},
666                         {NULL, 0, 0}
667                 },
668 
669                 .first_sysupgrade_partition = "os-image",
670                 .last_sysupgrade_partition = "support-list",
671         },
672         /** Firmware layout for the CPE710 V2 */
673         {
674                 .id     = "CPE710V2",
675                 .vendor = "CPE710(TP-LINK|UN|AC866-5|00000000):2.0\r\n",
676                 .support_list =
677                         "SupportList:\r\n"
678                         "CPE710(TP-LINK|UN|AC866-5|00000000):2.0\r\n"
679                         "CPE710(TP-LINK|EU|AC866-5|45550000):2.0\r\n"
680                         "CPE710(TP-LINK|US|AC866-5|55530000):2.0\r\n"
681                         "CPE710(TP-LINK|UN|AC866-5):2.0\r\n"
682                         "CPE710(TP-LINK|EU|AC866-5):2.0\r\n"
683                         "CPE710(TP-LINK|US|AC866-5):2.0\r\n",
684                 .part_trail = 0xff,
685                 .soft_ver = SOFT_VER_NUMERIC(1, 0, 0),
686                 .soft_ver_compat_level = 1,
687 
688                 .partitions = {
689                         {"fs-uboot", 0x00000, 0x50000},
690                         {"partition-table", 0x50000, 0x02000},
691                         {"default-mac", 0x60000, 0x00020},
692                         {"serial-number", 0x60100, 0x00020},
693                         {"product-info", 0x61100, 0x00100},
694                         {"device-info", 0x61400, 0x00400},
695                         {"signature", 0x62000, 0x00400},
696                         {"device-id", 0x63000, 0x00100},
697                         {"firmware", 0x70000, 0xf40000},
698                         {"soft-version", 0xfb0000, 0x00100},
699                         {"support-list", 0xfb1000, 0x01000},
700                         {"user-config", 0xfc0000, 0x10000},
701                         {"default-config", 0xfd0000, 0x10000},
702                         {"log", 0xfe0000, 0x10000},
703                         {"radio", 0xff0000, 0x10000},
704                         {NULL, 0, 0}
705                 },
706 
707                 .first_sysupgrade_partition = "os-image",
708                 .last_sysupgrade_partition = "support-list",
709         },
710 
711         {
712                 .id     = "WBS210",
713                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
714                 .support_list =
715                         "SupportList:\r\n"
716                         "WBS210(TP-LINK|UN|N300-2):1.20\r\n"
717                         "WBS210(TP-LINK|US|N300-2):1.20\r\n"
718                         "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
719                 .part_trail = 0xff,
720                 .soft_ver = SOFT_VER_DEFAULT,
721 
722                 .partitions = {
723                         {"fs-uboot", 0x00000, 0x20000},
724                         {"partition-table", 0x20000, 0x02000},
725                         {"default-mac", 0x30000, 0x00020},
726                         {"product-info", 0x31100, 0x00100},
727                         {"signature", 0x32000, 0x00400},
728                         {"firmware", 0x40000, 0x770000},
729                         {"soft-version", 0x7b0000, 0x00100},
730                         {"support-list", 0x7b1000, 0x00400},
731                         {"user-config", 0x7c0000, 0x10000},
732                         {"default-config", 0x7d0000, 0x10000},
733                         {"log", 0x7e0000, 0x10000},
734                         {"radio", 0x7f0000, 0x10000},
735                         {NULL, 0, 0}
736                 },
737 
738                 .first_sysupgrade_partition = "os-image",
739                 .last_sysupgrade_partition = "support-list",
740         },
741 
742         {
743                 .id     = "WBS210V2",
744                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
745                 .support_list =
746                         "SupportList:\r\n"
747                         "WBS210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
748                         "WBS210(TP-LINK|US|N300-2|55530000):2.0\r\n"
749                         "WBS210(TP-LINK|EU|N300-2|45550000):2.0\r\n",
750                 .part_trail = 0xff,
751                 .soft_ver = SOFT_VER_DEFAULT,
752 
753                 .partitions = {
754                         {"fs-uboot", 0x00000, 0x20000},
755                         {"partition-table", 0x20000, 0x02000},
756                         {"default-mac", 0x30000, 0x00020},
757                         {"product-info", 0x31100, 0x00100},
758                         {"signature", 0x32000, 0x00400},
759                         {"firmware", 0x40000, 0x770000},
760                         {"soft-version", 0x7b0000, 0x00100},
761                         {"support-list", 0x7b1000, 0x00400},
762                         {"user-config", 0x7c0000, 0x10000},
763                         {"default-config", 0x7d0000, 0x10000},
764                         {"log", 0x7e0000, 0x10000},
765                         {"radio", 0x7f0000, 0x10000},
766                         {NULL, 0, 0}
767                 },
768 
769                 .first_sysupgrade_partition = "os-image",
770                 .last_sysupgrade_partition = "support-list",
771         },
772 
773         {
774                 .id     = "WBS510",
775                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
776                 .support_list =
777                         "SupportList:\r\n"
778                         "WBS510(TP-LINK|UN|N300-5):1.20\r\n"
779                         "WBS510(TP-LINK|US|N300-5):1.20\r\n"
780                         "WBS510(TP-LINK|EU|N300-5):1.20\r\n"
781                         "WBS510(TP-LINK|CA|N300-5):1.20\r\n",
782                 .part_trail = 0xff,
783                 .soft_ver = SOFT_VER_DEFAULT,
784 
785                 .partitions = {
786                         {"fs-uboot", 0x00000, 0x20000},
787                         {"partition-table", 0x20000, 0x02000},
788                         {"default-mac", 0x30000, 0x00020},
789                         {"product-info", 0x31100, 0x00100},
790                         {"signature", 0x32000, 0x00400},
791                         {"firmware", 0x40000, 0x770000},
792                         {"soft-version", 0x7b0000, 0x00100},
793                         {"support-list", 0x7b1000, 0x00400},
794                         {"user-config", 0x7c0000, 0x10000},
795                         {"default-config", 0x7d0000, 0x10000},
796                         {"log", 0x7e0000, 0x10000},
797                         {"radio", 0x7f0000, 0x10000},
798                         {NULL, 0, 0}
799                 },
800 
801                 .first_sysupgrade_partition = "os-image",
802                 .last_sysupgrade_partition = "support-list",
803         },
804 
805         {
806                 .id     = "WBS510V2",
807                 .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n",
808                 .support_list =
809                         "SupportList:\r\n"
810                         "WBS510(TP-LINK|UN|N300-5|00000000):2.0\r\n"
811                         "WBS510(TP-LINK|US|N300-5|55530000):2.0\r\n"
812                         "WBS510(TP-LINK|EU|N300-5|45550000):2.0\r\n"
813                         "WBS510(TP-LINK|CA|N300-5|43410000):2.0\r\n",
814                 .part_trail = 0xff,
815                 .soft_ver = SOFT_VER_DEFAULT,
816 
817                 .partitions = {
818                         {"fs-uboot", 0x00000, 0x20000},
819                         {"partition-table", 0x20000, 0x02000},
820                         {"default-mac", 0x30000, 0x00020},
821                         {"product-info", 0x31100, 0x00100},
822                         {"signature", 0x32000, 0x00400},
823                         {"firmware", 0x40000, 0x770000},
824                         {"soft-version", 0x7b0000, 0x00100},
825                         {"support-list", 0x7b1000, 0x00400},
826                         {"user-config", 0x7c0000, 0x10000},
827                         {"default-config", 0x7d0000, 0x10000},
828                         {"log", 0x7e0000, 0x10000},
829                         {"radio", 0x7f0000, 0x10000},
830                         {NULL, 0, 0}
831                 },
832 
833                 .first_sysupgrade_partition = "os-image",
834                 .last_sysupgrade_partition = "support-list",
835         },
836 
837         /** Firmware layout for the AD7200 */
838         {
839                 .id = "AD7200",
840                 .vendor = "",
841                 .support_list =
842                         "SupportList:\r\n"
843                         "{product_name:AD7200,product_ver:1.0.0,special_id:00000000}\r\n",
844                 .part_trail = 0x00,
845                 .soft_ver = SOFT_VER_DEFAULT,
846 
847                 .partitions = {
848                         {"SBL1", 0x00000, 0x20000},
849                         {"MIBIB", 0x20000, 0x20000},
850                         {"SBL2", 0x40000, 0x20000},
851                         {"SBL3", 0x60000, 0x30000},
852                         {"DDRCONFIG", 0x90000, 0x10000},
853                         {"SSD", 0xa0000, 0x10000},
854                         {"TZ", 0xb0000, 0x30000},
855                         {"RPM", 0xe0000, 0x20000},
856                         {"fs-uboot", 0x100000, 0x70000},
857                         {"uboot-env", 0x170000, 0x40000},
858                         {"radio", 0x1b0000, 0x40000},
859                         {"os-image", 0x1f0000, 0x400000},
860                         {"file-system", 0x5f0000, 0x1900000},
861                         {"default-mac", 0x1ef0000, 0x00200},
862                         {"pin", 0x1ef0200, 0x00200},
863                         {"device-id", 0x1ef0400, 0x00200},
864                         {"product-info", 0x1ef0600, 0x0fa00},
865                         {"partition-table", 0x1f00000, 0x10000},
866                         {"soft-version", 0x1f10000, 0x10000},
867                         {"support-list", 0x1f20000, 0x10000},
868                         {"profile", 0x1f30000, 0x10000},
869                         {"default-config", 0x1f40000, 0x10000},
870                         {"user-config", 0x1f50000, 0x40000},
871                         {"qos-db", 0x1f90000, 0x40000},
872                         {"usb-config", 0x1fd0000, 0x10000},
873                         {"log", 0x1fe0000, 0x20000},
874                         {NULL, 0, 0}
875                 },
876 
877                 .first_sysupgrade_partition = "os-image",
878                 .last_sysupgrade_partition = "file-system"
879         },
880 
881         /** Firmware layout for the C2600 */
882         {
883                 .id     = "C2600",
884                 .vendor = "",
885                 .support_list =
886                         "SupportList:\r\n"
887                         "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
888                 .part_trail = 0x00,
889                 .soft_ver = SOFT_VER_DEFAULT,
890 
891                 /**
892                     We use a bigger os-image partition than the stock images (and thus
893                     smaller file-system), as our kernel doesn't fit in the stock firmware's
894                     2 MB os-image since kernel 4.14.
895                 */
896                 .partitions = {
897                         {"SBL1", 0x00000, 0x20000},
898                         {"MIBIB", 0x20000, 0x20000},
899                         {"SBL2", 0x40000, 0x20000},
900                         {"SBL3", 0x60000, 0x30000},
901                         {"DDRCONFIG", 0x90000, 0x10000},
902                         {"SSD", 0xa0000, 0x10000},
903                         {"TZ", 0xb0000, 0x30000},
904                         {"RPM", 0xe0000, 0x20000},
905                         {"fs-uboot", 0x100000, 0x70000},
906                         {"uboot-env", 0x170000, 0x40000},
907                         {"radio", 0x1b0000, 0x40000},
908                         {"os-image", 0x1f0000, 0x400000}, /* Stock: base 0x1f0000 size 0x200000 */
909                         {"file-system", 0x5f0000, 0x1900000}, /* Stock: base 0x3f0000 size 0x1b00000 */
910                         {"default-mac", 0x1ef0000, 0x00200},
911                         {"pin", 0x1ef0200, 0x00200},
912                         {"product-info", 0x1ef0400, 0x0fc00},
913                         {"partition-table", 0x1f00000, 0x10000},
914                         {"soft-version", 0x1f10000, 0x10000},
915                         {"support-list", 0x1f20000, 0x10000},
916                         {"profile", 0x1f30000, 0x10000},
917                         {"default-config", 0x1f40000, 0x10000},
918                         {"user-config", 0x1f50000, 0x40000},
919                         {"qos-db", 0x1f90000, 0x40000},
920                         {"usb-config", 0x1fd0000, 0x10000},
921                         {"log", 0x1fe0000, 0x20000},
922                         {NULL, 0, 0}
923                 },
924 
925                 .first_sysupgrade_partition = "os-image",
926                 .last_sysupgrade_partition = "file-system"
927         },
928 
929         /** Firmware layout for the A7-V5 */
930         {
931                 .id     = "ARCHER-A7-V5",
932                 .support_list =
933                         "SupportList:\n"
934                         "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n"
935                         "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n"
936                         "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n"
937                         "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n"
938                         "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n"
939                         "{product_name:Archer A7,product_ver:5.0.0,special_id:52550000}\n",
940                 .part_trail = 0x00,
941                 .soft_ver = SOFT_VER_TEXT("soft_ver:7.0.0\n"),
942 
943                 /* We're using a dynamic kernel/rootfs split here */
944                 .partitions = {
945                         {"factory-boot", 0x00000, 0x20000},
946                         {"fs-uboot", 0x20000, 0x20000},
947                         {"firmware", 0x40000, 0xec0000},        /* Stock: name os-image base 0x40000 size 0x120000 */
948                                                                 /* Stock: name file-system base 0x160000 size 0xda0000 */
949                         {"default-mac", 0xf40000, 0x00200},
950                         {"pin", 0xf40200, 0x00200},
951                         {"device-id", 0xf40400, 0x00100},
952                         {"product-info", 0xf40500, 0x0fb00},
953                         {"soft-version", 0xf50000, 0x00100},
954                         {"extra-para", 0xf51000, 0x01000},
955                         {"support-list", 0xf52000, 0x0a000},
956                         {"profile", 0xf5c000, 0x04000},
957                         {"default-config", 0xf60000, 0x10000},
958                         {"user-config", 0xf70000, 0x40000},
959                         {"certificate", 0xfb0000, 0x10000},
960                         {"partition-table", 0xfc0000, 0x10000},
961                         {"log", 0xfd0000, 0x20000},
962                         {"radio", 0xff0000, 0x10000},
963                         {NULL, 0, 0}
964                 },
965 
966                 .first_sysupgrade_partition = "os-image",
967                 .last_sysupgrade_partition = "file-system",
968         },
969 
970         /** Firmware layout for the Archer A9 v6 */
971         {
972                 .id     = "ARCHER-A9-V6",
973                 .support_list =
974                         "SupportList:\n"
975                         "{product_name:Archer A9,product_ver:6.0,special_id:55530000}\n"
976                         "{product_name:Archer A9,product_ver:6.0,special_id:45550000}\n"
977                         "{product_name:Archer A9,product_ver:6.0,special_id:52550000}\n"
978                         "{product_name:Archer A9,product_ver:6.0,special_id:4A500000}\n"
979                         "{product_name:Archer C90,product_ver:6.0,special_id:55530000}\n",
980                 .part_trail = 0x00,
981                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.1.0\n"),
982 
983                 /* We're using a dynamic kernel/rootfs split here */
984                 .partitions = {
985                         {"factory-boot", 0x00000, 0x20000},
986                         {"fs-uboot", 0x20000, 0x20000},
987                         {"partition-table", 0x40000, 0x10000},
988                         {"radio", 0x50000, 0x10000},
989                         {"default-mac", 0x60000, 0x00200},
990                         {"pin", 0x60200, 0x00200},
991                         {"device-id", 0x60400, 0x00100},
992                         {"product-info", 0x60500, 0x0fb00},
993                         {"soft-version", 0x70000, 0x01000},
994                         {"extra-para", 0x71000, 0x01000},
995                         {"support-list", 0x72000, 0x0a000},
996                         {"profile", 0x7c000, 0x04000},
997                         {"user-config", 0x80000, 0x10000},
998                         {"ap-config", 0x90000, 0x10000},
999                         {"apdef-config", 0xa0000, 0x10000},
1000                         {"router-config", 0xb0000, 0x10000},
1001                         {"firmware", 0xc0000, 0xf00000},        /* Stock: name os-image base 0xc0000 size 0x120000 */
1002                                                                 /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1003                         {"log", 0xfc0000, 0x20000},
1004                         {"certificate", 0xfe0000, 0x10000},
1005                         {"default-config", 0xff0000, 0x10000},
1006                         {NULL, 0, 0}
1007                 },
1008 
1009                 .first_sysupgrade_partition = "os-image",
1010                 .last_sysupgrade_partition = "file-system",
1011         },
1012 
1013         /** Firmware layout for the Archer AX21 v4 */
1014         {
1015                 .id     = "ARCHER-AX21-V4",
1016                 .vendor = "",
1017                 .support_list =
1018                         "SupportList:\n"
1019                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:55530000}\n"
1020                         "{product_name:Archer AX23,product_ver:1.20,special_id:55530000}\n"
1021                         "{product_name:Archer AX1800,product_ver:4.6,special_id:55530000}\n"
1022                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:43410000}\n"
1023                         "{product_name:Archer AX23,product_ver:1.20,special_id:43410000}\n"
1024                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:54570000}\n"
1025                         "{product_name:Archer AX23,product_ver:1.20,special_id:54570000}\n"
1026                         "{product_name:Archer AX20,product_ver:4.6,special_id:55530000}\n"
1027                         "{product_name:Archer AX21,product_ver:4.6,special_id:55530000}\n",
1028                 .part_trail = 0x00,
1029                 .soft_ver = SOFT_VER_TEXT("1.0.5\n"),
1030 
1031                 .partitions = {
1032                         {"fs-uboot", 0x00000, 0x40000},
1033                         {"os-image", 0x40000, 0x400000},
1034                         {"file-system", 0x440000, 0xb60000},
1035                         {"default-mac", 0xfa0000, 0x00200},
1036                         {"pin", 0xfa0200, 0x00100},
1037                         {"device-id", 0xfa0300, 0x00100},
1038                         {"product-info", 0xfa0400, 0x0fc00},
1039                         {"default-config", 0xfb0000, 0x08000},
1040                         {"ap-def-config", 0xfb8000, 0x08000},
1041                         {"user-config", 0xfc0000, 0x0a000},
1042                         {"ag-config", 0xfca000, 0x04000},
1043                         {"certificate", 0xfce000, 0x02000},
1044                         {"ap-config", 0xfd0000, 0x06000},
1045                         {"router-config", 0xfd6000, 0x06000},
1046                         {"favicon", 0xfdc000, 0x02000},
1047                         {"logo", 0xfde000, 0x02000},
1048                         {"partition-table", 0xfe0000, 0x00800},
1049                         {"soft-version", 0xfe0800, 0x00100},
1050                         {"support-list", 0xfe0900, 0x00400},
1051                         {"profile", 0xfe0d00, 0x03000},
1052                         {"extra-para", 0xfe3d00, 0x00100},
1053                         {"radio",0xff0000, 0x10000},
1054                 },
1055 
1056                 .first_sysupgrade_partition = "os-image",
1057                 .last_sysupgrade_partition = "file-system",
1058         },
1059 
1060         /** Firmware layout for the Archer AX23 v1 */
1061         {
1062                 .id     = "ARCHER-AX23-V1",
1063                 .vendor = "",
1064                 .support_list =
1065                         "SupportList:\n"
1066                         "{product_name:Archer AX23,product_ver:1.0,special_id:45550000}\n"
1067                         "{product_name:Archer AX23,product_ver:1.0,special_id:4A500000}\n"
1068                         "{product_name:Archer AX23,product_ver:1.0,special_id:4B520000}\n"
1069                         "{product_name:Archer AX23,product_ver:1.0,special_id:52550000}\n"
1070                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:43410000}\n"
1071                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:54570000}\n"
1072                         "{product_name:Archer AX23,product_ver:1.0.0,special_id:55530000}\n"
1073                         "{product_name:Archer AX23,product_ver:1.20,special_id:45550000}\n"
1074                         "{product_name:Archer AX23,product_ver:1.20,special_id:4A500000}\n"
1075                         "{product_name:Archer AX23,product_ver:1.20,special_id:52550000}\n"
1076                         "{product_name:Archer AX23,product_ver:1.20,special_id:55530000}\n"
1077                         "{product_name:Archer AX1800,product_ver:1.20,special_id:45550000}\n"
1078                         "{product_name:Archer AX1800,product_ver:1.20,special_id:52550000}\n",
1079                 .part_trail = 0x00,
1080                 .soft_ver = SOFT_VER_TEXT("soft_ver:3.0.3\n"),
1081 
1082                 .partitions = {
1083                         {"fs-uboot", 0x00000, 0x40000},
1084                         {"firmware", 0x40000, 0xf60000},
1085                         {"default-mac", 0xfa0000, 0x00200},
1086                         {"pin", 0xfa0200, 0x00100},
1087                         {"device-id", 0xfa0300, 0x00100},
1088                         {"product-info", 0xfa0400, 0x0fc00},
1089                         {"default-config", 0xfb0000, 0x08000},
1090                         {"ap-def-config", 0xfb8000, 0x08000},
1091                         {"user-config", 0xfc0000, 0x0a000},
1092                         {"ag-config", 0xfca000, 0x04000},
1093                         {"certificate", 0xfce000, 0x02000},
1094                         {"ap-config", 0xfd0000, 0x06000},
1095                         {"router-config", 0xfd6000, 0x06000},
1096                         {"favicon", 0xfdc000, 0x02000},
1097                         {"logo", 0xfde000, 0x02000},
1098                         {"partition-table", 0xfe0000, 0x00800},
1099                         {"soft-version", 0xfe0800, 0x00100},
1100                         {"support-list", 0xfe0900, 0x00400},
1101                         {"profile", 0xfe0d00, 0x03000},
1102                         {"extra-para", 0xfe3d00, 0x00100},
1103                         {"radio", 0xff0000, 0x10000},
1104                         {NULL, 0, 0}
1105                 },
1106                 .first_sysupgrade_partition = "os-image",
1107                 .last_sysupgrade_partition = "file-system",
1108         },
1109         /** Firmware layout for the C2v3 */
1110         {
1111                 .id     = "ARCHER-C2-V3",
1112                 .support_list =
1113                         "SupportList:\n"
1114                         "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n"
1115                         "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n"
1116                         "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n",
1117                 .part_trail = 0x00,
1118                 .soft_ver = SOFT_VER_TEXT("soft_ver:3.0.1\n"),
1119 
1120                 /** We're using a dynamic kernel/rootfs split here */
1121 
1122                 .partitions = {
1123                         {"factory-boot", 0x00000, 0x20000},
1124                         {"fs-uboot", 0x20000, 0x10000},
1125                         {"firmware", 0x30000, 0x7a0000},
1126                         {"user-config", 0x7d0000, 0x04000},
1127                         {"default-mac", 0x7e0000, 0x00100},
1128                         {"device-id", 0x7e0100, 0x00100},
1129                         {"extra-para", 0x7e0200, 0x00100},
1130                         {"pin", 0x7e0300, 0x00100},
1131                         {"support-list", 0x7e0400, 0x00400},
1132                         {"soft-version", 0x7e0800, 0x00400},
1133                         {"product-info", 0x7e0c00, 0x01400},
1134                         {"partition-table", 0x7e2000, 0x01000},
1135                         {"profile", 0x7e3000, 0x01000},
1136                         {"default-config", 0x7e4000, 0x04000},
1137                         {"merge-config", 0x7ec000, 0x02000},
1138                         {"qos-db", 0x7ee000, 0x02000},
1139                         {"radio", 0x7f0000, 0x10000},
1140                         {NULL, 0, 0}
1141                 },
1142 
1143                 .first_sysupgrade_partition = "os-image",
1144                 .last_sysupgrade_partition = "file-system",
1145         },
1146 
1147         /** Firmware layout for the C25v1 */
1148         {
1149                 .id     = "ARCHER-C25-V1",
1150                 .support_list =
1151                         "SupportList:\n"
1152                         "{product_name:ArcherC25,product_ver:1.0.0,special_id:00000000}\n"
1153                         "{product_name:ArcherC25,product_ver:1.0.0,special_id:55530000}\n"
1154                         "{product_name:ArcherC25,product_ver:1.0.0,special_id:45550000}\n",
1155                 .part_trail = 0x00,
1156                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1157 
1158                 /* We're using a dynamic kernel/rootfs split here */
1159                 .partitions = {
1160                         {"factory-boot", 0x00000, 0x20000},
1161                         {"fs-uboot", 0x20000, 0x10000},
1162                         {"firmware", 0x30000, 0x7a0000},        /* Stock: name os-image base 0x30000 size 0x100000 */
1163                                                                 /* Stock: name file-system base 0x130000 size 0x6a0000 */
1164                         {"user-config", 0x7d0000, 0x04000},
1165                         {"default-mac", 0x7e0000, 0x00100},
1166                         {"device-id", 0x7e0100, 0x00100},
1167                         {"extra-para", 0x7e0200, 0x00100},
1168                         {"pin", 0x7e0300, 0x00100},
1169                         {"support-list", 0x7e0400, 0x00400},
1170                         {"soft-version", 0x7e0800, 0x00400},
1171                         {"product-info", 0x7e0c00, 0x01400},
1172                         {"partition-table", 0x7e2000, 0x01000},
1173                         {"profile", 0x7e3000, 0x01000},
1174                         {"default-config", 0x7e4000, 0x04000},
1175                         {"merge-config", 0x7ec000, 0x02000},
1176                         {"qos-db", 0x7ee000, 0x02000},
1177                         {"radio", 0x7f0000, 0x10000},
1178                         {NULL, 0, 0}
1179                 },
1180 
1181                 .first_sysupgrade_partition = "os-image",
1182                 .last_sysupgrade_partition = "file-system",
1183         },
1184 
1185         /** Firmware layout for the C58v1 */
1186         {
1187                 .id     = "ARCHER-C58-V1",
1188                 .vendor = "",
1189                 .support_list =
1190                         "SupportList:\r\n"
1191                         "{product_name:Archer C58,product_ver:1.0.0,special_id:00000000}\r\n"
1192                         "{product_name:Archer C58,product_ver:1.0.0,special_id:45550000}\r\n"
1193                         "{product_name:Archer C58,product_ver:1.0.0,special_id:55530000}\r\n",
1194                 .part_trail = 0x00,
1195                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1196 
1197                 .partitions = {
1198                         {"fs-uboot", 0x00000, 0x10000},
1199                         {"default-mac", 0x10000, 0x00200},
1200                         {"pin", 0x10200, 0x00200},
1201                         {"product-info", 0x10400, 0x00100},
1202                         {"partition-table", 0x10500, 0x00800},
1203                         {"soft-version", 0x11300, 0x00200},
1204                         {"support-list", 0x11500, 0x00100},
1205                         {"device-id", 0x11600, 0x00100},
1206                         {"profile", 0x11700, 0x03900},
1207                         {"default-config", 0x15000, 0x04000},
1208                         {"user-config", 0x19000, 0x04000},
1209                         {"firmware", 0x20000, 0x7c8000},
1210                         {"certyficate", 0x7e8000, 0x08000},
1211                         {"radio", 0x7f0000, 0x10000},
1212                         {NULL, 0, 0}
1213                 },
1214 
1215                 .first_sysupgrade_partition = "os-image",
1216                 .last_sysupgrade_partition = "file-system",
1217         },
1218 
1219         /** Firmware layout for the C59v1 */
1220         {
1221                 .id     = "ARCHER-C59-V1",
1222                 .vendor = "",
1223                 .support_list =
1224                         "SupportList:\r\n"
1225                         "{product_name:Archer C59,product_ver:1.0.0,special_id:00000000}\r\n"
1226                         "{product_name:Archer C59,product_ver:1.0.0,special_id:43410000}\r\n"
1227                         "{product_name:Archer C59,product_ver:1.0.0,special_id:45550000}\r\n"
1228                         "{product_name:Archer C59,product_ver:1.0.0,special_id:52550000}\r\n"
1229                         "{product_name:Archer C59,product_ver:1.0.0,special_id:55530000}\r\n",
1230                 .part_trail = 0x00,
1231                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1232 
1233                 /* We're using a dynamic kernel/rootfs split here */
1234                 .partitions = {
1235                         {"fs-uboot", 0x00000, 0x10000},
1236                         {"default-mac", 0x10000, 0x00200},
1237                         {"pin", 0x10200, 0x00200},
1238                         {"device-id", 0x10400, 0x00100},
1239                         {"product-info", 0x10500, 0x0fb00},
1240                         {"firmware", 0x20000, 0xe30000},
1241                         {"partition-table", 0xe50000, 0x10000},
1242                         {"soft-version", 0xe60000, 0x10000},
1243                         {"support-list", 0xe70000, 0x10000},
1244                         {"profile", 0xe80000, 0x10000},
1245                         {"default-config", 0xe90000, 0x10000},
1246                         {"user-config", 0xea0000, 0x40000},
1247                         {"usb-config", 0xee0000, 0x10000},
1248                         {"certificate", 0xef0000, 0x10000},
1249                         {"qos-db", 0xf00000, 0x40000},
1250                         {"log", 0xfe0000, 0x10000},
1251                         {"radio", 0xff0000, 0x10000},
1252                         {NULL, 0, 0}
1253                 },
1254 
1255                 .first_sysupgrade_partition = "os-image",
1256                 .last_sysupgrade_partition = "file-system",
1257         },
1258 
1259         /** Firmware layout for the C59v2 */
1260         {
1261                 .id     = "ARCHER-C59-V2",
1262                 .vendor = "",
1263                 .support_list =
1264                         "SupportList:\r\n"
1265                         "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n"
1266                         "{product_name:Archer C59,product_ver:2.0.0,special_id:43410000}\r\n"
1267                         "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n"
1268                         "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n",
1269                 .part_trail = 0x00,
1270                 .soft_ver = SOFT_VER_TEXT("soft_ver:2.0.0 Build 20161206 rel.7303\n"),
1271 
1272                 /** We're using a dynamic kernel/rootfs split here */
1273                 .partitions = {
1274                         {"factory-boot", 0x00000, 0x20000},
1275                         {"fs-uboot", 0x20000, 0x10000},
1276                         {"default-mac", 0x30000, 0x00200},
1277                         {"pin", 0x30200, 0x00200},
1278                         {"device-id", 0x30400, 0x00100},
1279                         {"product-info", 0x30500, 0x0fb00},
1280                         {"firmware", 0x40000, 0xe10000},
1281                         {"partition-table", 0xe50000, 0x10000},
1282                         {"soft-version", 0xe60000, 0x10000},
1283                         {"support-list", 0xe70000, 0x10000},
1284                         {"profile", 0xe80000, 0x10000},
1285                         {"default-config", 0xe90000, 0x10000},
1286                         {"user-config", 0xea0000, 0x40000},
1287                         {"usb-config", 0xee0000, 0x10000},
1288                         {"certificate", 0xef0000, 0x10000},
1289                         {"extra-para", 0xf00000, 0x10000},
1290                         {"qos-db", 0xf10000, 0x30000},
1291                         {"log", 0xfe0000, 0x10000},
1292                         {"radio", 0xff0000, 0x10000},
1293                         {NULL, 0, 0}
1294                 },
1295 
1296                 .first_sysupgrade_partition = "os-image",
1297                 .last_sysupgrade_partition = "file-system",
1298         },
1299 
1300         /** Firmware layout for the Archer C6 v2 (EU/RU/JP) */
1301         {
1302                 .id     = "ARCHER-C6-V2",
1303                 .vendor = "",
1304                 .support_list =
1305                         "SupportList:\r\n"
1306                         "{product_name:Archer A6,product_ver:2.0.0,special_id:45550000}\r\n"
1307                         "{product_name:Archer A6,product_ver:2.0.0,special_id:52550000}\r\n"
1308                         "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n"
1309                         "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
1310                         "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
1311                 .part_trail = 0x00,
1312                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.9.1\n"),
1313 
1314                 .partitions = {
1315                         {"fs-uboot", 0x00000, 0x20000},
1316                         {"default-mac", 0x20000, 0x00200},
1317                         {"pin", 0x20200, 0x00100},
1318                         {"product-info", 0x20300, 0x00200},
1319                         {"device-id", 0x20500, 0x0fb00},
1320                         {"firmware", 0x30000, 0x7a9400},
1321                         {"soft-version", 0x7d9400, 0x00100},
1322                         {"extra-para", 0x7d9500, 0x00100},
1323                         {"support-list", 0x7d9600, 0x00200},
1324                         {"profile", 0x7d9800, 0x03000},
1325                         {"default-config", 0x7dc800, 0x03000},
1326                         {"partition-table", 0x7df800, 0x00800},
1327                         {"user-config", 0x7e0000, 0x0c000},
1328                         {"certificate", 0x7ec000, 0x04000},
1329                         {"radio", 0x7f0000, 0x10000},
1330                         {NULL, 0, 0}
1331                 },
1332 
1333                 .first_sysupgrade_partition = "os-image",
1334                 .last_sysupgrade_partition = "file-system",
1335         },
1336 
1337         /** Firmware layout for the Archer C6 v2 (US) and A6 v2 (US/TW) */
1338         {
1339                 .id     = "ARCHER-C6-V2-US",
1340                 .vendor = "",
1341                 .support_list =
1342                         "SupportList:\n"
1343                         "{product_name:Archer A6,product_ver:2.0.0,special_id:55530000}\n"
1344                         "{product_name:Archer A6,product_ver:2.0.0,special_id:54570000}\n"
1345                         "{product_name:Archer C6,product_ver:2.0.0,special_id:55530000}\n",
1346                 .part_trail = 0x00,
1347                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.9.1\n"),
1348 
1349                 .partitions = {
1350                         {"factory-boot", 0x00000, 0x20000},
1351                         {"default-mac", 0x20000, 0x00200},
1352                         {"pin", 0x20200, 0x00100},
1353                         {"product-info", 0x20300, 0x00200},
1354                         {"device-id", 0x20500, 0x0fb00},
1355                         {"fs-uboot", 0x30000, 0x20000},
1356                         {"firmware", 0x50000, 0xf89400},
1357                         {"soft-version", 0xfd9400, 0x00100},
1358                         {"extra-para", 0xfd9500, 0x00100},
1359                         {"support-list", 0xfd9600, 0x00200},
1360                         {"profile", 0xfd9800, 0x03000},
1361                         {"default-config", 0xfdc800, 0x03000},
1362                         {"partition-table", 0xfdf800, 0x00800},
1363                         {"user-config", 0xfe0000, 0x0c000},
1364                         {"certificate", 0xfec000, 0x04000},
1365                         {"radio", 0xff0000, 0x10000},
1366                         {NULL, 0, 0}
1367                 },
1368                 .first_sysupgrade_partition = "os-image",
1369                 .last_sysupgrade_partition = "file-system",
1370         },
1371         /** Firmware layout for the Archer C6 v3 */
1372         {
1373                 .id     = "ARCHER-C6-V3",
1374                 .vendor = "",
1375                 .support_list =
1376                         "SupportList:\n"
1377                         "{product_name:Archer C6,product_ver:3.20,special_id:55530000}"
1378                         "{product_name:Archer C6,product_ver:3.20,special_id:45550000}"
1379                         "{product_name:Archer C6,product_ver:3.20,special_id:52550000}"
1380                         "{product_name:Archer C6,product_ver:3.20,special_id:4A500000}"
1381                         "{product_name:Archer C6,product_ver:3.20,special_id:4B520000}"
1382                         "{product_name:Archer C6,product_ver:3.0.0,special_id:42520000}",
1383                 .part_trail = 0x00,
1384                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.9\n"),
1385 
1386                 .partitions = {
1387                         {"fs-uboot", 0x00000, 0x40000},
1388                         {"firmware", 0x40000, 0xf60000},
1389                         {"default-mac", 0xfa0000, 0x00200},
1390                         {"pin", 0xfa0200, 0x00100},
1391                         {"device-id", 0xfa0300, 0x00100},
1392                         {"product-info", 0xfa0400, 0x0fc00},
1393                         {"default-config", 0xfb0000, 0x08000},
1394                         {"ap-def-config", 0xfb8000, 0x08000},
1395                         {"user-config", 0xfc0000, 0x0a000},
1396                         {"ag-config", 0xfca000, 0x04000},
1397                         {"certificate", 0xfce000, 0x02000},
1398                         {"ap-config", 0xfd0000, 0x06000},
1399                         {"router-config", 0xfd6000, 0x06000},
1400                         {"favicon", 0xfdc000, 0x02000},
1401                         {"logo", 0xfde000, 0x02000},
1402                         {"partition-table", 0xfe0000, 0x00800},
1403                         {"soft-version", 0xfe0800, 0x00100},
1404                         {"support-list", 0xfe0900, 0x00200},
1405                         {"profile", 0xfe0b00, 0x03000},
1406                         {"extra-para", 0xfe3b00, 0x00100},
1407                         {"radio", 0xff0000, 0x10000},
1408                         {NULL, 0, 0}
1409                 },
1410                 .first_sysupgrade_partition = "os-image",
1411                 .last_sysupgrade_partition = "file-system",
1412         },
1413         /** Firmware layout for the Archer A6 v3  */
1414         {
1415                 .id     = "ARCHER-A6-V3",
1416                 .vendor = "",
1417                 .support_list =
1418                         "SupportList:\n"
1419                         "{product_name:Archer A6,product_ver:3.0.0,special_id:43410000}\n"
1420                         "{product_name:Archer A6,product_ver:3.0.0,special_id:55530000}\n"
1421                         "{product_name:Archer A6,product_ver:3.0.0,special_id:54570000}\n"
1422                         "{product_name:Archer A6,product_ver:3.0.0,special_id:4A500000}\n"
1423                         "{product_name:Archer A6,product_ver:3.20,special_id:45550000}\n"
1424                         "{product_name:Archer A6,product_ver:3.20,special_id:52550000}\n",
1425                 .part_trail = 0x00,
1426                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.5\n"),
1427 
1428                 .partitions = {
1429                         {"fs-uboot", 0x00000, 0x40000},
1430                         {"firmware", 0x40000, 0xf60000},
1431                         {"default-mac", 0xfa0000, 0x00200},
1432                         {"pin", 0xfa0200, 0x00100},
1433                         {"device-id", 0xfa0300, 0x00100},
1434                         {"product-info", 0xfa0400, 0x0fc00},
1435                         {"default-config", 0xfb0000, 0x08000},
1436                         {"ap-def-config", 0xfb8000, 0x08000},
1437                         {"user-config", 0xfc0000, 0x0a000},
1438                         {"ag-config", 0xfca000, 0x04000},
1439                         {"certificate", 0xfce000, 0x02000},
1440                         {"ap-config", 0xfd0000, 0x06000},
1441                         {"router-config", 0xfd6000, 0x06000},
1442                         {"favicon", 0xfdc000, 0x02000},
1443                         {"logo", 0xfde000, 0x02000},
1444                         {"partition-table", 0xfe0000, 0x00800},
1445                         {"soft-version", 0xfe0800, 0x00100},
1446                         {"support-list", 0xfe0900, 0x00200},
1447                         {"profile", 0xfe0b00, 0x03000},
1448                         {"extra-para", 0xfe3b00, 0x00100},
1449                         {"radio", 0xff0000, 0x10000},
1450                         {NULL, 0, 0}
1451                 },
1452                 .first_sysupgrade_partition = "os-image",
1453                 .last_sysupgrade_partition = "file-system",
1454         },
1455         /** Firmware layout for the Archer C6U v1 */
1456         {
1457                 .id     = "ARCHER-C6U-V1",
1458                 .vendor = "",
1459                 .support_list =
1460                         "SupportList:\n"
1461                         "{product_name:Archer C6U,product_ver:1.0.0,special_id:45550000}\n"
1462                         "{product_name:Archer C6U,product_ver:1.0.0,special_id:52550000}\n",
1463                 .part_trail = 0x00,
1464                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.2\n"),
1465 
1466                 .partitions = {
1467                         {"fs-uboot", 0x00000, 0x40000},
1468                         {"firmware", 0x40000, 0xf60000},
1469                         {"default-mac", 0xfa0000, 0x00200},
1470                         {"pin", 0xfa0200, 0x00100},
1471                         {"device-id", 0xfa0300, 0x00100},
1472                         {"product-info", 0xfa0400, 0x0fc00},
1473                         {"default-config", 0xfb0000, 0x08000},
1474                         {"ap-def-config", 0xfb8000, 0x08000},
1475                         {"user-config", 0xfc0000, 0x0c000},
1476                         {"certificate", 0xfcc000, 0x04000},
1477                         {"ap-config", 0xfd0000, 0x08000},
1478                         {"router-config", 0xfd8000, 0x08000},
1479                         {"partition-table", 0xfe0000, 0x00800},
1480                         {"soft-version", 0xfe0800, 0x00100},
1481                         {"support-list", 0xfe0900, 0x00200},
1482                         {"profile", 0xfe0b00, 0x03000},
1483                         {"extra-para", 0xfe3b00, 0x00100},
1484                         {"radio", 0xff0000, 0x10000},
1485                         {NULL, 0, 0}
1486                 },
1487                 .first_sysupgrade_partition = "os-image",
1488                 .last_sysupgrade_partition = "file-system",
1489         },
1490         /** Firmware layout for the C60v1 */
1491         {
1492                 .id     = "ARCHER-C60-V1",
1493                 .vendor = "",
1494                 .support_list =
1495                         "SupportList:\r\n"
1496                         "{product_name:Archer C60,product_ver:1.0.0,special_id:00000000}\r\n"
1497                         "{product_name:Archer C60,product_ver:1.0.0,special_id:43410000}\r\n"
1498                         "{product_name:Archer C60,product_ver:1.0.0,special_id:45550000}\r\n"
1499                         "{product_name:Archer C60,product_ver:1.0.0,special_id:55530000}\r\n",
1500                 .part_trail = 0x00,
1501                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1502 
1503                 .partitions = {
1504                         {"fs-uboot", 0x00000, 0x10000},
1505                         {"default-mac", 0x10000, 0x00200},
1506                         {"pin", 0x10200, 0x00200},
1507                         {"product-info", 0x10400, 0x00100},
1508                         {"partition-table", 0x10500, 0x00800},
1509                         {"soft-version", 0x11300, 0x00200},
1510                         {"support-list", 0x11500, 0x00100},
1511                         {"device-id", 0x11600, 0x00100},
1512                         {"profile", 0x11700, 0x03900},
1513                         {"default-config", 0x15000, 0x04000},
1514                         {"user-config", 0x19000, 0x04000},
1515                         {"firmware", 0x20000, 0x7c8000},
1516                         {"certyficate", 0x7e8000, 0x08000},
1517                         {"radio", 0x7f0000, 0x10000},
1518                         {NULL, 0, 0}
1519                 },
1520 
1521                 .first_sysupgrade_partition = "os-image",
1522                 .last_sysupgrade_partition = "file-system",
1523         },
1524 
1525         /** Firmware layout for the C60v2 */
1526         {
1527                 .id     = "ARCHER-C60-V2",
1528                 .vendor = "",
1529                 .support_list =
1530                         "SupportList:\r\n"
1531                         "{product_name:Archer C60,product_ver:2.0.0,special_id:42520000}\r\n"
1532                         "{product_name:Archer C60,product_ver:2.0.0,special_id:43410000}\r\n"
1533                         "{product_name:Archer C60,product_ver:2.0.0,special_id:45550000}\r\n"
1534                         "{product_name:Archer C60,product_ver:2.0.0,special_id:55530000}\r\n",
1535                 .part_trail = 0x00,
1536                 .soft_ver = SOFT_VER_TEXT("soft_ver:2.0.0\n"),
1537 
1538                 .partitions = {
1539                         {"factory-boot", 0x00000, 0x1fb00},
1540                         {"default-mac", 0x1fb00, 0x00200},
1541                         {"pin", 0x1fd00, 0x00100},
1542                         {"product-info", 0x1fe00, 0x00100},
1543                         {"device-id", 0x1ff00, 0x00100},
1544                         {"fs-uboot", 0x20000, 0x10000},
1545                         {"firmware", 0x30000, 0x7a0000},
1546                         {"soft-version", 0x7d9500, 0x00100},
1547                         {"support-list", 0x7d9600, 0x00100},
1548                         {"extra-para", 0x7d9700, 0x00100},
1549                         {"profile", 0x7d9800, 0x03000},
1550                         {"default-config", 0x7dc800, 0x03000},
1551                         {"partition-table", 0x7df800, 0x00800},
1552                         {"user-config", 0x7e0000, 0x0c000},
1553                         {"certificate", 0x7ec000, 0x04000},
1554                         {"radio", 0x7f0000, 0x10000},
1555                         {NULL, 0, 0}
1556                 },
1557 
1558                 .first_sysupgrade_partition = "os-image",
1559                 .last_sysupgrade_partition = "file-system",
1560         },
1561 
1562         /** Firmware layout for the C60v3 */
1563         {
1564                 .id     = "ARCHER-C60-V3",
1565                 .vendor = "",
1566                 .support_list =
1567                         "SupportList:\r\n"
1568                         "{product_name:Archer C60,product_ver:3.0.0,special_id:42520000}\r\n"
1569                         "{product_name:Archer C60,product_ver:3.0.0,special_id:43410000}\r\n"
1570                         "{product_name:Archer C60,product_ver:3.0.0,special_id:45550000}\r\n"
1571                         "{product_name:Archer C60,product_ver:3.0.0,special_id:55530000}\r\n",
1572                 .part_trail = 0x00,
1573                 .soft_ver = SOFT_VER_TEXT("soft_ver:3.0.0\n"),
1574 
1575                 .partitions = {
1576                         {"factory-boot", 0x00000, 0x1fb00},
1577                         {"default-mac", 0x1fb00, 0x00200},
1578                         {"pin", 0x1fd00, 0x00100},
1579                         {"product-info", 0x1fe00, 0x00100},
1580                         {"device-id", 0x1ff00, 0x00100},
1581                         {"fs-uboot", 0x20000, 0x10000},
1582                         {"firmware", 0x30000, 0x7a0000},
1583                         {"soft-version", 0x7d9500, 0x00100},
1584                         {"support-list", 0x7d9600, 0x00100},
1585                         {"extra-para", 0x7d9700, 0x00100},
1586                         {"profile", 0x7d9800, 0x03000},
1587                         {"default-config", 0x7dc800, 0x03000},
1588                         {"partition-table", 0x7df800, 0x00800},
1589                         {"user-config", 0x7e0000, 0x0c000},
1590                         {"certificate", 0x7ec000, 0x04000},
1591                         {"radio", 0x7f0000, 0x10000},
1592                         {NULL, 0, 0}
1593                 },
1594 
1595                 .first_sysupgrade_partition = "os-image",
1596                 .last_sysupgrade_partition = "file-system",
1597         },
1598 
1599         /** Firmware layout for the C5 */
1600         {
1601                 .id     = "ARCHER-C5-V2",
1602                 .vendor = "",
1603                 .support_list =
1604                         "SupportList:\r\n"
1605                         "{product_name:ArcherC5,product_ver:2.0.0,special_id:00000000}\r\n"
1606                         "{product_name:ArcherC5,product_ver:2.0.0,special_id:55530000}\r\n"
1607                         "{product_name:ArcherC5,product_ver:2.0.0,special_id:4A500000}\r\n", /* JP version */
1608                 .part_trail = 0x00,
1609                 .soft_ver = SOFT_VER_DEFAULT,
1610 
1611                 .partitions = {
1612                         {"fs-uboot", 0x00000, 0x40000},
1613                         {"os-image", 0x40000, 0x200000},
1614                         {"file-system", 0x240000, 0xc00000},
1615                         {"default-mac", 0xe40000, 0x00200},
1616                         {"pin", 0xe40200, 0x00200},
1617                         {"product-info", 0xe40400, 0x00200},
1618                         {"partition-table", 0xe50000, 0x10000},
1619                         {"soft-version", 0xe60000, 0x00200},
1620                         {"support-list", 0xe61000, 0x0f000},
1621                         {"profile", 0xe70000, 0x10000},
1622                         {"default-config", 0xe80000, 0x10000},
1623                         {"user-config", 0xe90000, 0x50000},
1624                         {"log", 0xee0000, 0x100000},
1625                         {"radio_bk", 0xfe0000, 0x10000},
1626                         {"radio", 0xff0000, 0x10000},
1627                         {NULL, 0, 0}
1628                 },
1629 
1630                 .first_sysupgrade_partition = "os-image",
1631                 .last_sysupgrade_partition = "file-system"
1632         },
1633 
1634         /** Firmware layout for the C7 */
1635         {
1636                 .id     = "ARCHER-C7-V4",
1637                 .support_list =
1638                         "SupportList:\n"
1639                         "{product_name:Archer C7,product_ver:4.0.0,special_id:00000000}\n"
1640                         "{product_name:Archer C7,product_ver:4.0.0,special_id:41550000}\n"
1641                         "{product_name:Archer C7,product_ver:4.0.0,special_id:45550000}\n"
1642                         "{product_name:Archer C7,product_ver:4.0.0,special_id:4B520000}\n"
1643                         "{product_name:Archer C7,product_ver:4.0.0,special_id:42520000}\n"
1644                         "{product_name:Archer C7,product_ver:4.0.0,special_id:4A500000}\n"
1645                         "{product_name:Archer C7,product_ver:4.0.0,special_id:52550000}\n"
1646                         "{product_name:Archer C7,product_ver:4.0.0,special_id:54570000}\n"
1647                         "{product_name:Archer C7,product_ver:4.0.0,special_id:55530000}\n"
1648                         "{product_name:Archer C7,product_ver:4.0.0,special_id:43410000}\n",
1649                 .part_trail = 0x00,
1650                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1651 
1652                 /* We're using a dynamic kernel/rootfs split here */
1653                 .partitions = {
1654                         {"factory-boot", 0x00000, 0x20000},
1655                         {"fs-uboot", 0x20000, 0x20000},
1656                         {"firmware", 0x40000, 0xEC0000},        /* Stock: name os-image base 0x40000 size 0x120000 */
1657                                                                 /* Stock: name file-system base 0x160000 size 0xda0000 */
1658                         {"default-mac", 0xf00000, 0x00200},
1659                         {"pin", 0xf00200, 0x00200},
1660                         {"device-id", 0xf00400, 0x00100},
1661                         {"product-info", 0xf00500, 0x0fb00},
1662                         {"soft-version", 0xf10000, 0x00100},
1663                         {"extra-para", 0xf11000, 0x01000},
1664                         {"support-list", 0xf12000, 0x0a000},
1665                         {"profile", 0xf1c000, 0x04000},
1666                         {"default-config", 0xf20000, 0x10000},
1667                         {"user-config", 0xf30000, 0x40000},
1668                         {"qos-db", 0xf70000, 0x40000},
1669                         {"certificate", 0xfb0000, 0x10000},
1670                         {"partition-table", 0xfc0000, 0x10000},
1671                         {"log", 0xfd0000, 0x20000},
1672                         {"radio", 0xff0000, 0x10000},
1673                         {NULL, 0, 0}
1674                 },
1675 
1676                 .first_sysupgrade_partition = "os-image",
1677                 .last_sysupgrade_partition = "file-system",
1678         },
1679 
1680         /** Firmware layout for the C7 v5*/
1681         {
1682                 .id     = "ARCHER-C7-V5",
1683                 .support_list =
1684                         "SupportList:\n"
1685                         "{product_name:Archer C7,product_ver:5.0.0,special_id:00000000}\n"
1686                         "{product_name:Archer C7,product_ver:5.0.0,special_id:45550000}\n"
1687                         "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n"
1688                         "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n"
1689                         "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n"
1690                         "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n"
1691                         "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n"
1692                         "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n",
1693 
1694                 .part_trail = 0x00,
1695                 .soft_ver = SOFT_VER_TEXT("soft_ver:7.0.0\n"),
1696 
1697                 /* We're using a dynamic kernel/rootfs split here */
1698                 .partitions = {
1699                         {"factory-boot",    0x00000,  0x20000},
1700                         {"fs-uboot",        0x20000,  0x20000},
1701                         {"partition-table", 0x40000,  0x10000},
1702                         {"radio",           0x50000,  0x10000},
1703                         {"default-mac",     0x60000,  0x00200},
1704                         {"pin",             0x60200,  0x00200},
1705                         {"device-id",       0x60400,  0x00100},
1706                         {"product-info",    0x60500,  0x0fb00},
1707                         {"soft-version",    0x70000,  0x01000},
1708                         {"extra-para",      0x71000,  0x01000},
1709                         {"support-list",    0x72000,  0x0a000},
1710                         {"profile",         0x7c000,  0x04000},
1711                         {"user-config",     0x80000,  0x40000},
1712 
1713 
1714                         {"firmware",        0xc0000,  0xf00000},        /* Stock: name os-image base 0xc0000  size 0x120000 */
1715                                                                         /* Stock: name file-system base 0x1e0000 size 0xde0000 */
1716 
1717                         {"log",             0xfc0000, 0x20000},
1718                         {"certificate",     0xfe0000, 0x10000},
1719                         {"default-config",  0xff0000, 0x10000},
1720                         {NULL, 0, 0}
1721 
1722                 },
1723 
1724                 .first_sysupgrade_partition = "os-image",
1725                 .last_sysupgrade_partition = "file-system",
1726         },
1727 
1728         /** Firmware layout for the C9 */
1729         {
1730                 .id     = "ARCHERC9",
1731                 .vendor = "",
1732                 .support_list =
1733                         "SupportList:\n"
1734                         "{product_name:ArcherC9,"
1735                         "product_ver:1.0.0,"
1736                         "special_id:00000000}\n",
1737                 .part_trail = 0x00,
1738                 .soft_ver = SOFT_VER_DEFAULT,
1739 
1740                 .partitions = {
1741                         {"fs-uboot", 0x00000, 0x40000},
1742                         {"os-image", 0x40000, 0x200000},
1743                         {"file-system", 0x240000, 0xc00000},
1744                         {"default-mac", 0xe40000, 0x00200},
1745                         {"pin", 0xe40200, 0x00200},
1746                         {"product-info", 0xe40400, 0x00200},
1747                         {"partition-table", 0xe50000, 0x10000},
1748                         {"soft-version", 0xe60000, 0x00200},
1749                         {"support-list", 0xe61000, 0x0f000},
1750                         {"profile", 0xe70000, 0x10000},
1751                         {"default-config", 0xe80000, 0x10000},
1752                         {"user-config", 0xe90000, 0x50000},
1753                         {"log", 0xee0000, 0x100000},
1754                         {"radio_bk", 0xfe0000, 0x10000},
1755                         {"radio", 0xff0000, 0x10000},
1756                         {NULL, 0, 0}
1757                 },
1758 
1759                 .first_sysupgrade_partition = "os-image",
1760                 .last_sysupgrade_partition = "file-system"
1761         },
1762 
1763         /** Firmware layout for the Deco M4R v1 and v2 */
1764         {
1765                 .id     = "DECO-M4R-V1",
1766                 .vendor = "",
1767                 .support_list =
1768                         "SupportList:\n"
1769                         "{product_name:M4R,product_ver:1.0.0,special_id:55530000}\n"
1770                         "{product_name:M4R,product_ver:1.0.0,special_id:45550000}\n"
1771                         "{product_name:M4R,product_ver:1.0.0,special_id:43410000}\n"
1772                         "{product_name:M4R,product_ver:1.0.0,special_id:4A500000}\n"
1773                         "{product_name:M4R,product_ver:1.0.0,special_id:41550000}\n"
1774                         "{product_name:M4R,product_ver:1.0.0,special_id:4B520000}\n"
1775                         "{product_name:M4R,product_ver:1.0.0,special_id:49440000}\n"
1776                         "{product_name:M4R,product_ver:2.0.0,special_id:55530000}\n"
1777                         "{product_name:M4R,product_ver:2.0.0,special_id:45550000}\n"
1778                         "{product_name:M4R,product_ver:2.0.0,special_id:43410000}\n"
1779                         "{product_name:M4R,product_ver:2.0.0,special_id:4A500000}\n"
1780                         "{product_name:M4R,product_ver:2.0.0,special_id:41550000}\n"
1781                         "{product_name:M4R,product_ver:2.0.0,special_id:4B520000}\n"
1782                         "{product_name:M4R,product_ver:2.0.0,special_id:54570000}\n"
1783                         "{product_name:M4R,product_ver:2.0.0,special_id:42340000}\n"
1784                         "{product_name:M4R,product_ver:2.0.0,special_id:49440000}\n",
1785                 .part_trail = 0x00,
1786                 .soft_ver = SOFT_VER_DEFAULT,
1787 
1788                 .partitions = {
1789                         {"fs-uboot", 0x00000, 0x80000},
1790                         {"firmware", 0x80000, 0xe00000},
1791                         {"product-info", 0xe80000, 0x05000},
1792                         {"default-mac", 0xe85000, 0x01000},
1793                         {"device-id", 0xe86000, 0x01000},
1794                         {"support-list", 0xe87000, 0x10000},
1795                         {"user-config", 0xea7000, 0x10000},
1796                         {"device-config", 0xeb7000, 0x10000},
1797                         {"group-info", 0xec7000, 0x10000},
1798                         {"partition-table", 0xed7000, 0x02000},
1799                         {"soft-version", 0xed9000, 0x10000},
1800                         {"profile", 0xee9000, 0x10000},
1801                         {"default-config", 0xef9000, 0x10000},
1802                         {"url-sig", 0xfe0000, 0x10000},
1803                         {"radio", 0xff0000, 0x10000},
1804                         {NULL, 0, 0}
1805                 },
1806                 .first_sysupgrade_partition = "os-image",
1807                 .last_sysupgrade_partition = "file-system",
1808         },
1809 
1810         /** Firmware layout for the Deco M4R v4 */
1811         {
1812                 .id     = "DECO-M4R-V4",
1813                 .vendor = "",
1814                 .support_list =
1815                         "SupportList:\n"
1816                         "{product_name:M4R,product_ver:4.0.0,special_id:55530000}\n"
1817                         "{product_name:M4R,product_ver:4.0.0,special_id:45550000}\n"
1818                         "{product_name:M4R,product_ver:4.0.0,special_id:4A500000}\n"
1819                         "{product_name:M4R,product_ver:4.0.0,special_id:42340000}\n"
1820                         "{product_name:M4R,product_ver:4.0.0,special_id:5A470000}\n",
1821                 .part_trail = 0x00,
1822                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
1823 
1824                 .partitions = {
1825                         {"fs-uboot", 0x00000, 0x40000},
1826                         {"firmware", 0x40000, 0xf60000},
1827                         {"default-mac", 0xfa0000, 0x00300},
1828                         {"device-id", 0xfa0300, 0x00100},
1829                         {"product-info", 0xfa0400, 0x0fc00},
1830                         {"group-info", 0xfb0000, 0x04000},
1831                         {"user-config", 0xfb4000, 0x0c000},
1832                         {"device-config", 0xfc0000, 0x10000},
1833                         {"default-config", 0xfd0000, 0x10000},
1834                         {"partition-table", 0xfe0000, 0x00800},
1835                         {"soft-version", 0xfe0800, 0x00100},
1836                         {"support-list", 0xfe0900, 0x00200},
1837                         {"profile", 0xfe0b00, 0x03000},
1838                         {"extra-para", 0xfe3b00, 0x00100},
1839                         {"radio", 0xff0000, 0x10000},
1840                         {NULL, 0, 0}
1841                 },
1842                 .first_sysupgrade_partition = "os-image",
1843                 .last_sysupgrade_partition = "file-system",
1844         },
1845 
1846         /** Firmware layout for the Deco M5 */
1847         {
1848                 .id = "DECO-M5",
1849                 .vendor = "",
1850                 .support_list =
1851                         "SupportList:\n"
1852                         "{product_name:M5,product_ver:1.0.0,special_id:55530000}\n"
1853                         "{product_name:M5,product_ver:1.0.0,special_id:45550000}\n"
1854                         "{product_name:M5,product_ver:1.0.0,special_id:43410000}\n"
1855                         "{product_name:M5,product_ver:1.0.0,special_id:4A500000}\n"
1856                         "{product_name:M5,product_ver:1.0.0,special_id:41550000}\n"
1857                         "{product_name:M5,product_ver:1.0.0,special_id:4B520000}\n"
1858                         "{product_name:M5,product_ver:1.0.0,special_id:49440000}\n"
1859                         "{product_name:M5,product_ver:3.0.0,special_id:55530000}\n"
1860                         "{product_name:M5,product_ver:3.0.0,special_id:45550000}\n"
1861                         "{product_name:M5,product_ver:3.0.0,special_id:43410000}\n"
1862                         "{product_name:M5,product_ver:3.0.0,special_id:4A500000}\n"
1863                         "{product_name:M5,product_ver:3.0.0,special_id:41550000}\n"
1864                         "{product_name:M5,product_ver:3.0.0,special_id:4B520000}\n"
1865                         "{product_name:M5,product_ver:3.0.0,special_id:49440000}\n"
1866                         "{product_name:M5,product_ver:3.0.0,special_id:53570000}\n"
1867                         "{product_name:M5,product_ver:3.0.0,special_id:42340000}\n"
1868                         "{product_name:M5,product_ver:3.0.0,special_id:54570000}\n"
1869                         "{product_name:M5,product_ver:3.2.0,special_id:55530000}\n"
1870                         "{product_name:M5,product_ver:3.2.0,special_id:45550000}\n"
1871                         "{product_name:M5,product_ver:3.2.0,special_id:43410000}\n"
1872                         "{product_name:M5,product_ver:3.2.0,special_id:4A500000}\n"
1873                         "{product_name:M5,product_ver:3.2.0,special_id:41550000}\n"
1874                         "{product_name:M5,product_ver:3.2.0,special_id:4B520000}\n"
1875                         "{product_name:M5,product_ver:3.2.0,special_id:49440000}\n"
1876                         "{product_name:M5,product_ver:3.2.0,special_id:53570000}\n"
1877                         "{product_name:M5,product_ver:3.2.0,special_id:42340000}\n"
1878                         "{product_name:M5,product_ver:3.2.0,special_id:54570000}\n",
1879                 .part_trail = 0x00,
1880                 .soft_ver = SOFT_VER_DEFAULT,
1881 
1882                 .partitions = {
1883                         {"SBL1", 0x00000, 0x30000},
1884                         {"boot-config_0", 0x30000, 0x10000},
1885                         {"MIBIB", 0x40000, 0x10000},
1886                         {"boot-config_1", 0x50000, 0x10000},
1887                         {"QSEE", 0x60000, 0x60000},
1888                         {"CDT", 0xc0000, 0x10000},
1889                         {"DDRPARAMS", 0xd0000, 0x10000},
1890                         {"uboot-env", 0xe0000, 0x10000},
1891                         {"fs-uboot@0", 0xf0000, 0x80000},
1892                         {"radio", 0x170000, 0x0fff0},
1893                         {"bluetooth-XTAL", 0x17fff0, 0x00010},
1894                         {"default-mac", 0x180000, 0x01000},
1895                         {"device-id", 0x182000, 0x01000},
1896                         {"product-info", 0x183000, 0x05000},
1897                         {"support-list", 0x190000, 0x10000},
1898                         {"user-config", 0x200000, 0x10000},
1899                         {"device-config", 0x210000, 0x10000},
1900                         {"group-info", 0x220000, 0x10000},
1901                         {"partition-table@0", 0x230000, 0x02000},
1902                         {"os-image@0", 0x240000, 0x300000},
1903                         {"file-system@0", 0x540000, 0x790000},
1904                         {"soft-version@0", 0xcd0000, 0x10000},
1905                         {"profile@0", 0xce0000, 0x10000},
1906                         {"default-config@0", 0xcf0000, 0x10000},
1907                         {"partition-table@1", 0xd00000, 0x02000},
1908                         {"fs-uboot@1", 0xd10000, 0x80000},
1909                         {"os-image@1", 0xd90000, 0x400000},
1910                         {"file-system@1", 0x1190000, 0xc40000},
1911                         {"soft-version@1", 0x1dd0000, 0x10000},
1912                         {"profile@1", 0x1de0000, 0x10000},
1913                         {"default-config@1", 0x1df0000, 0x10000},
1914                         {"tm-sig", 0x1e00000, 0x200000},
1915                         {NULL, 0, 0}
1916                 },
1917 
1918                 .partition_names.partition_table = "partition-table@1",
1919                 .partition_names.soft_ver = "soft-version@1",
1920                 .partition_names.os_image = "os-image@1",
1921                 .partition_names.file_system = "file-system@1",
1922 
1923                 .first_sysupgrade_partition = "os-image@1",
1924                 .last_sysupgrade_partition = "file-system@1"
1925         },
1926 
1927         /** Firmware layout for the Deco S4 v2 */
1928         {
1929                 .id     = "DECO-S4-V2",
1930                 .vendor = "",
1931                 .support_list =
1932                         "SupportList:\n"
1933                         "{product_name:S4,product_ver:1.0.0,special_id:55530000}\n"
1934                         "{product_name:S4,product_ver:1.0.0,special_id:45550000}\n"
1935                         "{product_name:S4,product_ver:1.0.0,special_id:43410000}\n"
1936                         "{product_name:S4,product_ver:1.0.0,special_id:4A500000}\n"
1937                         "{product_name:S4,product_ver:1.0.0,special_id:41550000}\n"
1938                         "{product_name:S4,product_ver:1.0.0,special_id:4B520000}\n"
1939                         "{product_name:S4,product_ver:2.0.0,special_id:55530000}\n"
1940                         "{product_name:S4,product_ver:2.0.0,special_id:45550000}\n"
1941                         "{product_name:S4,product_ver:2.0.0,special_id:43410000}\n"
1942                         "{product_name:S4,product_ver:2.0.0,special_id:4A500000}\n"
1943                         "{product_name:S4,product_ver:2.0.0,special_id:41550000}\n"
1944                         "{product_name:S4,product_ver:2.0.0,special_id:4B520000}\n",
1945                 .part_trail = 0x00,
1946                 .soft_ver = SOFT_VER_DEFAULT,
1947 
1948                 .partitions = {
1949                         {"fs-uboot", 0x00000, 0x80000},
1950                         {"product-info", 0x80000, 0x05000},
1951                         {"default-mac", 0x85000, 0x01000},
1952                         {"device-id", 0x86000, 0x01000},
1953                         {"support-list", 0x87000, 0x10000},
1954                         {"user-config", 0xa7000, 0x10000},
1955                         {"device-config", 0xb7000, 0x10000},
1956                         {"group-info", 0xc7000, 0x10000},
1957                         {"partition-table", 0xd7000, 0x02000},
1958                         {"soft-version", 0xd9000, 0x10000},
1959                         {"profile", 0xe9000, 0x10000},
1960                         {"default-config", 0xf9000, 0x10000},
1961                         {"url-sig", 0x1e0000, 0x10000},
1962                         {"radio", 0x1f0000, 0x10000},
1963                         {"firmware", 0x200000, 0xe00000},
1964                         {NULL, 0, 0}
1965                 },
1966                 .first_sysupgrade_partition = "os-image",
1967                 .last_sysupgrade_partition = "file-system",
1968         },
1969 
1970         /** Firmware layout for the EAP120 */
1971         {
1972                 .id     = "EAP120",
1973                 .vendor = "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1974                 .support_list =
1975                         "SupportList:\r\n"
1976                         "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
1977                 .part_trail = 0xff,
1978                 .soft_ver = SOFT_VER_DEFAULT,
1979 
1980                 .partitions = {
1981                         {"fs-uboot", 0x00000, 0x20000},
1982                         {"partition-table", 0x20000, 0x02000},
1983                         {"default-mac", 0x30000, 0x00020},
1984                         {"support-list", 0x31000, 0x00100},
1985                         {"product-info", 0x31100, 0x00100},
1986                         {"soft-version", 0x32000, 0x00100},
1987                         {"os-image", 0x40000, 0x180000},
1988                         {"file-system", 0x1c0000, 0x600000},
1989                         {"user-config", 0x7c0000, 0x10000},
1990                         {"backup-config", 0x7d0000, 0x10000},
1991                         {"log", 0x7e0000, 0x10000},
1992                         {"radio", 0x7f0000, 0x10000},
1993                         {NULL, 0, 0}
1994                 },
1995 
1996                 .first_sysupgrade_partition = "os-image",
1997                 .last_sysupgrade_partition = "file-system"
1998         },
1999 
2000         /** Firmware layout for the EAP225-Outdoor v1 */
2001         {
2002                 .id     = "EAP225-OUTDOOR-V1",
2003                 .support_list =
2004                         "SupportList:\r\n"
2005                         "EAP225-Outdoor(TP-Link|UN|AC1200-D):1.0\r\n",
2006                 .part_trail = PART_TRAIL_NONE,
2007                 .soft_ver = SOFT_VER_DEFAULT,
2008                 .soft_ver_compat_level = 2,
2009 
2010                 .partitions = {
2011                         {"fs-uboot", 0x00000, 0x20000},
2012                         {"partition-table", 0x20000, 0x02000},
2013                         {"default-mac", 0x30000, 0x01000},
2014                         {"support-list", 0x31000, 0x00100},
2015                         {"product-info", 0x31100, 0x00400},
2016                         {"soft-version", 0x32000, 0x00100},
2017                         {"firmware", 0x40000, 0xd80000},
2018                         {"user-config", 0xdc0000, 0x30000},
2019                         {"mutil-log", 0xf30000, 0x80000},
2020                         {"oops", 0xfb0000, 0x40000},
2021                         {"radio", 0xff0000, 0x10000},
2022                         {NULL, 0, 0}
2023                 },
2024 
2025                 .first_sysupgrade_partition = "os-image",
2026                 .last_sysupgrade_partition = "file-system"
2027         },
2028 
2029         /** Firmware layout for the EAP225 v1 */
2030         {
2031                 .id     = "EAP225-V1",
2032                 .support_list =
2033                         "SupportList:\r\n"
2034                         "EAP225(TP-LINK|UN|AC1200-D):1.0\r\n",
2035                 .part_trail = PART_TRAIL_NONE,
2036                 .soft_ver = SOFT_VER_DEFAULT,
2037 
2038                 .partitions = {
2039                         {"fs-uboot", 0x00000, 0x20000},
2040                         {"partition-table", 0x20000, 0x02000},
2041                         {"default-mac", 0x30000, 0x01000},
2042                         {"support-list", 0x31000, 0x00100},
2043                         {"product-info", 0x31100, 0x00400},
2044                         {"soft-version", 0x32000, 0x00100},
2045                         {"firmware", 0x40000, 0xd80000},
2046                         {"user-config", 0xdc0000, 0x30000},
2047                         {"radio", 0xff0000, 0x10000},
2048                         {NULL, 0, 0}
2049                 },
2050 
2051                 .first_sysupgrade_partition = "os-image",
2052                 .last_sysupgrade_partition = "file-system"
2053         },
2054 
2055         /** Firmware layout for the EAP225 v3
2056          * Also compatible with:
2057          *   - EAP225 v3.20
2058          *   - EAP225 v4
2059          *   - EAP225-Outdoor v1
2060          *   - EAP225-Outdoor v3
2061          *   */
2062         {
2063                 .id     = "EAP225-V3",
2064                 .support_list =
2065                         "SupportList:\r\n"
2066                         "EAP225(TP-Link|UN|AC1350-D):3.0\r\n"
2067                         "EAP225(TP-Link|UN|AC1350-D):3.20\r\n"
2068                         "EAP225(TP-Link|UN|AC1350-D):4.0 CA\r\n"
2069                         "EAP225-Outdoor(TP-Link|UN|AC1200-D):1.0\r\n"
2070                         "EAP225-Outdoor(TP-Link|UN|AC1200-D):3.0 CA,JP\r\n",
2071                 .part_trail = PART_TRAIL_NONE,
2072                 .soft_ver = SOFT_VER_DEFAULT,
2073                 .soft_ver_compat_level = 2,
2074 
2075                 .partitions = {
2076                         {"fs-uboot", 0x00000, 0x20000},
2077                         {"partition-table", 0x20000, 0x02000},
2078                         {"default-mac", 0x30000, 0x01000},
2079                         {"support-list", 0x31000, 0x00100},
2080                         {"product-info", 0x31100, 0x00400},
2081                         {"soft-version", 0x32000, 0x00100},
2082                         {"firmware", 0x40000, 0xd80000},
2083                         {"user-config", 0xdc0000, 0x30000},
2084                         {"mutil-log", 0xf30000, 0x80000},
2085                         {"oops", 0xfb0000, 0x40000},
2086                         {"radio", 0xff0000, 0x10000},
2087                         {NULL, 0, 0}
2088                 },
2089 
2090                 .first_sysupgrade_partition = "os-image",
2091                 .last_sysupgrade_partition = "file-system"
2092         },
2093 
2094         /** Firmware layout for the EAP225-Wall v2 */
2095         {
2096                 .id     = "EAP225-WALL-V2",
2097                 .support_list =
2098                         "SupportList:\r\n"
2099                         "EAP225-Wall(TP-Link|UN|AC1200-D):2.0\r\n",
2100                 .part_trail = PART_TRAIL_NONE,
2101                 .soft_ver = SOFT_VER_DEFAULT,
2102                 .soft_ver_compat_level = 1,
2103 
2104                 .partitions = {
2105                         {"fs-uboot", 0x00000, 0x20000},
2106                         {"partition-table", 0x20000, 0x02000},
2107                         {"default-mac", 0x30000, 0x01000},
2108                         {"support-list", 0x31000, 0x00100},
2109                         {"product-info", 0x31100, 0x00400},
2110                         {"soft-version", 0x32000, 0x00100},
2111                         {"firmware", 0x40000, 0xd80000},
2112                         {"user-config", 0xdc0000, 0x30000},
2113                         {"mutil-log", 0xf30000, 0x80000},
2114                         {"oops", 0xfb0000, 0x40000},
2115                         {"radio", 0xff0000, 0x10000},
2116                         {NULL, 0, 0}
2117                 },
2118 
2119                 .first_sysupgrade_partition = "os-image",
2120                 .last_sysupgrade_partition = "file-system"
2121         },
2122 
2123         /** Firmware layout for the EAP235-Wall v1 */
2124         {
2125                 .id     = "EAP235-WALL-V1",
2126                 .support_list =
2127                         "SupportList:\r\n"
2128                         "EAP235-Wall(TP-Link|UN|AC1200-D):1.0\r\n",
2129                 .part_trail = PART_TRAIL_NONE,
2130                 .soft_ver = SOFT_VER_NUMERIC(3, 0, 0),
2131                 .soft_ver_compat_level = 1,
2132 
2133                 .partitions = {
2134                         {"fs-uboot", 0x00000, 0x80000},
2135                         {"partition-table", 0x80000, 0x02000},
2136                         {"default-mac", 0x90000, 0x01000},
2137                         {"support-list", 0x91000, 0x00100},
2138                         {"product-info", 0x91100, 0x00400},
2139                         {"soft-version", 0x92000, 0x00100},
2140                         {"firmware", 0xa0000, 0xd20000},
2141                         {"user-config", 0xdc0000, 0x30000},
2142                         {"mutil-log", 0xf30000, 0x80000},
2143                         {"oops", 0xfb0000, 0x40000},
2144                         {"radio", 0xff0000, 0x10000},
2145                         {NULL, 0, 0}
2146                 },
2147 
2148                 .first_sysupgrade_partition = "os-image",
2149                 .last_sysupgrade_partition = "file-system"
2150         },
2151 
2152         /** Firmware layout for the EAP245 v1 */
2153         {
2154                 .id     = "EAP245-V1",
2155                 .support_list =
2156                         "SupportList:\r\n"
2157                         "EAP245(TP-LINK|UN|AC1750-D):1.0\r\n",
2158                 .part_trail = PART_TRAIL_NONE,
2159                 .soft_ver = SOFT_VER_DEFAULT,
2160 
2161                 .partitions = {
2162                         {"fs-uboot", 0x00000, 0x20000},
2163                         {"partition-table", 0x20000, 0x02000},
2164                         {"default-mac", 0x30000, 0x01000},
2165                         {"support-list", 0x31000, 0x00100},
2166                         {"product-info", 0x31100, 0x00400},
2167                         {"soft-version", 0x32000, 0x00100},
2168                         {"firmware", 0x40000, 0xd80000},
2169                         {"user-config", 0xdc0000, 0x30000},
2170                         {"radio", 0xff0000, 0x10000},
2171                         {NULL, 0, 0}
2172                 },
2173 
2174                 .first_sysupgrade_partition = "os-image",
2175                 .last_sysupgrade_partition = "file-system"
2176         },
2177 
2178         /** Firmware layout for the EAP245 v3 */
2179         {
2180                 .id     = "EAP245-V3",
2181                 .support_list =
2182                         "SupportList:\r\n"
2183                         "EAP245(TP-Link|UN|AC1750-D):3.0\r\n"
2184                         "EAP265 HD(TP-Link|UN|AC1750-D):1.0",
2185                 .part_trail = PART_TRAIL_NONE,
2186                 .soft_ver = SOFT_VER_DEFAULT,
2187                 .soft_ver_compat_level = 1,
2188 
2189                 /** Firmware partition with dynamic kernel/rootfs split */
2190                 .partitions = {
2191                         {"factroy-boot", 0x00000, 0x40000},
2192                         {"fs-uboot", 0x40000, 0x40000},
2193                         {"partition-table", 0x80000, 0x10000},
2194                         {"default-mac", 0x90000, 0x01000},
2195                         {"support-list", 0x91000, 0x00100},
2196                         {"product-info", 0x91100, 0x00400},
2197                         {"soft-version", 0x92000, 0x00100},
2198                         {"radio", 0xa0000, 0x10000},
2199                         {"extra-para", 0xb0000, 0x10000},
2200                         {"firmware", 0xc0000, 0xe40000},
2201                         {"config", 0xf00000, 0x30000},
2202                         {"mutil-log", 0xf30000, 0x80000},
2203                         {"oops", 0xfb0000, 0x40000},
2204                         {NULL, 0, 0}
2205                 },
2206 
2207                 .first_sysupgrade_partition = "os-image",
2208                 .last_sysupgrade_partition = "file-system"
2209         },
2210 
2211         /** Firmware layout for the EAP610 v3/EAP613 v1 */
2212         {
2213                 .id = "EAP610-V3",
2214                 .soft_ver = SOFT_VER_DEFAULT,
2215                 .soft_ver_compat_level = 2,
2216                 .support_list =
2217                         "SupportList:\r\n"
2218                         "EAP610(TP-Link|UN|AX1800-D):3.0\r\n"
2219                         "EAP610(TP-Link|JP|AX1800-D):3.0\r\n"
2220                         "EAP610(TP-Link|EG|AX1800-D):3.0\r\n"
2221                         "EAP610(TP-Link|CA|AX1800-D):3.0\r\n"
2222                         "EAP613(TP-Link|UN|AX1800-D):1.0 JP\r\n",
2223                 .part_trail = PART_TRAIL_NONE,
2224 
2225                 .partitions = {
2226                         {"fs-uboot", 0x00000, 0x80000},
2227                         {"partition-table", 0x80000, 0x02000},
2228                         {"default-mac", 0x90000, 0x01000},
2229                         {"support-list", 0x91000, 0x00100},
2230                         {"product-info", 0x91100, 0x00400},
2231                         {"soft-version", 0x92000, 0x00100},
2232                         {"firmware", 0xa0000, 0xcf0000},
2233                         {"user-config", 0xd90000, 0x60000},
2234                         {"mutil-log", 0xf30000, 0x80000},
2235                         {"oops", 0xfb0000, 0x40000},
2236                         {"radio", 0xff0000, 0x10000},
2237                         {NULL, 0, 0}
2238                 },
2239 
2240                 .first_sysupgrade_partition = "os-image",
2241                 .last_sysupgrade_partition = "file-system"
2242         },
2243 
2244         /** Firmware layout for the EAP615-Wall v1 */
2245         {
2246                 .id = "EAP615-WALL-V1",
2247                 .soft_ver = SOFT_VER_DEFAULT,
2248                 .soft_ver_compat_level = 2,
2249                 .support_list =
2250                         "SupportList:\r\n"
2251                         "EAP615-Wall(TP-Link|UN|AX1800-D):1.0\r\n"
2252                         "EAP615-Wall(TP-Link|CA|AX1800-D):1.0\r\n"
2253                         "EAP615-Wall(TP-Link|JP|AX1800-D):1.0\r\n",
2254                 .part_trail = PART_TRAIL_NONE,
2255 
2256                 .partitions = {
2257                         {"fs-uboot", 0x00000, 0x80000},
2258                         {"partition-table", 0x80000, 0x02000},
2259                         {"default-mac", 0x90000, 0x01000},
2260                         {"support-list", 0x91000, 0x00100},
2261                         {"product-info", 0x91100, 0x00400},
2262                         {"soft-version", 0x92000, 0x00100},
2263                         {"firmware", 0xa0000, 0xcf0000},
2264                         {"user-config", 0xd90000, 0x60000},
2265                         {"mutil-log", 0xf30000, 0x80000},
2266                         {"oops", 0xfb0000, 0x40000},
2267                         {"radio", 0xff0000, 0x10000},
2268                         {NULL, 0, 0}
2269                 },
2270 
2271                 .first_sysupgrade_partition = "os-image",
2272                 .last_sysupgrade_partition = "file-system"
2273         },
2274 
2275         /** Firmware layout for the TL-WA1201 v2 */
2276         {
2277                 .id     = "TL-WA1201-V2",
2278                 .vendor = "",
2279                 .support_list =
2280                         "SupportList:\n"
2281                         "{product_name:TL-WA1201,product_ver:2.0.0,special_id:45550000}\n"
2282                         "{product_name:TL-WA1201,product_ver:2.0.0,special_id:55530000}\n",
2283                 .part_trail = 0x00,
2284                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.1 Build 20200709 rel.66244\n"),
2285 
2286                 .partitions = {
2287                         {"fs-uboot", 0x00000, 0x20000},
2288                         {"default-mac", 0x20000, 0x00200},
2289                         {"pin", 0x20200, 0x00100},
2290                         {"product-info", 0x20300, 0x00200},
2291                         {"device-id", 0x20500, 0x0fb00},
2292                         {"firmware", 0x30000, 0xce0000},
2293                         {"portal-logo", 0xd10000, 0x20000},
2294                         {"portal-back", 0xd30000, 0x200000},
2295                         {"soft-version", 0xf30000, 0x00200},
2296                         {"extra-para", 0xf30200, 0x00200},
2297                         {"support-list", 0xf30400, 0x00200},
2298                         {"profile", 0xf30600, 0x0fa00},
2299                         {"apdef-config", 0xf40000, 0x10000},
2300                         {"ap-config", 0xf50000, 0x10000},
2301                         {"redef-config", 0xf60000, 0x10000},
2302                         {"re-config", 0xf70000, 0x10000},
2303                         {"multidef-config", 0xf80000, 0x10000},
2304                         {"multi-config", 0xf90000, 0x10000},
2305                         {"clientdef-config", 0xfa0000, 0x10000},
2306                         {"client-config", 0xfb0000, 0x10000},
2307                         {"partition-table", 0xfc0000, 0x10000},
2308                         {"user-config", 0xfd0000, 0x10000},
2309                         {"certificate", 0xfe0000, 0x10000},
2310                         {"radio", 0xff0000, 0x10000},
2311                         {NULL, 0, 0}
2312                 },
2313                 .first_sysupgrade_partition = "os-image",
2314                 .last_sysupgrade_partition = "file-system",
2315         },
2316 
2317         /** Firmware layout for the TL-WA850RE v2 */
2318         {
2319                 .id     = "TLWA850REV2",
2320                 .vendor = "",
2321                 .support_list =
2322                         "SupportList:\n"
2323                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55530000}\n"
2324                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:00000000}\n"
2325                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:55534100}\n"
2326                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:45550000}\n"
2327                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4B520000}\n"
2328                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:42520000}\n"
2329                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:4A500000}\n"
2330                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:43410000}\n"
2331                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:41550000}\n"
2332                         "{product_name:TL-WA850RE,product_ver:2.0.0,special_id:52550000}\n",
2333                 .part_trail = 0x00,
2334                 .soft_ver = SOFT_VER_DEFAULT,
2335 
2336                 /**
2337                    576KB were moved from file-system to os-image
2338                    in comparison to the stock image
2339                 */
2340                 .partitions = {
2341                         {"fs-uboot", 0x00000, 0x20000},
2342                         {"firmware", 0x20000, 0x390000},
2343                         {"partition-table", 0x3b0000, 0x02000},
2344                         {"default-mac", 0x3c0000, 0x00020},
2345                         {"pin", 0x3c0100, 0x00020},
2346                         {"product-info", 0x3c1000, 0x01000},
2347                         {"soft-version", 0x3c2000, 0x00100},
2348                         {"support-list", 0x3c3000, 0x01000},
2349                         {"profile", 0x3c4000, 0x08000},
2350                         {"user-config", 0x3d0000, 0x10000},
2351                         {"default-config", 0x3e0000, 0x10000},
2352                         {"radio", 0x3f0000, 0x10000},
2353                         {NULL, 0, 0}
2354                 },
2355 
2356                 .first_sysupgrade_partition = "os-image",
2357                 .last_sysupgrade_partition = "file-system"
2358         },
2359 
2360         /** Firmware layout for the TL-WA855RE v1 */
2361         {
2362                 .id     = "TLWA855REV1",
2363                 .vendor = "",
2364                 .support_list =
2365                         "SupportList:\n"
2366                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:00000000}\n"
2367                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:55530000}\n"
2368                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:45550000}\n"
2369                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4B520000}\n"
2370                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:42520000}\n"
2371                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:4A500000}\n"
2372                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:43410000}\n"
2373                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:41550000}\n"
2374                         "{product_name:TL-WA855RE,product_ver:1.0.0,special_id:52550000}\n",
2375                 .part_trail = 0x00,
2376                 .soft_ver = SOFT_VER_DEFAULT,
2377 
2378                 .partitions = {
2379                         {"fs-uboot", 0x00000, 0x20000},
2380                         {"os-image", 0x20000, 0x150000},
2381                         {"file-system", 0x170000, 0x240000},
2382                         {"partition-table", 0x3b0000, 0x02000},
2383                         {"default-mac", 0x3c0000, 0x00020},
2384                         {"pin", 0x3c0100, 0x00020},
2385                         {"product-info", 0x3c1000, 0x01000},
2386                         {"soft-version", 0x3c2000, 0x00100},
2387                         {"support-list", 0x3c3000, 0x01000},
2388                         {"profile", 0x3c4000, 0x08000},
2389                         {"user-config", 0x3d0000, 0x10000},
2390                         {"default-config", 0x3e0000, 0x10000},
2391                         {"radio", 0x3f0000, 0x10000},
2392                         {NULL, 0, 0}
2393                 },
2394 
2395                 .first_sysupgrade_partition = "os-image",
2396                 .last_sysupgrade_partition = "file-system"
2397         },
2398 
2399         /** Firmware layout for the TL-WPA8630P v2 (EU)*/
2400         {
2401                 .id     = "TL-WPA8630P-V2.0-EU",
2402                 .vendor = "",
2403                 .support_list =
2404                         "SupportList:\n"
2405                         "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:45550000}\n",
2406                 .part_trail = 0x00,
2407                 .soft_ver = SOFT_VER_DEFAULT,
2408 
2409                 .partitions = {
2410                         {"factory-uboot", 0x00000, 0x20000},
2411                         {"fs-uboot", 0x20000, 0x20000},
2412                         {"firmware", 0x40000, 0x5e0000},
2413                         {"partition-table", 0x620000, 0x02000},
2414                         {"default-mac", 0x630000, 0x00020},
2415                         {"pin", 0x630100, 0x00020},
2416                         {"device-id", 0x630200, 0x00030},
2417                         {"product-info", 0x631100, 0x01000},
2418                         {"extra-para", 0x632100, 0x01000},
2419                         {"soft-version", 0x640000, 0x01000},
2420                         {"support-list", 0x641000, 0x01000},
2421                         {"profile", 0x642000, 0x08000},
2422                         {"user-config", 0x650000, 0x10000},
2423                         {"default-config", 0x660000, 0x10000},
2424                         {"default-nvm", 0x670000, 0xc0000},
2425                         {"default-pib", 0x730000, 0x40000},
2426                         {"radio", 0x7f0000, 0x10000},
2427                         {NULL, 0, 0}
2428                 },
2429 
2430                 .first_sysupgrade_partition = "os-image",
2431                 .last_sysupgrade_partition = "file-system"
2432         },
2433 
2434         /** Firmware layout for the TL-WPA8630P v2 (INT)*/
2435         {
2436                 .id     = "TL-WPA8630P-V2-INT",
2437                 .vendor = "",
2438                 .support_list =
2439                         "SupportList:\n"
2440                         "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:41550000}\n"
2441                         "{product_name:TL-WPA8630P,product_ver:2.0.0,special_id:44450000}\n"
2442                         "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n",
2443                 .part_trail = 0x00,
2444                 .soft_ver = SOFT_VER_DEFAULT,
2445 
2446                 .partitions = {
2447                         {"factory-uboot", 0x00000, 0x20000},
2448                         {"fs-uboot", 0x20000, 0x20000},
2449                         {"firmware", 0x40000, 0x5e0000},
2450                         {"partition-table", 0x620000, 0x02000},
2451                         {"extra-para", 0x632100, 0x01000},
2452                         {"soft-version", 0x640000, 0x01000},
2453                         {"support-list", 0x641000, 0x01000},
2454                         {"profile", 0x642000, 0x08000},
2455                         {"user-config", 0x650000, 0x10000},
2456                         {"default-config", 0x660000, 0x10000},
2457                         {"default-nvm", 0x670000, 0xc0000},
2458                         {"default-pib", 0x730000, 0x40000},
2459                         {"default-mac", 0x7e0000, 0x00020},
2460                         {"pin", 0x7e0100, 0x00020},
2461                         {"device-id", 0x7e0200, 0x00030},
2462                         {"product-info", 0x7e1100, 0x01000},
2463                         {"radio", 0x7f0000, 0x10000},
2464                         {NULL, 0, 0}
2465                 },
2466 
2467                 .first_sysupgrade_partition = "os-image",
2468                 .last_sysupgrade_partition = "file-system"
2469         },
2470 
2471         /** Firmware layout for the TL-WPA8630P v2.1 (EU)*/
2472         {
2473                 .id     = "TL-WPA8630P-V2.1-EU",
2474                 .vendor = "",
2475                 .support_list =
2476                         "SupportList:\n"
2477                         "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n",
2478                 .part_trail = 0x00,
2479                 .soft_ver = SOFT_VER_DEFAULT,
2480 
2481                 .partitions = {
2482                         {"factory-uboot", 0x00000, 0x20000},
2483                         {"fs-uboot", 0x20000, 0x20000},
2484                         {"firmware", 0x40000, 0x5e0000},
2485                         {"extra-para", 0x680000, 0x01000},
2486                         {"product-info", 0x690000, 0x01000},
2487                         {"partition-table", 0x6a0000, 0x02000},
2488                         {"soft-version", 0x6b0000, 0x01000},
2489                         {"support-list", 0x6b1000, 0x01000},
2490                         {"profile", 0x6b2000, 0x08000},
2491                         {"user-config", 0x6c0000, 0x10000},
2492                         {"default-config", 0x6d0000, 0x10000},
2493                         {"default-nvm", 0x6e0000, 0xc0000},
2494                         {"default-pib", 0x7a0000, 0x40000},
2495                         {"default-mac", 0x7e0000, 0x00020},
2496                         {"pin", 0x7e0100, 0x00020},
2497                         {"device-id", 0x7e0200, 0x00030},
2498                         {"radio", 0x7f0000, 0x10000},
2499                         {NULL, 0, 0}
2500                 },
2501 
2502                 .first_sysupgrade_partition = "os-image",
2503                 .last_sysupgrade_partition = "file-system"
2504         },
2505 
2506         /** Firmware layout for the TL-WPA8631P v3 */
2507         {
2508                 .id     = "TL-WPA8631P-V3",
2509                 .vendor = "",
2510                 .support_list =
2511                         "SupportList:\n"
2512                         "{product_name:TL-WPA8631P,product_ver:3.0.0,special_id:41550000}\n"
2513                         "{product_name:TL-WPA8631P,product_ver:3.0.0,special_id:45550000}\n"
2514                         "{product_name:TL-WPA8631P,product_ver:3.0.0,special_id:55530000}\n"
2515                         "{product_name:TL-WPA8631P,product_ver:4.0.0,special_id:41550000}\n"
2516                         "{product_name:TL-WPA8631P,product_ver:4.0.0,special_id:45550000}\n"
2517                         "{product_name:TL-WPA8631P,product_ver:4.0.0,special_id:55530000}\n"
2518                         "{product_name:TL-WPA8635P,product_ver:3.0.0,special_id:46520000}\n",
2519                 .part_trail = 0x00,
2520                 .soft_ver = SOFT_VER_DEFAULT,
2521 
2522                 .partitions = {
2523                         {"fs-uboot", 0x00000, 0x20000},
2524                         {"firmware", 0x20000, 0x710000},
2525                         {"partition-table", 0x730000, 0x02000},
2526                         {"default-mac", 0x732000, 0x00020},
2527                         {"pin", 0x732100, 0x00020},
2528                         {"device-id", 0x732200, 0x00030},
2529                         {"default-region", 0x732300, 0x00010},
2530                         {"product-info", 0x732400, 0x00200},
2531                         {"extra-para", 0x732600, 0x00200},
2532                         {"soft-version", 0x732800, 0x00100},
2533                         {"support-list", 0x732900, 0x00200},
2534                         {"profile", 0x732b00, 0x00100},
2535                         {"default-config", 0x732c00, 0x00800},
2536                         {"plc-type", 0x733400, 0x00020},
2537                         {"default-pib", 0x733500, 0x06000},
2538                         {"user-config", 0x740000, 0x10000},
2539                         {"plc-pib", 0x750000, 0x10000},
2540                         {"plc-nvm", 0x760000, 0x90000},
2541                         {"radio", 0x7f0000, 0x10000},
2542                         {NULL, 0, 0}
2543                 },
2544 
2545                 .first_sysupgrade_partition = "os-image",
2546                 .last_sysupgrade_partition = "file-system"
2547         },
2548 
2549         /** Firmware layout for the TL-WR1043 v5 */
2550         {
2551                 .id     = "TLWR1043NV5",
2552                 .vendor = "",
2553                 .support_list =
2554                         "SupportList:\n"
2555                         "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:45550000}\n"
2556                         "{product_name:TL-WR1043N,product_ver:5.0.0,special_id:55530000}\n",
2557                 .part_trail = 0x00,
2558                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.0.0\n"),
2559                 .partitions = {
2560                         {"factory-boot", 0x00000, 0x20000},
2561                         {"fs-uboot", 0x20000, 0x20000},
2562                         {"firmware", 0x40000, 0xec0000},
2563                         {"default-mac", 0xf00000, 0x00200},
2564                         {"pin", 0xf00200, 0x00200},
2565                         {"device-id", 0xf00400, 0x00100},
2566                         {"product-info", 0xf00500, 0x0fb00},
2567                         {"soft-version", 0xf10000, 0x01000},
2568                         {"extra-para", 0xf11000, 0x01000},
2569                         {"support-list", 0xf12000, 0x0a000},
2570                         {"profile", 0xf1c000, 0x04000},
2571                         {"default-config", 0xf20000, 0x10000},
2572                         {"user-config", 0xf30000, 0x40000},
2573                         {"qos-db", 0xf70000, 0x40000},
2574                         {"certificate", 0xfb0000, 0x10000},
2575                         {"partition-table", 0xfc0000, 0x10000},
2576                         {"log", 0xfd0000, 0x20000},
2577                         {"radio", 0xff0000, 0x10000},
2578                         {NULL, 0, 0}
2579                 },
2580                 .first_sysupgrade_partition = "os-image",
2581                 .last_sysupgrade_partition = "file-system"
2582         },
2583 
2584         /** Firmware layout for the TL-WR1043 v4 */
2585         {
2586                 .id     = "TLWR1043NDV4",
2587                 .vendor = "",
2588                 .support_list =
2589                         "SupportList:\n"
2590                         "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
2591                 .part_trail = 0x00,
2592                 .soft_ver = SOFT_VER_DEFAULT,
2593 
2594                 /* We're using a dynamic kernel/rootfs split here */
2595                 .partitions = {
2596                         {"fs-uboot", 0x00000, 0x20000},
2597                         {"firmware", 0x20000, 0xf30000},
2598                         {"default-mac", 0xf50000, 0x00200},
2599                         {"pin", 0xf50200, 0x00200},
2600                         {"product-info", 0xf50400, 0x0fc00},
2601                         {"soft-version", 0xf60000, 0x0b000},
2602                         {"support-list", 0xf6b000, 0x04000},
2603                         {"profile", 0xf70000, 0x04000},
2604                         {"default-config", 0xf74000, 0x0b000},
2605                         {"user-config", 0xf80000, 0x40000},
2606                         {"partition-table", 0xfc0000, 0x10000},
2607                         {"log", 0xfd0000, 0x20000},
2608                         {"radio", 0xff0000, 0x10000},
2609                         {NULL, 0, 0}
2610                 },
2611 
2612                 .first_sysupgrade_partition = "os-image",
2613                 .last_sysupgrade_partition = "file-system"
2614         },
2615 
2616         /** Firmware layout for the TL-WR902AC v1 */
2617         {
2618                 .id     = "TL-WR902AC-V1",
2619                 .vendor = "",
2620                 .support_list =
2621                         "SupportList:\n"
2622                         "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:45550000}\n"
2623                         "{product_name:TL-WR902AC,product_ver:1.0.0,special_id:55530000}\n",
2624                 .part_trail = 0x00,
2625                 .soft_ver = SOFT_VER_DEFAULT,
2626 
2627                 /**
2628                    384KB were moved from file-system to os-image
2629                    in comparison to the stock image
2630                 */
2631                 .partitions = {
2632                         {"fs-uboot", 0x00000, 0x20000},
2633                         {"firmware", 0x20000, 0x730000},
2634                         {"default-mac", 0x750000, 0x00200},
2635                         {"pin", 0x750200, 0x00200},
2636                         {"product-info", 0x750400, 0x0fc00},
2637                         {"soft-version", 0x760000, 0x0b000},
2638                         {"support-list", 0x76b000, 0x04000},
2639                         {"profile", 0x770000, 0x04000},
2640                         {"default-config", 0x774000, 0x0b000},
2641                         {"user-config", 0x780000, 0x40000},
2642                         {"partition-table", 0x7c0000, 0x10000},
2643                         {"log", 0x7d0000, 0x20000},
2644                         {"radio", 0x7f0000, 0x10000},
2645                         {NULL, 0, 0}
2646                 },
2647 
2648                 .first_sysupgrade_partition = "os-image",
2649                 .last_sysupgrade_partition = "file-system",
2650         },
2651 
2652         /** Firmware layout for the TL-WR941HP v1 */
2653         {
2654                 .id     = "TL-WR941HP-V1",
2655                 .vendor = "",
2656                 .support_list =
2657                         "SupportList:\n"
2658                         "{product_name:TL-WR941HP,product_ver:1.0.0,special_id:00000000}\n",
2659                 .part_trail = 0x00,
2660                 .soft_ver = SOFT_VER_DEFAULT,
2661 
2662                 .partitions = {
2663                         {"fs-uboot", 0x00000, 0x20000},
2664                         {"firmware", 0x20000, 0x730000},
2665                         {"default-mac", 0x750000, 0x00200},
2666                         {"pin", 0x750200, 0x00200},
2667                         {"product-info", 0x750400, 0x0fc00},
2668                         {"soft-version", 0x760000, 0x0b000},
2669                         {"support-list", 0x76b000, 0x04000},
2670                         {"profile", 0x770000, 0x04000},
2671                         {"default-config", 0x774000, 0x0b000},
2672                         {"user-config", 0x780000, 0x40000},
2673                         {"partition-table", 0x7c0000, 0x10000},
2674                         {"log", 0x7d0000, 0x20000},
2675                         {"radio", 0x7f0000, 0x10000},
2676                         {NULL, 0, 0}
2677                 },
2678 
2679                 .first_sysupgrade_partition = "os-image",
2680                 .last_sysupgrade_partition = "file-system",
2681         },
2682 
2683         /** Firmware layout for the TL-WR942N V1 */
2684         {
2685                 .id     = "TLWR942NV1",
2686                 .vendor = "",
2687                 .support_list =
2688                         "SupportList:\r\n"
2689                         "{product_name:TL-WR942N,product_ver:1.0.0,special_id:00000000}\r\n"
2690                         "{product_name:TL-WR942N,product_ver:1.0.0,special_id:52550000}\r\n",
2691                 .part_trail = 0x00,
2692                 .soft_ver = SOFT_VER_DEFAULT,
2693 
2694                 .partitions = {
2695                         {"fs-uboot", 0x00000, 0x20000},
2696                         {"firmware", 0x20000, 0xe20000},
2697                         {"default-mac", 0xe40000, 0x00200},
2698                         {"pin", 0xe40200, 0x00200},
2699                         {"product-info", 0xe40400, 0x0fc00},
2700                         {"partition-table", 0xe50000, 0x10000},
2701                         {"soft-version", 0xe60000, 0x10000},
2702                         {"support-list", 0xe70000, 0x10000},
2703                         {"profile", 0xe80000, 0x10000},
2704                         {"default-config", 0xe90000, 0x10000},
2705                         {"user-config", 0xea0000, 0x40000},
2706                         {"qos-db", 0xee0000, 0x40000},
2707                         {"certificate", 0xf20000, 0x10000},
2708                         {"usb-config", 0xfb0000, 0x10000},
2709                         {"log", 0xfc0000, 0x20000},
2710                         {"radio-bk", 0xfe0000, 0x10000},
2711                         {"radio", 0xff0000, 0x10000},
2712                         {NULL, 0, 0}
2713                 },
2714 
2715                 .first_sysupgrade_partition = "os-image",
2716                 .last_sysupgrade_partition = "file-system",
2717         },
2718 
2719   /** Firmware layout for the RE200 v2 */
2720         {
2721                 .id     = "RE200-V2",
2722                 .vendor = "",
2723                 .support_list =
2724                         "SupportList:\n"
2725                         "{product_name:RE200,product_ver:2.0.0,special_id:00000000}\n"
2726                         "{product_name:RE200,product_ver:2.0.0,special_id:41520000}\n"
2727                         "{product_name:RE200,product_ver:2.0.0,special_id:41550000}\n"
2728                         "{product_name:RE200,product_ver:2.0.0,special_id:42520000}\n"
2729                         "{product_name:RE200,product_ver:2.0.0,special_id:43410000}\n"
2730                         "{product_name:RE200,product_ver:2.0.0,special_id:45530000}\n"
2731                         "{product_name:RE200,product_ver:2.0.0,special_id:45550000}\n"
2732                         "{product_name:RE200,product_ver:2.0.0,special_id:49440000}\n"
2733                         "{product_name:RE200,product_ver:2.0.0,special_id:4a500000}\n"
2734                         "{product_name:RE200,product_ver:2.0.0,special_id:4b520000}\n"
2735                         "{product_name:RE200,product_ver:2.0.0,special_id:52550000}\n"
2736                         "{product_name:RE200,product_ver:2.0.0,special_id:54570000}\n"
2737                         "{product_name:RE200,product_ver:2.0.0,special_id:55530000}\n",
2738                 .part_trail = 0x00,
2739                 .soft_ver = SOFT_VER_DEFAULT,
2740 
2741                 .partitions = {
2742                         {"fs-uboot", 0x00000, 0x20000},
2743                         {"firmware", 0x20000, 0x7a0000},
2744                         {"partition-table", 0x7c0000, 0x02000},
2745                         {"default-mac", 0x7c2000, 0x00020},
2746                         {"pin", 0x7c2100, 0x00020},
2747                         {"product-info", 0x7c3100, 0x01000},
2748                         {"soft-version", 0x7c4200, 0x01000},
2749                         {"support-list", 0x7c5200, 0x01000},
2750                         {"profile", 0x7c6200, 0x08000},
2751                         {"config-info", 0x7ce200, 0x00400},
2752                         {"user-config", 0x7d0000, 0x10000},
2753                         {"default-config", 0x7e0000, 0x10000},
2754                         {"radio", 0x7f0000, 0x10000},
2755                         {NULL, 0, 0}
2756                 },
2757 
2758                 .first_sysupgrade_partition = "os-image",
2759                 .last_sysupgrade_partition = "file-system"
2760         },
2761 
2762   /** Firmware layout for the RE200 v3 */
2763         {
2764                 .id     = "RE200-V3",
2765                 .vendor = "",
2766                 .support_list =
2767                         "SupportList:\n"
2768                         "{product_name:RE200,product_ver:3.0.0,special_id:00000000}\n"
2769                         "{product_name:RE200,product_ver:3.0.0,special_id:41520000}\n"
2770                         "{product_name:RE200,product_ver:3.0.0,special_id:41550000}\n"
2771                         "{product_name:RE200,product_ver:3.0.0,special_id:42520000}\n"
2772                         "{product_name:RE200,product_ver:3.0.0,special_id:43410000}\n"
2773                         "{product_name:RE200,product_ver:3.0.0,special_id:45470000}\n"
2774                         "{product_name:RE200,product_ver:3.0.0,special_id:45530000}\n"
2775                         "{product_name:RE200,product_ver:3.0.0,special_id:45550000}\n"
2776                         "{product_name:RE200,product_ver:3.0.0,special_id:49440000}\n"
2777                         "{product_name:RE200,product_ver:3.0.0,special_id:4A500000}\n"
2778                         "{product_name:RE200,product_ver:3.0.0,special_id:4B520000}\n"
2779                         "{product_name:RE200,product_ver:3.0.0,special_id:52550000}\n"
2780                         "{product_name:RE200,product_ver:3.0.0,special_id:54570000}\n"
2781                         "{product_name:RE200,product_ver:3.0.0,special_id:55530000}\n",
2782                 .part_trail = 0x00,
2783                 .soft_ver = SOFT_VER_DEFAULT,
2784 
2785                 .partitions = {
2786                         {"fs-uboot", 0x00000, 0x20000},
2787                         {"firmware", 0x20000, 0x7a0000},
2788                         {"partition-table", 0x7c0000, 0x02000},
2789                         {"default-mac", 0x7c2000, 0x00020},
2790                         {"pin", 0x7c2100, 0x00020},
2791                         {"product-info", 0x7c3100, 0x01000},
2792                         {"soft-version", 0x7c4200, 0x01000},
2793                         {"support-list", 0x7c5200, 0x01000},
2794                         {"profile", 0x7c6200, 0x08000},
2795                         {"config-info", 0x7ce200, 0x00400},
2796                         {"user-config", 0x7d0000, 0x10000},
2797                         {"default-config", 0x7e0000, 0x10000},
2798                         {"radio", 0x7f0000, 0x10000},
2799                         {NULL, 0, 0}
2800                 },
2801 
2802                 .first_sysupgrade_partition = "os-image",
2803                 .last_sysupgrade_partition = "file-system"
2804         },
2805 
2806   /** Firmware layout for the RE200 v4 */
2807         {
2808                 .id     = "RE200-V4",
2809                 .vendor = "",
2810                 .support_list =
2811                         "SupportList:\n"
2812                         "{product_name:RE200,product_ver:4.0.0,special_id:00000000}\n"
2813                         "{product_name:RE200,product_ver:4.0.0,special_id:45550000}\n"
2814                         "{product_name:RE200,product_ver:4.0.0,special_id:4A500000}\n"
2815                         "{product_name:RE200,product_ver:4.0.0,special_id:4B520000}\n"
2816                         "{product_name:RE200,product_ver:4.0.0,special_id:43410000}\n"
2817                         "{product_name:RE200,product_ver:4.0.0,special_id:41550000}\n"
2818                         "{product_name:RE200,product_ver:4.0.0,special_id:42520000}\n"
2819                         "{product_name:RE200,product_ver:4.0.0,special_id:55530000}\n"
2820                         "{product_name:RE200,product_ver:4.0.0,special_id:41520000}\n"
2821                         "{product_name:RE200,product_ver:4.0.0,special_id:52550000}\n"
2822                         "{product_name:RE200,product_ver:4.0.0,special_id:54570000}\n"
2823                         "{product_name:RE200,product_ver:4.0.0,special_id:45530000}\n"
2824                         "{product_name:RE200,product_ver:4.0.0,special_id:49440000}\n"
2825                         "{product_name:RE200,product_ver:4.0.0,special_id:45470000}\n",
2826                 .part_trail = 0x00,
2827                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.1.0\n"),
2828 
2829                 .partitions = {
2830                         {"fs-uboot", 0x00000, 0x20000},
2831                         {"firmware", 0x20000, 0x7a0000},
2832                         {"partition-table", 0x7c0000, 0x02000},
2833                         {"default-mac", 0x7c2000, 0x00020},
2834                         {"pin", 0x7c2100, 0x00020},
2835                         {"product-info", 0x7c3100, 0x01000},
2836                         {"soft-version", 0x7c4200, 0x01000},
2837                         {"support-list", 0x7c5200, 0x01000},
2838                         {"profile", 0x7c6200, 0x08000},
2839                         {"config-info", 0x7ce200, 0x00400},
2840                         {"user-config", 0x7d0000, 0x10000},
2841                         {"default-config", 0x7e0000, 0x10000},
2842                         {"radio", 0x7f0000, 0x10000},
2843                         {NULL, 0, 0}
2844                 },
2845 
2846                 .first_sysupgrade_partition = "os-image",
2847                 .last_sysupgrade_partition = "file-system"
2848         },
2849 
2850         /** Firmware layout for the RE205 v3 */
2851         {
2852                 .id     = "RE205-V3",
2853                 .vendor = "",
2854                 .support_list =
2855                         "SupportList:\n"
2856                         "{product_name:RE205,product_ver:3.0.0,special_id:00000000}\n"
2857                         "{product_name:RE205,product_ver:3.0.0,special_id:45550000}\n"
2858                         "{product_name:RE205,product_ver:3.0.0,special_id:4A500000}\n"
2859                         "{product_name:RE205,product_ver:3.0.0,special_id:4B520000}\n"
2860                         "{product_name:RE205,product_ver:3.0.0,special_id:43410000}\n"
2861                         "{product_name:RE205,product_ver:3.0.0,special_id:41550000}\n"
2862                         "{product_name:RE205,product_ver:3.0.0,special_id:42520000}\n"
2863                         "{product_name:RE205,product_ver:3.0.0,special_id:55530000}\n"
2864                         "{product_name:RE205,product_ver:3.0.0,special_id:41520000}\n"
2865                         "{product_name:RE205,product_ver:3.0.0,special_id:52550000}\n"
2866                         "{product_name:RE205,product_ver:3.0.0,special_id:54570000}\n"
2867                         "{product_name:RE205,product_ver:3.0.0,special_id:45530000}\n"
2868                         "{product_name:RE205,product_ver:3.0.0,special_id:45470000}\n",
2869                 .part_trail = 0x00,
2870                 .soft_ver = SOFT_VER_TEXT("soft_ver:1.1.0\n"),
2871 
2872                 .partitions = {
2873                         {"fs-uboot", 0x00000, 0x20000},
2874                         {"firmware", 0x20000, 0x7a0000},
2875                         {"partition-table", 0x7c0000, 0x02000},
2876                         {"default-mac", 0x7c2000, 0x00020},
2877                         {"pin", 0x7c2100, 0x00020},
2878                         {"product-info", 0x7c3100, 0x01000},
2879                         {"soft-version", 0x7c4200, 0x01000},
2880                         {"support-list", 0x7c5200, 0x01000},
2881                         {"profile", 0x7c6200, 0x08000},
2882                         {"config-info", 0x7ce200, 0x00400},
2883                         {"user-config", 0x7d0000, 0x10000},
2884                         {"default-config", 0x7e0000, 0x10000},
2885                         {"radio", 0x7f0000, 0x10000},
2886                         {NULL, 0, 0}
2887                 },
2888 
2889                 .first_sysupgrade_partition = "os-image",
2890                 .last_sysupgrade_partition = "file-system"
2891         },
2892 
2893         /** Firmware layout for the RE220 v2 */
2894         {
2895                 .id     = "RE220-V2",
2896                 .vendor = "",
2897                 .support_list =
2898                         "SupportList:\n"
2899                         "{product_name:RE220,product_ver:2.0.0,special_id:00000000}\n"
2900                         "{product_name:RE220,product_ver:2.0.0,special_id:41520000}\n"
2901                         "{product_name:RE220,product_ver:2.0.0,special_id:41550000}\n"
2902                         "{product_name:RE220,product_ver:2.0.0,special_id:42520000}\n"
2903                         "{product_name:RE220,product_ver:2.0.0,special_id:43410000}\n"
2904                         "{product_name:RE220,product_ver:2.0.0,special_id:45530000}\n"
2905                         "{product_name:RE220,product_ver:2.0.0,special_id:45550000}\n"
2906                         "{product_name:RE220,product_ver:2.0.0,special_id:49440000}\n"
2907                         "{product_name:RE220,product_ver:2.0.0,special_id:4a500000}\n"
2908                         "{product_name:RE220,product_ver:2.0.0,special_id:4b520000}\n"
2909                         "{product_name:RE220,product_ver:2.0.0,special_id:52550000}\n"
2910                         "{product_name:RE220,product_ver:2.0.0,special_id:54570000}\n"
2911                         "{product_name:RE220,product_ver:2.0.0,special_id:55530000}\n",
2912                 .part_trail = 0x00,
2913                 .soft_ver = SOFT_VER_DEFAULT,
2914 
2915                 .partitions = {
2916                         {"fs-uboot", 0x00000, 0x20000},
2917                         {"firmware", 0x20000, 0x7a0000},
2918                         {"partition-table", 0x7c0000, 0x02000},
2919                         {"default-mac", 0x7c2000, 0x00020},
2920                         {"pin", 0x7c2100, 0x00020},
2921                         {"product-info", 0x7c3100, 0x01000},
2922                         {"soft-version", 0x7c4200, 0x01000},
2923                         {"support-list", 0x7c5200, 0x01000},
2924                         {"profile", 0x7c6200, 0x08000},
2925                         {"config-info", 0x7ce200, 0x00400},
2926                         {"user-config", 0x7d0000, 0x10000},
2927                         {"default-config", 0x7e0000, 0x10000},
2928                         {"radio", 0x7f0000, 0x10000},
2929                         {NULL, 0, 0}
2930                 },
2931 
2932                 .first_sysupgrade_partition = "os-image",
2933                 .last_sysupgrade_partition = "file-system"
2934         },
2935 
2936   /** Firmware layout for the RE305 v1 */
2937         {
2938                 .id     = "RE305-V1",
2939                 .vendor = "",
2940                 .support_list =
2941                         "SupportList:\n"
2942                         "{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
2943                         "{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
2944                         "{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
2945                         "{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
2946                         "{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
2947                         "{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
2948                         "{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
2949                 .part_trail = 0x00,
2950                 .soft_ver = SOFT_VER_DEFAULT,
2951 
2952                 .partitions = {
2953                         {"fs-uboot", 0x00000, 0x20000},
2954                         {"firmware", 0x20000, 0x5e0000},
2955                         {"partition-table", 0x600000, 0x02000},
2956                         {"default-mac", 0x610000, 0x00020},
2957                         {"pin", 0x610100, 0x00020},
2958                         {"product-info", 0x611100, 0x01000},
2959                         {"soft-version", 0x620000, 0x01000},
2960                         {"support-list", 0x621000, 0x01000},
2961                         {"profile", 0x622000, 0x08000},
2962                         {"user-config", 0x630000, 0x10000},
2963                         {"default-config", 0x640000, 0x10000},
2964                         {"radio", 0x7f0000, 0x10000},
2965                         {NULL, 0, 0}
2966                 },
2967 
2968                 .first_sysupgrade_partition = "os-image",
2969                 .last_sysupgrade_partition = "file-system"
2970         },
2971 
2972         /** Firmware layout for the RE305 v3 */
2973         {
2974                 .id     = "RE305-V3",
2975                 .vendor = "",
2976                 .support_list =
2977                         "SupportList:\n"
2978                         "{product_name:RE305,product_ver:3.0.0,special_id:00000000}\n"
2979                         "{product_name:RE305,product_ver:3.0.0,special_id:45550000}\n"
2980                         "{product_name:RE305,product_ver:3.0.0,special_id:4A500000}\n"
2981                         "{product_name:RE305,product_ver:3.0.0,special_id:4B520000}\n"
2982                         "{product_name:RE305,product_ver:3.0.0,special_id:41550000}\n"
2983                         "{product_name:RE305,product_ver:3.0.0,special_id:42520000}\n"
2984                         "{product_name:RE305,product_ver:3.0.0,special_id:55530000}\n"
2985                         "{product_name:RE305,product_ver:3.0.0,special_id:45530000}\n"
2986                         "{product_name:RE305,product_ver:3.0.0,special_id:41530000}\n"
2987                         "{product_name:RE305,product_ver:3.0.0,special_id:43410000}\n"
2988                         "{product_name:RE305,product_ver:3.0.0,special_id:52550000}\n",
2989                 .part_trail = 0x00,
2990                 .soft_ver = SOFT_VER_TEXT("soft_ver:2.0.0\n"),
2991 
2992                 .partitions = {
2993                         {"fs-uboot", 0x00000, 0x20000},
2994                         {"firmware", 0x20000, 0x7a0000},
2995                         {"partition-table", 0x7c0000, 0x02000},
2996                         {"default-mac", 0x7c2000, 0x00020},
2997                         {"pin", 0x7c2100, 0x00020},
2998                         {"product-info", 0x7c3100, 0x01000},
2999                         {"soft-version", 0x7c4200, 0x01000},
3000                         {"support-list", 0x7c5200, 0x01000},
3001                         {"profile", 0x7c6200, 0x08000},
3002                         {"config-info", 0x7ce200, 0x00400},
3003                         {"user-config", 0x7d0000, 0x10000},
3004                         {"default-config", 0x7e0000, 0x10000},
3005                         {"radio", 0x7f0000, 0x10000},
3006                         {NULL, 0, 0}
3007                 },
3008 
3009                 .first_sysupgrade_partition = "os-image",
3010                 .last_sysupgrade_partition = "file-system"
3011         },
3012 
3013         /** Firmware layout for the RE350 v1 */
3014         {
3015                 .id     = "RE350-V1",
3016                 .vendor = "",
3017                 .support_list =
3018                         "SupportList:\n"
3019                         "{product_name:RE350,product_ver:1.0.0,special_id:45550000}\n"
3020                         "{product_name:RE350,product_ver:1.0.0,special_id:00000000}\n"
3021                         "{product_name:RE350,product_ver:1.0.0,special_id:41550000}\n"
3022                         "{product_name:RE350,product_ver:1.0.0,special_id:55530000}\n"
3023                         "{product_name:RE350,product_ver:1.0.0,special_id:43410000}\n"
3024                         "{product_name:RE350,product_ver:1.0.0,special_id:4b520000}\n"
3025                         "{product_name:RE350,product_ver:1.0.0,special_id:4a500000}\n",
3026                 .part_trail = 0x00,
3027                 .soft_ver = SOFT_VER_DEFAULT,
3028 
3029                 /** We're using a dynamic kernel/rootfs split here */
3030                 .partitions = {
3031                         {"fs-uboot", 0x00000, 0x20000},
3032                         {"firmware", 0x20000, 0x5e0000},
3033                         {"partition-table", 0x600000, 0x02000},
3034                         {"default-mac", 0x610000, 0x00020},
3035                         {"pin", 0x610100, 0x00020},
3036                         {"product-info", 0x611100, 0x01000},
3037                         {"soft-version", 0x620000, 0x01000},
3038                         {"support-list", 0x621000, 0x01000},
3039                         {"profile", 0x622000, 0x08000},
3040                         {"user-config", 0x630000, 0x10000},
3041                         {"default-config", 0x640000, 0x10000},
3042                         {"radio", 0x7f0000, 0x10000},
3043                         {NULL, 0, 0}
3044                 },
3045 
3046                 .first_sysupgrade_partition = "os-image",
3047                 .last_sysupgrade_partition = "file-system"
3048         },
3049 
3050         /** Firmware layout for the RE350K v1 */
3051         {
3052                 .id     = "RE350K-V1",
3053                 .vendor = "",
3054                 .support_list =
3055                         "SupportList:\n"
3056                         "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n",
3057                 .part_trail = 0x00,
3058                 .soft_ver = SOFT_VER_DEFAULT,
3059 
3060                 /** We're using a dynamic kernel/rootfs split here */
3061                 .partitions = {
3062                         {"fs-uboot", 0x00000, 0x20000},
3063                         {"firmware", 0x20000, 0xd70000},
3064                         {"partition-table", 0xd90000, 0x02000},
3065                         {"default-mac", 0xda0000, 0x00020},
3066                         {"pin", 0xda0100, 0x00020},
3067                         {"product-info", 0xda1100, 0x01000},
3068                         {"soft-version", 0xdb0000, 0x01000},
3069                         {"support-list", 0xdb1000, 0x01000},
3070                         {"profile", 0xdb2000, 0x08000},
3071                         {"user-config", 0xdc0000, 0x10000},
3072                         {"default-config", 0xdd0000, 0x10000},
3073                         {"device-id", 0xde0000, 0x00108},
3074                         {"radio", 0xff0000, 0x10000},
3075                         {NULL, 0, 0}
3076                 },
3077 
3078                 .first_sysupgrade_partition = "os-image",
3079                 .last_sysupgrade_partition = "file-system"
3080         },
3081 
3082         /** Firmware layout for the RE355 */
3083         {
3084                 .id     = "RE355",
3085                 .vendor = "",
3086                 .support_list =
3087                         "SupportList:\r\n"
3088                         "{product_name:RE355,product_ver:1.0.0,special_id:00000000}\r\n"
3089                         "{product_name:RE355,product_ver:1.0.0,special_id:55530000}\r\n"
3090                         "{product_name:RE355,product_ver:1.0.0,special_id:45550000}\r\n"
3091                         "{product_name:RE355,product_ver:1.0.0,special_id:4A500000}\r\n"
3092                         "{product_name:RE355,product_ver:1.0.0,special_id:43410000}\r\n"
3093                         "{product_name:RE355,product_ver:1.0.0,special_id:41550000}\r\n"
3094                         "{product_name:RE355,product_ver:1.0.0,special_id:4B520000}\r\n"
3095                         "{product_name:RE355,product_ver:1.0.0,special_id:55534100}\r\n",
3096                 .part_trail = 0x00,
3097                 .soft_ver = SOFT_VER_DEFAULT,
3098 
3099                 /* We're using a dynamic kernel/rootfs split here */
3100                 .partitions = {
3101                         {"fs-uboot", 0x00000, 0x20000},
3102                         {"firmware", 0x20000, 0x5e0000},
3103                         {"partition-table", 0x600000, 0x02000},
3104                         {"default-mac", 0x610000, 0x00020},
3105                         {"pin", 0x610100, 0x00020},
3106                         {"product-info", 0x611100, 0x01000},
3107                         {"soft-version", 0x620000, 0x01000},
3108                         {"support-list", 0x621000, 0x01000},
3109                         {"profile", 0x622000, 0x08000},
3110                         {"user-config", 0x630000, 0x10000},
3111                         {"default-config", 0x640000, 0x10000},
3112                         {"radio", 0x7f0000, 0x10000},
3113                         {NULL, 0, 0}
3114                 },
3115 
3116                 .first_sysupgrade_partition = "os-image",
3117                 .last_sysupgrade_partition = "file-system"
3118         },
3119 
3120         /** Firmware layout for the RE365 v1 */
3121         {
3122                 .id     = "RE365",
3123                 .vendor = "",
3124                 .support_list =
3125                         "SupportList:\r\n"
3126                         "{product_name:RE365,product_ver:1.0.0,special_id:45550000}\r\n"
3127                         "{product_name:RE365,product_ver:1.0.0,special_id:55530000}\r\n"
3128                         "{product_name:RE365,product_ver:1.0.0,special_id:4a500000}\r\n"
3129                         "{product_name:RE365,product_ver:1.0.0,special_id:42520000}\r\n"
3130                         "{product_name:RE365,product_ver:1.0.0,special_id:4b520000}\r\n"
3131                         "{product_name:RE365,product_ver:1.0.0,special_id:41550000}\r\n"
3132                         "{product_name:RE365,product_ver:1.0.0,special_id:43410000}\r\n"
3133                         "{product_name:RE365,product_ver:1.0.0,special_id:54570000}\r\n"
3134                         "{product_name:RE365,product_ver:1.0.0,special_id:41530000}\r\n",
3135                 .part_trail = 0x00,
3136                 .soft_ver = SOFT_VER_DEFAULT,
3137 
3138                 .partitions = {
3139                         {"fs-uboot", 0x00000, 0x20000},
3140                         {"firmware", 0x20000, 0x5e0000},
3141                         {"partition-table", 0x600000, 0x02000},
3142                         {"default-mac", 0x610000, 0x00020},
3143                         {"pin", 0x610100, 0x00020},
3144                         {"product-info", 0x611100, 0x01000},
3145                         {"soft-version", 0x620000, 0x01000},
3146                         {"support-list", 0x621000, 0x01000},
3147                         {"profile", 0x622000, 0x08000},
3148                         {"user-config", 0x630000, 0x10000},
3149                         {"default-config", 0x640000, 0x10000},
3150                         {"radio", 0x7f0000, 0x10000},
3151                         {NULL, 0, 0}
3152                 },
3153 
3154                 .first_sysupgrade_partition = "os-image",
3155                 .last_sysupgrade_partition = "file-system"
3156         },
3157 
3158         /** Firmware layout for the RE450 */
3159         {
3160                 .id     = "RE450",
3161                 .vendor = "",
3162                 .support_list =
3163                         "SupportList:\r\n"
3164                         "{product_name:RE450,product_ver:1.0.0,special_id:00000000}\r\n"
3165                         "{product_name:RE450,product_ver:1.0.0,special_id:55530000}\r\n"
3166                         "{product_name:RE450,product_ver:1.0.0,special_id:45550000}\r\n"
3167                         "{product_name:RE450,product_ver:1.0.0,special_id:4A500000}\r\n"
3168                         "{product_name:RE450,product_ver:1.0.0,special_id:43410000}\r\n"
3169                         "{product_name:RE450,product_ver:1.0.0,special_id:41550000}\r\n"
3170                         "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
3171                         "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
3172                 .part_trail = 0x00,
3173                 .soft_ver = SOFT_VER_DEFAULT,
3174 
3175                 /** We're using a dynamic kernel/rootfs split here */
3176                 .partitions = {
3177                         {"fs-uboot", 0x00000, 0x20000},
3178                         {"firmware", 0x20000, 0x5e0000},
3179                         {"partition-table", 0x600000, 0x02000},
3180                         {"default-mac", 0x610000, 0x00020},
3181                         {"pin", 0x610100, 0x00020},
3182                         {"product-info", 0x611100, 0x01000},
3183                         {"soft-version", 0x620000, 0x01000},
3184                         {"support-list", 0x621000, 0x01000},
3185                         {"profile", 0x622000, 0x08000},
3186                         {"user-config", 0x630000, 0x10000},
3187                         {"default-config", 0x640000, 0x10000},
3188                         {"radio", 0x7f0000, 0x10000},
3189                         {NULL, 0, 0}
3190                 },
3191 
3192                 .first_sysupgrade_partition = "os-image",
3193                 .last_sysupgrade_partition = "file-system"
3194         },
3195 
3196         /** Firmware layout for the RE450 v2 */
3197         {
3198                 .id     = "RE450-V2",
3199                 .vendor = "",
3200                 .support_list =
3201                         "SupportList:\r\n"
3202                         "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n"
3203                         "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n"
3204                         "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n"
3205                         "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n"
3206                         "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n"
3207                         "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n"
3208                         "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n"
3209                         "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n"
3210                         "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n",
3211                 .part_trail = 0x00,
3212                 .soft_ver = SOFT_VER_DEFAULT,
3213 
3214                 /* We're using a dynamic kernel/rootfs split here */
3215                 .partitions = {
3216                         {"fs-uboot", 0x00000, 0x20000},
3217                         {"firmware", 0x20000, 0x5e0000},
3218                         {"partition-table", 0x600000, 0x02000},
3219                         {"default-mac", 0x610000, 0x00020},
3220                         {"pin", 0x610100, 0x00020},
3221                         {"product-info", 0x611100, 0x01000},
3222                         {"soft-version", 0x620000, 0x01000},
3223                         {"support-list", 0x621000, 0x01000},
3224                         {"profile", 0x622000, 0x08000},
3225                         {"user-config", 0x630000, 0x10000},
3226                         {"default-config", 0x640000, 0x10000},
3227                         {"radio", 0x7f0000, 0x10000},
3228                         {NULL, 0, 0}
3229                 },
3230 
3231                 .first_sysupgrade_partition = "os-image",
3232                 .last_sysupgrade_partition = "file-system"
3233         },
3234 
3235         /** Firmware layout for the RE450 v3 */
3236         {
3237                 .id     = "RE450-V3",
3238                 .vendor = "",
3239                 .support_list =
3240                         "SupportList:\r\n"
3241                         "{product_name:RE450,product_ver:3.0.0,special_id:00000000}\r\n"
3242                         "{product_name:RE450,product_ver:3.0.0,special_id:55530000}\r\n"
3243                         "{product_name:RE450,product_ver:3.0.0,special_id:45550000}\r\n"
3244                         "{product_name:RE450,product_ver:3.0.0,special_id:4A500000}\r\n"
3245                         "{product_name:RE450,product_ver:3.0.0,special_id:43410000}\r\n"
3246                         "{product_name:RE450,product_ver:3.0.0,special_id:41550000}\r\n"
3247                         "{product_name:RE450,product_ver:3.0.0,special_id:41530000}\r\n"
3248                         "{product_name:RE450,product_ver:3.0.0,special_id:4B520000}\r\n"
3249                         "{product_name:RE450,product_ver:3.0.0,special_id:42520000}\r\n",
3250                 .part_trail = 0x00,
3251                 .soft_ver = SOFT_VER_DEFAULT,
3252 
3253                 /* We're using a dynamic kernel/rootfs split here */
3254                 .partitions = {
3255                         {"fs-uboot", 0x00000, 0x20000},
3256                         {"default-mac", 0x20000, 0x00020},
3257                         {"pin", 0x20020, 0x00020},
3258                         {"product-info", 0x21000, 0x01000},
3259                         {"partition-table", 0x22000, 0x02000},
3260                         {"soft-version", 0x24000, 0x01000},
3261                         {"support-list", 0x25000, 0x01000},
3262                         {"profile", 0x26000, 0x08000},
3263                         {"user-config", 0x2e000, 0x10000},
3264                         {"default-config", 0x3e000, 0x10000},
3265                         {"config-info", 0x4e000, 0x00400},
3266                         {"firmware", 0x50000, 0x7a0000},
3267                         {"radio", 0x7f0000, 0x10000},
3268                         {NULL, 0, 0}
3269                 },
3270 
3271                 .first_sysupgrade_partition = "os-image",
3272                 .last_sysupgrade_partition = "file-system"
3273         },
3274 
3275         /** Firmware layout for the RE455 v1 */
3276         {
3277                 .id     = "RE455-V1",
3278                 .vendor = "",
3279                 .support_list =
3280                         "SupportList:\r\n"
3281                         "{product_name:RE455,product_ver:1.0.0,special_id:00000000}\r\n"
3282                         "{product_name:RE455,product_ver:1.0.0,special_id:55530000}\r\n"
3283                         "{product_name:RE455,product_ver:1.0.0,special_id:45550000}\r\n"
3284                         "{product_name:RE455,product_ver:1.0.0,special_id:4A500000}\r\n"
3285                         "{product_name:RE455,product_ver:1.0.0,special_id:43410000}\r\n"
3286                         "{product_name:RE455,product_ver:1.0.0,special_id:41550000}\r\n"
3287                         "{product_name:RE455,product_ver:1.0.0,special_id:41530000}\r\n"
3288                         "{product_name:RE455,product_ver:1.0.0,special_id:4B520000}\r\n"
3289                         "{product_name:RE455,product_ver:1.0.0,special_id:42520000}\r\n",
3290                 .part_trail = 0x00,
3291                 .soft_ver = SOFT_VER_DEFAULT,
3292 
3293                 /* We're using a dynamic kernel/rootfs split here */
3294                 .partitions = {
3295                         {"fs-uboot", 0x00000, 0x20000},
3296                         {"default-mac", 0x20000, 0x00020},
3297                         {"pin", 0x20020, 0x00020},
3298                         {"product-info", 0x21000, 0x01000},
3299                         {"partition-table", 0x22000, 0x02000},
3300                         {"soft-version", 0x24000, 0x01000},
3301                         {"support-list", 0x25000, 0x01000},
3302                         {"profile", 0x26000, 0x08000},
3303                         {"user-config", 0x2e000, 0x10000},
3304                         {"default-config", 0x3e000, 0x10000},
3305                         {"config-info", 0x4e000, 0x00400},
3306                         {"firmware", 0x50000, 0x7a0000},
3307                         {"radio", 0x7f0000, 0x10000},
3308                         {NULL, 0, 0}
3309                 },
3310 
3311                 .first_sysupgrade_partition = "os-image",
3312                 .last_sysupgrade_partition = "file-system"
3313         },
3314 
3315         /** Firmware layout for the RE500 */
3316         {
3317                 .id     = "RE500-V1",
3318                 .vendor = "",
3319                 .support_list =
3320                         "SupportList:\r\n"
3321                         "{product_name:RE500,product_ver:1.0.0,special_id:00000000}\r\n"
3322                         "{product_name:RE500,product_ver:1.0.0,special_id:55530000}\r\n"
3323                         "{product_name:RE500,product_ver:1.0.0,special_id:45550000}\r\n"
3324                         "{product_name:RE500,product_ver:1.0.0,special_id:4A500000}\r\n"
3325                         "{product_name:RE500,product_ver:1.0.0,special_id:43410000}\r\n"
3326                         "{product_name:RE500,product_ver:1.0.0,special_id:41550000}\r\n"
3327                         "{product_name:RE500,product_ver:1.0.0,special_id:41530000}\r\n",
3328                 .part_trail = 0x00,
3329                 .soft_ver = SOFT_VER_DEFAULT,
3330 
3331                 /* We're using a dynamic kernel/rootfs split here */
3332                 .partitions = {
3333                         {"fs-uboot", 0x00000, 0x20000},
3334                         {"firmware", 0x20000, 0xde0000},
3335                         {"partition-table", 0xe00000, 0x02000},
3336                         {"default-mac", 0xe10000, 0x00020},
3337                         {"pin", 0xe10100, 0x00020},
3338                         {"product-info", 0xe11100, 0x01000},
3339                         {"soft-version", 0xe20000, 0x01000},
3340                         {"support-list", 0xe21000, 0x01000},
3341                         {"profile", 0xe22000, 0x08000},
3342                         {"user-config", 0xe30000, 0x10000},
3343                         {"default-config", 0xe40000, 0x10000},
3344                         {"radio", 0xff0000, 0x10000},
3345                         {NULL, 0, 0}
3346                 },
3347 
3348                 .first_sysupgrade_partition = "os-image",
3349                 .last_sysupgrade_partition = "file-system"
3350         },
3351 
3352         /** Firmware layout for the RE650 */
3353         {
3354                 .id     = "RE650-V1",
3355                 .vendor = "",
3356                 .support_list =
3357                         "SupportList:\r\n"
3358                         "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n"
3359                         "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n"
3360                         "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n"
3361                         "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n"
3362                         "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n"
3363                         "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n"
3364                         "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n",
3365                 .part_trail = 0x00,
3366                 .soft_ver = SOFT_VER_DEFAULT,
3367 
3368                 /* We're using a dynamic kernel/rootfs split here */
3369                 .partitions = {
3370                         {"fs-uboot", 0x00000, 0x20000},
3371                         {"firmware", 0x20000, 0xde0000},
3372                         {"partition-table", 0xe00000, 0x02000},
3373                         {"default-mac", 0xe10000, 0x00020},
3374                         {"pin", 0xe10100, 0x00020},
3375                         {"product-info", 0xe11100, 0x01000},
3376                         {"soft-version", 0xe20000, 0x01000},
3377                         {"support-list", 0xe21000, 0x01000},
3378                         {"profile", 0xe22000, 0x08000},
3379                         {"user-config", 0xe30000, 0x10000},
3380                         {"default-config", 0xe40000, 0x10000},
3381                         {"radio", 0xff0000, 0x10000},
3382                         {NULL, 0, 0}
3383                 },
3384 
3385                 .first_sysupgrade_partition = "os-image",
3386                 .last_sysupgrade_partition = "file-system"
3387         },
3388         /** Firmware layout for the RE650 V2 (8MB Flash)*/
3389         {
3390                 .id     = "RE650-V2",
3391                 .vendor = "",
3392                 .support_list =
3393                         "SupportList:\n"
3394                         "{product_name:RE650,product_ver:2.0.0,special_id:00000000}\n"
3395                         "{product_name:RE650,product_ver:2.0.0,special_id:45550000}\n"
3396                         "{product_name:RE650,product_ver:2.0.0,special_id:4A500000}\n"
3397                         "{product_name:RE650,product_ver:2.0.0,special_id:41550000}\n"
3398                         "{product_name:RE650,product_ver:2.0.0,special_id:43410000}\n"
3399                         "{product_name:RE650,product_ver:2.0.0,special_id:41530000}\n"
3400                         "{product_name:RE650,product_ver:2.0.0,special_id:55530000}\n",
3401                 .part_trail = 0x00,
3402                 /* For RE650 v2, soft ver is required, otherwise OEM install doesn't work */
3403                 .soft_ver = SOFT_VER_TEXT("soft_ver:2.0.0\n"),
3404 
3405                 /* We're using a dynamic kernel/rootfs split here */
3406                 .partitions = {
3407                         {"fs-uboot", 0x00000, 0x20000},
3408                         {"firmware", 0x20000, 0x7a0000},
3409                         {"partition-table", 0x7c0000, 0x02000},
3410                         {"default-mac", 0x7c2000, 0x00020},
3411                         {"pin", 0x7c2100, 0x00020},
3412                         {"product-info", 0x7c3100, 0x01000},
3413                         {"soft-version", 0x7c4200, 0x01000},
3414                         {"support-list", 0x7c5200, 0x01000},
3415                         {"profile", 0x7c6200, 0x08000},
3416                         {"config-info", 0x7ce200, 0x00400},
3417                         {"user-config", 0x7d0000, 0x10000},
3418                         {"default-config", 0x7e0000, 0x10000},
3419                         {"radio", 0x7f0000, 0x10000},
3420                         {NULL, 0, 0}
3421                 },
3422 
3423                 .first_sysupgrade_partition = "os-image",
3424                 .last_sysupgrade_partition = "file-system"
3425         },
3426 
3427         /** Firmware layout for the Mercusys MR70X */
3428         {
3429                 .id     = "MR70X",
3430                 .vendor = "",
3431                 .support_list =
3432                         "SupportList:\n"
3433                         "{product_name:MR1800X,product_ver:1.0.0,special_id:45550000}\n"
3434                         "{product_name:MR70X,product_ver:1.0.0,special_id:42520000}\n"
3435                         "{product_name:MR70X,product_ver:1.0.0,special_id:45470000}\n"
3436                         "{product_name:MR70X,product_ver:1.0.0,special_id:53470000}\n"
3437                         "{product_name:MR70X,product_ver:1.0.0,special_id:45550000}\n"
3438                         "{product_name:MR70X,product_ver:1.0.0,special_id:4A500000}\n"
3439                         "{product_name:MR70X,product_ver:1.0.0,special_id:55530000}\n",
3440                 .part_trail = 0x00,
3441                 .soft_ver = SOFT_VER_DEFAULT,
3442 
3443                 .partitions = {
3444                         {"fs-uboot", 0x00000, 0x40000},
3445                         {"firmware", 0x40000, 0xf60000},
3446                         {"default-mac", 0xfa0000, 0x00200},
3447                         {"pin", 0xfa0200, 0x00100},
3448                         {"device-id", 0xfa0300, 0x00100},
3449                         {"product-info", 0xfa0400, 0x0fc00},
3450                         {"default-config", 0xfb0000, 0x08000},
3451                         {"ap-def-config", 0xfb8000, 0x08000},
3452                         {"user-config", 0xfc0000, 0x0a000},
3453                         {"ag-config", 0xfca000, 0x04000},
3454                         {"certificate", 0xfce000, 0x02000},
3455                         {"ap-config", 0xfd0000, 0x06000},
3456                         {"router-config", 0xfd6000, 0x06000},
3457                         {"favicon", 0xfdc000, 0x02000},
3458                         {"logo", 0xfde000, 0x02000},
3459                         {"partition-table", 0xfe0000, 0x00800},
3460                         {"soft-version", 0xfe0800, 0x00100},
3461                         {"support-list", 0xfe0900, 0x00200},
3462                         {"profile", 0xfe0b00, 0x03000},
3463                         {"extra-para", 0xfe3b00, 0x00100},
3464                         {"radio", 0xff0000, 0x10000},
3465                         {NULL, 0, 0}
3466                 },
3467 
3468                 .first_sysupgrade_partition = "os-image",
3469                 .last_sysupgrade_partition = "file-system"
3470         },
3471 
3472         {}
3473 };
3474 
3475 #define error(_ret, _errno, _str, ...)                          \
3476         do {                                                    \
3477                 fprintf(stderr, _str ": %s\n", ## __VA_ARGS__,  \
3478                         strerror(_errno));                      \
3479                 if (_ret)                                       \
3480                         exit(_ret);                             \
3481         } while (0)
3482 
3483 
3484 /** Stores a uint32 as big endian */
3485 static inline void put32(uint8_t *buf, uint32_t val) {
3486         buf[0] = val >> 24;
3487         buf[1] = val >> 16;
3488         buf[2] = val >> 8;
3489         buf[3] = val;
3490 }
3491 
3492 static inline bool meta_partition_should_pad(enum partition_trail_value pv)
3493 {
3494         return (pv >= 0) && (pv <= PART_TRAIL_MAX);
3495 }
3496 
3497 /** Allocate a padded meta partition with a correctly initialised header
3498  * If the `data` pointer is NULL, then the required space is only allocated,
3499  * otherwise `data_len` bytes will be copied from `data` into the partition
3500  * entry. */
3501 static struct image_partition_entry init_meta_partition_entry(
3502         const char *name, const void *data, uint32_t data_len,
3503         enum partition_trail_value pad_value)
3504 {
3505         uint32_t total_len = sizeof(struct meta_header) + data_len;
3506         if (meta_partition_should_pad(pad_value))
3507                 total_len += 1;
3508 
3509         struct image_partition_entry entry = {
3510                 .name = name,
3511                 .size = total_len,
3512                 .data = malloc(total_len)
3513         };
3514         if (!entry.data)
3515                 error(1, errno, "failed to allocate meta partition entry");
3516 
3517         struct meta_header *header = (struct meta_header *)entry.data;
3518         header->length = htonl(data_len);
3519         header->zero = 0;
3520 
3521         if (data)
3522                 memcpy(entry.data+sizeof(*header), data, data_len);
3523 
3524         if (meta_partition_should_pad(pad_value))
3525                 entry.data[total_len - 1] = (uint8_t) pad_value;
3526 
3527         return entry;
3528 }
3529 
3530 /** Allocates a new image partition */
3531 static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
3532         struct image_partition_entry entry = {name, len, malloc(len)};
3533         if (!entry.data)
3534                 error(1, errno, "malloc");
3535 
3536         return entry;
3537 }
3538 
3539 /** Sets up default partition names whenever custom names aren't specified */
3540 static void set_partition_names(struct device_info *info)
3541 {
3542         if (!info->partition_names.partition_table)
3543                 info->partition_names.partition_table = "partition-table";
3544         if (!info->partition_names.soft_ver)
3545                 info->partition_names.soft_ver = "soft-version";
3546         if (!info->partition_names.os_image)
3547                 info->partition_names.os_image = "os-image";
3548         if (!info->partition_names.support_list)
3549                 info->partition_names.support_list = "support-list";
3550         if (!info->partition_names.file_system)
3551                 info->partition_names.file_system = "file-system";
3552         if (!info->partition_names.extra_para)
3553                 info->partition_names.extra_para = "extra-para";
3554 }
3555 
3556 /** Frees an image partition */
3557 static void free_image_partition(struct image_partition_entry *entry)
3558 {
3559         void *data = entry->data;
3560 
3561         entry->name = NULL;
3562         entry->size = 0;
3563         entry->data = NULL;
3564 
3565         free(data);
3566 }
3567 
3568 static time_t source_date_epoch = -1;
3569 static void set_source_date_epoch() {
3570         char *env = getenv("SOURCE_DATE_EPOCH");
3571         char *endptr = env;
3572         errno = 0;
3573         if (env && *env) {
3574                 source_date_epoch = strtoull(env, &endptr, 10);
3575                 if (errno || (endptr && *endptr != '\0')) {
3576                         fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
3577                         exit(1);
3578                 }
3579         }
3580 }
3581 
3582 /** Generates the partition-table partition */
3583 static struct image_partition_entry make_partition_table(const struct device_info *p)
3584 {
3585         struct image_partition_entry entry = alloc_image_partition(p->partition_names.partition_table, SAFELOADER_PAYLOAD_TABLE_SIZE);
3586 
3587         char *s = (char *)entry.data, *end = (char *)(s+entry.size);
3588 
3589         *(s++) = 0x00;
3590         *(s++) = 0x04;
3591         *(s++) = 0x00;
3592         *(s++) = 0x00;
3593 
3594         size_t i;
3595         for (i = 0; p->partitions[i].name; i++) {
3596                 size_t len = end-s;
3597                 size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n",
3598                         p->partitions[i].name, p->partitions[i].base, p->partitions[i].size);
3599 
3600                 if (w > len-1)
3601                         error(1, 0, "flash partition table overflow?");
3602 
3603                 s += w;
3604         }
3605 
3606         s++;
3607 
3608         memset(s, 0xff, end-s);
3609 
3610         return entry;
3611 }
3612 
3613 
3614 /** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
3615 static inline uint8_t bcd(uint8_t v) {
3616         return 0x10 * (v/10) + v%10;
3617 }
3618 
3619 
3620 /** Generates the soft-version partition */
3621 static struct image_partition_entry make_soft_version(const struct device_info *info, uint32_t rev)
3622 {
3623         /** If an info string is provided, use this instead of
3624          * the structured data, and include the null-termination */
3625         if (info->soft_ver.type == SOFT_VER_TYPE_TEXT) {
3626                 uint32_t len = strlen(info->soft_ver.text) + 1;
3627                 return init_meta_partition_entry(info->partition_names.soft_ver,
3628                         info->soft_ver.text, len, info->part_trail);
3629         }
3630 
3631         time_t t;
3632 
3633         if (source_date_epoch != -1)
3634                 t = source_date_epoch;
3635         else if (time(&t) == (time_t)(-1))
3636                 error(1, errno, "time");
3637 
3638         struct tm *tm = gmtime(&t);
3639 
3640         struct soft_version s = {
3641                 .pad1 = 0xff,
3642 
3643                 .version_major = info->soft_ver.num[0],
3644                 .version_minor = info->soft_ver.num[1],
3645                 .version_patch = info->soft_ver.num[2],
3646 
3647                 .year_hi = bcd((1900+tm->tm_year)/100),
3648                 .year_lo = bcd(tm->tm_year%100),
3649                 .month = bcd(tm->tm_mon+1),
3650                 .day = bcd(tm->tm_mday),
3651                 .rev = htonl(rev),
3652 
3653                 .compat_level = htonl(info->soft_ver_compat_level)
3654         };
3655 
3656         if (info->soft_ver_compat_level == 0)
3657                 return init_meta_partition_entry(info->partition_names.soft_ver, &s,
3658                         (uint8_t *)(&s.compat_level) - (uint8_t *)(&s),
3659                         info->part_trail);
3660         else
3661                 return init_meta_partition_entry(info->partition_names.soft_ver, &s,
3662                         sizeof(s), info->part_trail);
3663 }
3664 
3665 /** Generates the support-list partition */
3666 static struct image_partition_entry make_support_list(
3667         const struct device_info *info)
3668 {
3669         uint32_t len = strlen(info->support_list);
3670         return init_meta_partition_entry(info->partition_names.support_list, info->support_list,
3671                 len, info->part_trail);
3672 }
3673 
3674 /** Partition with extra-para data */
3675 static struct image_partition_entry make_extra_para(
3676         const struct device_info *info, const uint8_t *extra_para, size_t len)
3677 {
3678         return init_meta_partition_entry(info->partition_names.extra_para, extra_para, len,
3679                 info->part_trail);
3680 }
3681 
3682 /** Creates a new image partition with an arbitrary name from a file */
3683 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) {
3684         struct stat statbuf;
3685 
3686         if (stat(filename, &statbuf) < 0)
3687                 error(1, errno, "unable to stat file `%s'", filename);
3688 
3689         size_t len = statbuf.st_size;
3690 
3691         if (add_jffs2_eof) {
3692                 if (file_system_partition)
3693                         len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base;
3694                 else
3695                         len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
3696         }
3697 
3698         struct image_partition_entry entry = alloc_image_partition(part_name, len);
3699 
3700         FILE *file = fopen(filename, "rb");
3701         if (!file)
3702                 error(1, errno, "unable to open file `%s'", filename);
3703 
3704         if (fread(entry.data, statbuf.st_size, 1, file) != 1)
3705                 error(1, errno, "unable to read file `%s'", filename);
3706 
3707         if (add_jffs2_eof) {
3708                 uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
3709 
3710                 memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
3711                 memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
3712         }
3713 
3714         fclose(file);
3715 
3716         return entry;
3717 }
3718 
3719 /**
3720    Copies a list of image partitions into an image buffer and generates the image partition table while doing so
3721 
3722    Example image partition table:
3723 
3724      fwup-ptn partition-table base 0x00800 size 0x00800
3725      fwup-ptn os-image base 0x01000 size 0x113b45
3726      fwup-ptn file-system base 0x114b45 size 0x1d0004
3727      fwup-ptn support-list base 0x2e4b49 size 0x000d1
3728 
3729    Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
3730    the end of the partition table is marked with a zero byte.
3731 
3732    The firmware image must contain at least the partition-table and support-list partitions
3733    to be accepted. There aren't any alignment constraints for the image partitions.
3734 
3735    The partition-table partition contains the actual flash layout; partitions
3736    from the image partition table are mapped to the corresponding flash partitions during
3737    the firmware upgrade. The support-list partition contains a list of devices supported by
3738    the firmware image.
3739 
3740    The base offsets in the firmware partition table are relative to the end
3741    of the vendor information block, so the partition-table partition will
3742    actually start at offset 0x1814 of the image.
3743 
3744    I think partition-table must be the first partition in the firmware image.
3745 */
3746 static void put_partitions(uint8_t *buffer, const struct flash_partition_entry *flash_parts, const struct image_partition_entry *parts) {
3747         size_t i, j;
3748         char *image_pt = (char *)buffer, *end = image_pt + SAFELOADER_PAYLOAD_TABLE_SIZE;
3749 
3750         size_t base = SAFELOADER_PAYLOAD_TABLE_SIZE;
3751         for (i = 0; parts[i].name; i++) {
3752                 for (j = 0; flash_parts[j].name; j++) {
3753                         if (!strcmp(flash_parts[j].name, parts[i].name)) {
3754                                 if (parts[i].size > flash_parts[j].size)
3755                                         error(1, 0, "%s partition too big (more than %u bytes)", flash_parts[j].name, (unsigned)flash_parts[j].size);
3756                                 break;
3757                         }
3758                 }
3759 
3760                 assert(flash_parts[j].name);
3761 
3762                 memcpy(buffer + base, parts[i].data, parts[i].size);
3763 
3764                 size_t len = end-image_pt;
3765                 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);
3766 
3767                 if (w > len-1)
3768                         error(1, 0, "image partition table overflow?");
3769 
3770                 image_pt += w;
3771 
3772                 base += parts[i].size;
3773         }
3774 }
3775 
3776 /** Generates and writes the image MD5 checksum */
3777 static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
3778         MD5_CTX ctx;
3779 
3780         MD5_Init(&ctx);
3781         MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
3782         MD5_Update(&ctx, buffer, len);
3783         MD5_Final(md5, &ctx);
3784 }
3785 
3786 
3787 /**
3788    Generates the firmware image in factory format
3789 
3790    Image format:
3791 
3792      Bytes (hex)  Usage
3793      -----------  -----
3794      0000-0003    Image size (4 bytes, big endian)
3795      0004-0013    MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
3796      0014-0017    Vendor information length (without padding) (4 bytes, big endian)
3797      0018-1013    Vendor information (4092 bytes, padded with 0xff; there seem to be older
3798                   (VxWorks-based) TP-LINK devices which use a smaller vendor information block)
3799      1014-1813    Image partition table (2048 bytes, padded with 0xff)
3800      1814-xxxx    Firmware partitions
3801 */
3802 static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) {
3803         *len = SAFELOADER_PAYLOAD_OFFSET + SAFELOADER_PAYLOAD_TABLE_SIZE;
3804 
3805         size_t i;
3806         for (i = 0; parts[i].name; i++)
3807                 *len += parts[i].size;
3808 
3809         uint8_t *image = malloc(*len);
3810         if (!image)
3811                 error(1, errno, "malloc");
3812 
3813         memset(image, 0xff, *len);
3814         put32(image, *len);
3815 
3816         if (info->vendor) {
3817                 size_t vendor_len = strlen(info->vendor);
3818                 put32(image + SAFELOADER_PREAMBLE_SIZE, vendor_len);
3819                 memcpy(image + SAFELOADER_PREAMBLE_SIZE + 0x4, info->vendor, vendor_len);
3820         }
3821 
3822         put_partitions(image + SAFELOADER_PAYLOAD_OFFSET, info->partitions, parts);
3823         put_md5(image + 0x04, image + SAFELOADER_PREAMBLE_SIZE, *len - SAFELOADER_PREAMBLE_SIZE);
3824 
3825         return image;
3826 }
3827 
3828 /**
3829    Generates the firmware image in sysupgrade format
3830 
3831    This makes some assumptions about the provided flash and image partition tables and
3832    should be generalized when TP-LINK starts building its safeloader into hardware with
3833    different flash layouts.
3834 */
3835 static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) {
3836         size_t i, j;
3837         size_t flash_first_partition_index = 0;
3838         size_t flash_last_partition_index = 0;
3839         const struct flash_partition_entry *flash_first_partition = NULL;
3840         const struct flash_partition_entry *flash_last_partition = NULL;
3841         const struct image_partition_entry *image_last_partition = NULL;
3842 
3843         /** Find first and last partitions */
3844         for (i = 0; info->partitions[i].name; i++) {
3845                 if (!strcmp(info->partitions[i].name, info->first_sysupgrade_partition)) {
3846                         flash_first_partition = &info->partitions[i];
3847                         flash_first_partition_index = i;
3848                 } else if (!strcmp(info->partitions[i].name, info->last_sysupgrade_partition)) {
3849                         flash_last_partition = &info->partitions[i];
3850                         flash_last_partition_index = i;
3851                 }
3852         }
3853 
3854         assert(flash_first_partition && flash_last_partition);
3855         assert(flash_first_partition_index < flash_last_partition_index);
3856 
3857         /** Find last partition from image to calculate needed size */
3858         for (i = 0; image_parts[i].name; i++) {
3859                 if (!strcmp(image_parts[i].name, info->last_sysupgrade_partition)) {
3860                         image_last_partition = &image_parts[i];
3861                         break;
3862                 }
3863         }
3864 
3865         assert(image_last_partition);
3866 
3867         *len = flash_last_partition->base - flash_first_partition->base + image_last_partition->size;
3868 
3869         uint8_t *image = malloc(*len);
3870         if (!image)
3871                 error(1, errno, "malloc");
3872 
3873         memset(image, 0xff, *len);
3874 
3875         for (i = flash_first_partition_index; i <= flash_last_partition_index; i++) {
3876                 for (j = 0; image_parts[j].name; j++) {
3877                         if (!strcmp(info->partitions[i].name, image_parts[j].name)) {
3878                                 if (image_parts[j].size > info->partitions[i].size)
3879                                         error(1, 0, "%s partition too big (more than %u bytes)", info->partitions[i].name, (unsigned)info->partitions[i].size);
3880                                 memcpy(image + info->partitions[i].base - flash_first_partition->base, image_parts[j].data, image_parts[j].size);
3881                                 break;
3882                         }
3883 
3884                         assert(image_parts[j].name);
3885                 }
3886         }
3887 
3888         return image;
3889 }
3890 
3891 /** Generates an image according to a given layout and writes it to a file */
3892 static void build_image(const char *output,
3893                 const char *kernel_image,
3894                 const char *rootfs_image,
3895                 uint32_t rev,
3896                 bool add_jffs2_eof,
3897                 bool sysupgrade,
3898                 struct device_info *info) {
3899 
3900         size_t i;
3901 
3902         struct image_partition_entry parts[7] = {};
3903 
3904         struct flash_partition_entry *firmware_partition = NULL;
3905         struct flash_partition_entry *os_image_partition = NULL;
3906         struct flash_partition_entry *file_system_partition = NULL;
3907         size_t firmware_partition_index = 0;
3908 
3909         set_partition_names(info);
3910 
3911         for (i = 0; info->partitions[i].name; i++) {
3912                 if (!strcmp(info->partitions[i].name, "firmware"))
3913                 {
3914                         firmware_partition = &info->partitions[i];
3915                         firmware_partition_index = i;
3916                 }
3917         }
3918 
3919         if (firmware_partition)
3920         {
3921                 os_image_partition = &info->partitions[firmware_partition_index];
3922                 file_system_partition = &info->partitions[firmware_partition_index + 1];
3923 
3924                 struct stat kernel;
3925                 if (stat(kernel_image, &kernel) < 0)
3926                         error(1, errno, "unable to stat file `%s'", kernel_image);
3927 
3928                 if (kernel.st_size > firmware_partition->size)
3929                         error(1, 0, "kernel overflowed firmware partition\n");
3930 
3931                 for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--)
3932                         info->partitions[i+1] = info->partitions[i];
3933 
3934                 file_system_partition->name = info->partition_names.file_system;
3935 
3936                 file_system_partition->base = firmware_partition->base + kernel.st_size;
3937 
3938                 /* Align partition start to erase blocks for factory images only */
3939                 if (!sysupgrade)
3940                         file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000);
3941 
3942                 file_system_partition->size = firmware_partition->size - file_system_partition->base;
3943 
3944                 os_image_partition->name = info->partition_names.os_image;
3945 
3946                 os_image_partition->size = kernel.st_size;
3947         }
3948 
3949         parts[0] = make_partition_table(info);
3950         parts[1] = make_soft_version(info, rev);
3951         parts[2] = make_support_list(info);
3952         parts[3] = read_file(info->partition_names.os_image, kernel_image, false, NULL);
3953         parts[4] = read_file(info->partition_names.file_system, rootfs_image, add_jffs2_eof, file_system_partition);
3954 
3955 
3956         /* Some devices need the extra-para partition to accept the firmware */
3957         if (strcasecmp(info->id, "ARCHER-A6-V3") == 0 ||
3958             strcasecmp(info->id, "ARCHER-A7-V5") == 0 ||
3959             strcasecmp(info->id, "ARCHER-A9-V6") == 0 ||
3960             strcasecmp(info->id, "ARCHER-AX21-V4") == 0 ||
3961             strcasecmp(info->id, "ARCHER-AX23-V1") == 0 ||
3962             strcasecmp(info->id, "ARCHER-C2-V3") == 0 ||
3963             strcasecmp(info->id, "ARCHER-C7-V4") == 0 ||
3964             strcasecmp(info->id, "ARCHER-C7-V5") == 0 ||
3965             strcasecmp(info->id, "ARCHER-C25-V1") == 0 ||
3966             strcasecmp(info->id, "ARCHER-C59-V2") == 0 ||
3967             strcasecmp(info->id, "ARCHER-C60-V2") == 0 ||
3968             strcasecmp(info->id, "ARCHER-C60-V3") == 0 ||
3969             strcasecmp(info->id, "ARCHER-C6U-V1") == 0 ||
3970             strcasecmp(info->id, "ARCHER-C6-V3") == 0 ||
3971             strcasecmp(info->id, "DECO-M4R-V4") == 0 ||
3972             strcasecmp(info->id, "MR70X") == 0 ||
3973             strcasecmp(info->id, "TLWR1043NV5") == 0) {
3974                 const uint8_t extra_para[2] = {0x01, 0x00};
3975                 parts[5] = make_extra_para(info, extra_para,
3976                         sizeof(extra_para));
3977         } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0 ||
3978                    strcasecmp(info->id, "TL-WA1201-V2") == 0) {
3979                 const uint8_t extra_para[2] = {0x00, 0x01};
3980                 parts[5] = make_extra_para(info, extra_para,
3981                         sizeof(extra_para));
3982         } else if (strcasecmp(info->id, "ARCHER-C6-V2-US") == 0 ||
3983                    strcasecmp(info->id, "EAP245-V3") == 0) {
3984                 const uint8_t extra_para[2] = {0x01, 0x01};
3985                 parts[5] = make_extra_para(info, extra_para,
3986                         sizeof(extra_para));
3987         }
3988 
3989         size_t len;
3990         void *image;
3991         if (sysupgrade)
3992                 image = generate_sysupgrade_image(info, parts, &len);
3993         else
3994                 image = generate_factory_image(info, parts, &len);
3995 
3996         FILE *file = fopen(output, "wb");
3997         if (!file)
3998                 error(1, errno, "unable to open output file");
3999 
4000         if (fwrite(image, len, 1, file) != 1)
4001                 error(1, 0, "unable to write output file");
4002 
4003         fclose(file);
4004 
4005         free(image);
4006 
4007         for (i = 0; parts[i].name; i++)
4008                 free_image_partition(&parts[i]);
4009 }
4010 
4011 /** Usage output */
4012 static void usage(const char *argv0) {
4013         fprintf(stderr,
4014                 "Usage: %s [OPTIONS...]\n"
4015                 "\n"
4016                 "Options:\n"
4017                 "  -h              show this help\n"
4018                 "\n"
4019                 "Info about an image:\n"
4020                 "  -i <file>       input file to read from\n"
4021                 "Create a new image:\n"
4022                 "  -B <board>      create image for the board specified with <board>\n"
4023                 "  -k <file>       read kernel image from the file <file>\n"
4024                 "  -r <file>       read rootfs image from the file <file>\n"
4025                 "  -o <file>       write output to the file <file>\n"
4026                 "  -V <rev>        sets the revision number to <rev>\n"
4027                 "  -j              add jffs2 end-of-filesystem markers\n"
4028                 "  -S              create sysupgrade instead of factory image\n"
4029                 "Extract an old image:\n"
4030                 "  -x <file>       extract all oem firmware partition\n"
4031                 "  -d <dir>        destination to extract the firmware partition\n"
4032                 "  -z <file>       convert an oem firmware into a sysupgade file. Use -o for output file\n",
4033                 argv0
4034         );
4035 };
4036 
4037 
4038 static struct device_info *find_board(const char *id)
4039 {
4040         struct device_info *board = NULL;
4041 
4042         for (board = boards; board->id != NULL; board++)
4043                 if (strcasecmp(id, board->id) == 0)
4044                         return board;
4045 
4046         return NULL;
4047 }
4048 
4049 static int add_flash_partition(
4050                 struct flash_partition_entry *part_list,
4051                 size_t max_entries,
4052                 const char *name,
4053                 unsigned long base,
4054                 unsigned long size)
4055 {
4056         size_t ptr;
4057         /* check if the list has a free entry */
4058         for (ptr = 0; ptr < max_entries; ptr++, part_list++) {
4059                 if (part_list->name == NULL &&
4060                                 part_list->base == 0 &&
4061                                 part_list->size == 0)
4062                         break;
4063         }
4064 
4065         if (ptr == max_entries) {
4066                 error(1, 0, "No free flash part entry available.");
4067         }
4068 
4069         part_list->name = calloc(1, strlen(name) + 1);
4070         if (!part_list->name) {
4071                 error(1, 0, "Unable to allocate memory");
4072         }
4073 
4074         memcpy((char *)part_list->name, name, strlen(name));
4075         part_list->base = base;
4076         part_list->size = size;
4077 
4078         return 0;
4079 }
4080 
4081 /** read the partition table into struct flash_partition_entry */
4082 enum PARTITION_TABLE_TYPE {
4083         PARTITION_TABLE_FWUP,
4084         PARTITION_TABLE_FLASH,
4085 };
4086 
4087 static int read_partition_table(
4088                 FILE *file, long offset,
4089                 struct flash_partition_entry *entries, size_t max_entries,
4090                 int type)
4091 {
4092         char buf[SAFELOADER_PAYLOAD_TABLE_SIZE];
4093         char *ptr, *end;
4094         const char *parthdr = NULL;
4095         const char *fwuphdr = "fwup-ptn";
4096         const char *flashhdr = "partition";
4097 
4098         /* TODO: search for the partition table */
4099 
4100         switch(type) {
4101         case PARTITION_TABLE_FWUP:
4102                 parthdr = fwuphdr;
4103                 break;
4104         case PARTITION_TABLE_FLASH:
4105                 parthdr = flashhdr;
4106                 break;
4107         default:
4108                 error(1, 0, "Invalid partition table");
4109         }
4110 
4111         if (fseek(file, offset, SEEK_SET) < 0)
4112                 error(1, errno, "Can not seek in the firmware");
4113 
4114         if (fread(buf, sizeof(buf), 1, file) != 1)
4115                 error(1, errno, "Can not read fwup-ptn from the firmware");
4116 
4117         buf[sizeof(buf) - 1] = '\0';
4118 
4119         /* look for the partition header */
4120         if (memcmp(buf, parthdr, strlen(parthdr)) != 0) {
4121                 fprintf(stderr, "DEBUG: can not find fwuphdr\n");
4122                 return 1;
4123         }
4124 
4125         ptr = buf;
4126         end = buf + sizeof(buf);
4127         while ((ptr + strlen(parthdr)) < end &&
4128                         memcmp(ptr, parthdr, strlen(parthdr)) == 0) {
4129                 char *end_part;
4130                 char *end_element;
4131 
4132                 char name[32] = { 0 };
4133                 int name_len = 0;
4134                 unsigned long base = 0;
4135                 unsigned long size = 0;
4136 
4137                 end_part = memchr(ptr, '\n', (end - ptr));
4138                 if (end_part == NULL) {
4139                         /* in theory this should never happen, because a partition always ends with 0x09, 0x0D, 0x0A */
4140                         break;
4141                 }
4142 
4143                 for (int i = 0; i <= 4; i++) {
4144                         if (end_part <= ptr)
4145                                 break;
4146 
4147                         end_element = memchr(ptr, 0x20, (end_part - ptr));
4148                         if (end_element == NULL) {
4149                                 error(1, errno, "Ignoring the rest of the partition entries.");
4150                                 break;
4151                         }
4152 
4153                         switch (i) {
4154                                 /* partition header */
4155                                 case 0:
4156                                         ptr = end_element + 1;
4157                                         continue;
4158                                 /* name */
4159                                 case 1:
4160                                         name_len = (end_element - ptr) > 31 ? 31 : (end_element - ptr);
4161                                         strncpy(name, ptr, name_len);
4162                                         name[name_len] = '\0';
4163                                         ptr = end_element + 1;
4164                                         continue;
4165 
4166                                 /* string "base" */
4167                                 case 2:
4168                                         ptr = end_element + 1;
4169                                         continue;
4170 
4171                                 /* actual base */
4172                                 case 3:
4173                                         base = strtoul(ptr, NULL, 16);
4174                                         ptr = end_element + 1;
4175                                         continue;
4176 
4177                                 /* string "size" */
4178                                 case 4:
4179                                         ptr = end_element + 1;
4180                                         /* actual size. The last element doesn't have a sepeartor */
4181                                         size = strtoul(ptr, NULL, 16);
4182                                         /* the part ends with 0x09, 0x0d, 0x0a */
4183                                         ptr = end_part + 1;
4184                                         add_flash_partition(entries, max_entries, name, base, size);
4185                                         continue;
4186                         }
4187                 }
4188         }
4189 
4190         return 0;
4191 }
4192 
4193 static void safeloader_read_partition(FILE *input_file, size_t payload_offset,
4194                                       struct flash_partition_entry *entry,
4195                                       struct image_partition_entry *part)
4196 {
4197         size_t part_size = entry->size;
4198         void *part_data = malloc(part_size);
4199 
4200         if (fseek(input_file, payload_offset, SEEK_SET))
4201                 error(1, errno, "Failed to seek to partition data");
4202 
4203         if (!part_data)
4204                 error(1, ENOMEM, "Failed to allocate partition data");
4205 
4206         if (fread(part_data, 1, part_size, input_file) < part_size)
4207                 error(1, errno, "Failed to read partition data");
4208 
4209         part->data = part_data;
4210         part->size = part_size;
4211         part->name = entry->name;
4212 }
4213 
4214 static void safeloader_parse_image(FILE *input_file, struct safeloader_image_info *image)
4215 {
4216         static const char *HEADER_ID_CLOUD = "fw-type:Cloud";
4217         static const char *HEADER_ID_QNEW = "?NEW";
4218 
4219         char buf[64];
4220 
4221         if (!input_file)
4222                 return;
4223 
4224         fseek(input_file, SAFELOADER_PREAMBLE_SIZE, SEEK_SET);
4225 
4226         if (fread(buf, sizeof(buf), 1, input_file) != 1)
4227                 error(1, errno, "Can not read image header");
4228 
4229         if (memcmp(HEADER_ID_QNEW, &buf[0], strlen(HEADER_ID_QNEW)) == 0)
4230                 image->type = SAFELOADER_TYPE_QNEW;
4231         else if (memcmp(HEADER_ID_CLOUD, &buf[0], strlen(HEADER_ID_CLOUD)) == 0)
4232                 image->type = SAFELOADER_TYPE_CLOUD;
4233         else if (ntohl(*((uint32_t *) &buf[0])) <= SAFELOADER_HEADER_SIZE)
4234                 image->type = SAFELOADER_TYPE_VENDOR;
4235         else
4236                 image->type = SAFELOADER_TYPE_DEFAULT;
4237 
4238         switch (image->type) {
4239         case SAFELOADER_TYPE_DEFAULT:
4240         case SAFELOADER_TYPE_VENDOR:
4241         case SAFELOADER_TYPE_CLOUD:
4242                 image->payload_offset = SAFELOADER_PAYLOAD_OFFSET;
4243                 break;
4244         case SAFELOADER_TYPE_QNEW:
4245                 image->payload_offset = SAFELOADER_QNEW_PAYLOAD_OFFSET;
4246                 break;
4247         }
4248 
4249         /* Parse image partition table */
4250         read_partition_table(input_file, image->payload_offset, &image->entries[0],
4251                              MAX_PARTITIONS, PARTITION_TABLE_FWUP);
4252 }
4253 
4254 static void write_partition(
4255                 FILE *input_file,
4256                 size_t firmware_offset,
4257                 struct flash_partition_entry *entry,
4258                 FILE *output_file)
4259 {
4260         char buf[4096];
4261         size_t offset;
4262 
4263         fseek(input_file, entry->base + firmware_offset, SEEK_SET);
4264 
4265         for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) {
4266                 if (fread(buf, sizeof(buf), 1, input_file) != 1)
4267                         error(1, errno, "Can not read partition from input_file");
4268 
4269                 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
4270                         error(1, errno, "Can not write partition to output_file");
4271         }
4272         /* write last chunk smaller than buffer */
4273         if (offset < entry->size) {
4274                 offset = entry->size - offset;
4275                 if (fread(buf, offset, 1, input_file) != 1)
4276                         error(1, errno, "Can not read partition from input_file");
4277                 if (fwrite(buf, offset, 1, output_file) != 1)
4278                         error(1, errno, "Can not write partition to output_file");
4279         }
4280 }
4281 
4282 static int extract_firmware_partition(FILE *input_file, size_t firmware_offset, struct flash_partition_entry *entry, const char *output_directory)
4283 {
4284         FILE *output_file;
4285         char output[PATH_MAX];
4286 
4287         snprintf(output, PATH_MAX, "%s/%s", output_directory, entry->name);
4288         output_file = fopen(output, "wb+");
4289         if (output_file == NULL) {
4290                 error(1, errno, "Can not open output file %s", output);
4291         }
4292 
4293         write_partition(input_file, firmware_offset, entry, output_file);
4294 
4295         fclose(output_file);
4296 
4297         return 0;
4298 }
4299 
4300 /** extract all partitions from the firmware file */
4301 static int extract_firmware(const char *input, const char *output_directory)
4302 {
4303         struct safeloader_image_info info = {};
4304         struct stat statbuf;
4305         FILE *input_file;
4306 
4307         /* check input file */
4308         if (stat(input, &statbuf)) {
4309                 error(1, errno, "Can not read input firmware %s", input);
4310         }
4311 
4312         /* check if output directory exists */
4313         if (stat(output_directory, &statbuf)) {
4314                 error(1, errno, "Failed to stat output directory %s", output_directory);
4315         }
4316 
4317         if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
4318                 error(1, errno, "Given output directory is not a directory %s", output_directory);
4319         }
4320 
4321         input_file = fopen(input, "rb");
4322         safeloader_parse_image(input_file, &info);
4323 
4324         for (size_t i = 0; i < MAX_PARTITIONS && info.entries[i].name; i++)
4325                 extract_firmware_partition(input_file, info.payload_offset, &info.entries[i], output_directory);
4326 
4327         return 0;
4328 }
4329 
4330 static struct flash_partition_entry *find_partition(
4331                 struct flash_partition_entry *entries, size_t max_entries,
4332                 const char *name, const char *error_msg)
4333 {
4334         for (size_t i = 0; i < max_entries; i++, entries++) {
4335                 if (strcmp(entries->name, name) == 0)
4336                         return entries;
4337         }
4338 
4339         if (error_msg) {
4340                 error(1, 0, "%s", error_msg);
4341         }
4342 
4343         return NULL;
4344 }
4345 
4346 static int firmware_info(const char *input)
4347 {
4348         struct safeloader_image_info info = {};
4349         struct image_partition_entry part = {};
4350         struct flash_partition_entry *e;
4351         FILE *input_file;
4352 
4353         input_file = fopen(input, "rb");
4354 
4355         safeloader_parse_image(input_file, &info);
4356 
4357         if (info.type == SAFELOADER_TYPE_VENDOR) {
4358                 char buf[SAFELOADER_HEADER_SIZE] = {};
4359                 uint32_t vendor_size;
4360 
4361                 fseek(input_file, SAFELOADER_PREAMBLE_SIZE, SEEK_SET);
4362                 fread(&vendor_size, sizeof(uint32_t), 1, input_file);
4363 
4364                 vendor_size = ntohl(vendor_size);
4365                 fread(buf, vendor_size, 1, input_file);
4366 
4367                 printf("Firmware vendor string:\n");
4368                 fwrite(buf, strnlen(buf, vendor_size), 1, stdout);
4369                 printf("\n");
4370         }
4371 
4372         printf("Firmware image partitions:\n");
4373         printf("%-8s %-8s %s\n", "base", "size", "name");
4374 
4375         e = &info.entries[0];
4376         for (unsigned int i = 0; i < MAX_PARTITIONS && e->name; i++, e++)
4377                 printf("%08x %08x %s\n", e->base, e->size, e->name);
4378 
4379         e = find_partition(&info.entries[0], MAX_PARTITIONS, "soft-version", NULL);
4380         if (e) {
4381                 struct soft_version *s;
4382                 unsigned int ascii_len;
4383                 const uint8_t *buf;
4384                 size_t data_len;
4385                 bool isstr;
4386 
4387                 safeloader_read_partition(input_file, info.payload_offset + e->base, e, &part);
4388                 data_len = ntohl(((struct meta_header *) part.data)->length);
4389                 buf = part.data + sizeof(struct meta_header);
4390 
4391                 /* Check for (null-terminated) string */
4392                 ascii_len = 0;
4393                 while (ascii_len < data_len && isascii(buf[ascii_len]))
4394                         ascii_len++;
4395 
4396                 isstr = ascii_len == data_len;
4397 
4398                 printf("\n[Software version]\n");
4399                 if (isstr) {
4400                         fwrite(buf, strnlen((const char *) buf, data_len), 1, stdout);
4401                         putchar('\n');
4402                 } else if (data_len >= offsetof(struct soft_version, rev)) {
4403                         s = (struct soft_version *) buf;
4404 
4405                         printf("Version: %d.%d.%d\n", s->version_major, s->version_minor, s->version_patch);
4406                         printf("Date: %02x%02x-%02x-%02x\n", s->year_hi, s->year_lo, s->month, s->day);
4407                         printf("Revision: %d\n", ntohl(s->rev));
4408 
4409                         if (data_len >= offsetof(struct soft_version, compat_level)) {
4410                                 printf("Compatibility level: %d\n", ntohl(s->compat_level));
4411                         }
4412                 } else {
4413                         printf("Failed to parse data\n");
4414                 }
4415 
4416                 free_image_partition(&part);
4417         }
4418 
4419         e = find_partition(&info.entries[0], MAX_PARTITIONS, "support-list", NULL);
4420         if (e) {
4421                 size_t data_len;
4422 
4423                 safeloader_read_partition(input_file, info.payload_offset + e->base, e, &part);
4424                 data_len = ntohl(((struct meta_header *) part.data)->length);
4425 
4426                 printf("\n[Support list]\n");
4427                 fwrite(part.data + sizeof(struct meta_header), data_len, 1, stdout);
4428                 printf("\n");
4429 
4430                 free_image_partition(&part);
4431         }
4432 
4433         e = find_partition(&info.entries[0], MAX_PARTITIONS, "partition-table", NULL);
4434         if (e) {
4435                 size_t flash_table_offset = info.payload_offset + e->base + 4;
4436                 struct flash_partition_entry parts[MAX_PARTITIONS] = {};
4437 
4438                 if (read_partition_table(input_file, flash_table_offset, parts, MAX_PARTITIONS, PARTITION_TABLE_FLASH))
4439                         error(1, 0, "Error can not read the partition table (partition)");
4440 
4441                 printf("\n[Partition table]\n");
4442                 printf("%-8s %-8s %s\n", "base", "size", "name");
4443 
4444                 e = &parts[0];
4445                 for (unsigned int i = 0; i < MAX_PARTITIONS && e->name; i++, e++)
4446                         printf("%08x %08x %s\n", e->base, e->size, e->name);
4447         }
4448 
4449         fclose(input_file);
4450 
4451         return 0;
4452 }
4453 
4454 static void write_ff(FILE *output_file, size_t size)
4455 {
4456         char buf[4096];
4457         size_t offset;
4458 
4459         memset(buf, 0xff, sizeof(buf));
4460 
4461         for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) {
4462                 if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
4463                         error(1, errno, "Can not write 0xff to output_file");
4464         }
4465 
4466         /* write last chunk smaller than buffer */
4467         if (offset < size) {
4468                 offset = size - offset;
4469                 if (fwrite(buf, offset, 1, output_file) != 1)
4470                         error(1, errno, "Can not write partition to output_file");
4471         }
4472 }
4473 
4474 static void convert_firmware(const char *input, const char *output)
4475 {
4476         struct flash_partition_entry flash[MAX_PARTITIONS] = {};
4477         struct flash_partition_entry *fwup_partition_table;
4478         struct flash_partition_entry *flash_file_system;
4479         struct flash_partition_entry *fwup_file_system;
4480         struct flash_partition_entry *flash_os_image;
4481         struct flash_partition_entry *fwup_os_image;
4482         struct safeloader_image_info info = {};
4483         size_t flash_table_offset;
4484         struct stat statbuf;
4485         FILE *output_file;
4486         FILE *input_file;
4487 
4488         /* check input file */
4489         if (stat(input, &statbuf)) {
4490                 error(1, errno, "Can not read input firmware %s", input);
4491         }
4492 
4493         input_file = fopen(input, "rb");
4494         if (!input_file)
4495                 error(1, 0, "Can not open input firmware %s", input);
4496 
4497         output_file = fopen(output, "wb");
4498         if (!output_file)
4499                 error(1, 0, "Can not open output firmware %s", output);
4500 
4501         input_file = fopen(input, "rb");
4502         safeloader_parse_image(input_file, &info);
4503 
4504         fwup_os_image = find_partition(info.entries, MAX_PARTITIONS,
4505                         "os-image", "Error can not find os-image partition (fwup)");
4506         fwup_file_system = find_partition(info.entries, MAX_PARTITIONS,
4507                         "file-system", "Error can not find file-system partition (fwup)");
4508         fwup_partition_table = find_partition(info.entries, MAX_PARTITIONS,
4509                         "partition-table", "Error can not find partition-table partition");
4510 
4511         /* the flash partition table has a 0x00000004 magic haeder */
4512         flash_table_offset = info.payload_offset + fwup_partition_table->base + 4;
4513         if (read_partition_table(input_file, flash_table_offset, flash, MAX_PARTITIONS, PARTITION_TABLE_FLASH) != 0)
4514                 error(1, 0, "Error can not read the partition table (flash)");
4515 
4516         flash_os_image = find_partition(flash, MAX_PARTITIONS,
4517                         "os-image", "Error can not find os-image partition (flash)");
4518         flash_file_system = find_partition(flash, MAX_PARTITIONS,
4519                         "file-system", "Error can not find file-system partition (flash)");
4520 
4521         /* write os_image to 0x0 */
4522         write_partition(input_file, info.payload_offset, fwup_os_image, output_file);
4523         write_ff(output_file, flash_os_image->size - fwup_os_image->size);
4524 
4525         /* write file-system behind os_image */
4526         fseek(output_file, flash_file_system->base - flash_os_image->base, SEEK_SET);
4527         write_partition(input_file, info.payload_offset, fwup_file_system, output_file);
4528 
4529         fclose(output_file);
4530         fclose(input_file);
4531 }
4532 
4533 int main(int argc, char *argv[]) {
4534         const char *info_image = NULL, *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
4535         const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL;
4536         bool add_jffs2_eof = false, sysupgrade = false;
4537         unsigned rev = 0;
4538         struct device_info *info;
4539         set_source_date_epoch();
4540 
4541         while (true) {
4542                 int c;
4543 
4544                 c = getopt(argc, argv, "i:B:k:r:o:V:jSh:x:d:z:");
4545                 if (c == -1)
4546                         break;
4547 
4548                 switch (c) {
4549                 case 'i':
4550                         info_image = optarg;
4551                         break;
4552 
4553                 case 'B':
4554                         board = optarg;
4555                         break;
4556 
4557                 case 'k':
4558                         kernel_image = optarg;
4559                         break;
4560 
4561                 case 'r':
4562                         rootfs_image = optarg;
4563                         break;
4564 
4565                 case 'o':
4566                         output = optarg;
4567                         break;
4568 
4569                 case 'V':
4570                         sscanf(optarg, "r%u", &rev);
4571                         break;
4572 
4573                 case 'j':
4574                         add_jffs2_eof = true;
4575                         break;
4576 
4577                 case 'S':
4578                         sysupgrade = true;
4579                         break;
4580 
4581                 case 'h':
4582                         usage(argv[0]);
4583                         return 0;
4584 
4585                 case 'd':
4586                         output_directory = optarg;
4587                         break;
4588 
4589                 case 'x':
4590                         extract_image = optarg;
4591                         break;
4592 
4593                 case 'z':
4594                         convert_image = optarg;
4595                         break;
4596 
4597                 default:
4598                         usage(argv[0]);
4599                         return 1;
4600                 }
4601         }
4602 
4603         if (info_image) {
4604                 firmware_info(info_image);
4605         } else if (extract_image || output_directory) {
4606                 if (!extract_image)
4607                         error(1, 0, "No factory/oem image given via -x <file>. Output directory is only valid with -x");
4608                 if (!output_directory)
4609                         error(1, 0, "Can not extract an image without output directory. Use -d <dir>");
4610                 extract_firmware(extract_image, output_directory);
4611         } else if (convert_image) {
4612                 if (!output)
4613                         error(1, 0, "Can not convert a factory/oem image into sysupgrade image without output file. Use -o <file>");
4614                 convert_firmware(convert_image, output);
4615         } else {
4616                 if (!board)
4617                         error(1, 0, "no board has been specified");
4618                 if (!kernel_image)
4619                         error(1, 0, "no kernel image has been specified");
4620                 if (!rootfs_image)
4621                         error(1, 0, "no rootfs image has been specified");
4622                 if (!output)
4623                         error(1, 0, "no output filename has been specified");
4624 
4625                 info = find_board(board);
4626 
4627                 if (info == NULL)
4628                         error(1, 0, "unsupported board %s", board);
4629 
4630                 build_image(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, info);
4631         }
4632 
4633         return 0;
4634 }
4635 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt