Skip to content

Commit 2bf5334

Browse files
zyuiopmkroening
authored andcommitted
refactor(fdt): make bootargs owned
1 parent b4ad862 commit 2bf5334

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/arch/x86_64/firecracker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::borrow::ToOwned;
12
use core::ptr::write_bytes;
23
use core::{ptr, slice};
34

@@ -217,7 +218,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
217218
info!("Found available RAM: [{start_address:#x} - {end_address:#x}]");
218219

219220
if let Some(command_line) = command_line {
220-
fdt = fdt.bootargs(command_line).unwrap();
221+
fdt = fdt.bootargs(command_line.to_owned()).unwrap();
221222
}
222223

223224
let fdt = fdt.finish().unwrap();

src/arch/x86_64/multiboot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::borrow::ToOwned;
12
use core::ptr::write_bytes;
23
use core::{mem, ptr, slice};
34

@@ -65,7 +66,7 @@ impl DeviceTree {
6566
let mut fdt = Fdt::new("multiboot")?.memory_regions(memory_regions)?;
6667

6768
if let Some(cmdline) = multiboot.command_line() {
68-
fdt = fdt.bootargs(cmdline)?;
69+
fdt = fdt.bootargs(cmdline.to_owned())?;
6970
}
7071

7172
let fdt = fdt.finish()?;

src/fdt.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use alloc::format;
2+
use alloc::string::String;
23
use alloc::vec::Vec;
34
use core::ops::Range;
45

56
use vm_fdt::{FdtWriter, FdtWriterNode, FdtWriterResult};
67

7-
pub struct Fdt<'a> {
8+
pub struct Fdt {
89
writer: FdtWriter,
910
root_node: FdtWriterNode,
10-
bootargs: Option<&'a str>,
11+
bootargs: Option<String>,
1112
}
1213

13-
impl<'a> Fdt<'a> {
14+
impl Fdt {
1415
pub fn new(platform: &str) -> FdtWriterResult<Self> {
1516
let mut writer = FdtWriter::new()?;
1617

@@ -30,7 +31,7 @@ impl<'a> Fdt<'a> {
3031

3132
pub fn finish(mut self) -> FdtWriterResult<Vec<u8>> {
3233
let chosen_node = self.writer.begin_node("chosen")?;
33-
if let Some(bootargs) = self.bootargs {
34+
if let Some(bootargs) = &self.bootargs {
3435
self.writer.property_string("bootargs", bootargs)?;
3536
}
3637
self.writer.end_node(chosen_node)?;
@@ -41,7 +42,7 @@ impl<'a> Fdt<'a> {
4142
}
4243

4344
#[cfg_attr(target_os = "uefi", expect(unused))]
44-
pub fn bootargs(mut self, bootargs: &'a str) -> FdtWriterResult<Self> {
45+
pub fn bootargs(mut self, bootargs: String) -> FdtWriterResult<Self> {
4546
assert!(self.bootargs.is_none());
4647
self.bootargs = Some(bootargs);
4748

@@ -75,7 +76,7 @@ mod x86_64 {
7576
use multiboot::information::{MemoryMapIter, MemoryType};
7677
use vm_fdt::FdtWriterResult;
7778

78-
impl super::Fdt<'_> {
79+
impl super::Fdt {
7980
pub fn memory_regions(
8081
mut self,
8182
memory_regions: MemoryMapIter<'_, '_>,
@@ -105,7 +106,7 @@ mod uefi {
105106
use uefi::mem::memory_map::{MemoryMap, MemoryMapMut};
106107
use vm_fdt::FdtWriterResult;
107108

108-
impl super::Fdt<'_> {
109+
impl super::Fdt {
109110
pub fn memory_map(mut self, memory_map: &mut impl MemoryMapMut) -> FdtWriterResult<Self> {
110111
memory_map.sort();
111112
info!("Memory map:\n{}", memory_map.display());

0 commit comments

Comments
 (0)