Init: Introduce support for conditionally spawning services
depending on the architecture and selected board. With this the migration of initfs daemons to service definitions is almost done.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
requires_weak 10_lived.service 20_graphics.target
|
||||
notify RSDP_ADDR=$ RSDP_SIZE=$ hwd
|
||||
pcid-spawner --initfs
|
||||
@@ -1,2 +0,0 @@
|
||||
requires_weak 10_lived.service 20_graphics.target
|
||||
notify bcm2835-sdhcid
|
||||
@@ -0,0 +1,9 @@
|
||||
[unit]
|
||||
description = "BCM2835 SD card driver"
|
||||
requires_weak = ["10_inputd.service", "10_lived.service", "20_graphics.target"]
|
||||
condition_architecture = ["aarch64"]
|
||||
condition_board = ["raspi3bp"]
|
||||
|
||||
[service]
|
||||
cmd = "bcm2835-sdhcid"
|
||||
type = "notify"
|
||||
@@ -1,4 +0,0 @@
|
||||
requires_weak 10_lived.service 20_graphics.target
|
||||
notify ps2d
|
||||
notify RSDP_ADDR=$ RSDP_SIZE=$ hwd
|
||||
pcid-spawner --initfs
|
||||
@@ -0,0 +1,10 @@
|
||||
[unit]
|
||||
description = "Initfs drivers"
|
||||
requires_weak = [
|
||||
"10_lived.service",
|
||||
"20_graphics.target",
|
||||
"40_ps2d.service",
|
||||
"40_bcm2835-sdhcid.service",
|
||||
"40_hwd.service",
|
||||
"40_pcid-spawner.service",
|
||||
]
|
||||
@@ -0,0 +1,11 @@
|
||||
[unit]
|
||||
description = "Hardware manager"
|
||||
requires_weak = ["10_inputd.service", "10_lived.service", "20_graphics.target"]
|
||||
|
||||
[service]
|
||||
cmd = "hwd"
|
||||
inherit_envs = [
|
||||
"RSDP_ADDR",
|
||||
"RSDP_SIZE",
|
||||
]
|
||||
type = "notify"
|
||||
@@ -0,0 +1,8 @@
|
||||
[unit]
|
||||
description = "PCI driver spawner"
|
||||
requires_weak = ["10_inputd.service", "20_graphics.target", "40_hwd.service"]
|
||||
|
||||
[service]
|
||||
cmd = "pcid-spawner"
|
||||
args = ["--initfs"]
|
||||
type = "oneshot"
|
||||
@@ -0,0 +1,8 @@
|
||||
[unit]
|
||||
description = "PS/2 driver"
|
||||
requires_weak = ["10_inputd.service", "20_graphics.target"]
|
||||
condition_architecture = ["x86", "x86_64"]
|
||||
|
||||
[service]
|
||||
cmd = "ps2d"
|
||||
type = "notify"
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
requires_weak 40_drivers
|
||||
requires_weak 40_drivers.target
|
||||
REDOXFS_PASSWORD_ADDR=$ REDOXFS_PASSWORD_SIZE=$ redoxfs --uuid $REDOXFS_UUID file $REDOXFS_BLOCK
|
||||
|
||||
+18
-1
@@ -50,6 +50,7 @@ impl InitConfig {
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SwitchRoot {
|
||||
prefix: PathBuf,
|
||||
etcdir: PathBuf,
|
||||
@@ -112,7 +113,7 @@ fn run(
|
||||
unit::UnitKind::Target {} => {
|
||||
if config.log_debug {
|
||||
eprintln!(
|
||||
"Started target {}",
|
||||
"Reached target {}",
|
||||
unit.info.description.as_ref().unwrap_or(&unit.id.0),
|
||||
);
|
||||
}
|
||||
@@ -171,6 +172,22 @@ fn main() {
|
||||
let runtime_target = UnitId("00_runtime.target".to_owned());
|
||||
|
||||
'a: while let Some(unit) = pending_units.pop_front() {
|
||||
if let Some(condition_architecture) = &unit_store.unit(&unit).info.condition_architecture {
|
||||
if !condition_architecture
|
||||
.iter()
|
||||
.any(|arch| arch == std::env::consts::ARCH)
|
||||
{
|
||||
continue 'a;
|
||||
}
|
||||
}
|
||||
if let Some(condition_board) = &unit_store.unit(&unit).info.condition_board {
|
||||
if !condition_board
|
||||
.iter()
|
||||
.any(|board| Some(&**board) == option_env!("BOARD"))
|
||||
{
|
||||
continue 'a;
|
||||
}
|
||||
}
|
||||
if unit_store.unit(&unit).info.default_dependencies {
|
||||
if pending_units.contains(&runtime_target) {
|
||||
pending_units.push_back(unit);
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::process::Command;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Service {
|
||||
pub cmd: String,
|
||||
#[serde(default)]
|
||||
|
||||
@@ -77,12 +77,16 @@ pub struct Unit {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct UnitInfo {
|
||||
pub description: Option<String>,
|
||||
#[serde(default = "true_bool")]
|
||||
pub default_dependencies: bool,
|
||||
#[serde(default)]
|
||||
pub requires_weak: Vec<UnitId>,
|
||||
pub condition_architecture: Option<Vec<String>>,
|
||||
// FIXME replace this with hwd reading from the devicetree
|
||||
pub condition_board: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
fn true_bool() -> bool {
|
||||
@@ -97,17 +101,20 @@ pub enum UnitKind {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SerializedService {
|
||||
unit: UnitInfo,
|
||||
service: Service,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SerializedTarget {
|
||||
unit: UnitInfo,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SerializedSwitchRoot {
|
||||
unit: UnitInfo,
|
||||
switchroot: SwitchRoot,
|
||||
@@ -143,6 +150,8 @@ impl Unit {
|
||||
description: None,
|
||||
default_dependencies: true,
|
||||
requires_weak,
|
||||
condition_architecture: None,
|
||||
condition_board: None,
|
||||
},
|
||||
UnitKind::LegacyScript { script },
|
||||
warnings,
|
||||
|
||||
Reference in New Issue
Block a user