1 //! Types related to firmware storage.
2 
3 use crate::Guid;
4 use bitflags::bitflags;
5 
6 /// Corresponds to the C type `EFI_FIRMWARE_VOLUME_HEADER`.
7 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
8 #[repr(C)]
9 pub struct FirmwareVolumeHeader {
10     pub zero_vector: [u8; 16],
11     pub file_system_guid: Guid,
12     pub fv_length: u64,
13     pub signature: [u8; 4],
14     pub attributes: FirmwareVolumeAttributes,
15     pub header_length: u16,
16     pub checksum: u16,
17     pub ext_header_offset: u16,
18     pub reserved: u8,
19     pub revision: u8,
20 
21     /// Variable-length array of block maps, terminated with a zero-filled
22     /// entry.
23     pub block_map: [FirmwareVolumeBlockMap; 0],
24 }
25 
26 impl FirmwareVolumeHeader {
27     pub const SIGNATURE: [u8; 4] = *b"_FVH";
28 }
29 
30 /// Corresponds to the C type `EFI_FV_BLOCK_MAP`.
31 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
32 #[repr(C)]
33 pub struct FirmwareVolumeBlockMap {
34     pub num_blocks: u32,
35     pub length: u32,
36 }
37 
38 bitflags! {
39     /// Corresponds to the C type `EFI_FVB_ATTRIBUTES_2`.
40     #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
41     #[repr(transparent)]
42     pub struct FirmwareVolumeAttributes: u32 {
43         const READ_DISABLED_CAP = 0x0000_0001;
44         const READ_ENABLED_CAP = 0x0000_0002;
45         const READ_STATUS = 0x0000_0004;
46 
47         const WRITE_DISABLED_CAP = 0x0000_0008;
48         const WRITE_ENABLED_CAP = 0x0000_0010;
49         const WRITE_STATUS = 0x0000_0020;
50 
51         const LOCK_CAP = 0x0000_0040;
52         const LOCK_STATUS = 0x0000_0080;
53 
54         const STICKY_WRITE = 0x0000_0200;
55         const MEMORY_MAPPED = 0x0000_0400;
56         const ERASE_POLARITY = 0x0000_0800;
57 
58         const READ_LOCK_CAP = 0x0000_1000;
59         const READ_LOCK_STATUS = 0x0000_2000;
60 
61         const WRITE_LOCK_CAP = 0x0000_4000;
62         const WRITE_LOCK_STATUS = 0x0000_8000;
63 
64         const ALIGNMENT = 0x001f_0000;
65         const WEAK_ALIGNMENT = 0x8000_0000;
66         const ALIGNMENT_1 = 0x0000_0000;
67         const ALIGNMENT_2 = 0x0001_0000;
68         const ALIGNMENT_4 = 0x0002_0000;
69         const ALIGNMENT_8 = 0x0003_0000;
70         const ALIGNMENT_16 = 0x0004_0000;
71         const ALIGNMENT_32 = 0x0005_0000;
72         const ALIGNMENT_64 = 0x0006_0000;
73         const ALIGNMENT_128 = 0x0007_0000;
74         const ALIGNMENT_256 = 0x0008_0000;
75         const ALIGNMENT_512 = 0x0008_0000;
76         const ALIGNMENT_1K = 0x000a_0000;
77         const ALIGNMENT_2K = 0x000b_0000;
78         const ALIGNMENT_4K = 0x000c_0000;
79         const ALIGNMENT_8K = 0x000d_0000;
80         const ALIGNMENT_16K = 0x000e_0000;
81         const ALIGNMENT_32K = 0x000f_0000;
82         const ALIGNMENT_64K = 0x0010_0000;
83         const ALIGNMENT_128K = 0x0011_0000;
84         const ALIGNMENT_256K = 0x0012_0000;
85         const ALIGNMENT_512K = 0x0013_0000;
86         const ALIGNMENT_1M = 0x0014_0000;
87         const ALIGNMENT_2M = 0x0015_0000;
88         const ALIGNMENT_4M = 0x0016_0000;
89         const ALIGNMENT_8M = 0x0017_0000;
90         const ALIGNMENT_16M = 0x0018_0000;
91         const ALIGNMENT_32M = 0x0019_0000;
92         const ALIGNMENT_64M = 0x001a_0000;
93         const ALIGNMENT_128M = 0x001b_0000;
94         const ALIGNMENT_256M = 0x001c_0000;
95         const ALIGNMENT_512M = 0x001d_0000;
96         const ALIGNMENT_1G = 0x001e_0000;
97         const ALIGNMENT_2G = 0x001f_0000;
98     }
99 }
100