15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #include <linux/slab.h>
27 #include <linux/cramfs_fs.h>
32 #define MEM_CSE0_SIZE (0x04000000)
33 #define MEM_CSE1_SIZE (0x04000000)
35 #define FLASH_UNCACHED_ADDR KSEG_E
36 #define FLASH_CACHED_ADDR KSEG_F
38 #define PAGESIZE (512)
40 #if CONFIG_ETRAX_FLASH_BUSWIDTH==1
41 #define flash_data __u8
42 #elif CONFIG_ETRAX_FLASH_BUSWIDTH==2
43 #define flash_data __u16
44 #elif CONFIG_ETRAX_FLASH_BUSWIDTH==4
45 #define flash_data __u32
69 static void flash_copy_from(
struct map_info *
map,
void *to,
77 *(flash_data *)(map->
map_priv_1 + adr) = (flash_data)d.
x[0];
98 .bankwidth = CONFIG_ETRAX_FLASH_BUSWIDTH,
100 .copy_from = flash_copy_from,
114 .bankwidth = CONFIG_ETRAX_FLASH_BUSWIDTH,
116 .copy_from = flash_copy_from,
121 #define MAX_PARTITIONS 7
122 #ifdef CONFIG_ETRAX_NANDBOOT
123 #define NUM_DEFAULT_PARTITIONS 4
124 #define DEFAULT_ROOTFS_PARTITION_NO 2
125 #define DEFAULT_MEDIA_SIZE 0x2000000
127 #define NUM_DEFAULT_PARTITIONS 3
128 #define DEFAULT_ROOTFS_PARTITION_NO (-1)
129 #define DEFAULT_MEDIA_SIZE 0x800000
132 #if (MAX_PARTITIONS < NUM_DEFAULT_PARTITIONS)
133 #error MAX_PARTITIONS must be >= than NUM_DEFAULT_PARTITIONS
140 .size = CONFIG_ETRAX_PTABLE_SECTOR,
183 .name =
"boot firmware",
184 .size = CONFIG_ETRAX_PTABLE_SECTOR,
189 .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR,
190 .offset = CONFIG_ETRAX_PTABLE_SECTOR
192 #define FILESYSTEM_SECTOR (11 * CONFIG_ETRAX_PTABLE_SECTOR)
193 #ifdef CONFIG_ETRAX_NANDBOOT
196 .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR,
199 #undef FILESYSTEM_SECTOR
200 #define FILESYSTEM_SECTOR (21 * CONFIG_ETRAX_PTABLE_SECTOR)
205 .offset = FILESYSTEM_SECTOR
209 #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
234 "%s: Probing a 0x%08lx bytes large window at 0x%08lx.\n",
237 #ifdef CONFIG_MTD_CFI
240 #ifdef CONFIG_MTD_JEDECPROBE
259 static struct mtd_info *flash_probe(
void)
267 if ((mtd_cse0 = probe_cs(&map_cse0)) !=
NULL)
268 mtds[count++] = mtd_cse0;
269 if ((mtd_cse1 = probe_cs(&map_cse1)) !=
NULL)
270 mtds[count++] = mtd_cse1;
272 if (!mtd_cse0 && !mtd_cse1) {
292 mtd_total = mtd_cse0;
296 mtd_total = mtd_cse0 ? mtd_cse0 : mtd_cse1;
305 static int __init init_axis_flash(
void)
316 int ram_rootfs_partition = -1;
324 #if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
325 if (!romfs_in_flash && !nand_boot) {
327 "device; configure CONFIG_MTD_MTDRAM with size = 0!\n");
328 panic(
"This kernel cannot boot from RAM!\n");
332 main_mtd = flash_probe();
337 #ifdef CONFIG_ETRAX_NANDFLASH
343 #ifdef CONFIG_ETRAX_NANDBOOT
348 "making NAND flash primary device.\n");
356 if (!main_mtd && !aux_mtd) {
366 for (sectoraddr = 0; sectoraddr < 2*65536+4096;
368 main_mtd->read(main_mtd, sectoraddr,
PAGESIZE, &len,
371 "Sector at %d (length %d):\n",
373 for (i = 0; i <
PAGESIZE; i += 16) {
375 "%02x %02x %02x %02x "
376 "%02x %02x %02x %02x "
377 "%02x %02x %02x %02x "
378 "%02x %02x %02x %02x\n",
379 page[i] & 255, page[i+1] & 255,
380 page[i+2] & 255, page[i+3] & 255,
381 page[i+4] & 255, page[i+5] & 255,
382 page[i+6] & 255, page[i+7] & 255,
383 page[i+8] & 255, page[i+9] & 255,
384 page[i+10] & 255, page[i+11] & 255,
385 page[i+12] & 255, page[i+13] & 255,
386 page[i+14] & 255, page[i+15] & 255);
394 axisflash_mtd = main_mtd;
396 loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;
400 #ifdef CONFIG_ETRAX_NANDBOOT
411 }
while (blockstat && ptable_sector);
421 "axisflashmap: flash read %d bytes at 0x%08x, data: "
422 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
423 len, CONFIG_ETRAX_PTABLE_SECTOR,
424 page[0] & 255, page[1] & 255,
425 page[2] & 255, page[3] & 255,
426 page[4] & 255, page[5] & 255,
427 page[6] & 255, page[7] & 255);
429 "axisflashmap: partition table offset %d, data: "
430 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
444 && (ptable_head->
size <
447 && (*(
unsigned long*)((
void*)ptable_head +
sizeof(*ptable_head) +
456 ((
unsigned long)ptable_head +
sizeof(*ptable_head) +
458 unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
460 unsigned long csum = 0;
463 ((
unsigned long)ptable_head +
sizeof(*ptable_head));
466 p = (
unsigned char*) ptable;
468 while (p <= (
unsigned char*)max_addr) {
474 ptable_ok = (csum == ptable_head->
checksum);
478 "Found a%s partition table at 0x%p-0x%p.\n",
479 (ptable_ok ?
" valid" :
"n invalid"), ptable_head,
491 #ifdef CONFIG_ETRAX_NANDFLASH
493 axis_partitions[pidx].
size =
494 (((ptable+1)->offset ==
497 ((ptable+1)->offset + offset)) -
498 (ptable->
offset + offset);
502 axis_partitions[pidx].
size = ptable->
size;
503 #ifdef CONFIG_ETRAX_NANDBOOT
508 ram_rootfs_partition < 0 &&
512 ram_rootfs_partition = pidx;
523 if (main_mtd && !ptable_ok) {
524 memcpy(axis_partitions, axis_default_partitions,
525 sizeof(axis_default_partitions));
531 if (romfs_in_flash) {
535 "overlapping root file system image\n");
538 axis_partitions[pidx].
name =
"romfs";
540 ram_rootfs_partition = -1;
542 }
else if (romfs_length && !nand_boot) {
545 if (ram_rootfs_partition < 0) {
547 ram_rootfs_partition = pidx;
551 "root file system image in RAM\n");
554 axis_partitions[ram_rootfs_partition].
name =
"romfs";
555 axis_partitions[ram_rootfs_partition].
mask_flags |=
559 #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
561 main_partition.
size = main_mtd->
size;
564 panic(
"axisflashmap: Could not initialize "
565 "partition for whole main mtd device!\n");
573 for (part = 0; part < pidx; part++) {
574 if (part == ram_rootfs_partition) {
580 panic(
"axisflashmap: Couldn't allocate memory "
583 "for rootfs image.\n");
585 (
void *)partition[part].offset,
586 partition[part].
size,
587 partition[part].
name);
589 panic(
"axisflashmap: Could not initialize "
590 "MTD RAM device!\n");
596 CONFIG_ETRAX_PTABLE_SECTOR);
601 panic(
"axisflashmap: Could not add mtd "
602 "partition %d\n", part);
610 panic(
"axisflashmap: Could not initialize "
611 "aux mtd device!\n");