rom.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. }
  53. cook_coreboot_config()
  54. {
  55. [ -f "$srcdir/.config" ] || return 0
  56. printf "CONFIG_CCACHE=y\n" >> "$srcdir/.config" || \
  57. $err "$srcdir/.config: Could not enable ccache"
  58. make -C "$srcdir" oldconfig || $err "Could not cook $srcdir/.config"; :
  59. }
  60. check_coreboot_utils()
  61. {
  62. for util in cbfstool ifdtool; do
  63. [ "$badhash" = "y" ] && x_ rm -f "elf/$util/$1/$util"
  64. e "elf/$util/$1/$util" f && continue
  65. utilelfdir="elf/$util/$1"
  66. utilsrcdir="src/coreboot/$1/util/$util"
  67. utilmode="" && [ -n "$mode" ] && utilmode="clean"
  68. x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs
  69. [ -z "$mode" ] && [ ! -f "$utilelfdir/$util" ] && \
  70. x_ mkdir -p "$utilelfdir" && \
  71. x_ cp "$utilsrcdir/$util" "elf/$util/$1"
  72. [ -z "$mode" ] || x_ rm -Rf "$utilelfdir"; continue
  73. done; return 0
  74. }
  75. mkcorebootbin()
  76. {
  77. [ "$target" = "$tree" ] && return 0
  78. tmprom="$TMPDIR/coreboot.rom"
  79. $dry x_ cp "$srcdir/build/coreboot.rom" "$tmprom"
  80. initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
  81. initmode="${initmode%%_*}"
  82. [ -n "$displaymode" ] && displaymode="_$displaymode"
  83. cbfstool="elf/cbfstool/$tree/cbfstool"
  84. [ -n "$uboot_config" ] || uboot_config="default"
  85. [ "$payload_uboot" = "y" ] || payload_seabios="y"
  86. [ "$payload_grub" = "y" ] && payload_seabios="y"
  87. [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
  88. $dry $err "$target: U-Boot and SeaBIOS/GRUB are both enabled."
  89. [ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
  90. [ -n "$grubtree" ] || grubtree="default"
  91. grubelf="elf/grub/$grubtree/payload/grub.elf"
  92. [ "$payload_memtest" = "y" ] || payload_memtest="n"
  93. [ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
  94. if $dry grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then
  95. [ "$payload_seabios" = "y" ] && pname="seabios" && \
  96. $dry add_seabios
  97. [ "$payload_uboot" = "y" ] && pname="uboot" && $dry add_uboot
  98. else
  99. pname="custom" && $dry cprom; :
  100. fi; :
  101. }
  102. add_seabios()
  103. {
  104. _seabioself="elf/seabios/default/$initmode/bios.bin.elf"
  105. cbfs "$tmprom" "$_seabioself" "fallback/payload"
  106. x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
  107. _z="2"; [ "$initmode" = "vgarom" ] && _z="0"
  108. x_ "$cbfstool" "$tmprom" add-int -i $_z -n etc/pci-optionrom-exec
  109. x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
  110. [ "$initmode" = "libgfxinit" ] && \
  111. cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw
  112. [ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
  113. "elf/memtest86plus/memtest.bin" img/memtest
  114. [ "$payload_grub" = "y" ] && add_grub
  115. cprom && [ "$payload_grub" = "y" ] && pname="seagrub" && mkseagrub; :
  116. }
  117. add_grub()
  118. {
  119. cbfs "$tmprom" "$grubelf" "img/grub2"
  120. printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
  121. > "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
  122. cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
  123. }
  124. mkseagrub()
  125. {
  126. cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
  127. for keymap in config/data/grub/keymap/*.gkb; do
  128. [ -f "$keymap" ] && cprom "${keymap##*/}"; :
  129. done; :
  130. }
  131. add_uboot()
  132. {
  133. ubdir="elf/u-boot/$target/$uboot_config"
  134. ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
  135. ubootelf="$ubdir/u-boot"
  136. [ -f "$ubootelf" ] || $err "cb/$target: Can't find u-boot"
  137. cbfs "$tmprom" "$ubootelf" "fallback/payload"; cprom
  138. }
  139. cprom()
  140. {
  141. newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
  142. [ $# -gt 0 ] && newrom="${newrom%.rom}_${1%.gkb}.rom"
  143. x_ mkdir -p "bin/$target"
  144. x_ cp "$tmprom" "$newrom" && [ $# -gt 0 ] && \
  145. cbfs "$newrom" "config/data/grub/keymap/$1" keymap.gkb raw; :
  146. }
  147. mkcoreboottar()
  148. {
  149. [ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
  150. [ "$release" != "n" ] && $dry mkrom_tarball "bin/$target"; :
  151. }