Skip to content

Add big endian support #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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 <sean@xobs.io>
  • Loading branch information
xobs committed May 7, 2025
commit b0c8c1d5aa2a8aafaac4835f2b0fefd16cc1c92b
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,35 @@ macro_rules! algorithm {
#[link_section = "DeviceData"]
pub static FlashDevice: FlashDeviceDescription = FlashDeviceDescription {
// The version is never read by probe-rs and can be fixed.
vers: 0x1,
vers: 0x1u16.to_le(),
// The device name here can be customized but it really has no real use
// appart from identifying the device the ELF is intended for which we have
// in our YAML.
dev_name: $crate::arrayify_string($device_name),
// The specification does not specify the values that can go here,
// but this value means internal flash device.
dev_type: $device_type,
dev_addr: $flash_address,
device_size: $flash_size,
page_size: $page_size,
dev_type: ($device_type as u16).to_le(),
dev_addr: ($flash_address as u32).to_le(),
device_size: ($flash_size as u32).to_le(),
page_size: ($page_size as u32).to_le(),
_reserved: 0,
// The empty state of a byte in flash.
empty: $empty_value,
empty: ($empty_value as u8).to_le(),
// This value can be used to estimate the amount of time the flashing procedure takes worst case.
program_time_out: $program_time_out,
program_time_out: ($program_time_out as u32).to_le(),
// This value can be used to estimate the amount of time the erasing procedure takes worst case.
erase_time_out: $erase_time_out,
erase_time_out: ($erase_time_out as u32).to_le(),
flash_sectors: [
$(
FlashSector {
size: $size,
address: $address,
size: ($size as u32).to_le(),
address: ($address as u32).to_le(),
}
),+,
// This marks the end of the flash sector list.
FlashSector {
size: 0xffff_ffff,
address: 0xffff_ffff,
size: 0xffff_ffffu32.to_le(),
address: 0xffff_ffffu32.to_le(),
}
],
};
Expand All @@ -222,7 +222,7 @@ macro_rules! algorithm {
pub struct FlashDeviceDescription {
vers: u16,
dev_name: [u8; 128],
dev_type: DeviceType,
dev_type: u16,
dev_addr: u32,
device_size: u32,
page_size: u32,
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy