Skip to content

Commit fb22bdf

Browse files
committed
DEBUG: add debug logs - THIS COMMIT WILL BE DELETED
Signed-off-by: Almir Okato <[email protected]>
1 parent dafd878 commit fb22bdf

File tree

3 files changed

+278
-4
lines changed

3 files changed

+278
-4
lines changed

boot/bootutil/src/bootutil_public.c

Lines changed: 155 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
#include "bootutil_priv.h"
5252
#include "bootutil_misc.h"
5353

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+
5459
#ifdef CONFIG_MCUBOOT
5560
BOOT_LOG_MODULE_DECLARE(mcuboot);
5661
#else
@@ -223,6 +228,13 @@ boot_read_flag(const struct flash_area *fap, uint8_t *flag, uint32_t off)
223228
if (rc < 0) {
224229
return BOOT_EFLASH;
225230
}
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+
226238
if (bootutil_buffer_is_erased(fap, flag, sizeof *flag)) {
227239
*flag = BOOT_FLAG_UNSET;
228240
} else {
@@ -235,6 +247,8 @@ boot_read_flag(const struct flash_area *fap, uint8_t *flag, uint32_t off)
235247
static inline int
236248
boot_read_copy_done(const struct flash_area *fap, uint8_t *copy_done)
237249
{
250+
BOOT_LOG_INF("boot_read_copy_done");
251+
238252
return boot_read_flag(fap, copy_done, boot_copy_done_off(fap));
239253
}
240254

@@ -248,23 +262,49 @@ boot_read_swap_state(const struct flash_area *fap,
248262
uint8_t swap_info;
249263
int rc;
250264

265+
251266
off = boot_magic_off(fap);
267+
BOOT_LOG_INF("boot_read_swap_state MAGIC addr 0x%lx", fap->fa_off+off);
252268
rc = flash_area_read(fap, off, magic, BOOT_MAGIC_SZ);
253269
if (rc < 0) {
254270
return BOOT_EFLASH;
255271
}
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+
256288
if (bootutil_buffer_is_erased(fap, magic, BOOT_MAGIC_SZ)) {
257289
state->magic = BOOT_MAGIC_UNSET;
258290
} else {
259291
state->magic = boot_magic_decode(magic);
260292
}
261293

262294
off = boot_swap_info_off(fap);
295+
BOOT_LOG_INF("boot_read_swap_state SWAP_INFO addr 0x%lx", fap->fa_off+off);
263296
rc = flash_area_read(fap, off, &swap_info, sizeof swap_info);
264297
if (rc < 0) {
265298
return BOOT_EFLASH;
266299
}
267300

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+
268308
/* Extract the swap type and image number */
269309
state->swap_type = BOOT_GET_SWAP_TYPE(swap_info);
270310
state->image_num = BOOT_GET_IMAGE_NUM(swap_info);
@@ -329,7 +369,27 @@ boot_write_magic(const struct flash_area *fap)
329369
(unsigned long)(flash_area_get_off(fap) + off));
330370

331371
#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);
332375
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+
333393
#endif
334394

335395
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)
338398
return BOOT_EFLASH;
339399
}
340400

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+
341416
return 0;
342417
}
343418

@@ -366,14 +441,70 @@ boot_write_trailer(const struct flash_area *fap, uint32_t off,
366441
memset(&buf[inlen], erased_val, align - inlen);
367442

368443
#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);
369448
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+
370486
#endif
371487

372488
rc = flash_area_write(fap, off, buf, align);
373489
if (rc != 0) {
374490
return BOOT_EFLASH;
375491
}
376492

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+
377508
return 0;
378509
}
379510

@@ -391,7 +522,7 @@ boot_write_image_ok(const struct flash_area *fap)
391522
uint32_t off;
392523

393524
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)",
395526
flash_area_get_id(fap), (unsigned long)off,
396527
(unsigned long)(flash_area_get_off(fap) + off));
397528
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
@@ -400,6 +531,7 @@ boot_write_image_ok(const struct flash_area *fap)
400531
int
401532
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
402533
{
534+
BOOT_LOG_INF("boot_read_image_ok");
403535
return boot_read_flag(fap, image_ok, boot_image_ok_off(fap));
404536
}
405537

@@ -417,7 +549,7 @@ boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
417549

