Skip to content
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

Update flash size #797

Merged
merged 4 commits into from
Mar 4, 2025
Merged

Update flash size #797

merged 4 commits into from
Mar 4, 2025

Conversation

SergioGasquez
Copy link
Member

With this PR we will update the flash size in the following order:

  1. Provided by --flash-size arg
  2. Config file
  3. Detect if we can (if we are flashing we can try to detect, but save-image cant)
  4. Used the default flash size: 4Mb

We have to pass flasher arround which is not ideal... I initially though of cfef334 but that results in lots of duplicated code.

Tests

I generated an std template: cargo generate esp-rs/esp-idf-template cargo for S3 and with the default configurations. Updated the code to:

// Define a large static array (roughly 1MB)
// 1MB = 1 * 1024 * 1024 bytes
static LARGE_ARRAY: [u8; 1 * 1024 * 1024] = [0; 1 * 1024 * 1024];

fn main() {
    // It is necessary to call this function once. Otherwise some patches to the runtime
    // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
    esp_idf_svc::sys::link_patches();

    // Bind the log crate to the ESP Logging facilities
    esp_idf_svc::log::EspLogger::initialize_default();

    // Access the array to prevent it from being optimized away
    log::info!("Hello, world! Array size: {} bytes", LARGE_ARRAY.len());
    log::info!("First byte: {}", LARGE_ARRAY[0]);
}

When building this, we get the following elf:

❯ eza -l target/xtensa-esp32s3-espidf/release/app-size
.rwxr-xr-x 1.8M sergio 28 Feb 15:41 target/xtensa-esp32s3-espidf/release/app-size

When triying to flash it with [email protected] (installed a few days ago):

❯ espflash flash target/xtensa-esp32s3-espidf/release/app-size
[2025-02-28T14:52:13Z INFO ] Serial port: '/dev/ttyUSB1'
[2025-02-28T14:52:13Z INFO ] Connecting...
[2025-02-28T14:52:13Z INFO ] Using flash stub
[2025-02-28T14:52:14Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type:         esp32s3 (revision v0.1)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       60:55:f9:f5:20:d4
Error: espflash::image_too_big (link)

  × Supplied ELF image of 1455472B is too big, and doesn't fit configured app partition of 1048576B
  help: Reduce the size of the binary or increase the size of the app partition.

When using this patch:

❯ cargo r -r --bin espflash -- flash /home/sergio/Documents/Espressif/tests/app-size/target/xtensa-esp32s3-espidf/release/app-size
    Finished `release` profile [optimized] target(s) in 0.12s
     Running `target/release/espflash flash /home/sergio/Documents/Espressif/tests/app-size/target/xtensa-esp32s3-espidf/release/app-size`
[2025-02-28T14:53:51Z INFO ] Serial port: '/dev/ttyUSB1'
[2025-02-28T14:53:51Z INFO ] Connecting...
[2025-02-28T14:53:51Z INFO ] Using flash stub
[2025-02-28T14:53:52Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type:         esp32s3 (revision v0.1)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       60:55:f9:f5:20:d4
App/part. size:    1,455,472/8,323,072 bytes, 17.49%
[00:00:00] [========================================]      14/14      0x0                                                                                                                                                                                   
[00:00:00] [========================================]       1/1       0x8000                                                                                                                                                                                
[00:00:15] [========================================]     235/235     0x10000                                                                                                                                                                               [2025-02-28T14:54:18Z INFO ] Flashing has completed!

espflash on  feat/flash-size [$] via 🦀 v1.87.0-nightly took 27s 

@jessebraham
Copy link
Member

Thanks for the PR! Also don't love that we have to pass around Flasher here, will try to see if I can think of any other way to accomplish this.

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@jessebraham jessebraham added this pull request to the merge queue Mar 4, 2025
Merged via the queue into esp-rs:main with commit f86b149 Mar 4, 2025
24 checks passed
@SergioGasquez SergioGasquez deleted the feat/flash-size branch March 4, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants