0045-tools-firmware-utils-tplink-safeloader-clean-up-code.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Thu, 15 Oct 2015 20:03:51 +0200
  3. Subject: tools/firmware-utils: tplink-safeloader: clean up code
  4. There is no reason for the internal functions not to be static.
  5. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  6. diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
  7. index 9c5bb54..4607a1d 100644
  8. --- a/tools/firmware-utils/src/tplink-safeloader.c
  9. +++ b/tools/firmware-utils/src/tplink-safeloader.c
  10. @@ -152,7 +152,7 @@ static const unsigned char cpe510_support_list[] =
  11. /** Allocates a new image partition */
  12. -struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
  13. +static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
  14. struct image_partition_entry entry = {name, len, malloc(len)};
  15. if (!entry.data)
  16. error(1, errno, "malloc");
  17. @@ -161,12 +161,12 @@ struct image_partition_entry alloc_image_partition(const char *name, size_t len)
  18. }
  19. /** Frees an image partition */
  20. -void free_image_partition(struct image_partition_entry entry) {
  21. +static void free_image_partition(struct image_partition_entry entry) {
  22. free(entry.data);
  23. }
  24. /** Generates the partition-table partition */
  25. -struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
  26. +static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
  27. struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
  28. char *s = (char *)entry.data, *end = (char *)(s+entry.size);
  29. @@ -202,7 +202,7 @@ static inline uint8_t bcd(uint8_t v) {
  30. /** Generates the soft-version partition */
  31. -struct image_partition_entry make_soft_version(uint32_t rev) {
  32. +static struct image_partition_entry make_soft_version(uint32_t rev) {
  33. struct image_partition_entry entry = alloc_image_partition("soft-version", sizeof(struct soft_version));
  34. struct soft_version *s = (struct soft_version *)entry.data;
  35. @@ -233,14 +233,14 @@ struct image_partition_entry make_soft_version(uint32_t rev) {
  36. }
  37. /** Generates the support-list partition */
  38. -struct image_partition_entry make_support_list(const unsigned char *support_list, size_t len) {
  39. +static struct image_partition_entry make_support_list(const unsigned char *support_list, size_t len) {
  40. struct image_partition_entry entry = alloc_image_partition("support-list", len);
  41. memcpy(entry.data, support_list, len);
  42. return entry;
  43. }
  44. /** Creates a new image partition with an arbitrary name from a file */
  45. -struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) {
  46. +static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) {
  47. struct stat statbuf;
  48. if (stat(filename, &statbuf) < 0)
  49. @@ -300,7 +300,7 @@ struct image_partition_entry read_file(const char *part_name, const char *filena
  50. I think partition-table must be the first partition in the firmware image.
  51. */
  52. -void put_partitions(uint8_t *buffer, const struct image_partition_entry *parts) {
  53. +static void put_partitions(uint8_t *buffer, const struct image_partition_entry *parts) {
  54. size_t i;
  55. char *image_pt = (char *)buffer, *end = image_pt + 0x800;
  56. @@ -325,7 +325,7 @@ void put_partitions(uint8_t *buffer, const struct image_partition_entry *parts)
  57. }
  58. /** Generates and writes the image MD5 checksum */
  59. -void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
  60. +static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
  61. MD5_CTX ctx;
  62. MD5_Init(&ctx);
  63. @@ -349,7 +349,7 @@ void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
  64. 1014-1813 Image partition table (2048 bytes, padded with 0xff)
  65. 1814-xxxx Firmware partitions
  66. */
  67. -void * generate_factory_image(const unsigned char *vendor, size_t vendor_len, const struct image_partition_entry *parts, size_t *len) {
  68. +static void * generate_factory_image(const unsigned char *vendor, size_t vendor_len, const struct image_partition_entry *parts, size_t *len) {
  69. *len = 0x1814;
  70. size_t i;
  71. @@ -381,7 +381,7 @@ void * generate_factory_image(const unsigned char *vendor, size_t vendor_len, co
  72. should be generalized when TP-LINK starts building its safeloader into hardware with
  73. different flash layouts.
  74. */
  75. -void * generate_sysupgrade_image(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
  76. +static void * generate_sysupgrade_image(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
  77. const struct flash_partition_entry *flash_os_image = &flash_parts[5];
  78. const struct flash_partition_entry *flash_soft_version = &flash_parts[6];
  79. const struct flash_partition_entry *flash_support_list = &flash_parts[7];
  80. @@ -459,7 +459,7 @@ static void do_cpe510(const char *output, const char *kernel_image, const char *
  81. /** Usage output */
  82. -void usage(const char *argv0) {
  83. +static void usage(const char *argv0) {
  84. fprintf(stderr,
  85. "Usage: %s [OPTIONS...]\n"
  86. "\n"