0007-MIPS-lantiq-add-basic-tffs-driver.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From d27ec8bb97db0f60d81ab255d51ac4e967362067 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Thu, 7 Aug 2014 18:34:19 +0200
  4. Subject: [PATCH 07/36] MIPS: lantiq: add basic tffs driver
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. arch/mips/lantiq/xway/Makefile | 2 +-
  8. arch/mips/lantiq/xway/tffs.c | 87 ++++++++++++++++++++++++++++++++++++++++
  9. 2 files changed, 88 insertions(+), 1 deletion(-)
  10. create mode 100644 arch/mips/lantiq/xway/tffs.c
  11. --- a/arch/mips/lantiq/xway/Makefile
  12. +++ b/arch/mips/lantiq/xway/Makefile
  13. @@ -1,5 +1,5 @@
  14. obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
  15. -obj-y += vmmc.o
  16. +obj-y += vmmc.o tffs.o
  17. obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
  18. --- /dev/null
  19. +++ b/arch/mips/lantiq/xway/tffs.c
  20. @@ -0,0 +1,87 @@
  21. +#include <linux/module.h>
  22. +#include <linux/mtd/mtd.h>
  23. +#include <linux/errno.h>
  24. +#include <linux/slab.h>
  25. +
  26. +struct tffs_entry {
  27. + uint16_t id;
  28. + uint16_t len;
  29. +};
  30. +
  31. +static struct tffs_id {
  32. + uint32_t id;
  33. + char *name;
  34. + unsigned char *val;
  35. + uint32_t offset;
  36. + uint32_t len;
  37. +} ids[] = {
  38. + { 0x01A9, "annex" },
  39. + { 0x0188, "maca" },
  40. + { 0x0189, "macb" },
  41. + { 0x018a, "macwlan" },
  42. + { 0x0195, "macwlan2" },
  43. + { 0x018b, "macdsl" },
  44. + { 0x01C2, "webgui_pass" },
  45. + { 0x01AB, "wlan_key" },
  46. +};
  47. +
  48. +static struct mtd_info *tffs1, *tffs2;
  49. +
  50. +static struct tffs_id* tffs_find_id(int id)
  51. +{
  52. + int i;
  53. +
  54. + for (i = 0; i < ARRAY_SIZE(ids); i++)
  55. + if (id == ids[i].id)
  56. + return &ids[i];
  57. +
  58. + return NULL;
  59. +}
  60. +
  61. +static void tffs_index(void)
  62. +{
  63. + struct tffs_entry *E = NULL;
  64. + struct tffs_entry entry;
  65. + int ret, retlen;
  66. +
  67. + while ((unsigned int) E + sizeof(struct tffs_entry) < tffs2->size) {
  68. + struct tffs_id *id;
  69. + int len;
  70. +
  71. + ret = mtd_read(tffs2, (unsigned int) E, sizeof(struct tffs_entry), &retlen, (unsigned char *)&entry);
  72. + if (ret)
  73. + return;
  74. +
  75. + if (entry.id == 0xffff)
  76. + return;
  77. +
  78. + id = tffs_find_id(entry.id);
  79. + if (id) {
  80. + id->offset = (uint32_t) E;
  81. + id->len = entry.len;
  82. + id->val = kzalloc(entry.len + 1, GFP_KERNEL);
  83. + mtd_read(tffs2, ((unsigned int) E) + sizeof(struct tffs_entry), entry.len, &retlen, id->val);
  84. +
  85. + }
  86. + //printk(KERN_INFO "found entry at 0x%08X-> [<0x%x> %u bytes]\n", (uint32_t) E, entry.id, entry.len);
  87. + if (id && id->name)
  88. + printk(KERN_INFO "found entry name -> %s=%s\n", id->name, id->val);
  89. +
  90. + len = (entry.len + 3) & ~0x03;
  91. + E = (struct tffs_entry *)(((unsigned int)E) + sizeof(struct tffs_entry) + len);
  92. + }
  93. +}
  94. +
  95. +static int __init tffs_init(void)
  96. +{
  97. + tffs1 = get_mtd_device_nm("tffs (1)");
  98. + tffs2 = get_mtd_device_nm("tffs (2)");
  99. + if (IS_ERR(tffs1) || IS_ERR(tffs2))
  100. + return -1;
  101. +
  102. + tffs_index();
  103. +
  104. + return 0;
  105. +}
  106. +late_initcall(tffs_init);
  107. +