Skip to content

Commit

Permalink
Add UI process that controls which entry gets booted
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbaur committed Jun 5, 2023
1 parent d6101c1 commit 7ea1189
Show file tree
Hide file tree
Showing 39 changed files with 1,436 additions and 985 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.qcow2
*.iso
*.qcow2
.direnv
out
result*
target
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# TODO(jared): DON'T USE THIS, it is just an experimental way to have a quicker
# feedback loop while developing and is not done
# things to do to get this working:
# - nix shell with static musl toolchain so the CPIO does not need any shared libraries
# - nix derivations of the kernel, base initrd w/busybox utils, and base coreboot ROM

src := $(shell git ls-files --directory tinyboot)

.PHONY := default run clean

default: run

run: out/tinyboot-coreboot.rom
# bash test/test.bash out/tinyboot-coreboot.rom
echo run!

clean:
rm -rf out

out/tinyboot-coreboot.rom: $(src) out out/initrd out/kernel out/tinyboot.cpio out/coreboot.rom
echo concatentate tinyboot cpio to out/initrd
echo use cbfs to create out/tinyboot-coreboot.rom

out/tinyboot.cpio: out/bin
cargo build --manifest-path tinyboot/Cargo.toml
cd out && find ./bin | cpio -ov > tinyboot.cpio

out/bin:
cargo build --manifest-path tinyboot/Cargo.toml
mkdir -p out/bin
cp tinyboot/target/debug/{tbootd,tbootui,tbootctl} out/bin/

