template <class... Items>

class BootShim

Defined at line 114 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim is a base class for implementing boot shims. The model is that the

shim starts up, collects data from whatever legacy sources it has, then

ingests the ZBI, then appends "bootloader-provided" items to the data ZBI.

This class manages the data collection and tracks what items to append.

Each template argument is a class implementing the boot_shim::ItemBase API.

Each "item" can produce zero, one, or more ZBI items at runtime.

In several shims, everything must be figured out so that the final image

sizes are all known before any memory allocation can be done. So first a

data collection pass stores everything it needs in each item object. (The

BootShim base class does not do this part except for the CMDLINE item.)

Then BootShim::size_bytes() on BootShim sums Items::size_bytes() so the shim

can reserve memory for the data ZBI. Once the shim has ingested the input

ZBI and set up memory allocation it can set up the data ZBI with as much

extra capacity as size_bytes() requested. Then BootShim::AppendItems

iterates across Items::AppendItems calls. The shim is now ready to boot.

Public Methods

void BootShim<Items...> ()

Move-only, not default-constructible.

Defined at line 132 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void BootShim<Items...> (const BootShim<Items...> & )

Defined at line 133 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void BootShim<Items...> (BootShim<Items...> && )

Defined at line 134 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & operator= (const BootShim<Items...> & )

Defined at line 135 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & operator= (BootShim<Items...> && )

Defined at line 136 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void BootShim<Items...> (const char * shim_name, FILE * log)

The caller must supply the shim's own program name as a string constant.

This string is used in log messages and in "bootloader.name=...". In real

phys shims, this is always Symbolize::kProgramName_ and stdout is the only

FILE* there is. Other log streams can be used in testing.

Defined at line 142 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void BootShim<Items...> (const char * shim_name, FILE * log)

The caller must supply the shim's own program name as a string constant.

This string is used in log messages and in "bootloader.name=...". In real

phys shims, this is always Symbolize::kProgramName_ and stdout is the only

FILE* there is. Other log streams can be used in testing.

Defined at line 142 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_info (std::string_view str)

These fluent setters contribute to the built-in ZBI_TYPE_CMDLINE item,

along with the mandatory shim name from the constructor.

Defined at line 150 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_info (std::string_view str)

These fluent setters contribute to the built-in ZBI_TYPE_CMDLINE item,

along with the mandatory shim name from the constructor.

Defined at line 150 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_build_id (const elfldltl::ElfNote & build_id)

Defined at line 155 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline (std::string_view str)

Defined at line 160 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline (std::string_view str)

Defined at line 160 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_strings (std::span<std::string_view> strings)

Defined at line 168 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_strings (std::span<std::string_view> strings)

Defined at line 168 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_strings (std::span<std::string_view> strings)

Defined at line 168 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_strings (std::span<std::string_view> strings)

Defined at line 168 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_cstrings (std::span<const char *> cstrings)

Defined at line 173 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_cstrings (std::span<const char *> cstrings)

Defined at line 173 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_cstrings (std::span<const char *> cstrings)

Defined at line 173 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_cmdline_cstrings (std::span<const char *> cstrings)

Defined at line 173 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

std::string_view legacy_cmdline ()

Defined at line 178 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::span<const std::byte> boot_config)

Defined at line 180 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::span<const std::byte> boot_config)

Defined at line 180 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::span<const std::byte> boot_config)

Defined at line 180 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::span<const std::byte> boot_config)

Defined at line 180 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::string_view contents)

Defined at line 185 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (std::string_view contents)

Defined at line 185 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootShim<Items...> & set_linux_boot_config (const linux_boot_config::LinuxBootConfig & boot_config)

Defined at line 189 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

BootProperties legacy_boot_properties ()

Defined at line 193 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void Log (ByteView ramdisk)

Log how things look after calling set_* methods.

Defined at line 208 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void Log (ByteView ramdisk)

