Skip to content

Commit f88e6a0

Browse files
author
George Cosma
committed
wip: add TODO markers
Signed-off-by: George Cosma <george.cosma@wyliodrin.com>
1 parent 20b54f0 commit f88e6a0

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

tockloader-lib/src/connection.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Default for SerialTargetInfo {
4646
}
4747
}
4848

49+
// TODO(george-cosma): trait? and 2 struct ProbeConnection and SerialConection?
4950
#[allow(clippy::large_enum_variant)]
5051
pub enum Connection {
5152
ProbeRS {

tockloader-lib/src/errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
// Copyright OXIDOS AUTOMOTIVE 2024.
44

55
use std::io;
6-
76
use thiserror::Error;
87

8+
// TODO(george-cosma): Split this. Possibly each meta-function (install, list,
9+
// ...) should have its own error type + error type for connection. We can have
10+
// more detailed errors as "sources" for more generic error types, if we TRULY
11+
// need to know why probe-rs failed. Or serial.
12+
913
#[derive(Debug, Error)]
1014
pub enum TockloaderError {
1115
#[error("Error occurred while trying to access core: {0}")]

tockloader-lib/src/lib.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ pub fn list_serial_ports() -> Result<Vec<SerialPortInfo>, TockloaderError> {
3636
tokio_serial::available_ports().map_err(TockloaderError::SerialInitializationError)
3737
}
3838

39+
// TODO(george-cosma): These functions can all be turned into traits (Listable,
40+
// Installable, etc.) and be implemented on the Connection enum. Or, if we also
41+
// split Connection into trait + structs for each type of connection type, we
42+
// can implement these traits on the individual connections types, and not have
43+
// this mega-massive file.
44+
45+
// TODO(george-cosma): Examine if we need to split these functions into smaller
46+
// parts (reading - processing - writing) for mocking. Could also involve adding
47+
// functions to the proposed 'Connection' trait.
48+
49+
// TODO(george-cosma): General housekeeping in these functions.
50+
3951
pub async fn list(
4052
connection: &mut Connection,
4153
settings: &BoardSettings,
@@ -107,12 +119,12 @@ pub async fn install_app(
107119
.core(info.core)
108120
.map_err(|e| TockloaderError::CoreAccessError(info.core, e))?;
109121

110-
// TODO: extract these informations without bootloader
111-
// TODO: extract board name and kernelr version to verify app compatability
122+
// TODO(george-cosma): extract these informations without bootloader
123+
// TODO(george-cosma): extract board name and kernel version to verify app compatability
112124

113125
let mut address = settings.start_address;
114126

115-
// TODO: double-check/rework this
127+
// TODO(george-cosma): double-check/rework this
116128

117129
// Read a block of 200 8-bit words// Loop to check if there are another apps installed
118130
loop {
@@ -141,7 +153,7 @@ pub async fn install_app(
141153
"No architecture found.".to_owned(),
142154
))?;
143155

144-
let mut binary = tab_file.extract_binary(&arch.clone())?;
156+
let mut binary = tab_file.extract_binary(&arch)?;
145157
let size = binary.len() as u64;
146158

147159
// Make sure the app is aligned to a multiple of its size
@@ -155,12 +167,18 @@ pub async fn install_app(
155167
(address, 0)
156168
};
157169

158-
// No more need of core
170+
// TODO(george-cosma): This point MIGHT mark a good point to split
171+
// this function (for probe-rs).
172+
173+
// At this point we no longer need to hold the probe-rs connection
174+
// to the core, as the flashing is done without it.
159175
drop(core);
160176

161177
// Make sure the binary is a multiple of the page size by padding 0xFFs
162-
// TODO(Micu Ana): check if the page-size differs
163-
// TODO: also use page_size given or known. This works for now
178+
179+
// TODO(george-cosma): check if the page-size differs + support
180+
// multiple types of page sizes. Possibly make page size a board
181+
// setting.
164182
let page_size = 512;
165183
let needs_padding = binary.len() % page_size != 0;
166184

@@ -186,14 +204,16 @@ pub async fn install_app(
186204
}
187205
}
188206

189-
// If there are no pages valid, all pages would have been removed, so we write them all
207+
// If there are no pages valid, all pages would have been removed,
208+
// so we write them all
190209
if valid_pages.is_empty() {
191210
for i in 0..(size as usize / page_size) {
192211
valid_pages.push(i.try_into().unwrap());
193212
}
194213
}
195214

196-
// Include a blank page (if exists) after the end of a valid page. There might be a usable 0 on the next page
215+
// Include a blank page (if exists) after the end of a valid page.
216+
// There might be a usable 0 on the next page
197217
let mut ending_pages: Vec<u8> = Vec::new();
198218
for &i in &valid_pages {
199219
let mut iter = valid_pages.iter();
@@ -208,8 +228,8 @@ pub async fn install_app(
208228

209229
for i in valid_pages {
210230
println!("Writing page number {}", i);
211-
// Create the packet that we send to the bootloader
212-
// First four bytes are the address of the page
231+
// Create the packet that we send to the bootloader. First four
232+
// bytes are the address of the page
213233
let mut pkt = Vec::new();
214234

215235
// Then the bytes that go into the page

0 commit comments

Comments
 (0)