Alice Wang | 474c0ee | 2023-09-14 12:52:33 +0000 | [diff] [blame] | 1 | // 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 | |
| 17 | use core::ops::Range; |
Pierre-Clément Tosi | 1bf532b | 2023-11-13 11:06:20 +0000 | [diff] [blame] | 18 | use cstr::cstr; |
Alice Wang | 474c0ee | 2023-09-14 12:52:33 +0000 | [diff] [blame] | 19 | use libfdt::{Fdt, FdtError}; |
Alice Wang | 474c0ee | 2023-09-14 12:52:33 +0000 | [diff] [blame] | 20 | |
| 21 | /// Reads the DICE data range from the given `fdt`. |
| 22 | pub fn read_dice_range_from(fdt: &Fdt) -> libfdt::Result<Range<usize>> { |
| 23 | let node = fdt.node(cstr!("/reserved-memory"))?.ok_or(FdtError::NotFound)?; |
| 24 | let node = node.next_compatible(cstr!("google,open-dice"))?.ok_or(FdtError::NotFound)?; |
| 25 | node.first_reg()?.try_into() |
| 26 | } |
Alice Wang | 9eebbab | 2024-04-10 14:57:27 +0000 | [diff] [blame] | 27 | |
| 28 | pub(crate) fn read_vendor_hashtree_root_digest(fdt: &Fdt) -> libfdt::Result<Option<&[u8]>> { |
| 29 | let node = fdt.node(cstr!("/avf"))?.ok_or(FdtError::NotFound)?; |
| 30 | node.getprop(cstr!("vendor_hashtree_descriptor_root_digest")) |
| 31 | } |
Alice Wang | a2228b9 | 2024-07-26 08:38:47 +0000 | [diff] [blame^] | 32 | |
| 33 | pub(crate) fn read_is_strict_boot(fdt: &Fdt) -> libfdt::Result<bool> { |
| 34 | match fdt.chosen()? { |
| 35 | Some(node) => Ok(node.getprop(cstr!("avf,strict-boot"))?.is_some()), |
| 36 | None => Ok(false), |
| 37 | } |
| 38 | } |