From f208a5af5e52d9070880d0a62a4d356c02b649d1 Mon Sep 17 00:00:00 2001 From: decentclock Date: Sat, 24 Sep 2022 12:26:31 -0400 Subject: [PATCH 1/8] propagate errors to user in handle_control_response --- parser/src/control.rs | 5 ++--- sphinx-key/src/core/events.rs | 34 ++++++++++++++++++++-------------- tester/Cargo.toml | 3 ++- tester/src/main.rs | 10 ++++++---- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/parser/src/control.rs b/parser/src/control.rs index 31e2c9f..7147757 100644 --- a/parser/src/control.rs +++ b/parser/src/control.rs @@ -56,7 +56,7 @@ impl Controller { Ok(rmp_serde::from_slice(input)?) } // return the OG message for further processing - pub fn handle(&mut self, input: &[u8]) -> anyhow::Result<(Vec, ControlMessage)> { + pub fn handle(&mut self, input: &[u8]) -> anyhow::Result<(ControlMessage, ControlResponse)> { let msg_nonce = self.parse_msg_no_nonce(input)?; let msg = msg_nonce.0; // nonce must be higher each time @@ -110,8 +110,7 @@ impl Controller { ControlResponse::OtaConfirm(params) } }; - let response = self.build_response(res)?; - Ok((response, msg)) + Ok((msg, res)) } } diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index ddc8d3a..4b16e64 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -111,7 +111,9 @@ pub fn make_event_loop( Event::Control(ref msg_bytes) => { log::info!("GOT A CONTROL MSG"); let cres = ctrlr.handle(msg_bytes); - if let Some(res_data) = handle_control_response(&root_handler, cres, network) { + if let Some(res) = handle_control_response(&root_handler, cres, network) { + let res_data = + rmp_serde::to_vec(&res).expect("could not publish control response"); mqtt.publish(topics::CONTROL_RETURN, QOS, false, &res_data) .expect("could not publish control response"); } @@ -124,43 +126,47 @@ pub fn make_event_loop( fn handle_control_response( root_handler: &RootHandler, - cres: anyhow::Result<(Vec, ControlMessage)>, + cres: anyhow::Result<(ControlMessage, ControlResponse)>, network: Network, -) -> Option> { +) -> Option { match cres { - Ok((mut response, parsed_msg)) => { + Ok((control_msg, mut control_res)) => { // the following msg types require other actions besides Flash persistence - match parsed_msg { + match control_msg { ControlMessage::UpdatePolicy(new_policy) => { if let Err(e) = sphinx_key_signer::set_policy(&root_handler, network, new_policy) { log::error!("set policy failed {:?}", e); + control_res = ControlResponse::Error(format!("set policy failed {:?}", e)) } } ControlMessage::UpdateAllowlist(al) => { if let Err(e) = sphinx_key_signer::set_allowlist(&root_handler, &al) { log::error!("set allowlist failed {:?}", e); + control_res = + ControlResponse::Error(format!("set allowlist failed {:?}", e)) } } // overwrite the real Allowlist response, loaded from Node ControlMessage::QueryAllowlist => { - if let Ok(al) = sphinx_key_signer::get_allowlist(&root_handler) { - response = rmp_serde::to_vec(&ControlResponse::AllowlistCurrent(al)) - .expect("couldnt build ControlResponse::AllowlistCurrent"); - } else { - log::error!("read allowlist failed"); + match sphinx_key_signer::get_allowlist(&root_handler) { + Ok(al) => control_res = ControlResponse::AllowlistCurrent(al), + Err(e) => { + log::error!("read allowlist failed {:?}", e); + control_res = + ControlResponse::Error(format!("read allowlist failed {:?}", e)) + } } } _ => (), }; - Some(response) + Some(control_res) } Err(e) => { - let response = rmp_serde::to_vec(&ControlResponse::Error(e.to_string())) - .expect("couldnt build ControlResponse::Error"); + let control_res = ControlResponse::Error(e.to_string()); log::warn!("error parsing ctrl msg {:?}", e); - Some(response) + Some(control_res) } } } diff --git a/tester/Cargo.toml b/tester/Cargo.toml index 0db665b..9776d48 100644 --- a/tester/Cargo.toml +++ b/tester/Cargo.toml @@ -25,6 +25,7 @@ serde_json = "1.0" urlencoding = "2.1.0" dotenv = "0.15.0" rocket = "0.5.0-rc.2" +rmp-serde = "1.1.0" [[bin]] name = "config" @@ -36,4 +37,4 @@ path = "src/server.rs" [[bin]] name = "ctrl" -path = "src/ctrl.rs" \ No newline at end of file +path = "src/ctrl.rs" diff --git a/tester/src/main.rs b/tester/src/main.rs index 918efc9..37f75b7 100644 --- a/tester/src/main.rs +++ b/tester/src/main.rs @@ -101,13 +101,14 @@ async fn main() -> Result<(), Box> { } topics::CONTROL => { match ctrlr.handle(&msg_bytes) { - Ok((response, _new_policy)) => { + Ok((_msg, res)) => { + let res_data = rmp_serde::to_vec(&res).expect("could not publish control response"); client .publish( topics::CONTROL_RETURN, QoS::AtMostOnce, false, - response, + res_data, ) .await .expect("could not mqtt publish"); @@ -158,13 +159,14 @@ async fn main() -> Result<(), Box> { } topics::CONTROL => { match ctrlr.handle(&msg_bytes) { - Ok((response, _new_policy)) => { + Ok((_msg, res)) => { + let res_data = rmp_serde::to_vec(&res).expect("could not publish control response"); client .publish( topics::CONTROL_RETURN, QoS::AtMostOnce, false, - response, + res_data, ) .await .expect("could not mqtt publish"); From 79fea3092d643159d3ff182f976fcd40eb7acd8c Mon Sep 17 00:00:00 2001 From: decentclock Date: Fri, 16 Sep 2022 21:47:55 -0400 Subject: [PATCH 2/8] ota: pull update binary from http server, write it to sd card, and factory reset --- Cargo.toml | 6 +-- parser/src/control.rs | 2 +- sphinx-key/Cargo.toml | 2 +- sphinx-key/src/core/events.rs | 13 ++++++ sphinx-key/src/main.rs | 1 + sphinx-key/src/ota.rs | 81 +++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 sphinx-key/src/ota.rs diff --git a/Cargo.toml b/Cargo.toml index ad62d92..2e9e143 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [workspace] members = [ - "signer", "parser", + "signer", "tester", ] exclude = [ - "sphinx-key", - "persister", "broker", + "persister", + "sphinx-key", ] diff --git a/parser/src/control.rs b/parser/src/control.rs index 7147757..016fdbd 100644 --- a/parser/src/control.rs +++ b/parser/src/control.rs @@ -106,7 +106,7 @@ impl Controller { ControlResponse::AllowlistUpdated(na) } ControlMessage::Ota(params) => { - // ... + // same as above comments, actually done in core/events.rs ControlResponse::OtaConfirm(params) } }; diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 5679176..3b7acca 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -25,7 +25,7 @@ esp-idf-sys = { version = "0.31.6", features = ["binstart"] } sphinx-key-signer = { path = "../signer", optional = true } sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git" } embedded-svc = "0.22.1" -esp-idf-svc = "0.42.1" +esp-idf-svc = { version = "0.42.1", features = ["experimental", "alloc"] } esp-idf-hal = "0.38.0" embedded-hal = "=1.0.0-alpha.8" anyhow = {version = "1", features = ["backtrace"]} diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 4b16e64..45cc118 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -1,4 +1,5 @@ use crate::conn::mqtt::QOS; +use crate::ota::update_sphinx_key; use sphinx_key_signer::control::{Config, ControlMessage, ControlResponse, Controller, Policy}; use sphinx_key_signer::lightning_signer::bitcoin::Network; @@ -116,6 +117,9 @@ pub fn make_event_loop( rmp_serde::to_vec(&res).expect("could not publish control response"); mqtt.publish(topics::CONTROL_RETURN, QOS, false, &res_data) .expect("could not publish control response"); + if let ControlResponse::OtaConfirm(_) = res { + unsafe { esp_idf_sys::esp_restart() }; + } } } } @@ -159,6 +163,15 @@ fn handle_control_response( } } } + ControlMessage::Ota(params) => { + if let Err(e) = update_sphinx_key(params.version, params.url.clone()) { + log::error!("OTA update failed {:?}", e.to_string()); + control_res = + ControlResponse::Error(format!("OTA update failed {:?}", e)) + } else { + log::info!("OTA update completed, about to restart the glyph..."); + } + } _ => (), }; Some(control_res) diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index ea11941..1a579ef 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -1,6 +1,7 @@ #![feature(once_cell)] mod conn; mod core; +mod ota; mod periph; use crate::core::control::{controller_from_seed, FlashPersister}; diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs new file mode 100644 index 0000000..9069e32 --- /dev/null +++ b/sphinx-key/src/ota.rs @@ -0,0 +1,81 @@ +use anyhow::{anyhow, Result}; +use embedded_svc::http::client::Client; +use embedded_svc::http::client::Request; +use embedded_svc::http::client::Response; +use embedded_svc::io::Read; +use embedded_svc::ota::Ota; +use esp_idf_svc::http::client::EspHttpClient; +use esp_idf_svc::http::client::EspHttpClientConfiguration; +use esp_idf_svc::http::client::FollowRedirectsPolicy::FollowNone; +use esp_idf_svc::ota::EspOta; +use log::{error, info}; +use std::fs::{remove_file, File}; +use std::io::BufWriter; +use std::io::Write; + +const BUFFER_LEN: usize = 3072; +const UPDATE_BIN_PATH: &str = "/sdcard/update.bin"; + +fn factory_reset() -> Result<()> { + let mut ota = EspOta::new()?; + if ota.is_factory_reset_supported()? { + info!("Factory reset supported, attempting reset..."); + ota.factory_reset()?; + Ok(()) + } else { + error!("FACTORY RESET CURRENTLY NOT SUPPORTED!"); + error!("Only wrote the update binary to the sdcard"); + Err(anyhow!("Factory reset not supported")) + } +} + +fn get_update(version: u64, mut url: String) -> Result<()> { + let configuration = EspHttpClientConfiguration { + buffer_size: Some(BUFFER_LEN), + buffer_size_tx: Some(BUFFER_LEN / 3), + follow_redirects_policy: FollowNone, + use_global_ca_store: true, + crt_bundle_attach: None, + }; + let mut client = EspHttpClient::new(&configuration)?; + url.push_str(&version.to_string()); + let mut response = client.get(&url)?.submit()?; + let mut reader = response.reader(); + + let _ = remove_file(UPDATE_BIN_PATH); + let file = File::create(UPDATE_BIN_PATH)?; + let mut writer = BufWriter::new(file); + + let mut buf = [0_u8; BUFFER_LEN]; + let mut read_tot: usize = 0; + let mut write_tot: usize = 0; + let mut i = 0; + loop { + let r = reader.read(&mut buf)?; + if r == 0 { + break; + } + let w = writer.write(&buf[..r])?; + read_tot += r; + write_tot += w; + i += 1; + if i % 20 == 0 { + info!("Cumulative bytes read: {}", read_tot); + info!("Cumulative bytes written: {}", write_tot); + } + } + info!("TOTAL read: {}", read_tot); + info!("TOTAL written: {}", write_tot); + Ok(()) +} + +pub fn update_sphinx_key(version: u64, url: String) -> Result<()> { + info!("Getting the update..."); + info!("Version: {}", version.to_string()); + info!("URL: {}", url); + get_update(version, url)?; + info!("Update written to sd card, performing factory reset"); + factory_reset()?; + info!("Factory reset completed!"); + Ok(()) +} From f59aa3de5775598513d6cc35aa9e1e7776e2e636 Mon Sep 17 00:00:00 2001 From: decentclock Date: Mon, 19 Sep 2022 11:43:11 -0400 Subject: [PATCH 3/8] factory: init, writes upgrades from sd card to flash and sets up ESP to boot newly written app --- Cargo.toml | 1 + factory/.cargo/config.toml | 34 +++++++++ factory/Cargo.toml | 26 +++++++ factory/README.md | 14 ++++ factory/build.rs | 5 ++ factory/rust-toolchain.toml | 2 + factory/sdkconfig.defaults | 11 +++ factory/src/main.rs | 34 +++++++++ factory/src/ota.rs | 51 +++++++++++++ factory/src/sdcard.rs | 138 ++++++++++++++++++++++++++++++++++++ factory/table.csv | 7 ++ 11 files changed, 323 insertions(+) create mode 100644 factory/.cargo/config.toml create mode 100644 factory/Cargo.toml create mode 100644 factory/README.md create mode 100644 factory/build.rs create mode 100644 factory/rust-toolchain.toml create mode 100644 factory/sdkconfig.defaults create mode 100644 factory/src/main.rs create mode 100644 factory/src/ota.rs create mode 100644 factory/src/sdcard.rs create mode 100644 factory/table.csv diff --git a/Cargo.toml b/Cargo.toml index 2e9e143..9652e99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ exclude = [ "broker", + "factory", "persister", "sphinx-key", ] diff --git a/factory/.cargo/config.toml b/factory/.cargo/config.toml new file mode 100644 index 0000000..33f5399 --- /dev/null +++ b/factory/.cargo/config.toml @@ -0,0 +1,34 @@ +[build] +# Uncomment the relevant target for your chip here (ESP32, ESP32-S2, ESP32-S3 or ESP32-C3) +#target = "xtensa-esp32-espidf" +#target = "xtensa-esp32s2-espidf" +#target = "xtensa-esp32s3-espidf" +target = "riscv32imc-esp-espidf" + +[target.xtensa-esp32-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s2-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s3-espidf] +linker = "ldproxy" + +[target.riscv32imc-esp-espidf] +linker = "ldproxy" + +# Future - necessary for the experimental "native build" of esp-idf-sys with ESP32C3 +# See also https://github.com/ivmarkov/embuild/issues/16 +rustflags = ["-C", "default-linker-libraries"] + +[unstable] + +build-std = ["std", "panic_abort"] +build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation + +[env] +# Note: these variables are not used when using pio builder +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4) +ESP_IDF_VERSION = { value = "release/v4.4" } +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline) +#ESP_IDF_VERSION = { value = "master" } diff --git a/factory/Cargo.toml b/factory/Cargo.toml new file mode 100644 index 0000000..1da361e --- /dev/null +++ b/factory/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "sphinx-key-factory" +version = "0.1.0" +authors = ["decentclock "] +edition = "2021" + +[features] +pio = ["esp-idf-sys/pio"] + +[dependencies] +esp-idf-sys = { version = "0.31.8", features = ["binstart"] } +esp-idf-svc = { version = "0.42.3", features = ["experimental", "alloc"] } +esp-idf-hal = "0.38.1" +embedded-hal = "0.2.7" +embedded-svc = "0.22.1" +anyhow = { version = "1.0.65", features = ["backtrace"] } +rand = "0.8.5" +log = "0.4.17" +bitflags = "1.3.2" + +[build-dependencies] +embuild = "0.29" +anyhow = "1" + +[package.metadata.espflash] +partition_table = "table.csv" diff --git a/factory/README.md b/factory/README.md new file mode 100644 index 0000000..3990a9e --- /dev/null +++ b/factory/README.md @@ -0,0 +1,14 @@ +# Sphinx Key Factory App + +The main function of this app is to write any `update.bin` files from the sd card to the flash of the ESP, and configure the ESP so that on the next boot, it boots the freshly written app. + +## Background Reading + +- Partition Tables: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/partition-tables.html +- Over-the-Air Updates: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/system/ota.html + +## Flashing factory and sphinx-key + +- First flash the factory app here using the usual `espflash` command, but add the `--partition-table` flag and point it to `table.csv` here. See `espflash -h` for more info. +- Then use `esptool.py` to flash the sphinx-key binary at offset `0xc0000`. +- Finally use this command to tell the ESP to boot the sphinx-key binary first ( there is no update to write to the ESP yet, so we don't boot the factory app ): `otatool.py switch_ota_partition --slot 0` diff --git a/factory/build.rs b/factory/build.rs new file mode 100644 index 0000000..4dd5e1f --- /dev/null +++ b/factory/build.rs @@ -0,0 +1,5 @@ +// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641 +fn main() -> anyhow::Result<()> { + embuild::build::CfgArgs::output_propagated("ESP_IDF")?; + embuild::build::LinkArgs::output_propagated("ESP_IDF") +} diff --git a/factory/rust-toolchain.toml b/factory/rust-toolchain.toml new file mode 100644 index 0000000..271800c --- /dev/null +++ b/factory/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" \ No newline at end of file diff --git a/factory/sdkconfig.defaults b/factory/sdkconfig.defaults new file mode 100644 index 0000000..3a2aa72 --- /dev/null +++ b/factory/sdkconfig.defaults @@ -0,0 +1,11 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +CONFIG_ESP_MAIN_TASK_STACK_SIZE=64000 +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y + +# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). +# This allows to use 1 ms granuality for thread sleeps (10 ms by default). +#CONFIG_FREERTOS_HZ=1000 + +# Workaround for https://github.com/espressif/esp-idf/issues/7631 +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n diff --git a/factory/src/main.rs b/factory/src/main.rs new file mode 100644 index 0000000..2a6d7d8 --- /dev/null +++ b/factory/src/main.rs @@ -0,0 +1,34 @@ +mod ota; +mod sdcard; +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use log::{error, info, warn}; +use ota::{run_sdcard_ota_update, set_boot_main_app, UPDATE_BIN_PATH}; +use std::path::Path; +use std::thread; +use std::time::Duration; + +fn main() { + // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, + // or else some patches to the runtime implemented by esp-idf-sys might not link properly. + esp_idf_svc::log::EspLogger::initialize_default(); + esp_idf_sys::link_patches(); + + thread::sleep(Duration::from_secs(10)); + info!("Hello, world! Mounting sd card..."); + sdcard::mount_sd_card(); + info!("SD card mounted! Checking for update..."); + if let Ok(true) = Path::new(UPDATE_BIN_PATH).try_exists() { + info!("Found update.bin file! Launching the update process..."); + while let Err(e) = run_sdcard_ota_update() { + error!("OTA update failed: {}", e.to_string()); + error!("Trying again..."); + thread::sleep(Duration::from_secs(5)); + } + info!("OTA update complete!"); + } else { + warn!("Update file not found! Setting up main app boot..."); + set_boot_main_app(); + } + info!("Restarting ESP, booting the main app..."); + unsafe { esp_idf_sys::esp_restart() }; +} diff --git a/factory/src/ota.rs b/factory/src/ota.rs new file mode 100644 index 0000000..db603fa --- /dev/null +++ b/factory/src/ota.rs @@ -0,0 +1,51 @@ +use anyhow::Result; +use embedded_svc::io::Write; +use embedded_svc::ota::Ota; +use embedded_svc::ota::OtaUpdate; +use esp_idf_svc::ota::EspOta; +use esp_idf_sys::{esp, esp_ota_get_next_update_partition, esp_ota_set_boot_partition}; +use log::info; +use std::fs::File; +use std::io::BufReader; +use std::io::Read; +use std::ptr; + +pub const UPDATE_BIN_PATH: &str = "/sdcard/update.bin"; +const BUFFER_LEN: usize = 1024; + +pub fn run_sdcard_ota_update() -> Result<()> { + let f = File::open(UPDATE_BIN_PATH)?; + let mut reader = BufReader::with_capacity(BUFFER_LEN, f); + + let mut ota = EspOta::new()?; + let mut ota = ota.initiate_update()?; + + let mut buf = [0_u8; BUFFER_LEN]; + let mut read_tot: usize = 0; + let mut write_tot: usize = 0; + let mut i = 0; + loop { + let r = reader.read(&mut buf)?; + if r == 0 { + break; + } + let w = ota.write(&buf[..r])?; + read_tot += r; + write_tot += w; + i += 1; + if i % 20 == 0 { + info!("Cumulative bytes read: {}", read_tot); + info!("Cumulative bytes written: {}", write_tot); + } + } + info!("TOTAL read: {}", read_tot); + info!("TOTAL write: {}", write_tot); + ota.complete()?; + Ok(()) +} + +pub fn set_boot_main_app() { + let partition = unsafe { esp_ota_get_next_update_partition(ptr::null()) }; + esp!(unsafe { esp_ota_set_boot_partition(partition) }) + .expect("Couldn't set next boot partition..."); +} diff --git a/factory/src/sdcard.rs b/factory/src/sdcard.rs new file mode 100644 index 0000000..f242438 --- /dev/null +++ b/factory/src/sdcard.rs @@ -0,0 +1,138 @@ +use bitflags::bitflags; +use esp_idf_sys::c_types::c_char; +use esp_idf_sys::{ + esp, esp_vfs_fat_sdmmc_mount_config_t, esp_vfs_fat_sdspi_mount, gpio_num_t, sdmmc_card_t, + sdmmc_host_t, sdspi_device_config_t, spi_bus_config_t, spi_bus_initialize, spi_host_device_t, + spi_host_device_t_SPI2_HOST, +}; +use std::ptr; +use std::thread; +use std::time::Duration; + +const C_MOUNT_POINT: &'static [u8] = b"/sdcard\0"; + +const SPI_HOST_SLOT: spi_host_device_t = spi_host_device_t_SPI2_HOST; +const SPI_GPIO_MOSI: gpio_num_t = 7; +const SPI_GPIO_CLK: gpio_num_t = 6; +const SPI_GPIO_MISO: gpio_num_t = 2; +const SPI_GPIO_CS: gpio_num_t = 10; + +bitflags! { + struct SDMMCHostFlag: u32 { + /// host supports 1-line SD and MMC protocol + const BIT1 = 1 << 0; + /// host supports 4-line SD and MMC protocol + const BIT4 = 1 << 1; + /// host supports 8-line MMC protocol + const BIT8 = 1 << 2; + /// host supports SPI protocol + const SPI = 1 << 3; + /// host supports DDR mode for SD/MMC + const DDR = 1 << 4; + /// host `deinit` function called with the slot argument + const DEINIT_ARG = 1 << 5; + } +} + +#[allow(dead_code)] +enum SDMMCFreq { + /// SD/MMC Default speed (limited by clock divider) + Default = 20000, + /// SD High speed (limited by clock divider) + HighSPeed = 40000, + /// SD/MMC probing speed + Probing = 400, + /// MMC 52MHz speed + _52M = 52000, + /// MMC 26MHz speed + _26M = 26000, +} + +#[allow(unused)] +pub fn mount_sd_card() { + while let Err(e) = setup() { + println!("Failed to mount sd card. Make sure it is connected, trying again..."); + thread::sleep(Duration::from_secs(5)); + } +} + +fn setup() -> anyhow::Result<()> { + let mount_config = esp_vfs_fat_sdmmc_mount_config_t { + format_if_mount_failed: false, + max_files: 5, + allocation_unit_size: 16 * 1024, + }; + + let mut card: *mut sdmmc_card_t = ptr::null_mut(); + + let bus_cfg = spi_bus_config_t { + __bindgen_anon_1: esp_idf_sys::spi_bus_config_t__bindgen_ty_1 { + mosi_io_num: SPI_GPIO_MOSI, + }, + __bindgen_anon_2: esp_idf_sys::spi_bus_config_t__bindgen_ty_2 { + miso_io_num: SPI_GPIO_MISO, + }, + sclk_io_num: SPI_GPIO_CLK, + __bindgen_anon_3: esp_idf_sys::spi_bus_config_t__bindgen_ty_3 { quadwp_io_num: -1 }, + __bindgen_anon_4: esp_idf_sys::spi_bus_config_t__bindgen_ty_4 { quadhd_io_num: -1 }, + data4_io_num: -1, + data5_io_num: -1, + data6_io_num: -1, + data7_io_num: -1, + max_transfer_sz: 4000, + flags: 0, + intr_flags: 0, + }; + + if let Err(error) = esp!(unsafe { + spi_bus_initialize( + SPI_HOST_SLOT as u32, + &bus_cfg, + esp_idf_sys::spi_common_dma_t_SPI_DMA_CH_AUTO, + ) + }) { + if error.code() != 259 { + return Err(anyhow::Error::new(error)); + } + } + + println!("Initialized SPI BUS!"); + + let slot_config = sdspi_device_config_t { + host_id: SPI_HOST_SLOT, + gpio_cs: SPI_GPIO_CS, + gpio_cd: -1, + gpio_wp: -1, + gpio_int: -1, + }; + + let host = sdmmc_host_t { + flags: (SDMMCHostFlag::SPI | SDMMCHostFlag::DEINIT_ARG).bits, //SDMMC_HOST_FLAG_SPI | SDMMC_HOST_FLAG_DEINIT_ARG, + slot: SPI_HOST_SLOT as i32, + max_freq_khz: SDMMCFreq::Default as i32, //SDMMC_FREQ_DEFAULT, + io_voltage: 3.3f32, + init: Some(esp_idf_sys::sdspi_host_init), + set_bus_width: None, + get_bus_width: None, + set_bus_ddr_mode: None, + set_card_clk: Some(esp_idf_sys::sdspi_host_set_card_clk), + do_transaction: Some(esp_idf_sys::sdspi_host_do_transaction), + __bindgen_anon_1: esp_idf_sys::sdmmc_host_t__bindgen_ty_1 { + deinit_p: Some(esp_idf_sys::sdspi_host_remove_device), + }, + io_int_enable: Some(esp_idf_sys::sdspi_host_io_int_enable), + io_int_wait: Some(esp_idf_sys::sdspi_host_io_int_wait), + command_timeout_ms: 0, + }; + + esp!(unsafe { + esp_vfs_fat_sdspi_mount( + C_MOUNT_POINT.as_ptr() as *const c_char, + &host, + &slot_config, + &mount_config, + &mut card as *mut *mut sdmmc_card_t, + ) + })?; + Ok(()) +} diff --git a/factory/table.csv b/factory/table.csv new file mode 100644 index 0000000..8133218 --- /dev/null +++ b/factory/table.csv @@ -0,0 +1,7 @@ +# ESP-IDF Partition Table +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x4000, +otadata, data, ota, 0xd000, 0x2000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 1200K, +ota_0, app, ota_0, 0x140000, 2800K, From 2a4945f44a0748d48062d89a395ee4371f383a05 Mon Sep 17 00:00:00 2001 From: decentclock Date: Sun, 25 Sep 2022 19:30:18 -0400 Subject: [PATCH 4/8] tester: add ota control message sends to ctrl bin --- parser/src/control.rs | 4 +++- tester/src/ctrl.rs | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/parser/src/control.rs b/parser/src/control.rs index 016fdbd..fdb3965 100644 --- a/parser/src/control.rs +++ b/parser/src/control.rs @@ -2,7 +2,9 @@ use anyhow::Result; use sphinx_auther::nonce; use sphinx_auther::secp256k1::{PublicKey, SecretKey}; use sphinx_auther::token::Token; -pub use sphinx_glyph::types::{Config, ControlMessage, ControlResponse, Interval, Policy}; +pub use sphinx_glyph::types::{ + Config, ControlMessage, ControlResponse, Interval, OtaParams, Policy, +}; use std::sync::{Arc, Mutex}; // u64 is the nonce. Each signature must have a higher nonce diff --git a/tester/src/ctrl.rs b/tester/src/ctrl.rs index 6ddcd74..e7f97f3 100644 --- a/tester/src/ctrl.rs +++ b/tester/src/ctrl.rs @@ -1,6 +1,6 @@ use dotenv::dotenv; use serde::{Deserialize, Serialize}; -use sphinx_key_parser::control::{ControlMessage, Controller}; +use sphinx_key_parser::control::{ControlMessage, Controller, OtaParams}; use sphinx_key_signer::lightning_signer::bitcoin::Network; use std::env; use std::time::Duration; @@ -25,6 +25,15 @@ async fn main() -> anyhow::Result<()> { let seed = hex::decode(seed_string).expect("yo"); let mut ctrl = controller_from_seed(&Network::Regtest, &seed, nonce); + let version_string: String = env::var("VERSION").unwrap_or("0".to_string()); + let version: u64 = version_string.parse::().expect("failed to parse version"); + let ota_url: String = env::var("OTA_URL").unwrap_or("http://192.168.1.10/sphinx-update-".to_string()); + let control_message = ControlMessage::Ota(OtaParams { + version: version, + url: ota_url + }); + + //let msg = ctrl.build_msg(control_message)?; let msg = ctrl.build_msg(ControlMessage::Nonce)?; let msg_hex = hex::encode(&msg); From 85779d5a29383fec869741d0600517614b484268 Mon Sep 17 00:00:00 2001 From: decentclock Date: Sun, 25 Sep 2022 19:45:22 -0400 Subject: [PATCH 5/8] update sphinx-key cargo.lock, add factory cargo.lock --- .gitignore | 1 + factory/Cargo.lock | 1897 +++++++++++++++++++++++++++++++++++++++++ sphinx-key/Cargo.lock | 38 +- 3 files changed, 1922 insertions(+), 14 deletions(-) create mode 100644 factory/Cargo.lock diff --git a/.gitignore b/.gitignore index 0e8fc16..70a78b2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target Cargo.lock !sphinx-key/Cargo.lock +!factory/Cargo.lock .DS_Store notes.md test-flash diff --git a/factory/Cargo.lock b/factory/Cargo.lock new file mode 100644 index 0000000..24612a5 --- /dev/null +++ b/factory/Cargo.lock @@ -0,0 +1,1897 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +dependencies = [ + "backtrace", +] + +[[package]] +name = "atomic-polyfill" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c041a8d9751a520ee19656232a18971f18946a7900f1520ee4400002244dd89" +dependencies = [ + "critical-section", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bindgen" +version = "0.60.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "clap", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + +[[package]] +name = "bumpalo" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "camino" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3abb7553d5b9b8421c6de7cb02606ff15e0c6eea7d8eadd75ef013fd636bec36" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.14", + "serde", + "serde_json", +] + +[[package]] +name = "cargo_toml" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee685beed1fe2ab3cb9eb95d65727413b5e27f2b34014a3ea9c92053f8c230fc" +dependencies = [ + "serde", + "toml", +] + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + +[[package]] +name = "clang-sys" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "3.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +dependencies = [ + "atty", + "bitflags", + "clap_lex", + "indexmap", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "cmake" +version = "0.1.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +dependencies = [ + "cc", +] + +[[package]] +name = "cortex-m" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70858629a458fdfd39f9675c4dc309411f2a3f83bede76988d81bf1a0ecee9e0" +dependencies = [ + "bare-metal 0.2.5", + "bitfield", + "embedded-hal 0.2.7", + "volatile-register", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "critical-section" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95da181745b56d4bd339530ec393508910c909c784e8962d15d722bacf0bcbcd" +dependencies = [ + "bare-metal 1.0.0", + "cfg-if", + "cortex-m", + "riscv", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "once_cell", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "cstr_core" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956" +dependencies = [ + "cty", + "memchr", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "embedded-hal" +version = "1.0.0-alpha.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3babfc7fd332142a0b11aebf592992f211f4e01b6222fb04b03aba1bd80018d" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "embedded-io" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36673b79844ff4ec0e3f00aeca0b2cfff564ff6739ab9801d13f45a8ec6cc1c7" +dependencies = [ + "futures", +] + +[[package]] +name = "embedded-svc" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fb2cc875d8cb13978429beb5af7dea5f7f84d5d41187ff9593b83374d3fe77" +dependencies = [ + "anyhow", + "embedded-io", + "enumset", + "futures", + "heapless", + "log", + "no-std-net", + "num_enum", + "serde", + "serde_json", + "strum 0.23.0", + "strum_macros 0.23.1", +] + +[[package]] +name = "embuild" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1dd6c90e28cfc361281a692320fcd820bcae71d327215e87c7d749bf8ddd26" +dependencies = [ + "anyhow", + "bitflags", + "dirs", + "filetime", + "log", + "serde", + "serde_json", + "shlex", + "strum 0.24.1", + "thiserror", + "toml", + "xmas-elf", +] + +[[package]] +name = "embuild" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ca66d283ba92dc33ce461ba27bb5085a769dd740bad3f66e60e70926b34d05" +dependencies = [ + "anyhow", + "bindgen", + "bitflags", + "cargo_toml", + "cmake", + "dirs", + "filetime", + "globwalk", + "log", + "remove_dir_all 0.7.0", + "serde", + "serde_json", + "shlex", + "strum 0.24.1", + "tempfile", + "thiserror", + "toml", + "ureq", + "which", +] + +[[package]] +name = "enumset" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4799cdb24d48f1f8a7a98d06b7fde65a85a2d1e42b25a889f5406aa1fbefe074" +dependencies = [ + "enumset_derive", + "serde", +] + +[[package]] +name = "enumset_derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea83a3fbdc1d999ccfbcbee717eab36f8edf2d71693a23ce0d7cca19e085304c" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "env_logger" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "envy" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965" +dependencies = [ + "serde", +] + +[[package]] +name = "esp-idf-hal" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa416b08c24fc6439b59b7de329738e041af9bbddc733267e47085399f372487" +dependencies = [ + "anyhow", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0-alpha.8", + "embedded-svc", + "embuild 0.29.3", + "esp-idf-sys", + "nb 0.1.3", +] + +[[package]] +name = "esp-idf-svc" +version = "0.42.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "387d825a34a24ff5572385a6d42d94dc3b58f16b7f166a765f612178d4c16dcc" +dependencies = [ + "anyhow", + "cstr_core", + "embedded-svc", + "embuild 0.29.3", + "enumset", + "esp-idf-hal", + "esp-idf-sys", + "heapless", + "log", + "uncased", +] + +[[package]] +name = "esp-idf-sys" +version = "0.31.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17c64736a18d2bf2a4d661d787ca69499e59192ad11ae1cec50c4686303bed39" +dependencies = [ + "anyhow", + "bindgen", + "cargo_metadata", + "embuild 0.30.4", + "envy", + "libc", + "regex", + "serde", + "strum 0.24.1", +] + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + +[[package]] +name = "filetime" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys", +] + +[[package]] +name = "flate2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" + +[[package]] +name = "futures-io" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" + +[[package]] +name = "futures-sink" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" + +[[package]] +name = "futures-task" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" + +[[package]] +name = "futures-util" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "globset" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "globwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heapless" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version 0.4.0", + "serde", + "spin 0.9.4", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itoa" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +dependencies = [ + "adler", +] + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + +[[package]] +name = "no-std-net" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bcece43b12349917e096cddfa66107277f123e6c96a5aea78711dc601a47152" +dependencies = [ + "serde", +] + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro-crate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +dependencies = [ + "once_cell", + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro2" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "remove_dir_all" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882f368737489ea543bc5c340e6f3d34a28c39980bd9a979e47322b26f60ac40" +dependencies = [ + "libc", + "log", + "num_cpus", + "rayon", + "winapi", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "riscv" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba" +dependencies = [ + "bare-metal 1.0.0", + "bit_field", + "riscv-target", +] + +[[package]] +name = "riscv-target" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.14", +] + +[[package]] +name = "rustls" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustversion" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +dependencies = [ + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "sphinx-key-factory" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitflags", + "embedded-hal 0.2.7", + "embedded-svc", + "embuild 0.29.3", + "esp-idf-hal", + "esp-idf-svc", + "esp-idf-sys", + "log", + "rand", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strum" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb" +dependencies = [ + "strum_macros 0.23.1", +] + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros 0.24.3", +] + +[[package]] +name = "strum_macros" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.0", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all 0.5.3", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" + +[[package]] +name = "thiserror" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a99cb8c4b9a8ef0e7907cd3b617cc8dc04d571c4e73c8ae403d80ac160bb122" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a891860d3c8d66fec8e73ddb3765f90082374dbaaa833407b904a94f1a7eb43" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "uncased" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "ureq" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f" +dependencies = [ + "base64", + "chunked_transfer", + "flate2", + "log", + "once_cell", + "rustls", + "url", + "webpki", + "webpki-roots", +] + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +dependencies = [ + "webpki", +] + +[[package]] +name = "which" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +dependencies = [ + "either", + "libc", + "once_cell", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "xmas-elf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d29b4d8e7beaceb4e77447ba941a7600d23d0319ab52da0461abea214832d5a" +dependencies = [ + "zero", +] + +[[package]] +name = "zero" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/sphinx-key/Cargo.lock b/sphinx-key/Cargo.lock index 3dfa85f..0ed5ee9 100644 --- a/sphinx-key/Cargo.lock +++ b/sphinx-key/Cargo.lock @@ -280,12 +280,11 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.11.8" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72c3ff59e3b7d24630206bb63a73af65da4ed5df1f76ee84dfafb9fee2ba60e" +checksum = "ee685beed1fe2ab3cb9eb95d65727413b5e27f2b34014a3ea9c92053f8c230fc" dependencies = [ "serde", - "serde_derive", "toml", ] @@ -663,6 +662,7 @@ dependencies = [ "anyhow", "embedded-io", "enumset", + "futures", "heapless", "log", "no-std-net", @@ -695,9 +695,9 @@ dependencies = [ [[package]] name = "embuild" -version = "0.30.3" +version = "0.30.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01f030081cf69373a6c4b811934a81c7c9d3a11066ef22b564327a33f9991125" +checksum = "c6ca66d283ba92dc33ce461ba27bb5085a769dd740bad3f66e60e70926b34d05" dependencies = [ "anyhow", "bindgen", @@ -794,6 +794,7 @@ dependencies = [ "esp-idf-sys", "heapless", "log", + "uncased", ] [[package]] @@ -805,7 +806,7 @@ dependencies = [ "anyhow", "bindgen", "cargo_metadata", - "embuild 0.30.3", + "embuild 0.30.4", "envy", "libc", "regex", @@ -1488,9 +1489,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58" dependencies = [ "unicode-ident", ] @@ -2234,18 +2235,18 @@ checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" +checksum = "0a99cb8c4b9a8ef0e7907cd3b617cc8dc04d571c4e73c8ae403d80ac160bb122" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" +checksum = "3a891860d3c8d66fec8e73ddb3765f90082374dbaaa833407b904a94f1a7eb43" dependencies = [ "proc-macro2", "quote", @@ -2351,6 +2352,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "uncased" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.8" @@ -2579,9 +2589,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.4" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" dependencies = [ "webpki", ] From 8c7c081b720c0f5c98a69898798c412b9ff00e0f Mon Sep 17 00:00:00 2001 From: decentclock Date: Mon, 26 Sep 2022 14:14:23 -0400 Subject: [PATCH 6/8] Optimize factory binary size --- factory/Cargo.toml | 7 +++++++ factory/table.csv | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/factory/Cargo.toml b/factory/Cargo.toml index 1da361e..417c9d3 100644 --- a/factory/Cargo.toml +++ b/factory/Cargo.toml @@ -24,3 +24,10 @@ anyhow = "1" [package.metadata.espflash] partition_table = "table.csv" + +[profile.release] +strip = true # Automatically strip symbols from the binary. +opt-level = "z" # Optimize for size. +lto = true +codegen-units = 1 +panic = "abort" diff --git a/factory/table.csv b/factory/table.csv index 8133218..ef11890 100644 --- a/factory/table.csv +++ b/factory/table.csv @@ -3,5 +3,5 @@ nvs, data, nvs, 0x9000, 0x4000, otadata, data, ota, 0xd000, 0x2000, phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1200K, -ota_0, app, ota_0, 0x140000, 2800K, +factory, app, factory, 0x10000, 377K, +ota_0, app, ota_0, 0x70000, 3648K, From 7d398557512548d74a415c0eae8d7e36ef1d2b56 Mon Sep 17 00:00:00 2001 From: decentclock Date: Wed, 28 Sep 2022 13:47:54 -0400 Subject: [PATCH 7/8] ota: dispatch update download to its own thread --- sphinx-key/sdkconfig.defaults | 3 +- sphinx-key/src/core/events.rs | 22 +++++++++------ sphinx-key/src/ota.rs | 53 ++++++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/sphinx-key/sdkconfig.defaults b/sphinx-key/sdkconfig.defaults index f73fb9e..b97b1c6 100644 --- a/sphinx-key/sdkconfig.defaults +++ b/sphinx-key/sdkconfig.defaults @@ -1,6 +1,7 @@ # Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) CONFIG_ESP_MAIN_TASK_STACK_SIZE=64000 -#CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=10000 +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). # This allows to use 1 ms granuality for thread sleeps (10 ms by default). diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index b0bab0a..d5e1e8c 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -1,11 +1,12 @@ use crate::conn::mqtt::QOS; -use crate::ota::update_sphinx_key; +use crate::ota::{update_sphinx_key, validate_ota_message}; use sphinx_key_signer::control::{Config, ControlMessage, ControlResponse, Controller, Policy}; use sphinx_key_signer::lightning_signer::bitcoin::Network; use sphinx_key_signer::vls_protocol::model::PubKey; use sphinx_key_signer::{self, make_init_msg, topics, InitResponse, ParserError, RootHandler}; use std::sync::mpsc; +use std::thread; use embedded_svc::httpd::Result; use embedded_svc::mqtt::client::utils::ConnState; @@ -120,9 +121,6 @@ pub fn make_event_loop( rmp_serde::to_vec(&res).expect("could not publish control response"); mqtt.publish(topics::CONTROL_RETURN, QOS, false, &res_data) .expect("could not publish control response"); - if let ControlResponse::OtaConfirm(_) = res { - unsafe { esp_idf_sys::esp_restart() }; - } } } } @@ -167,12 +165,20 @@ fn handle_control_response( } } ControlMessage::Ota(params) => { - if let Err(e) = update_sphinx_key(params.version, params.url.clone()) { - log::error!("OTA update failed {:?}", e.to_string()); + if let Err(e) = validate_ota_message(params.clone()) { + log::error!("OTA update cannot launch {:?}", e.to_string()); control_res = - ControlResponse::Error(format!("OTA update failed {:?}", e)) + ControlResponse::Error(format!("OTA update cannot launch {:?}", e)) } else { - log::info!("OTA update completed, about to restart the glyph..."); + thread::spawn(move || { + if let Err(e) = update_sphinx_key(params) { + log::error!("OTA update failed {:?}", e.to_string()); + } else { + log::info!("OTA flow complete, restarting esp..."); + unsafe { esp_idf_sys::esp_restart() }; + } + }); + log::info!("OTA update launched..."); } } _ => (), diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs index 9069e32..afab4a5 100644 --- a/sphinx-key/src/ota.rs +++ b/sphinx-key/src/ota.rs @@ -2,6 +2,7 @@ use anyhow::{anyhow, Result}; use embedded_svc::http::client::Client; use embedded_svc::http::client::Request; use embedded_svc::http::client::Response; +use embedded_svc::http::Status; use embedded_svc::io::Read; use embedded_svc::ota::Ota; use esp_idf_svc::http::client::EspHttpClient; @@ -9,6 +10,7 @@ use esp_idf_svc::http::client::EspHttpClientConfiguration; use esp_idf_svc::http::client::FollowRedirectsPolicy::FollowNone; use esp_idf_svc::ota::EspOta; use log::{error, info}; +use sphinx_key_signer::control::OtaParams; use std::fs::{remove_file, File}; use std::io::BufWriter; use std::io::Write; @@ -29,7 +31,7 @@ fn factory_reset() -> Result<()> { } } -fn get_update(version: u64, mut url: String) -> Result<()> { +fn get_update(params: OtaParams) -> Result<()> { let configuration = EspHttpClientConfiguration { buffer_size: Some(BUFFER_LEN), buffer_size_tx: Some(BUFFER_LEN / 3), @@ -38,8 +40,8 @@ fn get_update(version: u64, mut url: String) -> Result<()> { crt_bundle_attach: None, }; let mut client = EspHttpClient::new(&configuration)?; - url.push_str(&version.to_string()); - let mut response = client.get(&url)?.submit()?; + let full_url = params_to_url(params); + let mut response = client.get(&full_url)?.submit()?; let mut reader = response.reader(); let _ = remove_file(UPDATE_BIN_PATH); @@ -69,13 +71,50 @@ fn get_update(version: u64, mut url: String) -> Result<()> { Ok(()) } -pub fn update_sphinx_key(version: u64, url: String) -> Result<()> { +pub fn update_sphinx_key(params: OtaParams) -> Result<()> { info!("Getting the update..."); - info!("Version: {}", version.to_string()); - info!("URL: {}", url); - get_update(version, url)?; + get_update(params)?; info!("Update written to sd card, performing factory reset"); factory_reset()?; info!("Factory reset completed!"); Ok(()) } + +pub fn validate_ota_message(params: OtaParams) -> Result<()> { + let configuration = EspHttpClientConfiguration { + buffer_size: Some(BUFFER_LEN / 3), + buffer_size_tx: Some(BUFFER_LEN / 3), + follow_redirects_policy: FollowNone, + use_global_ca_store: true, + crt_bundle_attach: None, + }; + let mut client = EspHttpClient::new(&configuration)?; + let full_url = params_to_url(params); + info!("Pinging this url for an update: {}", full_url); + let response = client.get(&full_url)?.submit()?; + let status = response.status(); + if status == 200 { + info!("Got valid OTA url! Proceeding with OTA update..."); + Ok(()) + } else if status == 404 { + error!("got 404, update not found on server, make sure the url and version are correct"); + Err(anyhow!( + "got 404, update not found on server, make sure the url and version are correct" + )) + } else { + error!( + "got {} code when fetching update, something is wrong", + &status.to_string() + ); + Err(anyhow!( + "got {} code when fetching update, something is wrong", + &status.to_string() + )) + } +} + +fn params_to_url(params: OtaParams) -> String { + let mut url = params.url.clone(); + url.push_str(¶ms.version.to_string()); + url +} From fcdd2ace7fa00eee3e3dab7dfc8ba8058ce35c83 Mon Sep 17 00:00:00 2001 From: decentclock Date: Wed, 28 Sep 2022 17:22:56 -0400 Subject: [PATCH 8/8] factory, ota: add ota led status main app blinks orange while downloading update to sd card factory app does a solid orange while writing the update from the sdcard to flash --- factory/src/led.rs | 41 +++++++++++++++++++++++++++++++++++ factory/src/main.rs | 3 +++ factory/table.csv | 4 ++-- sphinx-key/src/core/events.rs | 9 ++++++-- sphinx-key/src/ota.rs | 11 ++++++---- sphinx-key/src/periph/led.rs | 19 ++++++++-------- 6 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 factory/src/led.rs diff --git a/factory/src/led.rs b/factory/src/led.rs new file mode 100644 index 0000000..e3fa3ab --- /dev/null +++ b/factory/src/led.rs @@ -0,0 +1,41 @@ +use embedded_hal::blocking::delay::DelayMs; +use esp_idf_hal::delay::Ets; +use esp_idf_hal::peripherals::Peripherals; +use esp_idf_hal::rmt::config::TransmitConfig; +use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, Transmit}; +use std::time::Duration; + +pub fn set_ota_led() { + let peripherals = Peripherals::take().unwrap(); + let led = peripherals.pins.gpio8.into_output().unwrap(); + let channel = peripherals.rmt.channel0; + let config = TransmitConfig::new().clock_divider(1); + let mut tx = Transmit::new(led, channel, &config).unwrap(); + + let rgb = 0xffa500; // Orange + + let ticks_hz = tx.counter_clock().unwrap(); + let t0h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(350)).unwrap(); + let t0l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(800)).unwrap(); + let t1h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(700)).unwrap(); + let t1l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(600)).unwrap(); + + let mut signal = FixedLengthSignal::<24>::new(); + for i in 0..24 { + let bit = 2_u32.pow(i) & rotate_rgb(rgb) != 0; + let (high_pulse, low_pulse) = if bit { (t1h, t1l) } else { (t0h, t0l) }; + signal.set(i as usize, &(high_pulse, low_pulse)).unwrap(); + } + tx.start_blocking(&signal).unwrap(); + Ets.delay_ms(10u8); +} + +fn ns(nanos: u64) -> Duration { + Duration::from_nanos(nanos) +} + +fn rotate_rgb(rgb: u32) -> u32 { + let b_mask: u32 = 0xff; + let blue = (rgb & b_mask) << 16; + blue | (rgb >> 8) +} diff --git a/factory/src/main.rs b/factory/src/main.rs index 2a6d7d8..194f812 100644 --- a/factory/src/main.rs +++ b/factory/src/main.rs @@ -1,5 +1,7 @@ +mod led; mod ota; mod sdcard; +use crate::led::set_ota_led; use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported use log::{error, info, warn}; use ota::{run_sdcard_ota_update, set_boot_main_app, UPDATE_BIN_PATH}; @@ -14,6 +16,7 @@ fn main() { esp_idf_sys::link_patches(); thread::sleep(Duration::from_secs(10)); + set_ota_led(); info!("Hello, world! Mounting sd card..."); sdcard::mount_sd_card(); info!("SD card mounted! Checking for update..."); diff --git a/factory/table.csv b/factory/table.csv index ef11890..b207bd0 100644 --- a/factory/table.csv +++ b/factory/table.csv @@ -3,5 +3,5 @@ nvs, data, nvs, 0x9000, 0x4000, otadata, data, ota, 0xd000, 0x2000, phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 377K, -ota_0, app, ota_0, 0x70000, 3648K, +factory, app, factory, 0x10000, 448K, +ota_0, app, ota_0, 0x80000, 3584K, diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index d5e1e8c..5851abc 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -34,6 +34,7 @@ pub enum Status { ConnectingToMqtt, Connected, Signing, + Ota, } pub const ROOT_STORE: &str = "/sdcard/store"; @@ -116,7 +117,9 @@ pub fn make_event_loop( Event::Control(ref msg_bytes) => { log::info!("GOT A CONTROL MSG"); let cres = ctrlr.handle(msg_bytes); - if let Some(res) = handle_control_response(&root_handler, cres, network) { + if let Some(res) = + handle_control_response(&root_handler, cres, network, led_tx.clone()) + { let res_data = rmp_serde::to_vec(&res).expect("could not publish control response"); mqtt.publish(topics::CONTROL_RETURN, QOS, false, &res_data) @@ -133,6 +136,7 @@ fn handle_control_response( root_handler: &RootHandler, cres: anyhow::Result<(ControlMessage, ControlResponse)>, network: Network, + led_tx: mpsc::Sender, ) -> Option { match cres { Ok((control_msg, mut control_res)) => { @@ -171,7 +175,8 @@ fn handle_control_response( ControlResponse::Error(format!("OTA update cannot launch {:?}", e)) } else { thread::spawn(move || { - if let Err(e) = update_sphinx_key(params) { + led_tx.send(Status::Ota).unwrap(); + if let Err(e) = update_sphinx_key(params, led_tx) { log::error!("OTA update failed {:?}", e.to_string()); } else { log::info!("OTA flow complete, restarting esp..."); diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs index afab4a5..344c731 100644 --- a/sphinx-key/src/ota.rs +++ b/sphinx-key/src/ota.rs @@ -1,8 +1,9 @@ +use crate::core::events::Status; use anyhow::{anyhow, Result}; use embedded_svc::http::client::Client; use embedded_svc::http::client::Request; use embedded_svc::http::client::Response; -use embedded_svc::http::Status; +use embedded_svc::http::Status as HttpStatus; use embedded_svc::io::Read; use embedded_svc::ota::Ota; use esp_idf_svc::http::client::EspHttpClient; @@ -14,6 +15,7 @@ use sphinx_key_signer::control::OtaParams; use std::fs::{remove_file, File}; use std::io::BufWriter; use std::io::Write; +use std::sync::mpsc; const BUFFER_LEN: usize = 3072; const UPDATE_BIN_PATH: &str = "/sdcard/update.bin"; @@ -31,7 +33,7 @@ fn factory_reset() -> Result<()> { } } -fn get_update(params: OtaParams) -> Result<()> { +fn get_update(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { let configuration = EspHttpClientConfiguration { buffer_size: Some(BUFFER_LEN), buffer_size_tx: Some(BUFFER_LEN / 3), @@ -62,6 +64,7 @@ fn get_update(params: OtaParams) -> Result<()> { write_tot += w; i += 1; if i % 20 == 0 { + led_tx.send(Status::Ota).unwrap(); info!("Cumulative bytes read: {}", read_tot); info!("Cumulative bytes written: {}", write_tot); } @@ -71,9 +74,9 @@ fn get_update(params: OtaParams) -> Result<()> { Ok(()) } -pub fn update_sphinx_key(params: OtaParams) -> Result<()> { +pub fn update_sphinx_key(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { info!("Getting the update..."); - get_update(params)?; + get_update(params, led_tx)?; info!("Update written to sd card, performing factory reset"); factory_reset()?; info!("Factory reset completed!"); diff --git a/sphinx-key/src/periph/led.rs b/sphinx-key/src/periph/led.rs index 505aa95..059437d 100644 --- a/sphinx-key/src/periph/led.rs +++ b/sphinx-key/src/periph/led.rs @@ -19,15 +19,16 @@ pub struct Led { fn states() -> BTreeMap { let mut s = BTreeMap::new(); - s.insert(Status::Starting, (0x000001, 100)); - s.insert(Status::MountingSDCard, (0x000102, 100)); - s.insert(Status::SyncingTime, (0x000122, 100)); - s.insert(Status::WifiAccessPoint, (0x000100, 100)); - s.insert(Status::Configuring, (0x010000, 20)); - s.insert(Status::ConnectingToWifi, (0x010100, 350)); - s.insert(Status::ConnectingToMqtt, (0x010001, 100)); - s.insert(Status::Connected, (0x000101, 400)); - s.insert(Status::Signing, (0x111111, 100)); + s.insert(Status::Starting, (0x000001, 100)); // Blue + s.insert(Status::MountingSDCard, (0x000102, 100)); // Cyan + s.insert(Status::SyncingTime, (0x000122, 100)); // Cyan + s.insert(Status::WifiAccessPoint, (0x000100, 100)); // Green + s.insert(Status::Configuring, (0x010000, 20)); // Red + s.insert(Status::ConnectingToWifi, (0x010100, 350)); // Yellow + s.insert(Status::ConnectingToMqtt, (0x010001, 100)); // Purple + s.insert(Status::Connected, (0x000101, 400)); // Cyan + s.insert(Status::Signing, (0x111111, 100)); // White + s.insert(Status::Ota, (0xffa500, 100)); // Orange s }