Skip to content

Commit

Permalink
Add support for Stax and Flex in cargo-ledger.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed May 22, 2024
1 parent 80f8601 commit a332fba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cargo-ledger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "cargo-ledger"
version = "1.3.0"
version = "1.4.0"
authors = ["yhql"]
description = "Build and sideload Ledger Nano apps"
description = "Build and sideload Ledger devices apps"
categories = ["development-tools::cargo-plugins"]
repository = "https://github.com/LedgerHQ/cargo-ledger"
readme = "README.md"
Expand Down
10 changes: 9 additions & 1 deletion cargo-ledger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ enum Device {
Nanos,
Nanox,
Nanosplus,
Stax,
Flex,
}

impl Display for Device {
Expand All @@ -88,6 +90,8 @@ impl AsRef<str> for Device {
Device::Nanos => "nanos",
Device::Nanox => "nanox",
Device::Nanosplus => "nanosplus",
Device::Stax => "stax",
Device::Flex => "flex",
}
}
}
Expand Down Expand Up @@ -199,6 +203,8 @@ fn build_app(
Device::Nanos => std::env::var("NANOS_SDK"),
Device::Nanosplus => std::env::var("NANOSP_SDK"),
Device::Nanox => std::env::var("NANOX_SDK"),
Device::Stax => std::env::var("STAX_SDK"),
Device::Flex => std::env::var("FLEX_SDK"),
};

let mut args: Vec<String> = vec![];
Expand Down Expand Up @@ -294,7 +300,7 @@ fn build_app(
// Modify flags to enable BLE if targeting Nano X
let flags = match device {
Device::Nanos | Device::Nanosplus => metadata_ledger.flags,
Device::Nanox => {
Device::Nanox | Device::Stax | Device::Flex => {
let base = u32::from_str_radix(metadata_ledger.flags.as_str(), 16)
.unwrap_or(0);
format!("0x{:x}", base | 0x200)
Expand All @@ -307,6 +313,8 @@ fn build_app(
Device::Nanos => String::from("0x31100004"),
Device::Nanox => String::from("0x33000004"),
Device::Nanosplus => String::from("0x33100004"),
Device::Stax => String::from("0x33200004"),
Device::Flex => String::from("0x33300004"),
};

// create manifest
Expand Down
4 changes: 2 additions & 2 deletions cargo-ledger/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub fn install_targets() {
let sysroot_cmd = std::str::from_utf8(&sysroot_cmd).unwrap().trim();

let target_files_url = Path::new(
"https://raw.githubusercontent.com/LedgerHQ/ledger-device-rust-sdk/a630c93398316cc56dcec6aceb0d424b626d150c/ledger_device_sdk/"
"https://raw.githubusercontent.com/LedgerHQ/ledger-device-rust-sdk/feat/stax_nbgl_2/ledger_device_sdk/"
);
let sysroot = Path::new(sysroot_cmd).join("lib").join("rustlib");

// Retrieve each target file independently
// TODO: handle target.json modified upstream
for target in &["nanos", "nanox", "nanosplus"] {
for target in &["nanos", "nanox", "nanosplus", "stax", "flex"] {
let outfilepath = sysroot.join(target).join("target.json");
let targetpath =
outfilepath.clone().into_os_string().into_string().unwrap();
Expand Down
15 changes: 12 additions & 3 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,18 @@ impl<'a, const MAX_FIELD_NUMBER: usize, const STRING_BUFFER_SIZE: usize>
TYPE_TRANSACTION,
&tag_value_list as *const nbgl_layoutTagValueList_t,
self.icon,
self.c_string_helper.to_cstring(self.title).unwrap().as_ptr() as *const c_char,
self.c_string_helper.to_cstring(self.subtitle).unwrap().as_ptr() as *const c_char,
self.c_string_helper.to_cstring(self.finish_title).unwrap().as_ptr() as *const c_char,
self.c_string_helper
.to_cstring(self.title)
.unwrap()
.as_ptr() as *const c_char,
self.c_string_helper
.to_cstring(self.subtitle)
.unwrap()
.as_ptr() as *const c_char,
self.c_string_helper
.to_cstring(self.finish_title)
.unwrap()
.as_ptr() as *const c_char,
);

// Return true if the user approved the transaction, false otherwise.
Expand Down

0 comments on commit a332fba

Please sign in to comment.