Move live disk support from kernel to bootloader

This commit is contained in:
Jeremy Soller 2022-02-10 15:52:15 -07:00
parent 061cee89e1
commit ed5d2783a2
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
9 changed files with 34 additions and 157 deletions

@ -1 +1 @@
Subproject commit b53bcfd7cdc5bab8eebdc1c8a53a2e9a433b7697 Subproject commit 2100b1174bb37734c562cd35ab4f28be52557d21

View file

@ -1,37 +0,0 @@
# This is the default configuration file
# General settings
[general]
# Do not prompt if settings are not defined
prompt = false
# Package settings
[packages]
drivers = {}
init = {}
nulld = {}
#pciids = {}
ramfs = {}
randd = {}
redoxfs = {}
zerod = {}
[[files]]
path="/etc/init.rc"
data="""
export PATH /bin
export TMPDIR /tmp
nulld
zerod
randd
vesad T T G
stdio display:1
ps2d us
ramfs logging
acpid
pcid /etc/pcid/initfs.toml
redoxfs disk/live: file
cd file:
export PATH file:/bin
run.d /etc/init.d
"""

View file

@ -1,37 +0,0 @@
# This is the default configuration file
# General settings
[general]
# Do not prompt if settings are not defined
prompt = false
# Package settings
[packages]
drivers = {}
init = {}
nulld = {}
#pciids = {}
ramfs = {}
randd = {}
redoxfs = {}
zerod = {}
[[files]]
path="/etc/init.rc"
data="""
export PATH /bin
export TMPDIR /tmp
nulld
zerod
randd
vesad T T G
stdio display:1
ps2d us
ramfs logging
acpid
pcid /etc/pcid/initfs.toml
redoxfs disk/live: file
cd file:
export PATH file:/bin
run.d /etc/init.d
"""

2
kernel

@ -1 +1 @@
Subproject commit f92fe900697fd841bd63c9e08ea90a4d70a4cc37 Subproject commit 1aae949fc488b5a25f7a1204ddb958ff015eb290

View file

@ -6,6 +6,14 @@ build/bootloader.bin: bootloader/build/$(BOOTLOADER_TARGET)/bootloader.bin
mkdir -p build mkdir -p build
cp -v $< $@ cp -v $< $@
bootloader/build/$(BOOTLOADER_TARGET)/bootloader-live.bin: FORCE
env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \
$(MAKE) -C bootloader build/$(BOOTLOADER_TARGET)/bootloader-live.bin TARGET=$(BOOTLOADER_TARGET)
build/bootloader-live.bin: bootloader/build/$(BOOTLOADER_TARGET)/bootloader-live.bin
mkdir -p build
cp -v $< $@
bootloader/build/$(EFI_TARGET)/bootloader.efi: FORCE bootloader/build/$(EFI_TARGET)/bootloader.efi: FORCE
env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \ env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \
$(MAKE) -C bootloader build/$(EFI_TARGET)/bootloader.efi TARGET=$(EFI_TARGET) $(MAKE) -C bootloader build/$(EFI_TARGET)/bootloader.efi TARGET=$(EFI_TARGET)
@ -14,6 +22,14 @@ build/bootloader.efi: bootloader/build/$(EFI_TARGET)/bootloader.efi
mkdir -p build mkdir -p build
cp -v $< $@ cp -v $< $@
bootloader/build/$(EFI_TARGET)/bootloader-live.efi: FORCE
env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \
$(MAKE) -C bootloader build/$(EFI_TARGET)/bootloader-live.efi TARGET=$(EFI_TARGET)
build/bootloader-live.efi: bootloader/build/$(EFI_TARGET)/bootloader-live.efi
mkdir -p build
cp -v $< $@
bootloader-coreboot/build/bootloader: build/kernel_coreboot bootloader-coreboot/build/bootloader: build/kernel_coreboot
env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \ env --unset=RUST_TARGET_PATH --unset=RUSTUP_TOOLCHAIN --unset=XARGO_RUST_SRC \
$(MAKE) -C bootloader-coreboot clean build/bootloader KERNEL="$(ROOT)/$<" $(MAKE) -C bootloader-coreboot clean build/bootloader KERNEL="$(ROOT)/$<"

View file

