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

Y333/nbgl support for nanos #241

Merged
merged 29 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6136cd1
Move custom target files into cargo-ledger crate
yogh333 Feb 5, 2025
2dfc857
Update cargo ledger setup
yogh333 Feb 5, 2025
4b01fd8
Manage unknown device
yogh333 Feb 6, 2025
7c47bb9
Move custom targets and link files into sys crate
yogh333 Feb 6, 2025
19bf4b1
Use RUST_NIGHTLY env variable for setup target files
yogh333 Feb 6, 2025
b1e46a1
Fix C SDK info
yogh333 Feb 7, 2025
28ef844
Use single file for glyphs
yogh333 Feb 10, 2025
4386359
Enable NBGL for Nano S+ and Nano X
yogh333 Feb 10, 2025
4524cbb
Cleanup header files
yogh333 Feb 11, 2025
49105be
Update header for each target
yogh333 Feb 11, 2025
a8fd126
Add build.rs time monitoring
yogh333 Feb 11, 2025
963d75d
Update CFLAGS (same as C SDK)
yogh333 Feb 12, 2025
5d507fa
Remove CCID feature
yogh333 Feb 12, 2025
d5c29ed
Remove CCID feature bis
yogh333 Feb 12, 2025
327e86e
remove device match in bindings
yogh333 Feb 13, 2025
754ff65
Cleanup
yogh333 Feb 13, 2025
be9b7c2
Add libm.a and libgcc.a for linking + os_printf.c shall be built for …
yogh333 Feb 14, 2025
348a162
Add nbgl feature
yogh333 Feb 14, 2025
17e3a8b
Rename header files
yogh333 Feb 14, 2025
b5fd671
Move linker files from sdk crate to sys crate
yogh333 Feb 14, 2025
74756bb
Set the C SDK path in Device
yogh333 Feb 14, 2025
4a47de6
rename bolos_sdk as c_sdk
yogh333 Feb 17, 2025
6320ef2
Move glyphs_folders into Device
yogh333 Feb 17, 2025
33c5b7a
Set arm libs path in Device
yogh333 Feb 17, 2025
30f43b3
Move local functions
yogh333 Feb 17, 2025
80a8e2e
Update linker script name in custom targets for Stax and Flex
yogh333 Feb 17, 2025
f0a2b82
Move linker script in Device
yogh333 Feb 17, 2025
e226641
Enable NBGL build for all Nano* devices
yogh333 Feb 18, 2025
9076acc
Bump versions
yogh333 Feb 18, 2025
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cargo-ledger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-ledger"
version = "1.6.0"
version = "1.7.0"
authors = ["yhql", "agrojean-ledger", "y333"]
description = "Build and sideload Ledger devices apps"
categories = ["development-tools::cargo-plugins"]
Expand Down
28 changes: 24 additions & 4 deletions cargo-ledger/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
use std::path::Path;
use std::process::Command;
use std::str::from_utf8;

pub fn install_targets() {
println!("[ ] Checking for installed custom targets...");
println!("[ ] Install custom targets...");
// Check if target files are installed
let mut args: Vec<String> = vec![];
match std::env::var("RUST_NIGHTLY") {
Ok(version) => {
println!(
"Install custom targets for nightly toolchain: {}",
version
);
args.push(format!("+{}", version));
}
Err(_) => {
let rustup_cmd =
Command::new("rustup").arg("default").output().unwrap();
println!(
"Install custom targets for default toolchain {}",
from_utf8(rustup_cmd.stdout.as_slice()).unwrap()
);
}
}
args.push(String::from("--print"));
args.push(String::from("sysroot"));
let sysroot_cmd = Command::new("rustc")
.arg("--print")
.arg("sysroot")
.args(&args)
.output()
.expect("failed to call rustc")
.stdout;
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/a7fb841160df34b8de268b136704c8b2ed8f9973/ledger_device_sdk/"
"https://raw.githubusercontent.com/LedgerHQ/ledger-device-rust-sdk/refs/tags/ledger_secure_sdk_sys%401.7.0/ledger_secure_sdk_sys"
);
let sysroot = Path::new(sysroot_cmd).join("lib").join("rustlib");

Expand Down
6 changes: 3 additions & 3 deletions ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.20.4"
version = "1.21.0"
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
edition = "2021"
license.workspace = true
Expand All @@ -21,13 +21,13 @@ rand_core = { version = "0.6.3", default-features = false }
zeroize = { version = "1.6.0", default-features = false }
numtoa = "0.2.4"
const-zero = "0.1.1"
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.6.7" }
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.7.0" }

[features]
debug = []
speculos = []
ccid = []
heap = [ "ledger_secure_sdk_sys/heap" ]
nbgl = [ "ledger_secure_sdk_sys/nbgl" ]

default = [ "heap" ]

