Beispiel #1
0
__s32 _SetNewPhysicArch(void *phy_arch)
{
	__s32 ret;
	__u32 i, b, p, chip = 0;
	__u32 start_blk=12, blk_cnt=100;
	__u8 oob[128];
	__u32 good_blk_no;
	struct __NandStorageInfo_t *parch;
	struct __NandStorageInfo_t arch_tmp = {0};
	struct boot_physical_param nand_op;

    //parch = (struct __NandStorageInfo_t *)PHY_TMP_PAGE_CACHE;
	parch = (struct __NandStorageInfo_t *)MALLOC(64*1024);

	/* in order to get good block, get old physic arch info */
	ret = _GetOldPhysicArch(&arch_tmp, &good_blk_no);
	if (ret == -1) {
		/* can not find good block */
		PHY_ERR("_SetNewPhysicArch: can not find good block: 12~112\n");
		FREE(parch, 64*1024);
		return ret;
	}

	PHY_DBG("_SetNewPhysicArch: write physic arch to blk %d...\n", good_blk_no);

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

		ret = PHY_SimpleErase(&nand_op); //PHY_SimpleErase_CurCH(&nand_op);
		if (ret<0)
		{
			PHY_ERR("_SetNewPhysicArch: erase chip %d, block %d error\n", nand_op.chip, nand_op.block);

			for (i=0; i<128; i++)
		    	oob[i] = 0x0;

			for (p=0; p<NandStorageInfo.PageCntPerPhyBlk; p++)
			{
				nand_op.page = p;
				ret = PHY_SimpleWrite(&nand_op); //PHY_SimpleWrite_CurCH(&nand_op);
				if (ret<0) {
					PHY_ERR("_SetNewPhysicArch: mark bad block, write chip %d, block %d, page %d error\n", nand_op.chip, nand_op.block, nand_op.page);
				}
			}
		}
		else
		{
			PHY_DBG("_SetNewPhysicArch: erase block %d ok.\n", b);

			for (i=0; i<128; i++)
		    	oob[i] = 0x88;
		    oob[0] = 0x00; //bad block flag
			oob[1] = 0x50; //80; //'P'
			oob[2] = 0x48; //72; //'H'
			oob[3] = 0x59; //89; //'Y'
			oob[4] = 0x41; //65; //'A'
			oob[5] = 0x52; //82; //'R'
			oob[6] = 0x43; //67; //'C'
			oob[7] = 0x48; //72; //'H'

			//MEMSET(parch, 0x0, 1024);
			MEMCPY(parch, phy_arch, sizeof(struct __NandStorageInfo_t));
			//*parch = *((struct __NandStorageInfo_t *)phy_arch);
			for (p=0; p<NandStorageInfo.PageCntPerPhyBlk; p++)
			{
				nand_op.page = p;
				ret = PHY_SimpleWrite(&nand_op); //PHY_SimpleWrite_CurCH(&nand_op);
				if(ret<0)
				{
					PHY_ERR("_SetNewPhysicArch: write chip %d, block %d, page %d error\n", nand_op.chip, nand_op.block, nand_op.page);
					FREE(parch, 64*1024);
					return -1;
				}
			}
			break;
		}
	}

	PHY_DBG("_SetNewPhysicArch: ============\n");
    ret = _GetOldPhysicArch(&arch_tmp, &good_blk_no);
	if (ret == -1) {
		/* can not find good block */
		PHY_ERR("_SetNewPhysicArch: can not find good block: 12~112\n");
		FREE(parch, 64*1024);
		return ret;
	}

	FREE(parch, 64*1024);

	return 0;
}
/*
************************************************************************************************************************
*                       ERASE ONE SINGLE BLOCK
*
*Description: erase one block in nand based on single plane;
*
*Arguments  : *eraseop - the structure with physical address in nand and data buffer
*
*Return     :   = SUCESS  	erase ok;
*               = FAIL    	erase fail.
*				= BADBLOCK	erase fail and bad block made by erase
************************************************************************************************************************
*/
__s32 NAND_PhyErase(struct boot_physical_param *eraseop)
{
	return (PHY_SimpleErase (eraseop ));
}