Skip to content

Add esp32c3-qemu exec elf support#441

Open
YinhuaChen-vivo wants to merge 6 commits into
vivoblueos:mainfrom
YinhuaChen-vivo:add-esp32c3-exec-elf-support
Open

Add esp32c3-qemu exec elf support#441
YinhuaChen-vivo wants to merge 6 commits into
vivoblueos:mainfrom
YinhuaChen-vivo:add-esp32c3-exec-elf-support

Conversation

@YinhuaChen-vivo

Copy link
Copy Markdown
Contributor

Summary

Add fixed-address RV32 ET_EXEC loading support for ESP32-C3 while keeping the
existing position-independent ET_DYN flow intact.

The loader now selects the loading strategy from both the ELF type and the
mapper mode:

                         +------------------------------+
                         |          load_elf()          |
                         +---------------+--------------+
                                         |
                                  parse ELF header
                                         |
                     +-------------------+-------------------+
                     |                                       |
              ET_DYN + allocated                    ET_EXEC + fixed
                     |                                       |
          allocate backing storage                validate RV32 ELF
          copy and zero segments                   validate ranges/flags
          apply RELATIVE relocations               copy and zero segments
          translate entry point                    fence.i and use vaddr
                     |                                       |
                     +-------------------+-------------------+
                                         |
                                  executable entry

            Any ELF/mapper mismatch or failed validation is rejected.

What changed

  • Add a fixed mapping mode to MemoryMapper, backed by caller-authorized
    MemoryRegions and explicit read/write/execute permissions.
  • Support static, fixed-address, 32-bit little-endian RISC-V ET_EXEC images.
    Loadable segments are preflighted before any memory is written, including
    input bounds, address overflow, alignment, permissions, and executable-entry
    checks.
  • Reject dynamic segments and runtime relocations for ET_EXEC, and execute
    fence.i after installing code on RISC-V so the instruction stream observes
    the newly loaded image.
  • Harden the existing ET_DYN path with checked ELF integer conversions and
    range arithmetic, explicit BSS zeroing, load-bias-aware relative
    relocations, aligned writes, and rejection of unsupported dynamic
    relocations.
  • Add a statically linked RV32 test application placed in ESP32-C3 RTC fast
    memory at 0x50000000. The fixture verifies initialized data, zeroed BSS,
    and execution through the ELF entry point.
  • Select the ESP32 QEMU runner for boards using the ESP32 loader while
    preserving the existing generic QEMU path and PIC ELF tests for other
    targets.

Validation

The ESP32-C3 integration suite covers:

  • loading and executing the fixed-address ELF successfully;
  • initialized-data copying and BSS zeroing;
  • rejecting an ET_EXEC image with an allocated mapper;
  • rejecting a segment outside the authorized region before modifying memory;
  • rejecting a non-executable destination region; and
  • rejecting an entry point outside an executable load segment.

Existing non-ESP32 integration tests continue to exercise the PIC/ET_DYN
path and malformed ELF inputs.

Limitations

  • Fixed-address execution currently accepts only 32-bit little-endian RISC-V
    ET_EXEC images.
  • ET_EXEC images must be fully static: PT_DYNAMIC and runtime relocations
    are not supported.
  • The caller remains responsible for reserving and mapping every advertised
    MemoryRegion for its full lifetime and for avoiding conflicting accesses.

loader: dispatch ELF loading by image type

loader: validate segments and dynamic relocations

loader: validate ELF widths and relocation alignment

loader: correct 32-bit ELF width regression

loader: add fixed-address RV32 EXEC fixture

loader: run integration test on ESP32 QEMU

loader: support fixed-address RISC-V EXEC images

add print in loader/tests/inputs/exec_app/src/main.rs
@YinhuaChen-vivo YinhuaChen-vivo changed the title Add esp32c3 exec elf support Add esp32c3-qemu exec elf support Jul 27, 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.

1 participant