Skip to content

Commit 9cddb81

Browse files
authored
Merge pull request #192 from LedgerHQ/y333/settings_nvm_management
Y333/settings nvm management
2 parents 9a34887 + bb87dcd commit 9cddb81

13 files changed

+60
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger_device_sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.17.0"
3+
version = "1.17.1"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true

ledger_device_sdk/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<T> NVMData<T> {
135135
/// because a static mutable will be assumed to be located in
136136
/// RAM, and be accessed through the static base (r9)
137137
#[cfg(not(target_os = "nanos"))]
138-
pub fn get_mut(&mut self) -> &mut T {
138+
fn get_addr(&self) -> *mut T {
139139
use core::arch::asm;
140140
unsafe {
141141
// Compute offset in .nvm_data by taking the reference to
@@ -145,11 +145,25 @@ impl<T> NVMData<T> {
145145
asm!( "mov {}, r9", out(reg) static_base);
146146
let offset = (addr - static_base) as isize;
147147
let data_addr = (_nvm_data_start as *const u8).offset(offset);
148-
let pic_addr =
149-
ledger_secure_sdk_sys::pic(data_addr as *mut core::ffi::c_void) as *mut T;
148+
ledger_secure_sdk_sys::pic(data_addr as *mut core::ffi::c_void) as *mut T
149+
}
150+
}
151+
152+
#[cfg(not(target_os = "nanos"))]
153+
pub fn get_mut(&mut self) -> &mut T {
154+
unsafe {
155+
let pic_addr = self.get_addr();
150156
&mut *pic_addr.cast()
151157
}
152158
}
159+
160+
#[cfg(not(target_os = "nanos"))]
161+
pub fn get_ref(&self) -> &T {
162+
unsafe {
163+
let pic_addr = self.get_addr();
164+
&*pic_addr.cast()
165+
}
166+
}
153167
}
154168

155169
#[cfg(test)]

ledger_device_sdk/src/nbgl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ trait SyncNBGL: Sized {
7777
}
7878
}
7979

80-
fn ux_sync_wait(&mut self, exit_on_apdu: bool) -> SyncNbgl {
80+
fn ux_sync_wait(&self, exit_on_apdu: bool) -> SyncNbgl {
8181
unsafe {
8282
if let Some(comm) = COMM_REF.as_mut() {
8383
while !G_ENDED {

ledger_device_sdk/src/nbgl/nbgl_address_review.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> NbglAddressReview<'a> {
3131
}
3232
}
3333

34-
pub fn show(&mut self, address: &str) -> bool {
34+
pub fn show(&self, address: &str) -> bool {
3535
unsafe {
3636
let icon: nbgl_icon_details_t = match self.glyph {
3737
Some(g) => g.into(),

ledger_device_sdk/src/nbgl/nbgl_choice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'a> NbglChoice<'a> {
2222
}
2323

2424
pub fn show(
25-
&mut self,
25+
&self,
2626
message: &str,
2727
sub_message: &str,
2828
confirm_text: &str,

ledger_device_sdk/src/nbgl/nbgl_generic_review.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl InfoButton {
111111
/// using the NbglGenericReview struct.
112112
pub struct TagValueList {
113113
pairs: Vec<nbgl_contentTagValue_t>,
114-
items: Vec<CString>,
115-
values: Vec<CString>,
114+
_items: Vec<CString>,
115+
_values: Vec<CString>,
116116
nb_max_lines_for_value: u8,
117117
small_case_for_value: bool,
118118
wrapping: bool,
@@ -142,8 +142,8 @@ impl TagValueList {
142142
}
143143
TagValueList {
144144
pairs: c_field_strings,
145-
items: c_field_names,
146-
values: c_field_values,
145+
_items: c_field_names,
146+
_values: c_field_values,
147147
nb_max_lines_for_value,
148148
small_case_for_value,
149149
wrapping,
@@ -199,7 +199,7 @@ impl TagValueConfirm {
199199
/// when using the NbglGenericReview struct.
200200
pub struct InfosList {
201201
info_types_cstrings: Vec<CString>,
202-
info_contents_cstrings: Vec<CString>,
202+
_info_contents_cstrings: Vec<CString>,
203203
info_types_ptr: Vec<*const c_char>,
204204
info_contents_ptr: Vec<*const c_char>,
205205
}
@@ -220,7 +220,7 @@ impl InfosList {
220220
info_contents_cstrings.iter().map(|s| s.as_ptr()).collect();
221221
InfosList {
222222
info_types_cstrings: info_types_cstrings,
223-
info_contents_cstrings: info_contents_cstrings,
223+
_info_contents_cstrings: info_contents_cstrings,
224224
info_types_ptr: info_types_ptr,
225225
info_contents_ptr: info_contents_ptr,
226226
}
@@ -413,7 +413,7 @@ impl NbglGenericReview {
413413
.collect()
414414
}
415415

416-
pub fn show(&mut self, reject_button_str: &str) -> bool {
416+
pub fn show(&self, reject_button_str: &str) -> bool {
417417
unsafe {
418418
let c_content_list: Vec<nbgl_content_t> = self.to_c_content_list();
419419

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const INFO_FIELDS: [*const c_char; 2] = [
3838
"Developer\0".as_ptr() as *const c_char,
3939
];
4040

41+
pub enum PageIndex {
42+
Settings(u8),
43+
Home,
44+
}
45+
4146
/// Used to display the home screen of the application, with an optional glyph,
4247
/// information fields, and settings switches.
4348
pub struct NbglHomeAndSettings {
@@ -50,6 +55,7 @@ pub struct NbglHomeAndSettings {
5055
generic_contents: nbgl_genericContents_t,
5156
info_list: nbgl_contentInfoList_t,
5257
icon: nbgl_icon_details_t,
58+
start_page: PageIndex,
5359
}
5460

5561
impl SyncNBGL for NbglHomeAndSettings {}
@@ -76,6 +82,7 @@ impl<'a> NbglHomeAndSettings {
7682
generic_contents: nbgl_genericContents_t::default(),
7783
info_list: nbgl_contentInfoList_t::default(),
7884
icon: nbgl_icon_details_t::default(),
85+
start_page: PageIndex::Home,
7986
}
8087
}
8188

@@ -127,6 +134,13 @@ impl<'a> NbglHomeAndSettings {
127134
}
128135
}
129136

137+
pub fn set_start_page(self, page: PageIndex) -> NbglHomeAndSettings {
138+
NbglHomeAndSettings {
139+
start_page: page,
140+
..self
141+
}
142+
}
143+
130144
/// Show the home screen and settings page.
131145
/// This function will block until an APDU is received or the user quits the app.
132146
/// DEPRECATED as it constraints to refresh screen for every received APDU.
@@ -186,7 +200,10 @@ impl<'a> NbglHomeAndSettings {
186200
self.app_name.as_ptr() as *const c_char,
187201
&self.icon as *const nbgl_icon_details_t,
188202
core::ptr::null(),
189-
INIT_HOME_PAGE as u8,
203+
match self.start_page {
204+
PageIndex::Home => INIT_HOME_PAGE as u8,
205+
PageIndex::Settings(idx) => idx,
206+
},
190207
&self.generic_contents as *const nbgl_genericContents_t,
191208
&self.info_list as *const nbgl_contentInfoList_t,
192209
core::ptr::null(),
@@ -263,7 +280,10 @@ impl<'a> NbglHomeAndSettings {
263280
self.app_name.as_ptr() as *const c_char,
264281
&self.icon as *const nbgl_icon_details_t,
265282
core::ptr::null(),
266-
INIT_HOME_PAGE as u8,
283+
match self.start_page {
284+
PageIndex::Home => INIT_HOME_PAGE as u8,
285+
PageIndex::Settings(idx) => idx,
286+
},
267287
&self.generic_contents as *const nbgl_genericContents_t,
268288
&self.info_list as *const nbgl_contentInfoList_t,
269289
core::ptr::null(),

ledger_device_sdk/src/nbgl/nbgl_review.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a> NbglReview<'a> {
6666
}
6767
}
6868

69-
pub fn show(&mut self, fields: &[Field]) -> bool {
69+
pub fn show(&self, fields: &[Field]) -> bool {
7070
unsafe {
7171
let v: Vec<CField> = fields
7272
.iter()

ledger_device_sdk/src/nbgl/nbgl_review_status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a> NbglReviewStatus {
1919
NbglReviewStatus { status_type }
2020
}
2121

22-
pub fn show(&mut self, success: bool) {
22+
pub fn show(&self, success: bool) {
2323
unsafe {
2424
self.ux_sync_init();
2525
nbgl_useCaseReviewStatus(self.status_type.to_message(success), Some(quit_callback));

0 commit comments

Comments
 (0)