/****************************************************************************** * * axfs_get_sb_mtdnr * * Description: * Populates a axfs_fill_super_info struct after sanity checking the * mtd device of device number * * Parameters: * (IN) mtdnr - the mtd device number * * Returns: * pointer to a axfs_file_super_info or an error pointer * *****************************************************************************/ static struct axfs_fill_super_info *axfs_get_sb_mtdnr(int mtdnr) { struct axfs_fill_super_info *output; struct mtd_info *mtd; void *axfsimage; size_t retlen; int err; mtd = get_mtd_device(NULL, mtdnr); if (!mtd) { printk(KERN_DEBUG "axfs: MTD device #%u doesn't appear to exist\n", mtdnr); err = -EINVAL; goto out; } if (mtd->point) { } else { printk(KERN_DEBUG "axfs: MTD device #%u doesn't support point()\n", mtdnr); err = -EINVAL; goto out; } if (mtd->unpoint) { } else { printk(KERN_DEBUG "axfs: MTD device #%u doesn't support unpoint()\n", mtdnr); err = -EINVAL; goto out; } if (!((mtd->point(mtd, 0, PAGE_SIZE, &retlen, &axfsimage, NULL)) == 0)) { err = -EACCES; goto out; } output = (struct axfs_fill_super_info *)vmalloc(sizeof(struct axfs_fill_super_info)); if(!output) { err = - ENOMEM; goto out; } output->onmedia_super_block = (struct axfs_super_onmedia *)vmalloc(sizeof(struct axfs_super_onmedia)); if(!output->onmedia_super_block) { err = - ENOMEM; goto out; } memcpy((void *)output->onmedia_super_block, axfsimage, sizeof(struct axfs_super_onmedia)); mtd->unpoint(mtd, 0, retlen); output->physical_start_address = (unsigned long)mtd_get_partition_physaddr(mtd); output->virtual_start_address = 0; put_mtd_device(mtd); return output; out: put_mtd_device(mtd); return ERR_PTR(err); }
static int mtd_open(struct inode *inode, struct file *file) { int minor = minor(inode->i_rdev); int devnum = minor >> 1; struct mtd_info *mtd; DEBUG(MTD_DEBUG_LEVEL0, "MTD_open\n"); if (devnum >= MAX_MTD_DEVICES) return -ENODEV; /* You can't open the RO devices RW */ if ((file->f_mode & 2) && (minor & 1)) return -EACCES; mtd = get_mtd_device(NULL, devnum); if (!mtd) return -ENODEV; if (MTD_ABSENT == mtd->type) { put_mtd_device(mtd); return -ENODEV; } file->private_data = mtd; /* You can't open it RW if it's not a writeable device */ if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { put_mtd_device(mtd); return -EACCES; } return 0; } /* mtd_open */
static int cfe_init(void) { size_t erasesize; int i; int ret = 0; printk("!!! cfe_init !!!\n"); /* Find associated MTD device */ for (i = 0; i < MAX_MTD_DEVICES; i++) { cfe_mtd = get_mtd_device(NULL, i); if (cfe_mtd != NULL) { printk("cfe_init: CFE MTD %x %s %x\n", i, cfe_mtd->name, cfe_mtd->size); if (!strcmp(cfe_mtd->name, "pmon")) break; put_mtd_device(cfe_mtd); } } if (i >= MAX_MTD_DEVICES) { printk("cfe_init: No CFE MTD\n"); cfe_mtd = NULL; ret = -ENODEV; } if(cfe_mtd == NULL) goto fail; /* sector blocks to be erased and backup */ erasesize = ROUNDUP(CFE_NVRAM_SPACE, cfe_mtd->erasesize); printk("cfe_init: block size %d\n", erasesize); cfe_buf = kmalloc(erasesize, GFP_KERNEL); if(cfe_buf == NULL) { printk("cfe_init: No CFE Memory\n"); ret = -ENOMEM; goto fail; } if((ret = get_embedded_block(cfe_mtd, cfe_buf, erasesize, &cfe_offset, &cfe_nvram_header, &cfe_embedded_size))) goto fail; printk("cfe_init: cfe_nvram_header(%08x)\n", (unsigned int) cfe_nvram_header); bcm947xx_watchdog_disable(); return 0; fail: if (cfe_mtd != NULL) { put_mtd_device(cfe_mtd); cfe_mtd=NULL; } if(cfe_buf != NULL) { kfree(cfe_buf); cfe_buf=NULL; } return ret; }
int save_param_value(void) { unsigned int err = 0; unsigned char *addr = NULL; struct mtd_info *mtd; unsigned int ret = 0; unsigned int retlen; printk("%s start\n", __func__); addr = vmalloc(PARAM_LEN); if (!addr) return -ENOMEM; preempt_enable(); printk("%s get_mtd_device\n", __func__); mtd = get_mtd_device_nm("param"); if (IS_ERR(mtd)) { printk("(%s)Cannot find param partition.\n",__func__); goto fail; } printk("%s read\n", __func__); ret = mtd->read(mtd, 0x30000, PARAM_LEN, &retlen, addr); if (ret || retlen != PARAM_LEN) { printk("(%s)Failed to read param block.\n", __func__); put_mtd_device(mtd); goto fail; } // update MAIN memset(addr, 0, PARAM_LEN); memcpy(addr, ¶m_status, sizeof(param_status_t)); printk("%s write\n", __func__); ret = mtd->write(mtd, 0x30000, PARAM_LEN, &retlen, addr); if (ret || retlen != PARAM_LEN) { printk("(%s)Failed to write param block.\n", __func__); put_mtd_device(mtd); goto fail; } printk("%s put\n", __func__); put_mtd_device(mtd); fail: vfree(addr); preempt_disable(); printk("%s end\n", __func__); return err; }
static int mtd_open(struct inode *inode, struct file *file) { int minor = iminor(inode); int devnum = minor >> 1; int ret = 0; struct mtd_info *mtd; struct mtd_file_info *mfi; DEBUG(MTD_DEBUG_LEVEL0, "MTD_open\n"); if (devnum >= MAX_MTD_DEVICES) return -ENODEV; /* You can't open the RO devices RW */ if ((file->f_mode & 2) && (minor & 1)) return -EACCES; lock_kernel(); mtd = get_mtd_device(NULL, devnum); if (IS_ERR(mtd)) { ret = PTR_ERR(mtd); goto out; } if (MTD_ABSENT == mtd->type) { put_mtd_device(mtd); ret = -ENODEV; goto out; } /* You can't open it RW if it's not a writeable device */ if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { put_mtd_device(mtd); ret = -EACCES; goto out; } mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); if (!mfi) { put_mtd_device(mtd); ret = -ENOMEM; goto out; } mfi->mtd = mtd; file->private_data = mfi; out: unlock_kernel(); return ret; } /* mtd_open */
/*=========================================================================== FUNCTION FLASH_NAND_OPER_REGION_CLOSE DESCRIPTION close flash device and release flash handle DEPENDENCIES None. RETURN VALUE TRUE: valid FALSE: invalid SIDE EFFECTS None. ===========================================================================*/ void flash_nand_oper_region_close(oper_region_type oper_region_idx) { (void) kfree(operation_region[oper_region_idx].buffer); operation_region[oper_region_idx].buffer = NULL; put_mtd_device(g_mtd); return; }
static struct super_block *jffs2_read_super(struct super_block *sb, void *data, int silent) { struct jffs2_sb_info *c; int ret; D1(printk(KERN_DEBUG "jffs2: read_super for device %s\n", kdevname(sb->s_dev))); if (major(sb->s_dev) != MTD_BLOCK_MAJOR) { if (!silent) printk(KERN_DEBUG "jffs2: attempt to mount non-MTD device %s\n", kdevname(sb->s_dev)); return NULL; } c = JFFS2_SB_INFO(sb); memset(c, 0, sizeof(*c)); sb->s_op = &jffs2_super_operations; c->mtd = get_mtd_device(NULL, minor(sb->s_dev)); if (!c->mtd) { D1(printk(KERN_DEBUG "jffs2: MTD device #%u doesn't appear to exist\n", minor(sb->s_dev))); return NULL; } ret = jffs2_do_fill_super(sb, data, silent); if (ret) { put_mtd_device(c->mtd); return NULL; } return sb; }
static void dev_nvram_exit(void) { int order = 0; struct page *page, *end; if (nvram_class) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) class_device_destroy(nvram_class, MKDEV(nvram_major, 0)); #else /* 2.6.36 and up */ device_destroy(nvram_class, MKDEV(nvram_major, 0)); #endif class_destroy(nvram_class); } if (nvram_major >= 0) unregister_chrdev(nvram_major, "nvram"); if (nvram_mtd) put_mtd_device(nvram_mtd); while ((PAGE_SIZE << order) < MAX_NVRAM_SPACE) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) ClearPageReserved(page); _nvram_exit(); }
static release_t mtdblock_release(struct inode *inode, struct file *file) { int dev; struct mtd_info *mtd; DEBUG(1, "mtdblock_release\n"); if (inode == NULL) release_return(-ENODEV); dev = MINOR(inode->i_rdev); mtd = __get_mtd_device(NULL, dev); if (!mtd) { printk(KERN_WARNING "MTD device is absent on mtd_release!\n"); BLK_DEC_USE_COUNT; release_return(-ENODEV); } if (mtd->sync) mtd->sync(mtd); put_mtd_device(mtd); DEBUG(1, "ok\n"); BLK_DEC_USE_COUNT; release_return(0); }
static int mtdblock_open(struct inode *inode, struct file *file) { struct mtd_info *mtd = NULL; int dev; DEBUG(1,"mtdblock_open\n"); if (inode == 0) return -EINVAL; dev = MINOR(inode->i_rdev); mtd = get_mtd_device(NULL, dev); if (!mtd) return -EINVAL; if (MTD_ABSENT == mtd->type) { put_mtd_device(mtd); return -EINVAL; } BLK_INC_USE_COUNT; mtd_sizes[dev] = mtd->size>>9; DEBUG(1, "ok\n"); return 0; }
int ubi_part(char *part_name, const char *vid_header_offset) { struct mtd_info *mtd; int err = 0; ubi_detach(); mtd_probe_devices(); mtd = get_mtd_device_nm(part_name); if (IS_ERR(mtd)) { printf("Partition %s not found!\n", part_name); return 1; } put_mtd_device(mtd); err = ubi_dev_scan(mtd, vid_header_offset); if (err) { printf("UBI init error %d\n", err); printf("Please check, if the correct MTD partition is used (size big enough?)\n"); return err; } ubi = ubi_devices[0]; return 0; }
static void jffs2_kill_sb(struct super_block *sb) { struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); generic_shutdown_super(sb); put_mtd_device(c->mtd); kfree(c); }
static int spectra_release(struct inode *inode, struct file *file) { struct spectra_device *dev = file->private_data; put_mtd_device(dev->mtd); kfree(dev); return 0; }
static void dev_nvram_exit(void) { int order = 0; struct page *page, *end; if (nvram_class) { class_device_destroy(nvram_class, MKDEV(nvram_major, 0)); class_destroy(nvram_class); } if (nvram_major >= 0) unregister_chrdev(nvram_major, "nvram"); if (nvram_mtd) put_mtd_device(nvram_mtd); while ((PAGE_SIZE << order) < nvram_space) order++; end = virt_to_page(nvram_buf + (PAGE_SIZE << order) - 1); for (page = virt_to_page(nvram_buf); page <= end; page++) ClearPageReserved(page); _nvram_exit(); }
s32 nv_emmc_close(FILE* fp) { struct nv_emmc_file_header_stru* fd = (struct nv_emmc_file_header_stru*)fp; nv_file_debug(NV_FILE_CLOSE_API,0,0,0,0); if((NULL == fd)||(fd->fp != fd)) { nv_file_debug(NV_FILE_CLOSE_API,1,0,0,0); return BSP_ERR_NV_INVALID_PARAM; } put_mtd_device(fd->mtd); osl_sem_up(&fd->file_sem); fd->fp = NULL; fd->seek = 0; fd->length = 0; fd->off = 0; fd->ops --; fd->mtd = NULL; if(fd->ops != 0) { nv_file_debug(NV_FILE_CLOSE_API,2,fd->ops,0,0); return BSP_ERR_NV_CLOSE_FILE_FAIL; } return NV_OK; }
/* * Function : sc_bakup * Discription: c core nv init,this phase build upon the a core kernel init, * this phase after icc init,this phase ensure to use all nv api normal * start at this phase ,ops global ddr need spinlock * Parameter : none * Output : result * History : */ s32 sc_bakup(s8 *pdata, u32 len) { s32 sc_fp = 0; s32 wlen = 0; u32 sc_mtd_len = 0; struct mtd_info* mtd; sc_fp = bsp_open((char *)SC_PACKET_TRANS_FILE,(RFILE_RDONLY),0660); if(!sc_fp) { sc_error_printf("bsp_open error, chanid :0x%x sc_fp :0x%x\n",SC_ICC_CHAN_ID,sc_fp); return BSP_ERR_SC_NO_FILE; } else { sc_debug_printf("bsp_open ok, file is 0x%x!\n",sc_fp); } wlen = bsp_read(sc_fp, pdata, len); if(wlen != len) { sc_error_printf("bsp_read error, opt_len :0x%x sc_ram_len :0x%x\n", wlen, len); bsp_close(sc_fp); return BSP_ERR_SC_READ_FILE_FAIL; } else { sc_debug_printf("bsp_read ok, len is 0x%x!\n",(u32)(wlen)); } bsp_close(sc_fp); mtd = get_mtd_device_nm((char*)SC_BACKUP_SEC_NAME); if (IS_ERR(mtd)) { sc_error_printf("get mtd device err! %s\n",mtd); return BSP_ERR_READ_MTD_FAIL; } sc_mtd_len = mtd->size; sc_debug_printf("mtd len: 0x%x\n",sc_mtd_len); put_mtd_device(mtd); if((sc_mtd_len < SC_MTD_PTABLE_OFFSET) || (len >= SC_MTD_PTABLE_OFFSET)) { sc_error_printf("mtd length err! sc_mtd_len: 0x%x, len: 0x%x\n",sc_mtd_len, len); return BSP_ERR_READ_LGTH_FAIL; } wlen = bsp_nand_write((char*)SC_BACKUP_SEC_NAME, (sc_mtd_len - SC_MTD_PTABLE_OFFSET), pdata, len); if(wlen != BSP_OK) { sc_error_printf("mtd length err! wlen 0x%x, len is 0x%x\n",wlen,len); return BSP_ERR_SC_WRITE_FILE_FAIL; } sc_debug_printf("sc write to nand ok, len is 0x%x!\n",(u32)(wlen)); return SC_OK; }
static struct super_block *jffs2_get_sb_mtd(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, struct mtd_info *mtd) { struct super_block *sb; struct jffs2_sb_info *c; int ret; c = kmalloc(sizeof(*c), GFP_KERNEL); if (!c) return ERR_PTR(-ENOMEM); memset(c, 0, sizeof(*c)); c->mtd = mtd; sb = sget(fs_type, jffs2_sb_compare, jffs2_sb_set, c); if (IS_ERR(sb)) goto out_put; if (sb->s_root) { /* New mountpoint for JFFS2 which is already mounted */ D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): Device %d (\"%s\") is already mounted\n", mtd->index, mtd->name)); goto out_put; } D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): New superblock for device %d (\"%s\")\n", mtd->index, mtd->name)); /* Initialize JFFS2 superblock locks, the further initialization will be * done later */ init_MUTEX(&c->alloc_sem); init_MUTEX(&c->erase_free_sem); init_waitqueue_head(&c->erase_wait); init_waitqueue_head(&c->inocache_wq); spin_lock_init(&c->erase_completion_lock); spin_lock_init(&c->inocache_lock); sb->s_op = &jffs2_super_operations; sb->s_flags = flags | MS_NOATIME; ret = jffs2_do_fill_super(sb, data, (flags&MS_VERBOSE)?1:0); if (ret) { /* Failure case... */ up_write(&sb->s_umount); deactivate_super(sb); return ERR_PTR(ret); } sb->s_flags |= MS_ACTIVE; return sb; out_put: kfree(c); put_mtd_device(mtd); return sb; }
static int __init nandflash_bitfliptest_init(void) { int err = 0; uint64_t tmp = 0; pr_info(KERN_INFO "\n"); pr_info(KERN_INFO "=================================================\n"); if (dev < 0) { pr_info("Please specify a valid mtd-device via module parameter\n"); return -EINVAL; } pr_info("MTD device: %d\n", dev); mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); pr_info("error: cannot get MTD device\n"); return err; } mtd_part = (struct mtd_part *)mtd; if (mtd->type != MTD_NANDFLASH) { pr_info("this test requires NAND flash\n"); goto out; } tmp = mtd->size; do_div(tmp, mtd->erasesize); ebcnt = tmp; pgcnt = mtd->erasesize / mtd->writesize; pgsize = mtd->writesize; pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize, mtd->writesize, ebcnt, pgcnt, mtd->oobsize); err = mtd_test_scan_bad_block(); if (err) goto out; err = mtd_test_bitfliptest(); if(err) { pr_err("bitfliptest failed!\n"); goto out; } out: pr_info(KERN_INFO "=================================================\n"); if(bbt != NULL) vfree(bbt); put_mtd_device(mtd); return -1; }
static void jffs2_kill_sb(struct super_block *sb) { struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); if (!(sb->s_flags & MS_RDONLY)) jffs2_stop_garbage_collect_thread(c); generic_shutdown_super(sb); put_mtd_device(c->mtd); kfree(c); }
/* * get a superblock on an MTD-backed filesystem */ static struct dentry *mount_mtd_aux(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, struct mtd_info *mtd, int (*fill_super)(struct super_block *, void *, int)) { struct super_block *sb; int ret; sb = sget(fs_type, get_sb_mtd_compare, get_sb_mtd_set, mtd); if (IS_ERR(sb)) goto out_error; if (sb->s_root) goto already_mounted; /* fresh new superblock */ DEBUG(1, "MTDSB: New superblock for device %d (\"%s\")\n", mtd->index, mtd->name); sb->s_flags = flags; ret = fill_super(sb, data, flags & MS_SILENT ? 1 : 0); if (ret < 0) { deactivate_locked_super(sb); return ERR_PTR(ret); } /* go */ sb->s_flags |= MS_ACTIVE; return dget(sb->s_root); /* new mountpoint for an already mounted superblock */ already_mounted: DEBUG(1, "MTDSB: Device %d (\"%s\") is already mounted\n", mtd->index, mtd->name); put_mtd_device(mtd); return dget(sb->s_root); out_error: put_mtd_device(mtd); return ERR_CAST(sb); }
static int mt76_get_of_eeprom(struct mt76_dev *dev, int len) { #ifdef CONFIG_OF struct device_node *np = dev->dev->of_node; struct mtd_info *mtd; const __be32 *list; const char *part; phandle phandle; int offset = 0; int size; size_t retlen; int ret; if (!np) return -ENOENT; list = of_get_property(np, "mediatek,mtd-eeprom", &size); if (!list) return -ENOENT; phandle = be32_to_cpup(list++); if (!phandle) return -ENOENT; np = of_find_node_by_phandle(phandle); if (!np) return -EINVAL; part = of_get_property(np, "label", NULL); if (!part) part = np->name; mtd = get_mtd_device_nm(part); if (IS_ERR(mtd)) return PTR_ERR(mtd); if (size <= sizeof(*list)) return -EINVAL; offset = be32_to_cpup(list); ret = mtd_read(mtd, offset, len, &retlen, dev->eeprom.data); put_mtd_device(mtd); if (ret) return ret; if (retlen < len) return -EINVAL; return 0; #else return -ENOENT; #endif }
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& * Function: mtd_Flash_Release * Inputs: none * Outputs: PASS=0 (notice 0=ok here) * Description: Releases the flash. * *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ int mtd_Flash_Release(void) { nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", __FILE__, __LINE__, __func__); if (!spectra_mtd) return PASS; put_mtd_device(spectra_mtd); spectra_mtd = NULL; return PASS; }
static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev) { int ret = -EINVAL; #ifdef CONFIG_OF static struct firmware mtd_fw; struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL; size_t retlen, len = rt2x00dev->ops->eeprom_size; int size, offset = 0; struct mtd_info *mtd; const char *part; const __be32 *list; phandle phandle; list = of_get_property(np, "ralink,mtd-eeprom", &size); if (!list) { dev_err(rt2x00dev->dev, "failed to load eeprom property\n"); return -ENOENT; } phandle = be32_to_cpup(list++); if (phandle) mtd_np = of_find_node_by_phandle(phandle); if (!mtd_np) { dev_err(rt2x00dev->dev, "failed to load mtd phandle\n"); return -EINVAL; } part = of_get_property(mtd_np, "label", NULL); if (!part) part = mtd_np->name; mtd = get_mtd_device_nm(part); if (IS_ERR(mtd)) { dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part); return PTR_ERR(mtd); } if (size > sizeof(*list)) offset = be32_to_cpup(list); ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom); put_mtd_device(mtd); if (!ret) { rt2x00dev->eeprom_file = &mtd_fw; mtd_fw.size = len; mtd_fw.data = (const u8 *) rt2x00dev->eeprom; } #endif return ret; }
/*=========================================================================== FUNCTION FLASH_NAND_OPER_REGION_INIT DESCRIPTION Initilize user partition info,and get the handle of nand flash RETURN VALUE TRUE if Op Succeed FALSE if Op Failure SIDE EFFECTS None ===========================================================================*/ oper_region_struct_t *flash_nand_oper_region_init( oper_region_type oper_region_idx) { uint8 idx = (uint8)oper_region_idx; char *parent_name_ptr = NULL; unsigned int offset = 0; /* 范围保护 */ if (idx >= REGION_MAX) { printk(KERN_ERR "Parm error: idx = %d max_ids = %d\n",idx,REGION_MAX); return NULL; } /*lint -e662*/ parent_name_ptr = (char *)child_region[idx].parent_name; printk(KERN_DEBUG "parent_name_ptr =%s \n",parent_name_ptr); /*lint +e662*/ /*lint -e661*/ offset = child_region[idx].offset; /*lint +e661*/ /* get mtd device */ g_mtd = get_mtd_device_nm(parent_name_ptr); if (NULL == g_mtd) { printk(KERN_ERR "get_mtd_device_nm error\n"); return NULL; } printk(" info :mtd->erasesize = %d ,mtd->writesize = %d \n", g_mtd->erasesize,g_mtd->writesize); /* get the flash address */ operation_region[idx].block_size = g_mtd->erasesize; operation_region[idx].page_size = g_mtd->writesize; operation_region[idx].start_addr = (offset * operation_region[idx].block_size); operation_region[idx].buffer = himalloc(operation_region[idx].page_size); printk(KERN_DEBUG "operation_region[%d] = %u \n", idx, (unsigned int)operation_region[idx].start_addr); if (NULL == operation_region[idx].buffer) { put_mtd_device(g_mtd); return NULL; } /* 初始化读写flash时使用的缓冲区 */ memset((void *)operation_region[idx].buffer, NAND_FILL_CHAR_APP, operation_region[idx].page_size); return &operation_region[idx]; }
static int load_param_value(void) { unsigned char *addr = NULL; unsigned int ret = 0; struct mtd_info *mtd; unsigned int retlen; addr = vmalloc(PARAM_LEN); if (!addr) return -ENOMEM; preempt_enable(); mtd = get_mtd_device_nm("param"); if (IS_ERR(mtd)) { printk("(%s)Cannot find param partition.\n",__func__); goto fail; } ret = mtd->read(mtd, 0x30000, PARAM_LEN, &retlen, addr); if (ret || retlen != PARAM_LEN) { printk("(%s)Failed to read param block.\n", __func__); put_mtd_device(mtd); goto fail; } if (is_valid_param((param_status_t *)addr)) { printk("param is valid\n"); memcpy(¶m_status, addr, sizeof(param_status_t)); } put_mtd_device(mtd); fail: vfree(addr); preempt_disable(); return ret; }
int nettel_eraseconfig(void) { struct mtd_info *mtd; DECLARE_WAITQUEUE(wait, current); wait_queue_head_t wait_q; int ret; init_waitqueue_head(&wait_q); mtd = get_mtd_device(NULL, 2); if (mtd) { nettel_erase.mtd = mtd; nettel_erase.callback = nettel_erasecallback; nettel_erase.callback = NULL; nettel_erase.addr = 0; nettel_erase.len = mtd->size; nettel_erase.priv = (u_long) &wait_q; nettel_erase.priv = 0; set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&wait_q, &wait); ret = mtd->erase(mtd, &nettel_erase); if (ret) { set_current_state(TASK_RUNNING); remove_wait_queue(&wait_q, &wait); put_mtd_device(mtd); return(ret); } schedule(); /* Wait for erase to finish. */ remove_wait_queue(&wait_q, &wait); put_mtd_device(mtd); } return(0); }
static int spectra_open(struct inode *inode, struct file *file) { struct spectra_device *dev; struct mtd_info *mtd; int err; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (unlikely(!dev)) return -ENOMEM; dev->mtd = mtd = get_mtd_device_nm(CEFDK_CFG_PARTITION); if (unlikely(IS_ERR(mtd))) { printk(KERN_ERR DRV_NAME ": mtd partition '" CEFDK_CFG_PARTITION "' not found\n"); err = -ENXIO; goto out_free; } if (unlikely(mtd->type != MTD_NANDFLASH)) { printk(KERN_ERR DRV_NAME ": not a NAND partition\n"); err = -ENXIO; goto out_put; } BUG_ON(mtd->writesize > sizeof(dev->buf)); dev->device_info.writesize = mtd->writesize; dev->device_info.oobsize = mtd->oobsize; dev->device_info.pagesize = mtd->writesize + mtd->oobsize; dev->device_info.erasesize = mtd->erasesize; dev->device_info.blockpages = mtd_div_by_ws(mtd->erasesize, mtd); dev->device_info.blocksize = dev->device_info.pagesize * dev->device_info.blockpages; dev->device_info.blocks = CEFDK_CFG_PARTITION_OFFSET + mtd_div_by_eb(mtd->size, mtd); DBG("sizeof(device_info) 0x%x\n", sizeof(dev->device_info)); file->private_data = dev; return 0; out_put: put_mtd_device(dev->mtd); out_free: kfree(dev); return err; }
static struct super_block *jffs2_get_sb_mtd(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, struct mtd_info *mtd) { struct super_block *sb; struct jffs2_sb_info *c; int ret; c = kmalloc(sizeof(*c), GFP_KERNEL); if (!c) return ERR_PTR(-ENOMEM); memset(c, 0, sizeof(*c)); c->mtd = mtd; sb = sget(fs_type, jffs2_sb_compare, jffs2_sb_set, c); if (IS_ERR(sb)) goto out_put; if (sb->s_root) { /* New mountpoint for JFFS2 which is already mounted */ D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): Device %d (\"%s\") is already mounted\n", mtd->index, mtd->name)); goto out_put; } D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): New superblock for device %d (\"%s\")\n", mtd->index, mtd->name)); sb->s_op = &jffs2_super_operations; ret = jffs2_do_fill_super(sb, data, (flags&MS_VERBOSE)?1:0); if (ret) { /* Failure case... */ up_write(&sb->s_umount); deactivate_super(sb); return ERR_PTR(ret); } sb->s_flags |= MS_ACTIVE; return sb; out_put: kfree(c); put_mtd_device(mtd); return sb; }
static struct mtd_info *get_mtd_named(char *name) { int i; struct mtd_info *mtd; for (i = 0; i < MAX_MTD_DEVICES; i++) { mtd = get_mtd_device(NULL, i); if (!IS_ERR(mtd)) { if (strcmp(mtd->name, name) == 0) return(mtd); put_mtd_device(mtd); } } return(NULL); }
static int mtd_close(struct inode *inode, struct file *file) { struct mtd_info *mtd; DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); mtd = (struct mtd_info *)file->private_data; if (mtd->sync) mtd->sync(mtd); put_mtd_device(mtd); return 0; } /* mtd_close */