mrc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/usr/bin/env sh
  2. # Download Intel MRC images
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 2 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. #
  16. # This script assumes that the working directory is the
  17. # root of osboot_src or osboot git.
  18. # This file is forked from util/chromeos/crosfirmware.sh in coreboot cfc26ce278
  19. # Changes to it in osboot are copyright 2021 Leah Rowe
  20. [ "x${DEBUG+set}" = 'xset' ] && set -v
  21. set -u -e
  22. # On some systems, `parted` and `debugfs` are located in /sbin.
  23. export PATH="${PATH}:/sbin"
  24. download_image()
  25. {
  26. _url=${1}
  27. _file=${2}
  28. _sha1sum=${3}
  29. echo "Downloading recovery image"
  30. curl "$_url" > "$_file.zip"
  31. if [ "$(sha1sum ${_file}.zip | awk '{print $1}')" = "${_sha1sum}" ]; then
  32. unzip -q "${_file}.zip"
  33. rm "${_file}.zip"
  34. echo "Checksum verification passed for recovery image."
  35. return 0
  36. else
  37. rm "${_file}.zip"
  38. echo "Bad checksum. Recovery image deleted."
  39. return 1
  40. fi
  41. }
  42. extract_partition()
  43. {
  44. NAME=${1}
  45. FILE=${2}
  46. ROOTFS=${3}
  47. _bs=1024
  48. echo "Extracting ROOT-A partition"
  49. ROOTP=$( printf "unit\nB\nprint\nquit\n" | \
  50. parted ${FILE} 2>/dev/null | grep ${NAME} )
  51. START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) ))
  52. SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) ))
  53. dd if=${FILE} of=${ROOTFS} bs=${_bs} skip=$(( ${START} / ${_bs} )) \
  54. count=$(( ${SIZE} / ${_bs} )) > /dev/null
  55. }
  56. extract_shellball()
  57. {
  58. ROOTFS=${1}
  59. SHELLBALL=${2}
  60. echo "Extracting chromeos-firmwareupdate"
  61. printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" | \
  62. debugfs ${ROOTFS} > /dev/null 2>&1
  63. }
  64. extract_coreboot()
  65. {
  66. _shellball=${1}
  67. _unpacked=$( mktemp -d )
  68. echo "Extracting coreboot image"
  69. sh ${_shellball} --unpack ${_unpacked} > /dev/null
  70. _version=$( cat ${_unpacked}/VERSION | grep BIOS\ version: | \
  71. cut -f2 -d: | tr -d \ )
  72. cp ${_unpacked}/bios.bin coreboot-${_version}.bin
  73. rm -r "${_unpacked}"
  74. }
  75. check_existing()
  76. {
  77. _mrc_complete_hash="d18de1e3d52c0815b82ea406ca07897c56c65696"
  78. if [ -f mrc/haswell/mrc.bin ]; then
  79. printf 'found existing mrc.bin, checking its hash\n'
  80. if [ "$(sha1sum mrc/haswell/mrc.bin | awk '{print $1}')" = "${_mrc_complete_hash}" ]; then
  81. printf 'checksums matched, skipping redownloading image\n'
  82. return 0
  83. else
  84. printf 'hashes did not match, starting over\n'
  85. return 1
  86. fi
  87. else
  88. return 1
  89. fi
  90. }
  91. # Skips redownloading every time the script runs
  92. check_existing && exit 0
  93. if [ ! -d "coreboot/default/" ]; then
  94. ./download coreboot default
  95. fi
  96. if [ ! -f "coreboot/default/util/cbfstool/cbfstool" ]; then
  97. ./build module cbutils default
  98. fi
  99. # Remove the old version that may still exist
  100. # ------------------------------------------------------------------------------
  101. printf "Downloading Intel MRC blobs\n"
  102. #rm -Rf "mrc/"
  103. mkdir -p mrc/haswell/
  104. (
  105. cd mrc/haswell/
  106. # https://web.archive.org/web/20210211071412/https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf
  107. # peppy image used as defined here, mrc.bin extracted from that.
  108. # when wanting to use an updated version later on, just change the url and
  109. # sha1sums and such, in this script, based on a newer version on archive.org.
  110. # For haswell mrc.bin, used on ThinkPad T440p and W541
  111. _board="peppy"
  112. _file="chromeos_12239.92.0_peppy_recovery_stable-channel_mp-v3.bin"
  113. _url="https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_12239.92.0_peppy_recovery_stable-channel_mp-v3.bin.zip"
  114. _url2="https://web.archive.org/web/20200516070928/https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_12239.92.0_peppy_recovery_stable-channel_mp-v3.bin.zip"
  115. _sha1sum="cd5917cbe7f821ad769bf0fd87046898f9e175c8"
  116. download_image ${_url} ${_file} ${_sha1sum}
  117. if [ ! -f ${_file} ]; then
  118. download_image ${_url2} ${_file} ${_sha1sum}
  119. fi
  120. if [ ! -f $_file ]; then
  121. echo "${_file} was not downloaded, or verification failed. Exiting"
  122. exit 1
  123. fi
  124. extract_partition ROOT-A ${_file} root-a.ext2
  125. extract_shellball root-a.ext2 chromeos-firmwareupdate-${_board}
  126. extract_coreboot chromeos-firmwareupdate-${_board}
  127. ../../coreboot/default/util/cbfstool/cbfstool coreboot-*.bin extract -f mrc.bin -n mrc.bin -r RO_SECTION
  128. rm -f "chromeos-firmwareupdate-${_board}" coreboot-*.bin "${_file}" "root-a.ext2"
  129. printf "\n\nHaswell mrc.bin file (for T440p and W541) downloaded to mrc/haswell/mrc.bin\n\n"
  130. )
  131. exit 0