51
51
#include "bootutil_priv.h"
52
52
#include "bootutil_misc.h"
53
53
54
+ // TEMP FOR DEBUG - REMOVE
55
+ // #include "bootloader_flash_priv.h"
56
+
57
+ bool aligned_flash_read_ (uintptr_t addr , void * dest , size_t size , bool read_encrypted );
58
+
54
59
#ifdef CONFIG_MCUBOOT
55
60
BOOT_LOG_MODULE_DECLARE (mcuboot );
56
61
#else
@@ -223,6 +228,13 @@ boot_read_flag(const struct flash_area *fap, uint8_t *flag, uint32_t off)
223
228
if (rc < 0 ) {
224
229
return BOOT_EFLASH ;
225
230
}
231
+ // TEMP FOR DEBUG - REMOVE
232
+ uint8_t read_buf ;
233
+ BOOT_LOG_INF ("boot_read_flag whats read rc=0x%x addr=0x%lx 0x%x" , rc , fap -> fa_off + off , * flag );
234
+ rc = aligned_flash_read_ (fap -> fa_off + off , & read_buf , sizeof (read_buf ), false);
235
+ BOOT_LOG_INF ("boot_read_flag whats read - RAW rc=0x%x 0x%x" , rc , read_buf );
236
+ // TEMP FOR DEBUG - REMOVE
237
+
226
238
if (bootutil_buffer_is_erased (fap , flag , sizeof * flag )) {
227
239
* flag = BOOT_FLAG_UNSET ;
228
240
} else {
@@ -235,6 +247,8 @@ boot_read_flag(const struct flash_area *fap, uint8_t *flag, uint32_t off)
235
247
static inline int
236
248
boot_read_copy_done (const struct flash_area * fap , uint8_t * copy_done )
237
249
{
250
+ BOOT_LOG_INF ("boot_read_copy_done" );
251
+
238
252
return boot_read_flag (fap , copy_done , boot_copy_done_off (fap ));
239
253
}
240
254
@@ -248,23 +262,49 @@ boot_read_swap_state(const struct flash_area *fap,
248
262
uint8_t swap_info ;
249
263
int rc ;
250
264
265
+
251
266
off = boot_magic_off (fap );
267
+ BOOT_LOG_INF ("boot_read_swap_state MAGIC addr 0x%lx" , fap -> fa_off + off );
252
268
rc = flash_area_read (fap , off , magic , BOOT_MAGIC_SZ );
253
269
if (rc < 0 ) {
254
270
return BOOT_EFLASH ;
255
271
}
272
+
273
+ // TEMP FOR DEBUG - REMOVE
274
+ uint8_t read_buf [BOOT_MAGIC_SZ ];
275
+ BOOT_LOG_INF ("boot_read_swap_state whats read rc=0x%x" , rc );
276
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_SZ ; i = i + 4 ) {
277
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
278
+ magic [i ], magic [i + 1 ], magic [i + 2 ], magic [i + 3 ]);
279
+ }
280
+ rc = aligned_flash_read_ (fap -> fa_off + off , read_buf , BOOT_MAGIC_SZ , false);
281
+ BOOT_LOG_INF ("boot_read_swap_state whats read - RAW rc=0x%x" , rc );
282
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_SZ ; i = i + 4 ) {
283
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
284
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
285
+ }
286
+ // TEMP FOR DEBUG - REMOVE
287
+
256
288
if (bootutil_buffer_is_erased (fap , magic , BOOT_MAGIC_SZ )) {
257
289
state -> magic = BOOT_MAGIC_UNSET ;
258
290
} else {
259
291
state -> magic = boot_magic_decode (magic );
260
292
}
261
293
262
294
off = boot_swap_info_off (fap );
295
+ BOOT_LOG_INF ("boot_read_swap_state SWAP_INFO addr 0x%lx" , fap -> fa_off + off );
263
296
rc = flash_area_read (fap , off , & swap_info , sizeof swap_info );
264
297
if (rc < 0 ) {
265
298
return BOOT_EFLASH ;
266
299
}
267
300
301
+ // TEMP FOR DEBUG - REMOVE
302
+ uint8_t read_buf_swap ;
303
+ BOOT_LOG_INF ("boot_read_swap_state whats read rc=0x%x 0x%x" , rc , swap_info );
304
+ rc = aligned_flash_read_ (fap -> fa_off + off , & read_buf_swap , sizeof (swap_info ), false);
305
+ BOOT_LOG_INF ("boot_read_swap_state whats read - RAW rc=0x%x 0x%x" , rc , read_buf_swap );
306
+ // TEMP FOR DEBUG - REMOVE
307
+
268
308
/* Extract the swap type and image number */
269
309
state -> swap_type = BOOT_GET_SWAP_TYPE (swap_info );
270
310
state -> image_num = BOOT_GET_IMAGE_NUM (swap_info );
@@ -327,12 +367,48 @@ boot_write_magic(const struct flash_area *fap)
327
367
BOOT_LOG_DBG ("writing magic; fa_id=%d off=0x%lx (0x%lx)" ,
328
368
flash_area_get_id (fap ), (unsigned long )off ,
329
369
(unsigned long )(flash_area_get_off (fap ) + off ));
370
+
371
+ // TEMP FOR DEBUG - REMOVE
372
+ BOOT_LOG_INF ("boot_write_magic writing MAGIC; fa_id=%d off=0x%lx (0x%lx) size=0%0x" ,
373
+ flash_area_get_id (fap ), (unsigned long )pad_off ,
374
+ (unsigned long )(flash_area_get_off (fap ) + pad_off ), BOOT_MAGIC_ALIGN_SIZE );
375
+
376
+ uint8_t read_buf [BOOT_MAGIC_ALIGN_SIZE ];
377
+ rc = flash_area_read (fap , pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE );
378
+ BOOT_LOG_INF ("boot_write_magic whats read BEFORE writing rc=0x%x" , rc );
379
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
380
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
381
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
382
+ }
383
+ rc = aligned_flash_read_ (fap -> fa_off + pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE , false);
384
+ BOOT_LOG_INF ("boot_write_magic whats read BEFORE writing - RAW rc=0x%x" , rc );
385
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
386
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
387
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
388
+ }
389
+ // TEMP FOR DEBUG - REMOVE
390
+
330
391
rc = flash_area_write (fap , pad_off , & magic [0 ], BOOT_MAGIC_ALIGN_SIZE );
331
392
332
393
if (rc != 0 ) {
333
394
return BOOT_EFLASH ;
334
395
}
335
396
397
+ // TEMP FOR DEBUG - REMOVE
398
+ rc = flash_area_read (fap , pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE );
399
+ BOOT_LOG_INF ("boot_write_magic whats read AFTER writing rc=0x%x" , rc );
400
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
401
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
402
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
403
+ }
404
+ rc = aligned_flash_read_ (fap -> fa_off + pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE , false);
405
+ BOOT_LOG_INF ("boot_write_magic whats read AFTER writing - RAW rc=0x%x" , rc );
406
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
407
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
408
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
409
+ }
410
+ // TEMP FOR DEBUG - REMOVE
411
+
336
412
return 0 ;
337
413
}
338
414
@@ -360,11 +436,67 @@ boot_write_trailer(const struct flash_area *fap, uint32_t off,
360
436
memcpy (buf , inbuf , inlen );
361
437
memset (& buf [inlen ], erased_val , align - inlen );
362
438
439
+
440
+ // TEMP FOR DEBUG - REMOVE
441
+ BOOT_LOG_INF ("boot_write_trailer writing TRAILER; fa_id=%d off=0x%lx (0x%lx) size=0x%x" ,
442
+ flash_area_get_id (fap ), (unsigned long )off ,
443
+ (unsigned long )(flash_area_get_off (fap ) + off ), align );
444
+
445
+ uint8_t read_buf [BOOT_MAX_ALIGN ];
446
+
447
+ if ((unsigned long )(flash_area_get_off (fap ) + off ) == 0x16FFA0 ) {
448
+ BOOT_LOG_INF ("boot_write_trailer 0x16FFA0 CASE" );
449
+
450
+ rc = flash_area_read (fap , off + BOOT_MAX_ALIGN , read_buf , BOOT_MAX_ALIGN );
451
+ BOOT_LOG_INF ("boot_write_trailer whats read in addr 0x%lx AFTER ERASE rc=0x%x" ,
452
+ (unsigned long )(flash_area_get_off (fap ) + off + BOOT_MAX_ALIGN ), rc );
453
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
454
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
455
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
456
+ }
457
+ rc = aligned_flash_read_ (fap -> fa_off + off + BOOT_MAX_ALIGN , read_buf , BOOT_MAX_ALIGN , false);
458
+ BOOT_LOG_INF ("boot_write_trailer whats read in addr 0x%lx AFTER ERASE - RAW rc=0x%x" ,
459
+ (unsigned long )(flash_area_get_off (fap ) + off + BOOT_MAX_ALIGN ), rc );
460
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
461
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
462
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
463
+ }
464
+ }
465
+
466
+ rc = flash_area_read (fap , off , read_buf , BOOT_MAX_ALIGN );
467
+ BOOT_LOG_INF ("boot_write_trailer whats read BEFORE writing rc=0x%x" , rc );
468
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
469
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
470
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
471
+ }
472
+ rc = aligned_flash_read_ (fap -> fa_off + off , read_buf , BOOT_MAX_ALIGN , false);
473
+ BOOT_LOG_INF ("boot_write_trailer whats read BEFORE writing - RAW rc=0x%x" , rc );
474
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
475
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
476
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
477
+ }
478
+ // TEMP FOR DEBUG - REMOVE
479
+
363
480
rc = flash_area_write (fap , off , buf , align );
364
481
if (rc != 0 ) {
365
482
return BOOT_EFLASH ;
366
483
}
367
484
485
+ // TEMP FOR DEBUG - REMOVE
486
+ rc = flash_area_read (fap , off , read_buf , BOOT_MAX_ALIGN );
487
+ BOOT_LOG_INF ("boot_write_trailer whats read AFTER writing rc=0x%x" , rc );
488
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
489
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
490
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
491
+ }
492
+ rc = aligned_flash_read_ (fap -> fa_off + off , read_buf , BOOT_MAX_ALIGN , false);
493
+ BOOT_LOG_INF ("boot_write_trailer whats read AFTER writing - RAW rc=0x%x" , rc );
494
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
495
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
496
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
497
+ }
498
+ // TEMP FOR DEBUG - REMOVE
499
+
368
500
return 0 ;
369
501
}
370
502
@@ -382,7 +514,7 @@ boot_write_image_ok(const struct flash_area *fap)
382
514
uint32_t off ;
383
515
384
516
off = boot_image_ok_off (fap );
385
- BOOT_LOG_DBG ( " writing image_ok ; fa_id=%d off=0x%lx (0x%lx)" ,
517
+ BOOT_LOG_INF ( "boot_write_image_ok writing IMAGE_OK ; fa_id=%d off=0x%lx (0x%lx)" ,
386
518
flash_area_get_id (fap ), (unsigned long )off ,
387
519
(unsigned long )(flash_area_get_off (fap ) + off ));
388
520
return boot_write_trailer_flag (fap , off , BOOT_FLAG_SET );
@@ -391,6 +523,7 @@ boot_write_image_ok(const struct flash_area *fap)
391
523
int
392
524
boot_read_image_ok (const struct flash_area * fap , uint8_t * image_ok )
393
525
{
526
+ BOOT_LOG_INF ("boot_read_image_ok" );
394
527
return boot_read_flag (fap , image_ok , boot_image_ok_off (fap ));
395
528
}
396
529
@@ -408,7 +541,7 @@ boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
408
541
409
542
BOOT_SET_SWAP_INFO (swap_info , image_num , swap_type );
410
543
off = boot_swap_info_off (fap );
411
- BOOT_LOG_DBG ( " writing swap_info ; fa_id=%d off=0x%lx (0x%lx), swap_type=0x%x"
544
+ BOOT_LOG_INF ( "boot_write_swap_info writing SWAP_INFO ; fa_id=%d off=0x%lx (0x%lx), swap_type=0x%x"
412
545
" image_num=0x%x" ,
413
546
flash_area_get_id (fap ), (unsigned long )off ,
414
547
(unsigned long )(flash_area_get_off (fap ) + off ),
@@ -492,7 +625,7 @@ boot_write_copy_done(const struct flash_area *fap)
492
625
uint32_t off ;
493
626
494
627
off = boot_copy_done_off (fap );
495
- BOOT_LOG_DBG ( " writing copy_done ; fa_id=%d off=0x%lx (0x%lx)" ,
628
+ BOOT_LOG_INF ( "boot_write_copy_done writing COPY_DONE ; fa_id=%d off=0x%lx (0x%lx)" ,
496
629
flash_area_get_id (fap ), (unsigned long )off ,
497
630
(unsigned long )(flash_area_get_off (fap ) + off ));
498
631
return boot_write_trailer_flag (fap , off , BOOT_FLAG_SET );
@@ -534,11 +667,17 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
534
667
return rc ;
535
668
}
536
669
670
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx slot_state.image_ok=0x%lx slot_state.swap_type=0x%lx" ,
671
+ flash_area_get_id (fa ), slot_state .magic , slot_state .image_ok , slot_state .swap_type );
672
+
537
673
switch (slot_state .magic ) {
538
674
case BOOT_MAGIC_GOOD :
539
675
/* If non-active then swap already scheduled, else confirm needed.*/
540
-
676
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_GOOD)" ,
677
+ flash_area_get_id (fa ), slot_state .magic );
541
678
if (active && slot_state .image_ok == BOOT_FLAG_UNSET ) {
679
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx slot_state.image_ok=0x%lx (BOOT_FLAG_UNSET)" ,
680
+ flash_area_get_id (fa ), slot_state .magic , slot_state .image_ok );
542
681
/* Intentionally do not check copy_done flag to be able to
543
682
* confirm a padded image which has been programmed using
544
683
* a programming interface.
@@ -549,6 +688,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
549
688
break ;
550
689
551
690
case BOOT_MAGIC_UNSET :
691
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_UNSET)" ,
692
+ flash_area_get_id (fa ), slot_state .magic );
552
693
if (!active ) {
553
694
rc = boot_write_magic (fa );
554
695
@@ -570,6 +711,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
570
711
break ;
571
712
572
713
case BOOT_MAGIC_BAD :
714
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_BAD)" ,
715
+ flash_area_get_id (fa ), slot_state .magic );
573
716
if (active ) {
574
717
rc = BOOT_EBADVECT ;
575
718
} else {
@@ -582,6 +725,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
582
725
break ;
583
726
584
727
default :
728
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (SHOULD NEVER HAPPEN)" ,
729
+ flash_area_get_id (fa ), slot_state .magic );
585
730
/* Something is not OK, this should never happen */
586
731
assert (0 );
587
732
rc = BOOT_EBADIMAGE ;
@@ -761,6 +906,10 @@ boot_image_load_header(const struct flash_area *fa_p,
761
906
struct image_header * hdr )
762
907
{
763
908
uint32_t size ;
909
+
910
+ BOOT_LOG_INF ("boot_image_load_header; fa_id=%d addr=0x%lx" ,
911
+ flash_area_get_id (fa_p ), (unsigned long )(flash_area_get_off (fa_p )));
912
+
764
913
int rc = flash_area_read (fa_p , 0 , hdr , sizeof * hdr );
765
914
766
915
if (rc != 0 ) {
@@ -786,5 +935,8 @@ boot_image_load_header(const struct flash_area *fa_p,
786
935
return BOOT_EBADIMAGE ;
787
936
}
788
937
938
+ BOOT_LOG_INF ("boot_image_load_header; ih_magic=0%lx ih_flags=0x%lx ih_hdr_size=0x%lx ih_img_size=0x%lx" ,
939
+ hdr -> ih_magic , hdr -> ih_flags , hdr -> ih_hdr_size , hdr -> ih_img_size );
940
+
789
941
return 0 ;
790
942
}
0 commit comments