Flash

Overview

Flash offset concept

Offsets used by the user API are expressed in relation to the flash memory beginning address. This rule shall be applied to all flash controller regular memory that layout is accessible via API for retrieving the layout of pages (see CONFIG_FLASH_PAGE_LAYOUT).

An exception from the rule may be applied to a vendor-specific flash dedicated-purpose region (such a region obviously can’t be covered under API for retrieving the layout of pages).

Flash Simulator

Overview

The Flash Simulator provides a virtual, RAM-backed flash memory device. It is primarily used for testing and development on native targets ( such as native_sim or qemu_x86) where a physical flash device is not available.

The simulator implements the standard Zephyr flash API, allowing applications to read, write and erase data exactly as they would with a real hardware flash controller.

Configuration

Devicetree

To use the flash simulator, one must define a node in one’s devicetree that is compatible with zephyr,sim-flash.

The physical properties of the simulated flash (such as its size and block dimensions) are configured using standard devicetree properties:

flash0: flash_simulator@0 {
         compatible = "zephyr,sim-flash";
         reg = <0x00000000 DT_SIZE_K(1024)>;
         erase-block-size = <1024>;
         write-block-size = <4>;
         erase-value = <0xff>;
};
  • reg: Defines the base address and the total size of the simulated flash memory.

  • erase-block-size: The size of a single erasable block in bytes.

  • write-block-size: The minimum write alignment in bytes.

  • erase-value: The value of an erased flash cell. Typically 0xff or 0x00.

  • memory-region: (optional) A phandle to a memory region. If used, the memory is not cleared on boot.

Kconfig Options

The simulator supports several Kconfig options to mimic the behavior of physical hardware:

User API Reference

Flash

Implementation interface API Reference

Flash Internal