template <class... Items>
class BootShim
Defined at line 113 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 131 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
void BootShim<Items...> (const BootShim<Items...> & )
Defined at line 132 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
void BootShim<Items...> (BootShim<Items...> && )
Defined at line 133 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
BootShim<Items...> & operator= (const BootShim<Items...> & )
Defined at line 134 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
BootShim<Items...> & operator= (BootShim<Items...> && )
Defined at line 135 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 141 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 141 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 149 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 149 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 154 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 159 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 159 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 167 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 167 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 167 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 167 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 172 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 172 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 172 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 172 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
std::string_view legacy_cmdline ()
Defined at line 177 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 179 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 179 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 179 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 179 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 185 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 185 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 185 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 185 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 188 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 194 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 194 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 194 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 194 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename T>
T & Get ()
Get the item object of a particular type (among Items).
Defined at line 207 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename T>
const T & Get ()
Defined at line 213 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 221 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 227 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <invocable<Cmdline&, Items&...> T>
decltype(auto) OnItems (T && callback)
Returns callback(Items
&
...).
Defined at line 233 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <invocable<Cmdline&, Items&...> T>
decltype(auto) OnItems (T && callback)
Defined at line 237 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <template <typename> typename Predicate, typename T>
decltype(auto) OnSelectItems (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 256 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <template <typename> typename Predicate, typename T>
decltype(auto) OnSelectItems (T && callback)
Defined at line 261 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename Base = void, auto&& callback>
void ForEachItem (auto && callback)
Calls callback(item) for each of Items.
If Base is given, the items not derived from Base are skipped.
Defined at line 268 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename Base = void, auto&& callback>
void ForEachItem (auto && callback)
Defined at line 272 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename Base = void, auto&& callback>
bool EveryItem (auto && callback)
Returns callback(item)
&
&
... for each of Items.
If Base is given, the items not derived from Base are skipped.
Defined at line 279 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename Base = void, auto&& callback>
bool EveryItem (auto && callback)
Defined at line 283 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename Base = void, auto&& callback>
bool AnyItem (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 Base = void, auto&& callback>
bool AnyItem (auto && callback)
Defined at line 294 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename... T>
void OnInvocableItems (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 310 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h
template <typename... T>
void OnInvocableItems (T &&... callbacks)
Defined at line 314 of file ../../zircon/kernel/phys/lib/boot-shim/include/lib/boot-shim/boot-shim.h