espemu: eFuses, flash encryption, esp32c5, and a working hard reset (CII-251) - #431
Open
Harshal5 wants to merge 3 commits into
Open
espemu: eFuses, flash encryption, esp32c5, and a working hard reset (CII-251)#431Harshal5 wants to merge 3 commits into
Harshal5 wants to merge 3 commits into
Conversation
The qemu service can hand a test an eFuse image, burn eFuses into it and boot an encrypted image; the esp-emu service could do none of that, so the ESP-IDF tests that need a device state, rather than a peripheral, had nothing to run against. --espemu-efuse-path gives the emulator an eFuse image, creating a blank one when the file does not exist. execute_efuse_command() runs espefuse against a second instance started in download mode with its UART on a socket, since the running one is booted into the firmware and a socket carries no reset lines. --encrypt and --keyfile encrypt the merged image the same way the qemu service does, with the current espsecure command name.
esp-emu has supported `--chip esp32c5` for a while, but the service rejected
the target before launching it:
ValueError: esp-emu does not support target 'esp32c5'.
Supported targets: esp32c3, esp32c6, esp32h2, esp32p4, esp32s31
so every esp32c5 app was unrunnable under `--embedded-services idf,espemu`.
Nothing else in the service is target specific — the flash image comes from
the app's own flash arguments — so the target list was the only gap.
ESP-IDF tests reach the chip through two channels: the console stream
(`dut.expect`) and a control channel (`dut.serial`) that resets it, erases
flash and burns eFuses. `EspEmuDut` extends the plain `Dut`, so `dut.serial`
did not exist and 48 cases in an ESP-IDF sweep died at setup with
AttributeError: 'EspEmuDutWithIdfUnityDutMixin' object has no attribute 'serial'
40% of them only wanted a reset. esp-emu now serves a control channel, so
`hard_reset()` sends `reset` over it: the emulator process keeps running, so
the dut's stream, expect history and log all continue across the reset, which
relaunching the process would break.
The service asks `--help` whether the binary has the channel before passing
`--control-tcp`, since an older esp-emu exits on an unknown flag. The
operations that still need the emulator in download mode raise with the name
of what was wanted, so a test reports the operation it needed rather than a
missing attribute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The qemu service can give a test an eFuse image, burn eFuses into it and boot an encrypted image. The esp-emu service could do none of that, and it had no
dut.serialat all, so ESP-IDF tests that operate on device state had nothing to run against.eFuses
--espemu-efuse-pathgives the emulator an eFuse image, creating a blank QEMU-compatible one when the file does not exist.execute_efuse_command()runs espefuse against a second emulator instance started in download mode with its UART on a socket. A second instance is needed because the first one is booted into the firmware, and pyserial'ssocket://handler ignores modem control lines, so esptool cannot reset it into download mode.Flash encryption
--encryptand--keyfileencrypt the merged image the way the qemu service does, with one difference: the command isespsecure encrypt-flash-data --aes-xts. Every target the emulator supports encrypts flash with XTS-AESesp32c5
esp-emu has accepted
--chip esp32c5for a while, but the service rejected the target before launching it, so every esp32c5 app was unrunnable under--embedded-services idf,espemu. Nothing else in the service is target specific — the flash image comes from the app's own flash arguments — so the target list was the only gap.dut.serial.hard_reset()
ESP-IDF tests reach the chip through two channels: the console stream (
dut.expect) and a control channel (dut.serial) that resets it, erases flash and burns eFuses. esp-emu now serves a control channel, sohard_reset()sendsresetover it. The emulator process keeps running, so the dut's output stream, its expect history and its log all continue across the reset; relaunching the process would break all three.The service checks
esp-emu --helpfor--control-tcpbefore passing the flag, because an older binary exits on an unknown one. The operations that still need download mode raiseNotImplementedErrornaming the operation that was wanted.Validation
Run against ESP-IDF master with
--embedded-services idf,espemu:esp_systemandesp_hw_supportcases as the other targets.esp_driver_uart'stest_uart_single_dev, which used to fail at setup ondut.serial, now resets the chip six times and runs through to its test content.Dependency
hard_reset()needs an esp-emu build with--control-tcp, which no release carries yet. Without it the service behaves as it does today anddut.serial.hard_reset()raises with an explanation, so this can merge ahead of the emulator change.Checklist
Before submitting a Pull Request, please ensure the following: