roms_helper 19 KB

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