axisflashmap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. main_mtd = flash_probe();
  296. if (main_mtd)
  297. printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n",
  298. main_mtd->name, main_mtd->size);
  299. #ifdef CONFIG_ETRAX_NANDFLASH
  300. aux_mtd = crisv32_nand_flash_probe();
  301. if (aux_mtd)
  302. printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n",
  303. aux_mtd->name, aux_mtd->size);
  304. #ifdef CONFIG_ETRAX_NANDBOOT
  305. {
  306. struct mtd_info *tmp_mtd;
  307. printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, "
  308. "making NAND flash primary device.\n");
  309. tmp_mtd = main_mtd;
  310. main_mtd = aux_mtd;
  311. aux_mtd = tmp_mtd;
  312. }
  313. #endif /* CONFIG_ETRAX_NANDBOOT */
  314. #endif /* CONFIG_ETRAX_NANDFLASH */
  315. if (!main_mtd && !aux_mtd) {
  316. /* There's no reason to use this module if no flash chip can
  317. * be identified. Make sure that's understood.
  318. */
  319. printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
  320. }
  321. #if 0 /* Dump flash memory so we can see what is going on */
  322. if (main_mtd) {
  323. int sectoraddr, i;
  324. for (sectoraddr = 0; sectoraddr < 2*65536+4096;
  325. sectoraddr += PAGESIZE) {
  326. main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len,
  327. page);
  328. printk(KERN_INFO
  329. "Sector at %d (length %d):\n",
  330. sectoraddr, len);
  331. for (i = 0; i < PAGESIZE; i += 16) {
  332. printk(KERN_INFO
  333. "%02x %02x %02x %02x "
  334. "%02x %02x %02x %02x "
  335. "%02x %02x %02x %02x "
  336. "%02x %02x %02x %02x\n",
  337. page[i] & 255, page[i+1] & 255,
  338. page[i+2] & 255, page[i+3] & 255,
  339. page[i+4] & 255, page[i+5] & 255,
  340. page[i+6] & 255, page[i+7] & 255,
  341. page[i+8] & 255, page[i+9] & 255,
  342. page[i+10] & 255, page[i+11] & 255,
  343. page[i+12] & 255, page[i+13] & 255,
  344. page[i+14] & 255, page[i+15] & 255);
  345. }
  346. }
  347. }
  348. #endif
  349. if (main_mtd) {
  350. main_mtd->owner = THIS_MODULE;
  351. axisflash_mtd = main_mtd;
  352. loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;
  353. /* First partition (rescue) is always set to the default. */
  354. pidx++;
  355. #ifdef CONFIG_ETRAX_NANDBOOT
  356. /* We know where the partition table should be located,
  357. * it will be in first good block after that.
  358. */
  359. int blockstat;
  360. do {
  361. blockstat = mtd_block_isbad(main_mtd, ptable_sector);
  362. if (blockstat < 0)
  363. ptable_sector = 0; /* read error */
  364. else if (blockstat)
  365. ptable_sector += main_mtd->erasesize;
  366. } while (blockstat && ptable_sector);
  367. #endif
  368. if (ptable_sector) {
  369. mtd_read(main_mtd, ptable_sector, PAGESIZE, &len,
  370. page);
  371. ptable_head = &((struct partitiontable *) page)->head;
  372. }
  373. #if 0 /* Dump partition table so we can see what is going on */
  374. printk(KERN_INFO
  375. "axisflashmap: flash read %d bytes at 0x%08x, data: "
  376. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  377. len, CONFIG_ETRAX_PTABLE_SECTOR,
  378. page[0] & 255, page[1] & 255,
  379. page[2] & 255, page[3] & 255,
  380. page[4] & 255, page[5] & 255,
  381. page[6] & 255, page[7] & 255);
  382. printk(KERN_INFO
  383. "axisflashmap: partition table offset %d, data: "
  384. "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  385. PARTITION_TABLE_OFFSET,
  386. page[PARTITION_TABLE_OFFSET+0] & 255,
  387. page[PARTITION_TABLE_OFFSET+1] & 255,
  388. page[PARTITION_TABLE_OFFSET+2] & 255,
  389. page[PARTITION_TABLE_OFFSET+3] & 255,
  390. page[PARTITION_TABLE_OFFSET+4] & 255,
  391. page[PARTITION_TABLE_OFFSET+5] & 255,
  392. page[PARTITION_TABLE_OFFSET+6] & 255,
  393. page[PARTITION_TABLE_OFFSET+7] & 255);
  394. #endif
  395. }
  396. if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
  397. && (ptable_head->size <
  398. (MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
  399. PARTITIONTABLE_END_MARKER_SIZE))
  400. && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
  401. ptable_head->size -
  402. PARTITIONTABLE_END_MARKER_SIZE)
  403. == PARTITIONTABLE_END_MARKER)) {
  404. /* Looks like a start, sane length and end of a
  405. * partition table, lets check csum etc.
  406. */
  407. struct partitiontable_entry *max_addr =
  408. (struct partitiontable_entry *)
  409. ((unsigned long)ptable_head + sizeof(*ptable_head) +
  410. ptable_head->size);
  411. unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
  412. unsigned char *p;
  413. unsigned long csum = 0;
  414. ptable = (struct partitiontable_entry *)
  415. ((unsigned long)ptable_head + sizeof(*ptable_head));
  416. /* Lets be PARANOID, and check the checksum. */
  417. p = (unsigned char*) ptable;
  418. while (p <= (unsigned char*)max_addr) {
  419. csum += *p++;
  420. csum += *p++;
  421. csum += *p++;
  422. csum += *p++;
  423. }
  424. ptable_ok = (csum == ptable_head->checksum);
  425. /* Read the entries and use/show the info. */
  426. printk(KERN_INFO "axisflashmap: "
  427. "Found a%s partition table at 0x%p-0x%p.\n",
  428. (ptable_ok ? " valid" : "n invalid"), ptable_head,
  429. max_addr);
  430. /* We have found a working bootblock. Now read the
  431. * partition table. Scan the table. It ends with 0xffffffff.
  432. */
  433. while (ptable_ok
  434. && ptable->offset != PARTITIONTABLE_END_MARKER
  435. && ptable < max_addr
  436. && pidx < MAX_PARTITIONS - 1) {
  437. axis_partitions[pidx].offset = offset + ptable->offset;
  438. #ifdef CONFIG_ETRAX_NANDFLASH
  439. if (main_mtd->type == MTD_NANDFLASH) {
  440. axis_partitions[pidx].size =
  441. (((ptable+1)->offset ==
  442. PARTITIONTABLE_END_MARKER) ?
  443. main_mtd->size :
  444. ((ptable+1)->offset + offset)) -
  445. (ptable->offset + offset);
  446. } else
  447. #endif /* CONFIG_ETRAX_NANDFLASH */
  448. axis_partitions[pidx].size = ptable->size;
  449. #ifdef CONFIG_ETRAX_NANDBOOT
  450. /* Save partition number of jffs2 ro partition.
  451. * Needed if RAM booting or root file system in RAM.
  452. */
  453. if (!nand_boot &&
  454. ram_rootfs_partition < 0 && /* not already set */
  455. ptable->type == PARTITION_TYPE_JFFS2 &&
  456. (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
  457. PARTITION_FLAGS_READONLY)
  458. ram_rootfs_partition = pidx;
  459. #endif /* CONFIG_ETRAX_NANDBOOT */
  460. pidx++;
  461. ptable++;
  462. }
  463. }
  464. /* Decide whether to use default partition table. */
  465. /* Only use default table if we actually have a device (main_mtd) */
  466. struct mtd_partition *partition = &axis_partitions[0];
  467. if (main_mtd && !ptable_ok) {
  468. memcpy(axis_partitions, axis_default_partitions,
  469. sizeof(axis_default_partitions));
  470. pidx = NUM_DEFAULT_PARTITIONS;
  471. ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
  472. }
  473. /* Add artificial partitions for rootfs if necessary */
  474. if (romfs_in_flash) {
  475. /* rootfs is in directly accessible flash memory = NOR flash.
  476. Add an overlapping device for the rootfs partition. */
  477. printk(KERN_INFO "axisflashmap: Adding partition for "
  478. "overlapping root file system image\n");
  479. axis_partitions[pidx].size = romfs_length;
  480. axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
  481. axis_partitions[pidx].name = "romfs";
  482. axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
  483. ram_rootfs_partition = -1;
  484. pidx++;
  485. } else if (romfs_length && !nand_boot) {
  486. /* romfs exists in memory, but not in flash, so must be in RAM.
  487. * Configure an MTDRAM partition. */
  488. if (ram_rootfs_partition < 0) {
  489. /* None set yet, put it at the end */
  490. ram_rootfs_partition = pidx;
  491. pidx++;
  492. }
  493. printk(KERN_INFO "axisflashmap: Adding partition for "
  494. "root file system image in RAM\n");
  495. axis_partitions[ram_rootfs_partition].size = romfs_length;
  496. axis_partitions[ram_rootfs_partition].offset = romfs_start;
  497. axis_partitions[ram_rootfs_partition].name = "romfs";
  498. axis_partitions[ram_rootfs_partition].mask_flags |=
  499. MTD_WRITEABLE;
  500. }
  501. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  502. if (main_mtd) {
  503. main_partition.size = main_mtd->size;
  504. err = mtd_device_register(main_mtd, &main_partition, 1);
  505. if (err)
  506. panic("axisflashmap: Could not initialize "
  507. "partition for whole main mtd device!\n");
  508. }
  509. #endif
  510. /* Now, register all partitions with mtd.
  511. * We do this one at a time so we can slip in an MTDRAM device
  512. * in the proper place if required. */
  513. for (part = 0; part < pidx; part++) {
  514. if (part == ram_rootfs_partition) {
  515. /* add MTDRAM partition here */
  516. struct mtd_info *mtd_ram;
  517. mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  518. if (!mtd_ram)
  519. panic("axisflashmap: Couldn't allocate memory "
  520. "for mtd_info!\n");
  521. printk(KERN_INFO "axisflashmap: Adding RAM partition "
  522. "for rootfs image.\n");
  523. err = mtdram_init_device(mtd_ram,
  524. (void *)partition[part].offset,
  525. partition[part].size,
  526. partition[part].name);
  527. if (err)
  528. panic("axisflashmap: Could not initialize "
  529. "MTD RAM device!\n");
  530. /* JFFS2 likes to have an erasesize. Keep potential
  531. * JFFS2 rootfs happy by providing one. Since image
  532. * was most likely created for main mtd, use that
  533. * erasesize, if available. Otherwise, make a guess. */
  534. mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
  535. CONFIG_ETRAX_PTABLE_SECTOR);
  536. } else {
  537. err = mtd_device_register(main_mtd, &partition[part],
  538. 1);
  539. if (err)
  540. panic("axisflashmap: Could not add mtd "
  541. "partition %d\n", part);
  542. }
  543. }
  544. if (aux_mtd) {
  545. aux_partition.size = aux_mtd->size;
  546. err = mtd_device_register(aux_mtd, &aux_partition, 1);
  547. if (err)
  548. panic("axisflashmap: Could not initialize "
  549. "aux mtd device!\n");
  550. }
  551. return err;
  552. }
  553. /* This adds the above to the kernels init-call chain. */
  554. module_init(init_axis_flash);
  555. EXPORT_SYMBOL(axisflash_mtd);