9 releases

0.3.2 Jan 15, 2025
0.3.1 Jan 15, 2025
0.2.0 Jan 2, 2025
0.1.4 Nov 15, 2024
0.1.1 Jul 22, 2024

#219 in Hardware support

Download history 2/week @ 2024-10-29 8/week @ 2024-11-05 112/week @ 2024-11-12 16/week @ 2024-11-19 4/week @ 2024-12-10 5/week @ 2024-12-17 137/week @ 2024-12-31 133/week @ 2025-01-07 255/week @ 2025-01-14 16/week @ 2025-01-21 3/week @ 2025-01-28 66/week @ 2025-02-04

381 downloads per month

MIT license

41KB
856 lines

esp-hal-ota

OTA for esp-hal (no-std).

crates.io MIT license

Limitations

I cannot test if it works properly on esp32s2,esp32c2,esp32c6 and esp32h2. But esp32s3, esp32c3 and esp32 are working perfectly fine.

Features

  • Obviously OTA updates
  • Dynamic partitions reading (so no macros, no reading from partitions.csv) - fully automatic
  • Checking currently booted partition (using some pointer magic from ESP-IDF)
  • CRC32 verification

Getting started

  • Create partitions.csv file in project root (copy partitions.csv.template file)
  • In your project edit ./.cargo/config.toml file and append -T ./partitions.csv to the runner attribute
  • Optionally append --erase-parts otadata to ./cargo/config.toml to fix some ota issues
[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor -T ./partitions.csv --erase-parts otadata"

Example

To see real-world example look at ./examples and ./simple-ota-server dirs.

let flash_size = 1234; // get it from OTA server
let target_crc = 65436743; // get it from OTA server

let mut ota = Ota::new(FlashStorage::new()).unwrap();
ota.ota_begin(flash_size, target_crc);

let mut buf = [0; 4096];
loop {
    let n = read_next_chunk(&mut buf);
    if n == 0 {
        break;
    }

    let res = ota.ota_write_chunk(&buf[..n]);
    if res == Ok(true) { // end of flash
        if ota.ota_flush(true, true).is_ok() { // true if you want to verify crc reading flash, and true if you want rollbacks
            esp_hal::reset::software_reset();
        }
    }

    let progress = (ota.get_ota_progress() * 100) as u8;
    log::info!("progress: {}%", progress);
}

Running example

  • You can compile your .bin file using esp-flash
espflash save-image --chip esp32c3 ./target/riscv32imc-unknown-none-elf/debug/esp-hal-ota-example ../simple-ota-server/firmware.bin

This will generate .bin file from build file for chip.

Todo

  • Fully working library
  • Simple example
  • Better errors
  • Other esp32's (like esp32c3, esp32s2, etc..)
  • Rollbacks

Resources

Dependencies

~0–11MB
~215K SLoC