Skip to content

Commit f0fa773

Browse files
committed
refactor: change display values and formatting
Signed-off-by: Adrian Lungu <lunguadrian30@gmail.com>
1 parent 944cd9e commit f0fa773

3 files changed

Lines changed: 34 additions & 20 deletions

File tree

tbf-parser/src/types.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,14 @@ impl TbfHeader {
928928
}
929929
}
930930

931+
/// Return flags of the application
932+
pub fn flags(&self) -> u32 {
933+
match *self {
934+
TbfHeader::TbfHeaderV2(hd) => hd.base.flags,
935+
_ => 0,
936+
}
937+
}
938+
931939
/// Return header size of the application.
932940
pub fn header_size(&self) -> u16 {
933941
match *self {
@@ -956,7 +964,7 @@ impl TbfHeader {
956964

957965
/// Get the number of bytes from the start of the app's region in flash that
958966
/// is for kernel use only. The app cannot write this region.
959-
pub fn get_protected_size(&self) -> u32 {
967+
pub fn get_protected_trailer_size(&self) -> u32 {
960968
match *self {
961969
TbfHeader::TbfHeaderV2(hd) => {
962970
if hd.program.is_some() {
@@ -971,13 +979,13 @@ impl TbfHeader {
971979
}
972980
}
973981

974-
/// Get the start offset of the application binary from the beginning
982+
/// Get the protected region of the application binary from the beginning
975983
/// of the process binary (start of the TBF header). Only valid if this
976984
/// is an app.
977-
pub fn get_app_start_offset(&self) -> u32 {
985+
pub fn get_protected_region_size(&self) -> u32 {
978986
// The application binary starts after the header plus any
979987
// additional protected space.
980-
self.get_protected_size()
988+
self.header_size() as u32 + self.get_protected_trailer_size()
981989
}
982990

983991
/// Get the offset from the beginning of the app's flash region where the

tbf-parser/tests/parse.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ fn simple_tbf() {
1717
assert!(header.enabled());
1818
assert_eq!(header.get_minimum_app_ram_size(), 4848);
1919
assert_eq!(header.get_init_function_offset(), 41);
20-
assert_eq!(header.get_protected_size(), 0);
20+
assert_eq!(header.get_protected_trailer_size(), 0);
21+
assert_eq!(header.flags(), 1);
2122
assert_eq!(header.get_package_name().unwrap(), "_heart");
2223
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
2324
}
@@ -38,7 +39,8 @@ fn footer_sha256() {
3839
assert!(header.enabled());
3940
assert_eq!(header.get_minimum_app_ram_size(), 4848);
4041
assert_eq!(header.get_init_function_offset(), 41);
41-
assert_eq!(header.get_protected_size(), 0);
42+
assert_eq!(header.get_protected_trailer_size(), 0);
43+
assert_eq!(header.flags(), 1);
4244
assert_eq!(header.get_package_name().unwrap(), "_heart");
4345
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
4446
let binary_offset = header.get_binary_end() as usize;
@@ -88,7 +90,8 @@ fn footer_rsa4096() {
8890
assert!(header.enabled());
8991
assert_eq!(header.get_minimum_app_ram_size(), 4612);
9092
assert_eq!(header.get_init_function_offset(), 41);
91-
assert_eq!(header.get_protected_size(), 0);
93+
assert_eq!(header.get_protected_trailer_size(), 0);
94+
assert_eq!(header.flags(), 1);
9295
assert_eq!(header.get_package_name().unwrap(), "c_hello");
9396
assert_eq!(header.get_kernel_version().unwrap(), (2, 0));
9497
let binary_offset = header.get_binary_end() as usize;

tockloader-cli/src/display.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
7676
);
7777

7878
println!(
79-
" {BOLD_GREEN} Address in Flash: {RESET}{}",
79+
" {BOLD_GREEN} Address in Flash: {RESET}{:#x}",
8080
system_details.appaddr.unwrap(),
8181
);
8282

@@ -96,11 +96,14 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
9696
);
9797

9898
println!(
99-
" {BOLD_GREEN} checksum: {RESET}{}",
99+
" {BOLD_GREEN} checksum: {RESET}{:#x}",
100100
details.tbf_header.checksum(),
101101
);
102102

103-
println!(" {BOLD_GREEN} flags:{RESET}");
103+
println!(
104+
" {BOLD_GREEN} flags: {RESET}{:#b}",
105+
details.tbf_header.flags(),
106+
);
104107
println!(
105108
" {BOLD_GREEN} enabled: {RESET}{}",
106109
details.tbf_header.enabled(),
@@ -113,43 +116,43 @@ pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut
113116

114117
println!(" {BOLD_GREEN} TLV: Main (1){RESET}");
115118
println!(
116-
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
119+
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
117120
details.tbf_header.get_init_function_offset(),
118121
);
119122

120123
println!(
121-
" {BOLD_GREEN} protected_size: {RESET}{}",
122-
details.tbf_header.get_protected_size(),
124+
" {BOLD_GREEN} protected_trailer_size: {RESET}{}",
125+
details.tbf_header.get_protected_trailer_size(),
123126
);
124127

125128
println!(
126-
" {BOLD_GREEN} minimum_ram_size: {RESET}{}",
129+
" {BOLD_GREEN} minimum_ram_size: {RESET}{}",
127130
details.tbf_header.get_minimum_app_ram_size(),
128131
);
129132

130133
println!(" {BOLD_GREEN} TLV: Program (9){RESET}");
131134
println!(
132-
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
135+
" {BOLD_GREEN} init_fn_offset: {RESET}{}",
133136
details.tbf_header.get_init_function_offset(),
134137
);
135138

136139
println!(
137-
" {BOLD_GREEN} protected_size: {RESET}{}",
138-
details.tbf_header.get_protected_size(),
140+
" {BOLD_GREEN} protected_trailer_size: {RESET}{}",
141+
details.tbf_header.get_protected_trailer_size(),
139142
);
140143

141144
println!(
142-
" {BOLD_GREEN} minimum_ram_size: {RESET}{}",
145+
" {BOLD_GREEN} minimum_ram_size: {RESET}{}",
143146
details.tbf_header.get_minimum_app_ram_size(),
144147
);
145148

146149
println!(
147-
" {BOLD_GREEN} binary_end_offset: {RESET}{}",
150+
" {BOLD_GREEN} binary_end_offset: {RESET}{}",
148151
details.tbf_header.get_binary_end(),
149152
);
150153

151154
println!(
152-
" {BOLD_GREEN} app_version: {RESET}{}",
155+
" {BOLD_GREEN} app_version: {RESET}{}",
153156
details.tbf_header.get_binary_version(),
154157
);
155158

0 commit comments

Comments
 (0)