static int __init omapflash_probe(struct platform_device *pdev) { int err; struct omapflash_info *info; struct flash_platform_data *pdata = pdev->dev.platform_data; struct resource *res = pdev->resource; unsigned long size = res->end - res->start + 1; info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL); if (!info) return -ENOMEM; if (!request_mem_region(res->start, size, "flash")) { err = -EBUSY; goto out_free_info; } info->map.virt = ioremap(res->start, size); if (!info->map.virt) { err = -ENOMEM; goto out_release_mem_region; } info->map.name = pdev->dev.bus_id; info->map.phys = res->start; info->map.size = size; info->map.bankwidth = pdata->width; info->map.set_vpp = omap_set_vpp; simple_map_init(&info->map); info->mtd = do_map_probe(pdata->map_name, &info->map); if (!info->mtd) { err = -EIO; goto out_iounmap; } info->mtd->owner = THIS_MODULE; #ifdef CONFIG_MTD_PARTITIONS err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0); if (err > 0) add_mtd_partitions(info->mtd, info->parts, err); else if (err <= 0 && pdata->parts) add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); else #endif add_mtd_device(info->mtd); platform_set_drvdata(pdev, info); return 0; out_iounmap: iounmap(info->map.virt); out_release_mem_region: release_mem_region(res->start, size); out_free_info: kfree(info); return err; }
static int __devinit scb2_flash_probe(struct pci_dev *dev, const struct pci_device_id *ent) { u8 reg; /* enable decoding of the flash region in the south bridge */ pci_read_config_byte(dev, CSB5_FCR, ®); pci_write_config_byte(dev, CSB5_FCR, reg | CSB5_FCR_DECODE_ALL); if (!request_mem_region(SCB2_ADDR, SCB2_WINDOW, scb2_map.name)) { /* * The BIOS seems to mark the flash region as 'reserved' * in the e820 map. Warn and go about our business. */ printk(KERN_WARNING MODNAME ": warning - can't reserve rom window, continuing\n"); region_fail = 1; } /* remap the IO window (w/o caching) */ scb2_ioaddr = ioremap_nocache(SCB2_ADDR, SCB2_WINDOW); if (!scb2_ioaddr) { printk(KERN_ERR MODNAME ": Failed to ioremap window!\n"); if (!region_fail) release_mem_region(SCB2_ADDR, SCB2_WINDOW); return -ENOMEM; } scb2_map.map_priv_1 = (unsigned long)scb2_ioaddr; scb2_map.size = SCB2_WINDOW; /* try to find a chip */ scb2_mtd = do_map_probe("cfi_probe", &scb2_map); if (!scb2_mtd) { printk(KERN_ERR MODNAME ": flash probe failed!\n"); iounmap(scb2_ioaddr); if (!region_fail) release_mem_region(SCB2_ADDR, SCB2_WINDOW); return -ENODEV; } scb2_mtd->module = THIS_MODULE; if (scb2_fixup_mtd(scb2_mtd) < 0) { del_mtd_device(scb2_mtd); map_destroy(scb2_mtd); iounmap(scb2_ioaddr); if (!region_fail) release_mem_region(SCB2_ADDR, SCB2_WINDOW); return -ENODEV; } printk(KERN_NOTICE MODNAME ": chip size %x at offset %x\n", scb2_mtd->size, SCB2_WINDOW - scb2_mtd->size); add_mtd_device(scb2_mtd); return 0; }
static int __devinit generic_onenand_probe(struct device *dev) { struct onenand_info *info; struct platform_device *pdev = to_platform_device(dev); struct flash_platform_data *pdata = pdev->dev.platform_data; struct resource *res = pdev->resource; unsigned long size = res->end - res->start + 1; int err; info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL); if (!info) return -ENOMEM; if (!request_mem_region(res->start, size, dev->driver->name)) { err = -EBUSY; goto out_free_info; } info->onenand.base = ioremap(res->start, size); if (!info->onenand.base) { err = -ENOMEM; goto out_release_mem_region; } info->onenand.mmcontrol = pdata->mmcontrol; info->onenand.irq = platform_get_irq(pdev, 0); info->mtd.name = pdev->dev.bus_id; info->mtd.priv = &info->onenand; info->mtd.owner = THIS_MODULE; if (onenand_scan(&info->mtd, 1)) { err = -ENXIO; goto out_iounmap; } #ifdef CONFIG_MTD_PARTITIONS err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); if (err > 0) add_mtd_partitions(&info->mtd, info->parts, err); else if (err < 0 && pdata->parts) add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts); else #endif err = add_mtd_device(&info->mtd); dev_set_drvdata(&pdev->dev, info); return 0; out_iounmap: iounmap(info->onenand.base); out_release_mem_region: release_mem_region(res->start, size); out_free_info: kfree(info); return err; }
static int __init init_sc520cdp(void) { int i, devices_found = 0; #ifdef REPROGRAM_PAR /* reprogram PAR registers so flash appears at the desired addresses */ sc520cdp_setup_par(); #endif for (i = 0; i < NUM_FLASH_BANKS; i++) { printk(KERN_NOTICE "SC520 CDP flash device: 0x%lx at 0x%lx\n", sc520cdp_map[i].size, sc520cdp_map[i].phys); sc520cdp_map[i].virt = (void __iomem *)ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size); if (!sc520cdp_map[i].virt) { printk("Failed to ioremap_nocache\n"); return -EIO; } simple_map_init(&sc520cdp_map[i]); mymtd[i] = do_map_probe("cfi_probe", &sc520cdp_map[i]); if(!mymtd[i]) mymtd[i] = do_map_probe("jedec_probe", &sc520cdp_map[i]); if(!mymtd[i]) mymtd[i] = do_map_probe("map_rom", &sc520cdp_map[i]); if (mymtd[i]) { mymtd[i]->owner = THIS_MODULE; ++devices_found; } else { iounmap((void *)sc520cdp_map[i].virt); } } if(devices_found >= 2) { /* Combine the two flash banks into a single MTD device & register it: */ merged_mtd = mtd_concat_create(mymtd, 2, "SC520CDP Flash Banks #0 and #1"); if(merged_mtd) add_mtd_device(merged_mtd); } if(devices_found == 3) /* register the third (DIL-Flash) device */ add_mtd_device(mymtd[2]); return(devices_found ? 0 : -ENXIO); }
static int __init flash_init(void) { /* * Read the bootbus region 0 setup to determine the base * address of the flash. */ union cvmx_mio_boot_reg_cfgx region_cfg; region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(0)); if (region_cfg.s.en) { /* * The bootloader always takes the flash and sets its * address so the entire flash fits below * 0x1fc00000. This way the flash aliases to * 0x1fc00000 for booting. Software can access the * full flash at the true address, while core boot can * access 4MB. */ /* Use this name so old part lines work */ flash_map.name = "phys_mapped_flash"; flash_map.phys = region_cfg.s.base << 16; flash_map.size = 0x1fc00000 - flash_map.phys; flash_map.bankwidth = 1; flash_map.virt = ioremap(flash_map.phys, flash_map.size); pr_notice("Bootbus flash: Setting flash for %luMB flash at " "0x%08llx\n", flash_map.size >> 20, flash_map.phys); simple_map_init(&flash_map); mymtd = do_map_probe("cfi_probe", &flash_map); if (mymtd) { mymtd->owner = THIS_MODULE; #ifdef CONFIG_MTD_PARTITIONS nr_parts = parse_mtd_partitions(mymtd, part_probe_types, &parts, 0); if (nr_parts > 0) add_mtd_partitions(mymtd, parts, nr_parts); else add_mtd_device(mymtd); #else add_mtd_device(mymtd); #endif } else { pr_err("Failed to register MTD device for flash\n"); } }
static int __devinit mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct mtd_pci_info *info = (struct mtd_pci_info *)id->driver_data; struct map_pci_info *map = NULL; struct mtd_info *mtd = NULL; int err; err = pci_enable_device(dev); if (err) goto out; err = pci_request_regions(dev, "pci mtd"); if (err) goto out; map = kmalloc(sizeof(*map), GFP_KERNEL); err = -ENOMEM; if (!map) goto release; map->map = mtd_pci_map; map->map.name = pci_name(dev); map->dev = dev; map->exit = info->exit; map->translate = info->translate; err = info->init(dev, map); if (err) goto release; /* tsk - do_map_probe should take const char * */ mtd = do_map_probe((char *)info->map_name, &map->map); err = -ENODEV; if (!mtd) goto release; mtd->owner = THIS_MODULE; add_mtd_device(mtd); pci_set_drvdata(dev, mtd); return 0; release: if (mtd) map_destroy(mtd); if (map) { map->exit(dev, map); kfree(map); } pci_release_regions(dev); out: return err; }
static int __init dm270_init_flash (void) { struct mtd_partition *parts; int nb_parts = 0; int parsed_nr_parts = 0; const char *part_type; /* * Static partition definition selection */ part_type = "static"; parts = dm270_partitions; nb_parts = ARRAY_SIZE(dm270_partitions); dm270_map_flash.virt = phys_to_virt(dm270_map_flash.phys); simple_map_init(&dm270_map_flash); /* * Now let's probe for the actual flash. Do it here since * specific machine settings might have been set above. */ printk(KERN_NOTICE "DM270 flash: probing %d-bit flash bus\n", dm270_map_flash.bankwidth*8); dm270_flash_mtd = do_map_probe("cfi_probe", &dm270_map_flash); if (!dm270_flash_mtd) { return -ENXIO; } dm270_flash_mtd->owner = THIS_MODULE; /* * Dynamic partition selection stuff (might override the static ones) */ if (dm270_partition_types[0]) { parsed_nr_parts = parse_mtd_partitions(dm270_flash_mtd, dm270_partition_types, &parsed_parts, CONFIG_FLASH_MEM_BASE); } if (parsed_nr_parts > 0) { part_type = "dynamic"; parts = parsed_parts; nb_parts = parsed_nr_parts; } if (nb_parts == 0) { printk(KERN_NOTICE "DM270 flash: no partition info available," "registering whole flash at once\n"); if (add_mtd_device(dm270_flash_mtd)) { return -ENXIO; } } else { printk(KERN_NOTICE "Using %s partition definition\n", part_type); return add_mtd_partitions(dm270_flash_mtd, parts, nb_parts); } return 0; }
void flash_init(void) { struct dentry dentry = { .d_name = "mtd1" }; printk("Creating MTD device %s\n", dentry.d_name); if (mtdram_init_device(&mtd1, &_binary_sda1_start, 1024, dentry.d_name)) printk("error: mtdram init device failed\n"); add_mtd_device(&mtd1, dentry.d_name); } int main() { int fd; char buffer[128]; /* printk("filesystem at %p\n", &_binary_sda1_start); */ /* dump_romfs_info(&_binary_sda1_start); */ flash_init(); mount("/dev/mtd1", "/dev/flash", "romfs", 0, 0); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ fd = open("/dev/flash/lorem.txt", 0); if (fd < 0) { printk("error: failed to open /home/lorem.txt\n"); TEST_EXIT(1); } memset(buffer, 0, 128); read(fd, buffer, 11); printk("read(): %s\n", buffer); if (strcmp(buffer, "Lorem ipsum")) TEST_EXIT(1); memset(buffer, 0, 128); read(fd, buffer, 10); printk("read(): %s\n", buffer); if (strcmp(buffer, " dolor sit")) TEST_EXIT(1); memset(buffer, 0, 128); read(fd, buffer, 18); printk("read(): %s\n", buffer); if (strcmp(buffer, " amet, consectetur")) TEST_EXIT(1); /* rewind the file */ lseek(fd, 0, SEEK_SET); memset(buffer, 0, 128); read(fd, buffer, 11); printk("read(): %s\n", buffer); if (strcmp(buffer, "Lorem ipsum")) TEST_EXIT(1); TEST_EXIT(0); }
static int __init epxa_mtd_init(void) { int i; printk(KERN_NOTICE "%s flash device: %x at %x\n", BOARD_NAME, FLASH_SIZE, FLASH_START); epxa_map.map_priv_1 = (unsigned long)ioremap(FLASH_START, FLASH_SIZE); if (!epxa_map.map_priv_1) { printk("Failed to ioremap %s flash\n",BOARD_NAME); return -EIO; } mymtd = do_map_probe("cfi_probe", &epxa_map); if (!mymtd) { iounmap((void *)epxa_map.map_priv_1); return -ENXIO; } mymtd->module = THIS_MODULE; /* Unlock the flash device. */ if(mymtd->unlock){ for (i=0; i<mymtd->numeraseregions;i++){ int j; for(j=0;j<mymtd->eraseregions[i].numblocks;j++){ mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize); } } } #ifdef CONFIG_MTD_REDBOOT_PARTS nr_parts = parse_redboot_partitions(mymtd, &parts); if (nr_parts > 0) { add_mtd_partitions(mymtd, parts, nr_parts); return 0; } #endif #ifdef CONFIG_MTD_AFS_PARTS nr_parts = parse_afs_partitions(mymtd, &parts); if (nr_parts > 0) { add_mtd_partitions(mymtd, parts, nr_parts); return 0; } #endif /* No recognised partitioning schemes found - use defaults */ nr_parts = epxa_default_partitions(mymtd, &parts); if (nr_parts > 0) { add_mtd_partitions(mymtd, parts, nr_parts); return 0; } /* If all else fails... */ add_mtd_device(mymtd); return 0; }
static int ndfc_chip_probe(struct platform_device *pdev) { struct platform_nand_chip *nc = pdev->dev.platform_data; struct ndfc_chip_settings *settings = nc->priv; struct ndfc_controller *ndfc = &ndfc_ctrl; struct ndfc_nand_mtd *nandmtd; if (nc->chip_offset >= NDFC_MAX_BANKS || nc->nr_chips > NDFC_MAX_BANKS) return -EINVAL; /* Set the bank settings */ __raw_writel(settings->bank_settings, ndfc->ndfcbase + NDFC_BCFG0 + (nc->chip_offset << 2)); nandmtd = &ndfc_mtd[pdev->id]; if (nandmtd->pl_chip) return -EBUSY; nandmtd->pl_chip = nc; ndfc_chip_init(nandmtd); /* Scan for chips */ if (nand_scan(&nandmtd->mtd, nc->nr_chips)) { nandmtd->pl_chip = NULL; return -ENODEV; } #ifdef CONFIG_MTD_PARTITIONS printk("Number of partitions %d\n", nc->nr_partitions); if (nc->nr_partitions) { /* Add the full device, so complete dumps can be made */ add_mtd_device(&nandmtd->mtd); add_mtd_partitions(&nandmtd->mtd, nc->partitions, nc->nr_partitions); } else #else add_mtd_device(&nandmtd->mtd); #endif atomic_inc(&ndfc->childs_active); return 0; }
static int __init init_autcpu12_sram (void) { int err, save0, save1; autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K); if (!autcpu12_sram_map.virt) { printk("Failed to ioremap autcpu12 NV-RAM space\n"); err = -EIO; goto out; } simple_map_init(&autcpu_sram_map); save0 = map_read32(&autcpu12_sram_map,0); save1 = map_read32(&autcpu12_sram_map,0x10000); map_write32(&autcpu12_sram_map,~save0,0x10000); if ( map_read32(&autcpu12_sram_map,0) != save0) { map_write32(&autcpu12_sram_map,save0,0x0); goto map; } map_write32(&autcpu12_sram_map,save1,0x10000); autcpu12_sram_map.size = SZ_128K; map: sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map); if (!sram_mtd) { printk("NV-RAM probe failed\n"); err = -ENXIO; goto out_ioremap; } sram_mtd->owner = THIS_MODULE; sram_mtd->erasesize = 16; if (add_mtd_device(sram_mtd)) { printk("NV-RAM device addition failed\n"); err = -ENOMEM; goto out_probe; } printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K); return 0; out_probe: map_destroy(sram_mtd); sram_mtd = 0; out_ioremap: iounmap((void *)autcpu12_sram_map.virt); out: return err; }
int __init init_snsc_mpu210_map(unsigned long addr, unsigned long size, struct map_info *map, struct mtd_info **mtd #ifdef CONFIG_MTD_REDBOOT_PARTS , struct mtd_partition **parts #endif /* CONFIG_MTD_REDBOOT_PARTS */ ) { #ifdef CONFIG_MTD_REDBOOT_PARTS int nr_parts; #endif /* CONFIG_MTD_REDBOOT_PARTS */ printk(KERN_NOTICE "Flash device: %lx at %lx\n", size, addr); map->map_priv_1 = (unsigned long)ioremap_nocache(addr, size); if (!map->map_priv_1) { printk("Failed to ioremap\n"); return -EIO; } *mtd = do_map_probe("cfi_probe", map); if (*mtd) { (*mtd)->module = THIS_MODULE; #ifdef CONFIG_MTD_REDBOOT_PARTS nr_parts = parse_redboot_partitions(*mtd, parts); if (nr_parts > 0) { printk(KERN_NOTICE "Found RedBoot partition table.\n"); add_mtd_partitions(*mtd, *parts, nr_parts); } else { printk(KERN_NOTICE "Error looking for RedBoot partitions.\n"); add_mtd_device(*mtd); } #else /* CONFIG_MTD_REDBOOT_PARTS */ add_mtd_device(*mtd); #endif /* CONFIG_MTD_REDBOOT_PARTS */ return 0; } iounmap((void *)map->map_priv_1); return -ENXIO; }
static int __init init_soleng_maps(void) { int nr_parts; /* First probe at offset 0 */ soleng_flash_map.map_priv_1 = P2SEGADDR(0); soleng_eprom_map.map_priv_1 = P1SEGADDR(0x400000); printk(KERN_NOTICE "Probing for flash chips at 0x000000:\n"); flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); if (!flash_mtd) { /* Not there. Try swapping */ printk(KERN_NOTICE "Probing for flash chips at 0x400000:\n"); soleng_flash_map.map_priv_1 = P2SEGADDR(0x400000); soleng_eprom_map.map_priv_1 = P1SEGADDR(0); flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); if (!flash_mtd) { /* Eep. */ printk(KERN_NOTICE "Flash chips not detected at either possible location.\n"); return -ENXIO; } } printk(KERN_NOTICE "Solution Engine: Flash at 0x%08lx, EPROM at 0x%08lx\n", soleng_flash_map.map_priv_1 & 0x1fffffff, soleng_eprom_map.map_priv_1 & 0x1fffffff); flash_mtd->module = THIS_MODULE; eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map); if (eprom_mtd) { eprom_mtd->module = THIS_MODULE; add_mtd_device(eprom_mtd); } nr_parts = parse_redboot_partitions(flash_mtd, &parsed_parts); if (nr_parts) add_mtd_partitions(flash_mtd, parsed_parts, nr_parts); else add_mtd_device(flash_mtd); return 0; }
int __init init_s3c2410nor(void) { static const char *rom_probe_types[] = PROBETYPES; const char **type; const char *part_type = 0; printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR); s3c2410nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);//物理->虚拟地址 if (!s3c2410nor_map.virt) { printk(MSG_PREFIX "failed to ioremap\n"); return - EIO; } simple_map_init(&s3c2410nor_map); mymtd = 0; type = rom_probe_types; for (; !mymtd && *type; type++) { mymtd = do_map_probe(*type, &s3c2410nor_map);//探测NOR FLASH } if (mymtd) { mymtd->owner = THIS_MODULE; #ifdef CONFIG_MTD_PARTITIONS mtd_parts_nb = parse_mtd_partitions(mymtd, NULL, &mtd_parts, MTDID);//探测分区信息 if (mtd_parts_nb > 0) part_type = "detected"; if (mtd_parts_nb == 0) //未探测到,使用数组定义的分区信息 { mtd_parts = static_partitions; mtd_parts_nb = ARRAY_SIZE(static_partitions); part_type = "static"; } #endif add_mtd_device(mymtd); if (mtd_parts_nb == 0) printk(KERN_NOTICE MSG_PREFIX "no partition info available\n"); else { printk(KERN_NOTICE MSG_PREFIX "using %s partition definition\n", part_type); add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);//添加分区信息 } return 0; } iounmap((void*)s3c2410nor_map.virt); return - ENXIO; }
int __init init_physmap(void) { static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 }; const char **type; printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys); physmap_map.virt = (unsigned long)ioremap(physmap_map.phys, physmap_map.size); if (!physmap_map.virt) { printk("Failed to ioremap\n"); return -EIO; } simple_map_init(&physmap_map); mymtd = 0; type = rom_probe_types; for(; !mymtd && *type; type++) { mymtd = do_map_probe(*type, &physmap_map); } if (mymtd) { mymtd->owner = THIS_MODULE; #ifdef CONFIG_MTD_PARTITIONS mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, &mtd_parts, 0); if (mtd_parts_nb > 0) { add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb); return 0; } if (num_physmap_partitions != 0) { printk(KERN_NOTICE "Using physmap partition definition\n"); add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions); return 0; } #endif add_mtd_device(mymtd); return 0; } iounmap((void *)physmap_map.virt); return -ENXIO; }
int __init init_mtdram(void) { // Allocate some memory mtd_info = (struct mtd_info *)kmalloc(sizeof(struct mtd_info), GFP_KERNEL); if (!mtd_info) return -ENOMEM; memset(mtd_info, 0, sizeof(*mtd_info)); // Setup the MTD structure mtd_info->name = "mtdram test device"; mtd_info->type = MTD_RAM; mtd_info->flags = MTD_CAP_RAM; mtd_info->size = MTDRAM_TOTAL_SIZE; mtd_info->erasesize = MTDRAM_ERASE_SIZE; #if CONFIG_MTDRAM_ABS_POS > 0 mtd_info->priv = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE); #else mtd_info->priv = vmalloc(MTDRAM_TOTAL_SIZE); #endif if (!mtd_info->priv) { DEBUG(MTD_DEBUG_LEVEL1, "Failed to vmalloc(/ioremap) memory region of size %ld (ABS_POS:%ld)\n", (long)MTDRAM_TOTAL_SIZE, (long)CONFIG_MTDRAM_ABS_POS); kfree(mtd_info); mtd_info = NULL; return -ENOMEM; } #ifndef CONFIG_MIZI memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); #endif mtd_info->module = THIS_MODULE; mtd_info->erase = ram_erase; mtd_info->point = ram_point; mtd_info->unpoint = ram_unpoint; mtd_info->read = ram_read; mtd_info->write = ram_write; if (add_mtd_device(mtd_info)) { #if CONFIG_MTDRAM_ABS_POS > 0 iounmap(mtd_info->priv); #else vfree(mtd_info->priv); #endif kfree(mtd_info); mtd_info = NULL; return -EIO; } return 0; }
static int __init uclinux_mtd_init(void) { struct mtd_info *mtd; struct map_info *mapp; mapp = &uclinux_romfs_map; if (!mapp->size) mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); mapp->bankwidth = 4; #ifdef CONFIG_MTD_UCLINUX_RELOCATE printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", #else printk("uclinux[mtd]: ROM probe address=0x%x size=0x%x\n", #endif (int) mapp->phys, (int) mapp->size); mapp->virt = ioremap_nocache(mapp->phys, mapp->size); if (mapp->virt == 0) { printk("uclinux[mtd]: ioremap_nocache() failed\n"); return(-EIO); } simple_map_init(mapp); #ifdef CONFIG_MTD_UCLINUX_RELOCATE mtd = do_map_probe("map_ram", mapp); #else mtd = do_map_probe("map_rom", mapp); #endif if (!mtd) { printk("uclinux[mtd]: failed to find a mapping?\n"); iounmap(mapp->virt); return(-ENXIO); } mtd->owner = THIS_MODULE; mtd->point = uclinux_point; mtd->priv = mapp; uclinux_romfs_mtdinfo = mtd; #ifdef CONFIG_MTD_PARTITIONS add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS); #else add_mtd_device(mtd); #endif return(0); }
static int __init epxa_mtd_init(void) { int i; printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START); epxa_map.virt = (void __iomem *)ioremap(FLASH_START, FLASH_SIZE); if (!epxa_map.virt) { printk("Failed to ioremap %s flash\n",BOARD_NAME); return -EIO; } simple_map_init(&epxa_map); mymtd = do_map_probe("cfi_probe", &epxa_map); if (!mymtd) { iounmap((void *)epxa_map.virt); return -ENXIO; } mymtd->owner = THIS_MODULE; /* Unlock the flash device. */ if(mymtd->unlock){ for (i=0; i<mymtd->numeraseregions;i++){ int j; for(j=0;j<mymtd->eraseregions[i].numblocks;j++){ mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize); } } } #ifdef CONFIG_MTD_PARTITIONS nr_parts = parse_mtd_partitions(mymtd, probes, &parts, 0); if (nr_parts > 0) { add_mtd_partitions(mymtd, parts, nr_parts); return 0; } #endif /* No recognised partitioning schemes found - use defaults */ nr_parts = epxa_default_partitions(mymtd, &parts); if (nr_parts > 0) { add_mtd_partitions(mymtd, parts, nr_parts); return 0; } /* If all else fails... */ add_mtd_device(mymtd); return 0; }
static int __init init_cdb89712_flash (void) { int err; if (request_resource (&ioport_resource, &cdb89712_flash_resource)) { printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n"); err = -EBUSY; goto out; } cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE); if (!cdb89712_flash_map.virt) { printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n"); err = -EIO; goto out_resource; } simple_map_init(&cdb89712_flash_map); flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map); if (!flash_mtd) { flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map); if (flash_mtd) flash_mtd->erasesize = 0x10000; } if (!flash_mtd) { printk("FLASH probe failed\n"); err = -ENXIO; goto out_ioremap; } flash_mtd->owner = THIS_MODULE; if (add_mtd_device(flash_mtd)) { printk("FLASH device addition failed\n"); err = -ENOMEM; goto out_probe; } return 0; out_probe: map_destroy(flash_mtd); flash_mtd = 0; out_ioremap: iounmap((void *)cdb89712_flash_map.virt); out_resource: release_resource (&cdb89712_flash_resource); out: return err; }
static int __init init_l440gx(void) { struct pci_dev *dev; unsigned char b; __u16 w; dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, NULL); if (!dev) { printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n"); return -ENODEV; } l440gx_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE); if (!l440gx_map.map_priv_1) { printk("Failed to ioremap L440GX flash region\n"); return -ENOMEM; } /* Set XBCS# */ pci_read_config_word(dev, 0x4e, &w); w |= 0x4; pci_write_config_word(dev, 0x4e, w); /* Enable the gate on the WE line */ b = inb(TRIBUF_PORT); b |= 1; outb(b, TRIBUF_PORT); printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n"); mymtd = do_map_probe("jedec", &l440gx_map); if (!mymtd) { printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n"); mymtd = do_map_probe("map_rom", &l440gx_map); } if (mymtd) { mymtd->module = THIS_MODULE; add_mtd_device(mymtd); return 0; } iounmap((void *)l440gx_map.map_priv_1); return -ENXIO; }
int __init init_s3c2410nor(void) { static const char *rom_probe_types[] = PROBETYPES; const char **type; const char *part_type = 0; printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR); s3c2410nor_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);//物理->虚拟地址 //printk("vir=%x\n",s3c2410nor_map.virt); if (!s3c2410nor_map.virt) { printk(MSG_PREFIX "failed to ioremap\n"); return - EIO; } simple_map_init(&s3c2410nor_map); mymtd = 0; type = rom_probe_types; for (; !mymtd && *type; type++) { mymtd = do_map_probe(*type, &s3c2410nor_map);//探测NOR FLASH } if (mymtd) { mymtd->owner = THIS_MODULE; mtd_parts = static_partitions; mtd_parts_nb = ARRAY_SIZE(static_partitions); part_type = "static"; add_mtd_device(mymtd); if (mtd_parts_nb == 0) printk(KERN_NOTICE MSG_PREFIX "no partition info available\n"); else { printk(KERN_NOTICE MSG_PREFIX "using %s partition definition\n",part_type); add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);//添加分区信息 } return 0; } iounmap((void*)s3c2410nor_map.virt); return - ENXIO; }
static int __init init_flash (void) { struct mtd_partition *parts; int nb_parts = 0; int parsed_nr_parts = 0; const char *part_type; /* * Static partition definition selection */ part_type = "static"; parts = toto_flash_partitions; nb_parts = ARRAY_SIZE(toto_flash_partitions); omap_toto_map_flash.size = OMAP_TOTO_FLASH_SIZE; omap_toto_map_flash.phys = virt_to_phys(OMAP_TOTO_FLASH_BASE); simple_map_init(&omap_toto_map_flash); /* * Now let's probe for the actual flash. Do it here since * specific machine settings might have been set above. */ printk(KERN_NOTICE "OMAP toto flash: probing %d-bit flash bus\n", omap_toto_map_flash.bankwidth*8); flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash); if (!flash_mtd) return -ENXIO; if (parsed_nr_parts > 0) { parts = parsed_parts; nb_parts = parsed_nr_parts; } if (nb_parts == 0) { printk(KERN_NOTICE "OMAP toto flash: no partition info available," "registering whole flash at once\n"); if (add_mtd_device(flash_mtd)){ return -ENXIO; } } else { printk(KERN_NOTICE "Using %s partition definition\n", part_type); return add_mtd_partitions(flash_mtd, parts, nb_parts); } return 0; }
void flash_init(void) { struct dentry dentry = { .d_name = "mtd1" }; printk("Creating MTD device %s\n", dentry.d_name); if (mtdram_init_device(&mtd1, &_binary_sda1_start, 1024, dentry.d_name)) printk("error: mtdram init device failed\n"); add_mtd_device(&mtd1, dentry.d_name); } int main() { int fd; const char filename[] = "/dev/flash/foo/bar/lorem"; char buffer[32]; /* printk("filesystem at %p\n", &_binary_sda1_start); */ /* dump_romfs_info(&_binary_sda1_start); */ flash_init(); mount("/dev/mtd1", "/dev/flash", "romfs", 0, 0); /* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ fd = open(filename, 0); if (fd < 0) { printk("error: failed to open %s\n", filename); TEST_EXIT(1); } memset(buffer, 0, 32); if (read(fd, buffer, 11) != 11) TEST_EXIT(1); if (strcmp(buffer, "Lorem ipsum")) TEST_EXIT(1); memset(buffer, 0, 32); if (read(fd, buffer, 10) != 10) TEST_EXIT(1); if (strcmp(buffer, " dolor sit")) TEST_EXIT(1); close(fd); TEST_EXIT(0); }
static int __init init_cdb89712_bootrom (void) { int err; if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) { printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n"); err = -EBUSY; goto out; } cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE); if (!cdb89712_bootrom_map.virt) { printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n"); err = -EIO; goto out_resource; } simple_map_init(&cdb89712_bootrom_map); bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map); if (!bootrom_mtd) { printk("BootROM probe failed\n"); err = -ENXIO; goto out_ioremap; } bootrom_mtd->owner = THIS_MODULE; bootrom_mtd->erasesize = 0x10000; if (add_mtd_device(bootrom_mtd)) { printk("BootROM device addition failed\n"); err = -ENOMEM; goto out_probe; } return 0; out_probe: map_destroy(bootrom_mtd); bootrom_mtd = 0; out_ioremap: iounmap((void *)cdb89712_bootrom_map.virt); out_resource: release_resource (&cdb89712_bootrom_resource); out: return err; }
static int __init init_tsunami_flash(void) { static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 }; char **type; tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT); tsunami_flash_mtd = 0; type = rom_probe_types; for(; !tsunami_flash_mtd && *type; type++) { tsunami_flash_mtd = do_map_probe(*type, &tsunami_flash_map); } if (tsunami_flash_mtd) { tsunami_flash_mtd->module = THIS_MODULE; add_mtd_device(tsunami_flash_mtd); return 0; } return -ENXIO; }
static int __init cs553x_init(void) { int err = -ENXIO; int i; uint64_t val; /* If the CPU isn't a Geode GX or LX, abort */ if (!is_geode()) return -ENXIO; /* If it doesn't have the CS553[56], abort */ rdmsrl(MSR_DIVIL_GLD_CAP, val); val &= ~0xFFULL; if (val != CAP_CS5535 && val != CAP_CS5536) return -ENXIO; /* If it doesn't have the NAND controller enabled, abort */ rdmsrl(MSR_DIVIL_BALL_OPTS, val); if (val & 1) { printk(KERN_INFO "CS553x NAND controller: Flash I/O not enabled in MSR_DIVIL_BALL_OPTS.\n"); return -ENXIO; } for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { rdmsrl(MSR_DIVIL_LBAR_FLSH0 + i, val); if ((val & (FLSH_LBAR_EN|FLSH_NOR_NAND)) == (FLSH_LBAR_EN|FLSH_NOR_NAND)) err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF); } /* Register all devices together here. This means we can easily hack it to do mtdconcat etc. if we want to. */ for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { if (cs553x_mtd[i]) { add_mtd_device(cs553x_mtd[i]); /* If any devices registered, return success. Else the last error. */ err = 0; } } return err; }
int __init init_rpxlite(void) { printk(KERN_NOTICE "RPX Lite or CLLF flash device: %x at %x\n", WINDOW_SIZE*4, WINDOW_ADDR); rpxlite_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE * 4); if (!rpxlite_map.map_priv_1) { printk("Failed to ioremap\n"); return -EIO; } mymtd = do_map_probe("cfi_probe", &rpxlite_map); if (mymtd) { mymtd->module = THIS_MODULE; add_mtd_device(mymtd); return 0; } iounmap((void *)rpxlite_map.map_priv_1); return -ENXIO; }
int __init init_vmax301(void) { int i; unsigned long iomapadr; // Print out our little header.. printk("Tempustech VMAX 301 MEM:0x%x-0x%x\n",WINDOW_START, WINDOW_START+4*WINDOW_LENGTH); iomapadr = (unsigned long)ioremap(WINDOW_START, WINDOW_LENGTH*4); if (!iomapadr) { printk("Failed to ioremap memory region\n"); return -EIO; } /* Put the address in the map's private data area. We store the actual MTD IO address rather than the address of the first half, because it's used more often. */ vmax_map[0].map_priv_2 = iomapadr + WINDOW_START; vmax_map[1].map_priv_2 = iomapadr + (3*WINDOW_START); for (i=0; i<2; i++) { vmax_mtd[i] = do_map_probe("cfi_probe", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("jedec", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("map_ram", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("map_rom", &vmax_map[i]); if (vmax_mtd[i]) { vmax_mtd[i]->owner = THIS_MODULE; add_mtd_device(vmax_mtd[i]); } } if (!vmax_mtd[0] && !vmax_mtd[1]) { iounmap((void *)iomapadr); return -ENXIO; } return 0; }
int __init init_am8xx(void) { struct mtd_partition *parts; int nb_parts = 0; int parsed_nr_parts = 0; char *part_type; printk(KERN_NOTICE "A&M 8xx flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR); am8xx_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE); if (!am8xx_map.map_priv_1) { printk("Failed to ioremap\n"); return -EIO; } mymtd = do_map_probe("cfi_probe", &am8xx_map); if (mymtd) { mymtd->module = THIS_MODULE; #ifdef CONFIG_MTD_REDBOOT_PARTS if (parsed_nr_parts == 0) { int ret = parse_redboot_partitions(mymtd, &parsed_parts, 0); if (ret > 0) { part_type = "RedBoot"; parsed_nr_parts = ret; } } #endif if (parsed_nr_parts > 0) { parts = parsed_parts; nb_parts = parsed_nr_parts; } if (nb_parts == 0) { printk(KERN_NOTICE "A&M 8xx flash: no partition info available, registering whole flash at once\n"); add_mtd_device(mymtd); } else { printk(KERN_NOTICE "Using %s partition definition\n", part_type); add_mtd_partitions(mymtd, parts, nb_parts); } return 0; } iounmap((void *)am8xx_map.map_priv_1); return -ENXIO; }
int __init init_rpxlite(void) { printk(KERN_NOTICE "RPX Lite or CLLF flash device: %x at %x\n", WINDOW_SIZE*4, WINDOW_ADDR); rpxlite_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE * 4); if (!rpxlite_map.virt) { printk("Failed to ioremap\n"); return -EIO; } simple_map_init(&rpxlite_map); mymtd = do_map_probe("cfi_probe", &rpxlite_map); if (mymtd) { mymtd->owner = THIS_MODULE; add_mtd_device(mymtd); return 0; } iounmap((void *)rpxlite_map.virt); return -ENXIO; }