rom.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Copyright (c) 2014-2016,2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
  4. # Copyright (c) 2021-2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  5. # Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  6. # Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com>
  7. # Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
  8. mkserprog()
  9. {
  10. [ "$_f" = "-d" ] && return 0 # dry run
  11. basename -as .h "$serdir/"*.h > "$TMPDIR/ser" || $err "!mk $1 $TMPDIR"
  12. while read -r sertarget; do
  13. [ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$sertarget" \
  14. -DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc" \
  15. && x_ cmake --build "$sersrc/build"
  16. [ "$1" = "stm32" ] && x_ make -C "$sersrc" \
  17. libopencm3-just-make BOARD=$sertarget && x_ make -C \
  18. "$sersrc" BOARD=$sertarget; x_ mkdir -p "bin/serprog_$1"
  19. x_ mv "$serx" "bin/serprog_$1/serprog_$sertarget.${serx##*.}"
  20. done < "$TMPDIR/ser"
  21. [ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/serprog_$1"; return 0
  22. }
  23. mkpayload_grub()
  24. {
  25. eval `setvars "" grub_modules grub_install_modules`
  26. $dry eval `setcfg "$grubdata/module/$tree"`
  27. $dry x_ rm -f "$srcdir/grub.elf"
  28. $dry "$srcdir/grub-mkstandalone" --grub-mkimage="$srcdir/grub-mkimage" \
  29. -O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \
  30. --fonts= --themes= --locales= --modules="$grub_modules" \
  31. --install-modules="$grub_install_modules" \
  32. "/boot/grub/grub_default.cfg=${srcdir}/.config" \
  33. "/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
  34. "/background.png=$grubdata/background/background1280x800.png" || \
  35. $err "$tree: cannot build grub.elf"; return 0
  36. }
  37. mkvendorfiles()
  38. {
  39. check_coreboot_utils "$tree"
  40. printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
  41. $err "!mk $srcdir .coreboot-version"
  42. [ -z "$mode" ] && [ "$target" != "$tree" ] && \
  43. x_ ./vendor download $target; return 0
  44. }
  45. check_coreboot_utils()
  46. {
  47. for util in cbfstool ifdtool; do
  48. [ "$badhash" = "n" ] || rm -f "elf/$util/$1/$util" || \
  49. $err "!rm badelf elf/$util/$1/$util"
  50. e "elf/$util/$1/$util" f && continue
  51. utilelfdir="elf/$util/$1"
  52. utilsrcdir="src/coreboot/$1/util/$util"
  53. utilmode="" && [ -n "$mode" ] && utilmode="clean"
  54. x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
  55. [ -z "$mode" ] && [ ! -f "$utilelfdir/$util" ] && \
  56. x_ mkdir -p "$utilelfdir" && \
  57. x_ cp "$utilsrcdir/$util" "elf/$util/$1"
  58. [ -z "$mode" ] || x_ rm -Rf "$utilelfdir"; continue
  59. done; return 0
  60. }
  61. mkcorebootbin()
  62. {
  63. [ "$target" = "$tree" ] && return 0
  64. tmprom="$srcdir/build/coreboot.rom"
  65. initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
  66. initmode="${initmode%%_*}"
  67. [ -n "$displaymode" ] && displaymode="_$displaymode"
  68. cbfstool="elf/cbfstool/$tree/cbfstool"
  69. [ -n "$uboot_config" ] || uboot_config="default"
  70. [ "$payload_uboot" = "y" ] || payload_seabios="y"
  71. [ "$payload_grub" = "y" ] && payload_seabios="y"
  72. [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
  73. $dry $err "$target: U-Boot and SeaBIOS/GRUB are both enabled."
  74. [ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
  75. [ -n "$grubtree" ] || grubtree="default"
  76. grubelf="elf/grub/$grubtree/payload/grub.elf"
  77. [ "$payload_memtest" = "y" ] || payload_memtest="n"
  78. [ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
  79. if grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then
  80. [ "$payload_seabios" = "y" ] && pname="seabios" && \
  81. $dry add_seabios
  82. [ "$payload_uboot" = "y" ] && pname="uboot" && $dry add_uboot
  83. else
  84. pname="custom" # coreboot's build system added payloads
  85. fi
  86. newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
  87. $dry x_ mkdir -p "${newrom%/*}"; $dry x_ mv "$tmprom" "$newrom"
  88. [ "$XBMK_RELEASE" = "y" ] || return 0
  89. $dry mksha512sum "$newrom" "vendorhashes"; $dry ./vendor inject \
  90. -r "$newrom" -b "$target" -n nuke || $err "!nuke $newrom"
  91. }
  92. add_seabios()
  93. {
  94. _seabioself="elf/seabios/default/$initmode/bios.bin.elf"
  95. cbfs "$tmprom" "$_seabioself" "fallback/payload"
  96. x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
  97. _z="2"; [ "$initmode" = "vgarom" ] && _z="0"
  98. x_ "$cbfstool" "$tmprom" add-int -i $_z -n etc/pci-optionrom-exec
  99. x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
  100. [ "$initmode" = "libgfxinit" ] && \
  101. cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw
  102. [ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
  103. "elf/memtest86plus/memtest.bin" img/memtest
  104. [ "$payload_grub" = "y" ] && pname="seagrub" && add_grub; return 0
  105. }
  106. add_grub()
  107. {
  108. cbfs "$tmprom" "$grubelf" "img/grub2"
  109. printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
  110. > "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
  111. cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
  112. cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
  113. }
  114. add_uboot()
  115. {
  116. ubdir="elf/u-boot/$target/$uboot_config"
  117. ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
  118. ubootelf="$ubdir/u-boot"
  119. [ -f "$ubootelf" ] || $err "cb/$target: Can't find u-boot"
  120. cbfs "$tmprom" "$ubootelf" "fallback/payload"
  121. }
  122. mkcoreboottar()
  123. {
  124. [ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
  125. [ "$release" != "n" ] && $dry mkrom_tarball "bin/$target"; return 0
  126. }