You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tockloader-lib/src/attributes/app_attributes.rs
+36-36Lines changed: 36 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -48,8 +48,8 @@ impl AppAttributes {
48
48
/// The function below is used to retrieve header and footer data
49
49
///
50
50
/// Starting from the 0x40000 address,
51
-
/// using the 'parse_tbf_header_lengths' function, we read the very first 8 bytes to determine:
52
-
///
51
+
/// using the ['parse_tbf_header_lengths'] function, we read the very first 8 bytes to determine:
52
+
///
53
53
/// - tbf-version
54
54
/// - header_size
55
55
/// - total_size
@@ -109,10 +109,10 @@ impl AppAttributes {
109
109
.map_err(TockloaderError::ParsingError)?;
110
110
111
111
let binary_end_offset = header.get_binary_end();// the end of the header marks the beginning of the footer
112
-
113
-
/// 1. Calculate the total size of all footers by subtracting the binary's end offset (`binary_end_offset`) from the total application size (`total_size`).
114
-
/// 2. Initialize the reading offset (`footer_offset`) to the start of the footers (right after the binary ends).
115
-
/// 3. Loop until we've read all footers (when `footer_offset` reaches `total_size`):
112
+
113
+
// 1. Calculate the total size of all footers by subtracting the binary's end offset (`binary_end_offset`) from the total application size (`total_size`).
114
+
// 2. Initialize the reading offset (`footer_offset`) to the start of the footers (right after the binary ends).
115
+
// 3. Loop until we've read all footers (when `footer_offset` reaches `total_size`):
116
116
letmut footers:Vec<TbfFooter> = vec![];
117
117
letmut footers:Vec<TbfFooter> = vec![];
118
118
let total_footers_size = total_size - binary_end_offset;
@@ -172,25 +172,25 @@ impl AppAttributes {
172
172
letmut pkt = (appaddr asu32).to_le_bytes().to_vec();// the tockloader protocol only supports up to 32 bytes, hence we converted acquiring 4 byte little endians.
173
173
let length = (8_u16).to_le_bytes().to_vec();// 2 byte little endians
174
174
for i in length {
175
-
pkt.push(i);
175
+
pkt.push(i);
176
176
}
177
-
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
.map_err(TockloaderError::ProbeRsReadError)?;// The address is calculated as `(appaddr - 100)`, where `appaddr` marks the beginning of application binaries in flash.
165
+
)
166
+
.map_err(TockloaderError::ProbeRsReadError)?;// The address is calculated as `(appaddr - 100)`, where `appaddr` marks the beginning of application binaries in flash.
167
167
168
168
// Parse fixed fields from footer block
169
169
let sentinel = bytes_to_string(&kernel_attr_binary[96..100]);// Expect "TOCK" as usual
@@ -174,18 +174,17 @@ impl SystemAttributes {
174
174
175
175
let kernel_binary_start = LittleEndian::read_u32(&kernel_attr_binary[68..72]);
176
176
let kernel_binary_len = LittleEndian::read_u32(&kernel_attr_binary[72..76]);
177
-
/// This what it looks like:
178
-
///
179
-
/// - 0-79: is for padding, basically unused.
180
-
/// - 80-84: app_mem_start (u32, little-endian)
181
-
/// - 84-88: app_mem_len (u32)
182
-
/// - 88-92: kernel_mem_start (u32)
183
-
/// - 92-96: kernel_mem_len (u32)
184
-
/// - 96-100: Sentinel ("TOCK" ASCII)
185
-
/// - 95-96: Kernel version (u8)
186
-
177
+
// This what it looks like:
178
+
//
179
+
// - 0-79: is for padding, basically unused.
180
+
// - 80-84: app_mem_start (u32, little-endian)
181
+
// - 84-88: app_mem_len (u32)
182
+
// - 88-92: kernel_mem_start (u32)
183
+
// - 92-96: kernel_mem_len (u32)
184
+
// - 96-100: Sentinel ("TOCK" ASCII)
185
+
// - 95-96: Kernel version (u8)
187
186
// Store parsed values in result struct
188
-
result.sentinel = Some(sentinel);
187
+
result.sentinel = Some(sentinel);
189
188
result.kernel_version = Some(kernel_version);
190
189
result.app_mem_start = Some(app_memory_start);
191
190
result.app_mem_len = Some(app_memory_len);
@@ -227,18 +226,18 @@ impl SystemAttributes {
227
226
pkt.push(i);// Merges the two, making them 6 bytes in the vector
228
227
}
229
228
230
-
/// This sends a `ReadRange` command to the microcontroller to read 1024 bytes of memory starting at address `0x600`.
231
-
///
232
-
/// The microcontroller expects the command in this structure:
233
-
/// - 1 byte: Command ID (`0x06` or `0x10` for `ReadRange`)
234
-
/// - 1 byte: Payload length (always 6 bytes for this command)
235
-
/// - 6 bytes payload:
236
-
/// - 4 bytes: Start address (little-endian)
237
-
/// - 2 bytes: Number of bytes to read (little-endian)
238
-
///
239
-
/// In this case, we’re reading system attributes stored in memory starting at `0x600`.
240
-
///
241
-
/// The 1024-byte response will contain multiple 64-byte attribute blocks, each of which may encode a (key, value) pair.
229
+
// This sends a `ReadRange` command to the microcontroller to read 1024 bytes of memory starting at address `0x600`.
230
+
//
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)
237
+
//
238
+
// In this case, we’re reading system attributes stored in memory starting at `0x600`.
239
+
//
240
+
// The 1024-byte response will contain multiple 64-byte attribute blocks, each of which may encode a (key, value) pair.
242
241
let(_, buf) = issue_command(
243
242
port,
244
243
Command::ReadRange,// Read memory (e.g. 0x10)
@@ -307,19 +306,19 @@ impl SystemAttributes {
307
306
pkt.push(i);// Append length
308
307
}
309
308
310
-
/// This sends a `ReadRange` command to read 8 bytes from address `0x40E`,
311
-
/// which stores the bootloader version string (UTF-8 encoded).
312
-
///
313
-
/// The serial protocol proceeds as follows:
314
-
/// - 1 byte: Command ID
315
-
/// - 1 byte: Payload length = 6
316
-
/// - Payload =
317
-
/// - 4 bytes: Address (0x40E, little-endian)
318
-
/// - 2 bytes: Length (`8`, little-endian)
319
-
///
320
-
/// The response is expected to be a UTF-8 encoded string, often null-terminated.
321
-
///
322
-
/// We decode the returned bytes into a `String`, trimming any null characters from the end.
309
+
// This sends a `ReadRange` command to read 8 bytes from address `0x40E`,
310
+
// which stores the bootloader version string (UTF-8 encoded).
311
+
//
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)
318
+
//
319
+
// The response is expected to be a UTF-8 encoded string, often null-terminated.
320
+
//
321
+
// We decode the returned bytes into a `String`, trimming any null characters from the end.
0 commit comments