blob: 5b9efd29361059ccd879b496bbc81c0c009b5a2b [file] [log] [blame]
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +00001// 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//! High-level FDT functions.
16
17use core::ffi::CStr;
18use core::ops::Range;
19
20/// Extract from /chosen the address range containing the pre-loaded ramdisk.
21pub fn initrd_range(fdt: &libfdt::Fdt) -> libfdt::Result<Option<Range<usize>>> {
22 let start = CStr::from_bytes_with_nul(b"linux,initrd-start\0").unwrap();
23 let end = CStr::from_bytes_with_nul(b"linux,initrd-end\0").unwrap();
24
25 if let Some(chosen) = fdt.chosen()? {
26 if let (Some(start), Some(end)) = (chosen.getprop_u32(start)?, chosen.getprop_u32(end)?) {
27 return Ok(Some((start as usize)..(end as usize)));
28 }
29 }
30
31 Ok(None)
32}