0041-firmware-utils-tplink-safeloader-support-strings-as-soft_version.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. From: Jan Niehusmann <jan@gondor.com>
  2. Date: Fri, 19 May 2017 09:42:24 +0200
  3. Subject: firmware-utils: tplink-safeloader: support strings as soft_version
  4. Some TP-Link routers (C25, C59, C60) contain a version string instead
  5. of a binary structure in the soft_version partition.
  6. Flashing LEDE from the original firmware's GUI, this version string
  7. taken from the soft_ver partition of the firmware image is written to
  8. the router's config partition.
  9. When using tftp recovery to go back to the original Archer C25 firmware,
  10. a version check compares that version to the version of the firmware to
  11. be flashed.
  12. Without proper contents in the config partition, reverting to the
  13. original firmware fails.
  14. Therefore, write the string "soft_ver:1.0.0\n" to that soft_ver
  15. partition.
  16. Signed-off-by: Jan Niehusmann <jan@gondor.com>
  17. diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
  18. index 7617566829e159ae9fec00d5de95919a0fb234c6..24684268b1a3fe491c4eb876a5ebefc700f2e56e 100644
  19. --- a/tools/firmware-utils/src/tplink-safeloader.c
  20. +++ b/tools/firmware-utils/src/tplink-safeloader.c
  21. @@ -75,6 +75,7 @@ struct device_info {
  22. const char *vendor;
  23. const char *support_list;
  24. char support_trail;
  25. + const char *soft_ver;
  26. const struct flash_partition_entry partitions[MAX_PARTITIONS+1];
  27. const char *first_sysupgrade_partition;
  28. const char *last_sysupgrade_partition;
  29. @@ -130,6 +131,7 @@ static struct device_info boards[] = {
  30. "CPE220(TP-LINK|US|N300-2):1.1\r\n"
  31. "CPE220(TP-LINK|EU|N300-2):1.1\r\n",
  32. .support_trail = '\xff',
  33. + .soft_ver = NULL,
  34. .partitions = {
  35. {"fs-uboot", 0x00000, 0x20000},
  36. @@ -167,6 +169,7 @@ static struct device_info boards[] = {
  37. "CPE520(TP-LINK|US|N300-5):1.1\r\n"
  38. "CPE520(TP-LINK|EU|N300-5):1.1\r\n",
  39. .support_trail = '\xff',
  40. + .soft_ver = NULL,
  41. .partitions = {
  42. {"fs-uboot", 0x00000, 0x20000},
  43. @@ -198,6 +201,7 @@ static struct device_info boards[] = {
  44. "WBS210(TP-LINK|US|N300-2):1.20\r\n"
  45. "WBS210(TP-LINK|EU|N300-2):1.20\r\n",
  46. .support_trail = '\xff',
  47. + .soft_ver = NULL,
  48. .partitions = {
  49. {"fs-uboot", 0x00000, 0x20000},
  50. @@ -229,6 +233,7 @@ static struct device_info boards[] = {
  51. "WBS510(TP-LINK|US|N300-5):1.20\r\n"
  52. "WBS510(TP-LINK|EU|N300-5):1.20\r\n",
  53. .support_trail = '\xff',
  54. + .soft_ver = NULL,
  55. .partitions = {
  56. {"fs-uboot", 0x00000, 0x20000},
  57. @@ -259,6 +264,7 @@ static struct device_info boards[] = {
  58. "SupportList:\r\n"
  59. "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n",
  60. .support_trail = '\x00',
  61. + .soft_ver = NULL,
  62. .partitions = {
  63. {"SBL1", 0x00000, 0x20000},
  64. @@ -345,6 +351,7 @@ static struct device_info boards[] = {
  65. "product_ver:2.0.0,"
  66. "special_id:00000000}\r\n",
  67. .support_trail = '\x00',
  68. + .soft_ver = NULL,
  69. .partitions = {
  70. {"fs-uboot", 0x00000, 0x40000},
  71. @@ -379,6 +386,7 @@ static struct device_info boards[] = {
  72. "product_ver:1.0.0,"
  73. "special_id:00000000}\n",
  74. .support_trail = '\x00',
  75. + .soft_ver = NULL,
  76. .partitions = {
  77. {"fs-uboot", 0x00000, 0x40000},
  78. @@ -411,6 +419,7 @@ static struct device_info boards[] = {
  79. "SupportList:\r\n"
  80. "EAP120(TP-LINK|UN|N300-2):1.0\r\n",
  81. .support_trail = '\xff',
  82. + .soft_ver = NULL,
  83. .partitions = {
  84. {"fs-uboot", 0x00000, 0x20000},
  85. @@ -440,6 +449,7 @@ static struct device_info boards[] = {
  86. "SupportList:\n"
  87. "{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\n",
  88. .support_trail = '\x00',
  89. + .soft_ver = NULL,
  90. /**
  91. We use a bigger os-image partition than the stock images (and thus
  92. @@ -483,6 +493,7 @@ static struct device_info boards[] = {
  93. "{product_name:RE450,product_ver:1.0.0,special_id:4B520000}\r\n"
  94. "{product_name:RE450,product_ver:1.0.0,special_id:55534100}\r\n",
  95. .support_trail = '\x00',
  96. + .soft_ver = NULL,
  97. /**
  98. The flash partition table for RE450;
  99. @@ -611,6 +622,23 @@ static struct image_partition_entry make_soft_version(uint32_t rev) {
  100. return entry;
  101. }
  102. +static struct image_partition_entry make_soft_version_from_string(const char *soft_ver) {
  103. + /** String length _including_ the terminating zero byte */
  104. + uint32_t ver_len = strlen(soft_ver) + 1;
  105. + /** Partition contains 64 bit header, the version string, and one additional null byte */
  106. + size_t partition_len = 2*sizeof(uint32_t) + ver_len + 1;
  107. + struct image_partition_entry entry = alloc_image_partition("soft-version", partition_len);
  108. +
  109. + uint32_t *len = (uint32_t *)entry.data;
  110. + len[0] = htonl(ver_len);
  111. + len[1] = 0;
  112. + memcpy(&len[2], soft_ver, ver_len);
  113. +
  114. + entry.data[partition_len - 1] = 0;
  115. +
  116. + return entry;
  117. +}
  118. +
  119. /** Generates the support-list partition */
  120. static struct image_partition_entry make_support_list(const struct device_info *info) {
  121. size_t len = strlen(info->support_list);
  122. @@ -851,7 +879,11 @@ static void build_image(const char *output,
  123. struct image_partition_entry parts[7] = {};
  124. parts[0] = make_partition_table(info->partitions);
  125. - parts[1] = make_soft_version(rev);
  126. + if (info->soft_ver)
  127. + parts[1] = make_soft_version_from_string(info->soft_ver);
  128. + else
  129. + parts[1] = make_soft_version(rev);
  130. +
  131. parts[2] = make_support_list(info);
  132. parts[3] = read_file("os-image", kernel_image, false);
  133. parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);