out/coreboot.rom:
dd if=$(shell nix build --no-link --print-out-paths -L .\#coreboot.qemu-x86_64)/coreboot.rom of=out/coreboot.rom

out/initrd:
echo initrd

out/kernel:
echo kernel

out:
mkdir -p out
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# tinyboot

tinyboot is a linuxboot-like kexec bootloader for coreboot. Current boot
configuration support includes grub, syslinux/extlinux, and
[bls](https://uapi-group.org/specifications/specs/boot_loader_specification/).
The nix flake provides coreboot builds for a few boards, contributions for more
configs are welcome!
Tinyboot is a linuxboot kexec bootloader for coreboot. Current boot
configuration support includes
[bls](https://uapi-group.org/specifications/specs/boot_loader_specification/),
grub, and syslinux/extlinux. The nix flake provides coreboot builds for a few
boards, contributions for more configs are welcome!

## Usage

```bash
```
nix build github:jmbaur/tinyboot#coreboot.<your_board>
flashrom -w ./result/coreboot.rom -p <your_programmer>
```

## Hacking

```bash
```
nix run .#disk
nix run .#default
```
6 changes: 2 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
- provide a way to edit kernel cmdline
- don't allow clippy::new_ret_no_self lints
- way better UI
- better UI
- respond to SIGWINCH in tbootui
- better bootloader interface
- make the program smarter about printing to all known outputs, not just a
statically configured output
- don't call oneshot `mdev -s` when tinyboot is not being ran explicitly on a
tty
- when verified boot fails, hash the boot files and ask the user explicitly for
Expand Down
8 changes: 4 additions & 4 deletions boards/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ let
default = "/dev/null";
};
};
tty = lib.mkOption {
type = lib.types.str;
default = "tty0";
ttys = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "tty0" ];
};
extraInit = lib.mkOption {
type = lib.types.lines;
Expand All @@ -77,7 +77,7 @@ lib.mapAttrs
meta = { inherit (finalConfig.config) platforms; };
};
linux = pkgs.callPackage ../kernel.nix { inherit (finalConfig.config.kernel) basePackage configFile; };
initrd = pkgs.callPackage ../initramfs.nix { inherit (finalConfig.config.tinyboot) measuredBoot verifiedBoot debug tty extraInit extraInittab; };
initrd = pkgs.callPackage ../initramfs.nix { inherit (finalConfig.config.tinyboot) measuredBoot verifiedBoot debug ttys extraInit extraInittab; };
fitImage = buildFitImage { inherit board linux initrd; inherit (finalConfig.config.kernel) dtb dtbPattern; };
in
(buildPackages.runCommand "tinyboot-${coreboot.name}"
Expand Down
2 changes: 1 addition & 1 deletion boards/qemu-aarch64/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
coreboot.configFile = lib.mkDefault ./coreboot.config;
tinyboot = {
debug = lib.mkDefault true;
tty = lib.mkDefault "ttyAMA0";
ttys = lib.mkDefault [ "ttyAMA0" ];
verifiedBoot = {
enable = lib.mkDefault true;
publicKey = lib.mkDefault ../../test/keys/pubkey;
Expand Down
2 changes: 2 additions & 0 deletions boards/qemu-kernel.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
CONFIG_BLK_MQ_VIRTIO=y
CONFIG_DRM=y
CONFIG_DRM_VIRTIO_GPU=y
CONFIG_I2C_VIRTIO=y
CONFIG_NET_9P_VIRTIO=y
CONFIG_SCSI_VIRTIO=y
Expand Down
2 changes: 1 addition & 1 deletion boards/qemu-x86_64/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
kernel.configFile = lib.mkDefault (pkgs.concatText "qemu-x86_64-kernel.config" [ ../generic-kernel.config ../qemu-kernel.config ../x86_64-kernel.config ./kernel.config ]);
tinyboot = {
debug = lib.mkDefault true;
tty = lib.mkDefault "ttyS0";
ttys = lib.mkDefault [ "tty0" "ttyS0" ];
verifiedBoot = {
enable = lib.mkDefault true;
publicKey = lib.mkDefault ../../test/keys/pubkey;
Expand Down
2 changes: 2 additions & 0 deletions boards/x86_64-kernel.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CONFIG_MFD_INTEL_LPSS_PCI=y
CONFIG_PCI_MSI=y
CONFIG_PNP=y
CONFIG_PREEMPT_VOLUNTARY=y
CONFIG_RETPOLINE=y
CONFIG_SPECULATION_MITIGATIONS=y
CONFIG_SPI_DESIGNWARE=y
CONFIG_SPI_INTEL=y
CONFIG_SPI_INTEL_PCI=y
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions initramfs.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ debug
, ttys
, measuredBoot
, verifiedBoot
, tty
, extraInit
, extraInittab
, lib
Expand Down Expand Up @@ -32,25 +32,24 @@ let
mount -t tmpfs tmpfs /tmp
mount -t devpts devpts /dev/pts
mdev -s
mkdir -p /home/tinyuser
chown -R tinyuser:tinyuser /home/tinyuser
mkdir -p /home/tinyuser /tmp/tinyboot
chown -R tinyuser:tinygroup /home/tinyuser /tmp/tinyboot
'' + extraInit);
inittab = writeText "inittab" (''
::sysinit:/etc/init.d/rcS
::ctrlaltdel:/bin/reboot
::shutdown:/bin/umount -ar -t ext4,vfat
::restart:/init
::respawn:/bin/mdev -df
${tty}::respawn:/bin/tbootd --log-level=${if debug then "debug" else "info"}
${tty}::respawn:/bin/tbootui
'' + extraInittab);
::respawn:/bin/tbootd --log-level=${if debug then "debug" else "info"}
'' + (lib.concatLines (map (tty: "${tty}::respawn:/bin/tbootui") ttys)) + extraInittab);
passwd = writeText "passwd" ''
root:x:0:0:System administrator:/root:/bin/sh
tinyuser:x:1000:1000:TinyUser:/home/tinyuser:/bin/sh
'';
group = writeText "passwd" ''
root:x:0:
tinyuser:x:1000:
tinygroup:x:1000:
'';
mdevConf = writeText "mdev.conf" ''
([vs]d[a-z]) root:root 660 >disk/%1/0
Expand Down
2 changes: 1 addition & 1 deletion test/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
environment.systemPackages = [ pkgs.tinyboot-client ];
specialisation.alternate.configuration.boot.kernelParams = [ "console=tty0" ]; # to provide more menu options
boot.growPartition = true;
boot.loader.timeout = lib.mkDefault 5;
boot.loader.timeout = lib.mkDefault 15;
boot.loader.efi.canTouchEfiVariables = false;
users.users.root.password = "";
fileSystems."/boot" = {
Expand Down
4 changes: 2 additions & 2 deletions test/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fi
# -device tpm-tis,tpmdev=tpm0 \

@qemu@ @qemuFlags@ \
-no-reboot \
-nographic \
-smp 2 \
-m 2G \
-bios @corebootROM@/coreboot.rom \
-device virtio-vga \
-serial stdio \
-device nec-usb-xhci,id=xhci \
-device usb-storage,bus=xhci.0,drive=stick,removable=true \
-drive if=none,id=stick,format=raw,file=nixos-@system@.iso \
Expand Down
Loading

0 comments on commit 7ea1189

Please sign in to comment.