-
Notifications
You must be signed in to change notification settings - Fork 32
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
Update ELF metadata #88
Conversation
483b180
to
8697436
Compare
8697436
to
bf3db8b
Compare
build.rs
Outdated
// scott could use for_each | ||
command.define(define, None); | ||
} | ||
extract_defines_from_cx_makefile(&mut command, &cx_makefile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this for better readability but we can remove it.. Not related to what this PR is supposed to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in #96
@yhql I am missing APPNAME and APPVERSION, do you know how to add them when the rust SDK's build.rs is called ? |
src/infos.rs
Outdated
static ELF_API_LEVEL: [u8;4] = if cfg!(target_os = "nanos"){ | ||
*b"0\n\0\0" | ||
} else if cfg!(target_os = "nanox") { | ||
*b"5\n\0\0" | ||
} else if cfg!(target_os = "nanosplus") { | ||
*b"1\n\0\0" | ||
} else { | ||
*b"255\n" | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to be retrieved from the SDK, but this for after the change of architecture I guess?
Also, to be consistent with C sdk, the value for nanos should be : undefined, e.g. section doesn't exist.
and the else value might be the same ? Or a build error cause that's just invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes in the new SDK we will grab it from the C SDK, it is already done actually here https://github.com/LedgerHQ/secure-sdk-rust/blob/f78cb5803b47de24ef7b2b0323b8b08ad31f7399/build.rs#L180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
static ELF_TARGET: [u8; 8] = if cfg!(target_os = "nanos") { | ||
*b"nanos\n\0\0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there solutions to avoid these trailing "\n\0"? It seems a bit weird having them everywhere as I guess htey won't be used by the tools reading elf sections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
We could use the following code:
let mut elf_target: [u8; 8] = [0u8; 8];
let _ = &mut elf_target[..5].copy_from_slice("nanos".as_bytes());
but cannot be called to define static
const 😞 (and not sure it enhances readability)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I propose to keep it as it is currently (until better proposal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how these trailing \n and \0 will affect our tools reading metadata? Mostly Speculos and LedgerBlue for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #96
@@ -5,6 +5,7 @@ | |||
#![test_runner(testing::sdk_test_runner)] | |||
#![allow(incomplete_features)] | |||
#![feature(generic_const_exprs)] | |||
#![feature(const_cmp)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not find this nightly feature in Unstable Book.
- How did you find it ?
- Where is it used ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yogh333 it's for let min_length = core::cmp::min(bytes.len(), MAX_METADATA_STRING_SIZE - 1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But with @yhql 's proposed solution for strings, we probably would not need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for how I found it, I can't remember ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this if we replace this min
by a more manual version:
let min_length = if bytes.len() <= MAX_METADATA_STRING_SIZE - 1 {
bytes.len()
} else {
MAX_METADATA_STRING_SIZE - 1
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in #96
#[used] | ||
#[link_section = "ledger.api_level"] | ||
static ELF_API_LEVEL: [u8; 4] = if cfg!(target_os = "nanos") { | ||
*b"0\n\0\0" | ||
} else if cfg!(target_os = "nanox") { | ||
*b"5\n\0\0" | ||
} else if cfg!(target_os = "nanosplus") { | ||
*b"1\n\0\0" | ||
} else { | ||
*b"255\n" | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be update now that API_LEVEL is now at build time from SDK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
result | ||
} | ||
|
||
/// Expose the API_LEVEL to the app | ||
#[used] | ||
static API_LEVEL: u8 = if cfg!(target_os = "nanos") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be update to with proper value knwon at build time ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
|
||
#[used] | ||
#[link_section = "ledger.sdk_hash"] | ||
static ELF_SDK_HASH: [u8; 5] = *b"None\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can live with this, but best would be having the hash of the C SDK used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
|
||
#[used] | ||
#[link_section = "ledger.sdk_name"] | ||
static ELF_SDK_NAME: [u8; 18] = *b"ledger-secure-sdk\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case of a nano, with should probably set nanos-secure-sdk
as it doesn't use the unified one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
|
||
#[used] | ||
#[link_section = "ledger.sdk_version"] | ||
static ELF_SDK_VERSION: [u8; 5] = *b"None\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for the hash, would be best to have the real C SDK version, else that is not a drama.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #96
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some stuff could be up^date now that we use ledger_secure_sdk_sys crate.
We could use the env declared here: https://github.com/LedgerHQ/ledger-device-rust-sdk/blob/master/ledger_secure_sdk_sys/build.rs#L208-L210
And maybe add some more to populate properly SDK_HASH / SDK_NAME and SDK_VERSION ?
Replaced by #96 |
Update infos.rs (add more metadatas to match C SDK)
Still missing :