roms_helper 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. #!/usr/bin/env bash
  2. # helper script: create ROM images for a given mainboard
  3. #
  4. # Copyright (C) 2020,2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2021 Vitali64 <vitali64pmemail@protonmail.com>
  6. # Copyright (C) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  7. # Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # This script assumes that the working directory is the root
  23. # of git or release archive
  24. [ "x${DEBUG+set}" = 'xset' ] && set -v
  25. set -u -e
  26. projectname="$(cat projectname)"
  27. if [ "${1}" = "deblobbed" ]; then
  28. deblobbed=true
  29. shift
  30. else
  31. deblobbed=false
  32. fi
  33. displaymodes=""
  34. payloads=""
  35. keyboard_layouts=""
  36. while [[ $# > 0 ]]; do
  37. case ${1} in
  38. -d)
  39. displaymodes+="${2}"
  40. shift ;;
  41. -p)
  42. payloads+="${2}"
  43. shift ;;
  44. -k)
  45. keyboard_layouts+="${2}"
  46. shift ;;
  47. *)
  48. board=${1} ;;
  49. esac
  50. shift
  51. done
  52. echo "board is $board , kb is ${keyboard_layouts} , displaymode is ${displaymodes} , payloads is ${payloads}"
  53. if [ ! -d "resources/coreboot/${board}" ]; then
  54. printf "build/roms: Target %s does not exist in the %s build system. Skipping build.\n" "${projectname}" "${board}"
  55. exit 1
  56. fi
  57. if [ ! -f "resources/coreboot/${board}/board.cfg" ]; then
  58. printf "build/roms: Target %s does not have a board.cfg. Skipping build.\n" "${board}"
  59. exit 1
  60. fi
  61. # Workaround to grub's slow boot
  62. grub_scan_disk="undefined" # both: scan ata and ahci (slow), there is ata and ahci too
  63. # as an option
  64. cbtree="undefined"
  65. romtype="normal" # optional parameter in board.cfg. "normal" is default
  66. arch="undefined"
  67. # Disable all payloads by default.
  68. # board.cfg files have to specifically enable [a] payload(s)
  69. payload_grub="n"
  70. payload_grub_withseabios="n" # seabios chainloaded from grub
  71. payload_seabios="n"
  72. payload_seabios_withgrub="n" # i386-coreboot grub accessible from SeaBIOS boot menu
  73. seabios_opromloadonly="0"
  74. payload_memtest="n"
  75. payload_uboot="n"
  76. uboot_config="undefined"
  77. # Override the above defaults using board.cfg
  78. source "resources/coreboot/${board}/board.cfg"
  79. if [ "${grub_scan_disk}" = "undefined" ]; then
  80. printf "build/roms: Target %s does not define grub_scan_disk. Defaulting to 'both'.\n" "${board}"
  81. grub_scan_disk="both"
  82. fi
  83. if [ "${grub_scan_disk}" != "both" ] && \
  84. [ "${grub_scan_disk}" != "ata" ] && \
  85. [ "${grub_scan_disk}" != "ahci" ]; then
  86. printf "build/roms: Target %s defines an invalid grub_scan_disk setting. Defaulting to 'both'.\n" "${board}"
  87. grub_scan_disk="both"
  88. # erroring out would be silly. just use the default
  89. fi
  90. if [ "${cbtree}" = "undefined" ]; then
  91. printf "build/roms: Target %s does not define a coreboot tree. Skipping build.\n" "${board}"
  92. exit 1
  93. fi
  94. if [ "${arch}" = "undefined" ]; then
  95. printf "build/roms: Target %s does not define a CPU type. Skipping build.\n" "${board}"
  96. exit 1
  97. fi
  98. if [ "${seabios_opromloadonly}" != "0" ] && \
  99. [ "${seabios_opromloadonly}" != "1" ]; then
  100. seabios_opromloadonly="0"
  101. fi
  102. if [ "${payload_memtest}" != "n" ] && \
  103. [ "${payload_memtest}" != "y" ]; then
  104. payload_memtest="n"
  105. fi
  106. if [ "${payload_grub_withseabios}" = "y" ]; then
  107. payload_grub="y"
  108. fi
  109. if [ "${payload_grub_withseabios}" = "y" ]; then
  110. payload_seabios="y"
  111. payload_seabios_withgrub="y" # if grub-first works, then seabios-with-grub will also work
  112. fi
  113. if [ "${payload_seabios_withgrub}" = "y" ]; then
  114. payload_seabios="y" # if seabios-with-grub works, then SeaBIOS-alone should also work
  115. fi
  116. # NOTE: reverse logic must not be applied. If SeaBIOS-with-GRUB works, that doesn't
  117. # necessarily mean GRUB-with-SeaBIOS will work nicely. for example, the board might
  118. # only have an add-on GPU available, where it's recommended to boot SeaBIOS first
  119. if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] && [ "${payload_uboot}" != "y" ]; then
  120. while true; do
  121. for configfile in "resources/coreboot/${board}/config/"*; do
  122. if [ -f "${configfile}" ]; then
  123. printf "ERROR build/roms: Target '%s' does not define a payload. Exiting.\n" "${board}"
  124. exit 1
  125. fi
  126. done
  127. break
  128. done
  129. fi
  130. if [ "${payload_uboot}" != "n" ] && \
  131. [ "${payload_uboot}" != "y" ]; then
  132. payload_uboot="n"
  133. fi
  134. if [ "${payload_uboot}" = "y" ] && \
  135. [ "${uboot_config}" = "undefined" ]; then
  136. uboot_config="default"
  137. fi
  138. if [ "${payload_memtest}" = "y" ]; then
  139. if [ ! -f "memtest86plus/memtest" ]; then
  140. ./build module memtest86plus
  141. fi
  142. fi
  143. # Override all payload directives with cmdline args
  144. if [ ! -z ${payloads} ]; then
  145. echo "setting payloads $payloads"
  146. payload_grub="n"
  147. payload_grub_withseabios="n" # seabios chainloaded from grub
  148. payload_seabios="n"
  149. payload_seabios_withgrub="n" # i386-coreboot grub accessible from SeaBIOS boot menu
  150. seabios_opromloadonly="0"
  151. payload_memtest="n"
  152. for payload in ${payloads} ; do
  153. eval "payload_${payload}=y"
  154. done
  155. fi
  156. romdir="bin/${board}"
  157. cbdir="coreboot/${board}"
  158. if [ "${board}" != "${cbtree}" ]; then
  159. cbdir="coreboot/${cbtree}"
  160. fi
  161. cbfstool="${cbdir}/util/cbfstool/cbfstool"
  162. corebootrom="${cbdir}/build/coreboot.rom"
  163. seavgabiosrom="payload/seabios/seavgabios.bin"
  164. if [ ! -d "${cbdir}" ]; then
  165. ./download coreboot ${cbtree}
  166. fi
  167. if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
  168. if [ ! -d "${cbdir}/util/crossgcc/xgcc/i386-elf/" ]; then
  169. (
  170. cat version > "${cbdir}/.coreboot-version"
  171. cd "${cbdir}"
  172. make crossgcc-i386 CPUS=$(nproc) # even for 64-bit machines, coreboot builds
  173. # 32-bit ROM images, so we only need to worry about i386-elf
  174. )
  175. fi
  176. elif [ "${arch}" = "ARMv7" ]; then
  177. (
  178. cat version > "${cbdir}/.coreboot-version"
  179. cd "${cbdir}"
  180. make crossgcc-arm CPUS=$(nproc) # This is for armv7, doesn't apply to aarch64
  181. )
  182. elif [ "${arch}" = "AArch64" ]; then
  183. (
  184. cat version > "${cbdir}/.coreboot-version"
  185. cd "${cbdir}"
  186. make crossgcc-arm crossgcc-aarch64 CPUS=$(nproc) # This is for aarch64, doesn't apply to armv7
  187. )
  188. fi
  189. if [ ! -f "${cbfstool}" ]; then
  190. ./build module cbutils ${cbtree}
  191. fi
  192. if [ ! -f "${seavgabiosrom}" ] \
  193. || [ ! -f payload/seabios/seabios_libgfxinit.elf ] \
  194. || [ ! -f payload/seabios/seabios_vgarom.elf ]; then
  195. if [ "${payload_seabios}" = "y" ]; then
  196. ./build payload seabios
  197. elif [ "${payload_grub}" = "y" ] \
  198. && [ "${payload_grub_withseabios}" = "y" ]; then
  199. ./build payload seabios
  200. fi
  201. fi
  202. [ -d "${romdir}/" ] || mkdir -p "${romdir}/"
  203. rm -f "${romdir}"/*
  204. if [ "${payload_grub}" = "y" ] || [ "${payload_seabios_withgrub}" = "y" ]; then
  205. if [ -f "payload/grub/grub_usqwerty.cfg" ]; then
  206. grubrefchecksum="$(sha1sum resources/grub/config/grub.cfg)"
  207. grubrefchecksum="${grubrefchecksum% resources/grub/config/grub.cfg}"
  208. grubbuildchecksum="$(sha1sum payload/grub/grub_usqwerty.cfg)"
  209. grubbuildchecksum="${grubbuildchecksum% payload/grub/grub_usqwerty.cfg}"
  210. if [ "${grubrefchecksum}" != "${grubbuildchecksum}" ]; then
  211. rm -Rf payload/grub/
  212. printf "Changes detected to GRUB. Re-building now:\n"
  213. fi
  214. else
  215. printf "Required GRUB payloads not yet built. Building now:\n"
  216. rm -Rf payload/grub/ # just in case
  217. fi
  218. for keymapfile in resources/grub/keymap/*; do
  219. if [ ! -f "${keymapfile}" ]; then
  220. continue
  221. fi
  222. keymap="${keymapfile##*/}"
  223. keymap="${keymap%.gkb}"
  224. grubelf="payload/grub/grub_${keymap}.elf"
  225. grubcfg="payload/grub/grub_${keymap}.cfg"
  226. grubtestcfg="payload/grub/grub_${keymap}_test.cfg"
  227. if [ ! -f "${grubelf}" ] || [ ! -f "${grubcfg}" ] || \
  228. [ ! -f "${grubtestcfg}" ]; then
  229. ./build payload grub
  230. fi
  231. done
  232. fi
  233. if [ "${payload_uboot}" = "y" ]; then
  234. if [ "${uboot_config}" = "default" ] && \
  235. [ -f "payload/u-boot/${board}/u-boot.elf" ]; then
  236. ubootelf="payload/u-boot/${board}/u-boot.elf"
  237. else
  238. ubootelf="payload/u-boot/${board}/${uboot_config}/u-boot.elf"
  239. fi
  240. if [ ! -f "${ubootelf}" ]; then
  241. printf "Required U-Boot payloads not yet built. Building now:\n"
  242. rm -Rf "payload/u-boot/${board}" # just in case
  243. ./build payload u-boot "${board}"
  244. fi
  245. fi
  246. # it is assumed that no other work will be done on the ROM
  247. # after calling this function. therefore this function is "final"
  248. moverom() {
  249. rompath="$1"
  250. newrompath="$2"
  251. cuttype="$3"
  252. printf "\nCreating new ROM image: %s\n" "${newrompath}"
  253. if [ "${cuttype}" = "4MiB IFD BIOS region" ]; then
  254. dd if=${rompath} of=${newrompath} bs=1 skip=$[$(stat -c %s ${rompath}) - 0x400000] count=4194304
  255. else
  256. cp ${rompath} ${newrompath}
  257. fi
  258. for romsize in 4 8 16; do
  259. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOR flash" ]; then
  260. if [ ! -f "descriptors/ich9m/ich9fdgbe_${romsize}m.bin" ]; then
  261. ./build descriptors ich9m
  262. fi
  263. dd if=descriptors/ich9m/ich9fdgbe_${romsize}m.bin of=${newrompath} bs=1 count=12k conv=notrunc
  264. fi
  265. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOGBE NOR flash" ]; then
  266. if [ ! -f "descriptors/ich9m/ich9fdnogbe_${romsize}m.bin" ]; then
  267. ./build descriptors ich9m
  268. fi
  269. dd if=descriptors/ich9m/ich9fdnogbe_${romsize}m.bin of=${newrompath} bs=1 count=4k conv=notrunc
  270. fi
  271. done
  272. if [ "${cuttype}" = "i945 laptop" ]; then
  273. dd if=${newrompath} of=top64k.bin bs=1 skip=$[$(stat -c %s ${newrompath}) - 0x10000] count=64k
  274. dd if=top64k.bin of=${newrompath} bs=1 seek=$[$(stat -c %s ${newrompath}) - 0x20000] count=64k conv=notrunc
  275. rm -f top64k.bin
  276. fi
  277. }
  278. # expected: configs must not specify a payload
  279. mkCoreboot() {
  280. cbdir="${1}" # e.g. coreboot/default
  281. if ${deblobbed} ; then
  282. cbcfgpath="${2}_deblobbed"
  283. else
  284. cbcfgpath="${2}" # e.g. resources/coreboot/x200_8mb/config/libgfxinit_txtmode
  285. fi
  286. if [ ! -f "${cbcfgpath}" ]; then
  287. printf "\nmkCoreboot: Coreboot config '%s' does not exist. Skipping build.\n" \
  288. "${cbcfgpath}"
  289. return 0
  290. fi
  291. printf "%s-%s\n" "$(cat projectname)" "$(cat version)" > "${cbdir}/.coreboot-version"
  292. (
  293. if [ -f "${cbfstool}" ]; then
  294. mv "${cbfstool}" "${cbdir}/cbfstool"
  295. fi
  296. cd "${cbdir}"
  297. make distclean
  298. cd -
  299. if [ -f "${cbdir}/cbfstool" ]; then
  300. mv "${cbdir}/cbfstool" "${cbfstool}"
  301. fi
  302. )
  303. cp "${cbcfgpath}" "${cbdir}"/.config
  304. ./build module cbutils ${cbdir#coreboot/}
  305. (
  306. cd "${cbdir}"
  307. make -j$(nproc)
  308. )
  309. }
  310. # make a rom in /tmp/ and then print the path of that ROM
  311. make_seabios_rom() {
  312. target_cbrom="${1}" # rom to insert seabios in. this rom won't be touched
  313. # a tmpfile will be made instead
  314. target_seabios_cbfs_path="${2}" # e.g. fallback/payload
  315. target_opromloadonly="${3}" # 0 or 1. if 1, only load but don't execute oproms
  316. target_initmode="${4}" # e.g. libgfxinit
  317. if [ "${target_initmode}" = "normal" ]; then
  318. target_seabioself="payload/seabios/seabios_vgarom.elf"
  319. # if normal, etc/pci-optionrom-exec will be set to 2
  320. else
  321. target_seabioself="payload/seabios/seabios_${target_initmode}.elf"
  322. # if libgfxinit, etc/pci-optionrom-exec will be set to 2
  323. # if vgarom, etc/pci-optionrom-exec will be set to 0
  324. fi
  325. target_seavgabios_rom="payload/seabios/seavgabios.bin"
  326. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  327. cp "${target_cbrom}" "${tmprom}"
  328. "${cbfstool}" "${tmprom}" add-payload -f "${target_seabioself}" -n ${target_seabios_cbfs_path} -c lzma
  329. "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup
  330. if [ "${target_initmode}" = "normal" ] || [ "${target_initmode}" = "libgfxinit" ]; then
  331. "${cbfstool}" "${tmprom}" add-int -i 2 -n etc/pci-optionrom-exec
  332. elif [ "${target_initmode}" = "vgarom" ]; then
  333. "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/pci-optionrom-exec
  334. fi # for undefined modes, don't add this integer. rely on SeaBIOS defaults
  335. "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum
  336. "${cbfstool}" "${tmprom}" add-int -i ${target_opromloadonly} -n etc/only-load-option-roms
  337. if [ "${target_initmode}" = "libgfxinit" ]; then
  338. "${cbfstool}" "${tmprom}" add -f "${target_seavgabios_rom}" -n vgaroms/seavgabios.bin -t raw
  339. fi
  340. printf "%s\n" "${tmprom}"
  341. }
  342. # make a rom in /tmp/ and then print the path of that ROM
  343. make_uboot_payload_rom() {
  344. target_cbrom="${1}" # rom to insert u-boot in. this rom won't be touched
  345. # a tmpfile will be made instead
  346. target_uboot_cbfs_path="${2}" # e.g. fallback/payload
  347. target_uboot_config="${3}"
  348. cbfstool_path="${4}"
  349. if [ "${target_uboot_config}" = "default" ]; then
  350. target_ubootelf="payload/u-boot/${board}/u-boot.elf"
  351. else
  352. target_ubootelf="payload/u-boot/${board}/${target_uboot_config}/u-boot.elf"
  353. fi
  354. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  355. cp "${target_cbrom}" "${tmprom}"
  356. "${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" -n ${target_uboot_cbfs_path} -c lzma
  357. printf "%s\n" "${tmprom}"
  358. }
  359. # make a rom in /tmp/ and then print the path of that ROM
  360. make_grubrom_from_keymap() {
  361. target_keymap="${1}"
  362. target_cbrom="${2}"
  363. target_grubelf_cbfs_path="${3}" # e.g. fallback/payload
  364. grubelf="payload/grub/grub_${target_keymap}.elf"
  365. grubcfg="payload/grub/grub_${target_keymap}.cfg"
  366. grubtestcfg="payload/grub/grub_${target_keymap}_test.cfg"
  367. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  368. cp "${target_cbrom}" "${tmprom}"
  369. "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" -n ${target_grubelf_cbfs_path} -c lzma
  370. tmpgrubcfg=$(mktemp -t grub.cfg.XXXXXXXXXX)
  371. tmpgrubtestcfg=$(mktemp -t grubtest.cfg.XXXXXXXXXX)
  372. if [ "${grub_scan_disk}" = "ahci" ]; then
  373. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' "${grubcfg}" > "${tmpgrubcfg}"
  374. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' "${grubtestcfg}" > "${tmpgrubtestcfg}"
  375. elif [ "${grub_scan_disk}" = "ata" ]; then
  376. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' "${grubcfg}" > "${tmpgrubcfg}"
  377. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' "${grubtestcfg}" > "${tmpgrubtestcfg}"
  378. else
  379. cp "${grubcfg}" "${tmpgrubcfg}"
  380. cp "${grubtestcfg}" "${tmpgrubtestcfg}"
  381. fi
  382. "${cbfstool}" "${tmprom}" add -f "${tmpgrubcfg}" -n grub.cfg -t raw
  383. "${cbfstool}" "${tmprom}" add -f "${tmpgrubtestcfg}" -n grubtest.cfg -t raw
  384. rm -f "${tmpgrubcfg}" "${tmpgrubtestcfg}"
  385. backgroundfile="background1280x800.png"
  386. if [ "${board}" = "x60" ] || [ "${board}" = "t60_intelgpu" ]; then
  387. # TODO: don't hardcode this check. do it in board.cfg per board
  388. backgroundfile="background1024x768.png"
  389. fi
  390. backgroundfile="resources/grub/background/${backgroundfile}"
  391. "${cbfstool}" "${tmprom}" add -f ${backgroundfile} -n background.png -t raw
  392. printf "%s\n" "${tmprom}"
  393. }
  394. # Make separate ROM images with GRUB payload, for each supported keymap
  395. mkRomsWithGrub() {
  396. tmprompath="${1}"
  397. initmode="${2}"
  398. displaymode="${3}"
  399. firstpayloadname="${4}" # allow values: grub, seabios, seabios_withgrub, seabios_grubfirst
  400. if [ "${payload_grub_withseabios}" = "y" ] && [ "${firstpayloadname}" = "grub" ]; then
  401. mv "$(make_seabios_rom "${tmprompath}" "seabios.elf" "${seabios_opromloadonly}" "${initmode}")" "${tmprompath}"
  402. elif [ "${payload_seabios_withgrub}" ] && [ "${firstpayloadname}" != "grub" ]; then
  403. mv "$(make_seabios_rom "${tmprompath}" "fallback/payload" "${seabios_opromloadonly}" "${initmode}")" "${tmprompath}"
  404. if [ "${firstpayloadname}" = "seabios_grubfirst" ]; then
  405. tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  406. printf "/rom@img/grub2\n" > "${tmpbootorder}"
  407. "${cbfstool}" "${tmprompath}" add -f "${tmpbootorder}" -n bootorder -t raw
  408. rm -f "${tmpbootorder}"
  409. "${cbfstool}" "${tmprompath}" add-int -i 0 -n etc/show-boot-menu
  410. fi
  411. fi
  412. keymaps=""
  413. if [ -z ${keyboard_layouts} ]; then
  414. keymaps="resources/grub/keymap/*"
  415. else
  416. for keymapname in ${keyboard_layouts}; do
  417. keymaps+="resources/grub/keymap/${keymapname}.gkb"
  418. done
  419. fi
  420. for keymapfile in ${keymaps}; do
  421. echo "keymaps is $keymaps, keymapfile is $keymapfile"
  422. if [ ! -f "${keymapfile}" ]; then
  423. continue
  424. fi
  425. keymap="${keymapfile##*/}"
  426. keymap="${keymap%.gkb}"
  427. grub_path_in_cbfs="fallback/payload"
  428. if [ "${firstpayloadname}" != "grub" ]; then
  429. grub_path_in_cbfs="img/grub2"
  430. fi
  431. tmpgrubrom="$(make_grubrom_from_keymap "${keymap}" "${tmprompath}" "${grub_path_in_cbfs}")"
  432. if [ "${initmode}" = "normal" ]; then
  433. newrompath="${romdir}/${firstpayloadname}_${board}_${initmode}_${keymap}.rom"
  434. else
  435. newrompath="${romdir}/${firstpayloadname}_${board}_${initmode}_${displaymode}_${keymap}.rom"
  436. fi
  437. moverom "${tmpgrubrom}" "${newrompath}" "${romtype}"
  438. rm -f "${tmpgrubrom}"
  439. done
  440. }
  441. # Main ROM building function. This calls all other functions
  442. mkRoms() {
  443. cbcfgpath="${1}"
  444. displaymode="${2}"
  445. initmode="${3}"
  446. if [ ! -f "${cbcfgpath}" ]; then
  447. printf "'%s' does not exist. Skipping build for %s %s %s\n" \
  448. "${cbcfgpath}" "${board}" "${displaymode}" "${initmode}"
  449. return 0
  450. fi
  451. mkCoreboot "${cbdir}" "${cbcfgpath}"
  452. if [ "${displaymode}" = "txtmode" ] && [ "${payload_memtest}" = "y" ]; then
  453. "${cbfstool}" "${corebootrom}" add-payload -f memtest86plus/memtest -n img/memtest -c lzma
  454. fi
  455. if [ "${payload_seabios}" = "y" ]; then
  456. if [ "${payload_seabios_withgrub}" = "n" ]; then
  457. tmpseabiosrom="$(make_seabios_rom "${corebootrom}" "fallback/payload" "${seabios_opromloadonly}" "${initmode}")"
  458. if [ "${initmode}" = "normal" ]; then
  459. newrompath="${romdir}/seabios_${board}_${initmode}.rom"
  460. else
  461. newrompath="${romdir}/seabios_${board}_${initmode}_${displaymode}.rom"
  462. fi
  463. moverom "${tmpseabiosrom}" "${newrompath}" "${romtype}"
  464. rm -f "${tmpseabiosrom}"
  465. else
  466. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  467. cp "${corebootrom}" "${tmprom}"
  468. mkRomsWithGrub "${tmprom}" "${initmode}" "${displaymode}" "seabios_withgrub"
  469. cp "${corebootrom}" "${tmprom}"
  470. mkRomsWithGrub "${tmprom}" "${initmode}" "${displaymode}" "seabios_grubfirst"
  471. rm -f "${tmprom}"
  472. fi
  473. fi
  474. if [ "${payload_grub}" = "y" ]; then
  475. mkRomsWithGrub "${corebootrom}" "${initmode}" "${displaymode}" "grub"
  476. fi
  477. if [ "${payload_uboot}" = "y" ]; then
  478. tmpubootrom="$(make_uboot_payload_rom "${corebootrom}" "fallback/payload" "${uboot_config}" "${cbfstool}")"
  479. if [ "${initmode}" = "normal" ]; then
  480. newrompath="${romdir}/uboot_payload_${board}_${initmode}.rom"
  481. else
  482. newrompath="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
  483. fi
  484. moverom "${tmpubootrom}" "${newrompath}" "${romtype}"
  485. rm -f "${tmpubootrom}"
  486. fi
  487. }
  488. if [ -z ${displaymodes} ]; then
  489. initmode="libgfxinit"
  490. for displaymode in corebootfb txtmode; do
  491. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  492. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  493. done
  494. initmode="vgarom"
  495. for displaymode in vesafb txtmode; do
  496. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  497. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  498. done
  499. initmode="normal"
  500. displaymode="txtmode"
  501. cbcfgpath="resources/coreboot/${board}/config/${initmode}"
  502. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  503. else
  504. echo "special displaymode defined as $displaymodes"
  505. initmode="libgfxinit"
  506. for displaymode in ${displaymodes}; do
  507. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  508. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  509. done
  510. initmode="vgarom"
  511. for displaymode in ${displaymodes}; do
  512. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  513. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  514. done
  515. fi
  516. (
  517. cd "${cbdir}"
  518. make distclean
  519. )