pub struct SectionHeader {
pub length: u32,
pub next_offset: Option<u32>,
pub sect_type: SectionType,
pub sce_enabled: bool,
pub xip_page_size: XipPageRemapSize,
pub xip_block_size: u8,
/* private fields */
}
Expand description
Represents the header of a section in a binary image.
The SectionHeader
struct contains information about the section’s length, type,
offset to the next section, as well as details about encryption, remapping, and
validation. The struct is designed to handle sections in a memory or file layout
where the sections could represent different types of data, such as executable code
(XIP), memory regions (DTCM, ITCM), and more. Fields like xip_page_size
, xip_key
,
and xip_iv
are especially relevant when dealing with Execute-In-Place (XIP) sections.
Fields§
§length: u32
The length of the section in bytes.
This field stores the total size of the section, which may include data and metadata.
The exact meaning and content depend on the section type (sect_type
).
next_offset: Option<u32>
Offset to the next section.
This field indicates the position of the next section in memory. A value of 0xFFFF_FFFF
indicates that this is the last section, and no further sections exist.
sect_type: SectionType
The type of the current section.
sce_enabled: bool
Indicates whether Secure Copy Engine (SCE) is enabled for this section.
xip_page_size: XipPageRemapSize
XIP (Execute-In-Place) page size and remapping setting.
This field indicates the page size used for remapping during XIP operations. The value is an integer representing one of three possible values: 0 (16K), 1 (32K), and 2 (64K).
xip_block_size: u8
Block size for XIP remapping.
This field defines the block size used for XIP remapping, typically represented in bytes.
The default value is 0
, which means that remapping block size is not defined.
Implementations§
Source§impl SectionHeader
impl SectionHeader
Sourcepub fn has_next(&self) -> bool
pub fn has_next(&self) -> bool
Checks if the section has a next section.
This method checks if the next_offset
field of the SectionHeader
is set to the special
value 0xFFFF_FFFF
, which indicates that there is no next section. If next_offset
is
different from this value, it implies that there is a subsequent section, and the method
returns true
. Otherwise, it returns false
, indicating this is the last section.
§Returns
true
if the section has a next section (i.e.,next_offset
is not0xFFFF_FFFF
).false
if this is the last section (i.e.,next_offset
is0xFFFF_FFFF
).
Sourcepub fn xip_key_iv_valid(&self) -> bool
pub fn xip_key_iv_valid(&self) -> bool
Checks if both the xip_key
and xip_iv
fields are valid.
This method uses the is_valid_data!
macro to check the validity of both the xip_key
and xip_iv
fields. It returns true
if both fields are valid (i.e., they do not consist
entirely of 0xFF
bytes). If either field is invalid, it returns false
.
This method is typically used to determine if the section is encrypted and can be used for cryptographic operations.
§Returns
true
if bothxip_key
andxip_iv
are valid.false
if eitherxip_key
orxip_iv
is invalid.
Sourcepub fn get_xip_key(&self) -> DataRefType<'_, 16>
pub fn get_xip_key(&self) -> DataRefType<'_, 16>
Retrieves the XIP key.
Sourcepub fn get_xip_iv(&self) -> DataRefType<'_, 16>
pub fn get_xip_iv(&self) -> DataRefType<'_, 16>
Retrieves the XIP IV.
Sourcepub fn get_valid_pattern(&self) -> &[u8; 8]
pub fn get_valid_pattern(&self) -> &[u8; 8]
Retrieves the valid pattern.
pub fn set_xip_iv(&mut self, iv: DataType<16>)
pub fn set_xip_key(&mut self, key: DataType<16>)
Trait Implementations§
Source§impl BinarySize for SectionHeader
impl BinarySize for SectionHeader
Source§fn binary_size() -> usize
fn binary_size() -> usize
Returns the binary size (in bytes) of the SectionHeader
struct.
§Returns
Returns the binary size as a constant usize
value, which is 0x60
(96 bytes).
Source§impl Debug for SectionHeader
impl Debug for SectionHeader
Source§impl Default for SectionHeader
impl Default for SectionHeader
Source§fn default() -> SectionHeader
fn default() -> SectionHeader
Returns the default SectionHeader
instance with predefined values.
length
set to0
, representing an empty section.next_offset
set to0xFFFF_FFFF
, which indicates the absence of a next section.sect_type
set toSectionType::XIP
, as a default section type.sce_enabled
set tofalse
(assuming encryption is not enabled by default).xip_page_size
set toXipPageRemapSize::_16K
, the smallest page size for XIP remapping.xip_block_size
set to0
, indicating no block size set.valid_pattern
set to a default validation pattern of increasing values.xip_key
andxip_iv
both set to0xFF
, representing uninitialized keys/IV.
§Returns
Returns a SectionHeader
with the default values.
Source§impl FromStream for SectionHeader
impl FromStream for SectionHeader
Source§fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
Reads the SectionHeader
struct from a stream.
§Error Handling
This method may return an error if there is an issue with reading from the stream or if
an invalid value is encountered during deserialization (e.g., an invalid enum value for sect_type
or xip_page_size
). Any errors encountered during reading from the stream will be propagated as an Error
.
§Returns
Ok(())
if theSectionHeader
was successfully read from the stream.Err(Error)
if there was an issue reading from the stream or an invalid value was encountered.
§Panics
This function assumes that the binary data is well-formed and follows the expected format. If the format is incorrect or the stream is malformed, this function will return an error instead of panicking. However, it is still important to handle errors appropriately in calling code.
Source§impl ToStream for SectionHeader
impl ToStream for SectionHeader
Source§fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
Serializes the SectionHeader
struct to a stream.
§Parameters
writer
: A mutable reference to a type that implements thestd::io::Write
trait. The data will be written to this stream.
§Returns
Ok(())
: If the data is written successfully.Err(Error)
: If there is an issue writing the data to the stream.