blob: 5e773f7af2c95dc0b9ac15aee54b61b4377169d8 [file] [log] [blame]
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +01001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Low-level entry and exit points of pvmfw.
16
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +010017use crate::config;
Alice Wang93ee98a2023-06-08 08:20:39 +000018use crate::memory;
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +010019use core::arch::asm;
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +000020use core::mem::size_of;
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +010021use core::ops::Range;
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010022use core::slice;
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +010023use log::error;
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +010024use log::warn;
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +010025use log::LevelFilter;
Alice Wang4be4dd02023-06-07 07:50:40 +000026use vmbase::util::RangeExt as _;
Alice Wangeacb7382023-06-05 12:53:54 +000027use vmbase::{
Pierre-Clément Tosi8ab7c372024-10-30 20:46:04 +000028 arch::aarch64::min_dcache_line_size,
Pierre-Clément Tosieba83162024-11-02 12:11:48 +000029 configure_heap, console_writeln, layout, limit_stack_size, main,
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +000030 memory::{
Pierre-Clément Tosiae071612024-11-02 13:13:34 +000031 deactivate_dynamic_page_tables, map_image_footer, unshare_all_memory,
32 unshare_all_mmio_except_uart, unshare_uart, MemoryTrackerError, SIZE_128KB, SIZE_4KB,
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +000033 },
Alice Wangeacb7382023-06-05 12:53:54 +000034 power::reboot,
35};
Jakob Vukalovic44b1ce32023-04-17 19:10:10 +010036use zeroize::Zeroize;
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010037
38#[derive(Debug, Clone)]
Andrew Walbran19690632022-12-07 16:41:30 +000039pub enum RebootReason {
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +010040 /// A malformed BCC was received.
41 InvalidBcc,
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +010042 /// An invalid configuration was appended to pvmfw.
43 InvalidConfig,
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010044 /// An unexpected internal error happened.
45 InternalError,
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +000046 /// The provided FDT was invalid.
47 InvalidFdt,
48 /// The provided payload was invalid.
49 InvalidPayload,
50 /// The provided ramdisk was invalid.
51 InvalidRamdisk,
Alice Wang28cbcf12022-12-01 07:58:28 +000052 /// Failed to verify the payload.
53 PayloadVerificationError,
Pierre-Clément Tosi4f4f5eb2022-12-08 14:31:42 +000054 /// DICE layering process failed.
55 SecretDerivationError,
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010056}
57
Pierre-Clément Tosib5a3ab12023-09-15 11:18:38 +010058impl RebootReason {
59 pub fn as_avf_reboot_string(&self) -> &'static str {
60 match self {
61 Self::InvalidBcc => "PVM_FIRMWARE_INVALID_BCC",
62 Self::InvalidConfig => "PVM_FIRMWARE_INVALID_CONFIG_DATA",
63 Self::InternalError => "PVM_FIRMWARE_INTERNAL_ERROR",
64 Self::InvalidFdt => "PVM_FIRMWARE_INVALID_FDT",
65 Self::InvalidPayload => "PVM_FIRMWARE_INVALID_PAYLOAD",
66 Self::InvalidRamdisk => "PVM_FIRMWARE_INVALID_RAMDISK",
67 Self::PayloadVerificationError => "PVM_FIRMWARE_PAYLOAD_VERIFICATION_FAILED",
68 Self::SecretDerivationError => "PVM_FIRMWARE_SECRET_DERIVATION_FAILED",
69 }
70 }
71}
72
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010073main!(start);
Pierre-Clément Tosi6a4808c2023-06-29 09:19:38 +000074configure_heap!(SIZE_128KB);
Pierre-Clément Tosieba83162024-11-02 12:11:48 +000075limit_stack_size!(SIZE_4KB * 12);
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010076
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +000077#[derive(Debug)]
78enum NextStage {
79 LinuxBoot(usize),
80 LinuxBootWithUart(usize),
81}
82
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010083/// Entry point for pVM firmware.
84pub fn start(fdt_address: u64, payload_start: u64, payload_size: u64, _arg3: u64) {
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +000085 let fdt_address = fdt_address.try_into().unwrap();
86 let payload_start = payload_start.try_into().unwrap();
87 let payload_size = payload_size.try_into().unwrap();
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +010088
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +000089 let reboot_reason = match main_wrapper(fdt_address, payload_start, payload_size) {
90 Err(r) => r,
91 Ok((next_stage, bcc)) => match next_stage {
92 NextStage::LinuxBootWithUart(ep) => jump_to_payload(fdt_address, ep, bcc),
93 NextStage::LinuxBoot(ep) => {
94 if let Err(e) = unshare_uart() {
95 error!("Failed to unmap UART: {e}");
96 RebootReason::InternalError
97 } else {
98 jump_to_payload(fdt_address, ep, bcc)
99 }
100 }
101 },
102 };
103
104 const REBOOT_REASON_CONSOLE: usize = 1;
105 console_writeln!(REBOOT_REASON_CONSOLE, "{}", reboot_reason.as_avf_reboot_string());
106 reboot()
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +0100107
108 // if we reach this point and return, vmbase::entry::rust_entry() will call power::shutdown().
109}
110
111/// Sets up the environment for main() and wraps its result for start().
112///
113/// Provide the abstractions necessary for start() to abort the pVM boot and for main() to run with
114/// the assumption that its environment has been properly configured.
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100115fn main_wrapper(
116 fdt: usize,
117 payload: usize,
118 payload_size: usize,
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000119) -> Result<(NextStage, Range<usize>), RebootReason> {
Pierre-Clément Tosi5bbfca52022-10-21 12:14:35 +0100120 // Limitations in this function:
121 // - only access MMIO once (and while) it has been mapped and configured
122 // - only perform logging once the logger has been initialized
123 // - only access non-pvmfw memory once (and while) it has been mapped
Pierre-Clément Tosifc531152022-10-20 12:22:23 +0100124
Pierre-Clément Tosid3305482023-06-29 15:03:48 +0000125 log::set_max_level(LevelFilter::Info);
Pierre-Clément Tosi41748ed2023-03-31 18:20:40 +0100126
Pierre-Clément Tosi229dd9d2024-11-02 10:34:27 +0000127 let appended_data = get_appended_data_slice().map_err(|e| {
128 error!("Failed to map the appended data: {e}");
129 RebootReason::InternalError
130 })?;
Alan Stokesc3829f12023-06-02 15:02:23 +0100131
Alan Stokes65618332023-12-15 14:09:25 +0000132 let appended = AppendedPayload::new(appended_data).ok_or_else(|| {
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +0100133 error!("No valid configuration found");
134 RebootReason::InvalidConfig
Pierre-Clément Tosia8a4a202022-11-03 14:16:46 +0000135 })?;
136
Alan Stokesd0cf3cd2023-12-12 14:36:37 +0000137 let config_entries = appended.get_entries();
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100138
Pierre-Clément Tosi462bdf42024-10-30 17:46:23 +0000139 let slices = memory::MemorySlices::new(
Seungjae Yoo013f4c42024-01-02 13:04:19 +0900140 fdt,
141 payload,
142 payload_size,
143 config_entries.vm_dtbo,
Seungjae Yoof0af81d2024-01-17 13:48:36 +0900144 config_entries.vm_ref_dt,
Seungjae Yoo013f4c42024-01-02 13:04:19 +0900145 )?;
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +0000146
Pierre-Clément Tosi072969b2022-10-19 17:32:24 +0100147 // This wrapper allows main() to be blissfully ignorant of platform details.
Pierre-Clément Tosi64aff642024-07-31 16:20:21 +0100148 let (next_bcc, debuggable_payload) = crate::main(
Alan Stokesd0cf3cd2023-12-12 14:36:37 +0000149 slices.fdt,
150 slices.kernel,
151 slices.ramdisk,
152 config_entries.bcc,
153 config_entries.debug_policy,
154 )?;
Pierre-Clément Tosi12f923e2024-12-04 22:30:45 +0000155 // Keep UART MMIO_GUARD-ed for debuggable payloads, to enable earlycon.
156 let keep_uart = cfg!(debuggable_vms_improvements) && debuggable_payload;
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100157
Jakob Vukalovic44b1ce32023-04-17 19:10:10 +0100158 // Writable-dirty regions will be flushed when MemoryTracker is dropped.
Alan Stokesd0cf3cd2023-12-12 14:36:37 +0000159 config_entries.bcc.zeroize();
Pierre-Clément Tosi072969b2022-10-19 17:32:24 +0100160
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +0000161 unshare_all_mmio_except_uart().map_err(|e| {
Andrew Walbran19690632022-12-07 16:41:30 +0000162 error!("Failed to unshare MMIO ranges: {e}");
163 RebootReason::InternalError
164 })?;
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +0000165 unshare_all_memory();
Pierre-Clément Tosi64aff642024-07-31 16:20:21 +0100166
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000167 let next_stage = select_next_stage(slices.kernel, keep_uart);
168
169 Ok((next_stage, next_bcc))
Pierre-Clément Tosi12f923e2024-12-04 22:30:45 +0000170}
171
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000172fn select_next_stage(kernel: &[u8], keep_uart: bool) -> NextStage {
173 if keep_uart {
174 NextStage::LinuxBootWithUart(kernel.as_ptr() as _)
175 } else {
176 NextStage::LinuxBoot(kernel.as_ptr() as _)
Pierre-Clément Tosi5ad1e8c2023-06-29 10:36:48 +0000177 }
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000178}
Jakob Vukalovic4c1edbe2023-04-17 19:10:57 +0100179
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000180fn jump_to_payload(fdt_address: usize, payload_start: usize, bcc: Range<usize>) -> ! {
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +0000181 deactivate_dynamic_page_tables();
Pierre-Clément Tosia99bfa62022-10-06 13:30:52 +0100182
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100183 const ASM_STP_ALIGN: usize = size_of::<u64>() * 2;
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000184 const SCTLR_EL1_RES1: u64 = (0b11 << 28) | (0b101 << 20) | (0b1 << 11);
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100185 // Stage 1 instruction access cacheability is unaffected.
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000186 const SCTLR_EL1_I: u64 = 0b1 << 12;
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100187 // SETEND instruction disabled at EL0 in aarch32 mode.
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000188 const SCTLR_EL1_SED: u64 = 0b1 << 8;
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100189 // Various IT instructions are disabled at EL0 in aarch32 mode.
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000190 const SCTLR_EL1_ITD: u64 = 0b1 << 7;
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100191
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000192 const SCTLR_EL1_VAL: u64 = SCTLR_EL1_RES1 | SCTLR_EL1_ITD | SCTLR_EL1_SED | SCTLR_EL1_I;
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100193
Pierre-Clément Tosi0b02a2b2024-11-28 22:48:27 +0000194 let scratch = layout::data_bss_range();
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100195
Alice Wanga3931aa2023-07-05 12:52:09 +0000196 assert_ne!(scratch.end - scratch.start, 0, "scratch memory is empty.");
197 assert_eq!(scratch.start.0 % ASM_STP_ALIGN, 0, "scratch memory is misaligned.");
198 assert_eq!(scratch.end.0 % ASM_STP_ALIGN, 0, "scratch memory is misaligned.");
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100199
Alice Wanga3931aa2023-07-05 12:52:09 +0000200 assert!(bcc.is_within(&(scratch.start.0..scratch.end.0)));
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100201 assert_eq!(bcc.start % ASM_STP_ALIGN, 0, "Misaligned guest BCC.");
202 assert_eq!(bcc.end % ASM_STP_ALIGN, 0, "Misaligned guest BCC.");
203
Pierre-Clément Tosieba83162024-11-02 12:11:48 +0000204 let stack = layout::stack_range();
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100205
Alice Wanga3931aa2023-07-05 12:52:09 +0000206 assert_ne!(stack.end - stack.start, 0, "stack region is empty.");
207 assert_eq!(stack.start.0 % ASM_STP_ALIGN, 0, "Misaligned stack region.");
208 assert_eq!(stack.end.0 % ASM_STP_ALIGN, 0, "Misaligned stack region.");
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100209
Pierre-Clément Tosi0b02a2b2024-11-28 22:48:27 +0000210 let eh_stack = layout::eh_stack_range();
211
212 assert_ne!(eh_stack.end - eh_stack.start, 0, "EH stack region is empty.");
213 assert_eq!(eh_stack.start.0 % ASM_STP_ALIGN, 0, "Misaligned EH stack region.");
214 assert_eq!(eh_stack.end.0 % ASM_STP_ALIGN, 0, "Misaligned EH stack region.");
215
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100216 // Zero all memory that could hold secrets and that can't be safely written to from Rust.
Pierre-Clément Tosi6c0d48b2022-11-07 11:00:32 +0000217 // Disable the exception vector, caches and page table and then jump to the payload at the
218 // given address, passing it the given FDT pointer.
219 //
Andrew Walbran20bb4e42023-07-07 13:55:55 +0100220 // SAFETY: We're exiting pvmfw by passing the register values we need to a noreturn asm!().
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100221 unsafe {
222 asm!(
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100223 "cmp {scratch}, {bcc}",
224 "b.hs 1f",
225
226 // Zero .data & .bss until BCC.
227 "0: stp xzr, xzr, [{scratch}], 16",
228 "cmp {scratch}, {bcc}",
229 "b.lo 0b",
230
231 "1:",
232 // Skip BCC.
233 "mov {scratch}, {bcc_end}",
234 "cmp {scratch}, {scratch_end}",
235 "b.hs 1f",
236
237 // Keep zeroing .data & .bss.
238 "0: stp xzr, xzr, [{scratch}], 16",
239 "cmp {scratch}, {scratch_end}",
240 "b.lo 0b",
241
242 "1:",
243 // Flush d-cache over .data & .bss (including BCC).
244 "0: dc cvau, {cache_line}",
245 "add {cache_line}, {cache_line}, {dcache_line_size}",
246 "cmp {cache_line}, {scratch_end}",
247 "b.lo 0b",
248
249 "mov {cache_line}, {stack}",
250 // Zero stack region.
251 "0: stp xzr, xzr, [{stack}], 16",
252 "cmp {stack}, {stack_end}",
253 "b.lo 0b",
254
255 // Flush d-cache over stack region.
256 "0: dc cvau, {cache_line}",
257 "add {cache_line}, {cache_line}, {dcache_line_size}",
258 "cmp {cache_line}, {stack_end}",
259 "b.lo 0b",
260
Pierre-Clément Tosi0b02a2b2024-11-28 22:48:27 +0000261 "mov {cache_line}, {eh_stack}",
262 // Zero EH stack region.
263 "0: stp xzr, xzr, [{eh_stack}], 16",
264 "cmp {eh_stack}, {eh_stack_end}",
265 "b.lo 0b",
266
267 // Flush d-cache over EH stack region.
268 "0: dc cvau, {cache_line}",
269 "add {cache_line}, {cache_line}, {dcache_line_size}",
270 "cmp {cache_line}, {eh_stack_end}",
271 "b.lo 0b",
272
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100273 "msr sctlr_el1, {sctlr_el1_val}",
274 "isb",
275 "mov x1, xzr",
276 "mov x2, xzr",
277 "mov x3, xzr",
278 "mov x4, xzr",
279 "mov x5, xzr",
280 "mov x6, xzr",
281 "mov x7, xzr",
282 "mov x8, xzr",
283 "mov x9, xzr",
284 "mov x10, xzr",
285 "mov x11, xzr",
286 "mov x12, xzr",
287 "mov x13, xzr",
288 "mov x14, xzr",
289 "mov x15, xzr",
290 "mov x16, xzr",
291 "mov x17, xzr",
292 "mov x18, xzr",
293 "mov x19, xzr",
294 "mov x20, xzr",
295 "mov x21, xzr",
296 "mov x22, xzr",
297 "mov x23, xzr",
298 "mov x24, xzr",
299 "mov x25, xzr",
300 "mov x26, xzr",
301 "mov x27, xzr",
302 "mov x28, xzr",
303 "mov x29, xzr",
304 "msr ttbr0_el1, xzr",
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100305 // Ensure that CMOs have completed before entering payload.
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100306 "dsb nsh",
307 "br x30",
308 sctlr_el1_val = in(reg) SCTLR_EL1_VAL,
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100309 bcc = in(reg) u64::try_from(bcc.start).unwrap(),
310 bcc_end = in(reg) u64::try_from(bcc.end).unwrap(),
Alice Wanga3931aa2023-07-05 12:52:09 +0000311 cache_line = in(reg) u64::try_from(scratch.start.0).unwrap(),
312 scratch = in(reg) u64::try_from(scratch.start.0).unwrap(),
313 scratch_end = in(reg) u64::try_from(scratch.end.0).unwrap(),
314 stack = in(reg) u64::try_from(stack.start.0).unwrap(),
315 stack_end = in(reg) u64::try_from(stack.end.0).unwrap(),
Pierre-Clément Tosi0b02a2b2024-11-28 22:48:27 +0000316 eh_stack = in(reg) u64::try_from(eh_stack.start.0).unwrap(),
317 eh_stack_end = in(reg) u64::try_from(eh_stack.end.0).unwrap(),
Alice Wang3fa9b802023-06-06 07:52:31 +0000318 dcache_line_size = in(reg) u64::try_from(min_dcache_line_size()).unwrap(),
Pierre-Clément Tosi9bb62ac2024-12-06 23:42:46 +0000319 in("x0") u64::try_from(fdt_address).unwrap(),
320 in("x30") u64::try_from(payload_start).unwrap(),
Pierre-Clément Tosi97f52492023-04-04 15:52:17 +0100321 options(noreturn),
Pierre-Clément Tosi645e90e2022-10-21 13:27:19 +0100322 );
323 };
324}
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100325
Pierre-Clément Tosi229dd9d2024-11-02 10:34:27 +0000326fn get_appended_data_slice() -> Result<&'static mut [u8], MemoryTrackerError> {
Pierre-Clément Tosic26e2202024-11-01 23:12:23 +0000327 let range = map_image_footer()?;
Pierre-Clément Tosi229dd9d2024-11-02 10:34:27 +0000328 // SAFETY: This region was just mapped for the first time (as map_image_footer() didn't fail)
329 // and the linker script prevents it from overlapping with other objects.
330 Ok(unsafe { slice::from_raw_parts_mut(range.start as *mut u8, range.len()) })
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100331}
332
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +0100333enum AppendedPayload<'a> {
334 /// Configuration data.
335 Config(config::Config<'a>),
336 /// Deprecated raw BCC, as used in Android T.
337 LegacyBcc(&'a mut [u8]),
338}
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100339
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +0100340impl<'a> AppendedPayload<'a> {
Alan Stokesc3829f12023-06-02 15:02:23 +0100341 fn new(data: &'a mut [u8]) -> Option<Self> {
Pierre-Clément Tosi147addf2024-04-15 15:07:58 +0100342 // The borrow checker gets confused about the ownership of data (see inline comments) so we
343 // intentionally obfuscate it using a raw pointer; see a similar issue (still not addressed
344 // in v1.77) in https://users.rust-lang.org/t/78467.
345 let data_ptr = data as *mut [u8];
346
347 // Config::new() borrows data as mutable ...
348 match config::Config::new(data) {
349 // ... so this branch has a mutable reference to data, from the Ok(Config<'a>). But ...
350 Ok(valid) => Some(Self::Config(valid)),
351 // ... if Config::new(data).is_err(), the Err holds no ref to data. However ...
352 Err(config::Error::InvalidMagic) if cfg!(feature = "legacy") => {
353 // ... the borrow checker still complains about a second mutable ref without this.
354 // SAFETY: Pointer to a valid mut (not accessed elsewhere), 'a lifetime re-used.
355 let data: &'a mut _ = unsafe { &mut *data_ptr };
356
Alice Wangeacb7382023-06-05 12:53:54 +0000357 const BCC_SIZE: usize = SIZE_4KB;
Pierre-Clément Tosi7aca7ff2022-12-12 14:04:30 +0000358 warn!("Assuming the appended data at {:?} to be a raw BCC", data.as_ptr());
359 Some(Self::LegacyBcc(&mut data[..BCC_SIZE]))
360 }
Pierre-Clément Tosi7aca7ff2022-12-12 14:04:30 +0000361 Err(e) => {
Pierre-Clément Tosi147addf2024-04-15 15:07:58 +0100362 error!("Invalid configuration data at {data_ptr:?}: {e}");
363 None
Pierre-Clément Tosi7aca7ff2022-12-12 14:04:30 +0000364 }
Pierre-Clément Tosi7aca7ff2022-12-12 14:04:30 +0000365 }
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +0100366 }
367
Alan Stokes65618332023-12-15 14:09:25 +0000368 fn get_entries(self) -> config::Entries<'a> {
Pierre-Clément Tosi20b60962022-10-17 13:35:27 +0100369 match self {
Alan Stokesd0cf3cd2023-12-12 14:36:37 +0000370 Self::Config(cfg) => cfg.get_entries(),
371 Self::LegacyBcc(bcc) => config::Entries { bcc, ..Default::default() },
Pierre-Clément Tosi8edf72e2022-12-06 16:02:57 +0000372 }
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +0100373 }
374}