~/bend-docscommunity

src/boot/image.bend checks

raw source on the hub · import 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/boot/image.bend as MImage

3 imports
import Base
import ../lib/u64.bend as U
import ../lib/bytes.bend as B

Types

type ImageInfo source · line 15 · raw

Data

type Layout source · line 19 · raw

Data

Where everything goes in guest RAM.

type Zboot source · line 123 · raw

Data

An EFI zboot image (Linux's CONFIG_EFI_ZBOOT: the arm64 vmlinuz of Alpine, Fedora and Debian): "zimg" at byte 4, the payload's offset and size at bytes 8 and 12 (u32, little-endian), its compression's name at byte 24. A gzip payload is a compressed Image, inflated into RAM as a gzip kernel is.

Definitions

def Image.magic source · line 22 · raw

U32

def Image.old_text_offset source · line 25 · raw

0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64

def Image.mib2 source · line 28 · raw

U32

def Image.field source · line 32 · raw

@bs:List<&2, U32> -> @off:Nat -> 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64

The le64 field at byte off of the header.

def Image.text_offset source · line 36 · raw

@old:Bool -> @given:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64

A pre-3.17 kernel (image_size 0) loads at text_offset 0x8_0000.

def Image.when source · line 43 · raw

@-A:Data -> @ok:Bool -> @x:A -> Maybe<&2, A>

def Image.parse.fields source · line 51 · raw

@+bs:List<&2, U32> -> Maybe<&2, ImageInfo>

The fields of a header of at least 64 bytes.

def Image.parse.go source · line 58 · raw

@long:Bool -> @bs:List<&2, U32> -> Maybe<&2, ImageInfo>

def Image.parse source · line 67 · raw

@header:List<&2, U32> -> Maybe<&2, ImageInfo>

Parses the header; None if shorter than 64 bytes, the magic is wrong or the kernel is big-endian.

def Image.add source · line 72 · raw

@+a:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> @b:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> Maybe<&2, 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64>

a + b, or None when the sum wraps past 2^64.

def Image.align source · line 77 · raw

@k:Nat -> @+a:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> Maybe<&2, 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64>

a rounded up to a multiple of 2^k, or None when that wraps past 2^64.

def Image.max source · line 81 · raw

@+a:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> @+b:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> 0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64

def Image.layout source · line 95 · raw

@ram_base:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> @ram_size:0x9f122a1bc25cb981d0e1a1a147d78e4e/src/lib/u64.U64 -> @info:ImageInfo -> @kernel_len:U32 -> @dtb_len:U32 -> @initrd_len:U32 -> Maybe<&2, Layout>

Places the kernel, the DTB and the initrd in RAM [ram_base, ram_base+ram_size): - kernel at ram_base + text_offset (ram_base is 2 MiB aligned), spanning max(image_size, kernel_len) bytes; - the DTB at the first 2 MiB boundary at or after the kernel's end (it must be 8-byte aligned and within one 2 MiB region; dtb_len <= 2 MiB); - the initrd at the first 4 KiB boundary at or after the end of the DTB's 2 MiB region (initrd_len 0 gives initrd == initrd_end, still placed there). None if anything would end past the end of RAM.

Each region ends at or before the start of the next one, so the initrd's end bounds them all. Also None when dtb_len > 2 MiB or an address wraps past 2^64.

def Image.is_gzip source · line 114 · raw

@+head:List<&2, U32> -> Bool

A gzip stream (RFC 1952: 1f 8b), from a file's first bytes: a compressed kernel (Ubuntu's vmlinuz) the host inflates into RAM. A file of 2 bytes or fewer is not one.

def Image.byte source · line 126 · raw

@+head:List<&2, U32> -> @+n:Nat -> U32

def Image.le32 source · line 129 · raw

@+head:List<&2, U32> -> @+n:Nat -> U32

def Image.tag source · line 133 · raw

@+head:List<&2, U32> -> @+n:Nat -> @a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> Bool

The four bytes at n spell a, b, c, d.

def Image.zboot source · line 138 · raw

@+head:List<&2, U32> -> Maybe<&2, Zboot>

From a file's first 28 bytes: a zboot image's gzip payload (offset, size), or none (not one, another compression, or an empty payload).