pub struct HeaderV0 {Show 13 fields
pub kernel_size: u32,
pub kernel_addr: u32,
pub ramdisk_size: u32,
pub ramdisk_addr: u32,
pub second_bootloader_size: u32,
pub second_bootloader_addr: u32,
pub tags_addr: u32,
pub page_size: u32,
pub osversionpatch: OsVersionPatch,
pub board_name: [u8; 16],
pub hash_digest: [u8; 32],
pub cmdline: Box<[u8; 1536]>,
pub versioned: HeaderV0Versioned,
}Expand description
Standard Android boot image header versions 0, 1 and 2
§Section layout in the image
Sections after the header are marked by fields of the form *_size, and are stored
consecutively, padded to page size.
Sections in HeaderV0 are also marked with the physical address where a bootloader should
load them to.
┌─────────────────────────┐
│boot image header │
│+ padding to page size │
├─────────────────────────┤
│kernel │
│+ padding to page size │
├─────────────────────────┤
│ramdisk │
│+ padding to page size │
├─────────────────────────┤
│second stage bootloader │
│+ padding to page size │
├─────────────────────────┤
│recovery dtbo/acpio (v1+)│
│+ padding to page size │
├─────────────────────────┤
│dtb (v2) │
│+ padding to page size │
└─────────────────────────┘§Additional Documentation
Fields§
§kernel_size: u32Kernel size
kernel_addr: u32Kernel physical load address
ramdisk_size: u32Ramdisk size
ramdisk_addr: u32Ramdisk physical load address
second_bootloader_size: u32Second bootloader size
second_bootloader_addr: u32Second bootloader physical load address
Kernel tags physical load address
page_size: u32Page size in bytes
osversionpatch: OsVersionPatchOS version and patch level
board_name: [u8; 16]Board or product name
hash_digest: [u8; 32]Hash digest
Usually either a SHA1 (20 bytes of digest, 12 null-bytes) or a SHA256 (32 bytes of digest) digest of the following: kernel, ramdisk, second bootloader, recovery DTBO and DTB.
- If the size is nonzero, hash the contents.
- Update the hash with the little-endian representation of the 32-bit unsigned size (
u32::to_le_bytes), which may be zero.
cmdline: Box<[u8; 1536]>Kernel command line
versioned: HeaderV0VersionedVersion-specific part of the boot image header.
Implementations§
Source§impl HeaderV0
impl HeaderV0
Sourcepub const fn header_version(&self) -> u32
pub const fn header_version(&self) -> u32
Returns the boot image header’s version number.
Sourcepub const fn kernel_position(&self) -> usize
pub const fn kernel_position(&self) -> usize
Returns the kernel’s position in the boot image.
Sourcepub const fn ramdisk_position(&self) -> usize
pub const fn ramdisk_position(&self) -> usize
Returns the ramdisk’s position in the boot image.
Sourcepub const fn second_bootloader_position(&self) -> usize
pub const fn second_bootloader_position(&self) -> usize
Returns the second stage bootloader’s position in the boot image.
Sourcepub const fn recovery_dtbo_position(&self) -> usize
pub const fn recovery_dtbo_position(&self) -> usize
Returns the recovery DTBO’s position in the boot image.
Sourcepub const fn dtb_position(&self) -> Option<usize>
pub const fn dtb_position(&self) -> Option<usize>
Returns the DTB’s position in the boot image.
This returns None in version 0.
Note that this section is undefined in version 1.
Sourcepub const fn boot_image_size(&self) -> usize
pub const fn boot_image_size(&self) -> usize
Returns the size of the boot image.
Sourcepub fn compute_hash_digest<R: Read, D: Digest>(
kernel: Option<&mut R>,
ramdisk: Option<&mut R>,
second_bootloader: Option<&mut R>,
recovery_dtbo: Option<&mut R>,
dtb: Option<&mut R>,
) -> Result<[u8; 32]>
Available on crate feature hash only.
pub fn compute_hash_digest<R: Read, D: Digest>( kernel: Option<&mut R>, ramdisk: Option<&mut R>, second_bootloader: Option<&mut R>, recovery_dtbo: Option<&mut R>, dtb: Option<&mut R>, ) -> Result<[u8; 32]>
hash only.Finalizes the passed in hasher to create a Self::hash_digest.
§Errors
Passes through errors that occur in the readers and errors when more than u32::MAX
bytes were read from a single file.
Examples found in repository?
37fn hash_files<D: digest::Digest>(files: [Option<&mut &File>; 5]) -> [u8; 32] {
38 let [kernel_f, ramdisk_f, second_bootloader_f, recovery_dtbo_f, dtb_f] = files;
39
40 HeaderV0::compute_hash_digest::<_, D>(
41 kernel_f,
42 ramdisk_f,
43 second_bootloader_f,
44 recovery_dtbo_f,
45 dtb_f,
46 )
47 .unwrap()
48}Sourcepub fn full_write<W: Write + Seek, R: Read>(
&self,
writer: &mut W,
kernel: Option<&mut R>,
ramdisk: Option<&mut R>,
second_bootloader: Option<&mut R>,
recovery_dtbo: Option<&mut R>,
dtb: Option<&mut R>,
) -> BinResult<()>
Available on crate feature std only.
pub fn full_write<W: Write + Seek, R: Read>( &self, writer: &mut W, kernel: Option<&mut R>, ramdisk: Option<&mut R>, second_bootloader: Option<&mut R>, recovery_dtbo: Option<&mut R>, dtb: Option<&mut R>, ) -> BinResult<()>
std only.Writes the full Android boot image, including the different parts after the header.
- Requires the Rust standard library for
std::io::copy. - Assumes that the readers will output exact amounts. That is,
kernelwill only ever output exactlySelf::kernel_sizebytes.
§Errors
Passes through errors that occur in the readers or the writer or during serialization of the header.
Trait Implementations§
Source§impl BinRead for HeaderV0
impl BinRead for HeaderV0
Source§fn read_options<R: Read + Seek>(
__binrw_generated_var_reader: &mut R,
__binrw_generated_var_endian: Endian,
__binrw_generated_var_arguments: Self::Args<'_>,
) -> BinResult<Self>
fn read_options<R: Read + Seek>( __binrw_generated_var_reader: &mut R, __binrw_generated_var_endian: Endian, __binrw_generated_var_arguments: Self::Args<'_>, ) -> BinResult<Self>
Source§fn read<R>(reader: &mut R) -> Result<Self, Error>
fn read<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments. Read moreSource§fn read_be<R>(reader: &mut R) -> Result<Self, Error>
fn read_be<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments and assuming
big-endian byte order. Read moreSource§fn read_le<R>(reader: &mut R) -> Result<Self, Error>
fn read_le<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments and assuming
little-endian byte order. Read moreSource§fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
T from the reader assuming native-endian byte order. Read moreSource§fn read_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
fn read_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
Self from the reader using the given arguments. Read moreSource§fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
Self from the reader, assuming big-endian byte order, using the
given arguments. Read moreSource§impl BinWrite for HeaderV0
impl BinWrite for HeaderV0
Source§fn write_options<W: Write + Seek>(
&self,
__binrw_generated_var_writer: &mut W,
__binrw_generated_var_endian: Endian,
__binrw_generated_var_arguments: Self::Args<'_>,
) -> BinResult<()>
fn write_options<W: Write + Seek>( &self, __binrw_generated_var_writer: &mut W, __binrw_generated_var_endian: Endian, __binrw_generated_var_arguments: Self::Args<'_>, ) -> BinResult<()>
Source§fn write<W>(&self, writer: &mut W) -> Result<(), Error>
fn write<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer using default arguments. Read moreSource§fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer assuming big-endian byte order. Read moreSource§fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer assuming little-endian byte order. Read moreSource§fn write_ne<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_ne<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer assuming native-endian byte order. Read moreSource§fn write_args<W>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> Result<(), Error>
fn write_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
Self to the writer using the given arguments. Read moreSource§fn write_be_args<W>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> Result<(), Error>
fn write_be_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
Self to the writer, assuming big-endian byte order, using the
given arguments. Read more