Skip to content

mtd: spinand: add FORESEE F35SQA512M 512Mbit SPI NAND - #335

Merged
openipc-ai merged 1 commit into
OpenIPC:novatek-nt9856xfrom
andrein:spinand-foresee-f35sqa512m
Nov 29, 2026
Merged

openipc-ai merged 1 commit into
OpenIPC:novatek-nt9856xfrom
andrein:spinand-foresee-f35sqa512m

Conversation

@andrein

@andrein andrein commented Nov 28, 2026

Copy link
Copy Markdown

Adds the FORESEE F35SQA512M (JEDEC ID cd 70, 64 MiB, 2 KiB pages, 128 KiB blocks, 64-byte OOB) to the Novatek SPI NAND driver, and sets ECC strength and bitflip threshold to 1 for FORESEE, as is done for the Fudan chip.

The 1-bit strength is from the F35SQA512M datasheet (rev 1.1, section 11.4): one bit corrected per 512 bytes of data plus 16 bytes of spare.

Tested on a Reolink E340 (NT98566): chip detected with the geometry above, ecc_strength and bitflip_threshold read 1, UBI attach, UBIFS mount, erase and write work.

Not changed here: the ID lookup loop iterates over sizeof(spinand_flash_ids) rather than the number of entries.

🤖 Generated with Claude Code

The Reolink E340 (NT98566) carries a FORESEE F35SQA512M, JEDEC ID
cd 70. The driver only accepts chips listed in its own table, so the
flash is not usable without an entry.

The chip's on-die ECC corrects one bit per segment of 512 bytes of data
plus 16 bytes of spare (datasheet rev 1.1, section 11.4). Set strength
and bitflip threshold to 1, as is done for the Fudan chip, so that a
corrected read makes UBI move the data. With the generic values (4 and
3) a degrading block would never be scrubbed.

Tested on a Reolink E340: the chip is detected as 64 MiB with 128 KiB
blocks and 2 KiB pages, ecc_strength and bitflip_threshold read 1, and
UBI attach, UBIFS mount, erase and write work.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

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

Copy link
Copy Markdown

PR Summary by Qodo

mtd: spinand: support FORESEE F35SQA512M

✨ Enhancement 🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Recognize the FORESEE F35SQA512M and its 64 MiB SPI NAND geometry.
• Set one-bit ECC strength and bitflip threshold so corrected reads can trigger UBI scrubbing.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The new ID table entry and probe branch jointly configure one end-to-end storage behavior for the FORESEE part: identification supplies geometry and probe supplies ECC policy.
  • These are implementation hops of the same bounded SPI NAND integration, not independent capabilities.
Sources

drivers/mtd/spiflash/spinand.c[1404-1406]

		} else if (chip_id == MFG_ID_FORESEE) {
			info->nand_chip.ecc.strength = 1;
			mtd->bitflip_threshold = 1;
Behavioral complexity 🟢 Low 🧩 Straightforward

  • The base driver already maps vendor/device IDs to geometry and has vendor-specific ECC branches.
  • This change adds one matching table record, defines its vendor ID, and applies the same direct one-bit ECC rule used for the existing FUDAN case; it does not introduce new state, ordering, transformation, or compatibility interaction.
Sources

drivers/mtd/nvt_flash_spi/nvt_flash_spi_int.h[283-286]

#define MFG_ID_DOSILICON        0xE5
#define MFG_ID_XTX              0x0B
#define MFG_ID_FUDAN            0xA1
#define MFG_ID_FORESEE          0xCD

drivers/mtd/spiflash/spinand.c[1404-1406]

		} else if (chip_id == MFG_ID_FORESEE) {
			info->nand_chip.ecc.strength = 1;
			mtd->bitflip_threshold = 1;
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the new identification or initialization behavior regresses for the matching part, that device's MTD storage access could fail or remain unavailable.
  • No source evidence supports claiming impact to other vendors or unrelated storage.
  • Reverting the code should restore the previous driver behavior, assuming the device was previously unsupported and no external state was changed.
  • Code rollback restores the prior driver behavior; the affected capability may require reboot or reprobe, but no persistent repair is established by the source.
Sources

drivers/mtd/spiflash/spinand.c[435-437]

	{"F35SQA512M 512Mbit 3.3V",
		{ .id = {MFG_ID_FORESEE, 0x70} },
		SZ_2K, SZ_64, SZ_128K, 0, 2, 64 },

drivers/mtd/spiflash/spinand.c[1404-1406]

		} else if (chip_id == MFG_ID_FORESEE) {
			info->nand_chip.ecc.strength = 1;
			mtd->bitflip_threshold = 1;
Assessed commit 711e6fc
Diagram

graph TD
  chip["FORESEE NAND"] --> lookup["Read chip ID"] --> table["Device table"] --> geometry["Flash geometry"] --> mtd["MTD and UBI"]
  table --> policy["ECC policy"] --> mtd
Loading
High-Level Assessment

The existing device table and vendor-specific ECC branch are appropriate for one additional chip. Moving ECC settings into per-device metadata would be a broader refactor without a clear benefit for this change.

Files changed (2) +8 / -0

Enhancement (2) +8 / -0
nvt_flash_spi_int.hDefine the FORESEE manufacturer ID +1/-0

Define the FORESEE manufacturer ID

• Adds the 0xCD manufacturer constant used for device identification and ECC selection.

drivers/mtd/nvt_flash_spi/nvt_flash_spi_int.h

spinand.cRecognize F35SQA512M and configure one-bit ECC +7/-0

Recognize F35SQA512M and configure one-bit ECC

• Adds the cd 70 device entry with 2 KiB pages, 128 KiB erase blocks, and 64 MiB capacity. Sets ECC strength and bitflip threshold to one when probing FORESEE chips with on-die ECC.

drivers/mtd/spiflash/spinand.c

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@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.

Approving. I checked it against the driver and the datasheet:

  • cd 70 and the geometry (2 KiB pages, 64 MiB, 128 KiB blocks, 64-byte OOB) match the F35SQA512M. Mainline's drivers/mtd/nand/spi/foresee.c gives the same ID and NAND_ECCREQ(1, 512).
  • The chip has no corrected-bit count to read, so spinand_read_page_hwecc() takes the generic else arm and returns 1 on ECC_CORRECTED. With bitflip_threshold = 1 that is -EUCLEAN, and UBI scrubs the block. The default arm (strength 4, threshold 3) would never get there. This is the FM25S01A fix from #330, applied to a chip with the same 1-bit ECC.
  • 0xCD doesn't collide with any MFG_ID_* already in the header, and FORESEE takes no other vendor-specific arm (OOB layout, quad enable, ECC status), which matches your erase/write/UBIFS test.

You're right about the sizeof(spinand_flash_ids) loop in drv_nand_read_id(). It counts bytes, not entries, so an unlisted chip reads past the end of the table. A separate one-line PR changing it to ARRAY_SIZE() would be welcome.

@openipc-ai
openipc-ai merged commit 7a57ef5 into OpenIPC:novatek-nt9856x Nov 29, 2026
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