fidl_data_zbi/zbi.rs
1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// DO NOT EDIT.
6// Generated from FIDL library `zbi` by zither, a Fuchsia platform tool.
7
8#![allow(unused_imports)]
9
10use bitflags::bitflags;
11use zerocopy::{FromBytes, IntoBytes};
12
13pub const ALIGNMENT: u32 = 8;
14
15/// Numeric prefix for kernel types.
16///
17/// 'KRN\0'
18pub const TYPE_KERNEL_PREFIX: u32 = 0x004e524b;
19
20/// Mask to compare against TYPE_KERNEL_PREFIX.
21pub const TYPE_KERNEL_MASK: u32 = 0x00ffffff;
22
23/// Numeric prefix for driver metadata types.
24///
25/// 'm\0\0\0'
26pub const TYPE_DRIVER_METADATA_PREFIX: u32 = 0x0000006d;
27
28/// Mask to compare against TYPE_DRIVER_METADATA_PREFIX.
29pub const TYPE_DRIVER_METADATA_MASK: u32 = 0x000000ff;
30
31#[repr(u32)]
32#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
33pub enum Type {
34 /// 'BOOT'
35 ///
36 /// Each ZBI starts with a container header.
37 /// length: Total size of the image after this header.
38 /// This includes all item headers, payloads, and padding.
39 /// It does not include the container header itself.
40 /// Must be a multiple of ZBI_ALIGNMENT.
41 /// extra: Must be ZBI_CONTAINER_MAGIC.
42 /// flags: Must be ZBI_FLAGS_VERSION and no other flags.
43 Container = 0x544f4f42,
44
45 /// x86-64 kernel. See zbi_kernel_t for a payload description.
46 ///
47 /// 'KRNL'
48 KernelX64 = 1280201291, // 0x4c000000 | TYPE_KERNEL_PREFIX
49
50 /// ARM64 kernel. See zbi_kernel_t for a payload description.
51 ///
52 /// KRN8
53 KernelArm64 = 944656971, // 0x38000000 | TYPE_KERNEL_PREFIX
54
55 /// RISC-V kernel. See zbi_kernel_t for a payload description.
56 ///
57 /// 'KRNV'
58 KernelRiscv64 = 1447973451, // 0x56000000 | TYPE_KERNEL_PREFIX
59
60 /// A discarded item that should just be ignored. This is used for an
61 /// item that was already processed and should be ignored by whatever
62 /// stage is now looking at the ZBI. An earlier stage already "consumed"
63 /// this information, but avoided copying data around to remove it from
64 /// the ZBI item stream.
65 ///
66 /// 'SKIP'
67 Discard = 0x50494b53,
68
69 /// A virtual disk image. This is meant to be treated as if it were a
70 /// storage device. The payload (after decompression) is the contents of
71 /// the storage device, in whatever format that might be.
72 ///
73 /// 'RDSK'
74 StorageRamdisk = 0x4b534452,
75
76 /// The /boot filesystem in BOOTFS format, specified in
77 /// <lib/zbi-format/internal/bootfs.h>. This represents an internal
78 /// contract between Zircon userboot (//docs/userboot.md), which handles
79 /// the contents of this filesystem, and platform tooling, which prepares
80 /// them.
81 ///
82 /// 'BFSB'
83 StorageBootfs = 0x42534642,
84
85 /// Storage used by the kernel (such as a compressed image containing the
86 /// actual kernel). The meaning and format of the data is specific to the
87 /// kernel, though it always uses the standard (private) storage
88 /// compression protocol. Each particular KERNEL_{ARCH} item image and its
89 /// STORAGE_KERNEL item image are intimately tied and one cannot work
90 /// without the exact correct corresponding other.
91 ///
92 /// 'KSTR'
93 StorageKernel = 0x5254534b,
94
95 /// Device-specific factory data, stored in BOOTFS format.
96 ///
97 /// TODO(https://fxbug.dev/42109921): This should not use the "STORAGE" infix.
98 ///
99 /// 'BFSF'
100 StorageBootfsFactory = 0x46534642,
101
102 /// A kernel command line fragment, a UTF-8 string that need not be
103 /// NUL-terminated. The kernel's own option parsing accepts only printable
104 /// 'ASCI'I and treats all other characters as equivalent to whitespace. Multiple
105 /// ZBI_TYPE_CMDLINE items can appear. They are treated as if concatenated with
106 /// ' ' between each item, in the order they appear: first items in the bootable
107 /// ZBI containing the kernel; then items in the ZBI synthesized by the boot
108 /// loader. The kernel interprets the [whole command line](../../../../docs/kernel_cmdline.md).
109 ///
110 /// 'CMDL'
111 Cmdline = 0x4c444d43,
112
113 /// The crash log from the previous boot, a UTF-8 string.
114 ///
115 /// 'BOOM'
116 Crashlog = 0x4d4f4f42,
117
118 /// Physical memory region that will persist across warm boots. See zbi_nvram_t
119 /// for payload description.
120 ///
121 /// 'NVLL'
122 Nvram = 0x4c4c564e,
123
124 /// Platform ID Information.
125 ///
126 /// 'PLID'
127 PlatformId = 0x44494c50,
128
129 /// Board-specific information.
130 ///
131 /// mBSI
132 DrvBoardInfo = 1230193261, // 0x49534200 | TYPE_DRIVER_METADATA_PREFIX
133
134 /// CPU configuration. See zbi_topology_node_t for a description of the payload.
135 CpuTopology = 0x43505533,
136
137 /// Device memory configuration. See zbi_mem_range_t for a description of the
138 /// payload.
139 ///
140 /// 'MEMC'
141 MemConfig = 0x434d454d,
142
143 /// Kernel driver configuration. The zbi_header_t.extra field gives a
144 /// ZBI_KERNEL_DRIVER_* type that determines the payload format.
145 /// See <lib/zbi-format/driver-config.h> for details.
146 ///
147 /// 'KDRV'
148 KernelDriver = 0x5652444b,
149
150 /// 'ACPI' Root Table Pointer, a uint64_t physical address.
151 ///
152 /// 'RSDP'
153 AcpiRsdp = 0x50445352,
154
155 /// 'SMBI'
156 ///
157 /// 'SMBI'OS entry point, a uint64_t physical address.
158 Smbios = 0x49424d53,
159
160 /// EFI system table, a uint64_t physical address.
161 ///
162 /// 'EFIS'
163 EfiSystemTable = 0x53494645,
164
165 /// EFI memory attributes table. An example of this format can be found in UEFI 2.10 section 4.6.4,
166 /// but the consumer of this item is responsible for interpreting whatever the bootloader supplies
167 /// (in particular the "version" field may differ as the format evolves).
168 ///
169 /// 'EMAT'
170 EfiMemoryAttributesTable = 0x54414d45,
171
172 /// Framebuffer parameters, a zbi_swfb_t entry.
173 ///
174 /// 'SWFB'
175 Framebuffer = 0x42465753,
176
177 /// The image arguments, data is a trivial text format of one "key=value" per line
178 /// with leading whitespace stripped and "#" comment lines and blank lines ignored.
179 /// It is processed by bootsvc and parsed args are shared to others via Arguments service.
180 /// TODO: the format can be streamlined after the /config/additional_boot_args compat support is
181 /// removed.
182 ///
183 /// 'IARG'
184 ImageArgs = 0x47524149,
185
186 /// A copy of the boot version stored within the sysconfig
187 /// partition
188 ///
189 /// 'BVRS'
190 BootVersion = 0x53525642,
191
192 /// MAC address for Ethernet, Wifi, Bluetooth, etc. zbi_header_t.extra
193 /// is a board-specific index to specify which device the MAC address
194 /// applies to. zbi_header_t.length gives the size in bytes, which
195 /// varies depending on the type of address appropriate for the device.
196 ///
197 /// mMAC
198 DrvMacAddress = 1128353133, // 0x43414d00 | TYPE_DRIVER_METADATA_PREFIX
199
200 /// A partition map for a storage device, a zbi_partition_map_t header
201 /// followed by one or more zbi_partition_t entries. zbi_header_t.extra
202 /// is a board-specific index to specify which device this applies to.
203 ///
204 /// mPRT
205 DrvPartitionMap = 1414680685, // 0x54525000 | TYPE_DRIVER_METADATA_PREFIX
206
207 /// Private information for the board driver.
208 ///
209 /// mBOR
210 DrvBoardPrivate = 1380926061, // 0x524f4200 | TYPE_DRIVER_METADATA_PREFIX
211
212 /// 'HWRB'
213 HwRebootReason = 0x42525748,
214
215 /// The serial number, an unterminated ASCII string of printable non-whitespace
216 /// characters with length zbi_header_t.length.
217 ///
218 /// 'SRLN'
219 SerialNumber = 0x4e4c5253,
220
221 /// This type specifies a binary file passed in by the bootloader.
222 /// The first byte specifies the length of the filename without a NUL terminator.
223 /// The filename starts on the second byte.
224 /// The file contents are located immediately after the filename.
225 ///
226 /// Layout: | name_len | name | payload
227 /// ^(1 byte) ^(name_len bytes) ^(length of file)
228 ///
229 /// 'BTFL'
230 BootloaderFile = 0x4c465442,
231
232 /// The devicetree blob from the legacy boot loader, if any. This is used only
233 /// for diagnostic and development purposes. Zircon kernel and driver
234 /// configuration is entirely driven by specific ZBI items from the boot
235 /// loader. The boot shims for legacy boot loaders pass the raw devicetree
236 /// along for development purposes, but extract information from it to populate
237 /// specific ZBI items such as ZBI_TYPE_KERNEL_DRIVER et al.
238 Devicetree = 0xd00dfeed,
239
240 /// An arbitrary number of random bytes attested to have high entropy. Any
241 /// number of items of any size can be provided, but no data should be provided
242 /// that is not true entropy of cryptographic quality. This is used to seed
243 /// secure cryptographic pseudo-random number generators.
244 ///
245 /// 'RAND'
246 SecureEntropy = 0x444e4152,
247
248 /// This provides a data dump and associated logging from a boot loader,
249 /// shim, or earlier incarnation that wants its data percolated up by the
250 /// booting Zircon kernel. See zbi_debugdata_t for a description of the
251 /// payload.
252 ///
253 /// 'DBGD'
254 Debugdata = 0x44474244,
255
256 /// Each RISC-V hart has an associated "ISA string" encoding its supported
257 /// extensions: see Chapter 27 (ISA Extension Naming Conventions) in
258 /// https://riscv.org/wp-content/uploads/2019/12/riscv-spec-20191213.pdf.
259 /// This item gives the NUL-separated (and -terminated) concatenation of
260 /// all such strings in the system.
261 ///
262 /// The first character of the table must be NUL; that is, the first entry
263 /// in the table must be the empty and invalid, which is pointed to by a
264 /// default-constructructed index. Beyond that, there are no guarantees to
265 /// order the strings in the table or the extent of their (de)duplication.
266 ///
267 /// A given hart's index into the table is encoded within its associated
268 /// node structure in the ZBI_TYPE_CPU_TOPOLOGY item.
269 ///
270 /// 'VISA'
271 Riscv64IsaStrtab = 0x41534956,
272}
273
274/// LSW of sha256("bootdata")
275pub const CONTAINER_MAGIC: u32 = 0x868cf7e6;
276
277/// LSW of sha256("bootitem")
278pub const ITEM_MAGIC: u32 = 0xb5781729;
279
280/// Flags associated with an item. A valid flags value must always include
281/// ZBI_FLAGS_VERSION. Values should also contain ZBI_FLAGS_CRC32 for any item
282/// where it's feasible to compute the CRC32 at build time. Other flags are
283/// specific to each type.
284#[repr(C)]
285#[derive(IntoBytes, FromBytes, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
286pub struct Flags(u32);
287
288bitflags! {
289 impl Flags : u32 {
290
291 /// This flag is always required.
292 const VERSION = 1 << 16;
293
294 /// ZBI items with the CRC32 flag must have a valid crc32.
295 /// Otherwise their crc32 field must contain ZBI_ITEM_NO_CRC32
296 const CRC32 = 1 << 17;
297 }
298}
299
300/// Value for zbi_header_t.crc32 when ZBI_FLAGS_CRC32 is not set.
301pub const ITEM_NO_CRC32: u32 = 0x4a87e8d6;
302
303/// Each header must be 8-byte aligned. The length field specifies the
304/// actual payload length and does not include the size of padding.
305#[repr(C)]
306#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
307pub struct Header {
308 /// ZBI_TYPE_* constant.
309 pub r#type: Type,
310
311 /// Size of the payload immediately following this header. This
312 /// does not include the header itself nor any alignment padding
313 /// after the payload.
314 pub length: u32,
315
316 /// Type-specific extra data. Each type specifies the use of this
317 /// field. When not explicitly specified, it should be zero.
318 pub extra: u32,
319
320 /// Flags for this item.
321 pub flags: Flags,
322
323 /// For future expansion. Set to 0.
324 pub reserved0: u32,
325 pub reserved1: u32,
326
327 /// Must be ZBI_ITEM_MAGIC.
328 pub magic: u32,
329
330 /// Must be the CRC32 of payload if ZBI_FLAGS_CRC32 is set,
331 /// otherwise must be ZBI_ITEM_NO_CRC32.
332 pub crc32: u32,
333}