axisflashmap.c 18 KB

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