Expand Down
43 changes: 0 additions & 43 deletions ledger_device_sdk/build.rs

This file was deleted.

11 changes: 0 additions & 11 deletions ledger_device_sdk/src/ccid.rs

This file was deleted.

10 changes: 4 additions & 6 deletions ledger_device_sdk/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use ledger_secure_sdk_sys::buttons::{get_button_event, ButtonEvent, ButtonsState
use ledger_secure_sdk_sys::seph as sys_seph;
use ledger_secure_sdk_sys::*;

#[cfg(feature = "ccid")]
use crate::ccid;
use crate::seph;
use core::convert::{Infallible, TryFrom};
use core::ops::{Index, IndexMut};
Expand Down Expand Up @@ -193,10 +191,6 @@ impl Comm {
sys_seph::seph_send(&[sys_seph::SephTags::RawAPDU as u8, len[0], len[1]]);
sys_seph::seph_send(&self.apdu_buffer[..self.tx]);
}
#[cfg(feature = "ccid")]
APDU_USB_CCID => {
ccid::send(&self.apdu_buffer[..self.tx]);
}
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
APDU_BLE => {
ble::send(&self.apdu_buffer[..self.tx]);
Expand Down Expand Up @@ -378,6 +372,10 @@ impl Comm {
match seph::Events::from(tag) {
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
seph::Events::ButtonPush => {
#[cfg(feature = "nbgl")]
unsafe {
ux_process_button_event(spi_buffer.as_mut_ptr());
}
let button_info = spi_buffer[3] >> 1;
if let Some(btn_evt) = get_button_event(&mut self.buttons, button_info) {
return Some(Event::Button(btn_evt));
Expand Down
6 changes: 2 additions & 4 deletions ledger_device_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
pub mod ble;

#[cfg(feature = "ccid")]
pub mod ccid;
pub mod ecc;
pub mod hash;
pub mod hmac;
Expand All @@ -24,9 +22,9 @@ pub mod seph;

pub mod testing;

#[cfg(any(target_os = "stax", target_os = "flex"))]
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nbgl"))]
pub mod nbgl;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
#[cfg(not(any(target_os = "stax", target_os = "flex", feature = "nbgl")))]
pub mod ui;

pub mod uxapp;
Expand Down
4 changes: 4 additions & 0 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ledger_secure_sdk_sys::*;

pub mod nbgl_address_review;
pub mod nbgl_choice;
#[cfg(any(target_os = "stax", target_os = "flex"))]
pub mod nbgl_generic_review;
pub mod nbgl_home_and_settings;
pub mod nbgl_review;
Expand All @@ -20,6 +21,7 @@ pub mod nbgl_streaming_review;

pub use nbgl_address_review::*;
pub use nbgl_choice::*;
#[cfg(any(target_os = "stax", target_os = "flex"))]
pub use nbgl_generic_review::*;
pub use nbgl_home_and_settings::*;
pub use nbgl_review::*;
Expand Down Expand Up @@ -105,6 +107,7 @@ unsafe extern "C" fn quit_callback() {
G_ENDED = true;
}

#[cfg(any(target_os = "stax", target_os = "flex"))]
unsafe extern "C" fn rejected_callback() {
G_RET = SyncNbgl::UxSyncRetRejected.into();
G_ENDED = true;
Expand Down Expand Up @@ -274,6 +277,7 @@ pub enum TuneIndex {
// Direct translation of the C original. This was done to
// avoid compiling `os_io_seproxyhal.c` which includes many other things
#[no_mangle]
#[cfg(any(target_os = "stax", target_os = "flex"))]
extern "C" fn io_seproxyhal_play_tune(tune_index: u8) {
let mut buffer = [0u8; 4];
let mut spi_buffer = [0u8; 128];
Expand Down
10 changes: 8 additions & 2 deletions ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ impl<'a> NbglHomeAndSettings {
};
SWITCH_ARRAY[i].initState = state;
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
}
}

self.content = nbgl_content_t {
Expand Down Expand Up @@ -257,7 +260,10 @@ impl<'a> NbglHomeAndSettings {
};
SWITCH_ARRAY[i].initState = state;
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
}
}

self.content = nbgl_content_t {
Expand Down
4 changes: 2 additions & 2 deletions ledger_secure_sdk_sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_secure_sdk_sys"
version = "1.6.7"
version = "1.7.0"
authors = ["yhql", "agrojean-ledger", "yogh333"]
edition = "2021"
license.workspace = true
Expand All @@ -18,7 +18,7 @@ critical-section = { version = "1.1.2", optional = true }

[features]
heap = ["dep:embedded-alloc", "dep:critical-section"]
ccid = []
nbgl = []

[lints.rust.unexpected_cfgs]
level = "warn"
Expand Down
Loading
Loading