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:
bjorn3
2026-02-28 16:55:26 +01:00
parent 9624cd3c2c
commit e86dbfa17e
12 changed files with 75 additions and 11 deletions
-3
View File
@@ -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
+9
View File
@@ -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"
-4
View File
@@ -1,4 +0,0 @@
requires_weak 10_lived.service 20_graphics.target
notify ps2d
notify RSDP_ADDR=$ RSDP_SIZE=$ hwd
pcid-spawner --initfs
+10
View File
@@ -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",
]
+11
View File
@@ -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"
+8
View File
@@ -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"
+8
View File
@@ -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
View File
@@ -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
View File
@@ -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);
+1
View File
@@ -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)]
+9
View File
@@ -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,