Skip to main content

Crate zbi

Crate zbi 

Source
Expand description

ZBI Processing Library

This library is meant to be a generic processing library for the ZBI format defined in sdk/lib/zbi-format/include/lib/zbi-format/zbi.h.

Mainly it provides ZbiContainer that can create (ZbiContainer::new) valid container in the provided buffer. Or parses and checks (ZbiContainer::parse) existing container in the buffer. In both cases it provides iterator to walk thorough the items in container.

Note: in both cases provided buffer must be properly aligned to ZBI_ALIGNMENT_USIZE. Using align_buffer would do proper alignment for you.

use zbi::{ZbiContainer, ZbiFlags, ZbiType, align_buffer};

let mut buffer = [0; 200];
let mut buffer = align_buffer(&mut buffer[..]).unwrap();
let mut container = ZbiContainer::new(buffer).unwrap();
container.create_entry(ZbiType::DebugData, 0, ZbiFlags::default(), 10).unwrap();
container.create_entry_with_payload(ZbiType::DebugData, 0, ZbiFlags::default(), &[]).unwrap();

assert_eq!(container.iter().count(), 2);

let mut it = container.iter();
assert_eq!(it.next().unwrap().header.length, 10);
assert_eq!(it.next().unwrap().header.length, 0);
assert_eq!(it.next(), None);

Modules§

zbi_format

Structs§

ZbiContainer
Main structure to work with ZBI format.
ZbiContainerIterator
Container iterator
ZbiFlags
Flags associated with an item.
ZbiItem
ZbiItem is element representation in ZbiContainer

Enums§

ZbiError
Error values that can be returned by function in this library
ZbiType
All possible ZbiHeader.type values.

Constants§

ZBI_ALIGNMENT_USIZE
ZbiContainer requires buffer and each entry to be aligned to this amount of bytes. align_buffer can be used to adjust buffer alignment to match this requirement.

Functions§

align_buffer
Aligns provided slice to ZBI_ALIGNMENT_USIZE bytes.
merge_within
Merges two ZBI containers stored on the same buffer.

Type Aliases§

ZbiHeader
Rust type generated from C-reference structure zbi_header_t.
ZbiKernel
The kernel image.