uclinux.c 3.1 KB

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