withgrub_helper 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. # helper script: create ROM images for a given system, with SeaGRUB
  3. #
  4. # Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # This script assumes that the working directory is the root
  21. # of git or release archive
  22. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. if [ -z ${NPROC+x} ]; then
  25. cores="$(nproc)"
  26. else
  27. case ${NPROC} in
  28. ''|*[!0-9]*)
  29. printf "value '%s' for NPROC is invalid. non-numeric. Exiting.\n" "${NPROC}"
  30. exit 1
  31. ;;
  32. esac
  33. cores="${NPROC}"
  34. fi
  35. if (( $# != 1 )); then
  36. printf "Usage: ./oldbuild rom withgrub boardname\n"
  37. printf "Example: ./oldbuild rom withgrub x60\n"
  38. printf "You need to specify exactly 1 argument\n"
  39. exit 1
  40. fi
  41. boardtarget="${1}"
  42. if [ -f "version" ]; then
  43. # release archive is being used
  44. version="$(cat version)"
  45. else
  46. # git repo is being used
  47. version="$(git describe --tags HEAD)"
  48. fi
  49. printf "GRUB Helper script: build ROM images for '%s'\n" "${boardtarget}"
  50. (
  51. cbrevision="$(cat resources/libreboot/config/grub/${boardtarget}/cbrevision)"
  52. vbootrevision="$(cat resources/libreboot/config/grub/${boardtarget}/vbootrevision)"
  53. branchname="grub_${boardtarget}"
  54. cd "coreboot/${cbrevision}/${cbrevision}/"
  55. git checkout ${branchname}
  56. (
  57. cd "3rdparty/vboot/"
  58. git checkout ${branchname}
  59. )
  60. # Make sure to remove these first
  61. rm -f *.{elf,cfg}
  62. printf 'libreboot-%s\n' "${version}" > ".coreboot-version" # needed for reproducible builds in coreboot
  63. # Build ROM images with text-mode and corebootfb modes.
  64. if [ "${boardtarget}" = "qemu_i440fx_piix4" ] || [ "${boardtarget}" = "qemu_q35_ich9" ]
  65. then
  66. # assume that the default config enable framebuffer mode, duplicate and patch for text-mode
  67. # necessary, otherwise it will ask you to enter the Y/X resolution of the framebuffer at build time
  68. cp "../../../resources/libreboot/config/grub/${boardtarget}/config" "config_vesafb"
  69. sed 's/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/' < "config_vesafb" > "config_txtmode"
  70. else
  71. # assume that the default config enables text-mode, duplicate and patch for framebuffer mode
  72. cp "../../../resources/libreboot/config/grub/${boardtarget}/config" "config_txtmode"
  73. sed 's/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/' < "config_txtmode" > "config_vesafb"
  74. fi
  75. for romtype in txtmode vesafb
  76. do
  77. if [ "${boardtarget}" = "kgpe-d16" ] || [ "${boardtarget}" = "ga-g41m-es2l" ] || [ "${boardtarget}" = "kcma-d8" ] || [ "${boardtarget}" = "d510mo" ]; then
  78. if [ "${romtype}" = "vesafb" ]; then
  79. printf "Only text-mode is reported to work on KGPE-D16, KCMA-D8, D510MO and ga-g41m-es2l\n"
  80. printf "TODO: get tpearson to fix it\n"
  81. continue
  82. fi
  83. fi
  84. # Build coreboot ROM image
  85. make clean
  86. mv "config_${romtype}" ".config"
  87. cp "../../grub_${romtype}.elf" "grub.elf"
  88. if [ "${boardtarget}" = "d510mo" ] || [ "${boardtarget}" = "ga-g41m-es2l" ]; then
  89. # Do not use SeaGRUB
  90. cp grub.elf payload.elf
  91. make -j${cores}
  92. mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"
  93. # We dont need seabios.elf anymore
  94. rm -f "payload.elf"
  95. else
  96. # Use SeaGRUB
  97. cp "../../../seabios/out/bios.bin.elf" "payload.elf"
  98. make -j${cores}
  99. mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"
  100. # We dont need seabios.elf anymore
  101. rm -f "payload.elf"
  102. # Add the grub.elf to CBFS
  103. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-payload -c lzma -f grub.elf -n img/grub2
  104. # Set bootorder so that seabios loads grub by default
  105. printf "/rom@img/grub2\n" > bootorder
  106. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f bootorder -n bootorder -t raw
  107. rm -f bootorder
  108. # Add 0s delay to seabios, so that the user is not burdened by seeing
  109. # that horrible interface that seabios has
  110. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 0 -n etc/show-boot-menu || "already exists"
  111. # Add a file to CBFS that tells SeaBIOS not to load option ROMs
  112. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 0 -n etc/pci-optionrom-exec || "already exists"
  113. # keyboard spinup timeout
  114. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" remove -n etc/ps2-keyboard-spinup || printf "does not exist"
  115. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 3000 -n etc/ps2-keyboard-spinup || printf "already exists"
  116. fi
  117. printf "%s\n" "${version}" > lbversion
  118. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f lbversion -n lbversion -t raw
  119. rm -f "lbversion"
  120. # we dont need that grub.elf now
  121. rm -f "grub.elf"
  122. # .config no longer needed
  123. rm -f ".config"
  124. # Add the background image
  125. if [ "$romtype" = "vesafb" ]
  126. then
  127. if [ "$1" = "macbook21" ] || [ "$1" = "x200_4mb" ] || [ "$1" = "x200_8mb" ] || [ "$1" = "x200_16mb" ] || [ "$1" = "r400_4mb" ] || [ "$1" = "r400_8mb" ] || [ "$1" = "r400_16mb" ] || [ "$1" = "t400_4mb" ] || [ "$1" = "t400_8mb" ] || [ "$1" = "t400_16mb" ] || [ "$1" = "t500_4mb" ] || [ "$1" = "t500_8mb" ] || [ "$1" = "t500_16mb" ] || [ "$1" = "w500_4mb" ] || [ "$1" = "w500_8mb" ] || [ "$1" = "w500_16mb" ]
  128. then
  129. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../../../resources/grub/background/background1280x800.png -n background.png -t raw
  130. else
  131. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../../../resources/grub/background/background1024x768.png -n background.png -t raw
  132. fi
  133. fi
  134. # Add the correct GRUB configuration file for this image.
  135. for keylayout in ../../../resources/utilities/grub-assemble/keymap/original/*
  136. do
  137. keymap="${keylayout##*/}"
  138. # copy the images based on the keymap
  139. cp "${boardtarget}_${romtype}.rom" "${boardtarget}_${keymap}_${romtype}.rom"
  140. # Insert grub config into the image
  141. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f ../../"grub_${keymap}_${romtype}.cfg" -n grub.cfg -t raw
  142. # Insert grub test config into the image (for the user to test modifications to before modifying the main one)
  143. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f ../../"grub_${keymap}_${romtype}_test.cfg" -n grubtest.cfg -t raw
  144. done
  145. # This config-less ROM is no longer needed
  146. rm -f "${boardtarget}_${romtype}.rom"
  147. done
  148. # Clean up and prepare bin/ containing all ROM images
  149. # move ROM images into the newly created directory
  150. rm -Rf "${boardtarget:?}/"
  151. mkdir "${boardtarget}/"
  152. mv "${boardtarget}"*.rom "${boardtarget}/"
  153. # delete old ROM images
  154. rm -Rf "../../../bin/grub/${boardtarget}/"
  155. # put new ROM images in ../bin/grub/
  156. [ -d "../../../bin/grub/" ] || mkdir -p "../../../bin/grub/"
  157. mv "${boardtarget}/" "../../../bin/grub/"
  158. # version info file no longer needed
  159. rm -f ".coreboot-version"
  160. git checkout master
  161. (
  162. cd "3rdparty/vboot/"
  163. git checkout master
  164. )
  165. )
  166. printf "\n\n"