@ -1,19 +1,19 @@
build/harddrive.bin: build/filesystem.bin build/bootloader.bin build/harddrive.bin: build/bootloader.bin build/filesystem.bin
dd if=/dev/zero of=$@.partial bs=1M count=$$(expr $$(du -m $< | cut -f1) + 2) dd if=/dev/zero of=$@.partial bs=1M count=$$(expr $$(du -m build/filesystem.bin | cut -f1) + 2)
$(PARTED) -s -a minimal $@.partial mklabel msdos $(PARTED) -s -a minimal $@.partial mklabel msdos
$(PARTED) -s -a minimal $@.partial mkpart primary 2048s $$(expr $$(du -m $< | cut -f1) \* 2048 + 2048)s $(PARTED) -s -a minimal $@.partial mkpart primary 2048s $$(expr $$(du -m build/filesystem.bin | cut -f1) \* 2048 + 2048)s
dd if=build/bootloader.bin of=$@.partial bs=1 count=446 conv=notrunc dd if=$< of=$@.partial bs=1 count=446 conv=notrunc
dd if=build/bootloader.bin of=$@.partial bs=512 skip=1 seek=1 conv=notrunc dd if=$< of=$@.partial bs=512 skip=1 seek=1 conv=notrunc
dd if=$< of=$@.partial bs=1M seek=1 conv=notrunc dd if=build/filesystem.bin of=$@.partial bs=1M seek=1 conv=notrunc
mv $@.partial $@ mv $@.partial $@
build/livedisk.bin: build/filesystem-live.bin build/bootloader.bin build/livedisk.bin: build/bootloader-live.bin build/filesystem.bin
dd if=/dev/zero of=$@.partial bs=1M count=$$(expr $$(du -m $< | cut -f1) + 2) dd if=/dev/zero of=$@.partial bs=1M count=$$(expr $$(du -m build/filesystem.bin | cut -f1) + 2)
$(PARTED) -s -a minimal $@.partial mklabel msdos $(PARTED) -s -a minimal $@.partial mklabel msdos
$(PARTED) -s -a minimal $@.partial mkpart primary 2048s $$(expr $$(du -m $< | cut -f1) \* 2048 + 2048)s $(PARTED) -s -a minimal $@.partial mkpart primary 2048s $$(expr $$(du -m build/filesystem.bin | cut -f1) \* 2048 + 2048)s
dd if=build/bootloader.bin of=$@.partial bs=1 count=446 conv=notrunc dd if=$< of=$@.partial bs=1 count=446 conv=notrunc
dd if=build/bootloader.bin of=$@.partial bs=512 skip=1 seek=1 conv=notrunc dd if=$< of=$@.partial bs=512 skip=1 seek=1 conv=notrunc
dd if=$< of=$@.partial bs=1M seek=1 conv=notrunc dd if=build/filesystem.bin of=$@.partial bs=1M seek=1 conv=notrunc
mv $@.partial $@ mv $@.partial $@
build/livedisk.iso: build/livedisk.bin.gz build/livedisk.iso: build/livedisk.bin.gz
@ -52,7 +52,7 @@ build/harddrive-efi.bin: build/bootloader.efi build/filesystem.bin
dd if=$@.esp bs=512 seek=2048 conv=notrunc count=$$efi_disk_blkcount of=$@ && \ dd if=$@.esp bs=512 seek=2048 conv=notrunc count=$$efi_disk_blkcount of=$@ && \
dd if=build/filesystem.bin seek=$$efi_end bs=512 conv=notrunc of=$@ count=$$fs_disk_blkcount dd if=build/filesystem.bin seek=$$efi_end bs=512 conv=notrunc of=$@ count=$$fs_disk_blkcount
build/livedisk-efi.bin: build/bootloader.efi build/filesystem-live.bin build/livedisk-efi.bin: build/bootloader-live.efi build/filesystem.bin
# TODO: Validate the correctness of this \ # TODO: Validate the correctness of this \
# Populate an EFI system partition \ # Populate an EFI system partition \
dd if=/dev/zero of=$@.esp bs=1048576 count=$$(expr $$(du -m $< | cut -f1) + 1) && \ dd if=/dev/zero of=$@.esp bs=1048576 count=$$(expr $$(du -m $< | cut -f1) + 1) && \
@ -61,7 +61,7 @@ build/livedisk-efi.bin: build/bootloader.efi build/filesystem-live.bin
mmd -i $@.esp efi/boot && \ mmd -i $@.esp efi/boot && \
mcopy -i $@.esp $< ::efi/boot/bootx64.efi && \ mcopy -i $@.esp $< ::efi/boot/bootx64.efi && \
# Create the disk \ # Create the disk \
dd if=/dev/zero of=$@ bs=1048576 count=$$(expr $$(du -m $< | cut -f1) + 2 + $$(du -m build/filesystem-live.bin | cut -f1)) && \ dd if=/dev/zero of=$@ bs=1048576 count=$$(expr $$(du -m $< | cut -f1) + 2 + $$(du -m build/filesystem.bin | cut -f1)) && \
# Create partition table \ # Create partition table \
$(PARTED) -s -a minimal $@ mklabel gpt && \ $(PARTED) -s -a minimal $@ mklabel gpt && \
efi_disk_size=$$(du -m $< | cut -f1) && \ efi_disk_size=$$(du -m $< | cut -f1) && \
@ -69,11 +69,11 @@ build/livedisk-efi.bin: build/bootloader.efi build/filesystem-live.bin
efi_end=$$(expr 2048 + $$efi_disk_blkcount) && \ efi_end=$$(expr 2048 + $$efi_disk_blkcount) && \
efi_last=$$(expr $$efi_end - 1) && \ efi_last=$$(expr $$efi_end - 1) && \
$(PARTED) -s -a minimal $@ mkpart EFI fat32 2048s "$${efi_last}s" && \ $(PARTED) -s -a minimal $@ mkpart EFI fat32 2048s "$${efi_last}s" && \
fs_disk_size=$$(du -m build/filesystem-live.bin | cut -f1) && \ fs_disk_size=$$(du -m build/filesystem.bin | cut -f1) && \
fs_disk_blkcount=$$(expr $$fs_disk_size \* $$(expr 1048576 / 512)) && \ fs_disk_blkcount=$$(expr $$fs_disk_size \* $$(expr 1048576 / 512)) && \
$(PARTED) -s -a minimal $@ mkpart redox ext4 "$${efi_end}s" $$(expr $$efi_end + $$fs_disk_blkcount)s && \ $(PARTED) -s -a minimal $@ mkpart redox ext4 "$${efi_end}s" $$(expr $$efi_end + $$fs_disk_blkcount)s && \
$(PARTED) -s -a minimal $@ set 1 boot on && \ $(PARTED) -s -a minimal $@ set 1 boot on && \
$(PARTED) -s -a minimal $@ set 1 esp on && \ $(PARTED) -s -a minimal $@ set 1 esp on && \
# Write the partitions \ # Write the partitions \
dd if=$@.esp bs=512 seek=2048 conv=notrunc count=$$efi_disk_blkcount of=$@ && \ dd if=$@.esp bs=512 seek=2048 conv=notrunc count=$$efi_disk_blkcount of=$@ && \
dd if=build/filesystem-live.bin seek=$$efi_end bs=512 conv=notrunc of=$@ count=$$fs_disk_blkcount dd if=build/filesystem.bin seek=$$efi_end bs=512 conv=notrunc of=$@ count=$$fs_disk_blkcount

