PageRenderTime 1232ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/cris/arch-v32/drivers/axisflashmap.c

https://github.com/ab3416/linux-2.6
C | 651 lines | 464 code | 70 blank | 117 comment | 67 complexity | e06a4af3ad5e6c54840a0fab406f920f MD5 | raw file
  1. /*
  2. * Physical mapping layer for MTD using the Axis partitiontable format
  3. *
  4. * Copyright (c) 2001-2007 Axis Communications AB
  5. *
  6. * This file is under the GPL.
  7. *
  8. * First partition is always sector 0 regardless of if we find a partitiontable
  9. * or not. In the start of the next sector, there can be a partitiontable that
  10. * tells us what other partitions to define. If there isn't, we use a default
  11. * partition split defined below.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/mtd/concat.h>
  20. #include <linux/mtd/map.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/mtdram.h>
  23. #include <linux/mtd/partitions.h>
  24. #include <linux/cramfs_fs.h>
  25. #include <asm/axisflashmap.h>
  26. #include <asm/mmu.h>
  27. #define MEM_CSE0_SIZE (0x04000000)
  28. #define MEM_CSE1_SIZE (0x04000000)
  29. #define FLASH_UNCACHED_ADDR KSEG_E
  30. #define FLASH_CACHED_ADDR KSEG_F
  31. #define PAGESIZE (512)
  32. #if CONFIG_ETRAX_FLASH_BUSWIDTH==1
  33. #define flash_data __u8
  34. #elif CONFIG_ETRAX_FLASH_BUSWIDTH==2
  35. #define flash_data __u16
  36. #elif CONFIG_ETRAX_FLASH_BUSWIDTH==4
  37. #define flash_data __u32
  38. #endif
  39. /* From head.S */
  40. extern unsigned long romfs_in_flash; /* 1 when romfs_start, _length in flash */
  41. extern unsigned long romfs_start, romfs_length;
  42. extern unsigned long nand_boot; /* 1 when booted from nand flash */
  43. struct partition_name {
  44. char name[6];
  45. };
  46. /* The master mtd for the entire flash. */
  47. struct mtd_info* axisflash_mtd = NULL;
  48. /* Map driver functions. */
  49. static map_word flash_read(struct map_info *map, unsigned long ofs)
  50. {
  51. map_word tmp;
  52. tmp.x[0] = *(flash_data *)(map->map_priv_1 + ofs);
  53. return tmp;
  54. }
  55. static void flash_copy_from(struct map_info *map, void *to,
  56. unsigned long from, ssize_t len)
  57. {
  58. memcpy(to, (void *)(map->map_priv_1 + from), len);
  59. }
  60. static void flash_write(struct map_info *map, map_word d, unsigned long adr)
  61. {
  62. *(flash_data *)(map->map_priv_1 + adr) = (flash_data)d.x[0];
  63. }
  64. /*
  65. * The map for chip select e0.
  66. *
  67. * We run into tricky coherence situations if we mix cached with uncached
  68. * accesses to we only use the uncached version here.
  69. *
  70. * The size field is the total size where the flash chips may be mapped on the
  71. * chip select. MTD probes should find all devices there and it does not matter
  72. * if there are unmapped gaps or aliases (mirrors of flash devices). The MTD
  73. * probes will ignore them.
  74. *
  75. * The start address in map_priv_1 is in virtual memory so we cannot use
  76. * MEM_CSE0_START but must rely on that FLASH_UNCACHED_ADDR is the start
  77. * address of cse0.
  78. */
  79. static struct map_info map_cse0 = {
  80. .name = "cse0",
  81. .size = MEM_CSE0_SIZE,
  82. .bankwidth = CONFIG_ETRAX_FLASH_BUSWIDTH,
  83. .read = flash_read,
  84. .copy_from = flash_copy_from,
  85. .write = flash_write,
  86. .map_priv_1 = FLASH_UNCACHED_ADDR
  87. };
  88. /*
  89. * The map for chip select e1.
  90. *
  91. * If there was a gap between cse0 and cse1, map_priv_1 would get the wrong
  92. * address, but there isn't.
  93. */
  94. static struct map_info map_cse1 = {
  95. .name = "cse1",
  96. .size = MEM_CSE1_SIZE,
  97. .bankwidth = CONFIG_ETRAX_FLASH_BUSWIDTH,
  98. .read = flash_read,
  99. .copy_from = flash_copy_from,
  100. .write = flash_write,
  101. .map_priv_1 = FLASH_UNCACHED_ADDR + MEM_CSE0_SIZE
  102. };
  103. #define MAX_PARTITIONS 7
  104. #ifdef CONFIG_ETRAX_NANDBOOT
  105. #define NUM_DEFAULT_PARTITIONS 4
  106. #define DEFAULT_ROOTFS_PARTITION_NO 2
  107. #define DEFAULT_MEDIA_SIZE 0x2000000 /* 32 megs */
  108. #else
  109. #define NUM_DEFAULT_PARTITIONS 3
  110. #define DEFAULT_ROOTFS_PARTITION_NO (-1)
  111. #define DEFAULT_MEDIA_SIZE 0x800000 /* 8 megs */
  112. #endif
  113. #if (MAX_PARTITIONS < NUM_DEFAULT_PARTITIONS)
  114. #error MAX_PARTITIONS must be >= than NUM_DEFAULT_PARTITIONS
  115. #endif
  116. /* Initialize the ones normally used. */
  117. static struct mtd_partition axis_partitions[MAX_PARTITIONS] = {
  118. {
  119. .name = "part0",
  120. .size = CONFIG_ETRAX_PTABLE_SECTOR,
  121. .offset = 0
  122. },
  123. {
  124. .name = "part1",
  125. .size = 0,
  126. .offset = 0
  127. },
  128. {
  129. .name = "part2",
  130. .size = 0,
  131. .offset = 0
  132. },
  133. {
  134. .name = "part3",
  135. .size = 0,
  136. .offset = 0
  137. },
  138. {
  139. .name = "part4",
  140. .size = 0,
  141. .offset = 0
  142. },
  143. {
  144. .name = "part5",
  145. .size = 0,
  146. .offset = 0
  147. },
  148. {
  149. .name = "part6",
  150. .size = 0,
  151. .offset = 0
  152. },
  153. };
  154. /* If no partition-table was found, we use this default-set.
  155. * Default flash size is 8MB (NOR). CONFIG_ETRAX_PTABLE_SECTOR is most
  156. * likely the size of one flash block and "filesystem"-partition needs
  157. * to be >=5 blocks to be able to use JFFS.
  158. */
  159. static struct mtd_partition axis_default_partitions[NUM_DEFAULT_PARTITIONS] = {
  160. {
  161. .name = "boot firmware",
  162. .size = CONFIG_ETRAX_PTABLE_SECTOR,
  163. .offset = 0
  164. },
  165. {
  166. .name = "kernel",
  167. .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR,
  168. .offset = CONFIG_ETRAX_PTABLE_SECTOR
  169. },
  170. #define FILESYSTEM_SECTOR (11 * CONFIG_ETRAX_PTABLE_SECTOR)
  171. #ifdef CONFIG_ETRAX_NANDBOOT
  172. {
  173. .name = "rootfs",
  174. .size = 10 * CONFIG_ETRAX_PTABLE_SECTOR,
  175. .offset = FILESYSTEM_SECTOR
  176. },
  177. #undef FILESYSTEM_SECTOR
  178. #define FILESYSTEM_SECTOR (21 * CONFIG_ETRAX_PTABLE_SECTOR)
  179. #endif
  180. {
  181. .name = "rwfs",
  182. .size = DEFAULT_MEDIA_SIZE - FILESYSTEM_SECTOR,
  183. .offset = FILESYSTEM_SECTOR
  184. }
  185. };
  186. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  187. /* Main flash device */
  188. static struct mtd_partition main_partition = {
  189. .name = "main",
  190. .size = 0,
  191. .offset = 0
  192. };
  193. #endif
  194. /* Auxiliary partition if we find another flash */
  195. static struct mtd_partition aux_partition = {
  196. .name = "aux",
  197. .size = 0,
  198. .offset = 0
  199. };
  200. /*
  201. * Probe a chip select for AMD-compatible (JEDEC) or CFI-compatible flash
  202. * chips in that order (because the amd_flash-driver is faster).
  203. */
  204. static struct mtd_info *probe_cs(struct map_info *map_cs)
  205. {
  206. struct mtd_info *mtd_cs = NULL;
  207. printk(KERN_INFO
  208. "%s: Probing a 0x%08lx bytes large window at 0x%08lx.\n",
  209. map_cs->name, map_cs->size, map_cs->map_priv_1);
  210. #ifdef CONFIG_MTD_CFI
  211. mtd_cs = do_map_probe("cfi_probe", map_cs);
  212. #endif
  213. #ifdef CONFIG_MTD_JEDECPROBE
  214. if (!mtd_cs)
  215. mtd_cs = do_map_probe("jedec_probe", map_cs);
  216. #endif
  217. return mtd_cs;
  218. }
  219. /*
  220. * Probe each chip select individually for flash chips. If there are chips on
  221. * both cse0 and cse1, the mtd_info structs will be concatenated to one struct
  222. * so that MTD partitions can cross chip boundries.
  223. *
  224. * The only known restriction to how you can mount your chips is that each
  225. * chip select must hold similar flash chips. But you need external hardware
  226. * to do that anyway and you can put totally different chips on cse0 and cse1
  227. * so it isn't really much of a restriction.
  228. */
  229. extern struct mtd_info* __init crisv32_nand_flash_probe (void);
  230. static struct mtd_info *flash_probe(void)
  231. {
  232. struct mtd_info *mtd_cse0;
  233. struct mtd_info *mtd_cse1;
  234. struct mtd_info *mtd_total;
  235. struct mtd_info *mtds[2];
  236. int count = 0;
  237. if ((mtd_cse0 = probe_cs(&map_cse0)) != NULL)
  238. mtds[count++] = mtd_cse0;
  239. if ((mtd_cse1 = probe_cs(&map_cse1)) != NULL)
  240. mtds[count++] = mtd_cse1;
  241. if (!mtd_cse0 && !mtd_cse1) {
  242. /* No chip found. */
  243. return NULL;
  244. }
  245. if (count > 1) {
  246. /* Since the concatenation layer adds a small overhead we
  247. * could try to figure out if the chips in cse0 and cse1 are
  248. * identical and reprobe the whole cse0+cse1 window. But since
  249. * flash chips are slow, the overhead is relatively small.
  250. * So we use the MTD concatenation layer instead of further
  251. * complicating the probing procedure.
  252. */
  253. mtd_total = mtd_concat_create(mtds, count, "cse0+cse1");
  254. if (!mtd_total) {
  255. printk(KERN_ERR "%s and %s: Concatenation failed!\n",
  256. map_cse0.name, map_cse1.name);
  257. /* The best we can do now is to only use what we found
  258. * at cse0. */
  259. mtd_total = mtd_cse0;
  260. map_destroy(mtd_cse1);
  261. }
  262. } else
  263. mtd_total = mtd_cse0 ? mtd_cse0 : mtd_cse1;
  264. return mtd_total;
  265. }
  266. /*
  267. * Probe the flash chip(s) and, if it succeeds, read the partition-table
  268. * and register the partitions with MTD.
  269. */
  270. static int __init init_axis_flash(void)
  271. {
  272. struct mtd_info *main_mtd;
  273. struct mtd_info *aux_mtd = NULL;
  274. int err = 0;
  275. int pidx = 0;
  276. struct partitiontable_head *ptable_head = NULL;
  277. struct partitiontable_entry *ptable;
  278. int ptable_ok = 0;
  279. static char page[PAGESIZE];
  280. size_t len;
  281. int ram_rootfs_partition = -1; /* -1 => no RAM rootfs partition */
  282. int part;
  283. /* We need a root fs. If it resides in RAM, we need to use an
  284. * MTDRAM device, so it must be enabled in the kernel config,
  285. * but its size must be configured as 0 so as not to conflict
  286. * with our usage.
  287. */
  288. #if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
  289. if (!romfs_in_flash && !nand_boot) {
  290. printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
  291. "device; configure CONFIG_MTD_MTDRAM with size = 0!\n");
  292. panic("This kernel cannot boot from RAM!\n");
  293. }
  294. #endif
  295. #ifndef CONFIG_ETRAX_VCS_SIM
  296. main_mtd = flash_probe();
  297. if (main_mtd)
  298. printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n",
  299. main_mtd->name, main_mtd->size);
  300. #ifdef CONFIG_ETRAX_NANDFLASH
  301. aux_mtd = crisv32_nand_flash_probe();
  302. if (aux_mtd)
  303. printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n",
  304. aux_mtd->name, aux_mtd->size);
  305. #ifdef CONFIG_ETRAX_NANDBOOT
  306. {
  307. struct mtd_info *tmp_mtd;
  308. printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, "
  309. "making NAND flash primary device.\n");
  310. tmp_mtd = main_mtd;
  311. main_mtd = aux_mtd;
  312. aux_mtd = tmp_mtd;
  313. }
  314. #endif /* CONFIG_ETRAX_NANDBOOT */
  315. #endif /* CONFIG_ETRAX_NANDFLASH */
  316. if (!main_mtd && !aux_mtd) {
  317. /* There's no reason to use this module if no flash chip can
  318. * be identified. Make sure that's understood.
  319. */
  320. printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
  321. }
  322. #if 0 /* Dump flash memory so we can see what is going on */
  323. if (main_mtd) {
  324. int sectoraddr, i;
  325. for (sectoraddr = 0; sectoraddr < 2*65536+4096;
  326. sectoraddr += PAGESIZE) {
  327. main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len,
  328. page);
  329. printk(KERN_INFO
  330. "Sector at %d (length %d):\n",
  331. sectoraddr, len);
  332. for (i = 0; i < PAGESIZE; i += 16) {
  333. printk(KERN_INFO
  334. "%02x %02x %02x %02x "
  335. "%02x %02x %02x %02x "
  336. "%02x %02x %02x %02x "
  337. "%02x %02x %02x %02x\n",
  338. page[i] & 255, page[i+1] & 255,
  339. page[i+2] & 255, page[i+3] & 255,
  340. page[i+4] & 255, page[i+5] & 255,
  341. page[i+6] & 255, page[i+7] & 255,
  342. page[i+8] & 255, page[i+9] & 255,
  343. page[i+10] & 255, page[i+11] & 255,
  344. page[i+12] & 255, page[i+13] & 255,
  345. page[i+14] & 255, page[i+15] & 255);
  346. }
  347. }
  348. }
  349. #endif
  350. if (main_mtd) {
  351. main_mtd->owner = THIS_MODULE;
  352. axisflash_mtd = main_mtd;
  353. loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;
  354. /* First partition (rescue) is always set to the default. */
  355. pidx++;
  356. #ifdef CONFIG_ETRAX_NANDBOOT
  357. /* We know where the partition table should be located,
  358. * it will be in first good block after that.
  359. */
  360. int blockstat;
  361. do {
  362. blockstat = main_mtd->block_isbad(main_mtd,
  363. ptable_sector);
  364. if (blockstat < 0)
  365. ptable_sector = 0; /* read error */
  366. else if (blockstat)
  367. ptable_sector += main_mtd->erasesize;
  368. } while (blockstat && ptable_sector);
  369. #endif
  370. if (ptable_sector) {
  371. main_mtd->read(main_mtd, ptable_sector, PAGESIZE,
  372. &len, page);
  373. ptable_head = &((struct partitiontable *) page)->head;
  374. }
  375. #if 0 /* Dump partition table so we can see what is going on */
  376. printk(KERN_INFO
  377. "axisflashmap: flash read %d bytes at 0x%08x, data: "
  378. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  379. len, CONFIG_ETRAX_PTABLE_SECTOR,
  380. page[0] & 255, page[1] & 255,
  381. page[2] & 255, page[3] & 255,
  382. page[4] & 255, page[5] & 255,
  383. page[6] & 255, page[7] & 255);
  384. printk(KERN_INFO
  385. "axisflashmap: partition table offset %d, data: "
  386. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  387. PARTITION_TABLE_OFFSET,
  388. page[PARTITION_TABLE_OFFSET+0] & 255,
  389. page[PARTITION_TABLE_OFFSET+1] & 255,
  390. page[PARTITION_TABLE_OFFSET+2] & 255,
  391. page[PARTITION_TABLE_OFFSET+3] & 255,
  392. page[PARTITION_TABLE_OFFSET+4] & 255,
  393. page[PARTITION_TABLE_OFFSET+5] & 255,
  394. page[PARTITION_TABLE_OFFSET+6] & 255,
  395. page[PARTITION_TABLE_OFFSET+7] & 255);
  396. #endif
  397. }
  398. if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
  399. && (ptable_head->size <
  400. (MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
  401. PARTITIONTABLE_END_MARKER_SIZE))
  402. && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
  403. ptable_head->size -
  404. PARTITIONTABLE_END_MARKER_SIZE)
  405. == PARTITIONTABLE_END_MARKER)) {
  406. /* Looks like a start, sane length and end of a
  407. * partition table, lets check csum etc.
  408. */
  409. struct partitiontable_entry *max_addr =
  410. (struct partitiontable_entry *)
  411. ((unsigned long)ptable_head + sizeof(*ptable_head) +
  412. ptable_head->size);
  413. unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
  414. unsigned char *p;
  415. unsigned long csum = 0;
  416. ptable = (struct partitiontable_entry *)
  417. ((unsigned long)ptable_head + sizeof(*ptable_head));
  418. /* Lets be PARANOID, and check the checksum. */
  419. p = (unsigned char*) ptable;
  420. while (p <= (unsigned char*)max_addr) {
  421. csum += *p++;
  422. csum += *p++;
  423. csum += *p++;
  424. csum += *p++;
  425. }
  426. ptable_ok = (csum == ptable_head->checksum);
  427. /* Read the entries and use/show the info. */
  428. printk(KERN_INFO "axisflashmap: "
  429. "Found a%s partition table at 0x%p-0x%p.\n",
  430. (ptable_ok ? " valid" : "n invalid"), ptable_head,
  431. max_addr);
  432. /* We have found a working bootblock. Now read the
  433. * partition table. Scan the table. It ends with 0xffffffff.
  434. */
  435. while (ptable_ok
  436. && ptable->offset != PARTITIONTABLE_END_MARKER
  437. && ptable < max_addr
  438. && pidx < MAX_PARTITIONS - 1) {
  439. axis_partitions[pidx].offset = offset + ptable->offset;
  440. #ifdef CONFIG_ETRAX_NANDFLASH
  441. if (main_mtd->type == MTD_NANDFLASH) {
  442. axis_partitions[pidx].size =
  443. (((ptable+1)->offset ==
  444. PARTITIONTABLE_END_MARKER) ?
  445. main_mtd->size :
  446. ((ptable+1)->offset + offset)) -
  447. (ptable->offset + offset);
  448. } else
  449. #endif /* CONFIG_ETRAX_NANDFLASH */
  450. axis_partitions[pidx].size = ptable->size;
  451. #ifdef CONFIG_ETRAX_NANDBOOT
  452. /* Save partition number of jffs2 ro partition.
  453. * Needed if RAM booting or root file system in RAM.
  454. */
  455. if (!nand_boot &&
  456. ram_rootfs_partition < 0 && /* not already set */
  457. ptable->type == PARTITION_TYPE_JFFS2 &&
  458. (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
  459. PARTITION_FLAGS_READONLY)
  460. ram_rootfs_partition = pidx;
  461. #endif /* CONFIG_ETRAX_NANDBOOT */
  462. pidx++;
  463. ptable++;
  464. }
  465. }
  466. /* Decide whether to use default partition table. */
  467. /* Only use default table if we actually have a device (main_mtd) */
  468. struct mtd_partition *partition = &axis_partitions[0];
  469. if (main_mtd && !ptable_ok) {
  470. memcpy(axis_partitions, axis_default_partitions,
  471. sizeof(axis_default_partitions));
  472. pidx = NUM_DEFAULT_PARTITIONS;
  473. ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
  474. }
  475. /* Add artificial partitions for rootfs if necessary */
  476. if (romfs_in_flash) {
  477. /* rootfs is in directly accessible flash memory = NOR flash.
  478. Add an overlapping device for the rootfs partition. */
  479. printk(KERN_INFO "axisflashmap: Adding partition for "
  480. "overlapping root file system image\n");
  481. axis_partitions[pidx].size = romfs_length;
  482. axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
  483. axis_partitions[pidx].name = "romfs";
  484. axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
  485. ram_rootfs_partition = -1;
  486. pidx++;
  487. } else if (romfs_length && !nand_boot) {
  488. /* romfs exists in memory, but not in flash, so must be in RAM.
  489. * Configure an MTDRAM partition. */
  490. if (ram_rootfs_partition < 0) {
  491. /* None set yet, put it at the end */
  492. ram_rootfs_partition = pidx;
  493. pidx++;
  494. }
  495. printk(KERN_INFO "axisflashmap: Adding partition for "
  496. "root file system image in RAM\n");
  497. axis_partitions[ram_rootfs_partition].size = romfs_length;
  498. axis_partitions[ram_rootfs_partition].offset = romfs_start;
  499. axis_partitions[ram_rootfs_partition].name = "romfs";
  500. axis_partitions[ram_rootfs_partition].mask_flags |=
  501. MTD_WRITEABLE;
  502. }
  503. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  504. if (main_mtd) {
  505. main_partition.size = main_mtd->size;
  506. err = mtd_device_register(main_mtd, &main_partition, 1);
  507. if (err)
  508. panic("axisflashmap: Could not initialize "
  509. "partition for whole main mtd device!\n");
  510. }
  511. #endif
  512. /* Now, register all partitions with mtd.
  513. * We do this one at a time so we can slip in an MTDRAM device
  514. * in the proper place if required. */
  515. for (part = 0; part < pidx; part++) {
  516. if (part == ram_rootfs_partition) {
  517. /* add MTDRAM partition here */
  518. struct mtd_info *mtd_ram;
  519. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  520. if (!mtd_ram)
  521. panic("axisflashmap: Couldn't allocate memory "
  522. "for mtd_info!\n");
  523. printk(KERN_INFO "axisflashmap: Adding RAM partition "
  524. "for rootfs image.\n");
  525. err = mtdram_init_device(mtd_ram,
  526. (void *)partition[part].offset,
  527. partition[part].size,
  528. partition[part].name);
  529. if (err)
  530. panic("axisflashmap: Could not initialize "
  531. "MTD RAM device!\n");
  532. /* JFFS2 likes to have an erasesize. Keep potential
  533. * JFFS2 rootfs happy by providing one. Since image
  534. * was most likely created for main mtd, use that
  535. * erasesize, if available. Otherwise, make a guess. */
  536. mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
  537. CONFIG_ETRAX_PTABLE_SECTOR);
  538. } else {
  539. err = mtd_device_register(main_mtd, &partition[part],
  540. 1);
  541. if (err)
  542. panic("axisflashmap: Could not add mtd "
  543. "partition %d\n", part);
  544. }
  545. }
  546. #endif /* CONFIG_EXTRAX_VCS_SIM */
  547. #ifdef CONFIG_ETRAX_VCS_SIM
  548. /* For simulator, always use a RAM partition.
  549. * The rootfs will be found after the kernel in RAM,
  550. * with romfs_start and romfs_end indicating location and size.
  551. */
  552. struct mtd_info *mtd_ram;
  553. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  554. if (!mtd_ram) {
  555. panic("axisflashmap: Couldn't allocate memory for "
  556. "mtd_info!\n");
  557. }
  558. printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, "
  559. "at %u, size %u\n",
  560. (unsigned) romfs_start, (unsigned) romfs_length);
  561. err = mtdram_init_device(mtd_ram, (void *)romfs_start,
  562. romfs_length, "romfs");
  563. if (err) {
  564. panic("axisflashmap: Could not initialize MTD RAM "
  565. "device!\n");
  566. }
  567. #endif /* CONFIG_EXTRAX_VCS_SIM */
  568. #ifndef CONFIG_ETRAX_VCS_SIM
  569. if (aux_mtd) {
  570. aux_partition.size = aux_mtd->size;
  571. err = mtd_device_register(aux_mtd, &aux_partition, 1);
  572. if (err)
  573. panic("axisflashmap: Could not initialize "
  574. "aux mtd device!\n");
  575. }
  576. #endif /* CONFIG_EXTRAX_VCS_SIM */
  577. return err;
  578. }
  579. /* This adds the above to the kernels init-call chain. */
  580. module_init(init_axis_flash);
  581. EXPORT_SYMBOL(axisflash_mtd);