Skip to content

novatek: nt9856x: add Fudan FM25S01A SPI NAND and enable nvt-rng on NA51089 - #330

Merged
openipc-ai merged 2 commits into
OpenIPC:novatek-nt9856xfrom
vlw:nt98566-fm25s01a-hwrng
Nov 27, 2026
Merged

openipc-ai merged 2 commits into
OpenIPC:novatek-nt9856xfrom
vlw:nt98566-fm25s01a-hwrng

Conversation

@vlw

@vlw vlw commented Nov 27, 2026 •

Copy link
Copy Markdown

Adds Fudan Microelectronics FM25S01A SPI NAND support and enables the hardware RNG driver (nvt-rng) on Novatek NA51089 / NT98566:

  • drivers/mtd/spiflash/spinand.c — adds FM25S01A 1Gbit 3.3V (0xA1 0xE4, 128 MiB / 1 Gbit, 2048 B page, 128 KiB eraseblock, 64 B OOB).
  • drivers/char/hw_random/Kconfig — allows CONFIG_HW_RANDOM_NVT on NVT_IVOT_PLAT_NA51089 (leaving rng.quality at default 0 since nvt_rng_read() performs unchecked register reads).

Companion PRs:

Hardware Testing

Tested on Dahua DH-IPC-HFW2449SP-S-IL (DHI-IPC-HFW2449SP-S-IL-0280B):

  • SoC: Novatek NT98566 (NA51089), 128 MB DDR3
  • Flash: Fudan Microelectronics FM25S01A (128 MiB SPI NAND, ID 0xA1 0xE4)
  • Sensor: SmartSens SC430AI

Verified SPI NAND probe, UBI/UBIFS rootfs + rootfs_data mount, and /dev/hwrng probe on cold boot from OpenIPC U-Boot 2022.10.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Support FM25S01A SPI NAND and enable Novatek RNG on NA51089

✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Recognize FM25S01A SPI NAND so NA51089 devices can access their 128 MiB flash.
• Enable the Novatek hardware RNG driver on NA51089.
• Credit RNG output as entropy to accelerate kernel random initialization.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: Fudan SPI-NAND storage integration, Novatek hardware-random integration.
  • The changed Kconfig condition controls eligibility for the existing Novatek RNG driver, whose registered hwrng provider is the single end-to-end random-generation behavior; downstream random consumers use that provider but are not independent affected features.
  • The ID table, manufacturer constant, geometry, ECC policy, and MTD registration jointly implement one bounded storage capability.
  • Partitions and generic MTD/filesystem consumers are downstream users of that storage behavior, not independent capabilities.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before, the device-ID table and ECC selection lacked the FM25S01A compatibility case; after, a new manufacturer/device identity maps to specific page, capacity, erase-block, ECC-strength, and bitflip-threshold values.
  • The new correctness condition is that all of those values must agree with the physical device and with MTD consumers.
  • The surrounding ID matching, MTD registration, and ECC infrastructure are reused rather than newly implemented.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the newly enabled configuration or platform integration regresses, the hardware RNG provider may be unavailable and consumers fall back to other entropy sources or fail where no suitable source exists.
  • Reverting restores the prior build behavior; no persistent state repair is implicated.
  • Code rollback restores the previous eligibility condition.
  • The source shows no persistent state or external side effect requiring repair.
Assessed commit b6d67d8
Diagram

