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 );
@@ -329,7 +369,27 @@ boot_write_magic(const struct flash_area *fap)
329
369
(unsigned long )(flash_area_get_off (fap ) + off ));
330
370
331
371
#ifdef MCUBOOT_FLASH_HAS_HW_ENCRYPTION
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 );
332
375
rc = flash_area_erase (fap , pad_off , BOOT_MAGIC_ALIGN_SIZE );
376
+
377
+ // TEMP FOR DEBUG - REMOVE
378
+ uint8_t read_buf [BOOT_MAGIC_ALIGN_SIZE ];
379
+ rc = flash_area_read (fap , pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE );
380
+ BOOT_LOG_INF ("boot_write_magic whats read BEFORE writing rc=0x%x" , rc );
381
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
382
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
383
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
384
+ }
385
+ rc = aligned_flash_read_ (fap -> fa_off + pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE , false);
386
+ BOOT_LOG_INF ("boot_write_magic whats read BEFORE writing - RAW rc=0x%x" , rc );
387
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
388
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
389
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
390
+ }
391
+ // TEMP FOR DEBUG - REMOVE
392
+
333
393
#endif
334
394
335
395
rc = flash_area_write (fap , pad_off , & magic [0 ], BOOT_MAGIC_ALIGN_SIZE );
@@ -338,6 +398,21 @@ boot_write_magic(const struct flash_area *fap)
338
398
return BOOT_EFLASH ;
339
399
}
340
400
401
+ // TEMP FOR DEBUG - REMOVE
402
+ rc = flash_area_read (fap , pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE );
403
+ BOOT_LOG_INF ("boot_write_magic whats read AFTER writing rc=0x%x" , rc );
404
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
405
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
406
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
407
+ }
408
+ rc = aligned_flash_read_ (fap -> fa_off + pad_off , read_buf , BOOT_MAGIC_ALIGN_SIZE , false);
409
+ BOOT_LOG_INF ("boot_write_magic whats read AFTER writing - RAW rc=0x%x" , rc );
410
+ for (uint8_t i = 0 ; i < BOOT_MAGIC_ALIGN_SIZE ; i = i + 4 ) {
411
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
412
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
413
+ }
414
+ // TEMP FOR DEBUG - REMOVE
415
+
341
416
return 0 ;
342
417
}
343
418
@@ -366,14 +441,70 @@ boot_write_trailer(const struct flash_area *fap, uint32_t off,
366
441
memset (& buf [inlen ], erased_val , align - inlen );
367
442
368
443
#ifdef MCUBOOT_FLASH_HAS_HW_ENCRYPTION
444
+
445
+ BOOT_LOG_INF ("boot_write_trailer writing TRAILER; fa_id=%d off=0x%lx (0x%lx) size=0x%x" ,
446
+ flash_area_get_id (fap ), (unsigned long )off ,
447
+ (unsigned long )(flash_area_get_off (fap ) + off ), align );
369
448
rc = flash_area_erase (fap , off , align );
449
+
450
+ // TEMP FOR DEBUG - REMOVE
451
+ uint8_t read_buf [BOOT_MAX_ALIGN ];
452
+
453
+ if ((unsigned long )(flash_area_get_off (fap ) + off ) == 0x16FFA0 ) {
454
+ BOOT_LOG_INF ("boot_write_trailer 0x16FFA0 CASE" );
455
+
456
+ rc = flash_area_read (fap , off + BOOT_MAX_ALIGN , read_buf , BOOT_MAX_ALIGN );
457
+ BOOT_LOG_INF ("boot_write_trailer whats read in addr 0x%lx AFTER ERASE rc=0x%x" ,
458
+ (unsigned long )(flash_area_get_off (fap ) + off + BOOT_MAX_ALIGN ), rc );
459
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
460
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
461
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
462
+ }
463
+ rc = aligned_flash_read_ (fap -> fa_off + off + BOOT_MAX_ALIGN , read_buf , BOOT_MAX_ALIGN , false);
464
+ BOOT_LOG_INF ("boot_write_trailer whats read in addr 0x%lx AFTER ERASE - RAW rc=0x%x" ,
465
+ (unsigned long )(flash_area_get_off (fap ) + off + BOOT_MAX_ALIGN ), rc );
466
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
467
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
468
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
469
+ }
470
+ }
471
+
472
+ rc = flash_area_read (fap , off , read_buf , BOOT_MAX_ALIGN );
473
+ BOOT_LOG_INF ("boot_write_trailer whats read BEFORE writing 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
+ rc = aligned_flash_read_ (fap -> fa_off + off , read_buf , BOOT_MAX_ALIGN , false);
479
+ BOOT_LOG_INF ("boot_write_trailer whats read BEFORE writing - RAW rc=0x%x" , rc );
480
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
481
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
482
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
483
+ }
484
+ // TEMP FOR DEBUG - REMOVE
485
+
370
486
#endif
371
487
372
488
rc = flash_area_write (fap , off , buf , align );
373
489
if (rc != 0 ) {
374
490
return BOOT_EFLASH ;
375
491
}
376
492
493
+ // TEMP FOR DEBUG - REMOVE
494
+ rc = flash_area_read (fap , off , read_buf , BOOT_MAX_ALIGN );
495
+ BOOT_LOG_INF ("boot_write_trailer whats read AFTER writing rc=0x%x" , rc );
496
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
497
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
498
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
499
+ }
500
+ rc = aligned_flash_read_ (fap -> fa_off + off , read_buf , BOOT_MAX_ALIGN , false);
501
+ BOOT_LOG_INF ("boot_write_trailer whats read AFTER writing - RAW rc=0x%x" , rc );
502
+ for (uint8_t i = 0 ; i < BOOT_MAX_ALIGN ; i = i + 4 ) {
503
+ BOOT_LOG_INF ("0x%x 0x%x 0x%x 0x%x" ,
504
+ read_buf [i ], read_buf [i + 1 ], read_buf [i + 2 ], read_buf [i + 3 ]);
505
+ }
506
+ // TEMP FOR DEBUG - REMOVE
507
+
377
508
return 0 ;
378
509
}
379
510
@@ -391,7 +522,7 @@ boot_write_image_ok(const struct flash_area *fap)
391
522
uint32_t off ;
392
523
393
524
off = boot_image_ok_off (fap );
394
- BOOT_LOG_DBG ( " writing image_ok ; fa_id=%d off=0x%lx (0x%lx)" ,
525
+ BOOT_LOG_INF ( "boot_write_image_ok writing IMAGE_OK ; fa_id=%d off=0x%lx (0x%lx)" ,
395
526
flash_area_get_id (fap ), (unsigned long )off ,
396
527
(unsigned long )(flash_area_get_off (fap ) + off ));
397
528
return boot_write_trailer_flag (fap , off , BOOT_FLAG_SET );
@@ -400,6 +531,7 @@ boot_write_image_ok(const struct flash_area *fap)
400
531
int
401
532
boot_read_image_ok (const struct flash_area * fap , uint8_t * image_ok )
402
533
{
534
+ BOOT_LOG_INF ("boot_read_image_ok" );
403
535
return boot_read_flag (fap , image_ok , boot_image_ok_off (fap ));
404
536
}
405
537
@@ -417,7 +549,7 @@ boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
417
549
418
550
BOOT_SET_SWAP_INFO (swap_info , image_num , swap_type );
419
551
off = boot_swap_info_off (fap );
420
- BOOT_LOG_DBG ( " writing swap_info ; fa_id=%d off=0x%lx (0x%lx), swap_type=0x%x"
552
+ BOOT_LOG_INF ( "boot_write_swap_info writing SWAP_INFO ; fa_id=%d off=0x%lx (0x%lx), swap_type=0x%x"
421
553
" image_num=0x%x" ,
422
554
flash_area_get_id (fap ), (unsigned long )off ,
423
555
(unsigned long )(flash_area_get_off (fap ) + off ),
@@ -501,7 +633,7 @@ boot_write_copy_done(const struct flash_area *fap)
501
633
uint32_t off ;
502
634
503
635
off = boot_copy_done_off (fap );
504
- BOOT_LOG_DBG ( " writing copy_done ; fa_id=%d off=0x%lx (0x%lx)" ,
636
+ BOOT_LOG_INF ( "boot_write_copy_done writing COPY_DONE ; fa_id=%d off=0x%lx (0x%lx)" ,
505
637
flash_area_get_id (fap ), (unsigned long )off ,
506
638
(unsigned long )(flash_area_get_off (fap ) + off ));
507
639
return boot_write_trailer_flag (fap , off , BOOT_FLAG_SET );
@@ -543,11 +675,17 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
543
675
return rc ;
544
676
}
545
677
678
+ 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" ,
679
+ flash_area_get_id (fa ), slot_state .magic , slot_state .image_ok , slot_state .swap_type );
680
+
546
681
switch (slot_state .magic ) {
547
682
case BOOT_MAGIC_GOOD :
548
683
/* If non-active then swap already scheduled, else confirm needed.*/
549
-
684
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_GOOD)" ,
685
+ flash_area_get_id (fa ), slot_state .magic );
550
686
if (active && slot_state .image_ok == BOOT_FLAG_UNSET ) {
687
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx slot_state.image_ok=0x%lx (BOOT_FLAG_UNSET)" ,
688
+ flash_area_get_id (fa ), slot_state .magic , slot_state .image_ok );
551
689
/* Intentionally do not check copy_done flag to be able to
552
690
* confirm a padded image which has been programmed using
553
691
* a programming interface.
@@ -558,6 +696,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
558
696
break ;
559
697
560
698
case BOOT_MAGIC_UNSET :
699
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_UNSET)" ,
700
+ flash_area_get_id (fa ), slot_state .magic );
561
701
if (!active ) {
562
702
rc = boot_write_magic (fa );
563
703
@@ -579,6 +719,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
579
719
break ;
580
720
581
721
case BOOT_MAGIC_BAD :
722
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (BOOT_MAGIC_BAD)" ,
723
+ flash_area_get_id (fa ), slot_state .magic );
582
724
if (active ) {
583
725
rc = BOOT_EBADVECT ;
584
726
} else {
@@ -591,6 +733,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
591
733
break ;
592
734
593
735
default :
736
+ BOOT_LOG_INF ("boot_set_next; fa_id=%d slot_state.magic=0x%lx (SHOULD NEVER HAPPEN)" ,
737
+ flash_area_get_id (fa ), slot_state .magic );
594
738
/* Something is not OK, this should never happen */
595
739
assert (0 );
596
740
rc = BOOT_EBADIMAGE ;
@@ -770,6 +914,10 @@ boot_image_load_header(const struct flash_area *fa_p,
770
914
struct image_header * hdr )
771
915
{
772
916
uint32_t size ;
917
+
918
+ BOOT_LOG_INF ("boot_image_load_header; fa_id=%d addr=0x%lx" ,
919
+ flash_area_get_id (fa_p ), (unsigned long )(flash_area_get_off (fa_p )));
920
+
773
921
int rc = flash_area_read (fa_p , 0 , hdr , sizeof * hdr );
774
922
775
923
if (rc != 0 ) {
@@ -795,5 +943,8 @@ boot_image_load_header(const struct flash_area *fa_p,
795
943
return BOOT_EBADIMAGE ;
796
944
}
797
945
946
+ 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" ,
947
+ hdr -> ih_magic , hdr -> ih_flags , hdr -> ih_hdr_size , hdr -> ih_img_size );
948
+
798
949
return 0 ;
799
950
}
0 commit comments