withgrub_helper 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. # helper script: create ROM images for a given system, with GRUB
  3. #
  4. # Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
  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. # Build coreboot ROM image
  66. make clean
  67. mv "config_${romtype}" ".config"
  68. mv "grub_${romtype}.elf" "grub.elf"
  69. make -j"$(nproc)"
  70. mv "grub.elf" "grub_${romtype}.elf"
  71. mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"
  72. # .config no longer needed
  73. rm -f ".config"
  74. # Add version information to this image
  75. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f lbversion -n lbversion -t raw
  76. # Add the background image
  77. if [ "$romtype" = "vesafb" ]
  78. then
  79. 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" ]
  80. then
  81. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1280x800.png -n background.png -t raw
  82. else
  83. ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1024x768.png -n background.png -t raw
  84. fi
  85. fi
  86. # Add the correct GRUB configuration file for this image.
  87. for keylayout in ../resources/utilities/grub-assemble/keymap/original/*
  88. do
  89. keymap="${keylayout##*/}"
  90. # copy the images based on the keymap
  91. cp "${boardtarget}_${romtype}.rom" "${boardtarget}_${keymap}_${romtype}.rom"
  92. # Insert grub config into the image
  93. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}.cfg" -n grub.cfg -t raw
  94. # Insert grub test config into the image (for the user to test modifications to before modifying the main one)
  95. ./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}_test.cfg" -n grubtest.cfg -t raw
  96. done
  97. # This config-less ROM is no longer needed
  98. rm -f "${boardtarget}_${romtype}.rom"
  99. done
  100. # Now we clean up and prepare the bin directory containing all the images
  101. # ----------------------------------------------------------------------------------------------------------------------------
  102. # prepare directory for new ROM images
  103. rm -Rf "${boardtarget:?}/"
  104. mkdir "${boardtarget}/"
  105. # move the ROM's into the newly created directory
  106. mv "${boardtarget}"*.rom "${boardtarget}/"
  107. # delete the old ROM's from ../bin
  108. rm -Rf "../bin/grub/${boardtarget}/"
  109. # now put the new ROM's in ./bin/grub/
  110. [ ! -d "../bin/grub/" ] && mkdir -p "../bin/grub/"
  111. mv "${boardtarget}/" "../bin/grub/"
  112. # libreboot version file no longer needed
  113. rm -f "lbversion"
  114. # go back to main source directory
  115. cd "../"
  116. printf "\n\n"