Repository navigation
agent: scan NOR through flash_read, not the memory window that wraps at 1 MiB - #153
Conversation
…at 1 MiB
On hi3536dv100 (Xiongmai NBD8010S-KL-V2, W25Q128) `agent scan` reported
256/256 GOOD with per-sector CRCs repeating every 16 sectors: sector 16
(0x100000, kernel) carried sector 0's CRC (U-Boot). handle_scan() read
NOR through the memory-mapped boot-mode window at FLASH_MEM. That window
wraps at 1 MiB on some SoCs, which is why CMD_READ and CMD_CRC32 already
go through the register path ("boot mode memory window wraps at 1MB on
some SoCs", handle_crc32_cmd). So every sector past the first MiB was
scanned as a copy of one inside it, and empty sectors were missed.
Both passes now read the chip as CMD_READ does:
- Pass 1 (CRC32 and the uniformity check) reads each sector with
flash_read() into scan_buf. NOR sectors larger than scan_buf (128 KiB)
are read in chunks, with the CRC chained across them. NAND keeps its
one read per block.
- Pass 2, NOR's stability check, is an independent flash_crc32() of the
sector, a second read through the same path. Before, it was a second
pass over the same wrapped window.
On the board (agent built from this commit, flash = OpenIPC 16M image):
before, 256 GOOD and 16 distinct CRCs; now 133 GOOD and 123 EMPTY. The
123 EMPTY are the all-0xFF sectors FLASH_STREAM skips for this image.
There are 93 distinct CRCs, and every non-empty sector's scan CRC equals
CMD_CRC32 for it. The scan takes 20 s (27 s before).
make -C agent test passes. All ten SoC builds compile with the same
warnings as master (compared line by line on hi3536dv100/FMC100 and
hi3520dv200/HISFC350).
PR Summary by QodoFix NOR sector scans beyond the 1 MiB boot window
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1.
|
…d reads Qodo review on this branch. 1. Reads above 16 MiB. FMC100's register reads (flash_read, flash_crc32) send three address bytes, so on a 32/64 MiB FMC100 chip they cannot reach a sector at or above 16 MiB. CMD_READ and CMD_CRC32 share that limit today. The scan, though, read those sectors through the memory window before this branch, so it would have regressed there. scan_read() and scan_crc() now keep the window for FMC100 NOR offsets >= 16 MiB, exactly as before, and use the register path below that, where the 1 MiB wrap is. HISFC350's flash_read banks across the chip (hi3520dv200's 32 MiB MX25L25635E), so it is used everywhere there. SPI_DRIVER_FMC100 now tells main.c which driver it was built with. 2. Stalled reads. FMC100's NOR flash_read() ignored a timed-out fmc_wait_ready() and copied the I/O buffer anyway, and its NAND path ignored nand_read()'s 0xFF "never finished". flash_read() now returns -1 for either (HISFC350's memory-mapped reads return 0). The scan marks such a sector SCAN_READ_ERROR (0x05, already in the host's SectorStatus) with CRC 0, instead of judging stale bytes, which could pass as EMPTY. Other flash_read() callers keep ignoring the result. On the NBD8010S-KL-V2 (16 MiB W25Q128, so every sector takes the register path): 133 GOOD, 123 EMPTY, no READ_ERROR, and every GOOD sector's CRC equals CMD_CRC32's, in 20 s. The >= 16 MiB window branch is unchanged behaviour, not exercised here. make -C agent test passes. hi3536dv100 (FMC100) and hi3520dv200 (HISFC350) build with the same warnings as master, and four more SoCs build.
On hi3536dv100 (Xiongmai NBD8010S-KL-V2, W25Q128)
agent scanreported256/256 GOOD with per-sector CRCs repeating every 16 sectors: sector 16
(0x100000, kernel) carried sector 0's CRC (U-Boot). handle_scan() read
NOR through the memory-mapped boot-mode window at FLASH_MEM. That window
wraps at 1 MiB on some SoCs, which is why CMD_READ and CMD_CRC32 already
go through the register path ("boot mode memory window wraps at 1MB on
some SoCs", handle_crc32_cmd). So every sector past the first MiB was
scanned as a copy of one inside it, and empty sectors were missed.
Both passes now read the chip as CMD_READ does:
flash_read() into scan_buf. NOR sectors larger than scan_buf (128 KiB)
are read in chunks, with the CRC chained across them. NAND keeps its
one read per block.
sector, a second read through the same path. Before, it was a second
pass over the same wrapped window.
On the board (agent built from this commit, flash = OpenIPC 16M image):
before, 256 GOOD and 16 distinct CRCs; now 133 GOOD and 123 EMPTY. The
123 EMPTY are the all-0xFF sectors FLASH_STREAM skips for this image.
There are 93 distinct CRCs, and every non-empty sector's scan CRC equals
CMD_CRC32 for it. The scan takes 20 s (27 s before).
make -C agent test passes. All ten SoC builds compile with the same
warnings as master (compared line by line on hi3536dv100/FMC100 and
hi3520dv200/HISFC350).