@@ -289,6 +289,63 @@ int invoke_boot_go(struct sim_context *ctx, struct area_desc *adesc,
289
289
}
290
290
}
291
291
292
+ int invoke_boot_load_image_from_flash_to_sram (struct sim_context * ctx , struct area_desc * adesc )
293
+ {
294
+ #ifdef MCUBOOT_RAM_LOAD
295
+ int res ;
296
+ struct boot_loader_state * state ;
297
+ const struct flash_area * fa_p ;
298
+ struct image_header hdr ;
299
+
300
+ #if defined(MCUBOOT_SIGN_RSA ) || \
301
+ (defined(MCUBOOT_SIGN_EC256 ) && defined(MCUBOOT_USE_MBED_TLS )) || \
302
+ (defined(MCUBOOT_ENCRYPT_EC256 ) && defined(MCUBOOT_USE_MBED_TLS )) || \
303
+ (defined(MCUBOOT_ENCRYPT_X25519 ) && defined(MCUBOOT_USE_MBED_TLS ))
304
+ mbedtls_platform_set_calloc_free (calloc , free );
305
+ #endif
306
+
307
+ state = malloc (sizeof (struct boot_loader_state ));
308
+
309
+ sim_set_flash_areas (adesc );
310
+ sim_set_context (ctx );
311
+ boot_state_clear (state );
312
+
313
+ res = flash_area_open (FLASH_AREA_IMAGE_PRIMARY (0 ), & fa_p );
314
+ if (res != 0 ) {
315
+ printf ("Failed to open primary image area: %d\n" , res );
316
+ sim_reset_flash_areas ();
317
+ sim_reset_context ();
318
+ free (state );
319
+ return res ;
320
+ }
321
+
322
+ res = boot_image_load_header (fa_p , & hdr );
323
+ if (res != 0 ) {
324
+ printf ("Failed to load image header: %d\n" , res );
325
+ flash_area_close (fa_p );
326
+ sim_reset_flash_areas ();
327
+ sim_reset_context ();
328
+ free (state );
329
+ return res ;
330
+ }
331
+
332
+ res = boot_load_image_from_flash_to_sram (state , & hdr , fa_p );
333
+ if (res != 0 ) {
334
+ printf ("Failed to load image from flash to SRAM: %d\n" , res );
335
+ }
336
+
337
+ flash_area_close (fa_p );
338
+ sim_reset_flash_areas ();
339
+ sim_reset_context ();
340
+ free (state );
341
+ return res ;
342
+ #else
343
+ (void )ctx ;
344
+ (void )adesc ;
345
+ return 0 ;
346
+ #endif /* MCUBOOT_RAM_LOAD */
347
+ }
348
+
292
349
void * os_malloc (size_t size )
293
350
{
294
351
// printf("os_malloc 0x%x bytes\n", size);
0 commit comments