axisflashmap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 = mtd_block_isbad(main_mtd, ptable_sector);
  363. if (blockstat < 0)
  364. ptable_sector = 0; /* read error */
  365. else if (blockstat)
  366. ptable_sector += main_mtd->erasesize;
  367. } while (blockstat && ptable_sector);
  368. #endif
  369. if (ptable_sector) {
  370. mtd_read(main_mtd, ptable_sector, PAGESIZE, &len,
  371. page);
  372. ptable_head = &((struct partitiontable *) page)->head;
  373. }
  374. #if 0 /* Dump partition table so we can see what is going on */
  375. printk(KERN_INFO
  376. "axisflashmap: flash read %d bytes at 0x%08x, data: "
  377. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  378. len, CONFIG_ETRAX_PTABLE_SECTOR,
  379. page[0] & 255, page[1] & 255,
  380. page[2] & 255, page[3] & 255,
  381. page[4] & 255, page[5] & 255,
  382. page[6] & 255, page[7] & 255);
  383. printk(KERN_INFO
  384. "axisflashmap: partition table offset %d, data: "
  385. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  386. PARTITION_TABLE_OFFSET,
  387. page[PARTITION_TABLE_OFFSET+0] & 255,
  388. page[PARTITION_TABLE_OFFSET+1] & 255,
  389. page[PARTITION_TABLE_OFFSET+2] & 255,
  390. page[PARTITION_TABLE_OFFSET+3] & 255,
  391. page[PARTITION_TABLE_OFFSET+4] & 255,
  392. page[PARTITION_TABLE_OFFSET+5] & 255,
  393. page[PARTITION_TABLE_OFFSET+6] & 255,
  394. page[PARTITION_TABLE_OFFSET+7] & 255);
  395. #endif
  396. }
  397. if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
  398. && (ptable_head->size <
  399. (MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
  400. PARTITIONTABLE_END_MARKER_SIZE))
  401. && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
  402. ptable_head->size -
  403. PARTITIONTABLE_END_MARKER_SIZE)
  404. == PARTITIONTABLE_END_MARKER)) {
  405. /* Looks like a start, sane length and end of a
  406. * partition table, lets check csum etc.
  407. */
  408. struct partitiontable_entry *max_addr =
  409. (struct partitiontable_entry *)
  410. ((unsigned long)ptable_head + sizeof(*ptable_head) +
  411. ptable_head->size);
  412. unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
  413. unsigned char *p;
  414. unsigned long csum = 0;
  415. ptable = (struct partitiontable_entry *)
  416. ((unsigned long)ptable_head + sizeof(*ptable_head));
  417. /* Lets be PARANOID, and check the checksum. */
  418. p = (unsigned char*) ptable;
  419. while (p <= (unsigned char*)max_addr) {
  420. csum += *p++;
  421. csum += *p++;
  422. csum += *p++;
  423. csum += *p++;
  424. }
  425. ptable_ok = (csum == ptable_head->checksum);
  426. /* Read the entries and use/show the info. */
  427. printk(KERN_INFO "axisflashmap: "
  428. "Found a%s partition table at 0x%p-0x%p.\n",
  429. (ptable_ok ? " valid" : "n invalid"), ptable_head,
  430. max_addr);
  431. /* We have found a working bootblock. Now read the
  432. * partition table. Scan the table. It ends with 0xffffffff.
  433. */
  434. while (ptable_ok
  435. && ptable->offset != PARTITIONTABLE_END_MARKER
  436. && ptable < max_addr
  437. && pidx < MAX_PARTITIONS - 1) {
  438. axis_partitions[pidx].offset = offset + ptable->offset;
  439. #ifdef CONFIG_ETRAX_NANDFLASH
  440. if (main_mtd->type == MTD_NANDFLASH) {
  441. axis_partitions[pidx].size =
  442. (((ptable+1)->offset ==
  443. PARTITIONTABLE_END_MARKER) ?
  444. main_mtd->size :
  445. ((ptable+1)->offset + offset)) -
  446. (ptable->offset + offset);
  447. } else
  448. #endif /* CONFIG_ETRAX_NANDFLASH */
  449. axis_partitions[pidx].size = ptable->size;
  450. #ifdef CONFIG_ETRAX_NANDBOOT
  451. /* Save partition number of jffs2 ro partition.
  452. * Needed if RAM booting or root file system in RAM.
  453. */
  454. if (!nand_boot &&
  455. ram_rootfs_partition < 0 && /* not already set */
  456. ptable->type == PARTITION_TYPE_JFFS2 &&
  457. (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
  458. PARTITION_FLAGS_READONLY)
  459. ram_rootfs_partition = pidx;
  460. #endif /* CONFIG_ETRAX_NANDBOOT */
  461. pidx++;
  462. ptable++;
  463. }
  464. }
  465. /* Decide whether to use default partition table. */
  466. /* Only use default table if we actually have a device (main_mtd) */
  467. struct mtd_partition *partition = &axis_partitions[0];
  468. if (main_mtd && !ptable_ok) {
  469. memcpy(axis_partitions, axis_default_partitions,
  470. sizeof(axis_default_partitions));
  471. pidx = NUM_DEFAULT_PARTITIONS;
  472. ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
  473. }
  474. /* Add artificial partitions for rootfs if necessary */
  475. if (romfs_in_flash) {
  476. /* rootfs is in directly accessible flash memory = NOR flash.
  477. Add an overlapping device for the rootfs partition. */
  478. printk(KERN_INFO "axisflashmap: Adding partition for "
  479. "overlapping root file system image\n");
  480. axis_partitions[pidx].size = romfs_length;
  481. axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
  482. axis_partitions[pidx].name = "romfs";
  483. axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
  484. ram_rootfs_partition = -1;
  485. pidx++;
  486. } else if (romfs_length && !nand_boot) {
  487. /* romfs exists in memory, but not in flash, so must be in RAM.
  488. * Configure an MTDRAM partition. */
  489. if (ram_rootfs_partition < 0) {
  490. /* None set yet, put it at the end */
  491. ram_rootfs_partition = pidx;
  492. pidx++;
  493. }
  494. printk(KERN_INFO "axisflashmap: Adding partition for "
  495. "root file system image in RAM\n");
  496. axis_partitions[ram_rootfs_partition].size = romfs_length;
  497. axis_partitions[ram_rootfs_partition].offset = romfs_start;
  498. axis_partitions[ram_rootfs_partition].name = "romfs";
  499. axis_partitions[ram_rootfs_partition].mask_flags |=
  500. MTD_WRITEABLE;
  501. }
  502. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  503. if (main_mtd) {
  504. main_partition.size = main_mtd->size;
  505. err = mtd_device_register(main_mtd, &main_partition, 1);
  506. if (err)
  507. panic("axisflashmap: Could not initialize "
  508. "partition for whole main mtd device!\n");
  509. }
  510. #endif
  511. /* Now, register all partitions with mtd.
  512. * We do this one at a time so we can slip in an MTDRAM device
  513. * in the proper place if required. */
  514. for (part = 0; part < pidx; part++) {
  515. if (part == ram_rootfs_partition) {
  516. /* add MTDRAM partition here */
  517. struct mtd_info *mtd_ram;
  518. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  519. if (!mtd_ram)
  520. panic("axisflashmap: Couldn't allocate memory "
  521. "for mtd_info!\n");
  522. printk(KERN_INFO "axisflashmap: Adding RAM partition "
  523. "for rootfs image.\n");
  524. err = mtdram_init_device(mtd_ram,
  525. (void *)partition[part].offset,
  526. partition[part].size,
  527. partition[part].name);
  528. if (err)
  529. panic("axisflashmap: Could not initialize "
  530. "MTD RAM device!\n");
  531. /* JFFS2 likes to have an erasesize. Keep potential
  532. * JFFS2 rootfs happy by providing one. Since image
  533. * was most likely created for main mtd, use that
  534. * erasesize, if available. Otherwise, make a guess. */
  535. mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
  536. CONFIG_ETRAX_PTABLE_SECTOR);
  537. } else {
  538. err = mtd_device_register(main_mtd, &partition[part],
  539. 1);
  540. if (err)
  541. panic("axisflashmap: Could not add mtd "
  542. "partition %d\n", part);
  543. }
  544. }
  545. #endif /* CONFIG_EXTRAX_VCS_SIM */
  546. #ifdef CONFIG_ETRAX_VCS_SIM
  547. /* For simulator, always use a RAM partition.
  548. * The rootfs will be found after the kernel in RAM,
  549. * with romfs_start and romfs_end indicating location and size.
  550. */
  551. struct mtd_info *mtd_ram;
  552. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  553. if (!mtd_ram) {
  554. panic("axisflashmap: Couldn't allocate memory for "
  555. "mtd_info!\n");
  556. }
  557. printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, "
  558. "at %u, size %u\n",
  559. (unsigned) romfs_start, (unsigned) romfs_length);
  560. err = mtdram_init_device(mtd_ram, (void *)romfs_start,
  561. romfs_length, "romfs");
  562. if (err) {
  563. panic("axisflashmap: Could not initialize MTD RAM "
  564. "device!\n");
  565. }
  566. #endif /* CONFIG_EXTRAX_VCS_SIM */
  567. #ifndef CONFIG_ETRAX_VCS_SIM
  568. if (aux_mtd) {
  569. aux_partition.size = aux_mtd->size;
  570. err = mtd_device_register(aux_mtd, &aux_partition, 1);
  571. if (err)
  572. panic("axisflashmap: Could not initialize "
  573. "aux mtd device!\n");
  574. }
  575. #endif /* CONFIG_EXTRAX_VCS_SIM */
  576. return err;
  577. }
  578. /* This adds the above to the kernels init-call chain. */
  579. module_init(init_axis_flash);
  580. EXPORT_SYMBOL(axisflash_mtd);