roms_helper 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. # pike2008 cards cause a system hang when loading the option rom in seabios
  259. # if there is an empty option rom in cbfs, no option rom will be loaded
  260. if [ "${cuttype}" = "d8d16sas" ]; then
  261. emptyrom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  262. rm -f "${emptyrom}"
  263. touch "${emptyrom}"
  264. for deviceID in "0072" "3050"; do
  265. "${cbfstool}" "${newrompath}" add -f "${emptyrom}" -n pci1000,${deviceID}.rom -t raw
  266. done
  267. rm -f "${emptyrom}"
  268. fi
  269. for romsize in 4 8 16; do
  270. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOR flash" ]; then
  271. if [ ! -f "descriptors/ich9m/ich9fdgbe_${romsize}m.bin" ]; then
  272. ./build descriptors ich9m
  273. fi
  274. dd if=descriptors/ich9m/ich9fdgbe_${romsize}m.bin of=${newrompath} bs=1 count=12k conv=notrunc
  275. fi
  276. if [ "${cuttype}" = "${romsize}MiB ICH9 IFD NOGBE NOR flash" ]; then
  277. if [ ! -f "descriptors/ich9m/ich9fdnogbe_${romsize}m.bin" ]; then
  278. ./build descriptors ich9m
  279. fi
  280. dd if=descriptors/ich9m/ich9fdnogbe_${romsize}m.bin of=${newrompath} bs=1 count=4k conv=notrunc
  281. fi
  282. done
  283. if [ "${cuttype}" = "i945 laptop" ]; then
  284. dd if=${newrompath} of=top64k.bin bs=1 skip=$[$(stat -c %s ${newrompath}) - 0x10000] count=64k
  285. dd if=top64k.bin of=${newrompath} bs=1 seek=$[$(stat -c %s ${newrompath}) - 0x20000] count=64k conv=notrunc
  286. rm -f top64k.bin
  287. fi
  288. }
  289. # expected: configs must not specify a payload
  290. mkCoreboot() {
  291. cbdir="${1}" # e.g. coreboot/default
  292. if ${deblobbed} ; then
  293. cbcfgpath="${2}_deblobbed"
  294. else
  295. cbcfgpath="${2}" # e.g. resources/coreboot/x200_8mb/config/libgfxinit_txtmode
  296. fi
  297. if [ ! -f "${cbcfgpath}" ]; then
  298. printf "\nmkCoreboot: Coreboot config '%s' does not exist. Skipping build.\n" \
  299. "${cbcfgpath}"
  300. return 0
  301. fi
  302. printf "%s-%s\n" "$(cat projectname)" "$(cat version)" > "${cbdir}/.coreboot-version"
  303. (
  304. if [ -f "${cbfstool}" ]; then
  305. mv "${cbfstool}" "${cbdir}/cbfstool"
  306. fi
  307. cd "${cbdir}"
  308. make distclean
  309. cd -
  310. if [ -f "${cbdir}/cbfstool" ]; then
  311. mv "${cbdir}/cbfstool" "${cbfstool}"
  312. fi
  313. )
  314. cp "${cbcfgpath}" "${cbdir}"/.config
  315. ./build module cbutils ${cbdir#coreboot/}
  316. (
  317. cd "${cbdir}"
  318. make -j$(nproc)
  319. )
  320. }
  321. # make a rom in /tmp/ and then print the path of that ROM
  322. make_seabios_rom() {
  323. target_cbrom="${1}" # rom to insert seabios in. this rom won't be touched
  324. # a tmpfile will be made instead
  325. target_seabios_cbfs_path="${2}" # e.g. fallback/payload
  326. target_opromloadonly="${3}" # 0 or 1. if 1, only load but don't execute oproms
  327. target_initmode="${4}" # e.g. libgfxinit
  328. if [ "${target_initmode}" = "normal" ]; then
  329. target_seabioself="payload/seabios/seabios_vgarom.elf"
  330. # if normal, etc/pci-optionrom-exec will be set to 2
  331. else
  332. target_seabioself="payload/seabios/seabios_${target_initmode}.elf"
  333. # if libgfxinit, etc/pci-optionrom-exec will be set to 2
  334. # if vgarom, etc/pci-optionrom-exec will be set to 0
  335. fi
  336. target_seavgabios_rom="payload/seabios/seavgabios.bin"
  337. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  338. cp "${target_cbrom}" "${tmprom}"
  339. "${cbfstool}" "${tmprom}" add-payload -f "${target_seabioself}" -n ${target_seabios_cbfs_path} -c lzma
  340. "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup
  341. if [ "${target_initmode}" = "normal" ] || [ "${target_initmode}" = "libgfxinit" ]; then
  342. "${cbfstool}" "${tmprom}" add-int -i 2 -n etc/pci-optionrom-exec
  343. elif [ "${target_initmode}" = "vgarom" ]; then
  344. "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/pci-optionrom-exec
  345. fi # for undefined modes, don't add this integer. rely on SeaBIOS defaults
  346. "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum
  347. "${cbfstool}" "${tmprom}" add-int -i ${target_opromloadonly} -n etc/only-load-option-roms
  348. if [ "${target_initmode}" = "libgfxinit" ]; then
  349. "${cbfstool}" "${tmprom}" add -f "${target_seavgabios_rom}" -n vgaroms/seavgabios.bin -t raw
  350. fi
  351. printf "%s\n" "${tmprom}"
  352. }
  353. # make a rom in /tmp/ and then print the path of that ROM
  354. make_uboot_payload_rom() {
  355. target_cbrom="${1}" # rom to insert u-boot in. this rom won't be touched
  356. # a tmpfile will be made instead
  357. target_uboot_cbfs_path="${2}" # e.g. fallback/payload
  358. target_uboot_config="${3}"
  359. cbfstool_path="${4}"
  360. if [ "${target_uboot_config}" = "default" ]; then
  361. target_ubootelf="payload/u-boot/${board}/u-boot.elf"
  362. else
  363. target_ubootelf="payload/u-boot/${board}/${target_uboot_config}/u-boot.elf"
  364. fi
  365. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  366. cp "${target_cbrom}" "${tmprom}"
  367. "${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" -n ${target_uboot_cbfs_path} -c lzma
  368. printf "%s\n" "${tmprom}"
  369. }
  370. # make a rom in /tmp/ and then print the path of that ROM
  371. make_grubrom_from_keymap() {
  372. target_keymap="${1}"
  373. target_cbrom="${2}"
  374. target_grubelf_cbfs_path="${3}" # e.g. fallback/payload
  375. grubelf="payload/grub/grub_${target_keymap}.elf"
  376. grubcfg="payload/grub/grub_${target_keymap}.cfg"
  377. grubtestcfg="payload/grub/grub_${target_keymap}_test.cfg"
  378. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  379. cp "${target_cbrom}" "${tmprom}"
  380. "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" -n ${target_grubelf_cbfs_path} -c lzma
  381. tmpgrubcfg=$(mktemp -t grub.cfg.XXXXXXXXXX)
  382. tmpgrubtestcfg=$(mktemp -t grubtest.cfg.XXXXXXXXXX)
  383. if [ "${grub_scan_disk}" = "ahci" ]; then
  384. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' "${grubcfg}" > "${tmpgrubcfg}"
  385. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ahci\"/' "${grubtestcfg}" > "${tmpgrubtestcfg}"
  386. elif [ "${grub_scan_disk}" = "ata" ]; then
  387. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' "${grubcfg}" > "${tmpgrubcfg}"
  388. sed 's/set\ grub_scan_disk=\"both\"/set\ grub_scan_disk=\"ata\"/' "${grubtestcfg}" > "${tmpgrubtestcfg}"
  389. else
  390. cp "${grubcfg}" "${tmpgrubcfg}"
  391. cp "${grubtestcfg}" "${tmpgrubtestcfg}"
  392. fi
  393. "${cbfstool}" "${tmprom}" add -f "${tmpgrubcfg}" -n grub.cfg -t raw
  394. "${cbfstool}" "${tmprom}" add -f "${tmpgrubtestcfg}" -n grubtest.cfg -t raw
  395. rm -f "${tmpgrubcfg}" "${tmpgrubtestcfg}"
  396. backgroundfile="background1280x800.png"
  397. if [ "${board}" = "x60" ] || [ "${board}" = "t60_intelgpu" ]; then
  398. # TODO: don't hardcode this check. do it in board.cfg per board
  399. backgroundfile="background1024x768.png"
  400. fi
  401. backgroundfile="resources/grub/background/${backgroundfile}"
  402. "${cbfstool}" "${tmprom}" add -f ${backgroundfile} -n background.png -t raw
  403. printf "%s\n" "${tmprom}"
  404. }
  405. # Make separate ROM images with GRUB payload, for each supported keymap
  406. mkRomsWithGrub() {
  407. tmprompath="${1}"
  408. initmode="${2}"
  409. displaymode="${3}"
  410. firstpayloadname="${4}" # allow values: grub, seabios, seabios_withgrub, seabios_grubfirst
  411. if [ "${payload_grub_withseabios}" = "y" ] && [ "${firstpayloadname}" = "grub" ]; then
  412. mv "$(make_seabios_rom "${tmprompath}" "seabios.elf" "${seabios_opromloadonly}" "${initmode}")" "${tmprompath}"
  413. elif [ "${payload_seabios_withgrub}" ] && [ "${firstpayloadname}" != "grub" ]; then
  414. mv "$(make_seabios_rom "${tmprompath}" "fallback/payload" "${seabios_opromloadonly}" "${initmode}")" "${tmprompath}"
  415. if [ "${firstpayloadname}" = "seabios_grubfirst" ]; then
  416. tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  417. printf "/rom@img/grub2\n" > "${tmpbootorder}"
  418. "${cbfstool}" "${tmprompath}" add -f "${tmpbootorder}" -n bootorder -t raw
  419. rm -f "${tmpbootorder}"
  420. "${cbfstool}" "${tmprompath}" add-int -i 0 -n etc/show-boot-menu
  421. fi
  422. fi
  423. keymaps=""
  424. if [ -z ${keyboard_layouts} ]; then
  425. keymaps="resources/grub/keymap/*"
  426. else
  427. for keymapname in ${keyboard_layouts}; do
  428. keymaps+="resources/grub/keymap/${keymapname}.gkb"
  429. done
  430. fi
  431. for keymapfile in ${keymaps}; do
  432. echo "keymaps is $keymaps, keymapfile is $keymapfile"
  433. if [ ! -f "${keymapfile}" ]; then
  434. continue
  435. fi
  436. keymap="${keymapfile##*/}"
  437. keymap="${keymap%.gkb}"
  438. grub_path_in_cbfs="fallback/payload"
  439. if [ "${firstpayloadname}" != "grub" ]; then
  440. grub_path_in_cbfs="img/grub2"
  441. fi
  442. tmpgrubrom="$(make_grubrom_from_keymap "${keymap}" "${tmprompath}" "${grub_path_in_cbfs}")"
  443. if [ "${initmode}" = "normal" ]; then
  444. newrompath="${romdir}/${firstpayloadname}_${board}_${initmode}_${keymap}.rom"
  445. else
  446. newrompath="${romdir}/${firstpayloadname}_${board}_${initmode}_${displaymode}_${keymap}.rom"
  447. fi
  448. moverom "${tmpgrubrom}" "${newrompath}" "${romtype}"
  449. rm -f "${tmpgrubrom}"
  450. done
  451. }
  452. # Main ROM building function. This calls all other functions
  453. mkRoms() {
  454. cbcfgpath="${1}"
  455. displaymode="${2}"
  456. initmode="${3}"
  457. if [ ! -f "${cbcfgpath}" ]; then
  458. printf "'%s' does not exist. Skipping build for %s %s %s\n" \
  459. "${cbcfgpath}" "${board}" "${displaymode}" "${initmode}"
  460. return 0
  461. fi
  462. mkCoreboot "${cbdir}" "${cbcfgpath}"
  463. if [ "${displaymode}" = "txtmode" ] && [ "${payload_memtest}" = "y" ]; then
  464. "${cbfstool}" "${corebootrom}" add-payload -f memtest86plus/memtest -n img/memtest -c lzma
  465. fi
  466. if [ "${payload_seabios}" = "y" ]; then
  467. if [ "${payload_seabios_withgrub}" = "n" ]; then
  468. tmpseabiosrom="$(make_seabios_rom "${corebootrom}" "fallback/payload" "${seabios_opromloadonly}" "${initmode}")"
  469. if [ "${initmode}" = "normal" ]; then
  470. newrompath="${romdir}/seabios_${board}_${initmode}.rom"
  471. else
  472. newrompath="${romdir}/seabios_${board}_${initmode}_${displaymode}.rom"
  473. fi
  474. moverom "${tmpseabiosrom}" "${newrompath}" "${romtype}"
  475. rm -f "${tmpseabiosrom}"
  476. else
  477. tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
  478. cp "${corebootrom}" "${tmprom}"
  479. mkRomsWithGrub "${tmprom}" "${initmode}" "${displaymode}" "seabios_withgrub"
  480. cp "${corebootrom}" "${tmprom}"
  481. mkRomsWithGrub "${tmprom}" "${initmode}" "${displaymode}" "seabios_grubfirst"
  482. rm -f "${tmprom}"
  483. fi
  484. fi
  485. if [ "${payload_grub}" = "y" ]; then
  486. mkRomsWithGrub "${corebootrom}" "${initmode}" "${displaymode}" "grub"
  487. fi
  488. if [ "${payload_uboot}" = "y" ]; then
  489. tmpubootrom="$(make_uboot_payload_rom "${corebootrom}" "fallback/payload" "${uboot_config}" "${cbfstool}")"
  490. if [ "${initmode}" = "normal" ]; then
  491. newrompath="${romdir}/uboot_payload_${board}_${initmode}.rom"
  492. else
  493. newrompath="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
  494. fi
  495. moverom "${tmpubootrom}" "${newrompath}" "${romtype}"
  496. rm -f "${tmpubootrom}"
  497. fi
  498. }
  499. if [ -z ${displaymodes} ]; then
  500. initmode="libgfxinit"
  501. for displaymode in corebootfb txtmode; do
  502. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  503. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  504. done
  505. initmode="vgarom"
  506. for displaymode in vesafb txtmode; do
  507. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  508. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  509. done
  510. initmode="normal"
  511. displaymode="txtmode"
  512. cbcfgpath="resources/coreboot/${board}/config/${initmode}"
  513. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  514. else
  515. echo "special displaymode defined as $displaymodes"
  516. initmode="libgfxinit"
  517. for displaymode in ${displaymodes}; do
  518. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  519. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  520. done
  521. initmode="vgarom"
  522. for displaymode in ${displaymodes}; do
  523. cbcfgpath="resources/coreboot/${board}/config/${initmode}_${displaymode}"
  524. mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
  525. done
  526. fi
  527. (
  528. cd "${cbdir}"
  529. make distclean
  530. )