nuttx/drivers
Julian Oes 0c287d6f45 drivers/mtd/w25n: implement bad block management
Use the chip's built-in 20-entry non-volatile Bad Block Management
Look-Up Table (datasheet section 8.2.7) to transparently route around
bad blocks.

Init:
- Reserve the top 24 blocks of the array as a spare pool
- Clamp the MTD geometry to W25N_USER_BLOCKS = 1000 so upper layers
  never see the spare area (125 MB usable instead of 128 MB)
- Force BUF=1 alongside enabling ECC. The W25N01GVxxIT variant
  power-ups with BUF=0 (Continuous Read mode), in which Read Data
  ignores the column address and always starts at byte 0 - which
  silently broke any read targeting a non-zero column (OOB markers,
  sub-page reads in w25n_read).
- Scan all 1024 blocks for factory bad markers (non-FFh at byte 0 of
  the spare area of page 0) and remap any user-area bad blocks via the
  A1h BBM command. Idempotent across reboots: blocks already present
  in the LUT are skipped, so repeated scans don't consume LUT slots.

Runtime:
- On E-FAIL from w25n_block_erase or P-FAIL from w25n_program_execute,
  allocate a spare and issue A1h, then retry the operation once. The
  chip routes the retry to the spare PBA transparently. Data buffer is
  reloaded on program retry.
- Uncorrectable read ECC is left as -EIO (soft errors shouldn't trigger
  permanent remap, and remapping discards data we may still recover).

Safeguards against burning LUT slots on bogus bad blocks:
- w25n_pick_free_spare erases each candidate spare as an active proof
  of life before returning it - the factory OOB marker alone isn't
  trusted.
- w25n_bbm_swap rejects A1h with LBA outside the user area or PBA
  outside the spare pool.

Stack discipline for the logger-thread hot path:
- The 20-entry cached LUT lives in the device struct, not on the stack.
- w25n_read_bbm_lut decodes 4 bytes at a time instead of reading the
  full 80-byte LUT dump into a local buffer.

Boot diagnostics are emitted via syslog so they appear unconditionally:
- [w25n] BBM scan summary (new/remapped/unremapped/previously-remapped/
  LUT slots used)
- [w25n] W25N01GV ready line with user blocks, spare count, geometry,
  and actual SPI frequency
- [w25n] per-remap info and warnings on runtime E-FAIL/P-FAIL paths

Note: existing littlefs filesystems become unmountable because the
block count shrinks from 1024 to 1000; both PX4 board init.c paths
already mount with autoformat so they reformat on first boot after
this change.

Signed-off-by: Julian Oes <julian@oes.ch>
2026-04-23 16:26:44 +02:00
..
1wire style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
aie include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
analog include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
audio style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
bch include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
can include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
clk include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
contactless include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
coresight style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
crypto include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
devicetree include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
dma drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
dummy drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
eeprom include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
efuse include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
i2c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
i2s include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
i3c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
input include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
ioexpander include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
ipcc include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
lcd include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
leds include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
loop include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
math include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
misc include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
mmcsd include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
modem style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
motor style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
mtd drivers/mtd/w25n: implement bad block management 2026-04-23 16:26:44 +02:00
net include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
note include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pci include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pinctrl drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
pipes include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
power include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rc include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
regmap include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
reset include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rf include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rpmsg include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rptun include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
segger drivers/segger: Add a kconfig to override Segger SystemView target sources version 2025-07-22 23:21:31 +08:00
sensors sensors/Make.defs: Aligned Make with Cmake 2026-04-22 06:22:55 +08:00
serial style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
spi include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
syslog include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
thermal include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
timers include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
usbdev include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
usbhost arch/arm/src/stm32h5/stm32_usbdrdhost.c: Fixed Hub support 2026-04-19 14:24:40 +08:00
usbmisc include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
usbmonitor include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
usrsock include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
vhost include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
video video/fb: guarantee fb read-write integrity to prevent display tearing 2026-04-15 10:18:16 -03:00
virtio include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
wireless style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
.gitignore
CMakeLists.txt drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
drivers_initialize.c serial/uart_rpmsg: add _raw version of driver 2026-02-23 09:19:57 -03:00
Kconfig espressif/rmt: replace rmtchar with arch-specific lirc adapter 2026-04-04 11:18:32 -03:00
Makefile docs/rc: document RC/LIRC drivers and remove empty drivers/rmt files 2026-04-04 11:18:32 -03:00