Skip to content

Commit 46bb4c0

Browse files
author
liuyi
committed
v1.32:
1.support to upgrade 356x loader Signed-off-by: liuyi <[email protected]>
1 parent e607a5d commit 46bb4c0

File tree

4 files changed

+108
-92
lines changed

4 files changed

+108
-92
lines changed

DefineHeader.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <dirent.h>
99
#include <time.h>
1010
#include <unistd.h>
11-
// #include <iconv.h>
1211
#include <wchar.h>
1312
#include <errno.h>
1413
#include <pthread.h>

RKBoot.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ CRKBoot::CRKBoot(PBYTE lpBootData,DWORD dwBootSize,bool &bCheck)
241241
}
242242
PSTRUCT_RKBOOT_HEAD pBootHead;
243243
pBootHead = (PSTRUCT_RKBOOT_HEAD)(m_BootData);
244-
if ( pBootHead->uiTag!=0x544F4F42)
244+
if (( pBootHead->uiTag!=0x544F4F42)&&(pBootHead->uiTag!=0x2052444C))
245245
{
246246
bCheck=false;
247247
return;

configure.ac

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dnl Copyright (C) 2017 Trevor Woerner <[email protected]>
22

3-
AC_INIT([Rockchip rkdeveloptool], 1.3, [Eddie Cai <[email protected]>], rkdeveloptool)
3+
AC_INIT([Rockchip rkdeveloptool], 1.32, [Eddie Cai <[email protected]>], rkdeveloptool)
44
AC_PREREQ([2.68])
55
AC_CONFIG_SRCDIR(main.cpp)
66
AC_CONFIG_AUX_DIR(cfg)
@@ -20,7 +20,7 @@ AC_CANONICAL_HOST
2020
case "$host_os" in
2121
freebsd*)
2222
CPPFLAGS="$CFLAGS -I/usr/local/include"
23-
LDFLAGS="$LDFLAGS -L/usr/local/lib -liconv"
23+
LDFLAGS="$LDFLAGS -L/usr/local/lib"
2424
;;
2525
openbsd*)
2626
CPPFLAGS="$CFLAGS -I/usr/local/include"
@@ -30,11 +30,9 @@ case "$host_os" in
3030
;;
3131
esac
3232

33-
AC_SEARCH_LIBS(iconv, iconv)
3433

3534
PKG_CHECK_MODULES(LIBUSB1,libusb-1.0)
3635

3736
AC_CONFIG_FILES([Makefile])
38-
AC_CONFIG_FILES([cfg/Makefile])
3937

4038
AC_OUTPUT

main.cpp

+105-86
Original file line numberDiff line numberDiff line change
@@ -143,81 +143,6 @@ void PrintData(PBYTE pData, int nSize)
143143
printf(" %s\r\n", szPrint);
144144
}
145145

