roms_helper 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/bin/bash
  2. # helper script: create ROM images for a given system, with GRUB payload
  3. #
  4. # Copyright (C) 2020 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. # This script assumes that the working directory is the root
  20. # of git or release archive
  21. # TODO: add make -jWHATEVER to "make" command for coreboot
  22. # TODO: check if coreboot supports multi-core building in its build system
  23. [ "x${DEBUG+set}" = 'xset' ] && set -v
  24. set -u -e
  25. if (( $# != 1 )); then
  26. printf "Usage: ./build retroboot roms boardname\n"
  27. printf "Example: ./build retroboot roms x230_4mb\n"
  28. printf "You need to specify exactly 1 argument\n"
  29. exit 1
  30. fi
  31. board="${1}"
  32. if [ ! -d "resources/coreboot/${board}" ]; then
  33. printf "build/roms: Target %s does not exist in the retroboot build system. Skipping build.\n" "${board}"
  34. exit 1
  35. fi
  36. romdir_grub="bin/grub_${board}"
  37. romdir_seabios="bin/seabios_${board}"
  38. romdir_tianocore="bin/tianocore_${board}"
  39. cbdir="coreboot/${board}"
  40. cbfstool="${cbdir}/util/cbfstool/cbfstool"
  41. corebootrom="${cbdir}/build/coreboot.rom"
  42. seavgabiosrom="payload/seabios/seavgabios.bin"
  43. tianocoreelf="payload/tianocore/tianocore.elf"
  44. if [ ! -d "${cbdir}" ]; then
  45. ./download coreboot
  46. ./build module crossgcc
  47. ./build module cbutils
  48. ./download tianocore
  49. ./build payload tianocore
  50. fi
  51. if [ ! -d "${cbdir}/util/crossgcc/xgcc/" ]; then
  52. ./build module crossgcc
  53. fi
  54. romtype="normal"
  55. if [ -f "resources/coreboot/${board}/romtype" ]; then
  56. romtype="$(cat resources/coreboot/${board}/romtype)"
  57. fi
  58. if [ ! -f "${tianocoreelf}" ]; then
  59. ./build payload tianocore
  60. fi
  61. if [ ! -f "${seavgabiosrom}" ]; then
  62. ./build payload seabios
  63. fi
  64. [ -d "${romdir_grub}/" ] || mkdir -p "${romdir_grub}/"
  65. rm -f "${romdir_grub}"/* coreboot.tmp.grub.rom
  66. [ -d "${romdir_seabios}/" ] || mkdir -p "${romdir_seabios}/"
  67. rm -f "${romdir_seabios}"/* coreboot.tmp.seabios.rom
  68. [ -d "${romdir_tianocore}/" ] || mkdir -p "${romdir_tianocore}/"
  69. rm -f "${romdir_tianocore}"/* coreboot.tmp.tianocore.rom
  70. # it is assumed that no other work will be done on the ROM
  71. # after calling this function. therefore this function is "final"
  72. moverom() {
  73. rompath="$1"
  74. newrompath="$2"
  75. cuttype="$3"
  76. printf "\nCreating new ROM image: %s\n" "${newrompath}"
  77. if [ "${cuttype}" = "4MiB IFD BIOS region" ]; then
  78. dd if=${rompath} of=${newrompath} bs=1 skip=$[$(stat -c %s ${rompath}) - 0x400000] count=4194304
  79. else
  80. mv ${rompath} ${newrompath}
  81. fi
  82. for romsize in 4 8 16; do
  83. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOR flash" ]; then
  84. ./build descriptors ich9m
  85. dd if=descriptors/ich9m/ich9fdgbe_${romsize}m.bin of=${newrompath} bs=1 count=12k conv=notrunc
  86. fi
  87. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOGBE NOR flash" ]; then
  88. ./build descriptors ich9m
  89. dd if=descriptors/ich9m/ich9fdnogbe_${romsize}m.bin of=${newrompath} bs=1 count=4k conv=notrunc
  90. fi
  91. done
  92. if [ "${cuttype}" = "i945 laptop" ]; then
  93. dd if=${newrompath} of=top64k.bin bs=1 skip=$[$(stat -c %s ${newrompath}) - 0x10000] count=64k
  94. dd if=top64k.bin of=${newrompath} bs=1 seek=$[$(stat -c %s ${newrompath}) - 0x20000] count=64k conv=notrunc
  95. rm -f top64k.bin
  96. fi
  97. }
  98. for displaymode in vesafb txtmode; do
  99. for initmode in libgfxinit vgarom; do
  100. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  101. seabioself="payload/seabios/seabios_${initmode}.elf"
  102. if [ ! -f "${cbcfgpath}" ]; then
  103. printf "\nCoreboot config %s_%s for target %s does not exist in the build system. Skipping build.\n" \
  104. "${initmode}" "${displaymode}" "${board}"
  105. continue
  106. fi
  107. if [ ! -f "${cbfstool}" ]; then
  108. ./build module cbutils
  109. fi
  110. if [ ! -f "${seabioself}" ]; then
  111. ./build payload seabios
  112. fi
  113. (
  114. cd "${cbdir}"
  115. make distclean
  116. )
  117. cp "${cbcfgpath}" "${cbdir}"/.config
  118. (
  119. cd "${cbdir}"
  120. make
  121. )
  122. if [ "${displaymode}" = "txtmode" ]; then
  123. if [ ! -f "memtest86plus/memtest.bin" ]; then
  124. ./build module memtest86plus
  125. fi
  126. "${cbfstool}" "${corebootrom}" add-payload -f memtest86plus/memtest.bin -n img/memtest.bin -c lzma
  127. fi
  128. cp "${corebootrom}" coreboot.tmp.seabios.rom
  129. "${cbfstool}" coreboot.tmp.seabios.rom add-payload -f "${seabioself}" -n fallback/payload -c lzma
  130. "${cbfstool}" coreboot.tmp.seabios.rom add-int -i 3000 -n etc/ps2-keyboard-spinup
  131. if [ "${initmode}" = "libgfxinit" ]; then
  132. "${cbfstool}" coreboot.tmp.seabios.rom add -f "${seavgabiosrom}" -n vgaroms/seavgabios.bin -t raw
  133. fi
  134. newrompath="${romdir_seabios}/seabios_${board}_${initmode}_${displaymode}.rom"
  135. moverom "coreboot.tmp.seabios.rom" "${newrompath}" "${romtype}"
  136. # tianocore requires vesa framebuffer. will not work in text mode
  137. if [ "${displaymode}" = "vesafb" ] && \
  138. [ ! -f "resources/coreboot/${board}/x86_32" ]; then
  139. # do not include on 32-bit-only machines. this is 64-bit tianocore
  140. newrompath="${romdir_tianocore}/tianocore_${board}_${initmode}_${displaymode}.rom"
  141. cp "${corebootrom}" coreboot.tmp.tianocore.rom
  142. "${cbfstool}" coreboot.tmp.tianocore.rom add-payload -f ${tianocoreelf} -n fallback/payload -c lzma
  143. moverom "coreboot.tmp.tianocore.rom" "${newrompath}" "${romtype}"
  144. # also copy it to the generic ROM, which will have GRUB added
  145. "${cbfstool}" "${corebootrom}" add-payload -f ${tianocoreelf} -n tianocore.elf -c lzma
  146. fi
  147. "${cbfstool}" "${corebootrom}" add-payload -f "${seabioself}" -n seabios.elf -c lzma
  148. if [ "${initmode}" = "libgfxinit" ]; then
  149. "${cbfstool}" "${corebootrom}" add -f "${seavgabiosrom}" -n vgaroms/seavgabios.bin -t raw
  150. fi
  151. "${cbfstool}" "${corebootrom}" add-int -i 3000 -n etc/ps2-keyboard-spinup
  152. for keymapfile in resources/grub/keymap/original/*; do
  153. if [ ! -f "${keymapfile}" ]; then
  154. continue
  155. fi
  156. keymap="${keymapfile##*/}"
  157. grubelf="payload/grub/grub_${keymap}.elf"
  158. grubcfg="payload/grub/grub_${keymap}_${displaymode}.cfg"
  159. grubtestcfg="payload/grub/grub_${keymap}_${displaymode}_test.cfg"
  160. if [ ! -f "${grubelf}" ] || [ ! -f "${grubcfg}" ] \
  161. || [ ! -f "${grubtestcfg}" ]; then
  162. ./build payload grub
  163. fi
  164. cp "${corebootrom}" coreboot.tmp.grub.rom
  165. "${cbfstool}" coreboot.tmp.grub.rom add-payload -f "${grubelf}" -n fallback/payload -c lzma
  166. "${cbfstool}" coreboot.tmp.grub.rom add -f "${grubcfg}" -n grub.cfg -t raw
  167. "${cbfstool}" coreboot.tmp.grub.rom add -f "${grubtestcfg}" -n grubtest.cfg -t raw
  168. if [ "${displaymode}" = "vesafb" ]; then
  169. "${cbfstool}" coreboot.tmp.grub.rom add -f resources/grub/font/dejavusansmono.pf2 -n dejavusansmono.pf2 -t raw
  170. fi
  171. newrompath="${romdir_grub}/grub_${board}_${initmode}_${displaymode}_${keymap}.rom"
  172. moverom "coreboot.tmp.grub.rom" "${newrompath}" "${romtype}"
  173. done
  174. done
  175. done
  176. rm -f coreboot.tmp.{tianocore,seabios,grub}.rom
  177. printf "\nDone! Your ROMs are in bin/\n\n"