Upper bound is defined as the last block within the erase region.
Subtract one block unit from the erase size when programming upper
bound to prevent the erase range from extending into the next block.
With the correct upper/lower bounds in place, erase requests can be
handled in a single operation. Remove the block-by-block erase
loop.
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
Drop duplicated HAL_XSPIM_Config fallback code from STM32 XSPI
flash, MSPI, and MEMC drivers.
With manager setup centralized in the common XSPIM driver and
explicit xspim devicetree nodes, XSPI consumer drivers no longer
need to configure XSPIM directly.
Assisted-by: GitHub Copilot:GPT-5.3-Codex west
Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
Add tfm-nrf-mramc to zephyr MRAMC driver, since mramc is secure only
peripheral. Access of nrf-mramc need nrf mramc service.
Bugfix for unaligned write should be done byte by byte instead of word
by word.
Flash write in normal write mode, previously nrf_mramc driver write use
DIRECT_WRITE_MODE in mramc. It is a not reliable method of handling
flash write since the write buffer may lost content when the write is
interrupted. This change is to switch to normal write mode and the
every write should align to 16 bytes which is the write-block-size.
Signed-off-by: Travis Lam <travis.lam@nordicsemi.no>
Physical write block size of mram is 16 for nrf7120. While using
direct write mode for write. Writing 32-bits word is handled by
mramc hardware itself.
In nrf7120 is capable to disable busfault when word written is
corrupted. Data verification is added after write/erase to
ensure a write is robust.
Signed-off-by: Travis Lam <travis.lam@nordicsemi.no>
qspi_read_jedec_id() builds the JEDEC Read ID (0x9F) command with
.AddressMode set to QSPI_ADDRESS_1_LINE, while intending to send no
address phase: .AddressSize is set to QSPI_ADDRESS_NONE, which is the
AddressMode "none" constant (0x0) and, used as an address size, equals
QSPI_ADDRESS_8_BITS.
Because the STM32 HAL emits an address phase whenever
AddressMode != QSPI_ADDRESS_NONE, the controller clocks out a phantom
8-bit address after the opcode. This shifts the returned data by one
byte and drops the manufacturer ID: flash_read_jedec_id() returns e.g.
40 19 00 instead of EF 40 19 for a Winbond W25Q256JV.
Set .AddressMode to QSPI_ADDRESS_NONE so the Read ID command issues no
address phase, as the 0x9F command requires.
Signed-off-by: Lucas Zampar Bernardi <lucas.zampar@gmail.com>
- Kconfigs in modules/ should not define configs with an SOC_ prefix.
Furthermore, these options are SDK specific, not SoC specific.
- The simplicity_sdk configs do the same.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Install flash functions at driver init, once the scheduler
is running, since early boot leaves the chip on the no-OS path.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
expose option bytes reading / writing via flash_ex_op interface
flash_stm32_option_bytes_write fails if flash is not unlocked
Signed-off-by: Mariusz Kryński <mrk@sed.pl>
Add support for checking and marking bad blocks in the shell via the
new commands:
- `flash is_bad [<device>] <address>`
- `flash mark_bad [<device>] <address>`
This allows users to identify and manage bad blocks on flash devices
that support these operations.
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Switch back to target io mode after sfdp_read().
If target io mode is not single, sfdp_read() will switch to single
and leave it that way. This would cause the subsequent mspi_xip_config()
call to be issued in the wrong io mode. This change makes sure
the target io mode is switched to again after the sfdp_read().
Signed-off-by: Mike J. Chen <mjchen@google.com>
Add K_SYSCALL_DRIVER_FLASH checks for src_dev and dst_dev in
z_vrfy_flash_copy() to ensure both devices implement the required
flash driver API before proceeding with the copy operation.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Opt-in optimisation for the api->fill callback (and, transitively,
flash_fill() and flash_flatten()): scan the target region in 16-byte
write-line granularity with a fast 4x32-bit compare and skip the
physical write entirely for lines that already hold the fill value.
Consecutive dirty lines are batched into a single underlying
nrf_write().
Disabled by default because it changes the worst-case latency profile
of fill operations; enable explicitly when write endurance matters
more than absolute determinism.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
Wire up the nRF RRAM driver to the new optional flash_api_fill
callback so flash_fill() and flash_flatten() on no-erase devices can
complete a region-fill in a single bulk operation instead of a long
write loop driven by CONFIG_FLASH_FILL_BUFFER_SIZE.
Result: a region-fill is now one rram_write() call covering the full
range, replacing thousands of write-block-sized api->write() calls
that each forced a hardware buffer commit. Flash_flatten() on RRAM
becomes effectively a single optimized memset.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
Prefer api->fill() when the driver provides it. Drivers that don't
implement the new callback (the vast majority today) keep using the
existing write-loop path with no behaviour change. The check is placed
after argument validation so misuse is caught the same way for both
paths, and before allocating the stack buffer so a fill-capable driver
does not pay for an unused CONFIG_FLASH_FILL_BUFFER_SIZE allocation.
This also fixes the long-standing inconsistency where flash_flatten()
on a no-erase device had to dispatch through flash_fill()'s slow loop
even when the underlying driver had a perfectly good bulk-fill path
available - flash_fill() now picks the fast path automatically.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
Add a new optional `flash_api_fill` callback type and matching field in
`struct flash_driver_api`. The callback lets a driver provide an
optimized implementation of fill-with-value (the operation that backs
`flash_fill()` and, transitively, `flash_flatten()` on devices without
explicit erase). When the field is left NULL behaviour is unchanged:
`flash_fill()` keeps using its generic write-loop emulation, so this is
a fully backwards compatible API extension and existing drivers compile
and run unchanged.
Explicit-erase drivers may also implement it when an internal command
is faster than a write loop.
The signature mirrors `flash_fill()` so the syscall implementation can
forward arguments verbatim. Alignment expectations match `api->write`
(write_block_size aligned offset/size); callers of `flash_fill()`
already satisfy this.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
Add support for reading and writing Option Bytes (OB) on STM32U3
series devices. This enables runtime configuration of OB fields
using the STM32 flash driver.
Signed-off-by: saeed molaie <saeed.molaie@st.com>
The SF32LB MPI QSPI NOR write path uses DMA to feed the MPI data
register before issuing page program commands. If the source buffer
points into the same memory-mapped NOR window, DMA can fetch from
flash while the controller is programming it, which can hang the bus.
Add a page-sized aligned SRAM bounce buffer for such source buffers,
and use it as the DMA source for affected chunks. Also harden flash
range validation and reject partially overlapping mapped flash source
and destination ranges while treating an exact same-range write as a
no-op.
Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
Include MSPI_DEVICE_CONFIG_IO_MODE in XIP_DEV_CFG_MASK and populate
mspi_cfg.io_mode from dev_config->read_io_mode so the XIP setup call
configures the XIP io-mode which wasn't previously the case.
Signed-off-by: David Jewsbury <david.jewsbury@nordicsemi.no>
Replace the direct memcpy() in flash_nrf_read() and nrf_rram_read()
with an inline check against soc_secure_flash_range_is_secure().
Reads that overlap a "nordic,tz-secure" partition go through
soc_secure_mem_read(); all others stay a plain memcpy() /
nrf_nvmc_buffer_read().
For secure builds and for NS builds without a tz-secure DT node the
predicate folds to a constant false and the secure branch is dropped
by the optimiser, so this is a no-op for any layout that does not
opt in.
Signed-off-by: Dag Erik Gjørvad <dag.erik.gjorvad@nordicsemi.no>
Add support for full SMIF hardware initialization for the serial
memory flash driver when booting from internal RRAM.
On PSE84, the ROM extended boot only configures the SMIF subsystem
when the device boots from external flash. When the first application
(MCUboot or CM33 secure) runs from RRAM, the SMIF pins, clocks,
peripheral groups, and peripheral itself are left uninitialized.
Introduce CONFIG_FLASH_INFINEON_SMIF_HW_INIT to conditionally
perform these steps before mtb_serial_memory_setup() is called.
Extract the info as much as possible from DT. Some are still hardcoded
in the driver and will require additional polishing in a follow-up PR.
Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Laura Carlesso <laura.carlesso@infineon.com>
- Read write_block_size from devicetree (default 4 in binding) to
allow board-level override for finer write granularity.
- Add CONFIG_FLASH_MCUX_XSPI_WRITE_BUFFER (default n) to copy
write data to a RAM buffer before transfer, preventing faults
when source data resides in flash and padding transfer size to
4-byte boundary for the XSPI IP Tx limitation.
- When write buffer is disabled, reject non-4-byte-aligned offset
or length with -EINVAL.
Signed-off-by: Ruijia Wang <ruijia.wang@nxp.com>
- Clamp write_size to remaining bytes in the current 256-byte page
to prevent page program address wrap, consistent with the FlexSPI
NOR drivers.
- Set write_block_size to 2 because OPI DTR mode requires all writes
to be 2-byte aligned and multiples of 2 bytes.
Signed-off-by: Ruijia Wang <ruijia.wang@nxp.com>
- Add JEDEC case for Macronix MX25U6432F to skip SFDP auto-parsing.
- Forces 24-bit addressing to prevent breaking active XIP loops.
Signed-off-by: Deepika R <deepika@aerlync.com>
the option MPU_ALLOW_FLASH_WRITE is only needed
when ARM_MPU. Only files in include/zephyr/arch/arm/mpu/
and include/zephyr/arch/arm64/cortex_r use it. it is not used in
xtensa or riscv.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
as in the spi_nor driver, so that the DPD mode can be used even if
the flash API caller does not perform the runtime device PM calls.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Add proper handling of the `has-dpd`, `t-enter-dpd`, and `t-exit-dpd`
devicetree properties that could be applied to "jedec,mspi-nor" nodes,
but caused no effect so far.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Correct alignment of `\` characters in the `FLASH_MSPI_NOR_INST(inst)`
macro definition.
Use `NSEC_PER_USEC` symbols instead of 1000 when doing conversion from
nanoseconds to microseconds.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
A flash manager thread is created and allocated to
process Flash Manager Process.
Definition of KConfigs STM32WBA_FLASH_MNGR_THREAD_STACK_SIZE,
and STM32WBA_FLASH_MNGR_THREAD_PRIO to configure the
flash manager thread.
STM32WBA_FLASH_MNGR_THREAD_STACK_SIZE is setting by default
to 768 bytes. This value was chosen empirically since reasonable
to cover generic cases.
Signed-off-by: Vincent Tardy <vincent.tardy@st.com>
Ready registers are defined for the nrf54h series but not necesssary for
other soc families.
Limit the Ready register check only to this family of socs.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
Remove the 'andestech,qspi-nor-xip' compatible string and unify both
flash_andes_qspi.c and flash_andes_qspi_xip.c flash drivers use
'andestech,qspi-nor' compatible string.
The driver selection is now handled via Kconfig logic.
CONFIG_FLASH_ANDES_QSPI_XIP is strickly depends on XIP is enabled and
the 'zephyr,flash' chosen node is compatible with 'andestech,qspi-nor'.
Since these two driver variants cannot coexist, the application is
responsible for enabling the appropriate driver Kconfig.
Signed-off-by: Jimmy Zheng <jimmyzhe@andestech.com>
When the TimeOut is enabled in MemoryMapped mode, the TO irq callback
has not to give any sem, because the read operation is done with
memcopy(). No sem was taken, nothing to release.
Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit fixes two boundary calculation bugs within read_non_aligned()
in the nrf_qspi_nor driver:
1. Prefix Alignment: Removed the `if (flash_prefix > size)` check. This
check artificially capped the prefix, resulting in unaligned addresses
being passed to the nrfx HAL.
2. Suffix Out-of-Bounds: Replaced the hardcoded WORD_SIZE * 2 suffix
read with a dynamic size check. Previously, if a read ended near the
physical boundary of the flash chip, the hardcoded 8-byte read would
request memory outside the chip's physical address space.
Fixes#109139Fixes#109140
Signed-off-by: T Madhusudhan Rao <tetakalam@aerlync.com>
memcpy is not optimized for the Cortex-M core due to this :
https://github.com/zephyrproject-rtos/zephyr/issues/95154
Modify this by writing each word individually only when source address
is aligned to 4 bytes boundary.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
When requesting/releasing the no_latency mode for the mram, verify that
the request/release is successful to avoid running into infinite loop if
the mram controller is in autopowerdown mode.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
Fix the case where the MRAM writes get corrupted in some conditions.
After each "MRAM_WORD_SIZE write", a read of the written/erased MRAM word
is performed while masking the bus faults to avoid halting the system.
If an error is detected in the BFSR status bits, retry the write for a
maximum of CONFIG_NRF_MRAM_MAX_RETRIES (default 20) times.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
When writes are issued to the mram controller without verifying that it
is ready, it can cause the reads to be stalled until all writes finish.
Fix this by adding a wait busy loop before each MRAM_WORD aligned write
and disable autopowerdown before starting the write.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
Add a BULID_ASSERT to make sure that the write_block_size defined in the
device tree is a multiple of the MRAM_WORD_SIZE which is 16B (128 bits)
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
Determine the expiry status before the read to ensure that this function
only returns `-ETIMEDOUT`` if the flash still isn't ready *after* the
provided `timeout_us`. Checking after the read (in the while condition)
can result in the status being read once on function entry, then the
thread not resuming from the `k_sleep` until after the timeout expires.
The changes the timeout behaviour of `spi_nand_wait_until_ready` from
"Flash not ready at some point before expiry" to "Flash still not ready
after at least `timeout_us`".
Signed-off-by: Jordan Yates <jordan@embeint.com>
Support setting desiered SPI communication frequency via configuring
the SCLK_DIV divisior in IFTIM register.
Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
When parts of code are running from EXTXIP and at the same
time QSPI external flash writes/erases are happenning there
is a high risk of a race condition where a thread running
EXTXIP code starts executing while an external flash operation
is in progress; This can lead to execution stalling or
bus faults/usage faults.
The issue was observed when parts of MCUMGR were relocated to
EXTXIP and DFU was performed.
To fix the issue added the CONFIG_NORDIC_QSPI_NOR_XIP_FLASH_SCHED_LOCK
option which should be used when executing parts of code from EXTXIP.
It ensures the blocking variant of nrfx_qspi_ is used and that
no preemption happens while an external flash write is in progress
(by making qspi_wait_while_writing blocking)
Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Add support for issuing a software reset sequence (RSTEN 0x66 followed
by RST 0x99) to the flash device during initialization, before reading
SFDP parameters.
The feature is controlled by a new devicetree property
'initial-soft-reset'. When enabled, the driver sends the reset
sequence using temporary LUT entries to avoid flash data
access during XIP critical sections.
An optional 't-reset-recovery' property specifies the minimum time in
nanoseconds the flash needs after reset before accepting new commands.
If provided, the driver will busy-wait(self defined) for the
specified duration.
Suggested-by: Sanjay Varghese <Varghesemela@gmail.com>
Link: https://github.com/zephyrproject-rtos/zephyr/pull/105891
Signed-off-by: Albort Xue <yao.xue@nxp.com>
Fix by demoting BIT(6) to a fallback, checked only when no active
entry method bit (BIT(0), BIT(1), BIT(4)) is also set. This aligns
with the approach in Zephyr's generic spi_nor driver and the Linux
kernel spi-nor subsystem, both of which prefer active entry commands
when available and treat the "always 4-byte" indication as a last
resort. Sending 0xB7 to a device that is already in 4-byte mode is
idempotent and harmless.
Signed-off-by: Albort Xue <yao.xue@nxp.com>