1.support erase block forcely

2.fix create gpt bug

Signed-off-by: liuyi <liuyi@rock-chips.com>
This commit is contained in:
liuyi 2021-01-22 14:26:24 +08:00
parent 9870459553
commit e541b7bbff
3 changed files with 24 additions and 16 deletions

View File

@ -584,7 +584,7 @@ bool CRKDevice::Boot_VendorRequest( DWORD requestCode, PBYTE pBuffer, DWORD dwDa
iRet = m_pComm->RKU_DeviceRequest(requestCode, pBuffer, dwDataSize);
return (iRet == ERR_SUCCESS) ? true : false;
}
int CRKDevice::EraseAllBlocks()
int CRKDevice::EraseAllBlocks(bool force_block_erase)
{
int i;
UINT uiBlockCount;
@ -599,6 +599,7 @@ int CRKDevice::EraseAllBlocks()
DWORD dwLayerID;
dwLayerID = LocationID;
ENUM_CALL_STEP emCallStep = CALL_FIRST;
if (!force_block_erase) {
if ((m_bEmmc)||(m_bDirectLba)) {
if (!EraseEmmc()) {
if (m_pLog) {
@ -608,6 +609,7 @@ int CRKDevice::EraseAllBlocks()
}
return 0;
}
}
for (i = 0; i < 8; i++) {
if ( m_flashInfo.bFlashCS & (1 << i) ) {
uiBlockCount = m_flashInfo.uiBlockNum;

View File

@ -93,7 +93,7 @@ public:
bool PowerOffDevice();
bool CheckChip();
bool GetFlashInfo();
int EraseAllBlocks();
int EraseAllBlocks(bool force_block_erase=false);
bool SetObject(CRKImage *pImage, CRKComm *pComm, CRKLog *pLog);
string GetLayerString(DWORD dwLocationID);
CRKDevice(STRUCT_RKDEVICE_DESC &device);

View File

@ -630,6 +630,9 @@ bool get_lba_from_gpt(u8 *master, char *pszName, u64 *lba, u64 *lba_end)
}
if (bFound) {
*lba = le64_to_cpu(gptEntry->starting_lba);
if (gptMasterHead->last_usable_lba == gptEntry->ending_lba)
*lba_end = 0xFFFFFFFF;
else
*lba_end = le64_to_cpu(gptEntry->ending_lba);
return true;
}
@ -1039,7 +1042,9 @@ bool write_gpt(STRUCT_RKDEVICE_DESC &dev, char *szParameter)
printf("\r\n");
return bSuccess;
}
vecItems[vecItems.size()-1].uiItemSize = total_size_sector - 33;
if (vecItems[vecItems.size()-1].uiItemSize!=0xFFFFFFFF)
total_size_sector = vecItems[vecItems.size()-1].uiItemOffset + vecItems[vecItems.size()-1].uiItemSize + 33
//vecItems[vecItems.size()-1].uiItemSize = total_size_sector - 33;
//3.generate gpt info
create_gpt_buffer(master_gpt, vecItems, vecUuid, total_size_sector);
memcpy(backup_gpt, master_gpt + 2* SECTOR_SIZE, 32 * SECTOR_SIZE);
@ -2561,6 +2566,7 @@ bool erase_ubi_block(STRUCT_RKDEVICE_DESC &dev, u32 uiOffset, u32 uiPartSize)
int iRet;
DWORD *pID=NULL;
printf("Erase ubi in, offset=0x%08x,size=0x%08x!\r\n",uiOffset,uiPartSize);
if (!check_device_type(dev, RKUSB_LOADER | RKUSB_MASKROM))
return false;
pComm = new CRKUsbComm(dev, g_pLogObject, bRet);
@ -2602,7 +2608,7 @@ bool erase_ubi_block(STRUCT_RKDEVICE_DESC &dev, u32 uiOffset, u32 uiPartSize)
else
uiEraseBlock = uiPartSize / info.usBlockSize + 1;
printf("Erase block start, offset=0x%08x,count=0x%08x!\r\n",uiStartBlock,uiEraseBlock);
uiErasePos=uiStartBlock;
while (uiEraseBlock>0)
{
@ -2695,9 +2701,9 @@ bool write_sparse_lba(STRUCT_RKDEVICE_DESC &dev, UINT uiBegin, UINT uiSize, char
FILE *file = NULL;
bool bRet, bSuccess = false, bFirst = true;
int iRet;
u64 iTotalWrite = 0, iFileSize = 0;
u64 iTotalWrite = 0, iFileSize = 0,dwChunkDataSize;
UINT iRead = 0, uiTransferSec, curChunk, i;
UINT dwChunkDataSize, dwMaxReadWriteBytes, dwTransferBytes, dwFillByte, dwCrc;
UINT dwMaxReadWriteBytes, dwTransferBytes, dwFillByte, dwCrc;
BYTE pBuf[SECTOR_SIZE * DEFAULT_RW_LBA];
sparse_header header;
chunk_header chunk;
@ -2776,7 +2782,7 @@ bool write_sparse_lba(STRUCT_RKDEVICE_DESC &dev, UINT uiBegin, UINT uiSize, char
}
break;
case CHUNK_TYPE_FILL:
dwChunkDataSize = chunk.chunk_sz * header.blk_sz;
dwChunkDataSize = (u64)chunk.chunk_sz * header.blk_sz;
if (!EatSparseData(file, (PBYTE)&dwFillByte, 4)) {
goto Exit_WriteSparseLBA;
}
@ -2817,7 +2823,7 @@ bool write_sparse_lba(STRUCT_RKDEVICE_DESC &dev, UINT uiBegin, UINT uiSize, char
}
break;
case CHUNK_TYPE_DONT_CARE:
dwChunkDataSize = chunk.chunk_sz * header.blk_sz;
dwChunkDataSize = (u64)chunk.chunk_sz * header.blk_sz;
iTotalWrite += dwChunkDataSize;
uiTransferSec = ((dwChunkDataSize % SECTOR_SIZE == 0) ? (dwChunkDataSize / SECTOR_SIZE) : (dwChunkDataSize / SECTOR_SIZE + 1));
uiBegin += uiTransferSec;