Skip to content
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

appflags shall be set in hex value and could be set at device level #227

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cargo-ledger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cargo-ledger"
version = "1.5.1"
authors = ["yhql", "agrojean-ledger"]
version = "1.6.0"
authors = ["yhql", "agrojean-ledger", "y333"]
description = "Build and sideload Ledger devices apps"
categories = ["development-tools::cargo-plugins"]
repository = "https://github.com/LedgerHQ/cargo-ledger"
Expand Down
69 changes: 22 additions & 47 deletions cargo-ledger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,18 @@ use utils::*;
mod setup;
mod utils;

/// Structure for retrocompatibility, when the cargo manifest file
/// contains a single `[package.metadata.nanos]` section
#[derive(Debug, Deserialize)]
struct NanosMetadata {
curve: Vec<String>,
path: Vec<String>,
flags: String,
icon: String,
icon_small: String,
name: Option<String>,
}

#[derive(Debug, Deserialize)]
struct LedgerMetadata {
curve: Vec<String>,
path: Vec<String>,
flags: String,
flags: Option<String>,
name: Option<String>,
}

#[derive(Debug, Deserialize)]
struct DeviceMetadata {
icon: String,
flags: Option<String>,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -123,7 +112,7 @@ fn main() {
fn retrieve_metadata(
device: Device,
manifest_path: Option<&str>,
) -> (Package, LedgerMetadata, DeviceMetadata) {
) -> Result<(Package, LedgerMetadata, DeviceMetadata), ()> {
let mut cmd = cargo_metadata::MetadataCommand::new();

// Only used during tests
Expand Down Expand Up @@ -154,31 +143,10 @@ fn retrieve_metadata(
serde_json::from_value(metadata_device)
.expect("Could not deserialize device medatada");

(this_pkg.clone(), ledger_metadata, device_metadata)
Ok((this_pkg.clone(), ledger_metadata, device_metadata))
} else {
println!("WARNING: 'package.metadata.ledger' section is missing in Cargo.toml, trying 'package.metadata.nanos'");
let nanos_section = this_pkg.metadata.get("nanos").expect(
"No appropriate [package.metadata.<ledger|nanos>] section found.",
);

let nanos_metadata: NanosMetadata =
serde_json::from_value(nanos_section.clone())
.expect("Could not deserialize medatada.nanos");
let ledger_metadata = LedgerMetadata {
curve: nanos_metadata.curve,
path: nanos_metadata.path,
flags: nanos_metadata.flags,
name: nanos_metadata.name,
};

let device_metadata = DeviceMetadata {
icon: match device {
Device::Nanos => nanos_metadata.icon,
_ => nanos_metadata.icon_small,
},
};

(this_pkg.clone(), ledger_metadata, device_metadata)
println!("No metadata found for device: {}", device);
Err(())
}
}

Expand Down Expand Up @@ -263,7 +231,7 @@ fn build_app(
};

let (this_pkg, metadata_ledger, metadata_device) =
retrieve_metadata(device, None);
retrieve_metadata(device, None).unwrap();

let package_path = this_pkg
.manifest_path
Expand Down Expand Up @@ -291,14 +259,21 @@ fn build_app(
// Retrieve real data size and SDK infos from ELF
let infos = retrieve_infos(&exe_path).unwrap();

// Modify flags to enable BLE if targeting Nano X
let flags = match device {
Device::Nanos | Device::Nanosplus => metadata_ledger.flags,
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)
}
let flags = match metadata_device.flags {
Some(flags) => flags,
None => match metadata_ledger.flags {
Some(flags) => match device {
// Modify flags to enable BLE if targeting Nano X
Device::Nanos | Device::Nanosplus => flags,
Device::Nanox | Device::Stax | Device::Flex => {
let base =
u32::from_str_radix(flags.trim_start_matches("0x"), 16)
.unwrap_or(0);
format!("0x{:x}", base | 0x200)
}
},
None => String::from("0x000"),
},
};

// Target ID according to target, in case it
Expand Down
Loading