grub 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # SPDX-FileCopyrightText: 2014,2015,2020,2021,2023 Leah Rowe <leah@libreboot.org>
  4. [ "x${DEBUG+set}" = 'xset' ] && set -v
  5. set -u -e
  6. . "include/err.sh"
  7. elfdir="elf/grub"
  8. grubcfgsdir="config/grub"
  9. layoutdir="/boot/grub/layouts"
  10. . "${grubcfgsdir}/modules.list"
  11. main()
  12. {
  13. handle_dependencies
  14. build_keymap_configs
  15. build_grub_payload
  16. printf "GRUB files now available under directory: %s\n" "${elfdir}"
  17. }
  18. handle_dependencies()
  19. {
  20. [ -d "src/grub" ] || x_ ./update trees -f grub
  21. [ -f "src/grub/grub-mkstandalone" ] || build_grub_utils
  22. x_ mkdir -p "${elfdir}"
  23. rm -f "${elfdir}/"* || err "!rm elf, handle_, ${elfdir}/"
  24. }
  25. build_grub_utils()
  26. {
  27. (
  28. x_ cd "src/grub"
  29. [ ! -d Makefile ] || x_ make distclean
  30. x_ ./bootstrap --gnulib-srcdir=gnulib/ --no-git
  31. x_ ./autogen.sh
  32. x_ ./configure --with-platform=coreboot
  33. make -j$(nproc) FS_PAYLOAD_MODULES="" || err "!mk grub utils"
  34. )
  35. }
  36. build_keymap_configs()
  37. {
  38. for keylayoutfile in "${grubcfgsdir}/keymap/"*.gkb; do
  39. [ -f "${keylayoutfile}" ] || continue
  40. keymap="${keylayoutfile##${grubcfgsdir}/keymap/}"
  41. keymap="${keymap%.gkb}"
  42. printf "keymap %s\n" "${keymap}" > \
  43. "${elfdir}/keymap_${keymap}.cfg" || err "!insert keymap"
  44. done
  45. }
  46. build_grub_payload()
  47. {
  48. ./src/grub/grub-mkstandalone \
  49. --grub-mkimage="src/grub/grub-mkimage" \
  50. -O i386-coreboot \
  51. -o "${elfdir}/grub.elf" \
  52. -d "src/grub/grub-core/" \
  53. --fonts= --themes= --locales= \
  54. --modules="${grub_modules}" \
  55. --install-modules="${grub_install_modules}" \
  56. "${layoutdir}/colemak.gkb=${grubcfgsdir}/keymap/colemak.gkb" \
  57. "${layoutdir}/deqwertz.gkb=${grubcfgsdir}/keymap/deqwertz.gkb" \
  58. "${layoutdir}/esqwerty.gkb=${grubcfgsdir}/keymap/esqwerty.gkb" \
  59. "${layoutdir}/frazerty.gkb=${grubcfgsdir}/keymap/frazerty.gkb" \
  60. "${layoutdir}/frdvbepo.gkb=${grubcfgsdir}/keymap/frdvbepo.gkb" \
  61. "${layoutdir}/itqwerty.gkb=${grubcfgsdir}/keymap/itqwerty.gkb" \
  62. "${layoutdir}/svenska.gkb=${grubcfgsdir}/keymap/svenska.gkb" \
  63. "${layoutdir}/trqwerty.gkb=${grubcfgsdir}/keymap/trqwerty.gkb" \
  64. "${layoutdir}/ukdvorak.gkb=${grubcfgsdir}/keymap/ukdvorak.gkb" \
  65. "${layoutdir}/ukqwerty.gkb=${grubcfgsdir}/keymap/ukqwerty.gkb" \
  66. "${layoutdir}/usdvorak.gkb=${grubcfgsdir}/keymap/usdvorak.gkb" \
  67. "${layoutdir}/usqwerty.gkb=${grubcfgsdir}/keymap/usqwerty.gkb" \
  68. "/boot/grub/grub.cfg=${grubcfgsdir}/config/grub_memdisk.cfg" \
  69. "/boot/grub/grub_default.cfg=${grubcfgsdir}/config/grub.cfg" || \
  70. err "build_grub_elf: cannot build grub payload (grub-mkstandalone)"
  71. }
  72. main $@