flash_simulator: add ability to use memory region
Add the ability for the flash simulator to store its contents in a memory region. This allows filesystems on the flash simulator to survive a reboot. And allows subsystems (e.g. coredump) to store their info on ram while using the (existing) flash partition backend. Add a example (for nucleo_f411re) that shows how to configure the flash simulator for hardware (cfg discussion #54166). Signed-off-by: Laczen JMS <laczenjms@gmail.com>
This commit is contained in:
parent
84fd4e671f
commit
d496a17bb6
|
@ -391,6 +391,9 @@ Drivers and Sensors
|
|||
with ``nrf_qspi_nor_xip_enable`` which apart from forcing the clock divider
|
||||
prevents the driver from deactivating the QSPI peripheral so that the XIP
|
||||
operation is actually possible.
|
||||
* flash_simulator: A memory region can now be used as the storage area for the
|
||||
flash simulator. Using the memory region allows the flash simulator to keep
|
||||
its contents over a device reboot.
|
||||
|
||||
* FPGA
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#define DT_DRV_COMPAT zephyr_sim_flash
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/linker/devicetree_regions.h>
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
@ -155,7 +157,14 @@ static bool flash_erase_at_start;
|
|||
static bool flash_rm_at_exit;
|
||||
static bool flash_in_ram;
|
||||
#else
|
||||
#if DT_NODE_HAS_PROP(DT_PARENT(SOC_NV_FLASH_NODE), memory_region)
|
||||
#define FLASH_SIMULATOR_MREGION \
|
||||
LINKER_DT_NODE_REGION_NAME( \
|
||||
DT_PHANDLE(DT_PARENT(SOC_NV_FLASH_NODE), memory_region))
|
||||
static uint8_t mock_flash[FLASH_SIMULATOR_FLASH_SIZE] Z_GENERIC_SECTION(FLASH_SIMULATOR_MREGION);
|
||||
#else
|
||||
static uint8_t mock_flash[FLASH_SIMULATOR_FLASH_SIZE];
|
||||
#endif
|
||||
#endif /* CONFIG_ARCH_POSIX */
|
||||
|
||||
static const struct flash_driver_api flash_sim_api;
|
||||
|
@ -436,14 +445,20 @@ static int flash_mock_init(const struct device *dev)
|
|||
}
|
||||
|
||||
#else
|
||||
|
||||
#if DT_NODE_HAS_PROP(DT_PARENT(SOC_NV_FLASH_NODE), memory_region)
|
||||
static int flash_mock_init(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int flash_mock_init(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
memset(mock_flash, FLASH_SIMULATOR_ERASE_VALUE, ARRAY_SIZE(mock_flash));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* DT_NODE_HAS_PROP(DT_PARENT(SOC_NV_FLASH_NODE), memory_region) */
|
||||
#endif /* CONFIG_ARCH_POSIX */
|
||||
|
||||
static int flash_init(const struct device *dev)
|
||||
|
|
|
@ -10,3 +10,8 @@ properties:
|
|||
erase-value:
|
||||
type: int
|
||||
description: Value of erased flash cell
|
||||
memory-region:
|
||||
type: phandle
|
||||
description: |
|
||||
Memory region used by the simulated flash memory. If this option is used
|
||||
the memory that is used by the simulated flash memory is not erased.
|
||||
|
|
50
tests/drivers/flash_simulator/boards/nucleo_f411re.overlay
Normal file
50
tests/drivers/flash_simulator/boards/nucleo_f411re.overlay
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Laczen
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/ {
|
||||
sram_2001C000:sram@2001C000 {
|
||||
compatible = "zephyr,memory-region", "mmio-sram";
|
||||
reg = <0x2001C000 0x4000>;
|
||||
zephyr,memory-region = "FlashSim";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
soc {
|
||||
sim_flash_controller: sim-flash-controller@0 {
|
||||
compatible = "zephyr,sim-flash";
|
||||
reg = <0x0 0x1>;
|
||||
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
erase-value = <0xff>;
|
||||
memory-region = <&sram_2001C000>;
|
||||
|
||||
flash_sim0: flash_sim@0 {
|
||||
status = "okay";
|
||||
compatible = "soc-nv-flash";
|
||||
erase-block-size = <512>;
|
||||
/* the flash_simulator test uses a write block
|
||||
* size of 4 for alignment test, so set it to 4.
|
||||
*/
|
||||
write-block-size = <4>;
|
||||
reg = <0x00000000 DT_SIZE_K(16)>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&flash_sim0 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
lfsram_partition: partition@0 {
|
||||
label = "lfsram";
|
||||
reg = <0x00000000 DT_SIZE_K(16)>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -32,7 +32,11 @@
|
|||
(((((((0xff & pat) << 8) | (0xff & pat)) << 8) | \
|
||||
(0xff & pat)) << 8) | (0xff & pat))
|
||||
|
||||
#if (defined(CONFIG_ARCH_POSIX) || defined(CONFIG_BOARD_QEMU_X86))
|
||||
static const struct device *const flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
|
||||
#else
|
||||
static const struct device *const flash_dev = DEVICE_DT_GET(DT_NODELABEL(sim_flash_controller));
|
||||
#endif
|
||||
static uint8_t test_read_buf[TEST_SIM_FLASH_SIZE];
|
||||
|
||||
static uint32_t p32_inc;
|
||||
|
|
|
@ -2,7 +2,7 @@ common:
|
|||
tags: drivers flash
|
||||
tests:
|
||||
drivers.flash.flash_simulator:
|
||||
platform_allow: qemu_x86 native_posix native_posix_64
|
||||
platform_allow: qemu_x86 native_posix native_posix_64 nucleo_f411re
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
drivers.flash.flash_simulator.qemu_erase_value_0x00:
|
||||
|
|
Loading…
Reference in a new issue