Skip to content
Permalink
Browse files

drivers: flash: add flash_simulator driver

This commit adds a flash driver implementation that writes to RAM and
exports statistics through stats.h. It can be used to simulate flash
memory for testing purposes.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
  • Loading branch information...
kapi-no authored and carlescufi committed Apr 18, 2019
1 parent c5f6e8b commit c837d85c2bf2a84fefc76a8ec3746864479d1723
@@ -159,6 +159,7 @@
/dts/bindings/*/st,stm32* @erwango
/dts/bindings/sensor/ams,ens210.yaml @alexanderwachter
/dts/bindings/sensor/ams,iaqcore.yaml @alexanderwachter
/dts/common/sim-flash.dtsi @nvlsianpu
/ext/fs/ @nashif @wentongwu
/ext/hal/cmsis/ @MaureenHelm @galak
/ext/hal/libmetal/ @galak
@@ -7,4 +7,6 @@
#define DT_ETH_E1000_IRQ_PRIORITY DT_INTEL_E1000_FEBC0000_IRQ_0_PRIORITY
#define DT_ETH_E1000_IRQ_FLAGS DT_INTEL_E1000_FEBC0000_IRQ_0_SENSE

#define DT_SIM_FLASH_DEV_NAME DT_SIM_FLASH_SIM_FLASH_LABEL

/* End of Board Level DTS fixup file */
@@ -13,6 +13,7 @@
#endif

#include <ia32.dtsi>
#include "../../../dts/common/sim-flash.dtsi"

/ {
model = "QEMU X86";
@@ -3,6 +3,7 @@
zephyr_library()

zephyr_library_sources_ifdef(CONFIG_SPI_NOR spi_nor.c)
zephyr_library_sources_ifdef(CONFIG_FLASH_SIMULATOR flash_simulator.c)
zephyr_library_sources_ifdef(CONFIG_SPI_FLASH_W25QXXDV spi_flash_w25qxxdv.c)
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_QMSI soc_flash_qmsi.c)
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NRF soc_flash_nrf.c)
@@ -65,4 +65,6 @@ source "drivers/flash/Kconfig.sam"

source "drivers/flash/Kconfig.w25qxxdv"

source "drivers/flash/Kconfig.simulator"

endif # FLASH
@@ -0,0 +1,94 @@
# Kconfig - Flash simulator config
#
# Copyright (c) 2018 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

menuconfig FLASH_SIMULATOR
bool
prompt "Flash simulator"
default n
depends on FLASH
select STATS
select STATS_NAMES
select FLASH_HAS_PAGE_LAYOUT
select FLASH_HAS_DRIVER_ENABLED
help
Enable the flash simulator.

if FLASH_SIMULATOR

config FLASH_SIMULATOR_BASE_OFFSET
int
prompt "Base offset of the flash"
default 0
help
The base offset of the flash.
The address space of the simulated flash ranges from this value
to this value plus FLASH_SIMULATOR_ERASE_UNIT * FLASH_SIMULATOR_FLASH_SIZE.

config FLASH_SIMULATOR_ERASE_UNIT
int
prompt "Erase unit size in bytes"
default 4096
range 1 65536
help
The smallest area of flash memory that can be indipendently erased.

config FLASH_SIMULATOR_PROG_UNIT
int
prompt "Program unit size in bytes"
default 4
range 1 4096
help
The smallest area of flash memory that can be indipendently programmed.

config FLASH_SIMULATOR_FLASH_SIZE
int
prompt "Flash size in erase units"
default 4
range 1 65536
help
The size of the simulated flash area expressed in erase units.

config FLASH_SIMULATOR_DOUBLE_WRITES
bool
prompt "Allow program units to be programmed more than once"
default n
help
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
prompt "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
prompt "Enable hardware timing simulation"

if FLASH_SIMULATOR_SIMULATE_TIMING

config FLASH_SIMULATOR_MIN_READ_TIME_US
int
prompt "Minimum read time (µS)"
default 2
range 1 1000000

config FLASH_SIMULATOR_MIN_WRITE_TIME_US
int
prompt "Minimum write time (µS)"
default 100
range 1 1000000

config FLASH_SIMULATOR_MIN_ERASE_TIME_US
int
prompt "Minimum erase time (µS)"
default 2000
range 1 1000000

endif

endif # FLASH_SIMULATOR

0 comments on commit c837d85

Please sign in to comment.
You can’t perform that action at this time.