Skip to content

Add secure padding for save-image #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

thetek42
Copy link
Contributor

@thetek42 thetek42 commented Jun 5, 2025

This PR adds support for "secure padding", just like esptool.py's --secure-pad-v2 option, as discussed in #713.

In contrast to main...SergioGasquez:espflash:feat/secure-padding, this also adds an additional padding section, just like esptool.py. Thus, using esptool.py and espflash save-image with --secure-pad-v2 will now result in exactly the same output.

Also, it makes the connection::reset crate public again, since it is required to call the Flasher::connect method when espflash is used as a library. It was previously made pub(crate) in be1ff81.

@SergioGasquez
Copy link
Member

Hi! Here are my testing results.

# Generate the project
> esp-generate --chip=esp32s3 secure-pad (do not select any features)
# Generate the binaries
> esptools tool --chip esp32s3 elf2image --version 2 --secure-pad-v2 --output esptool.bin target/xtensa-esp32s3-none-elf/release/secure-pad
> espflash save-image --secure-pad-v2 --chip esp32s3 target/xtensa-esp32s3-none-elf/release/secure-pad espflash.bin
# Compare binaries
> esptools tool --chip esp32s3 image_info esptool.bin
...
7 segments

Segment 1: len 0x00350 load 0x3c000020 file_offs 0x00000018 [DROM]
Segment 2: len 0x00258 load 0x3fc89168 file_offs 0x00000370 [BYTE_ACCESSIBLE,MEM_INTERNAL,DRAM]
Segment 3: len 0x00400 load 0x40378000 file_offs 0x000005d0 [MEM_INTERNAL,IRAM]
Segment 4: len 0x00d68 load 0x40378400 file_offs 0x000009d8 [MEM_INTERNAL,IRAM]
Segment 5: len 0x0e8c8 load 0x00000000 file_offs 0x00001748 [PADDING]
Segment 6: len 0x013e8 load 0x42010020 file_offs 0x00010018 [IROM]
Segment 7: len 0x0ebc0 load 0x00000000 file_offs 0x00011408 [PADDING]
Checksum: 0e (valid)
Validation Hash: 894bf1f00093738fa4da353d4483d6d14969b0f657ccd6f4e6fff5f4d3342848 (valid)
Status Ok(ExitStatus(unix_wait_status(0)))
> esptools tool --chip esp32s3 image_info espflash.bin
...
6 segments

Segment 1: len 0x00350 load 0x3c000020 file_offs 0x00000018 [DROM]
Segment 2: len 0x00258 load 0x3fc89168 file_offs 0x00000370 [BYTE_ACCESSIBLE,MEM_INTERNAL,DRAM]
Segment 3: len 0x01168 load 0x40378000 file_offs 0x000005d0 [MEM_INTERNAL,IRAM]
Segment 4: len 0x0e8d0 load 0x00000000 file_offs 0x00001740 [PADDING]
Segment 5: len 0x013e8 load 0x42010020 file_offs 0x00010018 [IROM]
Segment 6: len 0x0ebc0 load 0x00000000 file_offs 0x00011408 [PADDING]
Checksum: 0e (valid)
Validation Hash: 865e0745cc17b5ea9c8e7e2e499e5f4cc6a774c490c286013aed72fa6ec11ebc (valid)
Status Ok(ExitStatus(unix_wait_status(0)))

cc @ivmarkov

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