Skip to content

Commit

Permalink
rkdeveloptool: v1.3
Browse files Browse the repository at this point in the history
1.add LD to list devices
2.add PRM to write parameter
3.change PGPT to PPT to support print parameter and GPT

Signed-off-by: liuyi <liuyi@rock-chips.com>
  • Loading branch information
liuyi committed Mar 28, 2018
1 parent 797356f commit 081d237
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 38 deletions.
41 changes: 41 additions & 0 deletions RKComm.cpp
Expand Up @@ -196,6 +196,7 @@ void CRKUsbComm::InitializeCBW(PCBW pCBW, USB_OPERATION_CODE code)
case READ_FLASH_INFO:
case READ_CHIP_INFO:
case READ_EFUSE:
case READ_CAPABILITY:
pCBW->ucCBWFlags= DIRECTION_IN;
pCBW->ucCBWCBLength = 0x06;
break;
Expand Down Expand Up @@ -427,6 +428,46 @@ int CRKUsbComm::RKU_ReadFlashInfo(BYTE* lpBuffer, UINT *puiRead)

return ERR_SUCCESS;
}
int CRKUsbComm::RKU_ReadCapability(BYTE* lpBuffer)
{
if ((m_deviceDesc.emUsbType != RKUSB_LOADER) && (m_deviceDesc.emUsbType != RKUSB_MASKROM)) {
if (m_log) {
m_log->Record("Error:RKU_ReadCapability failed,device not support");
}
return ERR_DEVICE_NOT_SUPPORT;
}

CBW cbw;
CSW csw;
DWORD dwRead;

InitializeCBW(&cbw, READ_CAPABILITY);
cbw.dwCBWTransferLength = 8;

if(!RKU_Write((BYTE*)&cbw, sizeof(CBW)))
{
return ERR_DEVICE_WRITE_FAILED;
}

dwRead = RKU_Read_EX((BYTE*)&csw, sizeof(CSW));

if(dwRead != 8)
{
return ERR_DEVICE_READ_FAILED;
}
memcpy(lpBuffer, (BYTE*)&csw, 8);

if(!RKU_Read((BYTE*)&csw, sizeof(CSW)))
{
return ERR_DEVICE_READ_FAILED;
}

if( !UFI_CHECK_SIGN(cbw, csw) )
return ERR_CMD_NOTMATCH;

return ERR_SUCCESS;
}