graph TD
  F[("FM25S01A NAND")] --> S["SPI NAND probe"] --> U[("UBI rootfs")]
  K["SoC Kconfig"] --> R["Novatek RNG"] --> H["hwrng core"] --> C["kernel CRNG"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Set RNG quality per SoC
  • ➕ Avoids applying the same entropy-trust assumption to both NA51089 and NA51055.
  • ➖ Adds platform-specific configuration and validation for a driver currently shared by both SoCs.

Recommendation: The existing flash table and shared RNG driver are the simplest fit for these devices. Retain the approach if quality 1000 is justified for both supported SoCs; otherwise, make the quality platform-specific before relying on it to accelerate CRNG initialization.

Files changed (3) +6 / -1

Enhancement (2) +5 / -0
nvt-rng.cCredit Novatek RNG output at quality 1000 +1/-0

Credit Novatek RNG output at quality 1000

• Sets the registered hwrng quality to 1000. This changes how much entropy the hwrng core credits from the driver on every platform that uses it.

drivers/char/hw_random/nvt-rng.c

spinand.cIdentify FM25S01A SPI NAND +4/-0

Identify FM25S01A SPI NAND

• Adds flash ID 0xA1 0xE4 to the SPI NAND table with a 2 KiB page, 128 MiB capacity, 128 KiB eraseblock, and 64-byte OOB area.

drivers/mtd/spiflash/spinand.c

Other (1) +1 / -1
KconfigAllow Novatek RNG builds on NA51089 +1/-1

Allow Novatek RNG builds on NA51089

• Expands the HW_RANDOM_NVT platform dependency from NA51055 alone to either NA51055 or NA51089. The existing default remains unchanged.

drivers/char/hw_random/Kconfig

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Failed hardware can appear ready for keys ✓ Resolved
Description
nvt_rng_probe() assigns quality 1000 even though nvt_rng_read() returns every register value as
successful random output without checking readiness or failure status. If the hardware returns stale
or faulty values, the hardware-random framework automatically credits those values as nearly full
entropy, allowing them to satisfy the kernel's early random-readiness threshold.


Informational

2. Flash model claims eightfold capacity ✓ Resolved
Description
The new flash model string says 1GiB, while its SZ_128 capacity field denotes 128 MiB, or 1
Gbit. On identification, the NAND core uses the model string for the device name and probe message
but reports the actual 128 MiB geometry separately, leaving users with contradictory capacity
information.

Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

vlw added a commit to vlw/firmware that referenced this pull request Nov 27, 2026
…ixes

Keep the bridge patches aligned with OpenIPC/linux#330:
- Label FM25S01A as 1Gbit (128 MiB) instead of 1GiB.
- Leave nvt-rng quality at default 0 (enable Kconfig for NA51089 only).

@openipc-ai openipc-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The RNG half checks out on hardware. The flash half needs one driver change before it merges.

What I verified. I built rng-core and nvt-rng.c from novatek-nt9856x as modules against a 4.19.91 nt98566 tree and loaded them on a lab NT98566 (stock NOR board, today's nightly). The node is rng@f0680000 (nvt,nvt_rng), and both clocks (f0680000.rng, f0680000.rngro) exist on NA51089. The probe registers, and /dev/hwrng gives 2.5 MB/s. A 4 MiB sample had 119 repeated 32-bit words where a uniform source expects 128, χ² on the 16-bit halves was 65273 and 65170 (df 65535), and byte χ² was 281 (df 255). So relaxing the depends on is fine.

Changes requested

  1. Set the ECC strength and bitflip threshold for FM25S01A. The part has 1-bit on-die ECC per 512 B (your U-Boot PR #211 declares NAND_ECC_INFO(1, SZ_512)). In this driver it falls through to the else arm of the threshold block in spinand_probe(), so ecc.strength stays 4 and bitflip_threshold = DIV_ROUND_UP(4*3, 4) = 3. spinand_read_page_hwecc() reports 1 corrected bit for an unlisted vendor, so a read never reaches the threshold and never returns -EUCLEAN. UBI therefore never scrubs a page that has already used its only correctable bit, and the next flip in that sector is an uncorrectable read in rootfs. Add a MFG_ID_FUDAN (0xA1) define beside the others, use it in the ID table, and give it ecc.strength = 1; bitflip_threshold = 1, as the 1-bit Winbond and MICRON_MT29F1G01AA arms already do.
  2. Paste the probe output from the Dahua board, not a summary. I need the spinand identify lines from dmesg, cat /sys/class/mtd/mtd*/{name,ecc_strength,bitflip_threshold} after fix 1, and the UBI attach lines (they show bad PEBs and max_ec).
  3. Squash into two commits with accurate messages. 256d8a7860's title still says "set quality to 1000", and 53ef6d19f9 then reverts that. The history should carry what merges: one commit for the flash entry and one for the Kconfig dependency.

Merge order with OpenIPC/firmware#2970: this one lands first. The firmware build fetches the novatek-nt9856x branch tarball, not a pinned revision, so the firmware PR has to drop its local copies of these patches. Details are on that PR.

vlw added 2 commits November 27, 2026 16:41
Add MFG_ID_FUDAN (0xA1) and Fudan Microelectronics FM25S01A (ID 0xA1 0xE4,
128 MiB / 1 Gbit, 2048 B page, 128 KiB eraseblock, 64 B OOB, 1-bit on-die
ECC) to the Novatek SPI NAND driver, setting ecc.strength = 1 and
bitflip_threshold = 1 in spinand_probe() so UBI scrubs single-bit flips.

Tested on Dahua DH-IPC-HFW2449SP-S-IL (Novatek NT98566 / NA51089,
128 MB DDR3, Fudan FM25S01A 128 MiB SPI NAND ID 0xA1 0xE4, SC430AI).
Allow CONFIG_HW_RANDOM_NVT on NVT_IVOT_PLAT_NA51089 (NT9856x).

Tested on Dahua DH-IPC-HFW2449SP-S-IL (Novatek NT98566 / NA51089,
128 MB DDR3, Fudan FM25S01A 128 MiB SPI NAND ID 0xA1 0xE4, SC430AI).
@vlw

vlw commented Nov 27, 2026

Copy link
Copy Markdown
Author

Updated and squashed into two clean commits (50f382452 for FM25S01A + ECC, b6d67d8dd for nvt-rng Kconfig):

  1. Added MFG_ID_FUDAN (0xA1) in drivers/mtd/nvt_flash_spi/nvt_flash_spi_int.h, used it in spinand_flash_ids[], and set info->nand_chip.ecc.strength = 1; mtd->bitflip_threshold = 1; in spinand_probe().
  2. Squashed the history into 2 clean commits with accurate messages.
  3. Rebuilt and booted on Dahua DH-IPC-HFW2449SP-S-IL (NT98566 / NA51089, 128 MB DDR3, Fudan FM25S01A 128 MiB SPI NAND, SC430AI):

Hardware probe output

# dmesg | grep -iE "nand|mtd|ubi|rng"
Kernel command line: mem=48M console=ttyS0,115200 panic=20 init=/init root=ubi0:rootfs rootfstype=ubifs ubi.mtd=2,2048 mtdparts=spi_nand.0:2816k(boot),256k(env),-(ubi)
nvt_rng f0680000.rng: Register nvt_rng_probe successfully
nand: device found, Manufacturer ID: 0xa1, Chip ID: 0xe4
nand: Unknown FM25S01A 1Gbit 3.3V
nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
spi_nand f0400000.nand: 4-bit mode @ 40000000 Hz
3 cmdlinepart partitions found on MTD device spi_nand.0
Creating 3 MTD partitions on "spi_nand.0":
0x000000300000-0x000008000000 : "ubi"
ubi0: attaching mtd2
ubi0: scanning is finished
ubi0: attached mtd2 (name "ubi", size 125 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 999, bad PEBs: 1, corrupted PEBs: 0
ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 0
ubi0: available PEBs: 0, total reserved PEBs: 999, PEBs reserved for bad PEB handling: 19
ubi0: background thread "ubi_bgt0d" started, PID 641
UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs", R/O mode
UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
UBIFS (ubi0:0): FS size: 12570624 bytes (11 MiB, 99 LEBs), journal size 9023488 bytes (8 MiB, 72 LEBs)
UBIFS (ubi0:0): reserved for root: 0 bytes (0 KiB)
UBIFS (ubi0:0): media format: w4/r0 (latest is w5/r0), UUID 0E546A17-8CEA-4BDC-9784-E5D6D9DEAA98, small LPT model
VFS: Mounted root (ubifs filesystem) readonly on device 0:13.
UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 650
UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "rootfs_data"
UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
UBIFS (ubi0:1): FS size: 108564480 bytes (103 MiB, 855 LEBs), journal size 5459968 bytes (5 MiB, 43 LEBs)
UBIFS (ubi0:1): reserved for root: 4952683 bytes (4836 KiB)
UBIFS (ubi0:1): media format: w5/r0 (latest is w5/r0), UUID CA5BC89D-ABFC-4780-8621-F448E6F798A4, small LPT model

# for d in /sys/class/mtd/mtd[0-9]; do echo "$d: name=$(cat $d/name) ecc_strength=$(cat $d/ecc_strength) bitflip_threshold=$(cat $d/bitflip_threshold)"; done
/sys/class/mtd/mtd0: name=boot ecc_strength=1 bitflip_threshold=1
/sys/class/mtd/mtd1: name=env ecc_strength=1 bitflip_threshold=1
/sys/class/mtd/mtd2: name=ubi ecc_strength=1 bitflip_threshold=1

@vlw
vlw force-pushed the nt98566-fm25s01a-hwrng branch from 53ef6d1 to b6d67d8 Compare November 27, 2026 13:46
vlw added a commit to vlw/firmware that referenced this pull request Nov 27, 2026
…CI entry

Add nt98566_ultimate_defconfig, Kconfig-ordered nt98566.nand.config
(SPI NAND + HWECC, UBI/UBIFS, OF partitions, HW_RANDOM_NVT),
ubinize-nand.cfg (rootfs + autoresize rootfs_data), exfat-openipc +
exfatprogs, and register nt98566_ultimate in ci-matrix.py.

Note: Novatek's drivers/mtd/spiflash/Kconfig defines MTD_SPINOR with
'depends on (MTD) && (!MTD_SPINAND)', so a single NT98566 kernel cannot
enable both SPI NOR and SPI NAND simultaneously; nt98566_ultimate is
therefore SPI NAND only (nt98566_lite continues to cover SPI NOR).
Depends on OpenIPC/linux#330 (FM25S01A + nvt-rng Kconfig) and
OpenIPC/u-boot#211.

Tested on Dahua DH-IPC-HFW2449SP-S-IL (Novatek NT98566 / NA51089,
128 MB DDR3, Fudan FM25S01A 128 MiB SPI NAND ID 0xA1 0xE4, SC430AI).

@openipc-ai openipc-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. MFG_ID_FUDAN now has ecc.strength = 1 and bitflip_threshold = 1, and the board shows ecc_strength=1 bitflip_threshold=1 on every partition, so UBI will scrub a page once it has used its one correctable bit. The probe output, the UBI attach lines and the writes behind the rootfs_data mount and the sysupgrade run on OpenIPC/firmware#2970 cover the flash half. The RNG half matches what I measured on the lab NT98566. The history is two clean commits.

This lands before OpenIPC/firmware#2970, whose nt98566_ultimate kernel config relies on both changes.

@openipc-ai
openipc-ai merged commit e75a416 into OpenIPC:novatek-nt9856x Nov 27, 2026
vlw added a commit to vlw/firmware that referenced this pull request Nov 27, 2026
…CI entry

Add nt98566_ultimate_defconfig, Kconfig-ordered nt98566.nand.config
(SPI NAND + HWECC, UBI/UBIFS, OF partitions, HW_RANDOM_NVT),
ubinize-nand.cfg (rootfs + autoresize rootfs_data), exfat-openipc +
exfatprogs, and register nt98566_ultimate in ci-matrix.py.

Note: Novatek's drivers/mtd/spiflash/Kconfig defines MTD_SPINOR with
'depends on (MTD) && (!MTD_SPINAND)', so a single NT98566 kernel cannot
enable both SPI NOR and SPI NAND simultaneously; nt98566_ultimate is
therefore SPI NAND only (nt98566_lite continues to cover SPI NOR).
Depends on OpenIPC/linux#330 (FM25S01A + nvt-rng Kconfig) and
OpenIPC/u-boot#211.

Tested on Dahua DH-IPC-HFW2449SP-S-IL (Novatek NT98566 / NA51089,
128 MB DDR3, Fudan FM25S01A 128 MiB SPI NAND ID 0xA1 0xE4, SC430AI).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants