withgrub 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. #
  3. # helper script: build ROM images with GRUB and put them in ./bin/
  4. #
  5. # Copyright (C) 2014, 2015 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. [ -d bin ] || mkdir "bin/"
  27. # Put GRUB payloads and config files
  28. # in the coreboot directory, ready for next step
  29. (
  30. cd "coreboot/"
  31. for romtype in txtmode vesafb; do
  32. cd ../resources/utilities/grub-assemble
  33. ./gen.sh ${romtype}
  34. rm -f "../../../coreboot/grub_${romtype}.elf"
  35. mv "grub_${romtype}.elf" "../../../coreboot/"
  36. cd "../../../coreboot"
  37. # GRUB configuration files
  38. for keylayout in ../resources/utilities/grub-assemble/keymap/original/*; do
  39. keymap="${keylayout##*/}"
  40. cat ../resources/grub/config/extra/{common,"${romtype}"}.cfg > "grub_${keymap}_${romtype}.cfg"
  41. printf "keymap %s\n" "${keymap}" >> "grub_${keymap}_${romtype}.cfg"
  42. cat ../resources/grub/config/menuentries/{common,"${romtype}"}.cfg >> "grub_${keymap}_${romtype}.cfg"
  43. # grubtest.cfg should be able to switch back to grub.cfg
  44. sed "s/grubtest.cfg/grub.cfg/" < "grub_${keymap}_${romtype}.cfg" > "grub_${keymap}_${romtype}_test.cfg"
  45. done
  46. done
  47. )
  48. # Build ROM images for supported boards
  49. buildrom() {
  50. board="$1"
  51. if [ -f "resources/libreboot/config/grub/${board}/config" ]; then
  52. ./build roms withgrub_helper "${board}"
  53. fi
  54. }
  55. if [ $# -gt 0 ]; then
  56. for board in "${@}"; do
  57. buildrom "${board}"
  58. done
  59. else
  60. for board in resources/libreboot/config/grub/*; do
  61. buildrom "${board##*/}"
  62. done
  63. fi
  64. # Needed on i945 systems for the bucts/dd trick (documented)
  65. # This enables the ROM to be flashed over the lenovo bios firmware
  66. for i945board in "x60" "t60"
  67. do
  68. if [ -d "bin/grub/${i945board}/" ]; then
  69. cd "bin/grub/${i945board}/"
  70. for i945rom in *
  71. do
  72. dd if="${i945rom}" of=top64k.bin bs=1 skip=$[$(stat -c %s "${i945rom}") - 0x10000] count=64k
  73. dd if=top64k.bin of="${i945rom}" bs=1 seek=$[$(stat -c %s "${i945rom}") - 0x20000] count=64k conv=notrunc
  74. rm -f top64k.bin
  75. done
  76. cd "../../../"
  77. fi
  78. done
  79. # TEMPORARY HACK: copy t400* to r500*
  80. # (until proper R500 support is added)
  81. if [ -d "bin/grub/" ]; then
  82. cd "bin/grub/"
  83. for board in "t400"
  84. do
  85. for romsize in "4m" "8m"
  86. do
  87. if [ -d "${board}_${romsize}b/" ]; then
  88. cp -R "${board}_${romsize}b/" "r500_${romsize}b/"
  89. fi
  90. done
  91. done
  92. cd ../../
  93. fi
  94. # Build the deblobbed descriptor+gbe regions for GM45/ICH9M targets.
  95. # Then put them in the ROM images.
  96. if [ -d "bin/grub/" ]; then
  97. cd "bin/grub/"
  98. for board in "x200" "r400" "r500" "t400" "t500"
  99. do
  100. for romsize in "4m" "8m"
  101. do
  102. if [ -d "${board}_${romsize}b/" ]; then
  103. cd "${board}_${romsize}b/"
  104. ../../../resources/utilities/ich9deblob/ich9gen
  105. for rom in *
  106. do
  107. if [ "${board}" = "r500" ]; then
  108. dd if="ich9fdnogbe_${romsize}.bin" of="${rom}" bs=1 count=4k conv=notrunc
  109. else
  110. dd if="ich9fdgbe_${romsize}.bin" of="${rom}" bs=1 count=12k conv=notrunc
  111. fi
  112. done
  113. rm -f "ich9fd"*.bin "mk"*.[ch]
  114. cd "../"
  115. fi
  116. done
  117. done
  118. cd ../../
  119. fi
  120. # The GRUB files are no longer needed
  121. rm -f "coreboot/grub"*.{elf,cfg}
  122. printf "\n\n"