mirror of
https://github.com/sharkcz/rkdeveloptool.git
synced 2024-11-22 14:06:47 +01:00
v1.32:
1.support to upgrade 356x loader Signed-off-by: liuyi <liuyi@rock-chips.com>
This commit is contained in:
parent
e607a5d6ad
commit
46bb4c0736
@ -8,7 +8,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
// #include <iconv.h>
|
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -241,7 +241,7 @@ CRKBoot::CRKBoot(PBYTE lpBootData,DWORD dwBootSize,bool &bCheck)
|
|||||||
}
|
}
|
||||||
PSTRUCT_RKBOOT_HEAD pBootHead;
|
PSTRUCT_RKBOOT_HEAD pBootHead;
|
||||||
pBootHead = (PSTRUCT_RKBOOT_HEAD)(m_BootData);
|
pBootHead = (PSTRUCT_RKBOOT_HEAD)(m_BootData);
|
||||||
if ( pBootHead->uiTag!=0x544F4F42)
|
if (( pBootHead->uiTag!=0x544F4F42)&&(pBootHead->uiTag!=0x2052444C))
|
||||||
{
|
{
|
||||||
bCheck=false;
|
bCheck=false;
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
dnl Copyright (C) 2017 Trevor Woerner <twoerner@gmail.com>
|
dnl Copyright (C) 2017 Trevor Woerner <twoerner@gmail.com>
|
||||||
|
|
||||||
AC_INIT([Rockchip rkdeveloptool], 1.3, [Eddie Cai <eddie.cai.linux@gmail.com>], rkdeveloptool)
|
AC_INIT([Rockchip rkdeveloptool], 1.32, [Eddie Cai <eddie.cai.linux@gmail.com>], rkdeveloptool)
|
||||||
AC_PREREQ([2.68])
|
AC_PREREQ([2.68])
|
||||||
AC_CONFIG_SRCDIR(main.cpp)
|
AC_CONFIG_SRCDIR(main.cpp)
|
||||||
AC_CONFIG_AUX_DIR(cfg)
|
AC_CONFIG_AUX_DIR(cfg)
|
||||||
@ -20,7 +20,7 @@ AC_CANONICAL_HOST
|
|||||||
case "$host_os" in
|
case "$host_os" in
|
||||||
freebsd*)
|
freebsd*)
|
||||||
CPPFLAGS="$CFLAGS -I/usr/local/include"
|
CPPFLAGS="$CFLAGS -I/usr/local/include"
|
||||||
LDFLAGS="$LDFLAGS -L/usr/local/lib -liconv"
|
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||||
;;
|
;;
|
||||||
openbsd*)
|
openbsd*)
|
||||||
CPPFLAGS="$CFLAGS -I/usr/local/include"
|
CPPFLAGS="$CFLAGS -I/usr/local/include"
|
||||||
@ -30,11 +30,9 @@ case "$host_os" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
AC_SEARCH_LIBS(iconv, iconv)
|
|
||||||
|
|
||||||
PKG_CHECK_MODULES(LIBUSB1,libusb-1.0)
|
PKG_CHECK_MODULES(LIBUSB1,libusb-1.0)
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_CONFIG_FILES([cfg/Makefile])
|
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
191
main.cpp
191
main.cpp
@ -143,81 +143,6 @@ void PrintData(PBYTE pData, int nSize)
|
|||||||
printf(" %s\r\n", szPrint);
|
printf(" %s\r\n", szPrint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool StringToWideString(char *pszSrc, wchar_t *&pszDest)
|
|
||||||
// {
|
|
||||||
// if (!pszSrc)
|
|
||||||
// return false;
|
|
||||||
// int nSrcLen = strlen(pszSrc);
|
|
||||||
// int nDestLen = nSrcLen * 2;
|
|
||||||
//
|
|
||||||
// pszDest = NULL;
|
|
||||||
// pszDest = new wchar_t[nDestLen];
|
|
||||||
// if (!pszDest)
|
|
||||||
// return false;
|
|
||||||
// nDestLen = nDestLen * sizeof(wchar_t);
|
|
||||||
// memset(pszDest, 0, nDestLen);
|
|
||||||
// int iRet;
|
|
||||||
// iconv_t cd;
|
|
||||||
// cd = iconv_open("UTF-32", "UTF-8");
|
|
||||||
// if((iconv_t)-1 == cd) {
|
|
||||||
// delete []pszDest;
|
|
||||||
// pszDest = NULL;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// char *pIn, *pOut;
|
|
||||||
// pIn = (char *)pszSrc;
|
|
||||||
// pOut = (char *)pszDest;
|
|
||||||
//
|
|
||||||
// iRet = iconv(cd, (char **)&pIn, (size_t *)&nSrcLen, (char **)&pOut, (size_t *)&nDestLen);
|
|
||||||
//
|
|
||||||
// if(iRet == -1) {
|
|
||||||
// delete []pszDest;
|
|
||||||
// pszDest = NULL;
|
|
||||||
// iconv_close(cd);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// iconv_close(cd);
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// bool WideStringToString(wchar_t *pszSrc, char *&pszDest)
|
|
||||||
// {
|
|
||||||
// if (!pszSrc)
|
|
||||||
// return false;
|
|
||||||
// int nSrcLen = wcslen(pszSrc);
|
|
||||||
// int nDestLen = nSrcLen * 2;
|
|
||||||
// nSrcLen = nSrcLen * sizeof(wchar_t);
|
|
||||||
// pszDest = NULL;
|
|
||||||
// pszDest = new char[nDestLen];
|
|
||||||
// if (!pszDest)
|
|
||||||
// return false;
|
|
||||||
// memset(pszDest, 0, nDestLen);
|
|
||||||
// int iRet;
|
|
||||||
// iconv_t cd;
|
|
||||||
// cd = iconv_open("UTF-8", "UTF-32");
|
|
||||||
//
|
|
||||||
// if((iconv_t)-1 == cd) {
|
|
||||||
// delete []pszDest;
|
|
||||||
// pszDest = NULL;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// char *pIn, *pOut;
|
|
||||||
// pIn = (char *)pszSrc;
|
|
||||||
// pOut = (char *)pszDest;
|
|
||||||
// iRet = iconv(cd, (char **)&pIn, (size_t *)&nSrcLen, (char **)&pOut, (size_t *)&nDestLen);
|
|
||||||
//
|
|
||||||
// if(iRet == -1) {
|
|
||||||
// delete []pszDest;
|
|
||||||
// pszDest = NULL;
|
|
||||||
// iconv_close(cd);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// iconv_close(cd);
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
int find_config_item(CONFIG_ITEM_VECTOR &vecItems, const char *pszName)
|
int find_config_item(CONFIG_ITEM_VECTOR &vecItems, const char *pszName)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -1907,16 +1832,20 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
|
|||||||
CRKImage *pImage = NULL;
|
CRKImage *pImage = NULL;
|
||||||
CRKBoot *pBoot = NULL;
|
CRKBoot *pBoot = NULL;
|
||||||
CRKComm *pComm = NULL;
|
CRKComm *pComm = NULL;
|
||||||
bool bRet, bSuccess = false;
|
bool bRet,bNewIDBlock=false, bSuccess = false;
|
||||||
int iRet;
|
int iRet;
|
||||||
|
unsigned int i;
|
||||||
signed char index;
|
signed char index;
|
||||||
USHORT usFlashDataSec, usFlashBootSec;
|
USHORT usFlashDataSec, usFlashBootSec, usFlashHeadSec;
|
||||||
DWORD dwLoaderSize, dwLoaderDataSize, dwDelay, dwSectorNum;
|
DWORD dwLoaderSize, dwLoaderDataSize, dwLoaderHeadSize, dwDelay, dwSectorNum;
|
||||||
char loaderCodeName[] = "FlashBoot";
|
char loaderCodeName[] = "FlashBoot";
|
||||||
char loaderDataName[] = "FlashData";
|
char loaderDataName[] = "FlashData";
|
||||||
|
char loaderHeadName[] = "FlashHead";
|
||||||
PBYTE loaderCodeBuffer = NULL;
|
PBYTE loaderCodeBuffer = NULL;
|
||||||
PBYTE loaderDataBuffer = NULL;
|
PBYTE loaderDataBuffer = NULL;
|
||||||
|
PBYTE loaderHeadBuffer = NULL;
|
||||||
PBYTE pIDBData = NULL;
|
PBYTE pIDBData = NULL;
|
||||||
|
BYTE capability[8];
|
||||||
pImage = new CRKImage(szLoader, bRet);
|
pImage = new CRKImage(szLoader, bRet);
|
||||||
if (!bRet){
|
if (!bRet){
|
||||||
ERROR_COLOR_ATTR;
|
ERROR_COLOR_ATTR;
|
||||||
@ -1987,9 +1916,51 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
|
|||||||
goto Exit_UpgradeLoader;
|
goto Exit_UpgradeLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = pBoot->GetIndexByName(ENTRYLOADER, loaderHeadName);
|
||||||
|
if (index != -1) {
|
||||||
|
bRet = pBoot->GetEntryProperty(ENTRYLOADER, index, dwLoaderHeadSize, dwDelay);
|
||||||
|
if (!bRet) {
|
||||||
|
if (g_pLogObject) {
|
||||||
|
g_pLogObject->Record("ERROR: %s --> Get LoaderHead Entry Size failed", __func__);
|
||||||
|
}
|
||||||
|
goto Exit_UpgradeLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
loaderHeadBuffer= new BYTE[dwLoaderHeadSize];
|
||||||
|
memset(loaderHeadBuffer, 0, dwLoaderHeadSize);
|
||||||
|
if (!pBoot->GetEntryData(ENTRYLOADER,index,loaderHeadBuffer)) {
|
||||||
|
if (g_pLogObject) {
|
||||||
|
g_pLogObject->Record("ERROR: %s --> Get LoaderHead Data failed", __func__);
|
||||||
|
}
|
||||||
|
goto Exit_UpgradeLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
iRet = pComm->RKU_ReadCapability(capability);
|
||||||
|
if (iRet != ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
if (g_pLogObject)
|
||||||
|
g_pLogObject->Record("ERROR: %s --> read capability failed", __func__);
|
||||||
|
goto Exit_UpgradeLoader;
|
||||||
|
}
|
||||||
|
if ((capability[1] & 1) == 0) {
|
||||||
|
if (g_pLogObject)
|
||||||
|
g_pLogObject->Record("ERROR: %s --> device did not support to upgrade the loader", __func__);
|
||||||
|
ERROR_COLOR_ATTR;
|
||||||
|
printf("Device not support to upgrade the loader!");
|
||||||
|
NORMAL_COLOR_ATTR;
|
||||||
|
printf("\r\n");
|
||||||
|
goto Exit_UpgradeLoader;
|
||||||
|
}
|
||||||
|
bNewIDBlock = true;
|
||||||
|
}
|
||||||
|
|
||||||
usFlashDataSec = (ALIGN(dwLoaderDataSize, 2048)) / SECTOR_SIZE;
|
usFlashDataSec = (ALIGN(dwLoaderDataSize, 2048)) / SECTOR_SIZE;
|
||||||
usFlashBootSec = (ALIGN(dwLoaderSize, 2048)) / SECTOR_SIZE;
|
usFlashBootSec = (ALIGN(dwLoaderSize, 2048)) / SECTOR_SIZE;
|
||||||
dwSectorNum = 4 + usFlashDataSec + usFlashBootSec;
|
if (bNewIDBlock) {
|
||||||
|
usFlashHeadSec = (ALIGN(dwLoaderHeadSize, 2048)) / SECTOR_SIZE;
|
||||||
|
dwSectorNum = usFlashHeadSec + usFlashDataSec + usFlashBootSec;
|
||||||
|
} else
|
||||||
|
dwSectorNum = 4 + usFlashDataSec + usFlashBootSec;
|
||||||
pIDBData = new BYTE[dwSectorNum*SECTOR_SIZE];
|
pIDBData = new BYTE[dwSectorNum*SECTOR_SIZE];
|
||||||
if (!pIDBData) {
|
if (!pIDBData) {
|
||||||
ERROR_COLOR_ATTR;
|
ERROR_COLOR_ATTR;
|
||||||
@ -1999,14 +1970,36 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
|
|||||||
goto Exit_UpgradeLoader;
|
goto Exit_UpgradeLoader;
|
||||||
}
|
}
|
||||||
memset(pIDBData, 0, dwSectorNum * SECTOR_SIZE);
|
memset(pIDBData, 0, dwSectorNum * SECTOR_SIZE);
|
||||||
iRet = MakeIDBlockData(loaderDataBuffer, loaderCodeBuffer, pIDBData, usFlashDataSec, usFlashBootSec, dwLoaderDataSize, dwLoaderSize, pBoot->Rc4DisableFlag);
|
if (bNewIDBlock) {
|
||||||
if (iRet != 0) {
|
if (pBoot->Rc4DisableFlag)
|
||||||
ERROR_COLOR_ATTR;
|
{//close rc4 encryption
|
||||||
printf("Making idblock failed!");
|
for (i=0;i<dwLoaderHeadSize/SECTOR_SIZE;i++)
|
||||||
NORMAL_COLOR_ATTR;
|
{
|
||||||
printf("\r\n");
|
P_RC4(loaderHeadBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
|
||||||
goto Exit_UpgradeLoader;
|
}
|
||||||
|
for (i=0;i<dwLoaderDataSize/SECTOR_SIZE;i++)
|
||||||
|
{
|
||||||
|
P_RC4(loaderDataBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
for (i=0;i<dwLoaderSize/SECTOR_SIZE;i++)
|
||||||
|
{
|
||||||
|
P_RC4(loaderCodeBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(pIDBData, loaderHeadBuffer, dwLoaderHeadSize);
|
||||||
|
memcpy(pIDBData+SECTOR_SIZE*usFlashHeadSec, loaderDataBuffer, dwLoaderDataSize);
|
||||||
|
memcpy(pIDBData+SECTOR_SIZE*(usFlashHeadSec+usFlashDataSec), loaderCodeBuffer, dwLoaderSize);
|
||||||
|
} else {
|
||||||
|
iRet = MakeIDBlockData(loaderDataBuffer, loaderCodeBuffer, pIDBData, usFlashDataSec, usFlashBootSec, dwLoaderDataSize, dwLoaderSize, pBoot->Rc4DisableFlag);
|
||||||
|
if (iRet != 0) {
|
||||||
|
ERROR_COLOR_ATTR;
|
||||||
|
printf("Making idblock failed!");
|
||||||
|
NORMAL_COLOR_ATTR;
|
||||||
|
printf("\r\n");
|
||||||
|
goto Exit_UpgradeLoader;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iRet = pComm->RKU_WriteLBA(64, dwSectorNum, pIDBData);
|
iRet = pComm->RKU_WriteLBA(64, dwSectorNum, pIDBData);
|
||||||
CURSOR_MOVEUP_LINE(1);
|
CURSOR_MOVEUP_LINE(1);
|
||||||
CURSOR_DEL_LINE;
|
CURSOR_DEL_LINE;
|
||||||
@ -2028,6 +2021,8 @@ Exit_UpgradeLoader:
|
|||||||
delete []loaderCodeBuffer;
|
delete []loaderCodeBuffer;
|
||||||
if (loaderDataBuffer)
|
if (loaderDataBuffer)
|
||||||
delete []loaderDataBuffer;
|
delete []loaderDataBuffer;
|
||||||
|
if (loaderHeadBuffer)
|
||||||
|
delete []loaderHeadBuffer;
|
||||||
if (pIDBData)
|
if (pIDBData)
|
||||||
delete []pIDBData;
|
delete []pIDBData;
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
@ -2412,6 +2407,30 @@ bool read_capability(STRUCT_RKDEVICE_DESC &dev)
|
|||||||
{
|
{
|
||||||
printf("First 4m Access:\tenabled\r\n");
|
printf("First 4m Access:\tenabled\r\n");
|
||||||
}
|
}
|
||||||
|
if (capability[0] & 8)
|
||||||
|
{
|
||||||
|
printf("Read LBA:\tenabled\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capability[0] & 20)
|
||||||
|
{
|
||||||
|
printf("Read Com Log:\tenabled\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capability[0] & 40)
|
||||||
|
{
|
||||||
|
printf("Read IDB Config:\tenabled\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capability[0] & 80)
|
||||||
|
{
|
||||||
|
printf("Read Secure Mode:\tenabled\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capability[1] & 1)
|
||||||
|
{
|
||||||
|
printf("New IDB:\tenabled\r\n");
|
||||||
|
}
|
||||||
bSuccess = true;
|
bSuccess = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user