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