Skip to content

Commit 2346d69

Browse files
de-nordicnordicjm
authored andcommitted
zephyr: Add support for devices without erase and reduced erases
Add Kconfig options: - CONFIG_MCUBOOT_STORAGE_WITHOUT_ERASE that enables MCUboot configuration MCUBOOT_SUPPORT_DEV_WITHOUT_ERASE - CONFIG_MCUBOOT_STORAGE_WITH_ERASE that enables MCUboot configuration MCUBOOT_SUPPORT_DEV_WITH_ERASE - CONFIG_MCUBOOT_STORAGE_MINIMAL_SCRAMBLE that enables MCUboot configuration MCUBOOT_MINIMAL_SCRAMBLE Adds implementation of flash_area_erase_required, which is required when MCUBOOT_STORAGE_DEV_WITHOUT_ERASE is enabled. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 2a2b562 commit 2346d69

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

boot/zephyr/Kconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,44 @@ endmenu
10291029

10301030
endmenu
10311031

1032+
config MCUBOOT_STORAGE_WITHOUT_ERASE
1033+
bool "Support for devices without erase"
1034+
depends on FLASH_HAS_NO_EXPLICIT_ERASE
1035+
default y
1036+
help
1037+
Not all devices require erase before write and, depending on driver,
1038+
may emulate erase by write, as a way to scramble data rather then
1039+
by hardware requirement. This unfortunately means that code that
1040+
does erase before write, when not needed, will write device twice
1041+
which not only reduces device life time but also doubles time
1042+
of any write operation (one write for erase and one write for actual
1043+
write).
1044+
When this option is enabled, MCUboot will check for type of device
1045+
and will avoid erase where not needed.
1046+
1047+
config MCUBOOT_STORAGE_WITH_ERASE
1048+
bool "Support for devices with erase"
1049+
depends on FLASH_HAS_EXPLICIT_ERASE
1050+
default y
1051+
help
1052+
Support for devices with erase
1053+
1054+
config MCUBOOT_STORAGE_MINIMAL_SCRAMBLE
1055+
bool "Do minimal required work to remove data (EXPERIMENTAL)"
1056+
help
1057+
In some cases MCUboot has to remove data, which usually means make
1058+
it non-viable for MCUboot rather then completely destroyed.
1059+
For example when MCUboot does not want to bother with broken image,
1060+
in some slot, it will remove it.
1061+
The same can be achieved with just removal of header and footer,
1062+
leaving the rest of image untouched, as without header MCUboot will
1063+
not be able to recognize image in slot as bootable.
1064+
When this option is enabled, MCUboot will not attempt to erase
1065+
entire slot or image, instead it will just remove enough of
1066+
data from slot to not recognize it as image anymore.
1067+
Depending on type of device this may be done by erase of minimal
1068+
number of pages or overwrite of part of image.
1069+
10321070
config MCUBOOT_DEVICE_SETTINGS
10331071
# Hidden selector for device-specific settings
10341072
bool

boot/zephyr/include/flash_map_backend/flash_map_backend.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ static inline uint32_t flash_sector_get_size(const struct flash_sector *fs)
106106
int flash_area_get_sector(const struct flash_area *fa, off_t off,
107107
struct flash_sector *fs);
108108

109+
110+
#if defined(CONFIG_MCUBOOT)
111+
static inline bool flash_area_erase_required(const struct flash_area *fa)
112+
{
113+
#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
114+
const struct flash_parameters *fp = flash_get_parameters(flash_area_get_device(fa));
115+
116+
return flash_params_get_erase_cap(flash_get_parameters(flash_area_get_device(fa))) &
117+
FLASH_ERASE_C_EXPLICIT;
118+
#elif defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
119+
return true;
120+
#else
121+
return false;
122+
#endif
123+
}
124+
#endif
125+
109126
#ifdef __cplusplus
110127
}
111128
#endif

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,29 @@
307307
#define MCUBOOT_ERASE_PROGRESSIVELY
308308
#endif
309309

310+
/*
311+
* Devices that do not require erase prior to write or do not support
312+
* erase should avoid emulation of erase by additional write.
313+
* The emulation is also taking time which doubles required write time
314+
* for such devices.
315+
*/
316+
#ifdef CONFIG_MCUBOOT_STORAGE_WITHOUT_ERASE
317+
#define MCUBOOT_SUPPORT_DEV_WITHOUT_ERASE
318+
#endif
319+
320+
#ifdef CONFIG_MCUBOOT_STORAGE_WITH_ERASE
321+
#define MCUBOOT_SUPPORT_DEV_WITH_ERASE
322+
#endif
323+
324+
/*
325+
* MCUboot often calls erase on device just to remove data or make application
326+
* image not recognizable. In such instances it may be faster to just remove
327+
* portion of data to make image unrecognizable.
328+
*/
329+
#ifdef CONFIG_MCUBOOT_STORAGE_MINIMAL_SCRAMBLE
330+
#define MCUBOOT_MINIMAL_SCRAMBLE
331+
#endif
332+
310333
/*
311334
* Enabling this option uses newer flash map APIs. This saves RAM and
312335
* avoids deprecated API usage.

0 commit comments

Comments
 (0)