示例#1
0
文件: nand.c 项目: eagle860/bare
int nand_read(unsigned int nand_start, unsigned int ddr_start, unsigned int len)
{
	unsigned int addr = nand_start;
	int i, count = 0;
	unsigned char *dest = (unsigned char *)ddr_start;
	
	/* 选中芯片 */
	nand_select();

	while (count < len)
	{
		/* 发出命令0x00 */
		nand_cmd(0x00);

		/* 发出地址 */
		nand_send_addr(addr);

		/* 发出命令0x30 */
		nand_cmd(0x30);

		/* 等待就绪 */
		wait_ready();

		/* 读数据 */
		for (i = 0; i < 2048 && count < len; i++)
		{
			dest[count++] = nand_get_data();
		}

		addr += 2048;			
	}

	/* 取消片选 */
	nand_deselect();
	return 0;
}
示例#2
0
文件: ftl.c 项目: cantona/iphonelinux
int ftl_setup() {
	if(HasFTLInit)
		return 0;

	nand_setup();

	Data = nand_get_geometry();
	Data2 = nand_get_data();

	if(VFL_Init() != 0) {
		bufferPrintf("ftl: VFL_Init failed\r\n");
		return -1;
	}

	if(FTL_Init() != 0) {
		bufferPrintf("ftl: FTL_Init failed\r\n");
		return -1;
	}

	int i;
	int foundSignature = FALSE;

	DebugPrintf("ftl: Attempting to read %d pages from first block of first bank.\r\n", Data->pagesPerBlock);
	uint8_t* buffer = malloc(Data->bytesPerPage);
	for(i = 0; i < Data->pagesPerBlock; i++) {
		int ret;
		if((ret = nand_read_alternate_ecc(0, i, buffer)) == 0) {
			uint32_t id = *((uint32_t*) buffer);
			if(id == FTL_ID_V1 || id == FTL_ID_V2) {
				bufferPrintf("ftl: Found production format: %x\r\n", id);
				foundSignature = TRUE;
				break;
			} else {
				DebugPrintf("ftl: Found non-matching signature: %x\r\n", ((uint32_t*) buffer));
			}
		} else {
			DebugPrintf("ftl: page %d of first bank is unreadable: %x!\r\n", i, ret);
		}
	}
	free(buffer);

	if(!foundSignature || !hasDeviceInfoBBT()) {
		bufferPrintf("ftl: no signature or production format.\r\n");
		return -1;
	}

	if(VFL_Open() != 0) {
		bufferPrintf("ftl: VFL_Open failed\r\n");
		return -1;
	}

	int pagesAvailable;
	int bytesPerPage;
	if(FTL_Open(&pagesAvailable, &bytesPerPage) != 0) {
		bufferPrintf("ftl: FTL_Open failed\r\n");
		return -1;
	}

	HasFTLInit = TRUE;

	return 0;
}