418550
BOOT_SET_SWAP_INFO(swap_info, image_num, swap_type);
419551
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"
421553
" image_num=0x%x",
422554
flash_area_get_id(fap), (unsigned long)off,
423555
(unsigned long)(flash_area_get_off(fap) + off),
@@ -501,7 +633,7 @@ boot_write_copy_done(const struct flash_area *fap)
501633
uint32_t off;
502634

503635
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)",
505637
flash_area_get_id(fap), (unsigned long)off,
506638
(unsigned long)(flash_area_get_off(fap) + off));
507639
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)
543675
return rc;
544676
}
545677

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+
546681
switch (slot_state.magic) {
547682
case BOOT_MAGIC_GOOD:
548683
/* 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);
550686
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);
551689
/* Intentionally do not check copy_done flag to be able to
552690
* confirm a padded image which has been programmed using
553691
* a programming interface.
@@ -558,6 +696,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
558696
break;
559697

560698
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);
561701
if (!active) {
562702
rc = boot_write_magic(fa);
563703

@@ -579,6 +719,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
579719
break;
580720

581721
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);
582724
if (active) {
583725
rc = BOOT_EBADVECT;
584726
} else {
@@ -591,6 +733,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
591733
break;
592734

593735
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);
594738
/* Something is not OK, this should never happen */
595739
assert(0);
596740
rc = BOOT_EBADIMAGE;
@@ -770,6 +914,10 @@ boot_image_load_header(const struct flash_area *fa_p,
770914
struct image_header *hdr)
771915
{
772916
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+
773921
int rc = flash_area_read(fa_p, 0, hdr, sizeof *hdr);
774922

775923
if (rc != 0) {
@@ -795,5 +943,8 @@ boot_image_load_header(const struct flash_area *fa_p,
795943
return BOOT_EBADIMAGE;
796944
}
797945

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+
798949
return 0;
799950
}

boot/bootutil/src/loader.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#include "bootutil/boot_hooks.h"
5050
#include "bootutil/mcuboot_status.h"
5151

52+
// TEMP FOR DEBUG - REMOVE
53+
#include "bootloader_flash_priv.h"
54+
5255
#ifdef MCUBOOT_ENC_IMAGES
5356
#include "bootutil/enc_key.h"
5457
#endif
@@ -758,13 +761,48 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
758761
(unsigned long)flash_area_get_off(fap) + off);
759762

760763
#ifdef MCUBOOT_FLASH_HAS_HW_ENCRYPTION
764+
BOOT_LOG_INF("loader.c writing SWAP STATUS; fa_id=%d off=0x%lx (0x%lx)",
765+
flash_area_get_id(fap), (unsigned long)off,
766+
(unsigned long)(flash_area_get_off(fap) + off));
761767
rc = flash_area_erase(fap, off, align);
768+
769+
// TEMP FOR DEBUG - REMOVE
770+
uint8_t read_buf[BOOT_MAX_ALIGN];
771+
rc = flash_area_read(fap, off, read_buf, BOOT_MAX_ALIGN);
772+
BOOT_LOG_INF("whats read BEFORE writing rc=0x%x", rc);
773+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
774+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
775+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
776+
}
777+
rc = bootloader_flash_read(fap->fa_off + off, read_buf, BOOT_MAX_ALIGN, false);
778+
BOOT_LOG_INF("whats read BEFORE writing - RAW rc=0x%x", rc);
779+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
780+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
781+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
782+
}
783+
// TEMP FOR DEBUG - REMOVE
784+
762785
#endif
763786
rc = flash_area_write(fap, off, buf, align);
764787
if (rc != 0) {
765788
rc = BOOT_EFLASH;
766789
}
767790

791+
// TEMP FOR DEBUG - REMOVE
792+
rc = flash_area_read(fap, off, read_buf, BOOT_MAX_ALIGN);
793+
BOOT_LOG_INF("whats read AFTER writing rc=0x%x", rc);
794+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
795+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
796+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
797+
}
798+
rc = bootloader_flash_read(fap->fa_off + off, read_buf, BOOT_MAX_ALIGN, false);
799+
BOOT_LOG_INF("whats read AFTER writing - RAW rc=0x%x", rc);
800+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
801+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
802+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
803+
}
804+
// TEMP FOR DEBUG - REMOVE
805+
768806
flash_area_close(fap);
769807

770808
return rc;

0 commit comments

Comments
 (0)