Skip to content

Commit 552a800

Browse files
authored
Merge pull request #241 from LedgerHQ/y333/nbgl_support_for_nanos
Y333/nbgl support for nanos
2 parents ad901b5 + 9076acc commit 552a800

39 files changed

+1102
-763
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-ledger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-ledger"
3-
version = "1.6.0"
3+
version = "1.7.0"
44
authors = ["yhql", "agrojean-ledger", "y333"]
55
description = "Build and sideload Ledger devices apps"
66
categories = ["development-tools::cargo-plugins"]

cargo-ledger/src/setup.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
use std::path::Path;
22
use std::process::Command;
3+
use std::str::from_utf8;
34

45
pub fn install_targets() {
5-
println!("[ ] Checking for installed custom targets...");
6+
println!("[ ] Install custom targets...");
67
// Check if target files are installed
8+
let mut args: Vec<String> = vec![];
9+
match std::env::var("RUST_NIGHTLY") {
10+
Ok(version) => {
11+
println!(
12+
"Install custom targets for nightly toolchain: {}",
13+
version
14+
);
15+
args.push(format!("+{}", version));
16+
}
17+
Err(_) => {
18+
let rustup_cmd =
19+
Command::new("rustup").arg("default").output().unwrap();
20+
println!(
21+
"Install custom targets for default toolchain {}",
22+
from_utf8(rustup_cmd.stdout.as_slice()).unwrap()
23+
);
24+
}
25+
}
26+
args.push(String::from("--print"));
27+
args.push(String::from("sysroot"));
728
let sysroot_cmd = Command::new("rustc")
8-
.arg("--print")
9-
.arg("sysroot")
29+
.args(&args)
1030
.output()
1131
.expect("failed to call rustc")
1232
.stdout;
1333
let sysroot_cmd = std::str::from_utf8(&sysroot_cmd).unwrap().trim();
1434

1535
let target_files_url = Path::new(
16-
"https://raw.githubusercontent.com/LedgerHQ/ledger-device-rust-sdk/a7fb841160df34b8de268b136704c8b2ed8f9973/ledger_device_sdk/"
36+
"https://raw.githubusercontent.com/LedgerHQ/ledger-device-rust-sdk/refs/tags/ledger_secure_sdk_sys%401.7.0/ledger_secure_sdk_sys"
1737
);
1838
let sysroot = Path::new(sysroot_cmd).join("lib").join("rustlib");
1939

ledger_device_sdk/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.20.4"
3+
version = "1.21.0"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true
@@ -21,13 +21,13 @@ rand_core = { version = "0.6.3", default-features = false }
2121
zeroize = { version = "1.6.0", default-features = false }
2222
numtoa = "0.2.4"
2323
const-zero = "0.1.1"
24-
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.6.7" }
24+
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.7.0" }
2525

2626
[features]
2727
debug = []
2828
speculos = []
29-
ccid = []
3029
heap = [ "ledger_secure_sdk_sys/heap" ]
30+
nbgl = [ "ledger_secure_sdk_sys/nbgl" ]
3131

3232
default = [ "heap" ]
3333

ledger_device_sdk/build.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

ledger_device_sdk/src/ccid.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

ledger_device_sdk/src/io.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use ledger_secure_sdk_sys::buttons::{get_button_event, ButtonEvent, ButtonsState
55
use ledger_secure_sdk_sys::seph as sys_seph;
66
use ledger_secure_sdk_sys::*;
77

8-
#[cfg(feature = "ccid")]
9-
use crate::ccid;
108
use crate::seph;
119
use core::convert::{Infallible, TryFrom};
1210
use core::ops::{Index, IndexMut};
@@ -193,10 +191,6 @@ impl Comm {
193191
sys_seph::seph_send(&[sys_seph::SephTags::RawAPDU as u8, len[0], len[1]]);
194192
sys_seph::seph_send(&self.apdu_buffer[..self.tx]);
195193
}
196-
#[cfg(feature = "ccid")]
197-
APDU_USB_CCID => {
198-
ccid::send(&self.apdu_buffer[..self.tx]);
199-
}
200194
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
201195
APDU_BLE => {
202196
ble::send(&self.apdu_buffer[..self.tx]);
@@ -378,6 +372,10 @@ impl Comm {
378372
match seph::Events::from(tag) {
379373
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
380374
seph::Events::ButtonPush => {
375+
#[cfg(feature = "nbgl")]
376+
unsafe {
377+
ux_process_button_event(spi_buffer.as_mut_ptr());
378+
}
381379
let button_info = spi_buffer[3] >> 1;
382380
if let Some(btn_evt) = get_button_event(&mut self.buttons, button_info) {
383381
return Some(Event::Button(btn_evt));

ledger_device_sdk/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
1111
pub mod ble;
1212

13-
#[cfg(feature = "ccid")]
14-
pub mod ccid;
1513
pub mod ecc;
1614
pub mod hash;
1715
pub mod hmac;
@@ -24,9 +22,9 @@ pub mod seph;
2422

2523
pub mod testing;
2624

27-
#[cfg(any(target_os = "stax", target_os = "flex"))]
25+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nbgl"))]
2826
pub mod nbgl;
29-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
27+
#[cfg(not(any(target_os = "stax", target_os = "flex", feature = "nbgl")))]
3028
pub mod ui;
3129

3230
pub mod uxapp;

ledger_device_sdk/src/nbgl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ledger_secure_sdk_sys::*;
1010

1111
pub mod nbgl_address_review;
1212
pub mod nbgl_choice;
13+
#[cfg(any(target_os = "stax", target_os = "flex"))]
1314
pub mod nbgl_generic_review;
1415
pub mod nbgl_home_and_settings;
1516
pub mod nbgl_review;
@@ -20,6 +21,7 @@ pub mod nbgl_streaming_review;
2021

2122
pub use nbgl_address_review::*;
2223
pub use nbgl_choice::*;
24+
#[cfg(any(target_os = "stax", target_os = "flex"))]
2325
pub use nbgl_generic_review::*;
2426
pub use nbgl_home_and_settings::*;
2527
pub use nbgl_review::*;
@@ -105,6 +107,7 @@ unsafe extern "C" fn quit_callback() {
105107
G_ENDED = true;
106108
}
107109

110+
#[cfg(any(target_os = "stax", target_os = "flex"))]
108111
unsafe extern "C" fn rejected_callback() {
109112
G_RET = SyncNbgl::UxSyncRetRejected.into();
110113
G_ENDED = true;
@@ -274,6 +277,7 @@ pub enum TuneIndex {
274277
// Direct translation of the C original. This was done to
275278
// avoid compiling `os_io_seproxyhal.c` which includes many other things
276279
#[no_mangle]
280+
#[cfg(any(target_os = "stax", target_os = "flex"))]
277281
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
278282
let mut buffer = [0u8; 4];
279283
let mut spi_buffer = [0u8; 128];

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ impl<'a> NbglHomeAndSettings {
173173
};
174174
SWITCH_ARRAY[i].initState = state;
175175
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
176-
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
176+
#[cfg(any(target_os = "stax", target_os = "flex"))]
177+
{
178+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
179+
}
177180
}
178181

179182
self.content = nbgl_content_t {
@@ -257,7 +260,10 @@ impl<'a> NbglHomeAndSettings {
257260
};
258261
SWITCH_ARRAY[i].initState = state;
259262
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
260-
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
263+
#[cfg(any(target_os = "stax", target_os = "flex"))]
264+
{
265+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
266+
}
261267
}
262268

263269
self.content = nbgl_content_t {

0 commit comments

Comments
 (0)