blob: 06879d0095f95d0df3d55b5f5cd5868ca42ab90a [file] [log] [blame]
Alice Wang474c0ee2023-09-14 12:52:33 +00001// Copyright 2023, 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//! High-level FDT functions.
16
17use core::ops::Range;
18use libfdt::{Fdt, FdtError};
Alice Wang474c0ee2023-09-14 12:52:33 +000019
20/// Reads the DICE data range from the given `fdt`.
21pub fn read_dice_range_from(fdt: &Fdt) -> libfdt::Result<Range<usize>> {
Alan Stokesf46a17c2025-01-05 15:50:18 +000022 let node = fdt.node(c"/reserved-memory")?.ok_or(FdtError::NotFound)?;
23 let node = node.next_compatible(c"google,open-dice")?.ok_or(FdtError::NotFound)?;
Alice Wang474c0ee2023-09-14 12:52:33 +000024 node.first_reg()?.try_into()
25}
Alice Wang9eebbab2024-04-10 14:57:27 +000026
27pub(crate) fn read_vendor_hashtree_root_digest(fdt: &Fdt) -> libfdt::Result<Option<&[u8]>> {
Alan Stokesf46a17c2025-01-05 15:50:18 +000028 let node = fdt.node(c"/avf")?.ok_or(FdtError::NotFound)?;
29 node.getprop(c"vendor_hashtree_descriptor_root_digest")
Alice Wang9eebbab2024-04-10 14:57:27 +000030}
Alice Wanga2228b92024-07-26 08:38:47 +000031
32pub(crate) fn read_is_strict_boot(fdt: &Fdt) -> libfdt::Result<bool> {
33 match fdt.chosen()? {
Alan Stokesf46a17c2025-01-05 15:50:18 +000034 Some(node) => Ok(node.getprop(c"avf,strict-boot")?.is_some()),
Alice Wanga2228b92024-07-26 08:38:47 +000035 None => Ok(false),
36 }
37}