withgrub 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env bash
  2. #
  3. # helper script: build ROM images with SeaGRUB and put them in ./bin/
  4. #
  5. # Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
  6. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # This script assumes that the working directory is the root
  22. # of git or release archive
  23. [ "x${DEBUG+set}" = 'xset' ] && set -v
  24. set -u -e
  25. printf "Building ROM images with the GRUB payload\n"
  26. # The GRUB files should be deleted first
  27. rm -f "coreboot/grub"*.{elf,cfg}
  28. rm -f "coreboot/"*/*/grub*.{elf,cfg}
  29. [ -d bin ] || mkdir "bin/"
  30. # Put GRUB payloads and config files
  31. # in the coreboot directory, ready for next step
  32. (
  33. cd "coreboot/"
  34. for romtype in txtmode vesafb; do
  35. cd ../resources/utilities/grub-assemble
  36. ./gen.sh ${romtype}
  37. rm -f "../../../coreboot/grub_${romtype}.elf"
  38. mv "grub_${romtype}.elf" "../../../coreboot/"
  39. cd "../../../coreboot"
  40. # GRUB configuration files
  41. for keylayout in ../resources/utilities/grub-assemble/keymap/original/*; do
  42. keymap="${keylayout##*/}"
  43. cat ../resources/grub/config/extra/{common,"${romtype}"}.cfg > "grub_${keymap}_${romtype}.cfg"
  44. printf "keymap %s\n" "${keymap}" >> "grub_${keymap}_${romtype}.cfg"
  45. cat ../resources/grub/config/menuentries/{common,"${romtype}"}.cfg >> "grub_${keymap}_${romtype}.cfg"
  46. # grubtest.cfg should be able to switch back to grub.cfg
  47. sed "s/grubtest.cfg/grub.cfg/" < "grub_${keymap}_${romtype}.cfg" > "grub_${keymap}_${romtype}_test.cfg"
  48. done
  49. done
  50. )
  51. # Build ROM images for supported boards
  52. buildrom() {
  53. board="$1"
  54. if [ -f "resources/libreboot/config/grub/${board}/config" ]; then
  55. ./oldbuild roms withgrub_helper "${board}"
  56. fi
  57. }
  58. if [ $# -gt 0 ]; then
  59. for board in "${@}"; do
  60. buildrom "${board}"
  61. done
  62. else
  63. for board in resources/libreboot/config/grub/*; do
  64. buildrom "${board##*/}"
  65. done
  66. fi
  67. # Needed on i945 systems for the bucts/dd trick (documented)
  68. # This enables the ROM to be flashed over the lenovo bios firmware
  69. for i945board in "x60" "t60"
  70. do
  71. if [ -d "bin/grub/${i945board}/" ]; then
  72. cd "bin/grub/${i945board}/"
  73. for i945rom in *
  74. do
  75. dd if="${i945rom}" of=top64k.bin bs=1 skip=$[$(stat -c %s "${i945rom}") - 0x10000] count=64k
  76. dd if=top64k.bin of="${i945rom}" bs=1 seek=$[$(stat -c %s "${i945rom}") - 0x20000] count=64k conv=notrunc
  77. rm -f top64k.bin
  78. done
  79. cd "../../../"
  80. fi
  81. done
  82. # Build the deblobbed descriptor+gbe regions for GM45/ICH9M targets.
  83. # Then put them in the ROM images.
  84. if [ -d "bin/grub/" ]; then
  85. cd "bin/grub/"
  86. for board in "x200" "r400" "t400" "t500" "w500"
  87. do
  88. for romsize in "4m" "8m" "16m"
  89. do
  90. if [ -d "${board}_${romsize}b/" ]; then
  91. cd "${board}_${romsize}b/"
  92. if [ -f "../../../gm45macaddress" ]; then
  93. ../../../resources/utilities/ich9deblob/ich9gen --macaddress $(cat ../../../gm45macaddress)
  94. else
  95. ../../../resources/utilities/ich9deblob/ich9gen
  96. fi
  97. for rom in *.rom
  98. do
  99. dd if="ich9fdgbe_${romsize}.bin" of="${rom}" bs=1 count=12k conv=notrunc
  100. done
  101. rm -f "ich9fd"*.bin "mk"*.[ch]
  102. cd "../"
  103. fi
  104. done
  105. done
  106. cd ../../
  107. fi
  108. # The GRUB files are no longer needed
  109. rm -f "coreboot/"*.{elf,cfg}
  110. rm -f "coreboot/"*/*/*.{elf,cfg}
  111. printf "\n\n"