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