--- a/OtaSupport.c | |
+++ b/OtaSupport.c | |
@@ -116,10 +116,9 @@ typedef bool (*efuse_AESKeyPresent_t)(void); | |
typedef int (*efuse_LoadUniqueKey_t)(void); | |
typedef uint32_t (*aesLoadKeyFromOTP_t)(AES_KEY_SIZE_T keySize); | |
-const static efuse_LoadUniqueKey_t efuse_LoadUniqueKey = (efuse_LoadUniqueKey_t)ROM_API_efuse_LoadUniqueKey; | |
-const static aesLoadKeyFromOTP_t aesLoadKeyFromOTP = (aesLoadKeyFromOTP_t)ROM_API_aesLoadKeyFromOTP; | |
-const static efuse_AESKeyPresent_t efuse_AESKeyPresent = (efuse_AESKeyPresent_t)ROM_API_efuse_AESKeyPresent; | |
- | |
+static const efuse_LoadUniqueKey_t efuse_LoadUniqueKey = (efuse_LoadUniqueKey_t)ROM_API_efuse_LoadUniqueKey; | |
+static const aesLoadKeyFromOTP_t aesLoadKeyFromOTP = (aesLoadKeyFromOTP_t)ROM_API_aesLoadKeyFromOTP; | |
+static const efuse_AESKeyPresent_t efuse_AESKeyPresent = (efuse_AESKeyPresent_t)ROM_API_efuse_AESKeyPresent; | |
#if gUsePasswordCiphering_d | |
const static uint32_t (*aesLoadKeyFromSW)(AES_KEY_SIZE_T keySize, | |
@@ -187,6 +186,7 @@ typedef struct { | |
int max_cnt_idle; | |
int q_sz; | |
int q_max; | |
+ osaMutexId_t msgQueueMutex; | |
#endif | |
eEncryptionKeyType ciphered_mode; | |
#if gExternalFlashIsCiphered_d | |
@@ -207,6 +207,7 @@ typedef struct { | |
#if ( gEepromParams_bufferedWrite_c == 1) | |
bool_t gOtaInvalidateHeader; | |
#endif | |
+ bool_t isInitialized; | |
} OtaFlashTaskContext_t; | |
/****************************************************************************** | |
@@ -287,6 +288,7 @@ static OtaFlashTaskContext_t mHandle = { | |
#if ( gEepromParams_bufferedWrite_c == 1) | |
.gOtaInvalidateHeader = FALSE, | |
#endif | |
+ .isInitialized = FALSE, | |
}; | |
@@ -460,6 +462,11 @@ otaResult_t OTA_StartImageWithMaxSize(uint32_t length, uint32_t maxAllowedArchSi | |
int OTA_TransactionResume(void) | |
{ | |
int nb_treated = 0; | |
+ | |
+ if (mHandle.isInitialized) | |
+ { | |
+ OSA_MutexLock(mHandle.msgQueueMutex, osaWaitForever_c); | |
+ | |
while ( OTA_IsTransactionPending() /* There are queued flash operations pending in queue */ | |
&& (nb_treated < MAX_CONSECUTIVE_TRANSACTIONS)) /* ... but do not schedule too many in a same pass */ | |
{ | |
@@ -553,6 +560,9 @@ int OTA_TransactionResume(void) | |
/* There were transactions pending but we consumed some */ | |
mHandle.cnt_idle_op = 0; | |
+ OSA_MutexUnlock(mHandle.msgQueueMutex); | |
+ } | |
+ | |
return nb_treated; | |
} | |
/***************************************************************************** | |
@@ -578,7 +588,11 @@ void OTA_WritePendingData(void) | |
while (EEPROM_isBusy()); | |
/* Always take head of queue : we just queued something so we know it is not empty */ | |
- OTA_TransactionResume(); | |
+ while (OTA_IsTransactionPending()) | |
+ { | |
+ OTA_TransactionResume(); | |
+ } | |
+ | |
while (EEPROM_isBusy()); | |
} while (0); | |
@@ -877,7 +891,14 @@ otaResult_t OTA_PushImageChunk(uint8_t* pData, uint16_t length, uint32_t* pImage | |
OTA_MsgQueue(pMsg); | |
OTA_DBG_LOG("Submitted page Addr=%x", pMsg->flash_addr); | |
- mHandle.cur_transaction = NULL; | |
+ if (mHandle.cur_transaction != NULL) | |
+ { | |
+ mHandle.cur_transaction = NULL; | |
+ } | |
+ else | |
+ { | |
+ Addr += PROGRAM_PAGE_SZ; | |
+ } | |
} | |
else | |
{ | |
@@ -1229,6 +1250,9 @@ otaResult_t OTA_ClientInit(void) | |
OTA_DEBUG_TRACE("%s\r\n", __FUNCTION__); | |
otaResult_t res = gOtaSuccess_c; | |
+ if (!mHandle.isInitialized) | |
+ { | |
+ | |
mHandle.LoadOtaImageInEepromInProgress = FALSE; | |
mHandle.OtaImageTotalLength = 0; | |
mHandle.OtaImageCurrentLength = 0; | |
@@ -1255,6 +1279,7 @@ otaResult_t OTA_ClientInit(void) | |
#if gOtaEepromPostedOperations_d | |
MSG_InitQueue(&mHandle.op_queue); | |
+ mHandle.msgQueueMutex = OSA_MutexCreate(); | |
#endif | |
#if gExternalFlashIsCiphered_d | |
mHandle.ciphered_mode = (efuse_AESKeyPresent()) ? eEfuseKey : eSoftwareKey; | |
@@ -1262,6 +1287,9 @@ otaResult_t OTA_ClientInit(void) | |
mHandle.ciphered_mode = eCipherKeyNone; | |
#endif | |
res = OTA_InitExternalMemory(); | |
+ | |
+ mHandle.isInitialized = TRUE; | |
+ } | |
return res; | |
} | |
@@ -1645,7 +1673,7 @@ static uint32_t OTA_GetMaxAllowedArchSize(void) | |
return gFlashMaxStatedSize*2 - current_app_stated_size; | |
#else | |
/* Read the value from the psector img directory */ | |
- uint32_t allowedSize = 0; | |
+ uint32_t maxImgPages = 0; | |
uint8_t i; | |
psector_page_data_t * mPage0Hdl = psector_GetPage0Handle(); | |
if (mPage0Hdl != NULL) | |
@@ -1653,12 +1681,12 @@ static uint32_t OTA_GetMaxAllowedArchSize(void) | |
image_directory_entry_t * currentEntry = mPage0Hdl->page0_v3.img_directory; | |
for (i=0; i<IMG_DIRECTORY_MAX_SIZE; i++) | |
{ | |
- if (currentEntry->img_nb_pages > allowedSize) | |
- allowedSize = currentEntry->img_nb_pages*512; | |
+ if (currentEntry->img_nb_pages > maxImgPages) | |
+ maxImgPages = currentEntry->img_nb_pages; | |
currentEntry++; | |
} | |
} | |
- return allowedSize; | |
+ return maxImgPages*512; /* 512 corresponding to the size of one page in the internal flash */ | |
#endif | |
} |