Skip to content

Commit 64ec4e9

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

File tree

3 files changed

+279
-4
lines changed

3 files changed

+279
-4
lines changed

boot/bootutil/src/bootutil_public.c

Lines changed: 156 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);
@@ -327,12 +367,48 @@ boot_write_magic(const struct flash_area *fap)
327367
BOOT_LOG_DBG("writing magic; fa_id=%d off=0x%lx (0x%lx)",
328368
flash_area_get_id(fap), (unsigned long)off,
329369
(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+
330391
rc = flash_area_write(fap, pad_off, &magic[0], BOOT_MAGIC_ALIGN_SIZE);
331392

332393
if (rc != 0) {
333394
return BOOT_EFLASH;
334395
}
335396

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+
336412
return 0;
337413
}
338414

@@ -360,11 +436,67 @@ boot_write_trailer(const struct flash_area *fap, uint32_t off,
360436
memcpy(buf, inbuf, inlen);
361437
memset(&buf[inlen], erased_val, align - inlen);
362438

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+
363480
rc = flash_area_write(fap, off, buf, align);
364481
if (rc != 0) {
365482
return BOOT_EFLASH;
366483
}
367484

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+
368500
return 0;
369501
}
370502

@@ -382,7 +514,7 @@ boot_write_image_ok(const struct flash_area *fap)
382514
uint32_t off;
383515

384516
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)",
386518
flash_area_get_id(fap), (unsigned long)off,
387519
(unsigned long)(flash_area_get_off(fap) + off));
388520
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
@@ -391,6 +523,7 @@ boot_write_image_ok(const struct flash_area *fap)
391523
int
392524
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
393525
{
526+
BOOT_LOG_INF("boot_read_image_ok");
394527
return boot_read_flag(fap, image_ok, boot_image_ok_off(fap));
395528
}
396529

@@ -408,7 +541,7 @@ boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
408541

409542
BOOT_SET_SWAP_INFO(swap_info, image_num, swap_type);
410543
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"
412545
" image_num=0x%x",
413546
flash_area_get_id(fap), (unsigned long)off,
414547
(unsigned long)(flash_area_get_off(fap) + off),
@@ -492,7 +625,7 @@ boot_write_copy_done(const struct flash_area *fap)
492625
uint32_t off;
493626

494627
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)",
496629
flash_area_get_id(fap), (unsigned long)off,
497630
(unsigned long)(flash_area_get_off(fap) + off));
498631
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)
534667
return rc;
535668
}
536669

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+
537673
switch (slot_state.magic) {
538674
case BOOT_MAGIC_GOOD:
539675
/* 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);
541678
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);
542681
/* Intentionally do not check copy_done flag to be able to
543682
* confirm a padded image which has been programmed using
544683
* a programming interface.
@@ -549,6 +688,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
549688
break;
550689

551690
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);
552693
if (!active) {
553694
rc = boot_write_magic(fa);
554695

@@ -570,6 +711,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
570711
break;
571712

572713
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);
573716
if (active) {
574717
rc = BOOT_EBADVECT;
575718
} else {
@@ -582,6 +725,8 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
582725
break;
583726

584727
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);
585730
/* Something is not OK, this should never happen */
586731
assert(0);
587732
rc = BOOT_EBADIMAGE;
@@ -761,6 +906,10 @@ boot_image_load_header(const struct flash_area *fa_p,
761906
struct image_header *hdr)
762907
{
763908
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+
764913
int rc = flash_area_read(fa_p, 0, hdr, sizeof *hdr);
765914

766915
if (rc != 0) {
@@ -786,5 +935,8 @@ boot_image_load_header(const struct flash_area *fa_p,
786935
return BOOT_EBADIMAGE;
787936
}
788937

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+
789941
return 0;
790942
}

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
@@ -757,11 +760,46 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
757760
flash_area_get_id(fap), (unsigned long)off,
758761
(unsigned long)flash_area_get_off(fap) + off);
759762

763+
// TEMP FOR DEBUG - REMOVE
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));
767+
768+
uint8_t read_buf[BOOT_MAX_ALIGN];
769+
rc = flash_area_read(fap, off, read_buf, BOOT_MAX_ALIGN);
770+
BOOT_LOG_INF("whats read BEFORE writing rc=0x%x", rc);
771+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
772+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
773+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
774+
}
775+
rc = bootloader_flash_read(fap->fa_off + off, read_buf, BOOT_MAX_ALIGN, false);
776+
BOOT_LOG_INF("whats read BEFORE writing - RAW rc=0x%x", rc);
777+
for (uint8_t i=0; i<BOOT_MAX_ALIGN; i=i+4) {
778+
BOOT_LOG_INF("0x%x 0x%x 0x%x 0x%x",
779+
read_buf[i], read_buf[i+1], read_buf[i+2], read_buf[i+3]);
780+
}
781+
// TEMP FOR DEBUG - REMOVE
782+
760783
rc = flash_area_write(fap, off, buf, align);
761784
if (rc != 0) {
762785
rc = BOOT_EFLASH;
763786
}
764787

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

767805
return rc;

0 commit comments

Comments
 (0)