Example #1
0
URET uffs_InitDevice(uffs_Device *dev)
{
    URET ret;

    ret = uffs_InitDeviceConfig(dev);
    if (ret != U_SUCC)
        return U_FAIL;

    if (dev->mem.init) {
        if (dev->mem.init(dev) != U_SUCC) {
            uffs_Perror(UFFS_MSG_SERIOUS, "Init memory allocator fail.");
            return U_FAIL;
        }
    }

    memset(&(dev->st), 0, sizeof(uffs_FlashStat));

    uffs_DeviceInitLock(dev);
    uffs_BadBlockInit(dev);


    if (uffs_FlashInterfaceInit(dev) != U_SUCC) {
        uffs_Perror(UFFS_MSG_SERIOUS, "Can't initialize flash interface !");
        goto fail;
    }

    uffs_Perror(UFFS_MSG_NOISY, "init page buf");
    ret = uffs_BufInit(dev, dev->cfg.page_buffers, dev->cfg.dirty_pages);
    if (ret != U_SUCC) {
        uffs_Perror(UFFS_MSG_DEAD, "Initialize page buffers fail");
        goto fail;
    }
    uffs_Perror(UFFS_MSG_NOISY, "init block info cache");
    ret = uffs_BlockInfoInitCache(dev, dev->cfg.bc_caches);
    if (ret != U_SUCC) {
        uffs_Perror(UFFS_MSG_DEAD, "Initialize block info fail");
        goto fail;
    }

    ret = uffs_TreeInit(dev);
    if (ret != U_SUCC) {
        uffs_Perror(UFFS_MSG_SERIOUS, "fail to init tree buffers");
        goto fail;
    }

    ret = uffs_BuildTree(dev);
    if (ret != U_SUCC) {
        uffs_Perror(UFFS_MSG_SERIOUS, "fail to build tree");
        goto fail;
    }

    return U_SUCC;

fail:
    uffs_DeviceReleaseLock(dev);

    return U_FAIL;
}
Example #2
0
URET uffs_InitDevice(uffs_Device *dev)
{
	URET ret;

	if (dev->mem.init) {
		if (dev->mem.init(dev) != U_SUCC) {
			uffs_Perror(UFFS_ERR_SERIOUS, "Init memory allocator fail.");
			return U_FAIL;
		}
	}

	memset(&(dev->st), 0, sizeof(uffs_FlashStat));

	uffs_DeviceInitLock(dev);
	uffs_BadBlockInit(dev);

	if (uffs_FlashInterfaceInit(dev) != U_SUCC) {
		uffs_Perror(UFFS_ERR_SERIOUS, "Can't initialize flash interface !");
		goto fail;
	}

	uffs_Perror(UFFS_ERR_NOISY, "init page buf");
	ret = uffs_BufInit(dev, MAX_PAGE_BUFFERS, MAX_DIRTY_PAGES_IN_A_BLOCK);
	if (ret != U_SUCC) {
		uffs_Perror(UFFS_ERR_DEAD, "Initialize page buffers fail");
		goto fail;
	}
	uffs_Perror(UFFS_ERR_NOISY, "init block info cache");
	ret = uffs_BlockInfoInitCache(dev, MAX_CACHED_BLOCK_INFO);
	if (ret != U_SUCC) {
		uffs_Perror(UFFS_ERR_DEAD, "Initialize block info fail");
		goto fail;
	}

	ret = uffs_TreeInit(dev);
	if (ret != U_SUCC) {
		uffs_Perror(UFFS_ERR_SERIOUS, "fail to init tree buffers");
		goto fail;
	}

	ret = uffs_BuildTree(dev);
	if (ret != U_SUCC) {
		uffs_Perror(UFFS_ERR_SERIOUS, "fail to build tree");
		goto fail;
	}

	return U_SUCC;

fail:
	uffs_DeviceReleaseLock(dev);

	return U_FAIL;
}