README.md (2840B)
1 # esp-hal-ota 2 OTA for esp-hal (no-std). 3 4 [](https://crates.io/crates/esp-hal-ota) 5 []() 6 7 ## Limitations 8 I cannot test if it works properly on esp32s2,esp32c2,esp32c6 and esp32h2. 9 But esp32s3, esp32c3 and esp32 are working perfectly fine. 10 11 ## Features 12 - Obviously OTA updates 13 - Dynamic partitions reading (so no macros, no reading from partitions.csv) - fully automatic 14 - Checking currently booted partition (using some pointer magic from ESP-IDF) 15 - CRC32 verification 16 17 ## Getting started 18 - Create `partitions.csv` file in project root (copy `partitions.csv.template` file) 19 - In your project edit `./.cargo/config.toml` file and append `--partition-table ./partitions.csv` to the `runner` attribute 20 - Optionally append `--erase-parts otadata` to `./cargo/config.toml` to fix some ota issues 21 22 ```toml 23 [target.xtensa-esp32s3-none-elf] 24 runner = "espflash flash --monitor --partition-table ./partitions.csv --erase-parts otadata" 25 ``` 26 27 ## Example 28 To see real-world example look at `./examples` and `./simple-ota-server` dirs. 29 30 ```rust 31 let flash_size = 1234; // get it from OTA server 32 let target_crc = 65436743; // get it from OTA server 33 34 let mut ota = Ota::new(FlashStorage::new()).unwrap(); 35 ota.ota_begin(flash_size, target_crc); 36 37 let mut buf = [0; 4096]; 38 loop { 39 let n = read_next_chunk(&mut buf); 40 if n == 0 { 41 break; 42 } 43 44 let res = ota.ota_write_chunk(&buf[..n]); 45 if res == Ok(true) { // end of flash 46 if ota.ota_flush(true, true).is_ok() { // true if you want to verify crc reading flash, and true if you want rollbacks 47 esp_hal::reset::software_reset(); 48 } 49 } 50 51 let progress = (ota.get_ota_progress() * 100) as u8; 52 log::info!("progress: {}%", progress); 53 } 54 ``` 55 56 ### Running example 57 - You can compile your .bin file using esp-flash 58 ```bash 59 espflash save-image --chip esp32c3 ./target/riscv32imc-unknown-none-elf/debug/esp-hal-ota-example ../simple-ota-server/firmware.bin 60 ``` 61 62 This will generate .bin file from build file for chip. 63 64 ## Todo 65 - [x] Fully working library 66 - [x] Simple example 67 - [x] Better errors 68 - [x] Other esp32's (like esp32c3, esp32s2, etc..) 69 - [x] Rollbacks 70 71 ## Resources 72 - https://github.com/esp-rs/espflash (this led me to esp-idf-part) 73 - https://github.com/esp-rs/esp-idf-part 74 - https://github.com/espressif/esp-idf/blob/master/docs/en/api-reference/system/ota.rst (especially Python API) 75 - https://github.com/python/cpython/blob/main/Modules/binascii.c (internal_crc32) 76 - https://github.com/espressif/esp-idf/blob/master/components/app_update/esp_ota_ops.c#L552 (esp get current partition (paddr)) 77 - https://github.com/bjoernQ/esp32c3-ota-experiment (i've only seen this after first experiments, so haven't looked at it yet)