View file

@ -20,13 +20,6 @@ build/filesystem.bin: filesystem.toml build/kernel prefix
rm -rf build/filesystem/ rm -rf build/filesystem/
mv $@.partial $@ mv $@.partial $@
build/filesystem-live.bin: build/kernel_live
rm -rf $@ $@.partial build/filesystem-live/
mkdir -p build/filesystem-live/
cp $< build/filesystem-live/kernel
cargo run --manifest-path redoxfs/Cargo.toml --release --bin redoxfs-ar -- $@.partial build/filesystem-live
mv $@.partial $@
mount: FORCE mount: FORCE
mkdir -p build/filesystem/ mkdir -p build/filesystem/
cargo build --manifest-path redoxfs/Cargo.toml --release --bin redoxfs cargo build --manifest-path redoxfs/Cargo.toml --release --bin redoxfs

View file

@ -12,29 +12,3 @@ build/initfs.tag: initfs.toml prefix
rm -f build/initfs/bin/$$bin; \ rm -f build/initfs/bin/$$bin; \
done done
touch $@ touch $@
build/initfs_coreboot.tag: initfs_coreboot.toml prefix
cargo build --manifest-path cookbook/Cargo.toml --release
cargo build --manifest-path installer/Cargo.toml --release
rm -f build/libkernel_coreboot.a
rm -rf build/initfs_coreboot
mkdir -p build/initfs_coreboot
$(INSTALLER) -c $< build/initfs_coreboot/
#TODO: HACK FOR SMALLER INITFS, FIX IN PACKAGING
for bin in $(INITFS_RM_BINS); do \
rm -f build/initfs_coreboot/bin/$$bin; \
done
touch $@
build/initfs_live.tag: initfs_live.toml prefix
cargo build --manifest-path cookbook/Cargo.toml --release
cargo build --manifest-path installer/Cargo.toml --release
rm -f build/libkernel_live.a
rm -rf build/initfs_live
mkdir -p build/initfs_live
$(INSTALLER) -c $< build/initfs_live/
#TODO: HACK FOR SMALLER INITFS, FIX IN PACKAGING
for bin in $(INITFS_RM_BINS); do \
rm -f build/initfs_live/bin/$$bin; \
done
touch $@

