Skip to content

Commit b0c8c1d

Browse files
committed
lib: support big endian devices
With big endian devices, the symbols are stored in big endian order. This is fine if the header is getting loaded onto the target, however the header is only for use with the host system, which is almost alays little endian. Ensure each field of the header is correctly swapped by adding `.to_le()` to each field. Additionally, ensure all fields are primitive integer types, as byte swapping is undefined for Rust types. Signed-off-by: Sean Cross <[email protected]>
1 parent a915acb commit b0c8c1d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,35 +185,35 @@ macro_rules! algorithm {
185185
#[link_section = "DeviceData"]
186186
pub static FlashDevice: FlashDeviceDescription = FlashDeviceDescription {
187187
// The version is never read by probe-rs and can be fixed.
188-
vers: 0x1,
188+
vers: 0x1u16.to_le(),
189189
// The device name here can be customized but it really has no real use
190190
// appart from identifying the device the ELF is intended for which we have
191191
// in our YAML.
192192
dev_name: $crate::arrayify_string($device_name),
193193
// The specification does not specify the values that can go here,
194194
// but this value means internal flash device.
195-
dev_type: $device_type,
196-
dev_addr: $flash_address,
197-
device_size: $flash_size,
198-
page_size: $page_size,
195+
dev_type: ($device_type as u16).to_le(),
196+
dev_addr: ($flash_address as u32).to_le(),
197+
device_size: ($flash_size as u32).to_le(),
198+
page_size: ($page_size as u32).to_le(),
199199
_reserved: 0,
200200
// The empty state of a byte in flash.
201-
empty: $empty_value,
201+
empty: ($empty_value as u8).to_le(),
202202
// This value can be used to estimate the amount of time the flashing procedure takes worst case.
203-
program_time_out: $program_time_out,
203+
program_time_out: ($program_time_out as u32).to_le(),
204204
// This value can be used to estimate the amount of time the erasing procedure takes worst case.
205-
erase_time_out: $erase_time_out,
205+
erase_time_out: ($erase_time_out as u32).to_le(),
206206
flash_sectors: [
207207
$(
208208
FlashSector {
209-
size: $size,
210-
address: $address,
209+
size: ($size as u32).to_le(),
210+
address: ($address as u32).to_le(),
211211
}
212212
),+,
213213
// This marks the end of the flash sector list.
214214
FlashSector {
215-
size: 0xffff_ffff,
216-
address: 0xffff_ffff,
215+
size: 0xffff_ffffu32.to_le(),
216+
address: 0xffff_ffffu32.to_le(),
217217
}
218218
],
219219
};
@@ -222,7 +222,7 @@ macro_rules! algorithm {
222222
pub struct FlashDeviceDescription {
223223
vers: u16,
224224
dev_name: [u8; 128],
225-
dev_type: DeviceType,
225+
dev_type: u16,
226226
dev_addr: u32,
227227
device_size: u32,
228228
page_size: u32,

0 commit comments

Comments
 (0)