qemu_command_builder/boot.rs
1use bon::Builder;
2
3use crate::common::OnOff;
4use crate::to_command::ToArg;
5use crate::to_command::ToCommand;
6
7/// Specify boot order drives as a string of drive letters. Valid drive
8/// letters depend on the target architecture. The x86 PC uses: a, b
9/// (floppy 1 and 2), c (first hard disk), d (first CD-ROM), n-p
10/// (Etherboot from network adapter 1-4), hard disk boot is the default.
11/// To apply a particular boot order only on the first startup, specify
12/// it via ``once``. Note that the ``order`` or ``once`` parameter
13/// should not be used together with the ``bootindex`` property of
14/// devices, since the firmware implementations normally do not support
15/// both at the same time.
16///
17/// Interactive boot menus/prompts can be enabled via ``menu=on`` as far
18/// as firmware/BIOS supports them. The default is non-interactive boot.
19///
20/// A splash picture could be passed to bios, enabling user to show it
21/// as logo, when option splash=sp\_name is given and menu=on, If
22/// firmware/BIOS supports them. Currently Seabios for X86 system
23/// support it. limitation: The splash file could be a jpeg file or a
24/// BMP file in 24 BPP format(true color). The resolution should be
25/// supported by the SVGA mode, so the recommended is 320x240, 640x480,
26/// 800x640.
27///
28/// A timeout could be passed to bios, guest will pause for rb\_timeout
29/// ms when boot failed, then reboot. If rb\_timeout is '-1', guest will
30/// not reboot, qemu passes '-1' to bios by default. Currently Seabios
31/// for X86 system support it.
32///
33/// Do strict boot via ``strict=on`` as far as firmware/BIOS supports
34/// it. This only effects when boot priority is changed by bootindex
35/// options. The default is non-strict boot.
36#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Builder)]
37pub struct Boot {
38 order: Option<String>,
39 once: Option<String>,
40 menu: Option<OnOff>,
41 splash: Option<String>,
42 splash_time: Option<usize>,
43 reboot_timeout: Option<usize>,
44 strict: Option<OnOff>,
45}
46
47impl ToCommand for Boot {
48 fn to_command(&self) -> Vec<String> {
49 let mut cmd = vec![];
50
51 if self.order.is_some()
52 || self.once.is_some()
53 || self.menu.is_some()
54 || self.splash.is_some()
55 || self.splash_time.is_some()
56 || self.reboot_timeout.is_some()
57 || self.strict.is_some()
58 {
59 cmd.push("-boot".to_string());
60 }
61
62 let mut args = vec![];
63
64 if let Some(order) = &self.order {
65 args.push(format!("order={}", order));
66 }
67 if let Some(once) = &self.once {
68 args.push(format!("once={}", once));
69 }
70 if let Some(menu) = &self.menu {
71 args.push(format!("menu={}", menu.to_arg()));
72 }
73 if let Some(splash) = &self.splash {
74 args.push(format!("splash={}", splash));
75 }
76 if let Some(splash_time) = &self.splash_time {
77 args.push(format!("splash-time={}", splash_time));
78 }
79 if let Some(reboot_timeout) = &self.reboot_timeout {
80 args.push(format!("reboot-timeout={}", reboot_timeout));
81 }
82 if let Some(strict) = &self.strict {
83 args.push(format!("strict={}", strict.to_arg()));
84 }
85 cmd.push(args.join(","));
86 cmd
87 }
88}