Exemple #1
0
static int init_uffs_fs(
	struct _nand_dev * nand_part)
{
    uffs_MountTable * mtb;
    struct rt_mtd_nand_device * nand;
    struct uffs_StorageAttrSt * flash_storage;

    mtb = &nand_part->mount_table;
    nand = nand_part->dev;
    flash_storage = &nand_part->storage;

	/* setup nand storage attributes */
	uffs_setup_storage(flash_storage, nand);

	/* register mount table */
	if(mtb->dev)
	{
		/* set memory allocator for uffs */
#if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0
		uffs_MemSetupSystemAllocator(&mtb->dev->mem);
#endif
		/* setup device init/release entry */
		mtb->dev->Init = _device_init;
		mtb->dev->Release = _device_release;
		mtb->dev->attr = flash_storage;

		uffs_RegisterMountTable(mtb);
	}
	/* mount uffs partion on nand device */
	return uffs_Mount(nand_part->mount_path) == U_SUCC ? 0 : -1;
}
static int my_init_filesystem(void)
{
	uffs_MountTable *mtbl = &(demo_mount_table[0]);

	/* setup nand storage attributes */
	setup_flash_storage(&g_my_flash_storage);

	/* setup memory allocator */
	uffs_MemSetupStaticAllocator(&demo_device_1.mem, static_buffer_par1, sizeof(static_buffer_par1));
	uffs_MemSetupStaticAllocator(&demo_device_2.mem, static_buffer_par2, sizeof(static_buffer_par2));

	/* register mount table */
	while(mtbl->dev) {
		// setup device init/release entry
		mtbl->dev->Init = my_InitDevice;
		mtbl->dev->Release = my_ReleaseDevice;
		uffs_RegisterMountTable(mtbl);
		mtbl++;
	}

	// mount partitions
	for (mtbl = &(demo_mount_table[0]); mtbl->mount != NULL; mtbl++) {
		uffs_Mount(mtbl->mount);
	}

	return uffs_InitFileSystemObjects() == U_SUCC ? 0 : -1;
}
Exemple #3
0
static int dfs_uffs_mkfs(const char* device_name)
{
	rt_base_t index;
	rt_uint32_t block;
	struct rt_mtd_nand_device * mtd;

	/*1. find the device index */
	for (index = 0; index < UFFS_DEVICE_MAX; index++)
	{
		if (rt_strncmp(nand_part[index].dev->parent.parent.name,
				       device_name, RT_NAME_MAX) == 0)
			break;
	}

	if (index == UFFS_DEVICE_MAX)
	{
		/* can't find device driver */
		rt_kprintf("can not find device driver: %s\n", device_name);
		return -DFS_STATUS_ENOENT;
	}

	/*2. then unmount the partition */
	uffs_Mount(nand_part[index].mount_path);
	mtd = nand_part[index].dev;

	/*3. erase all blocks on the partition */
	block = mtd->block_start;
	for (; block <= mtd->block_end; block++)
	{
		rt_mtd_nand_erase_block(mtd, block);
		if (rt_mtd_nand_check_block(mtd, block) != RT_EOK)
		{
			rt_kprintf("found bad block %d\n", block);
			rt_mtd_nand_mark_badblock(mtd, block);
		}
	}

	/*4. remount it */
	if (init_uffs_fs(&nand_part[index]) < 0)
	{
		return uffs_result_to_dfs(uffs_get_error());
	}
	return DFS_STATUS_OK;
}
Exemple #4
0
static int dfs_uffs_mkfs(rt_device_t dev_id)
{
    rt_base_t index;
    rt_uint32_t block;
    struct rt_mtd_nand_device * mtd;

    /*1. find the device index */
    for (index = 0; index < UFFS_DEVICE_MAX; index++)
    {
        if (nand_part[index].dev == (struct rt_mtd_nand_device *)dev_id)
            break;
    }

    if (index == UFFS_DEVICE_MAX)
    {
        /* can't find device driver */
        return -ENOENT;
    }

    /*2. then unmount the partition */
    uffs_Mount(nand_part[index].mount_path);
    mtd = nand_part[index].dev;

    /*3. erase all blocks on the partition */
    block = mtd->block_start;
    for (; block <= mtd->block_end; block++)
    {
        rt_mtd_nand_erase_block(mtd, block);
        if (rt_mtd_nand_check_block(mtd, block) != RT_EOK)
        {
            rt_kprintf("found bad block %d\n", block);
            rt_mtd_nand_mark_badblock(mtd, block);
        }
    }

    /*4. remount it */
    if (init_uffs_fs(&nand_part[index]) < 0)
    {
        return uffs_result_to_dfs(uffs_get_error());
    }
    return RT_EOK;
}
/** mount partition or show mounted partitions
 *		mount [<mount>]
 */
static int cmd_mount(int argc, char *argv[])
{
	uffs_MountTable *tab;
	const char *mount = NULL;

	if (argc == 1) {
		tab = uffs_MtbGetMounted();
		while (tab) {
			MSG(" %s : (%d) ~ (%d)\n", tab->mount, tab->start_block, tab->end_block);
			tab = tab->next;
		}
	}
	else {
		mount = argv[1];
		if (uffs_Mount(mount) < 0) {
			MSGLN("Can't mount %s", mount);
			return -1;
		}
	}
	return 0;
}
static int init_uffs_fs(void)
{
	static int bIsFileSystemInited = 0;
	struct uffs_MountTableEntrySt *mtbl = &(conf_mounts[0]);
	struct uffs_ConfigSt cfg = {
		0,			// bc_caches - default
		0,			// page_buffers - default
		0,			// dirty_pages - default
		0,			// dirty_groups - default
		0,			// reserved_free_blocks - default
	};

	if (bIsFileSystemInited)
		return -4;

	bIsFileSystemInited = 1;

	while (mtbl->dev) {

		memcpy(&mtbl->dev->cfg, &cfg, sizeof(struct uffs_ConfigSt));

#if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0
		uffs_MemSetupSystemAllocator(&mtbl->dev->mem);
#endif
		setup_device(mtbl->dev);
		uffs_RegisterMountTable(mtbl);
		mtbl++;
	}

	// mount partitions
	for (mtbl = &(conf_mounts[0]); mtbl->mount != NULL; mtbl++) {
		uffs_Mount(mtbl->mount);
	}

	return uffs_InitFileSystemObjects() == U_SUCC ? 0 : -1;
}