2021-05-18 12:56:12 +00:00
|
|
|
set prefix=(memdisk)/boot/grub
|
|
|
|
|
|
|
|
insmod at_keyboard
|
|
|
|
insmod usb_keyboard
|
|
|
|
insmod nativedisk
|
|
|
|
insmod ehci
|
|
|
|
insmod ohci
|
|
|
|
insmod uhci
|
|
|
|
insmod usb
|
|
|
|
insmod usbms
|
|
|
|
insmod regexp
|
|
|
|
|
|
|
|
terminal_input --append at_keyboard
|
2021-12-19 23:15:32 +00:00
|
|
|
terminal_input --append usb_keyboard
|
2021-05-18 12:56:12 +00:00
|
|
|
terminal_output --append cbmemc
|
|
|
|
|
|
|
|
gfxpayload=keep
|
|
|
|
terminal_output --append gfxterm
|
|
|
|
|
2021-10-30 23:54:53 +00:00
|
|
|
if [ -f (cbfsdisk)/background.png ]; then
|
|
|
|
insmod png
|
|
|
|
background_image (cbfsdisk)/background.png
|
|
|
|
elif [ -f (cbfsdisk)/background.jpg ]; then
|
|
|
|
insmod jpeg
|
|
|
|
background_image (cbfsdisk)/background.jpg
|
|
|
|
fi
|
|
|
|
|
2021-05-18 12:56:12 +00:00
|
|
|
set default="0"
|
2023-04-15 11:18:06 +00:00
|
|
|
set timeout=30
|
2021-05-18 12:56:12 +00:00
|
|
|
set pager=1
|
2021-12-29 06:55:07 +00:00
|
|
|
set grub_scan_disk="both"
|
grub: all one grub.elf containing keymaps and cfg
new behaviour:
* grub.cfg and grubtest.cfg no longer inserted to cbfs
* grub.cfg in memdisk instead
* grub.cfg in memdisk defers to cbfs/grub.cfg if added
(not added by default, anymore)
* does not defer to grubtest.cfg even if available
* only shows link to grubtest.cfg if available,
as a menuentry item
keymaps:
if /keymap.gkb exists in cbfs, it uses that by default,
but by default this isn't added. instead, it looks for
a file named keymap.cfg and sources that, which then
sets the keymap to one that is located under memdisk.
this file is inserted for each rom, per layout.
if keymap.gkb and keymap.cfg both absent, grub.cfg in
memdisk shall defer to usqwerty as the default keymap
grub_scan_disk: grub.cfg looks for cbfs file "scan.cfg"
and sources that if found, which will be inserted with
the string: set grub_scandisk=setting_goes_here (based
on target.cfg, generated by build/boot/roms automatically).
If no scan.cfg is found, it defaults to "both"
The "background.png" file remains unchanged, and present in
CBFS, used by grub.cfg if present (and it is, by default)
This change actually *saves* space in CBFS, due to compression,
and means that the grub.cfg is now compressed heavily. This
is also safer, because now the user overrides grub.cfg by
adding it, and they can still add grubtest.cfg for testing
first. If they accidentally delete both configs from cbfs,
Libreboot will fall back to the one in memdisk which would
presumably not be deleted.
This also means that lbmk can now more easily be used by
other build systems, that just want the GRUB part to re-use
in their own project. For example, people who want to build
custom coreboot images without using Libreboot's build system.
This change also *speeds* up the build process considerably,
on the parts where ROM images are copied. It's less than half
a second now, whereas previously it took about 30-45 seconds
for ROM images to copy, because of grub.elf being re-added in
each ROM via cbfstool, where compression is used; I believe
the compression part is what caused slowness.
Much, much faster, more versatile builds.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-28 17:10:35 +00:00
|
|
|
if [ -f (cbfsdisk)/scan.cfg ]; then
|
|
|
|
source (cbfsdisk)/scan.cfg
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f (cbfsdisk)/keymap.gkb ]; then
|
|
|
|
keymap (cbfsdisk)/keymap.gkb
|
|
|
|
elif [ -f (cbfsdisk)/keymap.cfg ]; then
|
|
|
|
source (cbfsdisk)/keymap.cfg
|
|
|
|
else
|
|
|
|
keymap usqwerty
|
|
|
|
fi
|
2021-05-18 12:56:12 +00:00
|
|
|
|
|
|
|
function try_user_config {
|
|
|
|
set root="${1}"
|
|
|
|
for dir in boot grub grub2 boot/grub boot/grub2; do
|
|
|
|
for name in '' osboot_ autoboot_ libreboot_ coreboot_; do
|
|
|
|
if [ -f /"${dir}"/"${name}"grub.cfg ]; then
|
2021-10-31 17:55:49 +00:00
|
|
|
unset superusers
|
2021-05-18 12:56:12 +00:00
|
|
|
configfile /"${dir}"/"${name}"grub.cfg
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
function search_grub {
|
2021-12-29 06:23:57 +00:00
|
|
|
echo -n "Attempting to load grub.cfg from '${1}' devices"
|
2021-12-28 18:23:10 +00:00
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
|
|
|
|
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
|
|
|
try_user_config "(${1}${i},${part})"
|
|
|
|
done
|
2021-12-29 06:04:42 +00:00
|
|
|
# raw devices e.g. (ahci0) instead of (ahci0,1)
|
2021-12-28 18:23:10 +00:00
|
|
|
try_user_config "(${1}${i})"
|
2021-05-18 12:56:12 +00:00
|
|
|
done
|
2021-12-29 06:23:57 +00:00
|
|
|
echo # Insert newline
|
2021-05-18 12:56:12 +00:00
|
|
|
}
|
2021-12-28 18:23:10 +00:00
|
|
|
|
2021-05-18 12:56:12 +00:00
|
|
|
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 {
|
2021-12-29 06:23:57 +00:00
|
|
|
echo "\nAttempting to parse isolinux/syslinux config from '${1}' devices"
|
2021-12-29 02:37:05 +00:00
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
|
|
|
|
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
|
|
|
try_isolinux_config "(${1}${i},${part})"
|
|
|
|
done
|
2021-12-29 06:04:42 +00:00
|
|
|
# raw devices e.g. (usb0) instead of (usb0,1)
|
2021-12-29 02:37:05 +00:00
|
|
|
try_isolinux_config "(${1}${i})"
|
2021-05-18 12:56:12 +00:00
|
|
|
done
|
2021-12-29 06:23:57 +00:00
|
|
|
echo # Insert newline
|
2021-05-18 12:56:12 +00:00
|
|
|
}
|
|
|
|
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
|
2021-12-29 06:55:07 +00:00
|
|
|
|
|
|
|
if [ "${grub_scan_disk}" != "ata" ]; then
|
|
|
|
search_grub ahci
|
|
|
|
fi
|
|
|
|
if [ "${grub_scan_disk}" != "ahci" ]; then
|
|
|
|
search_grub ata
|
|
|
|
fi
|
2021-12-29 06:04:42 +00:00
|
|
|
|
|
|
|
# grub device enumeration is very slow, so checks are hardcoded
|
|
|
|
|
|
|
|
# TODO: add more strings, based on what distros set up when
|
|
|
|
# the user select auto-partitioning on those installers
|
2021-12-29 05:58:03 +00:00
|
|
|
lvmvol="lvm/matrix-bootvol lvm/matrix-rootvol"
|
2021-12-29 06:04:42 +00:00
|
|
|
|
2021-12-29 05:58:03 +00:00
|
|
|
raidvol="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
|
|
|
|
|
|
|
|
# in practise, doing multiple redundant checks is perfectly fast and
|
|
|
|
# TODO: optimize grub itself, and use */? here for everything
|
|
|
|
|
2021-05-18 12:56:12 +00:00
|
|
|
for vol in ${lvmvol} ${raidvol} ; do
|
|
|
|
try_user_config "${vol}"
|
|
|
|
done
|
|
|
|
|
|
|
|
unset ahcidev
|
|
|
|
unset atadev
|
2021-12-29 05:58:03 +00:00
|
|
|
for i in 11 10 9 8 7 6 5 4 3 2 1 0; do
|
|
|
|
for part in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do
|
2021-12-29 06:55:07 +00:00
|
|
|
if [ "${grub_scan_disk}" != "ata" ]; then
|
|
|
|
ahcidev="(ahci${i},${part}) ${ahcidev}"
|
|
|
|
fi
|
|
|
|
if [ "${grub_scan_disk}" != "ahci" ]; then
|
|
|
|
atadev="(ata${i},${part}) ${atadev}"
|
|
|
|
fi
|
2021-10-30 15:03:10 +00:00
|
|
|
done
|
2021-12-29 05:58:03 +00:00
|
|
|
done
|
|
|
|
|
2021-05-18 12:56:12 +00:00
|
|
|
set pager=0
|
2021-12-29 06:23:57 +00:00
|
|
|
echo -n "Attempting to unlock encrypted volumes"
|
2021-10-31 18:08:13 +00:00
|
|
|
for dev in ${ahcidev} ${atadev} ${lvmvol} ${raidvol}; do
|
2021-10-30 15:03:10 +00:00
|
|
|
if cryptomount "${dev}" ; then break ; fi
|
2021-05-18 12:56:12 +00:00
|
|
|
done
|
|
|
|
set pager=1
|
2021-12-29 06:04:42 +00:00
|
|
|
echo
|
2021-05-18 12:56:12 +00:00
|
|
|
|
2021-12-29 06:04:42 +00:00
|
|
|
# after cryptomount, lvm volumes might be available
|
2021-05-18 12:56:12 +00:00
|
|
|
for vol in ${lvmvol}; do
|
|
|
|
try_user_config "${vol}"
|
|
|
|
done
|
|
|
|
|
2021-10-31 18:10:34 +00:00
|
|
|
search_grub crypto
|
|
|
|
|
2021-12-29 06:55:07 +00:00
|
|
|
if [ "${grub_scan_disk}" != "ata" ]; then
|
|
|
|
# Last resort, if all else fails
|
|
|
|
set root=ahci0,1
|
|
|
|
for p in / /boot/; do
|
|
|
|
if [ -f "${p}vmlinuz" ]; then
|
|
|
|
linux ${p}vmlinuz root=/dev/sda1 rw
|
|
|
|
if [ -f "${p}initrd.img" ]; then
|
|
|
|
initrd ${p}initrd.img
|
|
|
|
fi
|
2021-05-18 12:56:12 +00:00
|
|
|
fi
|
2021-12-29 06:55:07 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${grub_scan_disk}" != "ahci" ]; then
|
|
|
|
# Last resort (for setups that use IDE instead of SATA)
|
|
|
|
set root=ata0,1
|
|
|
|
for p in / /boot/; do
|
|
|
|
if [ -f "${p}vmlinuz" ]; then
|
|
|
|
linux ${p}vmlinuz root=/dev/sda1 rw
|
|
|
|
if [ -f "${p}initrd.img" ]; then
|
|
|
|
initrd ${p}initrd.img
|
|
|
|
fi
|
2021-05-18 12:56:12 +00:00
|
|
|
fi
|
2021-12-29 06:55:07 +00:00
|
|
|
done
|
|
|
|
fi
|
2021-05-18 12:56:12 +00:00
|
|
|
|
|
|
|
true # Prevent pager requiring to accept each line instead of whole screen
|
|
|
|
}
|
2021-10-30 15:03:10 +00:00
|
|
|
|
2021-05-18 12:56:12 +00:00
|
|
|
menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
|
|
|
|
search_isolinux ahci
|
|
|
|
}
|
|
|
|
menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
|
|
|
|
search_isolinux usb
|
|
|
|
}
|
2021-12-29 06:10:45 +00:00
|
|
|
menuentry 'Search ISOLINUX menu (ATA/IDE) [d]' --hotkey='d' {
|
|
|
|
search_isolinux ata
|
|
|
|
}
|
grub: all one grub.elf containing keymaps and cfg
new behaviour:
* grub.cfg and grubtest.cfg no longer inserted to cbfs
* grub.cfg in memdisk instead
* grub.cfg in memdisk defers to cbfs/grub.cfg if added
(not added by default, anymore)
* does not defer to grubtest.cfg even if available
* only shows link to grubtest.cfg if available,
as a menuentry item
keymaps:
if /keymap.gkb exists in cbfs, it uses that by default,
but by default this isn't added. instead, it looks for
a file named keymap.cfg and sources that, which then
sets the keymap to one that is located under memdisk.
this file is inserted for each rom, per layout.
if keymap.gkb and keymap.cfg both absent, grub.cfg in
memdisk shall defer to usqwerty as the default keymap
grub_scan_disk: grub.cfg looks for cbfs file "scan.cfg"
and sources that if found, which will be inserted with
the string: set grub_scandisk=setting_goes_here (based
on target.cfg, generated by build/boot/roms automatically).
If no scan.cfg is found, it defaults to "both"
The "background.png" file remains unchanged, and present in
CBFS, used by grub.cfg if present (and it is, by default)
This change actually *saves* space in CBFS, due to compression,
and means that the grub.cfg is now compressed heavily. This
is also safer, because now the user overrides grub.cfg by
adding it, and they can still add grubtest.cfg for testing
first. If they accidentally delete both configs from cbfs,
Libreboot will fall back to the one in memdisk which would
presumably not be deleted.
This also means that lbmk can now more easily be used by
other build systems, that just want the GRUB part to re-use
in their own project. For example, people who want to build
custom coreboot images without using Libreboot's build system.
This change also *speeds* up the build process considerably,
on the parts where ROM images are copied. It's less than half
a second now, whereas previously it took about 30-45 seconds
for ROM images to copy, because of grub.elf being re-added in
each ROM via cbfstool, where compression is used; I believe
the compression part is what caused slowness.
Much, much faster, more versatile builds.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-28 17:10:35 +00:00
|
|
|
if [ -f (cbfsdisk)/grubtest.cfg ]; then
|
2021-05-18 12:56:12 +00:00
|
|
|
menuentry 'Load test configuration (grubtest.cfg) inside of CBFS [t]' --hotkey='t' {
|
|
|
|
set root='(cbfsdisk)'
|
|
|
|
if [ -f /grubtest.cfg ]; then
|
|
|
|
configfile /grubtest.cfg
|
|
|
|
fi
|
|
|
|
}
|
grub: all one grub.elf containing keymaps and cfg
new behaviour:
* grub.cfg and grubtest.cfg no longer inserted to cbfs
* grub.cfg in memdisk instead
* grub.cfg in memdisk defers to cbfs/grub.cfg if added
(not added by default, anymore)
* does not defer to grubtest.cfg even if available
* only shows link to grubtest.cfg if available,
as a menuentry item
keymaps:
if /keymap.gkb exists in cbfs, it uses that by default,
but by default this isn't added. instead, it looks for
a file named keymap.cfg and sources that, which then
sets the keymap to one that is located under memdisk.
this file is inserted for each rom, per layout.
if keymap.gkb and keymap.cfg both absent, grub.cfg in
memdisk shall defer to usqwerty as the default keymap
grub_scan_disk: grub.cfg looks for cbfs file "scan.cfg"
and sources that if found, which will be inserted with
the string: set grub_scandisk=setting_goes_here (based
on target.cfg, generated by build/boot/roms automatically).
If no scan.cfg is found, it defaults to "both"
The "background.png" file remains unchanged, and present in
CBFS, used by grub.cfg if present (and it is, by default)
This change actually *saves* space in CBFS, due to compression,
and means that the grub.cfg is now compressed heavily. This
is also safer, because now the user overrides grub.cfg by
adding it, and they can still add grubtest.cfg for testing
first. If they accidentally delete both configs from cbfs,
Libreboot will fall back to the one in memdisk which would
presumably not be deleted.
This also means that lbmk can now more easily be used by
other build systems, that just want the GRUB part to re-use
in their own project. For example, people who want to build
custom coreboot images without using Libreboot's build system.
This change also *speeds* up the build process considerably,
on the parts where ROM images are copied. It's less than half
a second now, whereas previously it took about 30-45 seconds
for ROM images to copy, because of grub.elf being re-added in
each ROM via cbfstool, where compression is used; I believe
the compression part is what caused slowness.
Much, much faster, more versatile builds.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-28 17:10:35 +00:00
|
|
|
fi
|
2021-05-18 12:56:12 +00:00
|
|
|
menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
|
|
|
|
search_grub usb
|
|
|
|
}
|
|
|
|
if [ -f (cbfsdisk)/seabios.elf ]; then
|
|
|
|
menuentry 'Load SeaBIOS (payload) [b]' --hotkey='b' {
|
2021-10-31 17:55:49 +00:00
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /seabios.elf
|
2021-05-18 12:56:12 +00:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
if [ -f (cbfsdisk)/img/grub2 ]; then
|
|
|
|
menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
|
2021-10-31 17:55:49 +00:00
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /fallback/payload
|
2021-05-18 12:56:12 +00:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
menuentry 'Poweroff [p]' --hotkey='p' {
|
|
|
|
halt
|
|
|
|
}
|
|
|
|
menuentry 'Reboot [r]' --hotkey='r' {
|
|
|
|
reboot
|
|
|
|
}
|
2021-11-01 02:51:10 +00:00
|
|
|
if [ -f (cbfsdisk)/img/memtest ]; then
|
|
|
|
menuentry 'Load MemTest86+ [m]' --hotkey='m' {
|
|
|
|
set root='cbfsdisk'
|
|
|
|
chainloader /img/memtest
|
|
|
|
}
|
|
|
|
fi
|