axisflashmap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. /* Auxilliary 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. #ifdef CONFIG_MTD_CONCAT
  247. /* Since the concatenation layer adds a small overhead we
  248. * could try to figure out if the chips in cse0 and cse1 are
  249. * identical and reprobe the whole cse0+cse1 window. But since
  250. * flash chips are slow, the overhead is relatively small.
  251. * So we use the MTD concatenation layer instead of further
  252. * complicating the probing procedure.
  253. */
  254. mtd_total = mtd_concat_create(mtds, count, "cse0+cse1");
  255. #else
  256. printk(KERN_ERR "%s and %s: Cannot concatenate due to kernel "
  257. "(mis)configuration!\n", map_cse0.name, map_cse1.name);
  258. mtd_toal = NULL;
  259. #endif
  260. if (!mtd_total) {
  261. printk(KERN_ERR "%s and %s: Concatenation failed!\n",
  262. map_cse0.name, map_cse1.name);
  263. /* The best we can do now is to only use what we found
  264. * at cse0. */
  265. mtd_total = mtd_cse0;
  266. map_destroy(mtd_cse1);
  267. }
  268. } else
  269. mtd_total = mtd_cse0 ? mtd_cse0 : mtd_cse1;
  270. return mtd_total;
  271. }
  272. /*
  273. * Probe the flash chip(s) and, if it succeeds, read the partition-table
  274. * and register the partitions with MTD.
  275. */
  276. static int __init init_axis_flash(void)
  277. {
  278. struct mtd_info *main_mtd;
  279. struct mtd_info *aux_mtd = NULL;
  280. int err = 0;
  281. int pidx = 0;
  282. struct partitiontable_head *ptable_head = NULL;
  283. struct partitiontable_entry *ptable;
  284. int ptable_ok = 0;
  285. static char page[PAGESIZE];
  286. size_t len;
  287. int ram_rootfs_partition = -1; /* -1 => no RAM rootfs partition */
  288. int part;
  289. /* We need a root fs. If it resides in RAM, we need to use an
  290. * MTDRAM device, so it must be enabled in the kernel config,
  291. * but its size must be configured as 0 so as not to conflict
  292. * with our usage.
  293. */
  294. #if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
  295. if (!romfs_in_flash && !nand_boot) {
  296. printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
  297. "device; configure CONFIG_MTD_MTDRAM with size = 0!\n");
  298. panic("This kernel cannot boot from RAM!\n");
  299. }
  300. #endif
  301. #ifndef CONFIG_ETRAX_VCS_SIM
  302. main_mtd = flash_probe();
  303. if (main_mtd)
  304. printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n",
  305. main_mtd->name, main_mtd->size);
  306. #ifdef CONFIG_ETRAX_NANDFLASH
  307. aux_mtd = crisv32_nand_flash_probe();
  308. if (aux_mtd)
  309. printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n",
  310. aux_mtd->name, aux_mtd->size);
  311. #ifdef CONFIG_ETRAX_NANDBOOT
  312. {
  313. struct mtd_info *tmp_mtd;
  314. printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, "
  315. "making NAND flash primary device.\n");
  316. tmp_mtd = main_mtd;
  317. main_mtd = aux_mtd;
  318. aux_mtd = tmp_mtd;
  319. }
  320. #endif /* CONFIG_ETRAX_NANDBOOT */
  321. #endif /* CONFIG_ETRAX_NANDFLASH */
  322. if (!main_mtd && !aux_mtd) {
  323. /* There's no reason to use this module if no flash chip can
  324. * be identified. Make sure that's understood.
  325. */
  326. printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
  327. }
  328. #if 0 /* Dump flash memory so we can see what is going on */
  329. if (main_mtd) {
  330. int sectoraddr, i;
  331. for (sectoraddr = 0; sectoraddr < 2*65536+4096;
  332. sectoraddr += PAGESIZE) {
  333. main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len,
  334. page);
  335. printk(KERN_INFO
  336. "Sector at %d (length %d):\n",
  337. sectoraddr, len);
  338. for (i = 0; i < PAGESIZE; i += 16) {
  339. printk(KERN_INFO
  340. "%02x %02x %02x %02x "
  341. "%02x %02x %02x %02x "
  342. "%02x %02x %02x %02x "
  343. "%02x %02x %02x %02x\n",
  344. page[i] & 255, page[i+1] & 255,
  345. page[i+2] & 255, page[i+3] & 255,
  346. page[i+4] & 255, page[i+5] & 255,
  347. page[i+6] & 255, page[i+7] & 255,
  348. page[i+8] & 255, page[i+9] & 255,
  349. page[i+10] & 255, page[i+11] & 255,
  350. page[i+12] & 255, page[i+13] & 255,
  351. page[i+14] & 255, page[i+15] & 255);
  352. }
  353. }
  354. }
  355. #endif
  356. if (main_mtd) {
  357. main_mtd->owner = THIS_MODULE;
  358. axisflash_mtd = main_mtd;
  359. loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;
  360. /* First partition (rescue) is always set to the default. */
  361. pidx++;
  362. #ifdef CONFIG_ETRAX_NANDBOOT
  363. /* We know where the partition table should be located,
  364. * it will be in first good block after that.
  365. */
  366. int blockstat;
  367. do {
  368. blockstat = main_mtd->block_isbad(main_mtd,
  369. ptable_sector);
  370. if (blockstat < 0)
  371. ptable_sector = 0; /* read error */
  372. else if (blockstat)
  373. ptable_sector += main_mtd->erasesize;
  374. } while (blockstat && ptable_sector);
  375. #endif
  376. if (ptable_sector) {
  377. main_mtd->read(main_mtd, ptable_sector, PAGESIZE,
  378. &len, page);
  379. ptable_head = &((struct partitiontable *) page)->head;
  380. }
  381. #if 0 /* Dump partition table so we can see what is going on */
  382. printk(KERN_INFO
  383. "axisflashmap: flash read %d bytes at 0x%08x, data: "
  384. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  385. len, CONFIG_ETRAX_PTABLE_SECTOR,
  386. page[0] & 255, page[1] & 255,
  387. page[2] & 255, page[3] & 255,
  388. page[4] & 255, page[5] & 255,
  389. page[6] & 255, page[7] & 255);
  390. printk(KERN_INFO
  391. "axisflashmap: partition table offset %d, data: "
  392. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  393. PARTITION_TABLE_OFFSET,
  394. page[PARTITION_TABLE_OFFSET+0] & 255,
  395. page[PARTITION_TABLE_OFFSET+1] & 255,
  396. page[PARTITION_TABLE_OFFSET+2] & 255,
  397. page[PARTITION_TABLE_OFFSET+3] & 255,
  398. page[PARTITION_TABLE_OFFSET+4] & 255,
  399. page[PARTITION_TABLE_OFFSET+5] & 255,
  400. page[PARTITION_TABLE_OFFSET+6] & 255,
  401. page[PARTITION_TABLE_OFFSET+7] & 255);
  402. #endif
  403. }
  404. if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
  405. && (ptable_head->size <
  406. (MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
  407. PARTITIONTABLE_END_MARKER_SIZE))
  408. && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
  409. ptable_head->size -
  410. PARTITIONTABLE_END_MARKER_SIZE)
  411. == PARTITIONTABLE_END_MARKER)) {
  412. /* Looks like a start, sane length and end of a
  413. * partition table, lets check csum etc.
  414. */
  415. struct partitiontable_entry *max_addr =
  416. (struct partitiontable_entry *)
  417. ((unsigned long)ptable_head + sizeof(*ptable_head) +
  418. ptable_head->size);
  419. unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
  420. unsigned char *p;
  421. unsigned long csum = 0;
  422. ptable = (struct partitiontable_entry *)
  423. ((unsigned long)ptable_head + sizeof(*ptable_head));
  424. /* Lets be PARANOID, and check the checksum. */
  425. p = (unsigned char*) ptable;
  426. while (p <= (unsigned char*)max_addr) {
  427. csum += *p++;
  428. csum += *p++;
  429. csum += *p++;
  430. csum += *p++;
  431. }
  432. ptable_ok = (csum == ptable_head->checksum);
  433. /* Read the entries and use/show the info. */
  434. printk(KERN_INFO "axisflashmap: "
  435. "Found a%s partition table at 0x%p-0x%p.\n",
  436. (ptable_ok ? " valid" : "n invalid"), ptable_head,
  437. max_addr);
  438. /* We have found a working bootblock. Now read the
  439. * partition table. Scan the table. It ends with 0xffffffff.
  440. */
  441. while (ptable_ok
  442. && ptable->offset != PARTITIONTABLE_END_MARKER
  443. && ptable < max_addr
  444. && pidx < MAX_PARTITIONS - 1) {
  445. axis_partitions[pidx].offset = offset + ptable->offset;
  446. #ifdef CONFIG_ETRAX_NANDFLASH
  447. if (main_mtd->type == MTD_NANDFLASH) {
  448. axis_partitions[pidx].size =
  449. (((ptable+1)->offset ==
  450. PARTITIONTABLE_END_MARKER) ?
  451. main_mtd->size :
  452. ((ptable+1)->offset + offset)) -
  453. (ptable->offset + offset);
  454. } else
  455. #endif /* CONFIG_ETRAX_NANDFLASH */
  456. axis_partitions[pidx].size = ptable->size;
  457. #ifdef CONFIG_ETRAX_NANDBOOT
  458. /* Save partition number of jffs2 ro partition.
  459. * Needed if RAM booting or root file system in RAM.
  460. */
  461. if (!nand_boot &&
  462. ram_rootfs_partition < 0 && /* not already set */
  463. ptable->type == PARTITION_TYPE_JFFS2 &&
  464. (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
  465. PARTITION_FLAGS_READONLY)
  466. ram_rootfs_partition = pidx;
  467. #endif /* CONFIG_ETRAX_NANDBOOT */
  468. pidx++;
  469. ptable++;
  470. }
  471. }
  472. /* Decide whether to use default partition table. */
  473. /* Only use default table if we actually have a device (main_mtd) */
  474. struct mtd_partition *partition = &axis_partitions[0];
  475. if (main_mtd && !ptable_ok) {
  476. memcpy(axis_partitions, axis_default_partitions,
  477. sizeof(axis_default_partitions));
  478. pidx = NUM_DEFAULT_PARTITIONS;
  479. ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
  480. }
  481. /* Add artificial partitions for rootfs if necessary */
  482. if (romfs_in_flash) {
  483. /* rootfs is in directly accessible flash memory = NOR flash.
  484. Add an overlapping device for the rootfs partition. */
  485. printk(KERN_INFO "axisflashmap: Adding partition for "
  486. "overlapping root file system image\n");
  487. axis_partitions[pidx].size = romfs_length;
  488. axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
  489. axis_partitions[pidx].name = "romfs";
  490. axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
  491. ram_rootfs_partition = -1;
  492. pidx++;
  493. } else if (romfs_length && !nand_boot) {
  494. /* romfs exists in memory, but not in flash, so must be in RAM.
  495. * Configure an MTDRAM partition. */
  496. if (ram_rootfs_partition < 0) {
  497. /* None set yet, put it at the end */
  498. ram_rootfs_partition = pidx;
  499. pidx++;
  500. }
  501. printk(KERN_INFO "axisflashmap: Adding partition for "
  502. "root file system image in RAM\n");
  503. axis_partitions[ram_rootfs_partition].size = romfs_length;
  504. axis_partitions[ram_rootfs_partition].offset = romfs_start;
  505. axis_partitions[ram_rootfs_partition].name = "romfs";
  506. axis_partitions[ram_rootfs_partition].mask_flags |=
  507. MTD_WRITEABLE;
  508. }
  509. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  510. if (main_mtd) {
  511. main_partition.size = main_mtd->size;
  512. err = add_mtd_partitions(main_mtd, &main_partition, 1);
  513. if (err)
  514. panic("axisflashmap: Could not initialize "
  515. "partition for whole main mtd device!\n");
  516. }
  517. #endif
  518. /* Now, register all partitions with mtd.
  519. * We do this one at a time so we can slip in an MTDRAM device
  520. * in the proper place if required. */
  521. for (part = 0; part < pidx; part++) {
  522. if (part == ram_rootfs_partition) {
  523. /* add MTDRAM partition here */
  524. struct mtd_info *mtd_ram;
  525. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  526. if (!mtd_ram)
  527. panic("axisflashmap: Couldn't allocate memory "
  528. "for mtd_info!\n");
  529. printk(KERN_INFO "axisflashmap: Adding RAM partition "
  530. "for rootfs image.\n");
  531. err = mtdram_init_device(mtd_ram,
  532. (void *)partition[part].offset,
  533. partition[part].size,
  534. partition[part].name);
  535. if (err)
  536. panic("axisflashmap: Could not initialize "
  537. "MTD RAM device!\n");
  538. /* JFFS2 likes to have an erasesize. Keep potential
  539. * JFFS2 rootfs happy by providing one. Since image
  540. * was most likely created for main mtd, use that
  541. * erasesize, if available. Otherwise, make a guess. */
  542. mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
  543. CONFIG_ETRAX_PTABLE_SECTOR);
  544. } else {
  545. err = add_mtd_partitions(main_mtd, &partition[part], 1);
  546. if (err)
  547. panic("axisflashmap: Could not add mtd "
  548. "partition %d\n", part);
  549. }
  550. }
  551. #endif /* CONFIG_EXTRAX_VCS_SIM */
  552. #ifdef CONFIG_ETRAX_VCS_SIM
  553. /* For simulator, always use a RAM partition.
  554. * The rootfs will be found after the kernel in RAM,
  555. * with romfs_start and romfs_end indicating location and size.
  556. */
  557. struct mtd_info *mtd_ram;
  558. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  559. if (!mtd_ram) {
  560. panic("axisflashmap: Couldn't allocate memory for "
  561. "mtd_info!\n");
  562. }
  563. printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, "
  564. "at %u, size %u\n",
  565. (unsigned) romfs_start, (unsigned) romfs_length);
  566. err = mtdram_init_device(mtd_ram, (void *)romfs_start,
  567. romfs_length, "romfs");
  568. if (err) {
  569. panic("axisflashmap: Could not initialize MTD RAM "
  570. "device!\n");
  571. }
  572. #endif /* CONFIG_EXTRAX_VCS_SIM */
  573. #ifndef CONFIG_ETRAX_VCS_SIM
  574. if (aux_mtd) {
  575. aux_partition.size = aux_mtd->size;
  576. err = add_mtd_partitions(aux_mtd, &aux_partition, 1);
  577. if (err)
  578. panic("axisflashmap: Could not initialize "
  579. "aux mtd device!\n");
  580. }
  581. #endif /* CONFIG_EXTRAX_VCS_SIM */
  582. return err;
  583. }
  584. /* This adds the above to the kernels init-call chain. */
  585. module_init(init_axis_flash);
  586. EXPORT_SYMBOL(axisflash_mtd);