Rust library with type definitions and parsing functions for Multiboot2 headers.
This library is no_std
and can be used in bootloaders.
What this library is good for:
- writing a small binary which writes you a valid Multiboot2 header
into a file (such as header.bin
)
- understanding Multiboot2 headers better
- analyze Multiboot2 headers at runtime
What this library is not optimal for: - compiling a Multiboot2 header statically into an object file using only Rust code
no_std
This library is always no_std
. However, the builder
-feature requires the alloc
-crate
to be available. You need the builder
only if you want to construct new headers. For parsing,
this is not relevant.
```toml
builder
-feature (and without alloc
-crate)multiboot2-header = { version = "
alloc
-crate)multiboot2-header = "
```rust use multiboot2header::builder::{InformationRequestHeaderTagBuilder, Multiboot2HeaderBuilder}; use multiboot2header::{HeaderTagFlag, HeaderTagISA, MbiTagType, RelocatableHeaderTag, RelocatableHeaderTagPreference, Multiboot2Header};
/// Small example that creates a Multiboot2 header and parses it afterwards. fn main() { // We create a Multiboot2 header during runtime here. A practical example is that your // program gets the header from a file and parses it afterwards. let mb2hdrbytes = Multiboot2HeaderBuilder::new(HeaderTagISA::I386) .relocatabletag(RelocatableHeaderTag::new( HeaderTagFlag::Required, 0x1337, 0xdeadbeef, 4096, RelocatableHeaderTagPreference::None, )) .informationrequesttag( InformationRequestHeaderTagBuilder::new(HeaderTagFlag::Required) .addirs(&[MbiTagType::Cmdline, MbiTagType::BootLoaderName]), ) .build();
// Cast bytes in vector to Multiboot2 information structure
let mb2_hdr = unsafe { Multiboot2Header::from_addr(mb2_hdr_bytes.as_ptr() as usize) };
println!("{:#?}", mb2_hdr);
} ```
You can use the builder, construct a Multiboot2 header, write it to a file and include it like this: ```
static MULTIBOOT2HDR: &[u8; 64] = includebytes!("mb2hdrdump.bin"); ``` You may need a special linker script to place this in a LOAD segment with a file offset with less than 32768 bytes. See specification.
The MSRV is 1.52.1 stable.
See main README file.