uclinux.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /****************************************************************************/
  2. /*
  3. * uclinux.c -- generic memory mapped MTD driver for uclinux
  4. *
  5. * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
  6. *
  7. * $Id: uclinux.c,v 1.10 2005/01/05 18:05:13 dwmw2 Exp $
  8. */
  9. /****************************************************************************/
  10. #include <linux/config.h>
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/fs.h>
  16. #include <linux/major.h>
  17. #include <linux/root_dev.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/map.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <asm/io.h>
  22. /****************************************************************************/
  23. /****************************************************************************/
  24. struct map_info uclinux_ram_map = {
  25. .name = "RAM",
  26. };
  27. struct mtd_info *uclinux_ram_mtdinfo;
  28. /****************************************************************************/
  29. struct mtd_partition uclinux_romfs[] = {
  30. { .name = "ROMfs" }
  31. };
  32. #define NUM_PARTITIONS (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0]))
  33. /****************************************************************************/
  34. int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  35. size_t *retlen, u_char **mtdbuf)
  36. {
  37. struct map_info *map = mtd->priv;
  38. *mtdbuf = (u_char *) (map->virt + ((int) from));
  39. *retlen = len;
  40. return(0);
  41. }
  42. /****************************************************************************/
  43. int __init uclinux_mtd_init(void)
  44. {
  45. struct mtd_info *mtd;
  46. struct map_info *mapp;
  47. extern char _ebss;
  48. mapp = &uclinux_ram_map;
  49. mapp->phys = (unsigned long) &_ebss;
  50. mapp->size = PAGE_ALIGN(*((unsigned long *)((&_ebss) + 8)));
  51. mapp->bankwidth = 4;
  52. printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
  53. (int) mapp->map_priv_2, (int) mapp->size);
  54. mapp->virt = ioremap_nocache(mapp->phys, mapp->size);
  55. if (mapp->virt == 0) {
  56. printk("uclinux[mtd]: ioremap_nocache() failed\n");
  57. return(-EIO);
  58. }
  59. simple_map_init(mapp);
  60. mtd = do_map_probe("map_ram", mapp);
  61. if (!mtd) {
  62. printk("uclinux[mtd]: failed to find a mapping?\n");
  63. iounmap(mapp->virt);
  64. return(-ENXIO);
  65. }
  66. mtd->owner = THIS_MODULE;
  67. mtd->point = uclinux_point;
  68. mtd->priv = mapp;
  69. uclinux_ram_mtdinfo = mtd;
  70. add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
  71. printk("uclinux[mtd]: set %s to be root filesystem\n",
  72. uclinux_romfs[0].name);
  73. ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0);
  74. put_mtd_device(mtd);
  75. return(0);
  76. }
  77. /****************************************************************************/
  78. void __exit uclinux_mtd_cleanup(void)
  79. {
  80. if (uclinux_ram_mtdinfo) {
  81. del_mtd_partitions(uclinux_ram_mtdinfo);
  82. map_destroy(uclinux_ram_mtdinfo);
  83. uclinux_ram_mtdinfo = NULL;
  84. }
  85. if (uclinux_ram_map.map_priv_1) {
  86. iounmap((void *) uclinux_ram_map.virt);
  87. uclinux_ram_map.virt = 0;
  88. }
  89. }
  90. /****************************************************************************/
  91. module_init(uclinux_mtd_init);
  92. module_exit(uclinux_mtd_cleanup);
  93. MODULE_LICENSE("GPL");
  94. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  95. MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
  96. /****************************************************************************/