eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9d823c9f7f1db78123c9216e9658d21b18bb8b66
parent 07904d072b87f1ba098c4db871b34b5cff081c77
Author: filipton <filipton12@gmail.com>
Date:   Mon, 22 Jul 2024 20:32:56 +0200

feat: log feature to enable inner logging

Diffstat:
MCargo.lock | 2+-
MCargo.toml | 8++++++--
MREADME.md | 12+++++++++++-
Msrc/lib.rs | 16+++++++++++++---
4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" [[package]] name = "esp-hal-ota" -version = "0.1.0" +version = "0.1.1" dependencies = [ "embedded-storage", "log", diff --git a/Cargo.toml b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "esp-hal-ota" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MIT" description = "OTA library for esp-hal" @@ -9,4 +9,8 @@ description = "OTA library for esp-hal" [dependencies] embedded-storage = "0.3.1" -log = "0.4.22" +log = { version = "0.4.22", optional = true } + +[features] +default = ["log"] +log = ["dep:log"] diff --git a/README.md b/README.md @@ -1,7 +1,7 @@ # esp-hal-ota OTA for esp-hal (no-std). -[![crates.io](https://img.shields.io/crates/v/mdns.svg)](https://crates.io/crates/esp-hal-ota) +[![crates.io](https://img.shields.io/crates/v/esp-hal-ota.svg)](https://crates.io/crates/esp-hal-ota) [![MIT license](https://img.shields.io/github/license/mashape/apistatus.svg)]() ## Limitations @@ -13,6 +13,16 @@ For now only works on esp32s3 (esp32c3 in the near future). - 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 + +```toml +[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. diff --git a/src/lib.rs b/src/lib.rs @@ -63,7 +63,9 @@ where pub fn new(mut flash: S) -> Result<Self> { let pinfo = Self::read_partitions(&mut flash)?; if pinfo.ota_partitions_count < 2 { + #[cfg(feature = "log")] log::error!("Not enough OTA partitions! (>= 2)"); + return Err(OtaError::NotEnoughPartitions); } @@ -100,7 +102,9 @@ where /// Returns ota progress in f32 (0..1) pub fn get_ota_progress(&self) -> f32 { if self.progress.is_none() { + #[cfg(feature = "log")] log::warn!("[OTA] Cannot get ota progress! Seems like update wasn't started yet."); + return 0.0; } @@ -126,6 +130,7 @@ where .write(progress.flash_offset, &chunk[..write_size]) .map_err(|_| OtaError::FlashRWError)?; + #[cfg(feature = "log")] log::debug!( "[OTA] Wrote {} bytes to ota partition at 0x{:x}", write_size, @@ -143,7 +148,9 @@ where pub fn ota_flush(&mut self, verify: bool) -> Result<()> { if verify { if !self.ota_verify()? { + #[cfg(feature = "log")] log::error!("[OTA] Verify failed! Not flushing..."); + return Err(OtaError::OtaVerifyError); } } @@ -154,9 +161,12 @@ where .ok_or_else(|| OtaError::OtaNotStarted)?; if progress.target_crc != progress.last_crc { - log::warn!("[OTA] Calculated crc: {:?}", progress.last_crc); - log::warn!("[OTA] Target crc: {:?}", progress.target_crc); - log::error!("[OTA] Crc check failed! Cant finish ota update..."); + #[cfg(feature = "log")] + { + log::warn!("[OTA] Calculated crc: {:?}", progress.last_crc); + log::warn!("[OTA] Target crc: {:?}", progress.target_crc); + log::error!("[OTA] Crc check failed! Cant finish ota update..."); + } return Err(OtaError::WrongCRC); }