Skip to main content

fdt_raw/node/
chosen.rs

1//! Chosen node type for boot parameters.
2//!
3//! This module provides the `Chosen` type which represents the /chosen node
4//! in the device tree, containing boot parameters and system configuration.
5
6use core::ops::Deref;
7
8use super::NodeBase;
9
10/// The /chosen node containing boot parameters.
11///
12/// This node contains system configuration parameters chosen by the firmware
13/// or bootloader, such as boot arguments, console paths, and other boot-time
14/// settings.
15#[derive(Clone)]
16pub struct Chosen<'a> {
17    node: NodeBase<'a>,
18}
19
20impl<'a> Chosen<'a> {
21    /// Creates a new Chosen wrapper from a NodeBase.
22    pub(crate) fn new(node: NodeBase<'a>) -> Self {
23        Self { node }
24    }
25
26    /// Returns the bootargs property value.
27    ///
28    /// This property contains command-line arguments to be passed to the
29    /// operating system kernel.
30    pub fn bootargs(&self) -> Option<&'a str> {
31        self.node.find_property_str("bootargs")
32    }
33
34    /// Returns the stdout-path property value.
35    ///
36    /// This property specifies the path to the device to be used for
37    /// standard output (console).
38    pub fn stdout_path(&self) -> Option<&'a str> {
39        self.node.find_property_str("stdout-path")
40    }
41
42    /// Returns the stdin-path property value.
43    ///
44    /// This property specifies the path to the device to be used for
45    /// standard input.
46    pub fn stdin_path(&self) -> Option<&'a str> {
47        self.node.find_property_str("stdin-path")
48    }
49}
50
51impl<'a> Deref for Chosen<'a> {
52    type Target = NodeBase<'a>;
53
54    fn deref(&self) -> &Self::Target {
55        &self.node
56    }
57}
58
59impl core::fmt::Debug for Chosen<'_> {
60    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61        f.debug_struct("Chosen")
62            .field("bootargs", &self.bootargs())
63            .field("stdout_path", &self.stdout_path())
64            .finish()
65    }
66}