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