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

bootutil: Add support for devices without erase #2114

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,36 @@ endif # BOOT_DECOMPRESSION_SUPPORT

endmenu

config MCUBOOT_STORAGE_NO_UNNEEDED_ERASE
bool "Erase is performed only on devices that require it by design"
depends on FLASH_HAS_NO_EXPLICIT_ERASE
help
Not all devices require erase before write and, depending on driver,
may emulate erase by write, as a way to scramble data rather then
by hardware requirement. This unfortunately means that code that
does erase before write, when not needed, will write device twice
which not only reduces device life time but also doubles time
of any write operation (one write for erase and one write for actual
write).
When this option is enabled, MCUboot will check for type of device
and will avoid erase where not needed.

config MCUBOOT_STORAGE_MINIMAL_SCRAMBLE
bool "Do minimal required work to remove data"
help
In some cases MCUboot has to remove data, which usually means make
it non-viable for MCUboot rather then completely destroyed.
For example when MCUboot does not want to bother with broken image
in some slot it will remove it.
The same can be achieved with just removal of header, leaving the
rest of image untouched, as without header MCUboot will not be able
to recognize image in slot as bootable.
Comment on lines +856 to +858
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include footer

When this option is enabled, MCUboot will not attempt to erase
entire slot or image, instead it will just remove enough of
data from slot to not recognize it as image anymore.
Depending on type of device this may be done by erase of minimal
number of pages or overwrite of part of image.

config MCUBOOT_DEVICE_SETTINGS
# Hidden selector for device-specific settings
bool
Expand Down
18 changes: 18 additions & 0 deletions boot/zephyr/include/flash_map_backend/flash_map_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ static inline uint32_t flash_sector_get_size(const struct flash_sector *fs)
int flash_area_get_sector(const struct flash_area *fa, off_t off,
struct flash_sector *fs);


#if defined(CONFIG_MCUBOOT)
static inline bool flash_area_erase_required(const struct flash_area *fa)
{
#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
const struct flash_parameters *fp = flash_get_parameters(flash_area_get_device(fa));

return flash_params_get_erase_cap(flash_get_parameters(flash_area_get_device(fa))) & FLASH_ERASE_C_EXPLICIT;
#else
#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
return true;
#else
return false;
#endif
#endif
}
#endif

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 19 additions & 0 deletions boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@
#define MCUBOOT_ERASE_PROGRESSIVELY
#endif

/*
* Devices that do not require erase should not call the function to
* avoid emulation of erase by additional write.
* The emulation is also taking time which doubles required write time
* for such devices.
*/
#ifdef CONFIG_MCUBOOT_STORAGE_NO_UNNEEDED_ERASE
#define MCUBOOT_DEV_WITHOUT_ERASE_THEN_NO_ERASE
#endif

/*
* MCUboot often calls erase on device just to remove data or make application
* image not recognizable. In such instances it may be faster to just remove
* portion of data to make image unrecognizable.
*/
#ifdef CONFIG_MCUBOOT_STORAGE_MINIMAL_SCRAMBLE
#define MCUBOOT_MINIMAL_SCRAMBLE
#endif

/*
* Enabling this option uses newer flash map APIs. This saves RAM and
* avoids deprecated API usage.
Expand Down