grub 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # generate GRUB ELF files (coreboot payload) and configuration files
  3. #
  4. # Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. [ "x${DEBUG+set}" = 'xset' ] && set -v
  20. set -u -e
  21. # This is where GRUB is expected to be (outside of the grub-assemble, instead in main checkout)
  22. source "resources/grub/modules.list"
  23. printf "Creating GRUB payloads and configuration files\n"
  24. if [ ! -d "grub/" ]; then
  25. ./download grub
  26. fi
  27. if [ ! -f "grub/grub-mkstandalone" ]; then
  28. ./build module grub
  29. fi
  30. [ ! -d "payload/" ] && mkdir -p payload/
  31. [ ! -d "payload/grub" ] && mkdir -p payload/grub/
  32. rm -f payload/grub/*
  33. # This creates a grub.elf, which will be used with both
  34. # text mode and vesa startup in coreboot
  35. # This will reduce memdisk usage, important to mitigate bug with memdisk too big
  36. # Make GRUB payload executables for each supported keyboard layout.
  37. # Each payload will be applicable to text mode or corebootfb configuration in coreboot
  38. for keylayoutfile in resources/grub/keymap/*; do
  39. if [ ! -f "${keylayoutfile}" ]; then
  40. continue
  41. fi
  42. keymap="${keylayoutfile##*/}"
  43. keymap="${keymap%.gkb}"
  44. grub/grub-mkstandalone \
  45. --grub-mkimage="grub/grub-mkimage" \
  46. -O i386-coreboot \
  47. -o payload/grub/grub_${keymap}.elf \
  48. -d grub/grub-core/ \
  49. --fonts= --themes= --locales= \
  50. --modules="${grub_modules}" \
  51. --install-modules="${grub_install_modules}" \
  52. /boot/grub/grub.cfg=resources/grub/config/grub_memdisk.cfg \
  53. /boot/grub/layouts/${keymap}.gkb=resources/grub/keymap/${keymap}.gkb
  54. printf "Generated: 'payload/grub/grub_%s.elf'\n" "${keymap}"
  55. done
  56. # Now generate the configs. One pair of configs for each keyboard layout.
  57. # In each pair there is a configuration for text mode, and one for corebootfb
  58. for romtype in txtmode corebootfb; do
  59. # GRUB configuration files
  60. for keylayoutfile in resources/grub/keymap/*; do
  61. if [ ! -f "${keylayoutfile}" ]; then
  62. continue
  63. fi
  64. keymap="${keylayoutfile##*/}"
  65. keymap="${keymap%.gkb}"
  66. cat resources/grub/config/extra/{common,"${romtype}"}.cfg > payload/grub/grub_${keymap}_${romtype}.cfg
  67. printf "keymap %s\n" "${keymap}" >> payload/grub/grub_${keymap}_${romtype}.cfg
  68. cat resources/grub/config/menuentries/{common,${romtype}}.cfg >> payload/grub/grub_${keymap}_${romtype}.cfg
  69. # grubtest.cfg should be able to switch back to grub.cfg
  70. sed "s/grubtest.cfg/grub.cfg/" < payload/grub/grub_${keymap}_${romtype}.cfg > payload/grub/grub_${keymap}_${romtype}_test.cfg
  71. printf "Generated 'payload/grub/grub_%s_%s.cfg'\n" "${keymap}" "${romtype}"
  72. printf "Generated 'payload/grub/grub_%s_%s_test.cfg'\n" "${keymap}" "${romtype}"
  73. done
  74. done
  75. ./download dejavusansmono || touch osbmk_error
  76. if [ -f osbmk_error ]; then
  77. rm -f osbmk_error
  78. printf "ERROR: build/payload/grub: Problem downloading dejavusansmono\n"
  79. exit 1
  80. fi
  81. ./grub/grub-mkfont -o payload/grub/dejavusansmono.pf2 dejavusansmono/ttf/DejaVuSansMono.ttf \
  82. || touch osbmk_error
  83. if [ -f osbmk_error ]; then
  84. rm -f osbmk_error
  85. rm -f payload/grub/dejavusansmono.pf2
  86. printf "ERROR: build/payload/grub: Problem generating dejavu font\n"
  87. exit 1
  88. fi
  89. printf "Generated 'payload/grub/dejavusansmono.pf2'\n"
  90. printf "Done! Check payload/grub/ to see the files.\n\n"