^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * uclinux.c -- generic memory mapped MTD driver for uclinux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * License: GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mtd/map.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mtd/partitions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #ifdef CONFIG_MTD_ROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define MAP_NAME "rom"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define MAP_NAME "ram"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct map_info uclinux_ram_map = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .name = MAP_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static unsigned long physaddr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) module_param(physaddr, ulong, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct mtd_info *uclinux_ram_mtdinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const struct mtd_partition uclinux_romfs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { .name = "ROMfs" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) size_t *retlen, void **virt, resource_size_t *phys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct map_info *map = mtd->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *virt = map->virt + from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (phys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *phys = map->phys + from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *retlen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int __init uclinux_mtd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct mtd_info *mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct map_info *mapp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mapp = &uclinux_ram_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (physaddr == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) mapp->phys = (resource_size_t)__bss_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mapp->phys = physaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!mapp->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) mapp->bankwidth = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) (int) mapp->phys, (int) mapp->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * The filesystem is guaranteed to be in direct mapped memory. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * directly following the kernels own bss region. Following the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * mechanism used by architectures setting up traditional initrds we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * use phys_to_virt to get the virtual address of its start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) mapp->virt = phys_to_virt(mapp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (mapp->virt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) printk("uclinux[mtd]: no virtual mapping?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) simple_map_init(mapp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mtd = do_map_probe("map_" MAP_NAME, mapp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!mtd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) printk("uclinux[mtd]: failed to find a mapping?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return(-ENXIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) mtd->owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) mtd->_point = uclinux_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) mtd->priv = mapp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) uclinux_ram_mtdinfo = mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) device_initcall(uclinux_mtd_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /****************************************************************************/