Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions tbf-parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,9 @@ impl TbfHeader {
match *self {
TbfHeader::TbfHeaderV2(hd) => {
if hd.program.is_some() {
hd.program.map_or(0, |p| {
(hd.base.header_size as u32) + p.protected_trailer_size
})
hd.program.map_or(0, |p| p.protected_trailer_size)
} else if hd.main.is_some() {
hd.main.map_or(0, |m| {
(hd.base.header_size as u32) + m.protected_trailer_size
})
hd.main.map_or(0, |m| m.protected_trailer_size)
} else {
0
}
Expand All @@ -990,11 +986,9 @@ impl TbfHeader {
match *self {
TbfHeader::TbfHeaderV2(hd) => {
if hd.program.is_some() {
hd.program
.map_or(0, |p| p.init_fn_offset + (hd.base.header_size as u32))
hd.program.map_or(0, |p| p.init_fn_offset)
} else if hd.main.is_some() {
hd.main
.map_or(0, |m| m.init_fn_offset + (hd.base.header_size as u32))
hd.main.map_or(0, |m| m.init_fn_offset)
} else {
0
}
Expand Down Expand Up @@ -1175,6 +1169,14 @@ impl TbfHeader {
}
}

/// Return the TBF version
pub fn get_tbf_version(&self) -> u16 {
match self {
TbfHeader::TbfHeaderV2(hd) => hd.base.version,
_ => 0,
}
}

Comment on lines +1172 to +1179
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add this function?

/// Return the fixed ShortId of the application if it was specified in the
/// TBF header.
pub fn get_fixed_short_id(&self) -> Option<core::num::NonZeroU32> {
Expand Down
12 changes: 6 additions & 6 deletions tbf-parser/tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn simple_tbf() {
dbg!(&header);
assert!(header.enabled());
assert_eq!(header.get_minimum_app_ram_size(), 4848);
assert_eq!(header.get_init_function_offset(), 41 + header_len as u32);
assert_eq!(header.get_protected_size(), header_len as u32);
assert_eq!(header.get_init_function_offset(), 41);
assert_eq!(header.get_protected_size(), 0);
assert_eq!(header.get_package_name().unwrap(), "_heart");
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
}
Expand All @@ -37,8 +37,8 @@ fn footer_sha256() {
dbg!(&header);
assert!(header.enabled());
assert_eq!(header.get_minimum_app_ram_size(), 4848);
assert_eq!(header.get_init_function_offset(), 41 + header_len as u32);
assert_eq!(header.get_protected_size(), header_len as u32);
assert_eq!(header.get_init_function_offset(), 41);
assert_eq!(header.get_protected_size(), 0);
assert_eq!(header.get_package_name().unwrap(), "_heart");
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
let binary_offset = header.get_binary_end() as usize;
Expand Down Expand Up @@ -87,8 +87,8 @@ fn footer_rsa4096() {
dbg!(&header);
assert!(header.enabled());
assert_eq!(header.get_minimum_app_ram_size(), 4612);
assert_eq!(header.get_init_function_offset(), 41 + header_len as u32);
assert_eq!(header.get_protected_size(), header_len as u32);
assert_eq!(header.get_init_function_offset(), 41);
assert_eq!(header.get_protected_size(), 0);
assert_eq!(header.get_package_name().unwrap(), "c_hello");
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
let binary_offset = header.get_binary_end() as usize;
Expand Down
12 changes: 6 additions & 6 deletions tockloader-cli/src/display.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thx

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut

println!(
" {BOLD_GREEN} TBF version: {RESET}{}",
details.tbf_header.get_binary_version(),
details.tbf_header.get_tbf_version(),
);

println!(
Expand Down Expand Up @@ -111,7 +111,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
details.tbf_header.sticky(),
);

println!(" {BOLD_GREEN} TVL: Main (1){RESET}");
println!(" {BOLD_GREEN} TLV: Main (1){RESET}");
println!(
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
details.tbf_header.get_init_function_offset(),
Expand All @@ -127,7 +127,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
details.tbf_header.get_minimum_app_ram_size(),
);

println!(" {BOLD_GREEN} TVL: Program (9){RESET}");
println!(" {BOLD_GREEN} TLV: Program (9){RESET}");
println!(
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
details.tbf_header.get_init_function_offset(),
Expand All @@ -153,13 +153,13 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
details.tbf_header.get_binary_version(),
);

println!(" {BOLD_GREEN} TVL: Package Name (3){RESET}");
println!(" {BOLD_GREEN} TLV: Package Name (3){RESET}");
println!(
" {BOLD_GREEN} package_name: {RESET}{}",
details.tbf_header.get_package_name().unwrap(),
);

println!(" {BOLD_GREEN} TVL: Kernel Version (8){RESET}");
println!(" {BOLD_GREEN} TLV: Kernel Version (8){RESET}");
println!(
" {BOLD_GREEN} kernel_major: {RESET}{}",
details.tbf_header.get_kernel_version().unwrap().0,
Expand All @@ -183,7 +183,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
println!(" {BOLD_GREEN} footer_size: {RESET}{total_footer_size}");

for (j, footer_details) in details.tbf_footers.iter().enumerate() {
println!(" {BOLD_GREEN} Footer [{j}] TVL: Credentials{RESET}");
println!(" {BOLD_GREEN} Footer [{j}] TLV: Credentials{RESET}");

println!(
" {BOLD_GREEN} Type: {RESET}{}",
Expand Down
Loading