int CRKUsbComm::RKU_ReadLBA(DWORD dwPos, DWORD dwCount, BYTE* lpBuffer, BYTE bySubCode)
{
if ((m_deviceDesc.emUsbType != RKUSB_LOADER) && (m_deviceDesc.emUsbType != RKUSB_MASKROM)) {
Expand Down
3 changes: 3 additions & 0 deletions RKComm.h
Expand Up @@ -49,6 +49,7 @@ typedef enum {
WRITE_NEW_EFUSE = 0x23,
READ_NEW_EFUSE = 0x24,
ERASE_LBA=0x25,
READ_CAPABILITY=0xAA,
DEVICE_RESET = 0xFF
} USB_OPERATION_CODE;

Expand Down Expand Up @@ -117,6 +118,7 @@ class CRKComm
virtual int RKU_EraseBlock(BYTE ucFlashCS, DWORD dwPos, DWORD dwCount, BYTE ucEraseType) = 0;
virtual int RKU_ReadChipInfo(BYTE *lpBuffer) = 0;
virtual int RKU_ReadFlashID(BYTE *lpBuffer) = 0;
virtual int RKU_ReadCapability(BYTE *lpBuffer)=0;
virtual int RKU_ReadFlashInfo(BYTE *lpBuffer, UINT *puiRead = NULL) = 0;
virtual int RKU_ReadLBA(DWORD dwPos, DWORD dwCount, BYTE *lpBuffer, BYTE bySubCode = RWMETHOD_IMAGE) = 0;
virtual int RKU_ResetDevice(BYTE bySubCode = RST_NONE_SUBCODE) = 0;
Expand All @@ -142,6 +144,7 @@ class CRKUsbComm:public CRKComm
virtual int RKU_EraseBlock(BYTE ucFlashCS, DWORD dwPos, DWORD dwCount, BYTE ucEraseType);
virtual int RKU_ReadChipInfo(BYTE *lpBuffer);
virtual int RKU_ReadFlashID(BYTE *lpBuffer);
virtual int RKU_ReadCapability(BYTE *lpBuffer);
virtual int RKU_ReadFlashInfo(BYTE *lpBuffer, UINT *puiRead = NULL);
virtual int RKU_ReadLBA(DWORD dwPos, DWORD dwCount, BYTE *lpBuffer, BYTE bySubCode = RWMETHOD_IMAGE);
virtual int RKU_ResetDevice(BYTE bySubCode = RST_NONE_SUBCODE);
Expand Down
78 changes: 54 additions & 24 deletions RKDevice.cpp
Expand Up @@ -175,6 +175,8 @@ CRKDevice::CRKDevice(STRUCT_RKDEVICE_DESC &device)
m_usFlashInfoDataLen = 0;
m_usFlashInfoDataOffset = 0;
m_bEmmc = false;
m_bDirectLba = false;
m_bFirst4mAccess = false;
}
CRKDevice::~CRKDevice()
{
Expand Down Expand Up @@ -248,38 +250,44 @@ int CRKDevice::EraseEmmcByWriteLBA(DWORD dwSectorPos, DWORD dwCount)
}
bool CRKDevice::EraseEmmc()
{
UINT uiCount, uiEraseCount, uiSectorOffset;
int iRet = ERR_SUCCESS, iLoopTimes = 0;
uiCount = m_flashInfo.uiFlashSize;

UINT uiCount,uiEraseCount,uiSectorOffset,uiTotalCount;
UINT uiErase=1024*32;
int iRet=ERR_SUCCESS,iLoopTimes=0;
uiTotalCount = uiCount = m_flashInfo.uiFlashSize*2*1024;
uiSectorOffset = 0;
DWORD dwLayerID;
dwLayerID = m_locationID;
ENUM_CALL_STEP emCallStep = CALL_FIRST;
uiEraseCount = 4;
while (uiEraseCount < uiCount) {
uiSectorOffset = uiEraseCount * 2048;
if (uiEraseCount>8) {
iRet = EraseEmmcByWriteLBA(uiSectorOffset, 32);
} else
iRet = EraseEmmcByWriteLBA(uiSectorOffset, 2048);

while (uiCount)
{
if (uiCount >= uiErase)
{
uiEraseCount = uiErase;
}
else
uiEraseCount = uiCount;
iRet = m_pComm->RKU_EraseLBA(uiSectorOffset, uiEraseCount);

if (iRet != ERR_SUCCESS) {
if (m_pLog) {
m_pLog->Record("<LAYER %s> ERROR:EraseEmmc-->EraseEmmcByWriteLBA failed, RetCode(%d)", m_layerName, iRet);
m_pLog->Record("ERROR:EraseEmmc-->RKU_EraseLBA failed,RetCode(%d),offset=0x%x,count=0x%x",iRet, uiSectorOffset, uiEraseCount);
}
return false;
}
uiEraseCount++;
uiCount -= uiEraseCount;
uiSectorOffset += uiEraseCount;
iLoopTimes++;
if (iLoopTimes%8 == 0) {
if (iLoopTimes % 8 == 0) {
if (m_callBackProc) {
m_callBackProc(dwLayerID, ERASEFLASH_PROGRESS, uiCount, uiEraseCount, emCallStep);
m_callBackProc(dwLayerID, ERASEFLASH_PROGRESS, uiTotalCount, uiSectorOffset, emCallStep);
emCallStep = CALL_MIDDLE;
}
}
}
if (m_callBackProc) {
emCallStep = CALL_LAST;
m_callBackProc(dwLayerID, ERASEFLASH_PROGRESS, uiCount, uiCount, emCallStep);
m_callBackProc(dwLayerID, ERASEFLASH_PROGRESS, uiTotalCount, uiTotalCount, emCallStep);
}
return true;
}
Expand Down Expand Up @@ -587,17 +595,11 @@ int CRKDevice::EraseAllBlocks()
bCSCount++;
}
}
ReadCapability();
DWORD dwLayerID;
dwLayerID = LocationID;
ENUM_CALL_STEP emCallStep = CALL_FIRST;
if (m_bEmmc) {
iRet = EraseEmmcBlock(0, 0, IDBLOCK_TOP);
if (iRet != ERR_SUCCESS) {
if (m_pLog) {
m_pLog->Record("<LAYER %s> ERROR:EraseAllBlocks-->EraseEmmcBlock failed,RetCode(%d)", m_layerName, iRet);
}
return -1;
}
if ((m_bEmmc)||(m_bDirectLba)) {
if (!EraseEmmc()) {
if (m_pLog) {
m_pLog->Record("<LAYER %s> ERROR:EraseAllBlocks-->EraseEmmc failed", m_layerName);
Expand Down Expand Up @@ -640,4 +642,32 @@ int CRKDevice::EraseAllBlocks()
}
return 0;
}
bool CRKDevice::ReadCapability()
{
int ret;
BYTE data[8];
ret = m_pComm->RKU_ReadCapability(data);
if (ret != ERR_SUCCESS)
{
if (m_pLog)
{
m_pLog->Record("ERROR:ReadCapability-->RKU_ReadCapability failed,err(%d)", ret);
}
return false;
}
if (data[0] & 0x1)
{
m_bDirectLba = true;
}
else
m_bDirectLba = false;
if (data[0] & 0x4)
{
m_bFirst4mAccess = true;
}
else
m_bFirst4mAccess = false;
return true;
}


3 changes: 3 additions & 0 deletions RKDevice.h
Expand Up @@ -109,10 +109,13 @@ class CRKDevice
CRKLog *m_pLog;
ProgressPromptCB m_callBackProc;
bool m_bEmmc;
bool m_bDirectLba;
bool m_bFirst4mAccess;
int EraseEmmcBlock(UCHAR ucFlashCS, DWORD dwPos, DWORD dwCount);
int EraseEmmcByWriteLBA(DWORD dwSectorPos, DWORD dwCount);
bool EraseEmmc();
bool Boot_VendorRequest(DWORD requestCode, PBYTE pBuffer, DWORD dwDataSize);
bool ReadCapability();
private:
USHORT m_vid;
USHORT m_pid;
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,6 +1,6 @@
dnl Copyright (C) 2017 Trevor Woerner <twoerner@gmail.com>

AC_INIT([Rockchip rkdeveloptool], 1.2, [Eddie Cai <eddie.cai.linux@gmail.com>], rkdeveloptool)
AC_INIT([Rockchip rkdeveloptool], 1.3, [Eddie Cai <eddie.cai.linux@gmail.com>], rkdeveloptool)
AC_PREREQ([2.68])
AC_CONFIG_SRCDIR(main.cpp)
AC_CONFIG_AUX_DIR(cfg)
Expand Down

0 comments on commit 081d237

Please sign in to comment.