withgrub_helper 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # helper script: create ROM images for a given system, with GRUB
  3. #
  4. # Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # This script assumes that the working directory is the root
  21. # of libreboot_src or git
  22. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. if (( $# != 1 )); then
  25. printf "Usage: ./buildrom-withgrub boardname\n"
  26. printf "Example: ./buildrom-withgrub x60\n"
  27. printf "You need to specify exactly 1 argument\n"
  28. exit 1
  29. fi
  30. boardtarget="${1}"
  31. printf "GRUB Helper script: build ROM images for '%s'\n" "${boardtarget}"
  32. cd "coreboot/"
  33. if [ -f "../version" ]; then
  34. # _src release archive is being used
  35. version="$(cat ../version)"
  36. else
  37. # git repo is being used
  38. version="$(git describe --tags HEAD)"
  39. fi
  40. printf '%s\n' "${version}" >"lbversion"
  41. # Build ROM images with text-mode and corebootfb modes.
  42. # ---------------------------------------------------------------------------------------------------------------
  43. if [ "${boardtarget}" = "qemu_i440fx_piix4" ] || [ "${boardtarget}" = "qemu_q35_ich9" ]
  44. then
  45. # assume that the default config enable framebuffer mode, duplicate and patch for text-mode
  46. # necessary, otherwise it will ask you to enter the Y/X resolution of the framebuffer at build time
  47. cp "../resources/libreboot/config/grub/${boardtarget}/config" "config_vesafb"
  48. sed 's/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/' < "config_vesafb" > "config_txtmode"
  49. else
  50. # assume that the default config enables text-mode, duplicate and patch for framebuffer mode
  51. cp "../resources/libreboot/config/grub/${boardtarget}/config" "config_txtmode"
  52. sed 's/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/' < "config_txtmode" > "config_vesafb"
  53. fi
  54. for romtype in txtmode vesafb
  55. do
  56. if [ "${boardtarget}" = "x200_8mb" ] || [ "${boardtarget}" = "x200_4mb" ] || [ "${boardtarget}" = "r400_8mb" ] || [ "${boardtarget}" = "r400_4mb" ] || [ "${boardtarget}" = "r500_8mb" ] || [ "${boardtarget}" = "r500_4mb" ] || [ "${boardtarget}" = "t400_8mb" ] || [ "${boardtarget}" = "t400_4mb" ] || [ "${boardtarget}" = "t500_8mb" ] || [ "${boardtarget}" = "t500_4mb" ]
  57. then
  58. if [ "${romtype}" = "txtmode" ]
  59. then
  60. printf "Text mode graphics is currently broken on X200, R400, T400 and T500. Only framebuffer mode works.\n"
  61. printf "TODO: offending coreboot commit found (see docs/release.html). Fix text-mode graphics initialization.\n"
  62. continue
  63. fi
  64. fi
  65. if [ "${boardtarget}" = "kgpe-d16" ]; then
  66. if [ "${romtype}" = "vesafb" ]; then
  67. printf "Only text-mode is reported to work on KGPE-D16\n"
  68. printf "TODO: get tpearson to fix it\n"
  69. continue
  70. fi
  71. fi
  72. # Build coreboot ROM image
  73. make clean
  74. mv "config_${romtype}" ".config"
  75. mv "grub_${romtype}.elf" "grub.elf"
  76. make -j"$(nproc)"
  77. mv "grub.elf" "grub_${romtype}.elf"
  78. mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"
  79. # .config no longer needed
  80. rm -f ".config"
  81. # Add version information to this image
  82. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f lbversion -n lbversion -t raw
  83. # Add the background image
  84. if [ "$romtype" = "vesafb" ]
  85. then
  86. if [ "$1" = "macbook21" ] || [ "$1" = "x200_4mb" ] || [ "$1" = "x200_8mb" ] || [ "$1" = "r400_4mb" ] || [ "$1" = "r400_8mb" ] || [ "$1" = "r500_4mb" ] || [ "$1" = "r500_8mb" ] || [ "$1" = "t400_4mb" ] || [ "$1" = "t400_8mb" ] || [ "$1" = "t500_4mb" ] || [ "$1" = "t500_8mb" ]
  87. then
  88. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1280x800.png -n background.png -t raw
  89. else
  90. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1024x768.png -n background.png -t raw
  91. fi
  92. fi
  93. # Add SeaBIOS to the image
  94. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../seabios/out/bios.bin.elf -n bios.bin.elf -t raw
  95. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../seabios/out/vgabios.bin -n vgaroms/vgabios.bin -t raw
  96. # Add the correct GRUB configuration file for this image.
  97. for keylayout in ../resources/utilities/grub-assemble/keymap/original/*
  98. do
  99. keymap="${keylayout##*/}"
  100. # copy the images based on the keymap
  101. cp "${boardtarget}_${romtype}.rom" "${boardtarget}_${keymap}_${romtype}.rom"
  102. # Insert grub config into the image
  103. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}.cfg" -n grub.cfg -t raw
  104. # Insert grub test config into the image (for the user to test modifications to before modifying the main one)
  105. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}_test.cfg" -n grubtest.cfg -t raw
  106. done
  107. # This config-less ROM is no longer needed
  108. rm -f "${boardtarget}_${romtype}.rom"
  109. done
  110. # Now we clean up and prepare the bin directory containing all the images
  111. # ----------------------------------------------------------------------------------------------------------------------------
  112. # prepare directory for new ROM images
  113. rm -Rf "${boardtarget:?}/"
  114. mkdir "${boardtarget}/"
  115. # move the ROM images into the newly created directory
  116. mv "${boardtarget}"*.rom "${boardtarget}/"
  117. # delete the old ROM images from ../bin
  118. rm -Rf "../bin/grub/${boardtarget}/"
  119. # now put the new ROM images in ./bin/grub/
  120. [ ! -d "../bin/grub/" ] && mkdir -p "../bin/grub/"
  121. mv "${boardtarget}/" "../bin/grub/"
  122. # libreboot version file no longer needed
  123. rm -f "lbversion"
  124. # go back to main source directory
  125. cd "../"
  126. printf "\n\n"