Example #1
0
/*
	0: no physic arch info;
	1: ok;
	-1: fail;
*/
__s32 _GetOldPhysicArch(void *phy_arch, __u32 *good_blk_no)
{
	__s32 ret, ret2 = 0;
	__u32 b, chip = 0;
	__u32 start_blk=12, blk_cnt=100;
	__u8 oob[128];
	struct __NandStorageInfo_t *parch;
	struct boot_physical_param nand_op;

	//parch = (struct __NandStorageInfo_t *)PHY_TMP_PAGE_CACHE;
	parch = (struct __NandStorageInfo_t *)MALLOC(64*1024);
	if(!parch)
	{
		PRINT("%s,malloc fail\n",__func__);
		ret2 = -1;
		goto EXIT;
	}

	for (b=start_blk; b<start_blk+blk_cnt; b++)
	{
		nand_op.chip = chip;
		nand_op.block = b;
		nand_op.page = 0;
		nand_op.mainbuf = (void *)parch;
		nand_op.oobbuf = oob;

		ret = PHY_SimpleRead(&nand_op); //PHY_SimpleRead_CurCH(&nand_op);
		PHY_DBG("_GetOldPhysicArch: ch: %d, chip %d, block %d, page 0, "
				"oob: 0x%x, 0x%x, 0x%x, 0x%x\n",NandIndex,nand_op.chip, nand_op.block,
				oob[0], oob[1], oob[2], oob[3]);
		if (ret>=0)
		{
			if (oob[0]==0x00)
			{
				if ((oob[1]==0x50) && (oob[2]==0x48) && (oob[3]==0x59) && (oob[4]==0x41) && (oob[5]==0x52) && (oob[6]==0x43) && (oob[7]==0x48))
				{
					//*((struct __NandStorageInfo_t *)phy_arch) = *parch;
					if((parch->PlaneCntPerDie !=1) && (parch->PlaneCntPerDie !=2))
					{
						PHY_DBG("_GetOldPhysicArch: get old physic arch ok,but para error: 0x%x 0x%x!\n", parch->OperationOpt, parch->PlaneCntPerDie);
					}
					else
					{
						MEMCPY(phy_arch, parch, sizeof(struct __NandStorageInfo_t));
						PHY_DBG("_GetOldPhysicArch: get old physic arch ok, 0x%x 0x%x!\n", parch->OperationOpt, parch->PlaneCntPerDie);
						ret2 = 1;
						break;
					}
				}
				else
				{
					PHY_DBG("_GetOldPhysicArch: mark bad block!\n");
				}
			}
			else if(oob[0]==0xff)
			{
				PHY_DBG("_GetOldPhysicArch: find a good block, but no physic arch info.\n");
				ret2 = 2;//blank page
				break;
			}
			else
			{
				PHY_DBG("_GetOldPhysicArch: unkonwn1!\n");
			}
		}
		else
		{
			if (oob[0]==0xff)
			{
				PHY_DBG("_GetOldPhysicArch: blank block!\n");
				ret2 = 2;
				break;
			}
			else if (oob[0]==0)
			{
				PHY_DBG("_GetOldPhysicArch: bad block!\n");
			}
			else
			{
				PHY_DBG("_GetOldPhysicArch: unkonwn2!\n");
			}
		}
	}

	if (b == (start_blk+blk_cnt)) {
		ret2 = -1;
		*good_blk_no = 0;
	} else
		*good_blk_no = b;

EXIT:
    FREE(parch, 64*1024);

	return ret2;
}
/*
************************************************************************************************************************
*                       READ ONE SINGLE PAGE
*
*Description: read one page data from nand based on single plane;
*
*Arguments  : *readop - the structure with physical address in nand and data buffer
*
*Return     :   = SUCESS  read ok;
*               = FAIL    read fail.
************************************************************************************************************************
*/
__s32 NAND_PhyRead (struct boot_physical_param *readop)
{

	return(PHY_SimpleRead (readop));

}