drivers/flash/flash_simulator: integrate WP service into write/erase
Flash write protection services were integrated into erase and write procedures. This is step required for fixing following issue: Multi-threading flash access is not supported by flash_write_protection_set(). flash_write_protection_set() will be deprecated As CONFIG_FLASH_SIMULATOR_ERASE_PROTECT become a dead option. this commit removes it as well. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
7f01abadde
commit
7c01b18de7
|
@ -28,12 +28,6 @@ config FLASH_SIMULATOR_DOUBLE_WRITES
|
|||
If selected, writing to a non-erased program unit will succeed, otherwise, it will return an error.
|
||||
Keep in mind that write operations can only pull bits to zero, regardless.
|
||||
|
||||
config FLASH_SIMULATOR_ERASE_PROTECT
|
||||
bool "Enable erase protection on write protection"
|
||||
default y
|
||||
help
|
||||
If selected, turning on write protection will also prevent erasing.
|
||||
|
||||
config FLASH_SIMULATOR_SIMULATE_TIMING
|
||||
bool "Enable hardware timing simulation"
|
||||
|
||||
|
|
|
@ -136,8 +136,6 @@ static const char default_flash_file_path[] = "flash.bin";
|
|||
static uint8_t mock_flash[FLASH_SIMULATOR_FLASH_SIZE];
|
||||
#endif /* CONFIG_ARCH_POSIX */
|
||||
|
||||
static bool write_protection;
|
||||
|
||||
static const struct flash_driver_api flash_sim_api;
|
||||
|
||||
static const struct flash_parameters flash_sim_parameters = {
|
||||
|
@ -161,16 +159,11 @@ static int flash_range_is_valid(const struct device *dev, off_t offset,
|
|||
static int flash_wp_set(const struct device *dev, bool enable)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
write_protection = enable;
|
||||
ARG_UNUSED(enable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool flash_wp_is_set(void)
|
||||
{
|
||||
return write_protection;
|
||||
}
|
||||
|
||||
static int flash_sim_read(const struct device *dev, const off_t offset,
|
||||
void *data,
|
||||
const size_t len)
|
||||
|
@ -217,10 +210,6 @@ static int flash_sim_write(const struct device *dev, const off_t offset,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (flash_wp_is_set()) {
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
STATS_INC(flash_sim_stats, flash_write_calls);
|
||||
|
||||
/* check if any unit has been already programmed */
|
||||
|
@ -296,11 +285,6 @@ static int flash_sim_erase(const struct device *dev, const off_t offset,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FLASH_SIMULATOR_ERASE_PROTECT
|
||||
if (flash_wp_is_set()) {
|
||||
return -EACCES;
|
||||
}
|
||||
#endif
|
||||
/* erase operation must be aligned to the erase unit boundary */
|
||||
if ((offset % FLASH_SIMULATOR_ERASE_UNIT) ||
|
||||
(len % FLASH_SIMULATOR_ERASE_UNIT)) {
|
||||
|
|
|
@ -2,5 +2,4 @@ CONFIG_ZTEST=y
|
|||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_SIMULATOR=y
|
||||
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=n
|
||||
CONFIG_FLASH_SIMULATOR_ERASE_PROTECT=y
|
||||
CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=n
|
||||
|
|
Loading…
Reference in a new issue