eculocate

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

commit 79f312f33eb23063918b3a806d9e460712ecd836
parent ba2c97fa3162bfb94be5b979abe0e54b17c9c11a
Author: filipton <filipton12@gmail.com>
Date:   Thu,  4 Jul 2024 21:09:30 +0200

feat: simple ota server (raw tcp) with working ota update

Diffstat:
M.gitignore | 9+--------
Aexamples | 1+
Asimple-ota-server/Cargo.lock | 7+++++++
Asimple-ota-server/Cargo.toml | 8++++++++
Asimple-ota-server/firmware.bin | 0
Asimple-ota-server/src/main.rs | 23+++++++++++++++++++++++
Msrc/lib.rs | 17++++++++++++++++-
7 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,8 +1 @@ -/target - - -# Added by cargo -# -# already existing elements were commented out - -#/target +target diff --git a/examples b/examples @@ -0,0 +1 @@ +Subproject commit 8a93df58375da1a5d043db6f454c9fe535163f26 diff --git a/simple-ota-server/Cargo.lock b/simple-ota-server/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "simple-ota-server" +version = "0.1.0" diff --git a/simple-ota-server/Cargo.toml b/simple-ota-server/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "simple-ota-server" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/simple-ota-server/firmware.bin b/simple-ota-server/firmware.bin Binary files differ. diff --git a/simple-ota-server/src/main.rs b/simple-ota-server/src/main.rs @@ -0,0 +1,23 @@ +use std::{io::{Read, Write}, net::TcpListener}; + +const BINARY: &[u8] = include_bytes!("../firmware.bin"); +fn main() { + println!("BINARY_SIZE: {}", BINARY.len()); + + let listener = TcpListener::bind("0.0.0.0:6969").unwrap(); + for stream in listener.incoming() { + println!("Connection"); + let mut stream = stream.unwrap(); + + let chunks = BINARY.chunks(512); + let mut buf = [0; 1]; + for chunk in chunks { + println!("Writing: {}", chunk.len()); + + _ = stream.write_all(chunk); + _ = stream.read_exact(&mut buf); + + std::thread::sleep(std::time::Duration::from_millis(10)); + } + } +} diff --git a/src/lib.rs b/src/lib.rs @@ -25,6 +25,7 @@ where { flash: S, ota_offset: Option<u32>, + target_partition: Option<usize>, flash_size: u32, ota_remaining: u32, } @@ -39,6 +40,7 @@ where Ota { flash, ota_offset: None, + target_partition: None, ota_remaining: 0, flash_size: 0, } @@ -49,7 +51,11 @@ where let next_part = Self::get_next_ota_partition(); let ota_offset = next_part.map(|i| PARTITIONS[i].start); - Ota { ota_offset, ..self } + Ota { + ota_offset, + target_partition: next_part, + ..self + } } /// Sets the firmware flash size @@ -93,6 +99,15 @@ where Ok(self.ota_remaining == 0) } + // TODO: crc checks or sth + pub fn ota_flush(&mut self) -> Result<(), ()> { + if let Some(target_partition) = self.target_partition { + self.set_target_ota_boot_partition(target_partition); + } + + Ok(()) + } + /// Sets ota boot target partition pub fn set_target_ota_boot_partition(&mut self, target: usize) { let (seq1, seq2) = self.get_ota_boot_sequences();