diff options
author | Jesper Nilsson <jesper.nilsson@axis.com> | 2007-11-30 10:01:53 -0500 |
---|---|---|
committer | Jesper Nilsson <jesper.nilsson@axis.com> | 2008-02-08 05:06:25 -0500 |
commit | 5fc1f3122fda1a15df0e4f83d85f4d2991bf0edd (patch) | |
tree | 896fae7f6d43b429a5b1e7eba2a032cdd9e10d70 /arch/cris/arch-v32/drivers/axisflashmap.c | |
parent | 201ca54aa039eb1e5143a98311e7ea25afc57ebb (diff) |
CRIS v32: Update and improve axisflashmap
- Use default partition table when no partition is found (for initial tests)
- Add config ETRAX_AXISFLASHMAP_MTD0WHOLE to allow whole flash as mtd0.
- Add config for VCS simulator connection.
Diffstat (limited to 'arch/cris/arch-v32/drivers/axisflashmap.c')
-rw-r--r-- | arch/cris/arch-v32/drivers/axisflashmap.c | 488 |
1 files changed, 345 insertions, 143 deletions
diff --git a/arch/cris/arch-v32/drivers/axisflashmap.c b/arch/cris/arch-v32/drivers/axisflashmap.c index c5ff95e18269..51e1e85df96d 100644 --- a/arch/cris/arch-v32/drivers/axisflashmap.c +++ b/arch/cris/arch-v32/drivers/axisflashmap.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Physical mapping layer for MTD using the Axis partitiontable format | 2 | * Physical mapping layer for MTD using the Axis partitiontable format |
3 | * | 3 | * |
4 | * Copyright (c) 2001, 2002, 2003 Axis Communications AB | 4 | * Copyright (c) 2001-2007 Axis Communications AB |
5 | * | 5 | * |
6 | * This file is under the GPL. | 6 | * This file is under the GPL. |
7 | * | 7 | * |
@@ -10,9 +10,6 @@ | |||
10 | * tells us what other partitions to define. If there isn't, we use a default | 10 | * tells us what other partitions to define. If there isn't, we use a default |
11 | * partition split defined below. | 11 | * partition split defined below. |
12 | * | 12 | * |
13 | * Copy of os/lx25/arch/cris/arch-v10/drivers/axisflashmap.c 1.5 | ||
14 | * with minor changes. | ||
15 | * | ||
16 | */ | 13 | */ |
17 | 14 | ||
18 | #include <linux/module.h> | 15 | #include <linux/module.h> |
@@ -27,7 +24,8 @@ | |||
27 | #include <linux/mtd/mtdram.h> | 24 | #include <linux/mtd/mtdram.h> |
28 | #include <linux/mtd/partitions.h> | 25 | #include <linux/mtd/partitions.h> |
29 | 26 | ||
30 | #include <asm/arch/hwregs/config_defs.h> | 27 | #include <linux/cramfs_fs.h> |
28 | |||
31 | #include <asm/axisflashmap.h> | 29 | #include <asm/axisflashmap.h> |
32 | #include <asm/mmu.h> | 30 | #include <asm/mmu.h> |
33 | 31 | ||
@@ -37,16 +35,24 @@ | |||
37 | #define FLASH_UNCACHED_ADDR KSEG_E | 35 | #define FLASH_UNCACHED_ADDR KSEG_E |
38 | #define FLASH_CACHED_ADDR KSEG_F | 36 | #define FLASH_CACHED_ADDR KSEG_F |
39 | 37 | ||
38 | #define PAGESIZE (512) | ||
39 | |||
40 | #if CONFIG_ETRAX_FLASH_BUSWIDTH==1 | 40 | #if CONFIG_ETRAX_FLASH_BUSWIDTH==1 |
41 | #define flash_data __u8 | 41 | #define flash_data __u8 |
42 | #elif CONFIG_ETRAX_FLASH_BUSWIDTH==2 | 42 | #elif CONFIG_ETRAX_FLASH_BUSWIDTH==2 |
43 | #define flash_data __u16 | 43 | #define flash_data __u16 |
44 | #elif CONFIG_ETRAX_FLASH_BUSWIDTH==4 | 44 | #elif CONFIG_ETRAX_FLASH_BUSWIDTH==4 |
45 | #define flash_data __u16 | 45 | #define flash_data __u32 |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | /* From head.S */ | 48 | /* From head.S */ |
49 | extern unsigned long romfs_start, romfs_length, romfs_in_flash; | 49 | extern unsigned long romfs_in_flash; /* 1 when romfs_start, _length in flash */ |
50 | extern unsigned long romfs_start, romfs_length; | ||
51 | extern unsigned long nand_boot; /* 1 when booted from nand flash */ | ||
52 | |||
53 | struct partition_name { | ||
54 | char name[6]; | ||
55 | }; | ||
50 | 56 | ||
51 | /* The master mtd for the entire flash. */ | 57 | /* The master mtd for the entire flash. */ |
52 | struct mtd_info* axisflash_mtd = NULL; | 58 | struct mtd_info* axisflash_mtd = NULL; |
@@ -112,32 +118,20 @@ static struct map_info map_cse1 = { | |||
112 | .map_priv_1 = FLASH_UNCACHED_ADDR + MEM_CSE0_SIZE | 118 | .map_priv_1 = FLASH_UNCACHED_ADDR + MEM_CSE0_SIZE |
113 | }; | 119 | }; |
114 | 120 | ||
115 | /* If no partition-table was found, we use this default-set. */ | 121 | #define MAX_PARTITIONS 7 |
116 | #define MAX_PARTITIONS 7 | 122 | #ifdef CONFIG_ETRAX_NANDBOOT |
117 | #define NUM_DEFAULT_PARTITIONS 3 | 123 | #define NUM_DEFAULT_PARTITIONS 4 |
124 | #define DEFAULT_ROOTFS_PARTITION_NO 2 | ||
125 | #define DEFAULT_MEDIA_SIZE 0x2000000 /* 32 megs */ | ||
126 | #else | ||
127 | #define NUM_DEFAULT_PARTITIONS 3 | ||
128 | #define DEFAULT_ROOTFS_PARTITION_NO (-1) | ||
129 | #define DEFAULT_MEDIA_SIZE 0x800000 /* 8 megs */ | ||
130 | #endif | ||
118 | 131 | ||
119 | /* | 132 | #if (MAX_PARTITIONS < NUM_DEFAULT_PARTITIONS) |
120 | * Default flash size is 2MB. CONFIG_ETRAX_PTABLE_SECTOR is most likely the | 133 | #error MAX_PARTITIONS must be >= than NUM_DEFAULT_PARTITIONS |
121 | * size of one flash block and "filesystem"-partition needs 5 blocks to be able | 134 | #endif |
122 | * to use JFFS. | ||
123 | */ | ||
124 | static struct mtd_partition axis_default_partitions[NUM_DEFAULT_PARTITIONS] = { | ||
125 | { | ||
126 | .name = "boot firmware", | ||
127 | .size = CONFIG_ETRAX_PTABLE_SECTOR, | ||
128 | .offset = 0 | ||
129 | }, | ||
130 | { | ||
131 | .name = "kernel", | ||
132 | .size = 0x200000 - (6 * CONFIG_ETRAX_PTABLE_SECTOR), | ||
133 | .offset = CONFIG_ETRAX_PTABLE_SECTOR | ||
134 | }, | ||
135 | { | ||
136 | .name = "filesystem", | ||
137 | .size = 5 * CONFIG_ETRAX_PTABLE_SECTOR, | ||
138 | .offset = 0x200000 - (5 * CONFIG_ETRAX_PTABLE_SECTOR) | ||
139 | } | ||
140 | }; | ||
141 | 135 | ||
142 | /* Initialize the ones normally used. */ | 136 | /* Initialize the ones normally used. */ |
143 | static struct mtd_partition axis_partitions[MAX_PARTITIONS] = { | 137 | static struct mtd_partition axis_partitions[MAX_PARTITIONS] = { |
@@ -178,6 +172,56 @@ static struct mtd_partition axis_partitions[MAX_PARTITIONS] = { | |||
178 | }, | 172 | }, |
179 | }; | 173 | }; |
180 | 174 | ||
175 | |||
176 | /* If no partition-table was found, we use this default-set. | ||
177 | * Default flash size is 8MB (NOR). CONFIG_ETRAX_PTABLE_SECTOR is most | ||
178 | * likely the size of one flash block and "filesystem"-partition needs | ||
179 | * to be >=5 blocks to be able to use JFFS. | ||
180 | */ | ||
181 | static struct mtd_partition axis_default_partitions[NUM_DEFAULT_PARTITIONS] = { | ||
182 | { | ||
183 | .name = "boot firmware", | ||
184 | .size = CONFIG_ETRAX_PTABLE_SECTOR, | ||
185 | .offset = 0 | ||
186 | }, | ||
187 | { | ||
188 | .name = "kernel", | ||
189 | .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR, | ||
190 | .offset = CONFIG_ETRAX_PTABLE_SECTOR | ||
191 | }, | ||
192 | #define FILESYSTEM_SECTOR (11 * CONFIG_ETRAX_PTABLE_SECTOR) | ||
193 | #ifdef CONFIG_ETRAX_NANDBOOT | ||
194 | { | ||
195 | .name = "rootfs", | ||
196 | .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR, | ||
197 | .offset = FILESYSTEM_SECTOR | ||
198 | }, | ||
199 | #undef FILESYSTEM_SECTOR | ||
200 | #define FILESYSTEM_SECTOR (21 * CONFIG_ETRAX_PTABLE_SECTOR) | ||
201 | #endif | ||
202 | { | ||
203 | .name = "rwfs", | ||
204 | .size = DEFAULT_MEDIA_SIZE - FILESYSTEM_SECTOR, | ||
205 | .offset = FILESYSTEM_SECTOR | ||
206 | } | ||
207 | }; | ||
208 | |||
209 | #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE | ||
210 | /* Main flash device */ | ||
211 | static struct mtd_partition main_partition = { | ||
212 | .name = "main", | ||
213 | .size = 0, | ||
214 | .offset = 0 | ||
215 | }; | ||
216 | #endif | ||
217 | |||
218 | /* Auxilliary partition if we find another flash */ | ||
219 | static struct mtd_partition aux_partition = { | ||
220 | .name = "aux", | ||
221 | .size = 0, | ||
222 | .offset = 0 | ||
223 | }; | ||
224 | |||
181 | /* | 225 | /* |
182 | * Probe a chip select for AMD-compatible (JEDEC) or CFI-compatible flash | 226 | * Probe a chip select for AMD-compatible (JEDEC) or CFI-compatible flash |
183 | * chips in that order (because the amd_flash-driver is faster). | 227 | * chips in that order (because the amd_flash-driver is faster). |
@@ -191,7 +235,7 @@ static struct mtd_info *probe_cs(struct map_info *map_cs) | |||
191 | map_cs->name, map_cs->size, map_cs->map_priv_1); | 235 | map_cs->name, map_cs->size, map_cs->map_priv_1); |
192 | 236 | ||
193 | #ifdef CONFIG_MTD_CFI | 237 | #ifdef CONFIG_MTD_CFI |
194 | mtd_cs = do_map_probe("cfi_probe", map_cs); | 238 | mtd_cs = do_map_probe("cfi_probe", map_cs); |
195 | #endif | 239 | #endif |
196 | #ifdef CONFIG_MTD_JEDECPROBE | 240 | #ifdef CONFIG_MTD_JEDECPROBE |
197 | if (!mtd_cs) | 241 | if (!mtd_cs) |
@@ -204,7 +248,7 @@ static struct mtd_info *probe_cs(struct map_info *map_cs) | |||
204 | /* | 248 | /* |
205 | * Probe each chip select individually for flash chips. If there are chips on | 249 | * Probe each chip select individually for flash chips. If there are chips on |
206 | * both cse0 and cse1, the mtd_info structs will be concatenated to one struct | 250 | * both cse0 and cse1, the mtd_info structs will be concatenated to one struct |
207 | * so that MTD partitions can cross chip boundaries. | 251 | * so that MTD partitions can cross chip boundries. |
208 | * | 252 | * |
209 | * The only known restriction to how you can mount your chips is that each | 253 | * The only known restriction to how you can mount your chips is that each |
210 | * chip select must hold similar flash chips. But you need external hardware | 254 | * chip select must hold similar flash chips. But you need external hardware |
@@ -216,9 +260,8 @@ static struct mtd_info *flash_probe(void) | |||
216 | { | 260 | { |
217 | struct mtd_info *mtd_cse0; | 261 | struct mtd_info *mtd_cse0; |
218 | struct mtd_info *mtd_cse1; | 262 | struct mtd_info *mtd_cse1; |
219 | struct mtd_info *mtd_nand = NULL; | ||
220 | struct mtd_info *mtd_total; | 263 | struct mtd_info *mtd_total; |
221 | struct mtd_info *mtds[3]; | 264 | struct mtd_info *mtds[2]; |
222 | int count = 0; | 265 | int count = 0; |
223 | 266 | ||
224 | if ((mtd_cse0 = probe_cs(&map_cse0)) != NULL) | 267 | if ((mtd_cse0 = probe_cs(&map_cse0)) != NULL) |
@@ -226,12 +269,7 @@ static struct mtd_info *flash_probe(void) | |||
226 | if ((mtd_cse1 = probe_cs(&map_cse1)) != NULL) | 269 | if ((mtd_cse1 = probe_cs(&map_cse1)) != NULL) |
227 | mtds[count++] = mtd_cse1; | 270 | mtds[count++] = mtd_cse1; |
228 | 271 | ||
229 | #ifdef CONFIG_ETRAX_NANDFLASH | 272 | if (!mtd_cse0 && !mtd_cse1) { |
230 | if ((mtd_nand = crisv32_nand_flash_probe()) != NULL) | ||
231 | mtds[count++] = mtd_nand; | ||
232 | #endif | ||
233 | |||
234 | if (!mtd_cse0 && !mtd_cse1 && !mtd_nand) { | ||
235 | /* No chip found. */ | 273 | /* No chip found. */ |
236 | return NULL; | 274 | return NULL; |
237 | } | 275 | } |
@@ -245,9 +283,7 @@ static struct mtd_info *flash_probe(void) | |||
245 | * So we use the MTD concatenation layer instead of further | 283 | * So we use the MTD concatenation layer instead of further |
246 | * complicating the probing procedure. | 284 | * complicating the probing procedure. |
247 | */ | 285 | */ |
248 | mtd_total = mtd_concat_create(mtds, | 286 | mtd_total = mtd_concat_create(mtds, count, "cse0+cse1"); |
249 | count, | ||
250 | "cse0+cse1+nand"); | ||
251 | #else | 287 | #else |
252 | printk(KERN_ERR "%s and %s: Cannot concatenate due to kernel " | 288 | printk(KERN_ERR "%s and %s: Cannot concatenate due to kernel " |
253 | "(mis)configuration!\n", map_cse0.name, map_cse1.name); | 289 | "(mis)configuration!\n", map_cse0.name, map_cse1.name); |
@@ -255,61 +291,162 @@ static struct mtd_info *flash_probe(void) | |||
255 | #endif | 291 | #endif |
256 | if (!mtd_total) { | 292 | if (!mtd_total) { |
257 | printk(KERN_ERR "%s and %s: Concatenation failed!\n", | 293 | printk(KERN_ERR "%s and %s: Concatenation failed!\n", |
258 | map_cse0.name, map_cse1.name); | 294 | map_cse0.name, map_cse1.name); |
259 | 295 | ||
260 | /* The best we can do now is to only use what we found | 296 | /* The best we can do now is to only use what we found |
261 | * at cse0. | 297 | * at cse0. */ |
262 | */ | ||
263 | mtd_total = mtd_cse0; | 298 | mtd_total = mtd_cse0; |
264 | map_destroy(mtd_cse1); | 299 | map_destroy(mtd_cse1); |
265 | } | 300 | } |
266 | } else { | 301 | } else |
267 | mtd_total = mtd_cse0? mtd_cse0 : mtd_cse1 ? mtd_cse1 : mtd_nand; | 302 | mtd_total = mtd_cse0 ? mtd_cse0 : mtd_cse1; |
268 | |||
269 | } | ||
270 | 303 | ||
271 | return mtd_total; | 304 | return mtd_total; |
272 | } | 305 | } |
273 | 306 | ||
274 | extern unsigned long crisv32_nand_boot; | ||
275 | extern unsigned long crisv32_nand_cramfs_offset; | ||
276 | |||
277 | /* | 307 | /* |
278 | * Probe the flash chip(s) and, if it succeeds, read the partition-table | 308 | * Probe the flash chip(s) and, if it succeeds, read the partition-table |
279 | * and register the partitions with MTD. | 309 | * and register the partitions with MTD. |
280 | */ | 310 | */ |
281 | static int __init init_axis_flash(void) | 311 | static int __init init_axis_flash(void) |
282 | { | 312 | { |
283 | struct mtd_info *mymtd; | 313 | struct mtd_info *main_mtd; |
314 | struct mtd_info *aux_mtd = NULL; | ||
284 | int err = 0; | 315 | int err = 0; |
285 | int pidx = 0; | 316 | int pidx = 0; |
286 | struct partitiontable_head *ptable_head = NULL; | 317 | struct partitiontable_head *ptable_head = NULL; |
287 | struct partitiontable_entry *ptable; | 318 | struct partitiontable_entry *ptable; |
288 | int use_default_ptable = 1; /* Until proven otherwise. */ | 319 | int ptable_ok = 0; |
289 | const char *pmsg = KERN_INFO " /dev/flash%d at 0x%08x, size 0x%08x\n"; | 320 | static char page[PAGESIZE]; |
290 | static char page[512]; | ||
291 | size_t len; | 321 | size_t len; |
322 | int ram_rootfs_partition = -1; /* -1 => no RAM rootfs partition */ | ||
323 | int part; | ||
324 | |||
325 | /* We need a root fs. If it resides in RAM, we need to use an | ||
326 | * MTDRAM device, so it must be enabled in the kernel config, | ||
327 | * but its size must be configured as 0 so as not to conflict | ||
328 | * with our usage. | ||
329 | */ | ||
330 | #if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0) | ||
331 | if (!romfs_in_flash && !nand_boot) { | ||
332 | printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM " | ||
333 | "device; configure CONFIG_MTD_MTDRAM with size = 0!\n"); | ||
334 | panic("This kernel cannot boot from RAM!\n"); | ||
335 | } | ||
336 | #endif | ||
337 | |||
338 | #ifndef CONFIG_ETRAX_VCS_SIM | ||
339 | main_mtd = flash_probe(); | ||
340 | if (main_mtd) | ||
341 | printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n", | ||
342 | main_mtd->name, main_mtd->size); | ||
343 | |||
344 | #ifdef CONFIG_ETRAX_NANDFLASH | ||
345 | aux_mtd = crisv32_nand_flash_probe(); | ||
346 | if (aux_mtd) | ||
347 | printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n", | ||
348 | aux_mtd->name, aux_mtd->size); | ||
349 | |||
350 | #ifdef CONFIG_ETRAX_NANDBOOT | ||
351 | { | ||
352 | struct mtd_info *tmp_mtd; | ||
292 | 353 | ||
293 | #ifndef CONFIG_ETRAXFS_SIM | 354 | printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, " |
294 | mymtd = flash_probe(); | 355 | "making NAND flash primary device.\n"); |
295 | mymtd->read(mymtd, CONFIG_ETRAX_PTABLE_SECTOR, 512, &len, page); | 356 | tmp_mtd = main_mtd; |
296 | ptable_head = (struct partitiontable_head *)(page + PARTITION_TABLE_OFFSET); | 357 | main_mtd = aux_mtd; |
358 | aux_mtd = tmp_mtd; | ||
359 | } | ||
360 | #endif /* CONFIG_ETRAX_NANDBOOT */ | ||
361 | #endif /* CONFIG_ETRAX_NANDFLASH */ | ||
297 | 362 | ||
298 | if (!mymtd) { | 363 | if (!main_mtd && !aux_mtd) { |
299 | /* There's no reason to use this module if no flash chip can | 364 | /* There's no reason to use this module if no flash chip can |
300 | * be identified. Make sure that's understood. | 365 | * be identified. Make sure that's understood. |
301 | */ | 366 | */ |
302 | printk(KERN_INFO "axisflashmap: Found no flash chip.\n"); | 367 | printk(KERN_INFO "axisflashmap: Found no flash chip.\n"); |
303 | } else { | ||
304 | printk(KERN_INFO "%s: 0x%08x bytes of flash memory.\n", | ||
305 | mymtd->name, mymtd->size); | ||
306 | axisflash_mtd = mymtd; | ||
307 | } | 368 | } |
308 | 369 | ||
309 | if (mymtd) { | 370 | #if 0 /* Dump flash memory so we can see what is going on */ |
310 | mymtd->owner = THIS_MODULE; | 371 | if (main_mtd) { |
372 | int sectoraddr, i; | ||
373 | for (sectoraddr = 0; sectoraddr < 2*65536+4096; | ||
374 | sectoraddr += PAGESIZE) { | ||
375 | main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len, | ||
376 | page); | ||
377 | printk(KERN_INFO | ||
378 | "Sector at %d (length %d):\n", | ||
379 | sectoraddr, len); | ||
380 | for (i = 0; i < PAGESIZE; i += 16) { | ||
381 | printk(KERN_INFO | ||
382 | "%02x %02x %02x %02x " | ||
383 | "%02x %02x %02x %02x " | ||
384 | "%02x %02x %02x %02x " | ||
385 | "%02x %02x %02x %02x\n", | ||
386 | page[i] & 255, page[i+1] & 255, | ||
387 | page[i+2] & 255, page[i+3] & 255, | ||
388 | page[i+4] & 255, page[i+5] & 255, | ||
389 | page[i+6] & 255, page[i+7] & 255, | ||
390 | page[i+8] & 255, page[i+9] & 255, | ||
391 | page[i+10] & 255, page[i+11] & 255, | ||
392 | page[i+12] & 255, page[i+13] & 255, | ||
393 | page[i+14] & 255, page[i+15] & 255); | ||
394 | } | ||
395 | } | ||
396 | } | ||
397 | #endif | ||
398 | |||
399 | if (main_mtd) { | ||
400 | main_mtd->owner = THIS_MODULE; | ||
401 | axisflash_mtd = main_mtd; | ||
402 | |||
403 | loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR; | ||
404 | |||
405 | /* First partition (rescue) is always set to the default. */ | ||
406 | pidx++; | ||
407 | #ifdef CONFIG_ETRAX_NANDBOOT | ||
408 | /* We know where the partition table should be located, | ||
409 | * it will be in first good block after that. | ||
410 | */ | ||
411 | int blockstat; | ||
412 | do { | ||
413 | blockstat = main_mtd->block_isbad(main_mtd, | ||
414 | ptable_sector); | ||
415 | if (blockstat < 0) | ||
416 | ptable_sector = 0; /* read error */ | ||
417 | else if (blockstat) | ||
418 | ptable_sector += main_mtd->erasesize; | ||
419 | } while (blockstat && ptable_sector); | ||
420 | #endif | ||
421 | if (ptable_sector) { | ||
422 | main_mtd->read(main_mtd, ptable_sector, PAGESIZE, | ||
423 | &len, page); | ||
424 | ptable_head = &((struct partitiontable *) page)->head; | ||
425 | } | ||
426 | |||
427 | #if 0 /* Dump partition table so we can see what is going on */ | ||
428 | printk(KERN_INFO | ||
429 | "axisflashmap: flash read %d bytes at 0x%08x, data: " | ||
430 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", | ||
431 | len, CONFIG_ETRAX_PTABLE_SECTOR, | ||
432 | page[0] & 255, page[1] & 255, | ||
433 | page[2] & 255, page[3] & 255, | ||
434 | page[4] & 255, page[5] & 255, | ||
435 | page[6] & 255, page[7] & 255); | ||
436 | printk(KERN_INFO | ||
437 | "axisflashmap: partition table offset %d, data: " | ||
438 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", | ||
439 | PARTITION_TABLE_OFFSET, | ||
440 | page[PARTITION_TABLE_OFFSET+0] & 255, | ||
441 | page[PARTITION_TABLE_OFFSET+1] & 255, | ||
442 | page[PARTITION_TABLE_OFFSET+2] & 255, | ||
443 | page[PARTITION_TABLE_OFFSET+3] & 255, | ||
444 | page[PARTITION_TABLE_OFFSET+4] & 255, | ||
445 | page[PARTITION_TABLE_OFFSET+5] & 255, | ||
446 | page[PARTITION_TABLE_OFFSET+6] & 255, | ||
447 | page[PARTITION_TABLE_OFFSET+7] & 255); | ||
448 | #endif | ||
311 | } | 449 | } |
312 | pidx++; /* First partition is always set to the default. */ | ||
313 | 450 | ||
314 | if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC) | 451 | if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC) |
315 | && (ptable_head->size < | 452 | && (ptable_head->size < |
@@ -322,7 +459,6 @@ static int __init init_axis_flash(void) | |||
322 | /* Looks like a start, sane length and end of a | 459 | /* Looks like a start, sane length and end of a |
323 | * partition table, lets check csum etc. | 460 | * partition table, lets check csum etc. |
324 | */ | 461 | */ |
325 | int ptable_ok = 0; | ||
326 | struct partitiontable_entry *max_addr = | 462 | struct partitiontable_entry *max_addr = |
327 | (struct partitiontable_entry *) | 463 | (struct partitiontable_entry *) |
328 | ((unsigned long)ptable_head + sizeof(*ptable_head) + | 464 | ((unsigned long)ptable_head + sizeof(*ptable_head) + |
@@ -346,104 +482,170 @@ static int __init init_axis_flash(void) | |||
346 | ptable_ok = (csum == ptable_head->checksum); | 482 | ptable_ok = (csum == ptable_head->checksum); |
347 | 483 | ||
348 | /* Read the entries and use/show the info. */ | 484 | /* Read the entries and use/show the info. */ |
349 | printk(KERN_INFO " Found a%s partition table at 0x%p-0x%p.\n", | 485 | printk(KERN_INFO "axisflashmap: " |
486 | "Found a%s partition table at 0x%p-0x%p.\n", | ||
350 | (ptable_ok ? " valid" : "n invalid"), ptable_head, | 487 | (ptable_ok ? " valid" : "n invalid"), ptable_head, |
351 | max_addr); | 488 | max_addr); |
352 | 489 | ||
353 | /* We have found a working bootblock. Now read the | 490 | /* We have found a working bootblock. Now read the |
354 | * partition table. Scan the table. It ends when | 491 | * partition table. Scan the table. It ends with 0xffffffff. |
355 | * there is 0xffffffff, that is, empty flash. | ||
356 | */ | 492 | */ |
357 | while (ptable_ok | 493 | while (ptable_ok |
358 | && ptable->offset != 0xffffffff | 494 | && ptable->offset != PARTITIONTABLE_END_MARKER |
359 | && ptable < max_addr | 495 | && ptable < max_addr |
360 | && pidx < MAX_PARTITIONS) { | 496 | && pidx < MAX_PARTITIONS - 1) { |
361 | 497 | ||
362 | axis_partitions[pidx].offset = offset + ptable->offset + (crisv32_nand_boot ? 16384 : 0); | 498 | axis_partitions[pidx].offset = offset + ptable->offset; |
363 | axis_partitions[pidx].size = ptable->size; | 499 | #ifdef CONFIG_ETRAX_NANDFLASH |
364 | 500 | if (main_mtd->type == MTD_NANDFLASH) { | |
365 | printk(pmsg, pidx, axis_partitions[pidx].offset, | 501 | axis_partitions[pidx].size = |
366 | axis_partitions[pidx].size); | 502 | (((ptable+1)->offset == |
503 | PARTITIONTABLE_END_MARKER) ? | ||
504 | main_mtd->size : | ||
505 | ((ptable+1)->offset + offset)) - | ||
506 | (ptable->offset + offset); | ||
507 | |||
508 | } else | ||
509 | #endif /* CONFIG_ETRAX_NANDFLASH */ | ||
510 | axis_partitions[pidx].size = ptable->size; | ||
511 | #ifdef CONFIG_ETRAX_NANDBOOT | ||
512 | /* Save partition number of jffs2 ro partition. | ||
513 | * Needed if RAM booting or root file system in RAM. | ||
514 | */ | ||
515 | if (!nand_boot && | ||
516 | ram_rootfs_partition < 0 && /* not already set */ | ||
517 | ptable->type == PARTITION_TYPE_JFFS2 && | ||
518 | (ptable->flags & PARTITION_FLAGS_READONLY_MASK) == | ||
519 | PARTITION_FLAGS_READONLY) | ||
520 | ram_rootfs_partition = pidx; | ||
521 | #endif /* CONFIG_ETRAX_NANDBOOT */ | ||
367 | pidx++; | 522 | pidx++; |
368 | ptable++; | 523 | ptable++; |
369 | } | 524 | } |
370 | use_default_ptable = !ptable_ok; | ||
371 | } | 525 | } |
372 | 526 | ||
373 | if (romfs_in_flash) { | 527 | /* Decide whether to use default partition table. */ |
374 | /* Add an overlapping device for the root partition (romfs). */ | 528 | /* Only use default table if we actually have a device (main_mtd) */ |
375 | 529 | ||
376 | axis_partitions[pidx].name = "romfs"; | 530 | struct mtd_partition *partition = &axis_partitions[0]; |
377 | if (crisv32_nand_boot) { | 531 | if (main_mtd && !ptable_ok) { |
378 | char* data = kmalloc(1024, GFP_KERNEL); | 532 | memcpy(axis_partitions, axis_default_partitions, |
379 | int len; | 533 | sizeof(axis_default_partitions)); |
380 | int offset = crisv32_nand_cramfs_offset & ~(1024-1); | 534 | pidx = NUM_DEFAULT_PARTITIONS; |
381 | char* tmp; | 535 | ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO; |
382 | 536 | } | |
383 | mymtd->read(mymtd, offset, 1024, &len, data); | ||
384 | tmp = &data[crisv32_nand_cramfs_offset % 512]; | ||
385 | axis_partitions[pidx].size = *(unsigned*)(tmp + 4); | ||
386 | axis_partitions[pidx].offset = crisv32_nand_cramfs_offset; | ||
387 | kfree(data); | ||
388 | } else { | ||
389 | axis_partitions[pidx].size = romfs_length; | ||
390 | axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR; | ||
391 | } | ||
392 | 537 | ||
538 | /* Add artificial partitions for rootfs if necessary */ | ||
539 | if (romfs_in_flash) { | ||
540 | /* rootfs is in directly accessible flash memory = NOR flash. | ||
541 | Add an overlapping device for the rootfs partition. */ | ||
542 | printk(KERN_INFO "axisflashmap: Adding partition for " | ||
543 | "overlapping root file system image\n"); | ||
544 | axis_partitions[pidx].size = romfs_length; | ||
545 | axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR; | ||
546 | axis_partitions[pidx].name = "romfs"; | ||
393 | axis_partitions[pidx].mask_flags |= MTD_WRITEABLE; | 547 | axis_partitions[pidx].mask_flags |= MTD_WRITEABLE; |
394 | 548 | ram_rootfs_partition = -1; | |
395 | printk(KERN_INFO | ||
396 | " Adding readonly flash partition for romfs image:\n"); | ||
397 | printk(pmsg, pidx, axis_partitions[pidx].offset, | ||
398 | axis_partitions[pidx].size); | ||
399 | pidx++; | 549 | pidx++; |
400 | } | 550 | } else if (romfs_length && !nand_boot) { |
401 | 551 | /* romfs exists in memory, but not in flash, so must be in RAM. | |
402 | if (mymtd) { | 552 | * Configure an MTDRAM partition. */ |
403 | if (use_default_ptable) { | 553 | if (ram_rootfs_partition < 0) { |
404 | printk(KERN_INFO " Using default partition table.\n"); | 554 | /* None set yet, put it at the end */ |
405 | err = add_mtd_partitions(mymtd, axis_default_partitions, | 555 | ram_rootfs_partition = pidx; |
406 | NUM_DEFAULT_PARTITIONS); | 556 | pidx++; |
407 | } else { | ||
408 | err = add_mtd_partitions(mymtd, axis_partitions, pidx); | ||
409 | } | 557 | } |
558 | printk(KERN_INFO "axisflashmap: Adding partition for " | ||
559 | "root file system image in RAM\n"); | ||
560 | axis_partitions[ram_rootfs_partition].size = romfs_length; | ||
561 | axis_partitions[ram_rootfs_partition].offset = romfs_start; | ||
562 | axis_partitions[ram_rootfs_partition].name = "romfs"; | ||
563 | axis_partitions[ram_rootfs_partition].mask_flags |= | ||
564 | MTD_WRITEABLE; | ||
565 | } | ||
410 | 566 | ||
411 | if (err) { | 567 | #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE |
412 | panic("axisflashmap could not add MTD partitions!\n"); | 568 | if (main_mtd) { |
413 | } | 569 | main_partition.size = main_mtd->size; |
570 | err = add_mtd_partitions(main_mtd, &main_partition, 1); | ||
571 | if (err) | ||
572 | panic("axisflashmap: Could not initialize " | ||
573 | "partition for whole main mtd device!\n"); | ||
414 | } | 574 | } |
415 | /* CONFIG_EXTRAXFS_SIM */ | ||
416 | #endif | 575 | #endif |
417 | 576 | ||
418 | if (!romfs_in_flash) { | 577 | /* Now, register all partitions with mtd. |
419 | /* Create an RAM device for the root partition (romfs). */ | 578 | * We do this one at a time so we can slip in an MTDRAM device |
579 | * in the proper place if required. */ | ||
580 | |||
581 | for (part = 0; part < pidx; part++) { | ||
582 | if (part == ram_rootfs_partition) { | ||
583 | /* add MTDRAM partition here */ | ||
584 | struct mtd_info *mtd_ram; | ||
585 | |||
586 | mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); | ||
587 | if (!mtd_ram) | ||
588 | panic("axisflashmap: Couldn't allocate memory " | ||
589 | "for mtd_info!\n"); | ||
590 | printk(KERN_INFO "axisflashmap: Adding RAM partition " | ||
591 | "for rootfs image.\n"); | ||
592 | err = mtdram_init_device(mtd_ram, | ||
593 | (void *)partition[part].offset, | ||
594 | partition[part].size, | ||
595 | partition[part].name); | ||
596 | if (err) | ||
597 | panic("axisflashmap: Could not initialize " | ||
598 | "MTD RAM device!\n"); | ||
599 | /* JFFS2 likes to have an erasesize. Keep potential | ||
600 | * JFFS2 rootfs happy by providing one. Since image | ||
601 | * was most likely created for main mtd, use that | ||
602 | * erasesize, if available. Otherwise, make a guess. */ | ||
603 | mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize : | ||
604 | CONFIG_ETRAX_PTABLE_SECTOR); | ||
605 | } else { | ||
606 | err = add_mtd_partitions(main_mtd, &partition[part], 1); | ||
607 | if (err) | ||
608 | panic("axisflashmap: Could not add mtd " | ||
609 | "partition %d\n", part); | ||
610 | } | ||
611 | } | ||
612 | #endif /* CONFIG_EXTRAX_VCS_SIM */ | ||
613 | |||
614 | #ifdef CONFIG_ETRAX_VCS_SIM | ||
615 | /* For simulator, always use a RAM partition. | ||
616 | * The rootfs will be found after the kernel in RAM, | ||
617 | * with romfs_start and romfs_end indicating location and size. | ||
618 | */ | ||
619 | struct mtd_info *mtd_ram; | ||
620 | |||
621 | mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); | ||
622 | if (!mtd_ram) { | ||
623 | panic("axisflashmap: Couldn't allocate memory for " | ||
624 | "mtd_info!\n"); | ||
625 | } | ||
420 | 626 | ||
421 | #if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0) | 627 | printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, " |
422 | /* No use trying to boot this kernel from RAM. Panic! */ | 628 | "at %u, size %u\n", |
423 | printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM " | 629 | (unsigned) romfs_start, (unsigned) romfs_length); |
424 | "device due to kernel (mis)configuration!\n"); | ||
425 | panic("This kernel cannot boot from RAM!\n"); | ||
426 | #else | ||
427 | struct mtd_info *mtd_ram; | ||
428 | 630 | ||
429 | mtd_ram = kmalloc(sizeof(struct mtd_info), | 631 | err = mtdram_init_device(mtd_ram, (void *)romfs_start, |
430 | GFP_KERNEL); | 632 | romfs_length, "romfs"); |
431 | if (!mtd_ram) { | 633 | if (err) { |
432 | panic("axisflashmap couldn't allocate memory for " | 634 | panic("axisflashmap: Could not initialize MTD RAM " |
433 | "mtd_info!\n"); | 635 | "device!\n"); |
434 | } | 636 | } |
637 | #endif /* CONFIG_EXTRAX_VCS_SIM */ | ||
435 | 638 | ||
436 | printk(KERN_INFO " Adding RAM partition for romfs image:\n"); | 639 | #ifndef CONFIG_ETRAX_VCS_SIM |
437 | printk(pmsg, pidx, romfs_start, romfs_length); | 640 | if (aux_mtd) { |
641 | aux_partition.size = aux_mtd->size; | ||
642 | err = add_mtd_partitions(aux_mtd, &aux_partition, 1); | ||
643 | if (err) | ||
644 | panic("axisflashmap: Could not initialize " | ||
645 | "aux mtd device!\n"); | ||
438 | 646 | ||
439 | err = mtdram_init_device(mtd_ram, (void*)romfs_start, | ||
440 | romfs_length, "romfs"); | ||
441 | if (err) { | ||
442 | panic("axisflashmap could not initialize MTD RAM " | ||
443 | "device!\n"); | ||
444 | } | ||
445 | #endif | ||
446 | } | 647 | } |
648 | #endif /* CONFIG_EXTRAX_VCS_SIM */ | ||
447 | 649 | ||
448 | return err; | 650 | return err; |
449 | } | 651 | } |