@@ -143,81 +143,6 @@ void PrintData(PBYTE pData, int nSize)
143
143
printf (" %s\r\n " , szPrint);
144
144
}
145
145
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
- // }
221
146
int find_config_item (CONFIG_ITEM_VECTOR &vecItems, const char *pszName)
222
147
{
223
148
unsigned int i;
@@ -1907,16 +1832,20 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
1907
1832
CRKImage *pImage = NULL ;
1908
1833
CRKBoot *pBoot = NULL ;
1909
1834
CRKComm *pComm = NULL ;
1910
- bool bRet, bSuccess = false ;
1835
+ bool bRet,bNewIDBlock= false , bSuccess = false ;
1911
1836
int iRet;
1837
+ unsigned int i;
1912
1838
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;
1915
1841
char loaderCodeName[] = " FlashBoot" ;
1916
1842
char loaderDataName[] = " FlashData" ;
1843
+ char loaderHeadName[] = " FlashHead" ;
1917
1844
PBYTE loaderCodeBuffer = NULL ;
1918
1845
PBYTE loaderDataBuffer = NULL ;
1846
+ PBYTE loaderHeadBuffer = NULL ;
1919
1847
PBYTE pIDBData = NULL ;
1848
+ BYTE capability[8 ];
1920
1849
pImage = new CRKImage (szLoader, bRet);
1921
1850
if (!bRet){
1922
1851
ERROR_COLOR_ATTR;
@@ -1987,9 +1916,51 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
1987
1916
goto Exit_UpgradeLoader;
1988
1917
}
1989
1918
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
+
1990
1957
usFlashDataSec = (ALIGN (dwLoaderDataSize, 2048 )) / SECTOR_SIZE;
1991
1958
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;
1993
1964
pIDBData = new BYTE[dwSectorNum*SECTOR_SIZE];
1994
1965
if (!pIDBData) {
1995
1966
ERROR_COLOR_ATTR;
@@ -1999,14 +1970,36 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
1999
1970
goto Exit_UpgradeLoader;
2000
1971
}
2001
1972
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
+ }
2009
2001
}
2002
+
2010
2003
iRet = pComm->RKU_WriteLBA (64 , dwSectorNum, pIDBData);
2011
2004
CURSOR_MOVEUP_LINE (1 );
2012
2005
CURSOR_DEL_LINE;
@@ -2028,6 +2021,8 @@ bool upgrade_loader(STRUCT_RKDEVICE_DESC &dev, char *szLoader)
2028
2021
delete [] loaderCodeBuffer;
2029
2022
if (loaderDataBuffer)
2030
2023
delete [] loaderDataBuffer;
2024
+ if (loaderHeadBuffer)
2025
+ delete [] loaderHeadBuffer;
2031
2026
if (pIDBData)
2032
2027
delete [] pIDBData;
2033
2028
return bSuccess;
@@ -2412,6 +2407,30 @@ bool read_capability(STRUCT_RKDEVICE_DESC &dev)
2412
2407
{
2413
2408
printf (" First 4m Access:\t enabled\r\n " );
2414
2409
}
2410
+ if (capability[0 ] & 8 )
2411
+ {
2412
+ printf (" Read LBA:\t enabled\r\n " );
2413
+ }
2414
+
2415
+ if (capability[0 ] & 20 )
2416
+ {
2417
+ printf (" Read Com Log:\t enabled\r\n " );
2418
+ }
2419
+
2420
+ if (capability[0 ] & 40 )
2421
+ {
2422
+ printf (" Read IDB Config:\t enabled\r\n " );
2423
+ }
2424
+
2425
+ if (capability[0 ] & 80 )
2426
+ {
2427
+ printf (" Read Secure Mode:\t enabled\r\n " );
2428
+ }
2429
+
2430
+ if (capability[1 ] & 1 )
2431
+ {
2432
+ printf (" New IDB:\t enabled\r\n " );
2433
+ }
2415
2434
bSuccess = true ;
2416
2435
}
2417
2436
} else {
0 commit comments