Skip to content

Commit 6b8a7f8

Browse files
authored
Add host startup options support to Grapefruit (#1984)
This is part of #1983
1 parent 1c9803c commit 6b8a7f8

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

app/grapefruit/app.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ max-sizes = {flash = 8192, ram = 2048}
109109
start = true
110110
# task-slots is explicitly empty: packrat should not send IPCs!
111111
task-slots = []
112+
features = ["grapefruit", "boot-kmdb"]
112113

113114
[tasks.hiffy]
114115
name = "task-hiffy"

task/packrat/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ build-util = { path = "../../build/util" }
2626

2727
[features]
2828
gimlet = ["drv-cpu-seq-api"]
29+
grapefruit = []
2930
boot-kmdb = []
3031
no-ipc-counters = ["idol/no-counters"]
3132

task/packrat/src/grapefruit.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Grapefruit-specific packrat data.
6+
7+
use task_packrat_api::HostStartupOptions;
8+
9+
pub(crate) struct GrapefruitData {
10+
host_startup_options: HostStartupOptions,
11+
}
12+
13+
const fn default_host_startup_options() -> HostStartupOptions {
14+
if cfg!(feature = "boot-kmdb") {
15+
// We have to do this because const fn.
16+
let bits = HostStartupOptions::STARTUP_KMDB.bits()
17+
| HostStartupOptions::STARTUP_PROM.bits()
18+
| HostStartupOptions::STARTUP_VERBOSE.bits()
19+
| HostStartupOptions::STARTUP_BOOT_RAMDISK.bits();
20+
match HostStartupOptions::from_bits(bits) {
21+
Some(options) => options,
22+
None => panic!("must be valid at compile-time"),
23+
}
24+
} else {
25+
HostStartupOptions::empty()
26+
}
27+
}
28+
29+
impl GrapefruitData {
30+
pub(crate) fn new() -> Self {
31+
Self {
32+
host_startup_options: default_host_startup_options(),
33+
}
34+
}
35+
36+
pub(crate) fn host_startup_options(&self) -> HostStartupOptions {
37+
self.host_startup_options
38+
}
39+
40+
pub(crate) fn set_host_startup_options(
41+
&mut self,
42+
options: HostStartupOptions,
43+
) {
44+
self.host_startup_options = options;
45+
}
46+
}

task/packrat/src/main.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ use userlib::RecvMessage;
4242
#[cfg(feature = "gimlet")]
4343
mod gimlet;
4444

45+
#[cfg(feature = "grapefruit")]
46+
mod grapefruit;
47+
4548
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4649
#[allow(dead_code)] // not all variants are used, depending on cargo features
4750
enum Trace {
@@ -111,6 +114,8 @@ fn main() -> ! {
111114
identity,
112115
#[cfg(feature = "gimlet")]
113116
gimlet_data: gimlet::GimletData::new(gimlet_bufs),
117+
#[cfg(feature = "grapefruit")]
118+
grapefruit_data: grapefruit::GrapefruitData::new(),
114119
};
115120

116121
let mut buffer = [0; idl::INCOMING_SIZE];
@@ -124,6 +129,8 @@ struct ServerImpl {
124129
identity: &'static mut Option<VpdIdentity>,
125130
#[cfg(feature = "gimlet")]
126131
gimlet_data: gimlet::GimletData,
132+
#[cfg(feature = "grapefruit")]
133+
grapefruit_data: grapefruit::GrapefruitData,
127134
}
128135

129136
impl ServerImpl {
@@ -204,7 +211,15 @@ impl idl::InOrderPackratImpl for ServerImpl {
204211
Ok(self.gimlet_data.host_startup_options())
205212
}
206213

207-
#[cfg(not(feature = "gimlet"))]
214+
#[cfg(feature = "grapefruit")]
215+
fn get_next_boot_host_startup_options(
216+
&mut self,
217+
_: &RecvMessage,
218+
) -> Result<HostStartupOptions, RequestError<Infallible>> {
219+
Ok(self.grapefruit_data.host_startup_options())
220+
}
221+
222+
#[cfg(not(any(feature = "gimlet", feature = "grapefruit")))]
208223
fn get_next_boot_host_startup_options(
209224
&mut self,
210225
_: &RecvMessage,
@@ -228,7 +243,21 @@ impl idl::InOrderPackratImpl for ServerImpl {
228243
Ok(())
229244
}
230245

231-
#[cfg(not(feature = "gimlet"))]
246+
#[cfg(feature = "grapefruit")]
247+
fn set_next_boot_host_startup_options(
248+
&mut self,
249+
_: &RecvMessage,
250+
host_startup_options: HostStartupOptions,
251+
) -> Result<(), RequestError<Infallible>> {
252+
ringbuf_entry!(Trace::SetNextBootHostStartupOptions(
253+
host_startup_options
254+
));
255+
self.grapefruit_data
256+
.set_host_startup_options(host_startup_options);
257+
Ok(())
258+
}
259+
260+
#[cfg(not(any(feature = "gimlet", feature = "grapefruit")))]
232261
fn set_next_boot_host_startup_options(
233262
&mut self,
234263
_: &RecvMessage,

0 commit comments

Comments
 (0)