lbmk/script/build/grub

83 lines
2.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2014,2015,2020,2021,2023 Leah Rowe <leah@libreboot.org>
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
. "include/err.sh"
elfdir="elf/grub"
grubcfgsdir="config/grub"
layoutdir="/boot/grub/layouts"
. "${grubcfgsdir}/modules.list"
main()
{
handle_dependencies
build_keymap_configs
build_grub_payload
printf "GRUB files now available under directory: %s\n" "${elfdir}"
}
handle_dependencies()
{
[ -d "src/grub" ] || x_ ./update trees -f grub
[ -f "src/grub/grub-mkstandalone" ] || build_grub_utils
x_ mkdir -p "${elfdir}"
x_ rm -f "${elfdir}/"*
}
build_grub_utils()
{
(
x_ cd "src/grub"
[ ! -d Makefile ] || x_ make distclean
x_ ./bootstrap --gnulib-srcdir=gnulib/ --no-git
x_ ./autogen.sh
x_ ./configure --with-platform=coreboot
x_ make -j$(nproc) FS_PAYLOAD_MODULES=""
)
}
build_keymap_configs()
{
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
for keylayoutfile in "${grubcfgsdir}/keymap/"*.gkb; do
[ -f "${keylayoutfile}" ] || continue
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
keymap="${keylayoutfile##${grubcfgsdir}/keymap/}"
keymap="${keymap%.gkb}"
x_ printf "keymap %s\n" "${keymap}" > \
"${elfdir}/keymap_${keymap}.cfg"
done
}
build_grub_payload()
{
./src/grub/grub-mkstandalone \
--grub-mkimage="src/grub/grub-mkimage" \
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
-O i386-coreboot \
-o "${elfdir}/grub.elf" \
-d "src/grub/grub-core/" \
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
--fonts= --themes= --locales= \
--modules="${grub_modules}" \
--install-modules="${grub_install_modules}" \
"${layoutdir}/colemak.gkb=${grubcfgsdir}/keymap/colemak.gkb" \
"${layoutdir}/deqwertz.gkb=${grubcfgsdir}/keymap/deqwertz.gkb" \
"${layoutdir}/esqwerty.gkb=${grubcfgsdir}/keymap/esqwerty.gkb" \
"${layoutdir}/frazerty.gkb=${grubcfgsdir}/keymap/frazerty.gkb" \
"${layoutdir}/frdvbepo.gkb=${grubcfgsdir}/keymap/frdvbepo.gkb" \
"${layoutdir}/itqwerty.gkb=${grubcfgsdir}/keymap/itqwerty.gkb" \
"${layoutdir}/svenska.gkb=${grubcfgsdir}/keymap/svenska.gkb" \
"${layoutdir}/trqwerty.gkb=${grubcfgsdir}/keymap/trqwerty.gkb" \
"${layoutdir}/ukdvorak.gkb=${grubcfgsdir}/keymap/ukdvorak.gkb" \
"${layoutdir}/ukqwerty.gkb=${grubcfgsdir}/keymap/ukqwerty.gkb" \
"${layoutdir}/usdvorak.gkb=${grubcfgsdir}/keymap/usdvorak.gkb" \
"${layoutdir}/usqwerty.gkb=${grubcfgsdir}/keymap/usqwerty.gkb" \
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
"/boot/grub/grub.cfg=${grubcfgsdir}/config/grub_memdisk.cfg" \
"/boot/grub/grub_default.cfg=${grubcfgsdir}/config/grub.cfg" || \
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
err "build_grub_elf: cannot build grub payload (grub-mkstandalone)"
}
main $@