rom.sh 5.7 KB

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