static int  CheckInit(yaffs_Device *dev)
{
	static int initialised = 0;
	
	int i;
	int fail = 0;
	int nAllocated = 0;
	
	if(initialised) 
	{
		return YAFFS_OK;
	}

	initialised = 1;
	
	
	ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
	
	ramdisk.block = YMALLOC(sizeof(yflash_Block *) * ramdisk.nBlocks);
	
	if(!ramdisk.block) return 0;
	
	for(i=0; i <ramdisk.nBlocks; i++)
	{
		ramdisk.block[i] = NULL;
	}
	
	for(i=0; i <ramdisk.nBlocks && !fail; i++)
	{
		if((ramdisk.block[i] = YMALLOC(sizeof(yflash_Block))) == 0)
		{
			fail = 1;
		}
		else
		{
			yflash_EraseBlockInNAND(dev,i);
			nAllocated++;
		}
	}
	
	if(fail)
	{
		for(i = 0; i < nAllocated; i++)
		{
			YFREE(ramdisk.block[i]);
		}
		YFREE(ramdisk.block);
		
		T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
		   nAllocated/64,ramdisk.nBlocks * YAFFS_BYTES_PER_BLOCK));
		return 0;
	}
	
	
	
	return 1;
}
Пример #2
0
/* 
purpose: format the disk partition.
const char *disk: the partition name 
char force: 0 - dont format the bad block.
	    1 - force format the bad block.
*/
void yaffs_format_partition(const char *disk, char force)
{
	int i;
	
	if(strcmp(disk, "/mnt")==0)
	{
		printf("yaffs formatting partition(/mnt) %d ... \n",force);
		for(i=flashDev0.startBlock; i<=flashDev0.endBlock; i++)
		{
			if(!force)
			{
				if(nand_flash_query_block(i)!=0xFF)
					continue;
			}
			yflash_EraseBlockInNAND(&flashDev0, i);
		}
	}
	
	if(strcmp(disk, "/flash")==0)
	{
		printf("yaffs formatting partition(/flash) %d ... \n",force);
		for(i=flashDev1.startBlock; i<=flashDev1.endBlock; i++)
		{
			if(!force)
			{
				if(nand_flash_query_block(i)!=0xFF)
					continue;
			}
			yflash_EraseBlockInNAND(&flashDev1, i);
		}
	}

	printf("yaffs finished format partition!\n");

	return;
}