reorganize nat helper packages, move ftp and irc nat to a package that is enabled...
[openwrt.git] / target / linux / ar7-2.4 / patches / 001-flash_map.patch
1 diff -urN linux.old/drivers/mtd/maps/ar7-flash.c linux.dev/drivers/mtd/maps/ar7-flash.c
2 --- linux.old/drivers/mtd/maps/ar7-flash.c      1970-01-01 01:00:00.000000000 +0100
3 +++ linux.dev/drivers/mtd/maps/ar7-flash.c      2005-07-22 04:35:26.624453992 +0200
4 @@ -0,0 +1,267 @@
5 +/*
6 + * $Id$
7 + *
8 + * Normal mappings of chips in physical memory
9 + */
10 +
11 +#include <linux/module.h>
12 +#include <linux/types.h>
13 +#include <linux/kernel.h>
14 +#include <asm/io.h>
15 +#include <linux/mtd/mtd.h>
16 +#include <linux/mtd/map.h>
17 +#include <linux/config.h>
18 +#include <linux/mtd/partitions.h>
19 +#include <linux/squashfs_fs.h>
20 +
21 +#define WINDOW_ADDR CONFIG_MTD_AR7_START
22 +#define WINDOW_SIZE CONFIG_MTD_AR7_LEN
23 +#define BUSWIDTH CONFIG_MTD_AR7_BUSWIDTH
24 +
25 +#include <asm/mips-boards/prom.h>
26 +extern char *prom_getenv(char *name);
27 +
28 +static int create_mtd_partitions(void);
29 +static void __exit ar7_mtd_cleanup(void);
30 +       
31 +#define MAX_NUM_PARTITIONS 5
32 +static struct mtd_partition ar7_partinfo[MAX_NUM_PARTITIONS];
33 +
34 +static struct mtd_info *ar7_mtd_info;
35 +
36 +__u8 ar7_read8(struct map_info *map, unsigned long ofs)
37 +{
38 +       return __raw_readb(map->map_priv_1 + ofs);
39 +}
40 +
41 +__u16 ar7_read16(struct map_info *map, unsigned long ofs)
42 +{
43 +       return __raw_readw(map->map_priv_1 + ofs);
44 +}
45 +
46 +__u32 ar7_read32(struct map_info *map, unsigned long ofs)
47 +{
48 +       return __raw_readl(map->map_priv_1 + ofs);
49 +}
50 +
51 +void ar7_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
52 +{
53 +       memcpy_fromio(to, map->map_priv_1 + from, len);
54 +}
55 +
56 +void ar7_write8(struct map_info *map, __u8 d, unsigned long adr)
57 +{
58 +       __raw_writeb(d, map->map_priv_1 + adr);
59 +       mb();
60 +}
61 +
62 +void ar7_write16(struct map_info *map, __u16 d, unsigned long adr)
63 +{
64 +       __raw_writew(d, map->map_priv_1 + adr);
65 +       mb();
66 +}
67 +
68 +void ar7_write32(struct map_info *map, __u32 d, unsigned long adr)
69 +{
70 +       __raw_writel(d, map->map_priv_1 + adr);
71 +       mb();
72 +}
73 +
74 +void ar7_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
75 +{
76 +       memcpy_toio(map->map_priv_1 + to, from, len);
77 +}
78 +
79 +struct map_info ar7_map = {
80 +       name: "Physically mapped flash",
81 +       size: WINDOW_SIZE,
82 +       buswidth: BUSWIDTH,
83 +       read8: ar7_read8,
84 +       read16: ar7_read16,
85 +       read32: ar7_read32,
86 +       copy_from: ar7_copy_from,
87 +       write8: ar7_write8,
88 +       write16: ar7_write16,
89 +       write32: ar7_write32,
90 +       copy_to: ar7_copy_to
91 +};
92 +
93 +int __init ar7_mtd_init(void)
94 +{
95 +       int partitions;
96 +       
97 +               printk(KERN_NOTICE "ar7 flash device: 0x%lx at 0x%lx.\n", (unsigned long)WINDOW_SIZE, (unsigned long)WINDOW_ADDR);
98 +       ar7_map.map_priv_1 = (unsigned long)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
99 +
100 +       if (!ar7_map.map_priv_1) {
101 +               printk("Failed to ioremap\n");
102 +               return -EIO;
103 +       }
104 +       
105 +       ar7_mtd_info = do_map_probe("cfi_probe", &ar7_map);
106 +       if (!ar7_mtd_info)
107 +       {
108 +               ar7_mtd_cleanup();
109 +               return -ENXIO;
110 +       }
111 +       
112 +       ar7_mtd_info->module = THIS_MODULE;
113 +
114 +       if (!(partitions = create_mtd_partitions()))
115 +               add_mtd_device(ar7_mtd_info);
116 +       else            
117 +               add_mtd_partitions(ar7_mtd_info, ar7_partinfo, partitions);
118 +
119 +       return 0;
120 +}
121 +
122 +static char *strdup(char *str)
123 +{
124 +       int n = strlen(str)+1;
125 +       char *s = kmalloc(n, GFP_KERNEL);
126 +       if (!s) return NULL;
127 +       return strcpy(s, str);
128 +}
129 +
130 +
131 +static int create_mtd_partitions(void)
132 +{
133 +       unsigned int offset;
134 +       unsigned int size;
135 +       unsigned int found = 0;
136 +       unsigned int p = 0;
137 +       unsigned char *flash_base;
138 +       unsigned char *flash_end;
139 +       char *env_ptr;
140 +       char *base_ptr;
141 +       char *end_ptr;
142 +       unsigned int adam2_size = 0x20000;
143 +       unsigned int config_offset = WINDOW_SIZE;
144 +       unsigned int rootfs_start = 0xe0000;
145 +
146 +       printk("Parsing ADAM2 partition map...\n");
147 +       
148 +       do {
149 +               char    env_name[20];
150 +
151 +               /* get base and end addresses of flash file system from environment */
152 +               sprintf(env_name, "mtd%1u", p);
153 +               printk("Looking for mtd device :%s:\n", env_name);
154 +
155 +               env_ptr = prom_getenv(env_name);
156 +               if(env_ptr == NULL) {
157 +                       /* No more partitions to find */
158 +                       break;
159 +               }
160 +
161 +               /* Extract the start and stop addresses of the partition */
162 +               base_ptr = strtok(env_ptr, ",");
163 +               end_ptr = strtok(NULL, ",");
164 +               if ((base_ptr == NULL) || (end_ptr == NULL)) {  
165 +                       printk("ADAM2 partition error: Invalid %s start,end.\n", env_name);
166 +                       break;
167 +               }
168 +
169 +               flash_base = (unsigned char*) simple_strtol(base_ptr, NULL, 0);
170 +               flash_end = (unsigned char*) simple_strtol(end_ptr, NULL, 0);
171 +               if((!flash_base) || (!flash_end)) {
172 +                       printk("ADAM2 partition error: Invalid %s start,end.\n", env_name);
173 +                       break;
174 +               }
175 +
176 +               offset = virt_to_bus(flash_base) - WINDOW_ADDR;
177 +               size = flash_end - flash_base;
178 +               printk("Found a %s image (0x%x), with size (0x%x).\n",env_name, offset, size);
179 +
180 +               
181 +               if (offset == 0) {
182 +                       printk("Assuming adam2 size of 0x%x\n", size);
183 +                       adam2_size = size;                      // boot loader
184 +               } else if (offset > 0x120000) {
185 +                       if (config_offset > offset)
186 +                               config_offset = offset;         // reserved at the end of the flash chip
187 +               } else if (offset > 0x30000) {
188 +                       printk("Assuming default rootfs offset of 0x%x\n", offset);
189 +                       rootfs_start = offset;                  // probably root fs
190 +               }
191 +               
192 +               p++;
193 +       } while (p < MAX_NUM_PARTITIONS);
194 +       
195 +       p = 0;
196 +       
197 +       ar7_partinfo[p].name = strdup("adam2");
198 +       ar7_partinfo[p].offset = 0;
199 +       ar7_partinfo[p].size = adam2_size;
200 +       ar7_partinfo[p++].mask_flags = 0;
201 +
202 +       ar7_partinfo[p].name = strdup("linux");
203 +       ar7_partinfo[p].offset = adam2_size;
204 +       ar7_partinfo[p].size = config_offset - adam2_size;
205 +       ar7_partinfo[p++].mask_flags = 0;
206 +
207 +       if (ar7_read32(&ar7_map, adam2_size) == 0xfeedfa42) {
208 +               rootfs_start = ar7_read32(&ar7_map, adam2_size + 4) + adam2_size + 28;
209 +               printk("Setting new rootfs offset to %08x\n", rootfs_start);
210 +       }
211 +       
212 +       ar7_partinfo[p].name = strdup("rootfs");
213 +       ar7_partinfo[p].offset = rootfs_start;
214 +       ar7_partinfo[p].size = config_offset - rootfs_start;
215 +       
216 +       ar7_partinfo[p++].mask_flags = 0;
217 +
218 +       ar7_partinfo[p].name = strdup("config");
219 +       ar7_partinfo[p].offset = config_offset;
220 +       ar7_partinfo[p].size = WINDOW_SIZE - config_offset;
221 +       ar7_partinfo[p++].mask_flags = 0;
222 +
223 +       if (ar7_read32(&ar7_map, rootfs_start) == SQUASHFS_MAGIC) {
224 +               int newsize, newoffset;
225 +               struct squashfs_super_block sb;
226 +
227 +               ar7_copy_from(&ar7_map, &sb, rootfs_start, sizeof(sb));
228 +               printk("Squashfs detected (size = 0x%08x)\n", sb.bytes_used);
229 +               
230 +               newoffset = rootfs_start + sb.bytes_used;
231 +
232 +               if ((newoffset % ar7_mtd_info->erasesize) > 0)
233 +                       newoffset += ar7_mtd_info->erasesize - (newoffset % ar7_mtd_info->erasesize);
234 +               
235 +               ar7_partinfo[p - 2].size = newoffset - rootfs_start;
236 +               
237 +               ar7_partinfo[p].name = strdup("OpenWrt");
238 +               ar7_partinfo[p].offset = newoffset;
239 +               ar7_partinfo[p].size = config_offset - newoffset;
240 +               ar7_partinfo[p++].mask_flags = 0;
241 +       } else {
242 +               printk("Unknown filesystem. Moving rootfs partition to next erase block");
243 +               if ((rootfs_start % ar7_mtd_info->erasesize) > 0) {
244 +                       ar7_partinfo[p - 2].offset += ar7_mtd_info->erasesize - (rootfs_start % ar7_mtd_info->erasesize);
245 +                       ar7_partinfo[p - 2].size -= ar7_mtd_info->erasesize - (rootfs_start % ar7_mtd_info->erasesize);
246 +               }
247 +       }
248 +
249 +       return p;
250 +}
251 +
252 +static void __exit ar7_mtd_cleanup(void)
253 +{
254 +       if (ar7_mtd_info) {
255 +               del_mtd_partitions(ar7_mtd_info);
256 +               del_mtd_device(ar7_mtd_info);
257 +               map_destroy(ar7_mtd_info);
258 +       }
259 +
260 +       if (ar7_map.map_priv_1) {
261 +               iounmap((void *)ar7_map.map_priv_1);
262 +               ar7_map.map_priv_1 = 0;
263 +       }
264 +}
265 +
266 +module_init(ar7_mtd_init);
267 +module_exit(ar7_mtd_cleanup);
268 +
269 +MODULE_LICENSE("GPL");
270 +MODULE_AUTHOR("Felix Fietkau");
271 +MODULE_DESCRIPTION("AR7 CFI map driver");
272 diff -urN linux.old/drivers/mtd/maps/Config.in linux.dev/drivers/mtd/maps/Config.in
273 --- linux.old/drivers/mtd/maps/Config.in        2005-07-21 05:36:32.414242296 +0200
274 +++ linux.dev/drivers/mtd/maps/Config.in        2005-07-21 06:29:04.067118232 +0200
275 @@ -48,6 +48,21 @@
276  fi
277  
278  if [ "$CONFIG_MIPS" = "y" ]; then
279 +    if [ "$CONFIG_AR7" = "y" ]; then
280 +      dep_tristate '  Flash chip mapping on Texas Instruments AR7' CONFIG_MTD_AR7 $CONFIG_MTD_CFI $CONFIG_MTD_PARTITIONS
281 +      dep_bool     '    Use defaults for Texas Instruments AR7' CONFIG_MTD_AR7_DEFAULTS $CONFIG_MTD_AR7
282 +      if [ "$CONFIG_MTD_AR7" = "y" -o "$CONFIG_MTD_AR7" = "m" ]; then
283 +         if [ "$CONFIG_MTD_AR7_DEFAULTS" = "y" ]; then
284 +            define_hex CONFIG_MTD_AR7_START 0x10000000
285 +            define_hex CONFIG_MTD_AR7_LEN 0x400000
286 +            define_int CONFIG_MTD_AR7_BUSWIDTH 2
287 +         else
288 +            hex '      Physical start address of flash mapping' CONFIG_MTD_AR7_START 0x10000000
289 +            hex '      Physical length of flash mapping' CONFIG_MTD_AR7_LEN 0x400000
290 +            int '      Bus width in octets' CONFIG_MTD_AR7_BUSWIDTH 2
291 +         fi
292 +      fi
293 +   fi
294     dep_tristate '  Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
295     dep_tristate '  Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
296     dep_tristate '  Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
297 diff -urN linux.old/drivers/mtd/maps/Makefile linux.dev/drivers/mtd/maps/Makefile
298 --- linux.old/drivers/mtd/maps/Makefile 2005-07-21 05:36:32.414242296 +0200
299 +++ linux.dev/drivers/mtd/maps/Makefile 2005-07-21 06:56:33.265401984 +0200
300 @@ -10,6 +10,7 @@
301  endif
302  
303  # Chip mappings
304 +obj-$(CONFIG_MTD_AR7)          += ar7-flash.o
305  obj-$(CONFIG_MTD_CDB89712)     += cdb89712.o
306  obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
307  obj-$(CONFIG_MTD_CFI_FLAGADM)  += cfi_flagadm.o