From d78a2422911b3c0674418cbda9c3e9e18c3f610f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20P=C3=A4ssler?= Date: Sat, 10 Oct 2020 20:42:11 +0200 Subject: . --- grub.cfg | 173 ----------------------------------- modules/coreboot/default.nix | 18 ++-- modules/grub2/default.nix | 17 +++- modules/grub2/files/background.png | Bin 0 -> 390630 bytes modules/grub2/files/grub.cfg | 182 +++++++++++++++++++++++++++++++++++++ 5 files changed, 208 insertions(+), 182 deletions(-) delete mode 100644 grub.cfg create mode 100644 modules/grub2/files/background.png create mode 100644 modules/grub2/files/grub.cfg diff --git a/grub.cfg b/grub.cfg deleted file mode 100644 index 9962c3e24115..000000000000 --- a/grub.cfg +++ /dev/null @@ -1,173 +0,0 @@ -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 (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 -} 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 Binary files /dev/null and b/modules/grub2/files/background.png 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 +} -- cgit v1.2.3