Skip to content

Add ESP32-C6 on-chip flash driver and C3/C6 flash layout symmetry - #470

Open
jinwjinl wants to merge 2 commits into
vivoblueos:mainfrom
jinwjinl:add-C6-flash
Open

jinwjinl wants to merge 2 commits into
vivoblueos:mainfrom
jinwjinl:add-C6-flash

Conversation

@jinwjinl

@jinwjinl jinwjinl commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

This branch adds ESP32-C6 on-chip Flash access and executable XIP mapping support, mirroring the existing C3 implementation. A reserved Flash region is exposed as /dev/esp32-flash0, allowing userspace loaders to erase, read, write, map, and unmap executable images without embedding ELF or image-management logic in the kernel. The C3 Flash modules are also renamed to an esp32c3_ prefix so the two SoCs share a symmetric naming scheme.

Main changes

Internal Flash driver

  • Adds an ESP32-C6 internal Flash driver based on the ROM spiflash_legacy SPI Flash API (the same chip-less path as C3, avoiding the higher-level esp_flash_t API which NULL-dereferences default_chip).
  • Supports bounded read, aligned programming, and sector erase operations.
  • Splits unaligned writes into page-sized operations and preserves unaffected bytes.
  • Serializes Flash operations to prevent concurrent access.
  • Validates alignment, capacity, protected ranges, and integer overflow.

Device registration

Registers the reserved internal Flash region as the misc device:

  • /dev/esp32-flash0
  • Provides standard device operations for reading, writing, querying capacity, and synchronization.

Adds versioned ioctl requests for:

  • erasing a Flash range;
  • mapping an executable image;
  • unmapping an executable image;
  • querying the safe DRAM boundary for loadable applications.

XIP mapping

  • Adds ESP32-C6 Flash MMU mapping support.
  • Maps the reserved physical Flash region into the shared IROM/DROM Flash window via CACHE_MSPI_MMU_SET direct writes (C6 maps code and rodata into a single 0x42000000 window, unlike C3 which has separate 0x3C000000 DROM and 0x42000000 IROM windows).
  • Handles 64-KiB MMU page alignment and multi-page mappings.
  • Invalidates the instruction cache and executes fence.i after mapping changes.
  • Tracks the active mapping and rejects concurrent or stale mapping operations.

Configuration

  • Adds the ESP32_INTERNAL_FLASH Kconfig option (default y) to gate the C6 on-chip Flash subsystem.

  • The loadable region constants are defined in the board module:

    • Physical offset: 0x00200000
    • Size: 0x00300000
    • End: 0x00500000

Board integration

  • esp32c6_devkitc_1/link.x keeps the HP RAM EXTRA_RAM 64 KiB split (RAM 0x40800000 LENGTH 0x5E610 + top EXTRA_RAM 0x10000) to host loadable-app RW data; restores the upstream mesh_sta_auth_expire_time EXTERN.
  • Initializes the internal Flash driver during ESP32-C6 boot.
  • Registers /dev/esp32-flash0 before VFS initialization.

C3 naming symmetry

  • Renames C3 Flash modules to match the C6 scheme:

    • esp32_rom.rsesp32c3_rom.rs
    • internal_flash.rsinternal_flash_c3.rs
    • flash_mmap.rsflash_mmap_c3.rs
    • esp32_flash.rsesp32c3_flash.rs
    • All use super::esp32_rom / flash_mmap:: references updated; the C3 loadable_region_reserves_xip_window test is kept.
  • Unifies the all(soc_esp32cN, esp32_internal_flash) gate across C3 and C6 module declarations; adds ESP32_INTERNAL_FLASH (default y) to the seeed C3 board and widens its on-chip Flash init gate from soc_esp32c3 to all(soc_esp32c3, esp32_internal_flash).

@jinwjinl

jinwjinl commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

build_prs

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Add the C6 on-chip flash subsystem (ROM API + MMU map) mirroring the
existing C3 one, and rename the C3 flash modules to an esp32c3_ prefix
so the two SoCs share a symmetric naming scheme.

C6 on-chip flash (new):
- esp32c6_rom.rs: ROM spiflash legacy API bindings (erase/read/write).
- flash_mmap_c6.rs: C6 MMU cache mapping (rom_mmu_map/unmap).
- internal_flash_c6.rs: ROM unlock + capacity probe + esp32-flash0
  block device registration.
- esp32c6_flash.rs: loadable-image Misc device with map_exec/map_drom
  entry points for XIP load of external ELF.

C3 rename (esp32_* -> esp32c3_*):
- esp32_rom.rs -> esp32c3_rom.rs
- internal_flash.rs -> internal_flash_c3.rs
- flash_mmap.rs -> flash_mmap_c3.rs
- esp32_flash.rs -> esp32c3_flash.rs
- All `use super::esp32_rom` / `flash_mmap::` references updated; the
  C3 `loadable_region_reserves_xip_window` test is kept.

drivers/flash/mod.rs:
- C3 module declarations renamed + gated with all(soc_esp32c3,
  esp32_internal_flash).
- C6 module declarations added, gated with all(soc_esp32c6,
  esp32_internal_flash).

Boards:
- esp32c6_devkitc_1: add ESP32_INTERNAL_FLASH Kconfig, LOADABLE_REGION
  consts (base 0x20_0000 / size 0x30_0000), and flash init in init();
  link.x keeps the EXTRA_RAM 64 KiB split for loadable-app RW data and
  restores the mesh EXTERN kept by upstream.
- seeed_xiao_esp32c3: add ESP32_INTERNAL_FLASH (default y) and widen
  the on-chip flash init gate to all(soc_esp32c3, esp32_internal_flash).

Scope: on-chip flash only. No LCD/touch/net/NOR-spi-flash changes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@jinwjinl

jinwjinl commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

build_prs

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

❌ Job failed. Failed jobs: check_license (failure), build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34338887822.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34341004174.

@jinwjinl

jinwjinl commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

build_prs

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34342754816.

flash_mmap_c6.rs imports DROM_VADDR_BASE/DROM_VADDR_END/IROM_VADDR_BASE/
FLASH_MMU_PAGE_SIZE from crate::boards, but the C6 board only defined
the LOADABLE_REGION_* constants, so agent_loop failed to compile.

C6 splits the flash-cache window into separate I-bus (0x4200_0000) and
D-bus (0x4280_0000) halves, unlike C3's DROM at 0x3C00_0000. Page size
is 64 KB, matching Cache_MMU_Set's psize argument in esp32c6_rom.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34744288410.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34744795740.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34745383386.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs #470 vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34747147999.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs #470 vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34750380898.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs #470 vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/34818756996.

@han-jiang277

Copy link
Copy Markdown
Contributor

build_prs #470 vivoblueos/build#81

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

✅ All jobs completed successfully, see https://github.com/vivoblueos/kernel/actions/runs/34852448229.

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