rom.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. copyps1bios()
  24. {
  25. x_ rm -Rf bin/playstation
  26. x_ mkdir -p bin/playstation
  27. x_ cp src/pcsx-redux/src/mips/openbios/openbios.bin bin/playstation
  28. printf "MIT License\n\nCopyright (c) 2019-2024 PCSX-Redux authors\n\n" \
  29. > bin/playstation/COPYING.txt || $err "!pcsx-redux copyright"
  30. cat config/snippet/mit >>bin/playstation/COPYING.txt || $err "!pcsx MIT"
  31. }
  32. mkpayload_grub()
  33. {
  34. eval `setvars "" grub_modules grub_install_modules`
  35. $dry eval `setcfg "$grubdata/module/$tree"`
  36. $dry x_ rm -f "$srcdir/grub.elf"; $dry \
  37. "$srcdir/grub-mkstandalone" --grub-mkimage="$srcdir/grub-mkimage" \
  38. -O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \
  39. --fonts= --themes= --locales= --modules="$grub_modules" \
  40. --install-modules="$grub_install_modules" \
  41. "/boot/grub/grub_default.cfg=${srcdir}/.config" \
  42. "/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
  43. "/background.png=$grubdata/background/background1280x800.png" || \
  44. $err "$tree: cannot build grub.elf"; return 0
  45. }
  46. mkvendorfiles()
  47. {
  48. [ -z "$mode" ] && $dry cook_coreboot_config
  49. check_coreboot_utils "$tree"
  50. printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \
  51. $err "!mk $srcdir .coreboot-version"
  52. [ -z "$mode" ] && [ "$target" != "$tree" ] && \
  53. x_ ./vendor download $target; return 0
  54. }
  55. cook_coreboot_config()
  56. {
  57. [ -f "$srcdir/.config" ] || return 0
  58. printf "CONFIG_CCACHE=y\n" >> "$srcdir/.config" || \
  59. $err "$srcdir/.config: Could not enable ccache"
  60. make -C "$srcdir" oldconfig || $err "Could not cook $srcdir/.config"; :
  61. }
  62. check_coreboot_utils()
  63. {
  64. for util in cbfstool ifdtool; do
  65. [ "$badhash" = "y" ] && x_ rm -f "elf/$util/$1/$util"
  66. e "elf/$util/$1/$util" f && continue
  67. utilelfdir="elf/$util/$1"
  68. utilsrcdir="src/coreboot/$1/util/$util"
  69. utilmode="" && [ -n "$mode" ] && utilmode="clean"
  70. x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
  71. [ -z "$mode" ] && [ ! -f "$utilelfdir/$util" ] && \
  72. x_ mkdir -p "$utilelfdir" && \
  73. x_ cp "$utilsrcdir/$util" "elf/$util/$1"
  74. [ -z "$mode" ] || x_ rm -Rf "$utilelfdir"; continue
  75. done; return 0
  76. }
  77. mkcorebootbin()
  78. {
  79. [ "$target" = "$tree" ] && return 0
  80. tmprom="$TMPDIR/coreboot.rom"
  81. $dry x_ cp "$srcdir/build/coreboot.rom" "$tmprom"
  82. initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
  83. [ "$displaymode" = "$initmode" ] && displaymode="" # "normal" config
  84. initmode="${initmode%%_*}"
  85. cbfstool="elf/cbfstool/$tree/cbfstool"
  86. [ "$payload_uboot_i386" = "y" ] && \
  87. [ "$payload_uboot_amd64" = "y" ] && \
  88. $err "'$target' enables 32- and 64-bit x86 U-Boot"
  89. if [ "$payload_uboot_i386" = "y" ] || \
  90. [ "$payload_uboot_amd64" = "y" ]; then
  91. printf "'$target' has x86 U-Boot; assuming SeaBIOS=y\n" 1>&2
  92. payload_seabios="y"
  93. fi
  94. [ -n "$uboot_config" ] || uboot_config="default"
  95. [ "$payload_uboot" = "y" ] || payload_seabios="y"
  96. [ "$payload_grub" = "y" ] && payload_seabios="y"
  97. [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
  98. $dry $err "$target: U-Boot(arm64) and SeaBIOS/GRUB both enabled."
  99. [ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
  100. [ -n "$grubtree" ] || grubtree="default"
  101. grubelf="elf/grub/$grubtree/payload/grub.elf"
  102. [ "$payload_memtest" = "y" ] || payload_memtest="n"
  103. [ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
  104. if $dry grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then
  105. [ "$payload_seabios" = "y" ] && pname="seabios" && \
  106. $dry add_seabios
  107. [ "$payload_uboot" = "y" ] && pname="uboot" && $dry add_uboot
  108. else
  109. pname="custom" && $dry cprom; :
  110. fi; :
  111. }
  112. add_seabios()
  113. {
  114. _seabioself="elf/seabios/default/$initmode/bios.bin.elf"
  115. cbfs "$tmprom" "$_seabioself" "fallback/payload"
  116. x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
  117. _z="2"; [ "$initmode" = "vgarom" ] && _z="0"
  118. x_ "$cbfstool" "$tmprom" add-int -i $_z -n etc/pci-optionrom-exec
  119. x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
  120. [ "$initmode" = "libgfxinit" ] && \
  121. cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw
  122. [ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
  123. "elf/memtest86plus/memtest.bin" img/memtest
  124. if [ "$payload_uboot_i386" = "y" ] || \
  125. [ "$payload_uboot_amd64" = "y" ]; then
  126. $dry add_uboot
  127. fi
  128. [ "$payload_grub" = "y" ] && add_grub
  129. cprom
  130. [ "$payload_uboot_amd64" = "y" ] && [ "$displaymode" != "txtmode" ] && \
  131. [ "$initmode" != "normal" ] && pname="seauboot" && cprom "seauboot"
  132. [ "$payload_grub" = "y" ] && pname="seagrub" && mkseagrub; :
  133. }
  134. add_grub()
  135. {
  136. cbfs "$tmprom" "$grubelf" "img/grub2"
  137. printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
  138. > "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
  139. cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
  140. }
  141. mkseagrub()
  142. {
  143. cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
  144. for keymap in config/data/grub/keymap/*.gkb; do
  145. [ -f "$keymap" ] && cprom "${keymap##*/}"; :
  146. done; :
  147. }
  148. add_uboot()
  149. {
  150. if [ "$displaymode" = "txtmode" ]; then
  151. printf "cb/$target: Cannot use U-Boot in text mode\n" 1>&2
  152. return 0
  153. elif [ "$initmode" = "normal" ]; then
  154. printf "cb/$target: Cannot use U-Boot in normal initmode\n" 1>&2
  155. return 0
  156. fi
  157. # TODO: re-work to allow each coreboot target to say which ub tree
  158. # instead of hardcoding as in the current logic below:
  159. # aarch64 targets:
  160. ubcbfsargs=""
  161. ubpath="fallback/payload"
  162. ubtarget="$target"
  163. # override for x86/x86_64 targets:
  164. if [ "$payload_uboot_i386" = "y" ] || \
  165. [ "$payload_uboot_amd64" = "y" ]; then
  166. ubcbfsargs="-l 0x1110000 -e 0x1110000" # 64-bit and 32-bit
  167. # on 64-bit, 0x1120000 is the SPL, and stub before that
  168. ubpath="img/u-boot" # 64-bit
  169. ubtarget="amd64coreboot"
  170. [ "$payload_uboot_i386" = "y" ] && ubpath="u-boot" # 32-bit
  171. [ "$payload_uboot_i386" = "y" ] && ubtarget="i386coreboot"; :
  172. fi
  173. ubdir="elf/u-boot/$ubtarget/$uboot_config"
  174. # aarch64 targets:
  175. ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
  176. ubootelf="$ubdir/u-boot"
  177. # override for x86/x86_64 targets:
  178. [ "$payload_uboot_i386" = "y" ] && ubootelf="$ubdir/u-boot-dtb.bin"
  179. [ "$payload_uboot_amd64" = "y" ] && \
  180. ubootelf="$ubdir/u-boot-x86-with-spl.bin" # EFI-compatible
  181. [ -f "$ubootelf" ] || $err "cb/$ubtarget: Can't find u-boot"
  182. cbfs "$tmprom" "$ubootelf" "$ubpath" $ubcbfsargs; cprom
  183. }
  184. cprom()
  185. {
  186. newrom="bin/$target/${pname}_${target}_$initmode.rom"
  187. [ -n "$displaymode" ] && newrom="${newrom%.rom}_$displaymode.rom"
  188. [ $# -gt 0 ] && [ "$1" != "seauboot" ] && \
  189. newrom="${newrom%.rom}_${1%.gkb}.rom"
  190. x_ mkdir -p "bin/$target"
  191. x_ cp "$tmprom" "$newrom" && [ $# -gt 0 ] && [ "$1" != "seauboot" ] && \
  192. cbfs "$newrom" "config/data/grub/keymap/$1" keymap.gkb raw
  193. [ $# -gt 0 ] && [ "$1" = "seauboot" ] && \
  194. cbfs "$newrom" "config/data/grub/bootorder_uboot" "bootorder" raw
  195. [ "$XBMK_RELEASE" = "y" ] || return 0
  196. $dry mksha512sum "$newrom" "vendorhashes"; $dry ./vendor inject \
  197. -r "$newrom" -b "$target" -n nuke || $err "!nuke $newrom"
  198. }
  199. mkcoreboottar()
  200. {
  201. [ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
  202. [ "$release" != "n" ] && $dry mkrom_tarball "bin/$target"; :
  203. }