__s32 BMM_MergeAllLogBlock(void) { __u32 tmpZoneNum, ZoneCnt, tmpLogPos; __s32 result; ZoneCnt = ZONE_CNT_OF_DIE * DieCntOfNand; PRINT("BMM_MergeAllLogBlock, ZoneCnt: %x\n", ZoneCnt); for(tmpZoneNum=0; tmpZoneNum<ZoneCnt; tmpZoneNum++) { PRINT("BMM_MergeAllLogBlock, tmpZoneNum: %x\n", tmpZoneNum); //swap the block mapping table to ram which is need be accessing currently if(tmpLogicalBlk!= 0xffff) LML_MergeLogBlk_Quit(); result = BMM_SwitchMapTbl(tmpZoneNum); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] BMM_MergeAllLogBlock, Switch block mapping table failed when read logical page! Err:0x%x\n", result); return -ERR_MAPPING; } BMM_SetDirtyFlag(); for(tmpLogPos = 0; tmpLogPos<MAX_LOG_BLK_CNT; tmpLogPos++) { if(LOG_BLK_TBL[tmpLogPos].LogicBlkNum != 0xffff) { PRINT("BMM_MergeAllLogBlock, logpos: %x, logblock: %x\n", tmpLogPos, LOG_BLK_TBL[tmpLogPos].LogicBlkNum); //need swap the page mapping table to ram which is accessing currently result = PMM_SwitchMapTbl(tmpLogPos); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] BMM_MergeAllLogBlock, Switch page mapping table failed when switch page map table! Err:0x%x\n", result); return -1; } result = LML_MergeLogBlk(NORMAL_MERGE_MODE,LOG_BLK_TBL[tmpLogPos].LogicBlkNum); if(result<0) { MAPPING_ERR("[MAPPING_ERR] BMM_MergeAllLogBlock, merge error! Err:0x%x\n", result); return -ERR_MAPPING; } } } } PRINT("BMM_MergeAllLogBlock end\n"); return result; }
/* ************************************************************************************************************************ * GET LOG PAGE PARAMETER * *Description: Get a page from log block for read or write. * *Arguments : nBlk the logical block number of the log block; * nPage the number of the logical page, which page need log page; * nMode the type of get log page, 'r' or 'w', others is invalid. * *Return : the number of the log page; * != 0xffff get log page successful, return page number; * = 0xffff get log page failed. * *Note : Scan the log block table to try to get the log block. * when the get type is 'r', if the log block is exsit and the logical * page contain a log page, return the number of the log page, else, * return 0xffff; * when the get type is 'w', if the log block is not exsit, need create * log block, then, if get log page failed, need merge the log block, and * try to get log page again, this mode should return a value page number * except there is no enough valid blocks. ************************************************************************************************************************ */ __u32 PMM_GetLogPage(__u32 nBlk, __u32 nPage, __u8 nMode) { __s32 result, tmpLogPst; __u16 tmpPage, PhyPageNum; if(nMode == 'r') { tmpLogPst = _GetLogBlkPst(nBlk); if(tmpLogPst < 0) { //get log page by read mode, there is no log block, return invalid value return INVALID_PAGE_NUM; } //need swap the page mapping table to ram which is accessing currently result = PMM_SwitchMapTbl(tmpLogPst); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Switch page mapping table failed when get log page! Err:0x%x\n", result); return INVALID_PAGE_NUM; } _CalLogAccessCnt(tmpLogPst); //get active read log block index if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[tmpLogPst].LogBlkType == LSB_TYPE)) { PhyPageNum = PAGE_MAP_TBL[nPage].PhyPageNum; if((PhyPageNum&(0x1<<15))&&(PhyPageNum!= 0xffff)) { LOG_BLK_TBL[tmpLogPst].ReadBlkIndex = 1; PhyPageNum &= 0x7fff; } else LOG_BLK_TBL[tmpLogPst].ReadBlkIndex = 0; return (PhyPageNum|LOG_BLK_TBL[tmpLogPst].ReadBlkIndex<<16); } else { LOG_BLK_TBL[tmpLogPst].ReadBlkIndex = 0; return PAGE_MAP_TBL[nPage].PhyPageNum; } } result = _GetLogPageForWrite(nBlk, nPage, &tmpPage, (__u32 *)&tmpLogPst); if(result < 0) { //get log page for write failed MAPPING_ERR("[MAPPING_ERR] Get log page for write failed!\n"); return INVALID_PAGE_NUM; } //check if the log page is valid if(!(tmpPage < PAGE_CNT_OF_SUPER_BLK)) { //the log page is not invalid, need to merge the log block, and get again result = LML_MergeLogBlk(SPECIAL_MERGE_MODE, nBlk); if(result < 0) { //merge log block failed, report error MAPPING_ERR("[MAPPING_ERR] Merge log block failed when get log page! Err:0x%x\n", result); return INVALID_PAGE_NUM; } //try to get log page for write again result = _GetLogPageForWrite(nBlk, nPage, &tmpPage, (__u32 *)&tmpLogPst); if(result < 0) { //get log page for write failed MAPPING_ERR("[MAPPING_ERR] Get log page for write failed!\n"); return INVALID_PAGE_NUM; } } //check if the log page is valid if(!(tmpPage < PAGE_CNT_OF_SUPER_BLK)) { //get log page for write failed MAPPING_ERR("[MAPPING_ERR] Get log page for write failed!\n"); return INVALID_PAGE_NUM; } else { LOG_BLK_TBL[tmpLogPst].LastUsedPage = tmpPage; } //update the page mapping table item if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[tmpLogPst].LogBlkType == LSB_TYPE)) { DBUG_MSG("[DBUG_MSG] PMM_GetLogPage 2, select bak log block\n"); PAGE_MAP_TBL[nPage].PhyPageNum = tmpPage|((LOG_BLK_TBL[tmpLogPst].WriteBlkIndex&0x1)<<15); } else PAGE_MAP_TBL[nPage].PhyPageNum = tmpPage; //set the flag that mark need update the page mapping table PAGE_MAP_CACHE->DirtyFlag = 1; _CalLogAccessCnt(tmpLogPst); if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[tmpLogPst].LogBlkType == LSB_TYPE)) return (tmpPage|LOG_BLK_TBL[tmpLogPst].WriteBlkIndex<<16); else return tmpPage; }
/* ************************************************************************************************************************ * CREATE A NEW LOG BLOCK * *Description: Create a new log block. * *Arguments : nBlk the logical block number of the log block; * pLogPst the pointer to the log block position in the log block table. * *Return : create new log block result. * = 0 create new log block successful; * =-1 create new log block failed. ************************************************************************************************************************ */ static __s32 _CreateNewLogBlk(__u32 nBlk, __u32 *pLogPst) { __s32 i, result, LogBlkType,tmpPst=-1; __u16 tmpLogAccessAge = 0xffff; struct __SuperPhyBlkType_t tmpFreeBlk, tmpFreeBlk1; struct __PhysicOpPara_t tmpPhyPage; struct __NandUserData_t tmpSpare[2]; #if CFG_SUPPORT_WEAR_LEVELLING //check if need do wear-levelling if(BLK_ERASE_CNTER >= WEAR_LEVELLING_FREQUENCY) { LML_WearLevelling(); } #endif //try to search an empty item in the log block table for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if(LOG_BLK_TBL[i].LogicBlkNum == 0xffff) { //find a empty item tmpPst = i; break; } } //there is no empty item in the log block table, need merge a log block if(tmpPst == -1) { //check if there is some full log block for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if(LOG_BLK_TBL[i].LastUsedPage == PAGE_CNT_OF_SUPER_BLK-1) { tmpPst = i; break; } } if(tmpPst == -1) { //there is no full log block, look for an oldest log block to merge for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if(LOG_ACCESS_AGE[i] < tmpLogAccessAge) { tmpLogAccessAge = LOG_ACCESS_AGE[i]; tmpPst = i; } } } //switch the page mapping table for merge the log block result = PMM_SwitchMapTbl(tmpPst); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Switch page mapping table failed when create new log block! Err:0x%x\n", result); return -1; } //merge the log block with normal type, to make an empty item result = LML_MergeLogBlk(NORMAL_MERGE_MODE, LOG_BLK_TBL[tmpPst].LogicBlkNum); if(result < 0) { //merge log block failed, report error MAPPING_ERR("[MAPPING_ERR] Merge log block failed when create new log block! Err:0x%x\n", result); return -1; } } LogBlkType = BMM_CalLogBlkType(nBlk); if((SUPPORT_LOG_BLOCK_MANAGE)&&(LogBlkType == LSB_TYPE)) { DBUG_MSG("[DBUG_MSG] _CreateNewLogBlk, select bak log block\n"); //get a free block to create a new log block result = BMM_GetFreeBlk(LOWEST_EC_TYPE, &tmpFreeBlk); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Get free block failed when create new log block!\n"); return -1; } //get a free block to create a new log block result = BMM_GetFreeBlk(LOWEST_EC_TYPE, &tmpFreeBlk1); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Get free block failed when create new log block!\n"); return -1; } //DBUG_INF("[DBUG] _CreateNewLogBlk, logic: %x, logblk0: %x, logblk1:%x \n", nBlk, tmpFreeBlk.PhyBlkNum, tmpFreeBlk1.PhyBlkNum); //make a new log item in the log block table LOG_BLK_TBL[tmpPst].LogicBlkNum = nBlk; LOG_BLK_TBL[tmpPst].LastUsedPage = 0xffff; LOG_BLK_TBL[tmpPst].LogBlkType = LogBlkType; LOG_BLK_TBL[tmpPst].WriteBlkIndex = 0; LOG_BLK_TBL[tmpPst].ReadBlkIndex = 0; LOG_BLK_TBL[tmpPst].PhyBlk = tmpFreeBlk; LOG_BLK_TBL[tmpPst].PhyBlk1 = tmpFreeBlk1; //set the return vaule of the log position *pLogPst = tmpPst; } else { //get a free block to create a new log block result = BMM_GetFreeBlk(LOWEST_EC_TYPE, &tmpFreeBlk); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Get free block failed when create new log block!\n"); return -1; } //make a new log item in the log block table LOG_BLK_TBL[tmpPst].LogicBlkNum = nBlk; LOG_BLK_TBL[tmpPst].LastUsedPage = 0xffff; LOG_BLK_TBL[tmpPst].LogBlkType = LogBlkType; LOG_BLK_TBL[tmpPst].WriteBlkIndex = 0; LOG_BLK_TBL[tmpPst].ReadBlkIndex = 0; LOG_BLK_TBL[tmpPst].PhyBlk = tmpFreeBlk; //set the return vaule of the log position *pLogPst = tmpPst; } __CHECK_LOGICAL_INFO_OF_DATA_BLOCK: //check if the data block is an empty block, if so, need update the logic information in the spare area LML_CalculatePhyOpPar(&tmpPhyPage, CUR_MAP_ZONE, DATA_BLK_TBL[nBlk].PhyBlkNum, 0); tmpPhyPage.SectBitmap = 0x03; tmpPhyPage.MDataPtr = LML_TEMP_BUF; tmpPhyPage.SDataPtr = (void *)tmpSpare; LML_VirtualPageRead(&tmpPhyPage); if(tmpSpare[0].LogicInfo == 0xffff) { tmpSpare[0].BadBlkFlag = 0xff; tmpSpare[1].BadBlkFlag = 0xff; tmpSpare[0].LogicInfo = ((CUR_MAP_ZONE % ZONE_CNT_OF_DIE)<<10) | nBlk; tmpSpare[1].LogicInfo = ((CUR_MAP_ZONE % ZONE_CNT_OF_DIE)<<10) | nBlk; tmpSpare[0].LogicPageNum = 0xffff; tmpSpare[1].LogicPageNum = 0xffff; tmpSpare[0].PageStatus = 0xff; tmpSpare[1].PageStatus = 0xff; //write the logical information to the spare area of the data block tmpPhyPage.SectBitmap = FULL_BITMAP_OF_SUPER_PAGE; result = LML_VirtualPageWrite(&tmpPhyPage); if(result < 0) { LOGICCTL_ERR("[MAPPING_ERR] Physical write module failed when write logical information, Err:0x%x!\n", result); return -1; } result = PHY_SynchBank(tmpPhyPage.BankNum, SYNC_CHIP_MODE); if(result < 0) { //the last write operation on current bank is failed, the block is bad, need proccess it LOGICCTL_DBG("[LOGICCTL_DBG] Find a bad block when write logical page! bank:0x%x, block:0x%x, page:0x%x\n", tmpPhyPage.BankNum, tmpPhyPage.BlkNum, tmpPhyPage.PageNum); //process the bad block result = LML_BadBlkManage(&DATA_BLK_TBL[nBlk], CUR_MAP_ZONE, 0, &tmpFreeBlk); if(result < 0) { LOGICCTL_ERR("[MAPPING_ERR] Bad block process failed when create new log block, Err:0x%x!\n", result); return -1; } DATA_BLK_TBL[nBlk] = tmpFreeBlk; goto __CHECK_LOGICAL_INFO_OF_DATA_BLOCK; } } return 0; }
static __s32 _write_back_page_map_tbl(__u32 nLogBlkPst) { __u16 TablePage; __u32 TableBlk; struct __NandUserData_t UserData[2]; struct __PhysicOpPara_t param; struct __SuperPhyBlkType_t BadBlk,NewBlk; /*check page poisition, merge if no free page*/ TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; if (TablePage == PAGE_CNT_OF_SUPER_BLK) { /*block id full,need merge*/ if (LML_MergeLogBlk(SPECIAL_MERGE_MODE,LOG_BLK_TBL[nLogBlkPst].LogicBlkNum)) { MAPPING_ERR("write back page tbl : merge err\n"); return NAND_OP_FALSE; } if (PAGE_MAP_CACHE->ZoneNum != 0xff) { /*move merge*/ TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; } else return NAND_OP_TRUE; } rewrite: //PRINT("-------------------write back page tbl for blk %x\n",TableBlk); /*write page map table*/ MEMSET((void *)&UserData,0xff,sizeof(struct __NandUserData_t) * 2); UserData[0].PageStatus = 0xaa; MEMSET(LML_PROCESS_TBL_BUF,0xff,SECTOR_CNT_OF_SUPER_PAGE * SECTOR_SIZE); if(PAGE_CNT_OF_SUPER_BLK >= 512) { __u32 page; for(page = 0; page < PAGE_CNT_OF_SUPER_BLK; page++) *((__u16 *)LML_PROCESS_TBL_BUF + page) = PAGE_MAP_TBL[page].PhyPageNum; ((__u32 *)LML_PROCESS_TBL_BUF)[511] = \ _GetTblCheckSum((__u32 *)LML_PROCESS_TBL_BUF, PAGE_CNT_OF_SUPER_BLK*2/(sizeof (__u32))); } else { MEMCPY(LML_PROCESS_TBL_BUF, PAGE_MAP_TBL,PAGE_CNT_OF_SUPER_BLK*sizeof(struct __PageMapTblItem_t)); ((__u32 *)LML_PROCESS_TBL_BUF)[511] = \ _GetTblCheckSum((__u32 *)LML_PROCESS_TBL_BUF, PAGE_CNT_OF_SUPER_BLK*sizeof(struct __PageMapTblItem_t)/(sizeof (__u32))); } param.MDataPtr = LML_PROCESS_TBL_BUF; param.SDataPtr = (void *)&UserData; param.SectBitmap = FULL_BITMAP_OF_SUPER_PAGE; //rewrite: LML_CalculatePhyOpPar(¶m, CUR_MAP_ZONE, TableBlk, TablePage); LML_VirtualPageWrite(¶m); if (NAND_OP_TRUE != PHY_SynchBank(param.BankNum, SYNC_CHIP_MODE)) { BadBlk.PhyBlkNum = TableBlk; if (NAND_OP_TRUE != LML_BadBlkManage(&BadBlk,CUR_MAP_ZONE,TablePage,&NewBlk)) { MAPPING_ERR("write page map table : bad block mange err after write\n"); return NAND_OP_FALSE; } TableBlk = NewBlk.PhyBlkNum; LOG_BLK_TBL[nLogBlkPst].PhyBlk = NewBlk; goto rewrite; } LOG_BLK_TBL[nLogBlkPst].LastUsedPage = TablePage; PAGE_MAP_CACHE->ZoneNum = 0xff; PAGE_MAP_CACHE->LogBlkPst = 0xff; return NAND_OP_TRUE; }
static __s32 _write_back_page_map_tbl(__u32 nLogBlkPst) { __u16 TablePage; __u32 TableBlk; struct __NandUserData_t UserData[2]; struct __PhysicOpPara_t param, tmpPage0; struct __SuperPhyBlkType_t BadBlk,NewBlk; __s32 result; /*check page poisition, merge if no free page*/ if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[nLogBlkPst].LogBlkType == LSB_TYPE)) { TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; DBUG_MSG("[DBUG] _write_back_page_map_tbl, log block: %x, bak log block %x\n", LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum, LOG_BLK_TBL[nLogBlkPst].PhyBlk1.PhyBlkNum); DBUG_MSG("[DBUG] _write_back_page_map_tbl, select bak log block\n"); TablePage = PMM_CalNextLogPage(TablePage); if((TablePage >= PAGE_CNT_OF_SUPER_BLK)&&(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex == 0)) { DBUG_MSG("[DBUG] _write_back_page_map_tbl, change to log block 1, phyblock1: %x\n", LOG_BLK_TBL[nLogBlkPst].PhyBlk1.PhyBlkNum); LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex = 1; TablePage = TablePage - PAGE_CNT_OF_SUPER_BLK; } if(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex == 1) TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk1.PhyBlkNum; else TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; if (TablePage >= PAGE_CNT_OF_SUPER_BLK){ //DBUG_INF("[DBUG] _write_back_page_map_tbl, log block full, need merge\n"); /*block id full,need merge*/ if (LML_MergeLogBlk(SPECIAL_MERGE_MODE,LOG_BLK_TBL[nLogBlkPst].LogicBlkNum)){ MAPPING_ERR("write back page tbl : merge err\n"); return NAND_OP_FALSE; } DBUG_MSG("[DBUG] _write_back_page_map_tbl, log block merge end\n"); if (PAGE_MAP_CACHE->ZoneNum != 0xff){ /*move merge*/ TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; TablePage = PMM_CalNextLogPage(TablePage); //DBUG_INF("[DBUG] _write_back_page_map_tbl, after move merge, table block: %x, table page %x\n", TableBlk, TablePage); } else return NAND_OP_TRUE; } } else { TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; if (TablePage == PAGE_CNT_OF_SUPER_BLK){ /*block id full,need merge*/ if (LML_MergeLogBlk(SPECIAL_MERGE_MODE,LOG_BLK_TBL[nLogBlkPst].LogicBlkNum)){ MAPPING_ERR("write back page tbl : merge err\n"); return NAND_OP_FALSE; } if (PAGE_MAP_CACHE->ZoneNum != 0xff){ /*move merge*/ TablePage = LOG_BLK_TBL[nLogBlkPst].LastUsedPage + 1; TableBlk = LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum; } else return NAND_OP_TRUE; } } rewrite: //PRINT("-------------------write back page tbl for blk %x\n",TableBlk); /*write page map table*/ if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[nLogBlkPst].LogBlkType == LSB_TYPE)) { if((TablePage== 0)&&(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex == 1)) { MEMSET((void *)(&UserData[0]),0xff,sizeof(struct __NandUserData_t) * 2); //log page is the page0 of the logblk1, should copy page0 of logblock0, and skip the page LML_CalculatePhyOpPar(&tmpPage0, CUR_MAP_ZONE, LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum, 0); tmpPage0.SectBitmap = FULL_BITMAP_OF_SUPER_PAGE; tmpPage0.MDataPtr = LML_TEMP_BUF; tmpPage0.SDataPtr = (void *)UserData; result = LML_VirtualPageRead(&tmpPage0); if(result < 0) { LOGICCTL_ERR("[LOGICCTL_ERR] Get log age of data block failed when write logical page, Err:0x%x!\n", result); return -ERR_PHYSIC; } //log page is the page0 of the logblk1, should skip the page UserData[0].LogType = LSB_TYPE|(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex<<4); UserData[1].LogType = LSB_TYPE|(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex<<4); LML_CalculatePhyOpPar(&tmpPage0, CUR_MAP_ZONE, LOG_BLK_TBL[nLogBlkPst].PhyBlk1.PhyBlkNum, 0); tmpPage0.SectBitmap = FULL_BITMAP_OF_SUPER_PAGE; tmpPage0.MDataPtr = LML_TEMP_BUF; tmpPage0.SDataPtr = (void *)UserData; result = LML_VirtualPageWrite(&tmpPage0); TablePage++; } } MEMSET((void *)(&UserData[0]),0xff,sizeof(struct __NandUserData_t) * 2); UserData[0].PageStatus = 0xaa; if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[nLogBlkPst].LogBlkType == LSB_TYPE)) { UserData[0].LogType = LSB_TYPE|(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex<<4); UserData[1].LogType = LSB_TYPE|(LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex<<4); } else { UserData[0].LogType = 0xff; UserData[1].LogType = 0xff; } //if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[nLogBlkPst].LogBlkType == LSB_TYPE)&&(TablePage== 0)) //{ // DBUG_INF("[DBUG] _write_back_page_map_tbl in page0, TablePage: %x, TableBlk: %x\n", TablePage, TableBlk); // DBUG_INF("[DBUG] _write_back_page_map_tbl in page0, logicNum: %x, log0: %x, log1: %x\n", LOG_BLK_TBL[nLogBlkPst].LogicBlkNum,LOG_BLK_TBL[nLogBlkPst].PhyBlk.PhyBlkNum, LOG_BLK_TBL[nLogBlkPst].PhyBlk1.PhyBlkNum); // DBUG_INF("[DBUG] _write_back_page_map_tbl in page0, logicinfo: %x, logicpage: %x\n", UserData[0].LogicInfo, UserData[0].LogicPageNum); // DBUG_INF("[DBUG] _write_back_page_map_tbl in page0, logtype: %x, pagestatus: %x\n", UserData[0].LogType, UserData[0].PageStatus); //} MEMSET(LML_PROCESS_TBL_BUF,0xff,SECTOR_CNT_OF_SUPER_PAGE * SECTOR_SIZE); if(PAGE_CNT_OF_SUPER_BLK >= 512) { __u32 page; for(page = 0; page < PAGE_CNT_OF_SUPER_BLK; page++) *((__u16 *)LML_PROCESS_TBL_BUF + page) = PAGE_MAP_TBL[page].PhyPageNum; ((__u32 *)LML_PROCESS_TBL_BUF)[511] = \ _GetTblCheckSum((__u32 *)LML_PROCESS_TBL_BUF, PAGE_CNT_OF_SUPER_BLK*2/(sizeof (__u32))); } else { MEMCPY(LML_PROCESS_TBL_BUF, PAGE_MAP_TBL,PAGE_CNT_OF_SUPER_BLK*sizeof(struct __PageMapTblItem_t)); ((__u32 *)LML_PROCESS_TBL_BUF)[511] = \ _GetTblCheckSum((__u32 *)LML_PROCESS_TBL_BUF, PAGE_CNT_OF_SUPER_BLK*sizeof(struct __PageMapTblItem_t)/(sizeof (__u32))); } param.MDataPtr = LML_PROCESS_TBL_BUF; param.SDataPtr = (void *)&UserData; param.SectBitmap = FULL_BITMAP_OF_SUPER_PAGE; //rewrite: LML_CalculatePhyOpPar(¶m, CUR_MAP_ZONE, TableBlk, TablePage); LML_VirtualPageWrite(¶m); if (NAND_OP_TRUE != PHY_SynchBank(param.BankNum, SYNC_CHIP_MODE)){ BadBlk.PhyBlkNum = TableBlk; if (NAND_OP_TRUE != LML_BadBlkManage(&BadBlk,CUR_MAP_ZONE,TablePage,&NewBlk)){ MAPPING_ERR("write page map table : bad block mange err after write\n"); return NAND_OP_FALSE; } TableBlk = NewBlk.PhyBlkNum; LOG_BLK_TBL[nLogBlkPst].PhyBlk = NewBlk; goto rewrite; } LOG_BLK_TBL[nLogBlkPst].LastUsedPage = TablePage; PAGE_MAP_CACHE->ZoneNum = 0xff; PAGE_MAP_CACHE->LogBlkPst = 0xff; if((SUPPORT_LOG_BLOCK_MANAGE)&&(LOG_BLK_TBL[nLogBlkPst].LogBlkType == LSB_TYPE)) DBUG_MSG("[DBUG] _write_back_page_map_tbl end, lastusedpage: %x, write_index: %x\n", LOG_BLK_TBL[nLogBlkPst].LastUsedPage, LOG_BLK_TBL[nLogBlkPst].WriteBlkIndex); return NAND_OP_TRUE; }
__s32 BMM_RleaseLogBlock(__u32 log_level) { __u32 tmpZoneNum, ZoneCnt, tmpLogPos; __s32 result, release_logblk_cnt; __s32 tmpPst=-1, i, ValidLogblkCnt = 0; __u16 tmpLogAccessAge = 0xffff; //check if need to release log block ValidLogblkCnt = 0; for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if(LOG_BLK_TBL[i].LogicBlkNum != 0xffff) { ValidLogblkCnt++; } } //valid log block if less than log_level, no need to release log block if(ValidLogblkCnt<=log_level) return 0; //PRINT("BMM_RleaseLogBlock\n"); BMM_SetDirtyFlag(); //check if there is some full log block for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if(LOG_BLK_TBL[i].LastUsedPage == PAGE_CNT_OF_SUPER_BLK-1) { tmpPst = i; break; } } if(tmpPst == -1) { //there is no full log block, look for an oldest log block to merge for(i=0; i<LOG_BLK_CNT_OF_ZONE; i++) { if((LOG_ACCESS_AGE[i] < tmpLogAccessAge)&&(LOG_BLK_TBL[i].LogicBlkNum != 0xffff)) { tmpLogAccessAge = LOG_ACCESS_AGE[i]; tmpPst = i; } } } if(tmpPst == -1) return -1; //switch the page mapping table for merge the log block result = PMM_SwitchMapTbl(tmpPst); if(result < 0) { MAPPING_ERR("[MAPPING_ERR] Switch page mapping table failed when create new log block! Err:0x%x\n", result); return -1; } //merge the log block with normal type, to make an empty item result = LML_MergeLogBlk(NORMAL_MERGE_MODE, LOG_BLK_TBL[tmpPst].LogicBlkNum); if(result < 0) { //merge log block failed, report error MAPPING_ERR("[MAPPING_ERR] Merge log block failed when create new log block! Err:0x%x\n", result); return -1; } return (ValidLogblkCnt-1); }