0065-fw-utils-tplink-safeloader.c-Add-support-for-Archer-C2600.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Thu, 9 Jun 2016 05:02:18 +0200
  3. Subject: fw-utils/tplink-safeloader.c: Add support for Archer C2600
  4. Signed-off-by: Ash Benz <ash.benz@bk.ru>
  5. Backport of LEDE 955c341d3bec0eb4971a03924e99156367255d7b
  6. diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
  7. index 77a894b237281f6211dd1123ead4b5b0f2f58370..2e204aa2335e55515a60a1f5c08ca1b499eb9287 100644
  8. --- a/tools/firmware-utils/src/tplink-safeloader.c
  9. +++ b/tools/firmware-utils/src/tplink-safeloader.c
  10. @@ -105,6 +105,8 @@ static const uint8_t md5_salt[16] = {
  11. /** Vendor information for CPE210/220/510/520 */
  12. static const char cpe510_vendor[] = "CPE510(TP-LINK|UN|N300-5):1.0\r\n";
  13. +/** Vendor information for C2600 */
  14. +static const char c2600_vendor[] = "";
  15. /**
  16. The flash partition table for CPE210/220/510/520;
  17. @@ -128,6 +130,39 @@ static const struct flash_partition_entry cpe510_partitions[] = {
  18. };
  19. /**
  20. + The flash partition table for C2600;
  21. + it is the same as the one used by the stock images.
  22. +*/
  23. +static const struct flash_partition_entry c2600_partitions[] = {
  24. + {"SBL1", 0x00000, 0x20000},
  25. + {"MIBIB", 0x20000, 0x20000},
  26. + {"SBL2", 0x40000, 0x20000},
  27. + {"SBL3", 0x60000, 0x30000},
  28. + {"DDRCONFIG", 0x90000, 0x10000},
  29. + {"SSD", 0xa0000, 0x10000},
  30. + {"TZ", 0xb0000, 0x30000},
  31. + {"RPM", 0xe0000, 0x20000},
  32. + {"fs-uboot", 0x100000, 0x70000},
  33. + {"uboot-env", 0x170000, 0x40000},
  34. + {"radio", 0x1b0000, 0x40000},
  35. + {"os-image", 0x1f0000, 0x200000},
  36. + {"file-system", 0x3f0000, 0x1b00000},
  37. + {"default-mac", 0x1ef0000, 0x00200},
  38. + {"pin", 0x1ef0200, 0x00200},
  39. + {"product-info", 0x1ef0400, 0x0fc00},
  40. + {"partition-table", 0x1f00000, 0x10000},
  41. + {"soft-version", 0x1f10000, 0x10000},
  42. + {"support-list", 0x1f20000, 0x10000},
  43. + {"profile", 0x1f30000, 0x10000},
  44. + {"default-config", 0x1f40000, 0x10000},
  45. + {"user-config", 0x1f50000, 0x40000},
  46. + {"qos-db", 0x1f90000, 0x40000},
  47. + {"usb-config", 0x1fd0000, 0x10000},
  48. + {"log", 0x1fe0000, 0x20000},
  49. + {NULL, 0, 0}
  50. +};
  51. +
  52. +/**
  53. The support list for CPE210/220/510/520
  54. */
  55. static const char cpe510_support_list[] =
  56. @@ -141,6 +176,13 @@ static const char cpe510_support_list[] =
  57. "CPE220(TP-LINK|UN|N300-2):1.0\r\n"
  58. "CPE220(TP-LINK|UN|N300-2):1.1\r\n";
  59. +/**
  60. + The support list for C2600
  61. +*/
  62. +static const char c2600_support_list[] =
  63. + "SupportList:\r\n"
  64. + "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n";
  65. +
  66. #define error(_ret, _errno, _str, ...) \
  67. do { \
  68. fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
  69. @@ -240,14 +282,14 @@ static struct image_partition_entry make_soft_version(uint32_t rev) {
  70. }
  71. /** Generates the support-list partition */
  72. -static struct image_partition_entry make_support_list(const char *support_list) {
  73. +static struct image_partition_entry make_support_list(const char *support_list, bool trailzero) {
  74. size_t len = strlen(support_list);
  75. struct image_partition_entry entry = alloc_image_partition("support-list", len + 9);
  76. put32(entry.data, len);
  77. memset(entry.data+4, 0, 4);
  78. memcpy(entry.data+8, support_list, len);
  79. - entry.data[len+8] = '\xff';
  80. + entry.data[len+8] = trailzero ? '\x00' : '\xff';
  81. return entry;
  82. }
  83. @@ -436,6 +478,37 @@ static void * generate_sysupgrade_image(const struct flash_partition_entry *flas
  84. return image;
  85. }
  86. +static void * generate_sysupgrade_image_c2600(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
  87. + const struct flash_partition_entry *flash_os_image = &flash_parts[11];
  88. + const struct flash_partition_entry *flash_file_system = &flash_parts[12];
  89. +
  90. + const struct image_partition_entry *image_os_image = &image_parts[3];
  91. + const struct image_partition_entry *image_file_system = &image_parts[4];
  92. +
  93. + assert(strcmp(flash_os_image->name, "os-image") == 0);
  94. + assert(strcmp(flash_file_system->name, "file-system") == 0);
  95. +
  96. + assert(strcmp(image_os_image->name, "os-image") == 0);
  97. + assert(strcmp(image_file_system->name, "file-system") == 0);
  98. +
  99. + if (image_os_image->size > flash_os_image->size)
  100. + error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
  101. + if (image_file_system->size > flash_file_system->size)
  102. + error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
  103. +
  104. + *len = flash_file_system->base - flash_os_image->base + image_file_system->size;
  105. +
  106. + uint8_t *image = malloc(*len);
  107. + if (!image)
  108. + error(1, errno, "malloc");
  109. +
  110. + memset(image, 0xff, *len);
  111. +
  112. + memcpy(image, image_os_image->data, image_os_image->size);
  113. + memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
  114. +
  115. + return image;
  116. +}
  117. /** Generates an image for CPE210/220/510/520 and writes it to a file */
  118. static void do_cpe510(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
  119. @@ -443,7 +516,7 @@ static void do_cpe510(const char *output, const char *kernel_image, const char *
  120. parts[0] = make_partition_table(cpe510_partitions);
  121. parts[1] = make_soft_version(rev);
  122. - parts[2] = make_support_list(cpe510_support_list);
  123. + parts[2] = make_support_list(cpe510_support_list,false);
  124. parts[3] = read_file("os-image", kernel_image, false);
  125. parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
  126. @@ -470,6 +543,39 @@ static void do_cpe510(const char *output, const char *kernel_image, const char *
  127. free_image_partition(parts[i]);
  128. }
  129. +/** Generates an image for C2600 and writes it to a file */
  130. +static void do_c2600(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
  131. + struct image_partition_entry parts[6] = {};
  132. +
  133. + parts[0] = make_partition_table(c2600_partitions);
  134. + parts[1] = make_soft_version(rev);
  135. + parts[2] = make_support_list(c2600_support_list,true);
  136. + parts[3] = read_file("os-image", kernel_image, false);
  137. + parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
  138. +
  139. + size_t len;
  140. + void *image;
  141. + if (sysupgrade)
  142. + image = generate_sysupgrade_image_c2600(c2600_partitions, parts, &len);
  143. + else
  144. + image = generate_factory_image(c2600_vendor, parts, &len);
  145. +
  146. + FILE *file = fopen(output, "wb");
  147. + if (!file)
  148. + error(1, errno, "unable to open output file");
  149. +
  150. + if (fwrite(image, len, 1, file) != 1)
  151. + error(1, 0, "unable to write output file");
  152. +
  153. + fclose(file);
  154. +
  155. + free(image);
  156. +
  157. + size_t i;
  158. + for (i = 0; parts[i].name; i++)
  159. + free_image_partition(parts[i]);
  160. +}
  161. +
  162. /** Usage output */
  163. static void usage(const char *argv0) {
  164. @@ -552,6 +658,8 @@ int main(int argc, char *argv[]) {
  165. if (strcmp(board, "CPE510") == 0)
  166. do_cpe510(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
  167. + else if (strcmp(board, "C2600") == 0)
  168. + do_c2600(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
  169. else
  170. error(1, 0, "unsupported board %s", board);