View file

@ -4,40 +4,8 @@ build/libkernel.a: kernel/Cargo.lock kernel/Cargo.toml kernel/src/* kernel/src/*
cd kernel && \ cd kernel && \
cargo rustc --lib --target=$(ROOT)/kernel/targets/$(KTARGET).json --release -- -C soft-float -C debuginfo=2 -C lto --emit link=../$@ cargo rustc --lib --target=$(ROOT)/kernel/targets/$(KTARGET).json --release -- -C soft-float -C debuginfo=2 -C lto --emit link=../$@
build/libkernel_coreboot.a: kernel/Cargo.toml kernel/src/* kernel/src/*/* kernel/src/*/*/* kernel/src/*/*/*/* build/initfs_coreboot.tag
export PATH="$(PREFIX_PATH):$$PATH" && \
export INITFS_FOLDER=$(ROOT)/build/initfs_coreboot && \
cd kernel && \
cargo rustc --lib --target=$(ROOT)/kernel/targets/$(KTARGET).json --release --features live -- -C soft-float -C debuginfo=2 -C lto --emit link=../$@
build/libkernel_live.a: kernel/Cargo.toml kernel/src/* kernel/src/*/* kernel/src/*/*/* kernel/src/*/*/*/* build/initfs_live.tag
export PATH="$(PREFIX_PATH):$$PATH" && \
export INITFS_FOLDER=$(ROOT)/build/initfs_live && \
cd kernel && \
cargo rustc --lib --target=$(ROOT)/kernel/targets/$(KTARGET).json --release --features live -- -C soft-float -C debuginfo=2 -C lto --emit link=../$@
build/kernel: kernel/linkers/$(ARCH).ld mk/kernel_ld.sh build/libkernel.a build/kernel: kernel/linkers/$(ARCH).ld mk/kernel_ld.sh build/libkernel.a
export PATH="$(PREFIX_PATH):$$PATH" && \ export PATH="$(PREFIX_PATH):$$PATH" && \
$(ROOT)/mk/kernel_ld.sh $(LD) --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libkernel.a && \ $(ROOT)/mk/kernel_ld.sh $(LD) --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libkernel.a && \
$(OBJCOPY) --only-keep-debug $@ $@.sym && \ $(OBJCOPY) --only-keep-debug $@ $@.sym && \
$(OBJCOPY) --strip-debug $@ $(OBJCOPY) --strip-debug $@
build/kernel_coreboot: kernel/linkers/$(ARCH).ld mk/kernel_ld.sh build/libkernel_coreboot.a build/live.o
export PATH="$(PREFIX_PATH):$$PATH" && \
$(ROOT)/mk/kernel_ld.sh $(LD) --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libkernel_coreboot.a build/live.o && \
$(OBJCOPY) --only-keep-debug $@ $@.sym && \
$(OBJCOPY) --strip-debug $@
build/kernel_live: kernel/linkers/$(ARCH).ld mk/kernel_ld.sh build/libkernel_live.a build/live.o
export PATH="$(PREFIX_PATH):$$PATH" && \
$(ROOT)/mk/kernel_ld.sh $(LD) --gc-sections -z max-page-size=0x1000 -T $< -o $@ build/libkernel_live.a build/live.o && \
$(OBJCOPY) --only-keep-debug $@ $@.sym && \
$(OBJCOPY) --strip-debug $@
build/live.o: build/filesystem.bin
#TODO: More general use of $(ARCH)
export PATH="$(PREFIX_PATH):$$PATH" && \
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 $< $@ \
--redefine-sym _binary_build_filesystem_bin_start=__live_start \
--redefine-sym _binary_build_filesystem_bin_end=__live_end \
--redefine-sym _binary_build_filesystem_bin_size=__live_size