[Feature][ZXW-130]merge P50U02 version
Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I4f29ec5bb7c59385f23738d2b7ca84e67c100f69
diff --git a/boot/common/src/uboot/drivers/efuse/efuse.c b/boot/common/src/uboot/drivers/efuse/efuse.c
old mode 100644
new mode 100755
index 46bc303..96e4901
--- a/boot/common/src/uboot/drivers/efuse/efuse.c
+++ b/boot/common/src/uboot/drivers/efuse/efuse.c
@@ -25,10 +25,10 @@
#include <../drivers/hash/drv_hash.h>
#include <../drivers/rsa/drv_rsa.h>
+#include <../drivers/hash/sha256.h>
#include <secure_verify.h>
#include <asm/arch/efuse.h>
-
-
+#include <boot_mode.h>
/****************************************************************************
* Local Macros
@@ -51,6 +51,14 @@
static unsigned char gbEfuseReadFlag = 0;
+otp_struct otpInfo;
+unsigned int guiOtpStatus = 1;
+extern int rootfs_flag;
+extern int m0_flag;
+extern int zsp_flag;
+extern int g_iftype;
+extern unsigned char g_nor_flag;
+
/****************************************************************************
* Local Funcs
****************************************************************************/
@@ -129,6 +137,62 @@
return 1;
}
#endif
+
+/*
+* Convert BIGENDIAN To SMALLENDIAN.
+*/
+void BIG2SMALL(u32 *pBuffer, u32 uiLen)
+{
+ u32 uiLoop;
+ u32 uiTmp = 0;
+
+ for (uiLoop = 0; uiLoop < uiLen/sizeof(u32); uiLoop++)
+ {
+ uiTmp = pBuffer[uiLoop];
+ pBuffer[uiLoop] = 0;
+ pBuffer[uiLoop] += (uiTmp & 0x000000FF) << 24;
+ pBuffer[uiLoop] += (uiTmp & 0x0000FF00) << 8;
+ pBuffer[uiLoop] += (uiTmp & 0x00FF0000) >> 8;
+ pBuffer[uiLoop] += (uiTmp & 0xFF000000) >> 24;
+ }
+}
+
+void get_otp_secure_verify_status(void)
+{
+ u32 uiLen;
+ otp_struct *psEfuseInfo = NULL;
+
+ /*
+ * 0. Èç¹ûsecure flag²»µÈÓÚ0£¬Í˳ö°²È«boot¡£
+ */
+ psEfuseInfo = (otp_struct*)&otpInfo;
+ if(psEfuseInfo->secure_flag != 0)
+ {
+ guiOtpStatus = 1; //Disable.
+ BOOT_PRINTF(UBOOT_NOTICE, "secure_flag!=0xFF, SecureVerify->Disable.\n");
+ return ;
+ }
+
+ /*
+ * 1.´ÓefuseÖжÁ³öpuk_hash[255:0], ÅжÏÈç¹ûÈ«²¿Îª0Í˳ö°²È«boot¡£
+ */
+ for(uiLen = 0; uiLen < 8; uiLen++)
+ {
+ if(psEfuseInfo->puk_hash[uiLen] != 0)
+ {
+ break;
+ }
+ if(uiLen == 7)
+ {
+ guiOtpStatus = 1; //Disable.
+ BOOT_PRINTF(UBOOT_NOTICE, "PubKey_HASH=Invalid, SecureVerify->Disable.\n");
+ return ;
+ }
+ }
+ BOOT_PRINTF(UBOOT_NOTICE, "All Flag & Param is Valid, SecureVerify->ENABLE.\n");
+ guiOtpStatus = 0; //Enable.
+}
+
static void efuse_get_data(void)
{
efuse_struct *psEfuseInfo = NULL;
@@ -168,7 +232,9 @@
BOOT_PRINTF(UBOOT_NOTICE, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
}
else if(((psEfuseInfo->secure_flag >> 8) == ZX297520V3ECOSC_GW_NYC_2G_DDR)
- ||((psEfuseInfo->secure_flag >> 8) == ZX297520V3ECOGG_GW_NYC_2G_DDR))
+ ||((psEfuseInfo->secure_flag >> 8) == ZX297520V3ECOGG_GW_NYC_2G_DDR)
+ ||((psEfuseInfo->secure_flag >> 8) == ZX297520V3ECOGG_GW_NYC_NOR_2G_DDR)
+ ||((psEfuseInfo->secure_flag >> 8) == ZX297520V3ECOSC_GW_NYC_NOR_2G_DDR))
{
g_ddr_size_flag = CHIP_DDR_IS_256M;
BOOT_PRINTF(UBOOT_NOTICE, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
@@ -217,98 +283,440 @@
return 0;
}
+u8 rootfs_secure_verify(u32 addr)
+{
+ if(g_nor_flag == 1)
+ {
+
+ u32 uiLen = 0;
+ u32 uiRet = -1;
+ u32 uiLoop = 0;
+ image_header_t *puiLegacyRootfsAddr = NULL;
+ sImageNewHeader *psRootfsHeader = NULL;
+ u32 *puiDataLoadAddr = NULL;
+ u32 *puiArrPubKeyEN = NULL;
+ u32 *puiArrPubKey = NULL;
+ u32 *puiArrHASH = NULL;
+ otp_struct *psEfuseInfo = NULL;
+ u32 uiHashResArr[8] = {0};
+ u32 uiHashResLen = 0;
+ u32 uiHashVerifySize = 0;
+ u32 uiRsaResArr[64] = {0};
+ u32 puiArrPubKeyE[64] = {0};
+ T_Rsa_Paramter sRSAInput;
+ u32 *puiRsaResAddr = NULL;
+ u32 sRamKey[9] = {0x0,0x33fa3e31,0x90d8d15a,0x073cee04,0x82ac24aa,0x2262748e,0x1a3663c7,0x4b603f6f,0xd098e0d8};
+ if(NULL == addr)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Bad Parameter(Empty Pointer)!\n");
+ return -1;
+ }
+
+ psRootfsHeader = (sImageNewHeader *)addr;
+ puiLegacyRootfsAddr = (image_header_t *)(addr + sizeof(sImageNewHeader));
+ uiHashVerifySize = ___htonl(puiLegacyRootfsAddr->ih_size) + sizeof(image_header_t);
+
+ //psEfuseInfo = (otp_struct*)sRamKey;
+ psEfuseInfo = (otp_struct*)&otpInfo;
+
+ /*
+ * step 0
+ */
+ puiArrPubKeyEN = psRootfsHeader->uiPubKeyRsaE;
+ uiLen = 380;
+ puiArrPubKey = &(psRootfsHeader->uiPubKeyRsaELen);
+ sha256_csum_wd((const unsigned char *)puiArrPubKey, uiLen, (unsigned char *)uiHashResArr);
+ uiHashResLen = 8;
+ /*´óС¶Ëת»»*/
+ BIG2SMALL(uiHashResArr, 32);
+
+ BOOT_PRINTF(UBOOT_DBG, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
+
+ if(efuse_cmp_word(psEfuseInfo->puk_hash, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "PubKey Hash Verify -> Failed !\n");
+ return 1;
+ }
+ puiArrHASH = psRootfsHeader->uiHashY;
+
+ /*
+ * step 1
+ */
+ memcpy(puiArrPubKeyE+63, puiArrPubKeyEN, 4);
+ sRSAInput.udCalMode = RSA_MOD_EXPO_WITH_INIT;
+ sRSAInput.udNbitLen = 2048;
+ sRSAInput.udEbitLen = 2048;
+ sRSAInput.pudInputM = puiArrHASH;
+ sRSAInput.pudInputE = puiArrPubKeyE;
+ sRSAInput.pudInputN = psRootfsHeader->uiPubKeyRsaN;
+ sRSAInput.pudOutputP = uiRsaResArr;
+
+ uiRet = Rsa_Calculate(sRSAInput);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Rsa_Calculate ERROR(0x%x)!\n", uiRet);
+ return 2;
+ }
+ puiRsaResAddr = sRSAInput.pudOutputP + (64 - uiHashResLen);
+
+ /*
+ * step 2
+ */
+ uiLen = uiHashVerifySize;
+ puiDataLoadAddr = CONFIG_SYS_SDRAM_ROOTFS_BASE - sizeof(image_header_t);
+
+ /* Cleanup Output Buffer. */
+ uiHashResLen = 0;
+ memset(uiHashResArr, 0, 8*sizeof(uiHashResArr[0]));
+
+ sha256_csum_wd((const unsigned char *)puiDataLoadAddr, uiLen, (unsigned char *)uiHashResArr);
+ uiHashResLen = 8;
+ /*´óС¶Ëת»»*/
+ BIG2SMALL(uiHashResArr, 32);
+
+ if(efuse_cmp_word(puiRsaResAddr, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "LegacyRootfs Verify -> Failed !\n");
+ return 3;
+ }
+
+ }
+ else
+ {
+
+ u32 uiLen = 0;
+ u32 uiRet = -1;
+ u32 uiLoop = 0;
+ image_header_t *puiLegacyRootfsAddr = NULL;
+ sImageNewHeader *psRootfsHeader = NULL;
+ u32 *puiDataLoadAddr = NULL;
+ u32 *puiArrPubKeyEN = NULL;
+ u32 *puiArrHASH = NULL;
+ efuse_struct *psEfuseInfo = NULL;
+ u32 uiHashResArr[4] = {0};
+ u32 uiHashResLen = 0;
+ u32 uiHashVerifySize = 0;
+ u32 uiRsaResArr[32] = {0};
+ u32 puiArrPubKeyE[32] = {0};
+ u32 puiArrPubKey[64] = {0};
+ T_Rsa_Paramter sRSAInput;
+ u32 *puiRsaResAddr = NULL;
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Bad Parameter(Empty Pointer)!\n");
+ return -1;
+ }
+
+ psRootfsHeader = (sImageNewHeader *)addr;
+ puiLegacyRootfsAddr = (image_header_t *)(addr + sizeof(sImageNewHeader));
+ uiHashVerifySize = ___htonl(puiLegacyRootfsAddr->ih_size) + sizeof(image_header_t);
+
+ psEfuseInfo = (efuse_struct*)EFUSE_RAM_BASE;
+
+ /*
+ * step 0
+ */
+
+ uiLen = E_N_LEN;
+ puiArrPubKeyEN = psRootfsHeader->uiPubKeyRsaE;
+ memcpy(puiArrPubKeyE+31, puiArrPubKeyEN, 4);
+ memcpy(puiArrPubKey+31, puiArrPubKeyEN, 4);
+ memcpy(puiArrPubKey+32, psRootfsHeader->uiPubKeyRsaN, 128);
+
+ Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiArrPubKey, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
+
+ BOOT_PRINTF(UBOOT_DBG, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
+
+ if(efuse_cmp_word(psEfuseInfo->puk_hash, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "PubKey Hash Verify -> Failed !\n");
+ return 1;
+ }
+ puiArrHASH = psRootfsHeader->uiHashY;
+
+ /*
+ * step 1
+ */
+ sRSAInput.udCalMode = RSA_MOD_EXPO_WITH_INIT;
+ sRSAInput.udNbitLen = 1024;
+ sRSAInput.udEbitLen = 1024;
+ sRSAInput.pudInputM = puiArrHASH;
+ sRSAInput.pudInputE = puiArrPubKeyE;
+ sRSAInput.pudInputN = psRootfsHeader->uiPubKeyRsaN;
+ sRSAInput.pudOutputP = uiRsaResArr;
+
+ uiRet = Rsa_Calculate(sRSAInput);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Rsa_Calculate ERROR(0x%x)!\n", uiRet);
+ return 2;
+ }
+ puiRsaResAddr = sRSAInput.pudOutputP + (32 - uiHashResLen);
+
+ /*
+ * step 2
+ */
+ uiLen = uiHashVerifySize;
+ puiDataLoadAddr = CONFIG_SYS_SDRAM_ROOTFS_BASE - sizeof(image_header_t);
+
+ /* Cleanup Output Buffer. */
+ uiHashResLen = 0;
+ memset(uiHashResArr, 0, 4*sizeof(uiHashResArr[0]));
+
+ uiRet = Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiDataLoadAddr, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Hash_Calculate ERROR(0x%x)!\n", uiRet);
+ return -1;
+ }
+
+ if(efuse_cmp_word(puiRsaResAddr, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "LegacyRootfs Verify -> Failed !\n");
+ return 3;
+ }
+ }
+
+ return 0;
+}
+
u8 secure_verify(u32 addr)
{
- u32 uiLen = 0;
- u32 uiRet = -1;
- u32 uiLoop = 0;
- image_header_t *puiLegacyImgAddr = NULL;
- sImageHeader *psImageHeader = NULL;
- u32 *puiDataLoadAddr = NULL;
- u32 *puiArrPubKeyEN = NULL;
- u32 *puiArrHASH = NULL;
+ if(g_nor_flag != 1){
+ u32 uiLen = 0;
+ u32 uiRet = -1;
+ u32 uiLoop = 0;
+ image_header_t *puiLegacyImgAddr = NULL;
+ sImageNewHeader *psImageHeader = NULL;
+ u32 *puiDataLoadAddr = NULL;
+ u32 *puiArrPubKeyEN = NULL;
+ u32 *puiArrHASH = NULL;
- efuse_struct *psEfuseInfo = NULL;
+ efuse_struct *psEfuseInfo = NULL;
- u32 uiHashResArr[4] = {0};
- u32 uiHashResLen = 0;
- u32 uiHashVerifySize = 0;
- u32 uiRsaResArr[32] = {0};
+ u32 uiHashResArr[4] = {0};
+ u32 uiHashResLen = 0;
+ u32 uiHashVerifySize = 0;
+ u32 uiRsaResArr[32] = {0};
+ u32 puiArrPubKeyE[32] = {0};
+ u32 puiArrPubKey[64] = {0};
- T_Rsa_Paramter sRSAInput;
- u32 *puiRsaResAddr = NULL;
+ T_Rsa_Paramter sRSAInput;
+ u32 *puiRsaResAddr = NULL;
- if(NULL == addr)
- {
- BOOT_PRINTF(UBOOT_ERR, "Bad Parameter(Empty Pointer)!\n");
- return -1;
+ if(NULL == addr)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Bad Parameter(Empty Pointer)!\n");
+ return -1;
+ }
+
+ psImageHeader = (sImageNewHeader *)addr;
+
+ if(rootfs_flag == 1)
+ {
+ puiLegacyImgAddr = (image_header_t *)(addr + sizeof(sImageNewHeader) + sizeof(sImageNewHeader) + sizeof(image_header_t));
+ uiHashVerifySize = ___htonl(puiLegacyImgAddr->ih_size) + sizeof(image_header_t) + sizeof(image_header_t) + sizeof(sImageNewHeader);
+ }
+ else
+ {
+ puiLegacyImgAddr = (image_header_t *)(addr + sizeof(sImageNewHeader));
+ uiHashVerifySize = ___htonl(puiLegacyImgAddr->ih_size) + sizeof(image_header_t);
+ }
+
+ psEfuseInfo = (efuse_struct*)EFUSE_RAM_BASE;
+
+ BOOT_PRINTF(UBOOT_NOTICE, "uiHashVerifySize=0x%x, EFUSE_RAM_BASE=0x%x.\n", uiHashVerifySize, EFUSE_RAM_BASE);
+
+ /*
+ * step 0
+ */
+ uiLen = E_N_LEN;
+ puiArrPubKeyEN = psImageHeader->uiPubKeyRsaE;
+ memcpy(puiArrPubKeyE+31, puiArrPubKeyEN, 4);
+ memcpy(puiArrPubKey+31, puiArrPubKeyEN, 4);
+ memcpy(puiArrPubKey+32, psImageHeader->uiPubKeyRsaN, 128);
+
+ Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiArrPubKey, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
+
+ BOOT_PRINTF(UBOOT_DBG, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
+
+ if(efuse_cmp_word(psEfuseInfo->puk_hash, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "PubKey Hash Verify -> Failed !\n");
+ return 1;
+ }
+ puiArrHASH = psImageHeader->uiHashY;
+
+ /*
+ * step 1
+ */
+ sRSAInput.udCalMode = RSA_MOD_EXPO_WITH_INIT;
+ sRSAInput.udNbitLen = 1024;
+ sRSAInput.udEbitLen = 1024;
+ sRSAInput.pudInputM = puiArrHASH;
+ sRSAInput.pudInputE = puiArrPubKeyE;
+ sRSAInput.pudInputN = psImageHeader->uiPubKeyRsaN;
+ sRSAInput.pudOutputP = uiRsaResArr;
+
+ uiRet = Rsa_Calculate(sRSAInput);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Rsa_Calculate ERROR(0x%x)!\n", uiRet);
+ return 2;
+ }
+ puiRsaResAddr = sRSAInput.pudOutputP + (32 - uiHashResLen);
+
+ /*
+ * step 2
+ */
+ uiLen = uiHashVerifySize;
+ if(rootfs_flag == 1)
+ {
+ puiDataLoadAddr = ___htonl(puiLegacyImgAddr->ih_load) - sizeof(image_header_t) - sizeof(image_header_t) - sizeof(sImageNewHeader);
+ }
+ else
+ {
+ if(1 == m0_flag || 1 == zsp_flag){
+ puiDataLoadAddr = (uchar *)addr + sizeof(sImageNewHeader);
+
+ }else{
+ puiDataLoadAddr = ___htonl(puiLegacyImgAddr->ih_load) - sizeof(image_header_t);
+ }
+
+ }
+
+ /* Cleanup Output Buffer. */
+ uiHashResLen = 0;
+ memset(uiHashResArr, 0, 4*sizeof(uiHashResArr[0]));
+
+ uiRet = Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiDataLoadAddr, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Hash_Calculate ERROR(0x%x)!\n", uiRet);
+ return -1;
+ }
+
+ if(efuse_cmp_word(puiRsaResAddr, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "LegacyImg Verify -> Failed !\n");
+ return 3;
+ }
+
}
+ else
+ {
+ u32 uiLen = 0;
+ u32 uiRet = -1;
+ u32 uiLoop = 0;
+ image_header_t *puiLegacyImgAddr = NULL;
+ sImageNewHeader *psImageHeader = NULL;
+ u32 *puiDataLoadAddr = NULL;
+ u32 *puiArrPubKeyEN = NULL;
+ u32 *puiArrPubKey = NULL;
+ u32 *puiArrHASH = NULL;
+ otp_struct *psEfuseInfo = NULL;
+ u32 uiHashResArr[8] = {0};
+ u32 uiHashResLen = 0;
+ u32 uiHashVerifySize = 0;
+ u32 uiRsaResArr[64] = {0};
+ u32 puiArrPubKeyE[64] = {0};
+ T_Rsa_Paramter sRSAInput;
+ u32 *puiRsaResAddr = NULL;
+ u32 sRamKey[9] = {0x0,0x33fa3e31,0x90d8d15a,0x073cee04,0x82ac24aa,0x2262748e,0x1a3663c7,0x4b603f6f,0xd098e0d8};
+ if(NULL == addr)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Bad Parameter(Empty Pointer)!\n");
+ return -1;
+ }
- psImageHeader = (sImageHeader *)addr;
- puiLegacyImgAddr = (image_header_t *)(addr + sizeof(sImageHeader));
- uiHashVerifySize = ___htonl(puiLegacyImgAddr->ih_size) + sizeof(image_header_t);
+ psImageHeader = (sImageNewHeader *)addr;
- psEfuseInfo = (efuse_struct*)EFUSE_RAM_BASE;
+ if(rootfs_flag == 1)
+ {
+ puiLegacyImgAddr = (image_header_t *)(addr + sizeof(sImageNewHeader) + sizeof(sImageNewHeader) + sizeof(image_header_t));
+ uiHashVerifySize = ___htonl(puiLegacyImgAddr->ih_size) + sizeof(image_header_t) + sizeof(image_header_t) + sizeof(sImageNewHeader);
+ }
+ else
+ {
+ puiLegacyImgAddr = (image_header_t *)(addr + sizeof(sImageNewHeader));
+ uiHashVerifySize = ___htonl(puiLegacyImgAddr->ih_size) + sizeof(image_header_t);
+ }
- BOOT_PRINTF(UBOOT_NOTICE, "uiHashVerifySize=0x%x, EFUSE_RAM_BASE=0x%x.\n", uiHashVerifySize, EFUSE_RAM_BASE);
+ psEfuseInfo = (otp_struct*)&otpInfo;
+ //psEfuseInfo = (otp_struct*)sRamKey;
+
+ /*
+ * step 0
+ */
+ uiLen = 380;
+ puiArrPubKey = &(psImageHeader->uiPubKeyRsaELen);
+ puiArrPubKeyEN = psImageHeader->uiPubKeyRsaE;
+ sha256_csum_wd((const unsigned char *)puiArrPubKey, uiLen, (unsigned char *)uiHashResArr);
+ uiHashResLen = 8;
+ /*´óС¶Ëת»»*/
+ BIG2SMALL(uiHashResArr, 32);
- /*
- * step 0
- */
- uiLen = E_N_LEN;
- puiArrPubKeyEN = psImageHeader->uiPubKeyRsaE;
+ BOOT_PRINTF(UBOOT_DBG, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
- Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiArrPubKeyEN, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
+ if(efuse_cmp_word(psEfuseInfo->puk_hash, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "PubKey Hash Verify -> Failed !\n");
+ return 1;
+ }
+ puiArrHASH = psImageHeader->uiHashY;
- BOOT_PRINTF(UBOOT_DBG, "secure_flag=0x%x.\n", psEfuseInfo->secure_flag);
+ /*
+ * step 1
+ */
+ memcpy(puiArrPubKeyE+63, puiArrPubKeyEN, 4);
+ sRSAInput.udCalMode = RSA_MOD_EXPO_WITH_INIT;
+ sRSAInput.udNbitLen = 2048;
+ sRSAInput.udEbitLen = 2048;
+ sRSAInput.pudInputM = puiArrHASH;
+ sRSAInput.pudInputE = puiArrPubKeyE;
+ sRSAInput.pudInputN = psImageHeader->uiPubKeyRsaN;
+ sRSAInput.pudOutputP = uiRsaResArr;
- if(efuse_cmp_word(psEfuseInfo->puk_hash, uiHashResArr, uiHashResLen))
- {
- BOOT_PRINTF(UBOOT_ERR, "PubKey Hash Verify -> Failed !\n");
- return 1;
- }
- puiArrHASH = psImageHeader->uiHashY;
+ uiRet = Rsa_Calculate(sRSAInput);
+ if(uiRet != 0)
+ {
+ BOOT_PRINTF(UBOOT_ERR, "Rsa_Calculate ERROR(0x%x)!\n", uiRet);
+ return 2;
+ }
+ puiRsaResAddr = sRSAInput.pudOutputP + (64 - uiHashResLen);
- /*
- * step 1
- */
- sRSAInput.udCalMode = RSA_MOD_EXPO_WITH_INIT;
- sRSAInput.udNbitLen = 1024;
- sRSAInput.udEbitLen = 1024;
- sRSAInput.pudInputM = puiArrHASH;
- sRSAInput.pudInputE = puiArrPubKeyEN;
- sRSAInput.pudInputN = (puiArrPubKeyEN + 32);
- sRSAInput.pudOutputP = uiRsaResArr;
+ /*
+ * step 2
+ */
+ uiLen = uiHashVerifySize;
+ if(rootfs_flag == 1)
+ {
+ puiDataLoadAddr = ___htonl(puiLegacyImgAddr->ih_load) - sizeof(image_header_t) - sizeof(image_header_t) - sizeof(sImageNewHeader);
+ }
+ else
+ {
+ if(1 == m0_flag || 1 == zsp_flag){
+ puiDataLoadAddr = (uchar *)addr + sizeof(sImageNewHeader);
+
+ }else{
+ puiDataLoadAddr = ___htonl(puiLegacyImgAddr->ih_load) - sizeof(image_header_t);
- uiRet = Rsa_Calculate(sRSAInput);
- if(uiRet != 0)
- {
- BOOT_PRINTF(UBOOT_ERR, "Rsa_Calculate ERROR(0x%x)!\n", uiRet);
- return 2;
- }
- puiRsaResAddr = sRSAInput.pudOutputP + (32 - uiHashResLen);
+ }
+ }
+
+ uiHashResLen = 0;
+ memset(uiHashResArr, 0, 8*sizeof(uiHashResArr[0]));
- /*
- * step 2
- */
- uiLen = uiHashVerifySize;
- puiDataLoadAddr = ___htonl(puiLegacyImgAddr->ih_load) - sizeof(image_header_t);
+ sha256_csum_wd((const unsigned char *)puiDataLoadAddr, uiLen, (unsigned char *)uiHashResArr);
+ uiHashResLen = 8;
+ /*´óС¶Ëת»»*/
+ BIG2SMALL(uiHashResArr, 32);
- /* Cleanup Output Buffer. */
- uiHashResLen = 0;
- memset(uiHashResArr, 0, 4*sizeof(uiHashResArr[0]));
+ if(efuse_cmp_word(puiRsaResAddr, uiHashResArr, uiHashResLen))
+ {
+ BOOT_PRINTF(UBOOT_ERR, "LegacyImg Verify -> Failed !\n");
+ return 3;
+ }
- uiRet = Hash_Calculate(HASH_MODE_MD5, HASH_SMALL_ENDIAN, puiDataLoadAddr, uiLen, NULL, 0, uiHashResArr, &uiHashResLen);
- if(uiRet != 0)
- {
- BOOT_PRINTF(UBOOT_ERR, "Hash_Calculate ERROR(0x%x)!\n", uiRet);
- return -1;
- }
-
- if(efuse_cmp_word(puiRsaResAddr, uiHashResArr, uiHashResLen))
- {
- BOOT_PRINTF(UBOOT_ERR, "LegacyImg Verify -> Failed !\n");
- return 3;
}
return 0;
@@ -360,6 +768,19 @@
/* Efuse Status decide ENABLE/DISABLE SecureVerify. */
efuse_get_data();
+ /*OTP status*/
+
+ if(g_nor_flag == 1)
+ {
+ g_iftype = IF_TYPE_NOR;
+ nand_init();
+ /*Çл»³õʼ»¯spi_nand*/
+ g_iftype = IF_TYPE_SPI_NAND;
+ nand_init();
+
+ get_otp_secure_verify_status();
+ }
+
return 0;
}