Skip to content

Commit

Permalink
Send boot files to server from client
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbaur committed May 12, 2024
1 parent 7a703dc commit 6d12523
Show file tree
Hide file tree
Showing 20 changed files with 375 additions and 183 deletions.
1 change: 1 addition & 0 deletions boards/volteer-elemi/config.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib, ... }:
{
debug = true;
platform.tigerlake = true;
chromebook = true;
video = true;
Expand Down
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});

const coreboot_support = b.option(bool, "coreboot", "Support for coreboot integration") orelse true;
const loglevel = b.option(u8, "loglevel", "Log level") orelse 3;
const tboot_loader_options = b.addOptions();
tboot_loader_options.addOption(bool, "coreboot_support", coreboot_support);
tboot_loader_options.addOption(u8, "loglevel", loglevel);

const tboot_loader_optimize = if (optimize == std.builtin.OptimizeMode.Debug)
std.builtin.OptimizeMode.Debug
Expand Down
20 changes: 19 additions & 1 deletion flake.lock

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

8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
description = "A small linuxboot payload for coreboot";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
zig.flake = false;
zig.url = "github:ziglang/zig/0.12.x";
};
outputs = inputs: {
formatter = inputs.nixpkgs.lib.mapAttrs (_: pkgs: pkgs.nixfmt-rfc-style) inputs.self.legacyPackages;
nixosModules.default = {
Expand All @@ -11,7 +15,7 @@
final: prev:
(
{
tinyboot = prev.callPackage ./pkgs/tinyboot.nix { };
tinyboot = prev.callPackage ./pkgs/tinyboot.nix { zigSrc = inputs.zig.outPath; };
armTrustedFirmwareMT8183 = prev.callPackage ./pkgs/arm-trusted-firmware-cros.nix {
platform = "mt8183";
};
Expand Down
1 change: 0 additions & 1 deletion kernel-configs/chromebook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
CROS_EC_SPI = yes;
HID_VIVALDI = yes;
I2C_CROS_EC_TUNNEL = yes;
INPUT_VIVALDIFMAP = yes;
KEYBOARD_CROS_EC = yes;
MMC = yes;
MMC_BLOCK = yes;
Expand Down
6 changes: 4 additions & 2 deletions kernel-configs/debug.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ in
with lib.kernel;
{
BUG = yes;
SERIAL_EARLYCON = yes;
EFI_EARLYCON = lib.mkIf efi yes;
DEBUG_BUGVERBOSE = yes;
DEBUG_KERNEL = yes;
DEBUG_MUTEXES = yes;
DYNAMIC_DEBUG = yes;
EARLY_PRINTK = yes;
EFI_EARLYCON = lib.mkIf efi yes;
FTRACE = yes;
GENERIC_BUG = yes;
IKCONFIG = yes;
KALLSYMS = yes;
SERIAL_EARLYCON = yes;
SYMBOLIC_ERRNAME = yes;
}
);
Expand Down
3 changes: 1 addition & 2 deletions kernel-configs/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in
BLOCK = yes;
CC_OPTIMIZE_FOR_PERFORMANCE = unset;
CC_OPTIMIZE_FOR_SIZE = yes;
COMMON_CLK = yes;
CONSOLE_TRANSLATIONS = yes;
CRYPTO_HW = yes;
CRYPTO_SHA256 = yes;
Expand Down Expand Up @@ -101,8 +102,6 @@ in
TIMERFD = yes;
TMPFS = yes;
TTY = yes;
TTY_PRINTK = yes;
TTY_PRINTK_LEVEL = freeform (if config.debug then 7 else 6);
UNIX = yes;
USB = yes;
USB_EHCI_HCD = yes;
Expand Down
6 changes: 3 additions & 3 deletions kernel-configs/platform.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ config, lib, ... }:
{
linux.kconfig =
linux.kconfig = lib.mkIf (config.platform != null) (
with lib.kernel;
{
"qemu" = {
Expand All @@ -9,7 +9,6 @@
E1000 = yes;
FW_CFG_SYSFS = yes;
I2C_VIRTIO = yes;
IKCONFIG = yes;
NETWORK_FILESYSTEMS = yes;
NET_9P = yes;
NET_9P_VIRTIO = yes;
Expand Down Expand Up @@ -210,5 +209,6 @@
USB_XHCI_MTK = yes;
};
}
.${lib.head (lib.attrNames config.platform)};
.${lib.head (lib.attrNames config.platform)}
);
}
12 changes: 10 additions & 2 deletions kernel-configs/video.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{ config, lib, ... }:
{
config,
lib,
pkgs,
...
}:
{
linux.kconfig = lib.mkIf config.video (
with lib.kernel;
{
BACKLIGHT_CLASS_DEVICE = yes;
DRM = yes;
DRM_SIMPLEDRM = yes;
FB = yes;
FB_SIMPLE = yes;
# TODO(jared): FB_SIMPLE = yes;
FONTS = yes;
FONT_SUPPORT = yes;
FONT_TER16x32 = yes;
FRAMEBUFFER_CONSOLE = yes;
ACPI_VIDEO = lib.mkIf pkgs.stdenv.hostPlatform.isx86_64 yes;
FRAMEBUFFER_CONSOLE_DETECT_PRIMARY = yes;
GOOGLE_FRAMEBUFFER_COREBOOT = yes;
LOGO = yes;
Expand Down
4 changes: 3 additions & 1 deletion kernel-configs/x86_64.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
ACPI_BUTTON = yes;
ACPI_PROCESSOR = yes;
ACPI_THERMAL = yes;
ACPI_VIDEO = yes;
ACPI_WMI = yes;
ATA_ACPI = yes;
CMDLINE_BOOL = yes;
CPU_MITIGATIONS = yes;
CRYPTO_SHA256_SSSE3 = yes;
CRYPTO_SHA512_SSSE3 = yes;
DMA_ACPI = yes;
DW_DMAC = yes;
GPIO_ACPI = yes;
IRQ_REMAP = yes;
Expand Down Expand Up @@ -59,6 +59,8 @@
X86_64 = yes;
X86_INTEL_LPSS = yes;
X86_IOPL_IOPERM = yes;
X86_IO_APIC = yes;
X86_LOCAL_APIC = yes;
X86_PAT = yes;
X86_PLATFORM_DEVICES = yes;
X86_REROUTE_FOR_BROKEN_BOOT_IRQS = yes;
Expand Down
49 changes: 39 additions & 10 deletions options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@
...
}:
let
tinyboot = pkgs.tinyboot.override { corebootSupport = config.coreboot.enable; };
tinyboot = pkgs.tinyboot.override {
inherit (config) debug;
corebootSupport = config.coreboot.enable;
};
buildFitImage = pkgs.callPackage ./fitimage { };
testStartupScript = pkgs.writeScript "installer-startup-script" ''
#!/bin/sh
mkdir -p /proc && mount -t proc proc /proc
mkdir -p /sys && mount -t sysfs sysfs /sys
mkdir -p /dev && mount -t devtmpfs devtmpfs /dev
mkdir -p /dev/pts && mount -t devpts devpts /dev/pts
mkdir -p /run && mount -t tmpfs tmpfs /run
ln -sfn /proc/self/fd /dev/fd
ln -sfn /proc/self/fd/0 /dev/stdin
ln -sfn /proc/self/fd/1 /dev/stdout
ln -sfn /proc/self/fd/2 /dev/stderr
'';
testInittab = pkgs.writeText "inittab" ''
::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
::ctrlaltdel:/bin/reboot
::shutdown:/bin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/bin/init
tty2::askfirst:/bin/sh
tty3::askfirst:/bin/sh
tty4::askfirst:/bin/sh
ttyS0::askfirst:/bin/sh
'';
testInitrd = pkgs.makeInitrdNG {
compressor = "xz";
contents = [
Expand All @@ -34,6 +50,10 @@ let
object = testStartupScript;
symlink = "/etc/init.d/rcS";
}
{
object = testInittab;
symlink = "/etc/inittab";
}
] ++ config.extraInitrdContents;
};
kconfigOption = lib.mkOption {
Expand Down Expand Up @@ -108,13 +128,16 @@ in
network = mkEnableOption "network";
chromebook = mkEnableOption "chromebook";
platform = mkOption {
type = types.attrTag {
alderlake = mkEnableOption "alderlake";
mediatek = mkEnableOption "mediatek";
qemu = mkEnableOption "qemu";
qualcomm = mkEnableOption "qualcomm";
tigerlake = mkEnableOption "tigerlake";
};
type = types.nullOr (
types.attrTag {
alderlake = mkEnableOption "alderlake";
mediatek = mkEnableOption "mediatek";
qemu = mkEnableOption "qemu";
qualcomm = mkEnableOption "qualcomm";
tigerlake = mkEnableOption "tigerlake";
}
);
default = null;
};
linux = {
package = mkOption {
Expand Down Expand Up @@ -142,7 +165,7 @@ in
};
coreboot = {
enable = mkEnableOption "coreboot integration" // {
default = true;
default = config.chromebook;
};
wpRange.start = mkOption { type = types.str; };
wpRange.length = mkOption { type = types.str; };
Expand Down Expand Up @@ -192,7 +215,13 @@ in
};
config = {
linux.kconfig.CMDLINE = lib.kernel.freeform (
toString (lib.optionals config.video [ "fbcon=logo-count:1" ] ++ [ "console=ttynull" ])
toString (
lib.optionals config.video [ "fbcon=logo-count:1" ]
++ [
"console=ttynull"
"loglevel=${if config.debug then "7" else "6"}"
]
)
);
extraInitrdContents = lib.optional (config.linux.firmware != [ ]) {
symlink = "/lib/firmware";
Expand Down
15 changes: 4 additions & 11 deletions pkgs/tinyboot.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
callPackage,
corebootSupport ? true,
fetchpatch,
debug ? false,
zigSrc,
lib,
stdenv,
xz,
Expand All @@ -12,6 +12,7 @@ let
"-Doptimize=ReleaseSafe"
"-Dtarget=${stdenv.hostPlatform.qemuArch}-linux"
"-Dcoreboot=${lib.boolToString corebootSupport}"
"-Dloglevel=${toString (if debug then 3 else 2)}" # https://github.com/ziglang/zig/blob/084c2cd90f79d5e7edf76b7ddd390adb95a27f0c/lib/std/log.zig#L78
];
in
stdenv.mkDerivation {
Expand All @@ -28,15 +29,7 @@ stdenv.mkDerivation {
};

nativeBuildInputs = [
(zig_0_12.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [
(fetchpatch {
name = "Fix usage of unexpectedErrno";
url = "https://github.com/ziglang/zig/commit/e4b86875ebdebd5279bea546b7cde143ba4ddb23.patch";
hash = "sha256-dBdx7k8uDO8+OsvLAiF8y+jSdkV2zu/1VfQS6v3i3Tk=";
})
];
}))
(zig_0_12.overrideAttrs (old: { src = zigSrc; }))
xz
];

Expand Down
Loading

0 comments on commit 6d12523

Please sign in to comment.