Skip to content

Commit c8b1b09

Browse files
committed
build: integrate rootfs building with buck2
Signed-off-by: Theo Paris <theo@theoparis.com>
1 parent 41a3945 commit c8b1b09

File tree

11 files changed

+443
-69
lines changed

11 files changed

+443
-69
lines changed

.buckignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.rootfs-staging
2+
.rootfs-build.manifest
3+
.rootfs-extract.manifest
4+
efi_root
5+
rootfs.img

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ target/
1717
*.pdb
1818
/buck-out
1919
.codex
20+
.rootfs-staging
21+
.rootfs-build.manifest
22+
.rootfs-extract.manifest

BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ command_alias(
2020
"BUCK_OVMF_FD": "$(location :ovmf_firmware)",
2121
"BUCK_KERNEL_BIN": "$(location //kernel:kernel_artifact)",
2222
"BUCK_MKROOTFS_BIN": "$(location //tools/mkrootfs:mkrootfs)",
23+
"BUCK_WIMUNPACK_BIN": "$(location //tools/wimunpack:wimunpack)",
2324
"BUCK_NATIVE_INIT_EXE": "$(location //userspace/native_init:native_init[init])",
2425
"BUCK_CHILD_EXE": "$(location //userspace/native_init:native_init[child])",
2526
"BUCK_NTDLL_DLL": "$(location //userspace/native_init:native_init[ntdll_dll])",

kernel/kernel.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use limine::{
3535
BaseRevision,
3636
};
3737
#[cfg(target_os = "uefi")]
38+
use alloc::vec;
39+
#[cfg(target_os = "uefi")]
3840
use uefi::proto::loaded_image::LoadedImage;
3941
#[cfg(target_os = "uefi")]
4042
use uefi::proto::media::block::BlockIO;
@@ -134,6 +136,8 @@ fn install_uefi_root_device(
134136
image_handle: uefi::Handle,
135137
system_table: &uefi::table::SystemTable<uefi::table::Boot>,
136138
) {
139+
const CRABFS_SUPERBLOCK_MAGIC: [u8; 4] = *b"XFSB";
140+
137141
let Ok(loaded_image) = system_table
138142
.boot_services()
139143
.open_protocol_exclusive::<LoadedImage>(image_handle)
@@ -173,11 +177,16 @@ fn install_uefi_root_device(
173177
let io_align = media.io_align() as usize;
174178
let media_id = media.media_id();
175179
let last_block = media.last_block();
180+
let mut sector0 = vec![0u8; block_size.max(4)];
181+
if block_io.read_blocks(media_id, 0, &mut sector0).is_err() {
182+
continue;
183+
}
184+
if sector0[..4] != CRABFS_SUPERBLOCK_MAGIC {
185+
continue;
186+
}
176187
let ptr = (&*block_io as *const BlockIO).cast_mut();
177188
core::mem::forget(block_io);
178-
let replace = best
179-
.as_ref()
180-
.is_none_or(|(_, _, _, _, best_last_block)| last_block > *best_last_block);
189+
let replace = best.is_none_or(|(_, _, _, _, best_last_block)| last_block > best_last_block);
181190
if replace {
182191
best = Some((ptr, media_id, block_size, io_align, last_block));
183192
}

third-party/BUCK

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3851,6 +3851,24 @@ http_archive(
38513851
visibility = [],
38523852
)
38533853

3854+
cargo.rust_library(
3855+
name = "serde_spanned-1",
3856+
srcs = [":serde_spanned-1.1.1.crate"],
3857+
crate = "serde_spanned",
3858+
crate_root = "serde_spanned-1.1.1.crate/src/lib.rs",
3859+
edition = "2024",
3860+
features = ["alloc"],
3861+
visibility = [],
3862+
)
3863+
3864+
http_archive(
3865+
name = "serde_spanned-1.1.1.crate",
3866+
sha256 = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26",
3867+
strip_prefix = "serde_spanned-1.1.1",
3868+
urls = ["https://static.crates.io/crates/serde_spanned/1.1.1/download"],
3869+
visibility = [],
3870+
)
3871+
38543872
cargo.rust_library(
38553873
name = "sha1-0.10",
38563874
srcs = [":sha1-0.10.6.crate"],
@@ -4577,6 +4595,51 @@ http_archive(
45774595
visibility = [],
45784596
)
45794597

4598+
alias(
4599+
name = "toml",
4600+
actual = ":toml-1",
4601+
visibility = ["PUBLIC"],
4602+
)
4603+
4604+
cargo.rust_library(
4605+
name = "toml-1",
4606+
srcs = [":toml-1.1.2+spec-1.1.0.crate"],
4607+
crate = "toml",
4608+
crate_root = "toml-1.1.2+spec-1.1.0.crate/src/lib.rs",
4609+
edition = "2024",
4610+
visibility = [],
4611+
deps = [
4612+
":serde_spanned-1",
4613+
":toml_datetime-1",
4614+
],
4615+
)
4616+
4617+
http_archive(
4618+
name = "toml-1.1.2+spec-1.1.0.crate",
4619+
sha256 = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee",
4620+
strip_prefix = "toml-1.1.2+spec-1.1.0",
4621+
urls = ["https://static.crates.io/crates/toml/1.1.2+spec-1.1.0/download"],
4622+
visibility = [],
4623+
)
4624+
4625+
cargo.rust_library(
4626+
name = "toml_datetime-1",
4627+
srcs = [":toml_datetime-1.1.1+spec-1.1.0.crate"],
4628+
crate = "toml_datetime",
4629+
crate_root = "toml_datetime-1.1.1+spec-1.1.0.crate/src/lib.rs",
4630+
edition = "2024",
4631+
features = ["alloc"],
4632+
visibility = [],
4633+
)
4634+
4635+
http_archive(
4636+
name = "toml_datetime-1.1.1+spec-1.1.0.crate",
4637+
sha256 = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7",
4638+
strip_prefix = "toml_datetime-1.1.1+spec-1.1.0",
4639+
urls = ["https://static.crates.io/crates/toml_datetime/1.1.1+spec-1.1.0/download"],
4640+
visibility = [],
4641+
)
4642+
45804643
cargo.rust_library(
45814644
name = "tower-0.5",
45824645
srcs = [":tower-0.5.3.crate"],

third-party/Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third-party/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ goblin = { version = "0.10.5", default-features = false, features = [
2626
"elf32",
2727
] }
2828
linked_list_allocator = "0.10.5"
29+
toml = { version = "1.1.2+spec-1.1.0", default-features = false }
2930
spin = "0.10.0"
3031
plist = "1.8.0"
3132
serde = { version = "1.0.228", default-features = false, features = ["derive"] }

tools/import_rootfs.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)