xref: /DADK/dadk-config/src/boot/mod.rs (revision 5129c63bfab60a54627def29dc1b53c722677e4e)
1 use std::{fs, path::PathBuf};
2 
3 use anyhow::Result;
4 use dragonstub::DragonStubConfig;
5 use grub::GrubConfig;
6 use hypervisor::qemu::QemuConfig;
7 use metadata::BootMetadata;
8 use serde::Deserialize;
9 use uboot::UbootConfig;
10 
11 pub mod dragonstub;
12 pub mod grub;
13 pub mod hypervisor;
14 pub mod metadata;
15 pub mod uboot;
16 
17 /// Boot configuration file
18 #[derive(Debug, Clone, Deserialize)]
19 pub struct BootConfigFile {
20     /// Boot metadata
21     pub metadata: BootMetadata,
22 
23     /// GRUB configuration
24     pub grub: Option<GrubConfig>,
25     /// DragonStub configuration
26     pub dragonstub: Option<DragonStubConfig>,
27 
28     /// U-Boot configuration
29     pub uboot: Option<UbootConfig>,
30 
31     /// QEMU configuration
32     pub qemu: Option<QemuConfig>,
33 }
34 
35 impl BootConfigFile {
36     pub fn load(path: &PathBuf) -> Result<Self> {
37         // 读取文件内容
38         let content = fs::read_to_string(path)?;
39         Self::load_from_str(&content)
40     }
41 
42     pub fn load_from_str(content: &str) -> Result<Self> {
43         let config: BootConfigFile = toml::from_str(content)?;
44 
45         Ok(config)
46     }
47 }
48