Next Generation WASM Microkernel Operating System
1// Copyright 2025 Jonas Kruckenberg
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8use core::str::FromStr;
9
10use crate::backtrace::BacktraceStyle;
11use crate::device_tree::DeviceTree;
12use crate::tracing::Filter;
13
14pub fn parse(devtree: &DeviceTree) -> crate::Result<Bootargs> {
15 let chosen = devtree.find_by_path("/chosen").unwrap();
16 let Some(prop) = chosen.property("bootargs") else {
17 return Ok(Bootargs::default());
18 };
19
20 Bootargs::from_str(prop.as_str()?)
21}
22
23#[derive(Default)]
24pub struct Bootargs {
25 pub log: Filter,
26 pub backtrace: BacktraceStyle,
27}
28
29impl FromStr for Bootargs {
30 type Err = anyhow::Error;
31
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 let mut log = None;
34 let mut backtrace = None;
35
36 let parts = s.trim().split(';');
37 for part in parts {
38 if let Some(current) = part.strip_prefix("log=") {
39 log = Some(Filter::from_str(current)?);
40 }
41
42 if let Some(current) = part.strip_prefix("backtrace=") {
43 backtrace = Some(BacktraceStyle::from_str(current)?);
44 }
45 }
46
47 Ok(Self {
48 log: log.unwrap_or_default(),
49 backtrace: backtrace.unwrap_or_default(),
50 })
51 }
52}