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
8 + * Normal mappings of chips in physical memory
11 +#include <linux/module.h>
12 +#include <linux/types.h>
13 +#include <linux/kernel.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>
21 +#define WINDOW_ADDR CONFIG_MTD_AR7_START
22 +#define WINDOW_SIZE CONFIG_MTD_AR7_LEN
23 +#define BUSWIDTH CONFIG_MTD_AR7_BUSWIDTH
25 +#include <asm/mips-boards/prom.h>
26 +extern char *prom_getenv(char *name);
28 +static int create_mtd_partitions(void);
29 +static void __exit ar7_mtd_cleanup(void);
31 +#define MAX_NUM_PARTITIONS 5
32 +static struct mtd_partition ar7_partinfo[MAX_NUM_PARTITIONS];
34 +static struct mtd_info *ar7_mtd_info;
36 +__u8 ar7_read8(struct map_info *map, unsigned long ofs)
38 + return __raw_readb(map->map_priv_1 + ofs);
41 +__u16 ar7_read16(struct map_info *map, unsigned long ofs)
43 + return __raw_readw(map->map_priv_1 + ofs);
46 +__u32 ar7_read32(struct map_info *map, unsigned long ofs)
48 + return __raw_readl(map->map_priv_1 + ofs);
51 +void ar7_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
53 + memcpy_fromio(to, map->map_priv_1 + from, len);
56 +void ar7_write8(struct map_info *map, __u8 d, unsigned long adr)
58 + __raw_writeb(d, map->map_priv_1 + adr);
62 +void ar7_write16(struct map_info *map, __u16 d, unsigned long adr)
64 + __raw_writew(d, map->map_priv_1 + adr);
68 +void ar7_write32(struct map_info *map, __u32 d, unsigned long adr)
70 + __raw_writel(d, map->map_priv_1 + adr);
74 +void ar7_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
76 + memcpy_toio(map->map_priv_1 + to, from, len);
79 +struct map_info ar7_map = {
80 + name: "Physically mapped flash",
86 + copy_from: ar7_copy_from,
88 + write16: ar7_write16,
89 + write32: ar7_write32,
90 + copy_to: ar7_copy_to
93 +int __init ar7_mtd_init(void)
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);
100 + if (!ar7_map.map_priv_1) {
101 + printk("Failed to ioremap\n");
105 + ar7_mtd_info = do_map_probe("cfi_probe", &ar7_map);
112 + ar7_mtd_info->module = THIS_MODULE;
114 + if (!(partitions = create_mtd_partitions()))
115 + add_mtd_device(ar7_mtd_info);
117 + add_mtd_partitions(ar7_mtd_info, ar7_partinfo, partitions);
122 +static char *strdup(char *str)
124 + int n = strlen(str)+1;
125 + char *s = kmalloc(n, GFP_KERNEL);
126 + if (!s) return NULL;
127 + return strcpy(s, str);
131 +static int create_mtd_partitions(void)
133 + unsigned int offset;
135 + unsigned int found = 0;
136 + unsigned int p = 0;
137 + unsigned char *flash_base;
138 + unsigned char *flash_end;
142 + unsigned int adam2_size = 0x20000;
143 + unsigned int config_offset = WINDOW_SIZE;
144 + unsigned int rootfs_start = 0xe0000;
146 + printk("Parsing ADAM2 partition map...\n");
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);
155 + env_ptr = prom_getenv(env_name);
156 + if(env_ptr == NULL) {
157 + /* No more partitions to find */
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);
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);
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);
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
193 + } while (p < MAX_NUM_PARTITIONS);
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;
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;
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);
212 + ar7_partinfo[p].name = strdup("rootfs");
213 + ar7_partinfo[p].offset = rootfs_start;
214 + ar7_partinfo[p].size = config_offset - rootfs_start;
216 + ar7_partinfo[p++].mask_flags = 0;
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;
223 + if (ar7_read32(&ar7_map, rootfs_start) == SQUASHFS_MAGIC) {
224 + int newsize, newoffset;
225 + squashfs_super_block sb;
227 + ar7_copy_from(&ar7_map, &sb, rootfs_start, sizeof(sb));
228 + printk("Squashfs detected (size = 0x%08x)\n", sb.bytes_used);
230 + newoffset = rootfs_start + sb.bytes_used;
232 + if ((newoffset % ar7_mtd_info->erasesize) > 0)
233 + newoffset += ar7_mtd_info->erasesize - (newoffset % ar7_mtd_info->erasesize);
235 + ar7_partinfo[p - 2].size = newoffset - rootfs_start;
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;
242 + printk("Unknown filesystem. Moving rootfs partition to next erase block");
243 + if ((rootfs_start % ar7_mtd_info->erasesize) > 0)
244 + rootfs_start += ar7_mtd_info->erasesize - (rootfs_start % ar7_mtd_info->erasesize);
250 +static void __exit ar7_mtd_cleanup(void)
252 + if (ar7_mtd_info) {
253 + del_mtd_partitions(ar7_mtd_info);
254 + del_mtd_device(ar7_mtd_info);
255 + map_destroy(ar7_mtd_info);
258 + if (ar7_map.map_priv_1) {
259 + iounmap((void *)ar7_map.map_priv_1);
260 + ar7_map.map_priv_1 = 0;
264 +module_init(ar7_mtd_init);
265 +module_exit(ar7_mtd_cleanup);
267 +MODULE_LICENSE("GPL");
268 +MODULE_AUTHOR("Felix Fietkau");
269 +MODULE_DESCRIPTION("AR7 CFI map driver");
270 diff -urN linux.old/drivers/mtd/maps/Config.in linux.dev/drivers/mtd/maps/Config.in
271 --- linux.old/drivers/mtd/maps/Config.in 2005-07-21 05:36:32.414242296 +0200
272 +++ linux.dev/drivers/mtd/maps/Config.in 2005-07-21 06:29:04.067118232 +0200
276 if [ "$CONFIG_MIPS" = "y" ]; then
277 + if [ "$CONFIG_AR7" = "y" ]; then
278 + dep_tristate ' Flash chip mapping on Texas Instruments AR7' CONFIG_MTD_AR7 $CONFIG_MTD_CFI $CONFIG_MTD_PARTITIONS
279 + dep_bool ' Use defaults for Texas Instruments AR7' CONFIG_MTD_AR7_DEFAULTS $CONFIG_MTD_AR7
280 + if [ "$CONFIG_MTD_AR7" = "y" -o "$CONFIG_MTD_AR7" = "m" ]; then
281 + if [ "$CONFIG_MTD_AR7_DEFAULTS" = "y" ]; then
282 + define_hex CONFIG_MTD_AR7_START 0x10000000
283 + define_hex CONFIG_MTD_AR7_LEN 0x400000
284 + define_int CONFIG_MTD_AR7_BUSWIDTH 2
286 + hex ' Physical start address of flash mapping' CONFIG_MTD_AR7_START 0x10000000
287 + hex ' Physical length of flash mapping' CONFIG_MTD_AR7_LEN 0x400000
288 + int ' Bus width in octets' CONFIG_MTD_AR7_BUSWIDTH 2
292 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
293 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
294 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
295 diff -urN linux.old/drivers/mtd/maps/Makefile linux.dev/drivers/mtd/maps/Makefile
296 --- linux.old/drivers/mtd/maps/Makefile 2005-07-21 05:36:32.414242296 +0200
297 +++ linux.dev/drivers/mtd/maps/Makefile 2005-07-21 06:56:33.265401984 +0200
302 +obj-$(CONFIG_MTD_AR7) += ar7-flash.o
303 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
304 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
305 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o