aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMilan Pässler <milan@petabyte.dev>2020-10-10 20:42:11 +0200
committerMilan Pässler <milan@petabyte.dev>2020-10-10 20:42:11 +0200
commitd78a2422911b3c0674418cbda9c3e9e18c3f610f (patch)
treed2ca921d4816499c709e3f653a8ffaea5457ee6a /modules
parentb0ae9e89f047a1fef88c41a64131c26c594b1eba (diff)
.
Diffstat (limited to 'modules')
-rw-r--r--modules/coreboot/default.nix18
-rw-r--r--modules/grub2/default.nix17
-rw-r--r--modules/grub2/files/background.pngbin0 -> 390630 bytes
-rw-r--r--modules/grub2/files/grub.cfg182
4 files changed, 208 insertions, 9 deletions
diff --git a/modules/coreboot/default.nix b/modules/coreboot/default.nix
index a4ae0f675c3f..b49c8a7d871e 100644
--- a/modules/coreboot/default.nix
+++ b/modules/coreboot/default.nix
@@ -37,12 +37,18 @@ in {
filteredFiles = filterAttrs (k: v: v != null) cfg.extraFiles;
filesList = mapAttrsToList (k: v: v // { name = k; }) filteredFiles;
- installCommands = concatMapStringsSep "\n" (file: ''
- cbfstool $out/coreboot.rom add \
- -f "${file.src}" \
- -n "${file.name}" \
- -t "${file.type}"
- '') filesList;
+ installCommands = concatMapStringsSep "\n" (file:
+ if file.type == "payload" then ''
+ cbfstool $out/coreboot.rom add-payload \
+ -f "${file.src}" \
+ -n "${file.name}" \
+ '' else ''
+ cbfstool $out/coreboot.rom add \
+ -f "${file.src}" \
+ -n "${file.name}" \
+ -t "${file.type}"
+ ''
+ ) filesList;
in pkgs.runCommand "coreboot-rom" {
buildInputs = with pkgs; [ cbfstool ];
diff --git a/modules/grub2/default.nix b/modules/grub2/default.nix
index c1993f2ea518..e07b2987bb0c 100644
--- a/modules/grub2/default.nix
+++ b/modules/grub2/default.nix
@@ -7,16 +7,27 @@ let
in {
options.grub2 = {
enable = mkEnableOption "grub2 coreboot primary payload";
+
+ font = mkOption {
+ type = types.path;
+ default = "${pkgs.unifont}/share/fonts/truetype/unifont.ttf";
+ };
};
config = lib.mkIf cfg.enable {
coreboot.extraFiles = {
"fallback/payload" = {
- type = "simple elf";
+ type = "payload";
src = "${pkgs.coreboot-payload-grub2}/default_payload.elf";
};
- "grub.cfg" = {
- src = ../../grub.cfg;
+ "etc/grub.cfg".src = ./files/grub.cfg;
+ "etc/background.png".src = ./files/background.png;
+ "font.pf2" = {
+ src = pkgs.runCommand "font.pf2" {
+ buildInputs = with pkgs; [ grub2 ];
+ } ''
+ grub-mkfont -o $out ${cfg.font}
+ '';
};
};
};
diff --git a/modules/grub2/files/background.png b/modules/grub2/files/background.png
new file mode 100644
index 000000000000..29275058f283
--- /dev/null
+++ b/modules/grub2/files/background.png
Binary files differ
diff --git a/modules/grub2/files/grub.cfg b/modules/grub2/files/grub.cfg
new file mode 100644
index 000000000000..5ed7fff569b8
--- /dev/null
+++ b/modules/grub2/files/grub.cfg
@@ -0,0 +1,182 @@
+function try_user_config {
+ set root="${1}"
+ for dir in boot grub grub2 boot/grub boot/grub2; do
+ for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
+ if [ -f /"${dir}"/"${name}"grub.cfg ]; then
+ unset superusers
+ configfile /"${dir}"/"${name}"grub.cfg
+ fi
+ done
+ done
+}
+
+function search_grub {
+ for i in 0 1; do
+ # raw devices
+ try_user_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_user_config "(${1}${i},${part})"
+ done
+ done
+}
+
+function try_isolinux_config {
+ set root="${1}"
+ for dir in '' /boot; do
+ if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
+ syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
+ elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
+ syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
+ fi
+ done
+}
+
+function search_isolinux {
+ for i in 0 1; do
+ # raw devices
+ try_isolinux_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_isolinux_config "(${1}${i},${part})"
+ done
+ done
+}
+
+function load_video {
+ if [ x$feature_all_video_module = xy ]; then
+ insmod all_video
+ else
+ insmod efi_gop
+ insmod efi_uga
+ insmod ieee1275_fb
+ insmod vbe
+ insmod vga
+ insmod video_bochs
+ insmod video_cirrus
+ fi
+}
+
+
+if loadfont (cbfsdisk)/font.pf2 ; then
+ set gfxmode=auto
+ load_video
+ insmod gfxterm
+ set locale_dir=$prefix/locale
+ set lang=en_US
+ insmod gettext
+fi
+
+terminal_input console
+terminal_output gfxterm
+gfxpayload=keep
+
+if [ x$feature_timeout_style = xy ] ; then
+ set timeout_style=menu
+ set timeout=1
+# Fallback normal timeout code in case the timeout_style feature is
+# unavailable.
+else
+ set timeout=5
+fi
+
+insmod png
+if background_image (cbfsdisk)/background.png; then
+ true
+fi
+
+#Scan for OS on internal HDD
+insmod regexp
+insmod ahci
+insmod part_msdos
+for x in (ahci*,*) ; do
+ if [ -f "$x/netbsd" ] ; then
+ menuentry "Load NetBSD from $x" $x {
+ root=$2
+ knetbsd /netbsd
+ }
+ fi
+done
+
+for x in (usb*,*) ; do
+ if [ -f "$x/netbsd" ] ; then
+ menuentry "Load NetBSD from $x" $x {
+ root=$2
+ knetbsd /netbsd
+ }
+ fi
+done
+
+for x in (ahci*,*) ; do
+ if [ -f "$x/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /grub/grub.cfg
+ }
+ fi
+ if [ -f "$x/boot/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /boot/grub/grub.cfg
+ }
+ fi
+done
+
+for x in (usb*,*) ; do
+ if [ -f "$x/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /grub/grub.cfg
+ }
+ fi
+ if [ -f "$x/boot/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /boot/grub/grub.cfg
+ }
+ fi
+done
+
+
+menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
+ search_isolinux ahci
+}
+
+menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
+ search_isolinux usb
+}
+
+menuentry 'Search ISOLINUX menu (CD/DVD) [d]' --hotkey='d' {
+ insmod ata
+ for dev in ata0 ata1 ata2 ata3 ahci1; do
+ try_isolinux_config "(${dev})"
+ done
+}
+
+menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
+ search_grub usb
+}
+
+menuentry 'nvramcui' {
+ chainloader (cbfsdisk)/img/nvramcui
+}
+
+menuentry 'coreinfo' {
+ chainloader (cbfsdisk)/img/coreinfo
+}
+
+menuentry 'Memtest86+' {
+ chainloader (cbfsdisk)/img/memtest
+}
+
+menuentry 'tint' {
+ chainloader (cbfsdisk)/img/tint
+}
+
+menuentry 'Poweroff [p]' --hotkey='p' {
+ halt
+}
+
+menuentry 'Reboot [r]' --hotkey='r' {
+ reboot
+}