grub 2.6 KB

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