@@ -88,10 +88,14 @@ static uint32_t emu_current_version(void)
8888{
8989 uintptr_t addr = (uintptr_t )WOLFBOOT_PARTITION_BOOT_ADDRESS ;
9090
91+ #ifdef WOLFCRYPT_SECURE_MODE
92+ return wolfBoot_nsc_current_firmware_version ();
93+ #else
9194 if (addr == 0u ) {
9295 return emu_get_blob_version_addr (0u );
9396 }
9497 return wolfBoot_get_blob_version ((uint8_t * )addr );
98+ #endif
9599}
96100
97101void emu_uart_putc (char c )
@@ -153,7 +157,9 @@ static void wait_for_update(uint32_t version)
153157
154158 memset (page , 0xFF , PAGESIZE );
155159
160+ #ifndef WOLFCRYPT_SECURE_MODE
156161 hal_flash_unlock ();
162+ #endif
157163
158164 emu_uart_write (START );
159165 for (i = 3 ; i >= 0 ; i -- ) {
@@ -209,23 +215,47 @@ static void wait_for_update(uint32_t version)
209215 page_idx += psize ;
210216 if ((page_idx == PAGESIZE ) || (next_seq + (uint32_t )psize >= tot_len )) {
211217 uint32_t dst = (WOLFBOOT_PARTITION_UPDATE_ADDRESS + recv_seq + (uint32_t )psize ) - (uint32_t )page_idx ;
218+ uint32_t dst_off = (recv_seq + (uint32_t )psize ) - (uint32_t )page_idx ;
219+ #ifdef WOLFCRYPT_SECURE_MODE
220+ if ((dst_off % WOLFBOOT_SECTOR_SIZE ) == 0u ) {
221+ wolfBoot_nsc_erase_update (dst_off , WOLFBOOT_SECTOR_SIZE );
222+ }
223+ wolfBoot_nsc_write_update (dst_off , page , PAGESIZE );
224+ #else
212225 if ((dst % WOLFBOOT_SECTOR_SIZE ) == 0u ) {
213226 hal_flash_erase (dst , WOLFBOOT_SECTOR_SIZE );
214227 }
215228 hal_flash_write (dst , page , PAGESIZE );
229+ #endif
216230 memset (page , 0xFF , PAGESIZE );
217231 }
218232 next_seq += (uint32_t )psize ;
219233 }
220234 ack (next_seq );
221235 if (next_seq >= tot_len ) {
236+ uint32_t update_ver ;
237+ #ifdef WOLFCRYPT_SECURE_MODE
238+ update_ver = wolfBoot_nsc_update_firmware_version ();
239+ #else
240+ update_ver = wolfBoot_get_blob_version ((uint8_t * )WOLFBOOT_PARTITION_UPDATE_ADDRESS );
241+ #endif
242+ if (update_ver == 7u ) {
243+ __asm volatile ("bkpt #0x4D" );
244+ break ;
245+ }
246+ #ifdef WOLFCRYPT_SECURE_MODE
247+ wolfBoot_nsc_update_trigger ();
248+ #else
222249 wolfBoot_update_trigger ();
250+ #endif
223251 __asm volatile ("bkpt #0x47" );
224252 break ;
225253 }
226254 }
227255
256+ #ifndef WOLFCRYPT_SECURE_MODE
228257 hal_flash_lock ();
258+ #endif
229259
230260 while (1 ) {
231261 __asm volatile ("wfi" );
@@ -242,7 +272,11 @@ int main(void)
242272 printf ("get_version=%lu\n" , (unsigned long )version );
243273
244274 if (version == 4u ) {
275+ #ifdef WOLFCRYPT_SECURE_MODE
276+ wolfBoot_nsc_success ();
277+ #else
245278 wolfBoot_success ();
279+ #endif
246280 __asm volatile ("bkpt #0x4A" );
247281 while (1 ) {
248282 __asm volatile ("wfi" );
@@ -255,7 +289,11 @@ int main(void)
255289 }
256290 }
257291 if (version == 8u ) {
292+ #ifdef WOLFCRYPT_SECURE_MODE
293+ wolfBoot_nsc_success ();
294+ #else
258295 wolfBoot_success ();
296+ #endif
259297 __asm volatile ("bkpt #0x4E" );
260298 while (1 ) {
261299 __asm volatile ("wfi" );
0 commit comments