Skip to content

Commit 44eb38d

Browse files
committed
replace bytes_to_string function with std function
1 parent 8555ba3 commit 44eb38d

2 files changed

Lines changed: 7 additions & 25 deletions

File tree

tockloader-lib/src/attributes/decode.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,3 @@ pub(crate) fn decode_attribute(step: &[u8]) -> Option<DecodedAttribute> {
7070
value = value.trim_end_matches('\0').to_string();
7171
Some(DecodedAttribute::new(key, value))
7272
}
73-
74-
// TODO(eva-cosma) replace this function with std::str::from_utf8(...). It
75-
// does the same thing.
76-
77-
/// Transform a byte-slice into a String.
78-
///
79-
/// # Panics
80-
///
81-
/// This code panics if the given bytes are not utf-8 representable
82-
pub(crate) fn bytes_to_string(raw: &[u8]) -> String {
83-
let decoder = utf8_decode::Decoder::new(raw.iter().cloned());
84-
85-
let mut string = String::new();
86-
for n in decoder {
87-
match n {
88-
Ok(c) => string.push(c),
89-
Err(_) => {}
90-
}
91-
}
92-
string
93-
}

tockloader-lib/src/attributes/system_attributes.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use byteorder::{ByteOrder, LittleEndian};
77
use crate::errors::{AttributeParseError, TockError, TockloaderError};
88
use crate::IO;
99

10-
use super::decode::{bytes_to_string, decode_attribute};
10+
use super::decode::decode_attribute;
1111

1212
/// This structure contains all relevant information about board that is stored
1313
/// in the bootloader ROM.
@@ -64,8 +64,8 @@ impl SystemAttributes {
6464
}
6565
}
6666
/// Read system and kernel attributes.
67-
///``
68-
///
67+
/// System attributes are read only if the board has
68+
/// a bootloader present.
6969
/// # Parameters
7070
/// - `conn` : Either a SerialConnection or a ProbeRSConnection.
7171
/// - `flash_address` : The start of flash memory.
@@ -95,6 +95,7 @@ impl SystemAttributes {
9595
.unwrap_or(false);
9696

9797
if !has_bootloader {
98+
// TODO: Chain: CLI arguments -> hardcoded start_address -> calculate from kernel app start address
9899
result.appaddr = Some(start_address);
99100
} else {
100101
for current_slot in 0..data.len() {
@@ -171,7 +172,9 @@ impl SystemAttributes {
171172
- 100;
172173
let kernel_attr_binary = conn.read(kernel_attr_addr, 100).await?;
173174

174-
let sentinel = bytes_to_string(&kernel_attr_binary[96..100]);
175+
let sentinel = std::str::from_utf8(&kernel_attr_binary[96..100])
176+
.unwrap_or("unknown")
177+
.to_string();
175178
let kernel_version = LittleEndian::read_uint(&kernel_attr_binary[95..96], 1);
176179

177180
let app_memory_len = LittleEndian::read_u32(&kernel_attr_binary[84..92]);

0 commit comments

Comments
 (0)