Skip to content

Commit

Permalink
Do not define API level field for Nano S
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Nov 23, 2023
1 parent 459451b commit b927bd0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
31 changes: 16 additions & 15 deletions ledger_secure_sdk_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Device {
#[derive(Default)]
struct SDKInfo {
pub bolos_sdk: PathBuf,
pub api_level: u32,
pub api_level: Option<u32>,
pub target_id: String,
pub target_name: String,
pub c_sdk_name: String,
Expand Down Expand Up @@ -163,14 +163,14 @@ fn retrieve_sdk_git_info(bolos_sdk: &Path) -> (String, String) {
(c_sdk_hash, c_sdk_version)
}

fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(u32, String), SDKBuildError> {
fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(Option<u32>, String), SDKBuildError> {
let makefile_defines =
File::open(bolos_sdk.join("Makefile.defines")).expect("Could not find Makefile.defines");
let mut api_level: Option<u32> = None;
let mut sdk_name: Option<String> = None;
for line in BufReader::new(makefile_defines).lines().flatten() {
if let Some(value) = line.split(":=").nth(1).map(str::trim) {
if line.contains("API_LEVEL") && api_level.is_none() {
if line.contains("API_LEVEL") && api_level.is_none() {
api_level = Some(value.parse().map_err(|_| SDKBuildError::InvalidAPILevel)?);
} else if line.contains("SDK_NAME") && sdk_name.is_none() {
sdk_name = Some(value.to_string().replace("\"", ""));
Expand All @@ -182,11 +182,8 @@ fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(u32, String), SDKBuildEr
break;
}
}

let api_level = api_level.ok_or(SDKBuildError::InvalidAPILevel)?;
let sdk_name = sdk_name.ok_or(SDKBuildError::MissingSDKName)?;

Ok((api_level as u32, sdk_name))
Ok((api_level, sdk_name))
}

fn retrieve_target_file_infos(
Expand Down Expand Up @@ -348,15 +345,19 @@ impl SDKBuilder {
let sdk_info = retrieve_sdk_info(&self.device, &sdk_path)?;

self.bolos_sdk = sdk_info.bolos_sdk;
self.api_level = sdk_info.api_level;

// Export SDK infos into env for 'infos.rs'
println!("cargo:rustc-env=API_LEVEL={}", self.api_level);
println!(
"cargo:rustc-env=API_LEVEL_STR={}",
format!("{}", self.api_level)
);
println!("cargo:warning=API_LEVEL is {}", self.api_level);
match sdk_info.api_level {
Some(api_level) => {
self.api_level = api_level;
// Export api level into env for 'infos.rs'
println!("cargo:rustc-env=API_LEVEL={}", self.api_level);
println!("cargo:warning=API_LEVEL is {}", self.api_level);
}
None => if self.device != Device::NanoS {
return Err(SDKBuildError::InvalidAPILevel);
},
}
// Export other SDK infos into env for 'infos.rs'
println!("cargo:rustc-env=TARGET_ID={}", sdk_info.target_id);
println!("cargo:warning=TARGET_ID is {}", sdk_info.target_id);
println!("cargo:rustc-env=TARGET_NAME={}", sdk_info.target_name);
Expand Down
5 changes: 4 additions & 1 deletion ledger_secure_sdk_sys/src/infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ const fn const_parse_api_level(x: &str) -> u8 {

/// Expose the API_LEVEL
#[used]
#[cfg(not(target_os = "nanos"))]
static API_LEVEL: u8 = const_parse_api_level(env!("API_LEVEL"));

// Store metadata in the ELF file
const_cstr!(ELF_API_LEVEL, "ledger.api_level", env!("API_LEVEL_STR"));
#[cfg(not(target_os = "nanos"))]
const_cstr!(ELF_API_LEVEL, "ledger.api_level", env!("API_LEVEL"));

const_cstr!(ELF_TARGET, "ledger.target", env!("TARGET"));
const_cstr!(ELF_TARGET_ID, "ledger.target_id", env!("TARGET_ID"));
const_cstr!(ELF_TARGET_NAME, "ledger.target_name", env!("TARGET_NAME"));
Expand Down

0 comments on commit b927bd0

Please sign in to comment.