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
/// Using this offset, we read the correct number of bytes from memory,
66
-
/// construct a TbfFooter struct from the raw bytes, and store it.
59
+
/// then, we save our binary app which marks the total size of the app and move on to the the footer.
60
+
///
61
+
/// Now, we calculate the total size of the footer.
62
+
///
63
+
/// Then, we compute the exact offset of the current footer.
64
+
///
65
+
/// Using it, we read the correct number of bytes from memory,
66
+
/// construct a 'TbfFooter' struct from the raw bytes, and store it.
67
+
///
67
68
/// Once all footers for an app are gathered,
68
69
/// we wrap the header, footers, and other metadata into an `AppAttributes` struct,
69
70
/// and push it into the apps_details vector, which holds info for all flashed applications
@@ -89,7 +90,7 @@ impl AppAttributes {
89
90
matchparse_tbf_header_lengths(
90
91
&appdata
91
92
.try_into()
92
-
.expect("Buffer length must be at least 8 bytes long."),
93
+
.expect("Buffer length must be at least 8 bytes long."),// All attributes always add up to 8 bytes.
93
94
){
94
95
Ok(data) => {
95
96
tbf_version = data.0;
@@ -107,16 +108,20 @@ impl AppAttributes {
107
108
let header = parse_tbf_header(&header_data, tbf_version)
108
109
.map_err(TockloaderError::ParsingError)?;
109
110
110
-
let binary_end_offset = header.get_binary_end();
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`):
116
+
letmut footers:Vec<TbfFooter> = vec![];
112
117
letmut footers:Vec<TbfFooter> = vec![];
113
118
let total_footers_size = total_size - binary_end_offset;
vec![0u8;(total_footers_size - (footer_offset - binary_end_offset))asusize];// we take the size of the whole footer initially then decrease it by the size of the previous one as we don't know the size of the footer we are reading
footer_offset += footer_info.1 + 4;// the next footer begins using this relation: (footer_offset = binary_end_offset) += summation of (previous_footer_size + 4)
132
137
133
138
if footer_offset == total_size {
134
-
break;
139
+
break;// all footers have been processed.
135
140
}
136
141
}
137
142
@@ -143,7 +148,18 @@ impl AppAttributes {
143
148
}
144
149
}
145
150
146
-
// TODO: Document this function
151
+
/// This reads application metadata and footers from a device just like the previous function except it's done via serial.
152
+
///
153
+
/// Starting at the given address, this function:
154
+
///
155
+
/// 1. Reads the initial 8 bytes of the app header to get version and size info.
156
+
/// 2. Reads the full app header based on that size.
157
+
/// 3. Reads and parses all app footers following the app binary.
158
+
/// 4. Collects and returns all app attributes found sequentially in memory.
159
+
///
160
+
/// Communicates using the Tockloader protocol’s `ReadRange` command and handles multiple apps until no more are found.
161
+
///
162
+
/// Returns a vector of app attributes or an error on failure.
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
+
let length = (8_u16).to_le_bytes().to_vec();// 2 byte little endians
0 commit comments