Log how things look after calling set_* methods.

Defined at line 208 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void Log (ByteView ramdisk)

Log how things look after calling set_* methods.

Defined at line 208 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

void Log (ByteView ramdisk)

Log how things look after calling set_* methods.

Defined at line 208 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

size_t size_bytes ()

Return the total size (upper bound) of additional data ZBI items.

Defined at line 211 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

fit::result<DataZbi::Error> AppendItems (DataZbi & zbi)

Append additional items to the data ZBI. The caller ensures there is as

much spare capacity as size_bytes() previously returned.

Defined at line 217 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

fit::result<DataZbi::Error> AppendItems (DataZbi & zbi)

Append additional items to the data ZBI. The caller ensures there is as

much spare capacity as size_bytes() previously returned.

Defined at line 217 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

fit::result<DataZbi::Error> AppendItems (DataZbi & zbi)

Append additional items to the data ZBI. The caller ensures there is as

much spare capacity as size_bytes() previously returned.

Defined at line 217 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

fit::result<DataZbi::Error> AppendItems (DataZbi & zbi)

Append additional items to the data ZBI. The caller ensures there is as

much spare capacity as size_bytes() previously returned.

Defined at line 217 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <class T, auto&& self>
decltype(auto) Get (auto && self)

Get the item object of a particular type (among Items).

Defined at line 232 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <class Item, typename... Args>
decltype(auto) InitItem (Item & item, Args &&... args)

This calls item.Init(args..., shim_name(), log()).

Defined at line 238 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <class Item, typename... Args>
decltype(auto) InitGetItem (Args &&... args)

This calls the Get

<Item

>() item method Init(args..., shim_name(), log()).

Defined at line 244 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <invocable<Cmdline&, Items&...> T, auto&& self>
decltype(auto) OnItems (auto && self, T && callback)

Returns callback(Items

&

...).

Defined at line 250 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <template <typename> typename Predicate, typename T, auto&& self>
decltype(auto) OnSelectItems (auto && self, T && callback)

Returns the result of `callback(item_0, ... , item_n)`, where each item

used as argument corresponds to the shim items where

`Predicate

<decltype

(item_i)>::value` is true. The relative order between

items is preserved.

Example:

// Assuming the items are:

std::tuple

<T0

, T1, T2, T3> items_;

And Predicate

<T

>::value for each of item types are respectively:

`{T0: false, T1: true, T2: true, T3: false}` then the generated call

is `callback(T1

&

, T2

&

)` and equivalent to

`callback(std::get

<

1>(items_), std::get

<

2>(items)`.

Defined at line 269 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <typename Base = void, auto&& self, auto&& callback>
void ForEachItem (auto && self, auto && callback)

Calls callback(item) for each of Items.

If Base is given, the items not derived from Base are skipped.

Defined at line 276 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <typename Base = void, auto&& self, auto&& callback>
bool EveryItem (auto && self, auto && callback)

Returns callback(item)

&

&

... for each of Items.

If Base is given, the items not derived from Base are skipped.

Defined at line 283 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <typename Base = void, auto&& self, auto&& callback>
bool AnyItem (auto && self, auto && callback)

Returns callback(item) || ... for each of Items.

If Base is given, the items not derived from Base are skipped.

Defined at line 290 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h

template <typename... T, auto&& self>
void OnInvocableItems (auto && self, T &&... callbacks)

This takes any number of callbacks invocable as void(Item

&

) for some Item

type. For each item, each callback that is invocable with that item type

will be called. This makes it easy to just list type-specific callbacks

together in one call:

```

shim.OnInvocableItems([](ItemA

&

a) { ... }, [](ItemB

&

b) { ... });

```

Note that it's no error if a given callback is not invocable on any

item, or even if no callback is invocable on any item. So when using

this, runtime tests are required to ensure that each callback has the

correct signature to get called when it's meant to be.

Defined at line 306 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h