Merge branch 'init_rework6' into 'main'

Migrate the entire initfs to service definitions

See merge request redox-os/base!140
This commit is contained in:
Jeremy Soller
2026-02-28 09:07:13 -07:00
15 changed files with 85 additions and 15 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",
]
+8
View File
@@ -0,0 +1,8 @@
[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"
-2
View File
@@ -1,2 +0,0 @@
requires_weak 40_drivers
REDOXFS_PASSWORD_ADDR=$ REDOXFS_PASSWORD_SIZE=$ redoxfs --uuid $REDOXFS_UUID file $REDOXFS_BLOCK
+9
View File
@@ -0,0 +1,9 @@
[unit]
description = "Rootfs"
requires_weak = ["40_drivers.target"]
[service]
cmd = "redoxfs"
args = ["--uuid" ,"$REDOXFS_UUID", "file", "$REDOXFS_BLOCK"]
inherit_envs = ["REDOXFS_PASSWORD_ADDR", "REDOXFS_PASSWORD_SIZE"]
type = "oneshot"
+1 -1
View File
@@ -1,5 +1,5 @@
[unit]
requires_weak = ["50_rootfs"]
requires_weak = ["50_rootfs.service"]
[switchroot]
prefix = "/usr"
+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 -1
View File
@@ -4,7 +4,7 @@ use std::{env, io, iter};
use crate::service::{Service, ServiceType};
use crate::unit::UnitId;
fn subst_env<'a>(arg: &str) -> String {
pub fn subst_env<'a>(arg: &str) -> String {
if arg.starts_with('$') {
env::var(&arg[1..]).unwrap_or(String::new())
} else {
+4 -1
View File
@@ -5,7 +5,10 @@ use std::process::Command;
use serde::Deserialize;
use crate::script::subst_env;
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Service {
pub cmd: String,
#[serde(default)]
@@ -31,7 +34,7 @@ pub enum ServiceType {
impl Service {
pub fn spawn(&self, base_envs: &BTreeMap<String, OsString>) {
let mut command = Command::new(&self.cmd);
command.args(&self.args);
command.args(self.args.iter().map(|arg| subst_env(arg)));
command.env_clear();
for env in &self.inherit_envs {
if let Some(value) = env::var_os(env) {
+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,