Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_last_sector_idx never returning #2151

Open
lefebvresam opened this issue Dec 17, 2024 · 4 comments
Open

find_last_sector_idx never returning #2151

lefebvresam opened this issue Dec 17, 2024 · 4 comments

Comments

@lefebvresam
Copy link

lefebvresam commented Dec 17, 2024

After calling boot_read_image_header(&state, 0, &hdr, &status); there is a call find_swap_count(state, swap_size); and find_last_sector_idx(state, copy_size); with copy_size = 76040.

This code part is never converging and crashes (line 481 of swap_scratch.c):

    while (1) {
        if ((primary_slot_size < copy_size) ||
            (primary_slot_size < secondary_slot_size)) {
           primary_slot_size += boot_img_sector_size(state,
                                                     BOOT_PRIMARY_SLOT,
                                                     last_sector_idx);
        }
        if ((secondary_slot_size < copy_size) ||
            (secondary_slot_size < primary_slot_size)) {
           secondary_slot_size += boot_img_sector_size(state,
                                                       BOOT_SECONDARY_SLOT,
                                                       last_sector_idx);
        }
        if (primary_slot_size >= copy_size &&
                secondary_slot_size >= copy_size &&
                primary_slot_size == secondary_slot_size) {
            break;
        }
        last_sector_idx++;
    }

It should look more logical that this must be:

        if ((primary_slot_size >= copy_size &&
                secondary_slot_size >= copy_size) ||
                primary_slot_size == secondary_slot_size) {
            break;
        }

Then I have only one iteration:

[INFO][BL]: Booting firmware image at 0x8021000
[INFO][main]: Boot confirmed
boot_read_swap_size
swap_size32 67212
flash_area_close
rc 0
copy_size 67212
primary_slot_size 0
secondary_slot_size 0

primary_slot_size 0
secondary_slot_size 66224890
primary_slot_size 35651584
break
last_sector_idx 1
swap_count 1

The piece of code should better have a check to assert before crashing/hanging.

Reproduction:

git clone [email protected]:saleconix/mcuboot.git
git clone [email protected]:saleconix/mcuboot_app.git
@nordicjm
Copy link
Collaborator

This code works fine on zephyr and mynewt so you have a problem with your deprecated and unsupported mbedos code which is outside the scope of MCUboot

@lefebvresam
Copy link
Author

lefebvresam commented Dec 18, 2024

swap_scratch.c is part of bootutil and has nothing to do with mbed.

@multiplemonomials asked to restart the mbed-ce support in pull/2152 becasue we have our community fork of mbed-os.

@nordicjm
Copy link
Collaborator

swap_scratch.c is part of bootutil and has nothing to do with mbed.

The code above adds sector sizes to a count value and that code is definitely coming from mbed, mcuboot has to query it somehow so your mbed code has an issue there (i.e. maybe it is returning 0 if you enter an infinite loop)

@multiplemonomials asked to restart the mbed-ce support in pull/2152 becasue we have our community port of mbed-os.

Interesting, if they're willing to maintain support for it and look into the issue then that's fine

@lefebvresam
Copy link
Author

I do not see any mbed references in this code:

 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright (c) 2019 JUUL Labs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants