Skip to main content

HeaderV0

Struct HeaderV0 

Source
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: u32

Kernel size

§kernel_addr: u32

Kernel physical load address

§ramdisk_size: u32

Ramdisk size

§ramdisk_addr: u32

Ramdisk physical load address

§second_bootloader_size: u32

Second bootloader size

§second_bootloader_addr: u32

Second bootloader physical load address

§tags_addr: u32

Kernel tags physical load address

§page_size: u32

Page size in bytes

§osversionpatch: OsVersionPatch

OS 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: HeaderV0Versioned

Version-specific part of the boot image header.

Implementations§

Source§

impl HeaderV0

Source

pub const fn header_version(&self) -> u32

Returns the boot image header’s version number.

Source

pub const fn kernel_position(&self) -> usize

Returns the kernel’s position in the boot image.

Source

pub const fn ramdisk_position(&self) -> usize

Returns the ramdisk’s position in the boot image.

Source

pub const fn second_bootloader_position(&self) -> usize

Returns the second stage bootloader’s position in the boot image.

Source

pub const fn recovery_dtbo_position(&self) -> usize

Returns the recovery DTBO’s position in the boot image.

Source

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.

Source

pub const fn boot_image_size(&self) -> usize

Returns the size of the boot image.

Source

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]>

Available on crate feature 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?
examples/compute-hash-digest.rs (lines 40-46)
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}
Source

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<()>

Available on crate feature 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, kernel will only ever output exactly Self::kernel_size bytes.
§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

Source§

type Args<'__binrw_generated_args_lifetime> = ()

The type used for the args parameter of read_args() and read_options(). Read more
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>

Read Self from the reader using the given Endian and arguments. Read more
Source§

fn read<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self: ReadEndian, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments. Read more
Source§

fn read_be<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming big-endian byte order. Read more
Source§

fn read_le<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming little-endian byte order. Read more
Source§

fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read T from the reader assuming native-endian byte order. Read more
Source§

fn read_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek, Self: ReadEndian,

Read Self from the reader using the given arguments. Read more
Source§

fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming big-endian byte order, using the given arguments. Read more
Source§

fn read_le_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming little-endian byte order, using the given arguments. Read more
Source§

fn read_ne_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read T from the reader, assuming native-endian byte order, using the given arguments. Read more
Source§

impl BinWrite for HeaderV0

Source§

type Args<'__binrw_generated_args_lifetime> = ()

The type used for the args parameter of write_args() and write_options(). Read more
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<()>

Write Self to the writer using the given Endian and arguments. Read more
Source§

fn write<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self: WriteEndian, Self::Args<'a>: for<'a> Required,

Write Self to the writer using default arguments. Read more
Source§

fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming big-endian byte order. Read more
Source§

fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming little-endian byte order. Read more
Source§

fn write_ne<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming native-endian byte order. Read more
Source§

fn write_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek, Self: WriteEndian,

Write Self to the writer using the given arguments. Read more
Source§

fn write_be_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming big-endian byte order, using the given arguments. Read more
Source§

fn write_le_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming little-endian byte order, using the given arguments. Read more
Source§

fn write_ne_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming native-endian byte order, using the given arguments. Read more
Source§

impl Clone for HeaderV0

Source§

fn clone(&self) -> HeaderV0

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeaderV0

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for HeaderV0

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HeaderV0

Source§

fn eq(&self, other: &HeaderV0) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReadEndian for HeaderV0

Source§

const ENDIAN: EndianKind

The endianness of the type.
Source§

impl ReadMagic for HeaderV0

Source§

const MAGIC: Self::MagicType

The magic number.
Source§

type MagicType = [u8; 8]

The type of the magic number.
Source§

impl WriteEndian for HeaderV0

Source§

const ENDIAN: EndianKind

The endianness of the type.
Source§

impl WriteMagic for HeaderV0

Source§

const MAGIC: Self::MagicType

The magic number.
Source§

type MagicType = [u8; 8]

The type of the magic number.
Source§

impl Eq for HeaderV0

Source§

impl StructuralPartialEq for HeaderV0

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.