146-
// bool StringToWideString(char *pszSrc, wchar_t *&pszDest)
147-
// {
148-
// if (!pszSrc)
149-
// return false;
150-
// int nSrcLen = strlen(pszSrc);
151-
// int nDestLen = nSrcLen * 2;
152-
//
153-
// pszDest = NULL;
154-
// pszDest = new wchar_t[nDestLen];
155-
// if (!pszDest)
156-
// return false;
157-
// nDestLen = nDestLen * sizeof(wchar_t);
158-
// memset(pszDest, 0, nDestLen);
159-
// int iRet;
160-
// iconv_t cd;
161-
// cd = iconv_open("UTF-32", "UTF-8");
162-
// if((iconv_t)-1 == cd) {
163-
// delete []pszDest;
164-
// pszDest = NULL;
165-
// return false;
166-
// }
167-
// char *pIn, *pOut;
168-
// pIn = (char *)pszSrc;
169-
// pOut = (char *)pszDest;
170-
//
171-
// iRet = iconv(cd, (char **)&pIn, (size_t *)&nSrcLen, (char **)&pOut, (size_t *)&nDestLen);
172-
//
173-
// if(iRet == -1) {
174-
// delete []pszDest;
175-
// pszDest = NULL;
176-
// iconv_close(cd);
177-
// return false;
178-
// }
179-
//
180-
// iconv_close(cd);
181-
//
182-
// return true;
183-
// }
184-
// bool WideStringToString(wchar_t *pszSrc, char *&pszDest)
185-
// {
186-
// if (!pszSrc)
187-
// return false;
188-
// int nSrcLen = wcslen(pszSrc);
189-
// int nDestLen = nSrcLen * 2;
190-
// nSrcLen = nSrcLen * sizeof(wchar_t);
191-
// pszDest = NULL;
192-
// pszDest = new char[nDestLen];
193-
// if (!pszDest)
194-
// return false;
195-
// memset(pszDest, 0, nDestLen);
196-
// int iRet;
197-
// iconv_t cd;
198-
// cd = iconv_open("UTF-8", "UTF-32");
199-
//
200-
// if((iconv_t)-1 == cd) {
201-
// delete []pszDest;
202-
// pszDest = NULL;
203-
// return false;
204-
// }
205-
// char *pIn, *pOut;
206-
// pIn = (char *)pszSrc;
207-
// pOut = (char *)pszDest;
208-
// iRet = iconv(cd, (char **)&pIn, (size_t *)&nSrcLen, (char **)&pOut, (size_t *)&nDestLen);
209-
//
210-
// if(iRet == -1) {
211-
// delete []pszDest;
212-
// pszDest = NULL;
213-
// iconv_close(cd);
214-
// return false;
215-
// }
216-
//
217-
// iconv_close(cd);
218-
//
219-
// return true;
220-
// }
221146
int find_config_item(CONFIG_ITEM_VECTOR &vecItems, const char *pszName)
222147
{
223148
unsigned int i;
@@ -1907,16 +1832,20 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
19071832
CRKImage *pImage = NULL;
19081833
CRKBoot *pBoot = NULL;
19091834
CRKComm *pComm = NULL;
1910-
bool bRet, bSuccess = false;
1835+
bool bRet,bNewIDBlock=false, bSuccess = false;
19111836
int iRet;
1837+
unsigned int i;
19121838
signed char index;
1913-
USHORT usFlashDataSec, usFlashBootSec;
1914-
DWORD dwLoaderSize, dwLoaderDataSize, dwDelay, dwSectorNum;
1839+
USHORT usFlashDataSec, usFlashBootSec, usFlashHeadSec;
1840+
DWORD dwLoaderSize, dwLoaderDataSize, dwLoaderHeadSize, dwDelay, dwSectorNum;
19151841
char loaderCodeName[] = "FlashBoot";
19161842
char loaderDataName[] = "FlashData";
1843+
char loaderHeadName[] = "FlashHead";
19171844
PBYTE loaderCodeBuffer = NULL;
19181845
PBYTE loaderDataBuffer = NULL;
1846+
PBYTE loaderHeadBuffer = NULL;
19191847
PBYTE pIDBData = NULL;
1848+
BYTE capability[8];
19201849
pImage = new CRKImage(szLoader, bRet);
19211850
if (!bRet){
19221851
ERROR_COLOR_ATTR;
@@ -1987,9 +1916,51 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
19871916
goto Exit_UpgradeLoader;
19881917
}
19891918

1919+
index = pBoot->GetIndexByName(ENTRYLOADER, loaderHeadName);
1920+
if (index != -1) {
1921+
bRet = pBoot->GetEntryProperty(ENTRYLOADER, index, dwLoaderHeadSize, dwDelay);
1922+
if (!bRet) {
1923+
if (g_pLogObject) {
1924+
g_pLogObject->Record("ERROR: %s --> Get LoaderHead Entry Size failed", __func__);
1925+
}
1926+
goto Exit_UpgradeLoader;
1927+
}
1928+
1929+
loaderHeadBuffer= new BYTE[dwLoaderHeadSize];
1930+
memset(loaderHeadBuffer, 0, dwLoaderHeadSize);
1931+
if (!pBoot->GetEntryData(ENTRYLOADER,index,loaderHeadBuffer)) {
1932+
if (g_pLogObject) {
1933+
g_pLogObject->Record("ERROR: %s --> Get LoaderHead Data failed", __func__);
1934+
}
1935+
goto Exit_UpgradeLoader;
1936+
}
1937+
1938+
iRet = pComm->RKU_ReadCapability(capability);
1939+
if (iRet != ERR_SUCCESS)
1940+
{
1941+
if (g_pLogObject)
1942+
g_pLogObject->Record("ERROR: %s --> read capability failed", __func__);
1943+
goto Exit_UpgradeLoader;
1944+
}
1945+
if ((capability[1] & 1) == 0) {
1946+
if (g_pLogObject)
1947+
g_pLogObject->Record("ERROR: %s --> device did not support to upgrade the loader", __func__);
1948+
ERROR_COLOR_ATTR;
1949+
printf("Device not support to upgrade the loader!");
1950+
NORMAL_COLOR_ATTR;
1951+
printf("\r\n");
1952+
goto Exit_UpgradeLoader;
1953+
}
1954+
bNewIDBlock = true;
1955+
}
1956+
19901957
usFlashDataSec = (ALIGN(dwLoaderDataSize, 2048)) / SECTOR_SIZE;
19911958
usFlashBootSec = (ALIGN(dwLoaderSize, 2048)) / SECTOR_SIZE;
1992-
dwSectorNum = 4 + usFlashDataSec + usFlashBootSec;
1959+
if (bNewIDBlock) {
1960+
usFlashHeadSec = (ALIGN(dwLoaderHeadSize, 2048)) / SECTOR_SIZE;
1961+
dwSectorNum = usFlashHeadSec + usFlashDataSec + usFlashBootSec;
1962+
} else
1963+
dwSectorNum = 4 + usFlashDataSec + usFlashBootSec;
19931964
pIDBData = new BYTE[dwSectorNum*SECTOR_SIZE];
19941965
if (!pIDBData) {
19951966
ERROR_COLOR_ATTR;
@@ -1999,14 +1970,36 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
19991970
goto Exit_UpgradeLoader;
20001971
}
20011972
memset(pIDBData, 0, dwSectorNum * SECTOR_SIZE);
2002-
iRet = MakeIDBlockData(loaderDataBuffer, loaderCodeBuffer, pIDBData, usFlashDataSec, usFlashBootSec, dwLoaderDataSize, dwLoaderSize, pBoot->Rc4DisableFlag);
2003-
if (iRet != 0) {
2004-
ERROR_COLOR_ATTR;
2005-
printf("Making idblock failed!");
2006-
NORMAL_COLOR_ATTR;
2007-
printf("\r\n");
2008-
goto Exit_UpgradeLoader;
1973+
if (bNewIDBlock) {
1974+
if (pBoot->Rc4DisableFlag)
1975+
{//close rc4 encryption
1976+
for (i=0;i<dwLoaderHeadSize/SECTOR_SIZE;i++)
1977+
{
1978+
P_RC4(loaderHeadBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
1979+
}
1980+
for (i=0;i<dwLoaderDataSize/SECTOR_SIZE;i++)
1981+
{
1982+
P_RC4(loaderDataBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
1983+
}
1984+
for (i=0;i<dwLoaderSize/SECTOR_SIZE;i++)
1985+
{
1986+
P_RC4(loaderCodeBuffer+SECTOR_SIZE*i,SECTOR_SIZE);
1987+
}
1988+
}
1989+
memcpy(pIDBData, loaderHeadBuffer, dwLoaderHeadSize);
1990+
memcpy(pIDBData+SECTOR_SIZE*usFlashHeadSec, loaderDataBuffer, dwLoaderDataSize);
1991+
memcpy(pIDBData+SECTOR_SIZE*(usFlashHeadSec+usFlashDataSec), loaderCodeBuffer, dwLoaderSize);
1992+
} else {
1993+
iRet = MakeIDBlockData(loaderDataBuffer, loaderCodeBuffer, pIDBData, usFlashDataSec, usFlashBootSec, dwLoaderDataSize, dwLoaderSize, pBoot->Rc4DisableFlag);
1994+
if (iRet != 0) {
1995+
ERROR_COLOR_ATTR;
1996+
printf("Making idblock failed!");
1997+
NORMAL_COLOR_ATTR;
1998+
printf("\r\n");
1999+
goto Exit_UpgradeLoader;
2000+
}
20092001
}
2002+
20102003
iRet = pComm->RKU_WriteLBA(64, dwSectorNum, pIDBData);
20112004
CURSOR_MOVEUP_LINE(1);
20122005
CURSOR_DEL_LINE;
@@ -2028,6 +2021,8 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
20282021
delete []loaderCodeBuffer;
20292022
if (loaderDataBuffer)
20302023
delete []loaderDataBuffer;
2024+
if (loaderHeadBuffer)
2025+
delete []loaderHeadBuffer;
20312026
if (pIDBData)
20322027
delete []pIDBData;
20332028
return bSuccess;
@@ -2412,6 +2407,30 @@ bool read_capability(STRUCT_RKDEVICE_DESC &dev)
24122407
{
24132408
printf("First 4m Access:\tenabled\r\n");
24142409
}
2410+
if (capability[0] & 8)
2411+
{
2412+
printf("Read LBA:\tenabled\r\n");
2413+
}
2414+
2415+
if (capability[0] & 20)
2416+
{
2417+
printf("Read Com Log:\tenabled\r\n");
2418+
}
2419+
2420+
if (capability[0] & 40)
2421+
{
2422+
printf("Read IDB Config:\tenabled\r\n");
2423+
}
2424+
2425+
if (capability[0] & 80)
2426+
{
2427+
printf("Read Secure Mode:\tenabled\r\n");
2428+
}
2429+
2430+
if (capability[1] & 1)
2431+
{
2432+
printf("New IDB:\tenabled\r\n");
2433+
}
24152434
bSuccess = true;
24162435
}
24172436
} else {

0 commit comments

Comments
 (0)