DA14585 Secondary Booter - Booting encrypted image bigger than 80KB
ID: LPCBARESDK-685
Status: Fixed
First reported: 6.0.14.1114
Fixed in: 6.0.16.1143
Description
With the SDK 6.0.14, the secondary booter enables by default the watchdog in reset mode. The watchdog is set to expire after 2.6 seconds. An image close to or bigger then 80KB will take more than 2.6 seconds to decrypt. During the decryption the watchdog is not refreshed. This results in the reset being triggered during the decryption process preventing the device from operating correctly. Try to boot an image near to 80KB. The decryption of a large image takes longer than the default load value of the watchdog. The watchdog is not refreshed while decryption is ongoing. Hence a reset is issued after 2.6 seconds.
Workaround
The solution is to change the Decrypt_Image() function and decrypt in chunks in order to allow the watchdog to be refreshed before it expires.
+#define DECRYPT_CHUNK 32*AES_BLOCKSIZE
+
void Decrypt_Image(int nsize)
{
+ uint8_t sys_ram = (uint8_t) SYSRAM_BASE_ADDRESS;
+
AES_set_key(&ctx,Key,IV,AES_MODE_128);
AES_convert_key(&ctx);
- AES_cbc_decrypt(&ctx, SYSRAM_BASE_ADDRESS,SYSRAM_BASE_ADDRESS,nsize);
-}
+
+ for(int i=nsize; i>=0; i-=DECRYPT_CHUNK)
+ {
+ AES_cbc_decrypt(&ctx, (const uint8_t*)sys_ram, sys_ram, DECRYPT_CHUNK);
+ SetWord16(WATCHDOG_REG, WATCHDOG_DEFAULT_PERIOD);
+ sys_ram += DECRYPT_CHUNK;
+ }
+
+}
The decryption procedure finishes correctly and the proximity reporter application advertises as expected.