Skip to content

Commit 4d8fea9

Browse files
committed
chore: document general and app attributes
1 parent 892920e commit 4d8fea9

2 files changed

Lines changed: 46 additions & 50 deletions

File tree

tockloader-lib/src/attributes/app_attributes.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ impl AppAttributes {
114114
// 2. Initialize the reading offset (`footer_offset`) to the start of the footers (right after the binary ends).
115115
// 3. Loop until we've read all footers (when `footer_offset` reaches `total_size`):
116116
let mut footers: Vec<TbfFooter> = vec![];
117-
let mut footers: Vec<TbfFooter> = vec![];
118117
let total_footers_size = total_size - binary_end_offset;
119118
let mut footer_offset = binary_end_offset;
120119
let mut footer_number = 0;
@@ -175,19 +174,16 @@ impl AppAttributes {
175174
pkt.push(i);
176175
}
177176

178-
// This sends a `ReadRange` command to the microcontroller to read 8 bytes of memory starting at `appaddr`,
179-
// and receives the result over the serial connection.
180-
//
181-
// The microcontroller receives the command, checks the Command ID (`0x06` for `ReadRange`),
182-
// then reads the 1-byte payload length and the actual payload:
183-
// 4 bytes for the address (little-endian), and 2 bytes for the length to read (also little-endian).
184-
//
185-
// The microcontroller processes incoming bytes using a state machine like this:
186-
//
187-
// enum SerialState {
188-
// WaitingForCommand, // Awaiting the 1-byte command ID
189-
// WaitingForLength, // Awaiting the 1-byte payload length
190-
// WaitingForPayload { command: u8, length: usize, buffer: Vec<u8> }, // Receiving payload
177+
// This sends a `ReadRange` command to the microcontroller to read 8 bytes of memory starting at `appaddr`,
178+
// and receives the result over the serial connection.
179+
// The microcontroller receives the command, checks the Command ID (`0x06` for `ReadRange`),
180+
// then reads the 1-byte payload length and the actual payload:
181+
// 4 bytes for the address (little-endian), and 2 bytes for the length to read (also little-endian).
182+
// The microcontroller processes incoming bytes using a state machine like this:
183+
// enum SerialState {
184+
// WaitingForCommand, // Awaiting the 1-byte command ID
185+
// WaitingForLength, // Awaiting the 1-byte payload length
186+
// WaitingForPayload { command: u8, length: usize, buffer: Vec<u8> }, // Receiving payload
191187
// }
192188
let (_, appdata) = // the first element in the tuple be returned is raw data so we ignore it and take the second which is the app data we need
193189
issue_command(port, Command::ReadRange, pkt, true, 8, Response::ReadRange).await?;
@@ -214,13 +210,13 @@ impl AppAttributes {
214210
for i in length {
215211
pkt.push(i);
216212
}
217-
// This also sends a ReadRange command to fetch the full TBF header from the same app address (appaddr).
213+
// This also sends a ReadRange command to fetch the full TBF header from the same app address (appaddr).
218214
//
219-
// The first read (8 bytes) gave us only the header lengths and total size,
220-
// but now that we know the full header size (header_size), we send a new request to retrieve the entire header.
215+
// The first read (8 bytes) gave us only the header lengths and total size,
216+
// but now that we know the full header size (header_size), we send a new request to retrieve the entire header.
221217
//
222-
// The returned data (header_data) is a raw byte vector containing all fields of the TBF header,
223-
// including version, flags, entry point, protected regions, package name, etc.
218+
// The returned data (header_data) is a raw byte vector containing all fields of the TBF header,
219+
// including version, flags, entry point, protected regions, package name, etc.
224220
let (_, header_data) = issue_command(
225221
port,
226222
Command::ReadRange,
@@ -253,7 +249,7 @@ impl AppAttributes {
253249
//
254250
// The response contains raw bytes starting from footer_offset, with the desired length.
255251
//
256-
// We ignore the first tuple element and keep only the returned footer bytes.
252+
// We ignore the first tuple element and keep only the returned footer bytes.
257253
let (_, appfooter) = issue_command(
258254
port,
259255
Command::ReadRange,

tockloader-lib/src/attributes/system_attributes.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,18 @@ impl SystemAttributes {
226226
pkt.push(i); // Merges the two, making them 6 bytes in the vector
227227
}
228228

229-
// This sends a `ReadRange` command to the microcontroller to read 1024 bytes of memory starting at address `0x600`.
229+
// This sends a `ReadRange` command to the microcontroller to read 1024 bytes of memory starting at address `0x600`.
230230
//
231-
// The microcontroller expects the command in this structure:
232-
// - 1 byte: Command ID (`0x06` or `0x10` for `ReadRange`)
233-
// - 1 byte: Payload length (always 6 bytes for this command)
234-
// - 6 bytes payload:
235-
// - 4 bytes: Start address (little-endian)
236-
// - 2 bytes: Number of bytes to read (little-endian)
231+
// The microcontroller expects the command in this structure:
232+
// - 1 byte: Command ID (`0x06` or `0x10` for `ReadRange`)
233+
// - 1 byte: Payload length (always 6 bytes for this command)
234+
// - 6 bytes payload:
235+
// - 4 bytes: Start address (little-endian)
236+
// - 2 bytes: Number of bytes to read (little-endian)
237237
//
238-
// In this case, we’re reading system attributes stored in memory starting at `0x600`.
238+
// In this case, we’re reading system attributes stored in memory starting at `0x600`.
239239
//
240-
// The 1024-byte response will contain multiple 64-byte attribute blocks, each of which may encode a (key, value) pair.
240+
// The 1024-byte response will contain multiple 64-byte attribute blocks, each of which may encode a (key, value) pair.
241241
let (_, buf) = issue_command(
242242
port,
243243
Command::ReadRange, // Read memory (e.g. 0x10)
@@ -306,19 +306,19 @@ impl SystemAttributes {
306306
pkt.push(i); // Append length
307307
}
308308

309-
// This sends a `ReadRange` command to read 8 bytes from address `0x40E`,
310-
// which stores the bootloader version string (UTF-8 encoded).
309+
// This sends a `ReadRange` command to read 8 bytes from address `0x40E`,
310+
// which stores the bootloader version string (UTF-8 encoded).
311311
//
312-
// The serial protocol proceeds as follows:
313-
// - 1 byte: Command ID
314-
// - 1 byte: Payload length = 6
315-
// - Payload =
316-
// - 4 bytes: Address (0x40E, little-endian)
317-
// - 2 bytes: Length (`8`, little-endian)
312+
// The serial protocol proceeds as follows:
313+
// - 1 byte: Command ID
314+
// - 1 byte: Payload length = 6
315+
// - Payload =
316+
// - 4 bytes: Address (0x40E, little-endian)
317+
// - 2 bytes: Length (`8`, little-endian)
318318
//
319-
// The response is expected to be a UTF-8 encoded string, often null-terminated.
319+
// The response is expected to be a UTF-8 encoded string, often null-terminated.
320320
//
321-
// We decode the returned bytes into a `String`, trimming any null characters from the end.
321+
// We decode the returned bytes into a `String`, trimming any null characters from the end.
322322
let (_, buf) =
323323
issue_command(port, Command::ReadRange, pkt, true, 8, Response::ReadRange).await?;
324324

@@ -343,20 +343,20 @@ impl SystemAttributes {
343343
pkt.push(i); // Append length
344344
}
345345

346-
// This sends a `ReadRange` command to read the last 100 bytes before the start of the application space,
347-
// which usually contains the kernel’s footer region.
346+
// This sends a `ReadRange` command to read the last 100 bytes before the start of the application space,
347+
// which usually contains the kernel’s footer region.
348348
//
349-
// The address is calculated as `(appaddr - 100)`, where `appaddr` marks the beginning of application binaries in flash.
349+
// The address is calculated as `(appaddr - 100)`, where `appaddr` marks the beginning of application binaries in flash.
350350
//
351-
// The request structure is:
352-
// - 1 byte: Command ID (`0x06`)
353-
// - 1 byte: Payload length = 6
354-
// - Payload =
355-
// - 4 bytes: Address (`appaddr - 100`, little-endian)
356-
// - 2 bytes: Length (`100`, little-endian)
351+
// The request structure is:
352+
// - 1 byte: Command ID (`0x06`)
353+
// - 1 byte: Payload length = 6
354+
// - Payload =
355+
// - 4 bytes: Address (`appaddr - 100`, little-endian)
356+
// - 2 bytes: Length (`100`, little-endian)
357357
//
358-
// The microcontroller responds with 100 bytes from that memory region.
359-
// These bytes might contain metadata or checksums relevant to the kernel image.
358+
// The microcontroller responds with 100 bytes from that memory region.
359+
// These bytes might contain metadata or checksums relevant to the kernel image.
360360
let (_, kernel_attr_binary) = issue_command(
361361
port,
362362
Command::ReadRange,

0 commit comments

Comments
 (0)