mrc.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # Logic based on util/chromeos/crosfirmware.sh in coreboot cfc26ce278.
  3. # Modifications in this version are Copyright 2021, 2023 and 2024 Leah Rowe.
  4. # Original copyright detailed in repo: https://review.coreboot.org/coreboot/
  5. eval "$(setvars "" MRC_url MRC_url_bkup MRC_hash MRC_board SHELLBALL)"
  6. extract_ref()
  7. {
  8. # refcode needed on broadwell, but not needed on haswell
  9. # we check mrc twice, because each check only verifies one file,
  10. # but refcode is downloaded alongside mrc. in cases where lbmk
  11. # erred, downloading only mrc, we must ensure downloading refcode
  12. [ -n "$CONFIG_MRC_FILE" ] || \
  13. $err "extract_ref $board: CONFIG_MRC_FILE not defined"
  14. # the extract_mrc function actually downloads the refcode
  15. fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE"
  16. }
  17. extract_mrc()
  18. {
  19. [ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set"
  20. [ -z "${CONFIG_MRC_FILE}" ] && \
  21. $err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set"
  22. SHELLBALL="chromeos-firmwareupdate-${MRC_board}"
  23. (
  24. x_ cd "${appdir}"
  25. extract_partition "${MRC_url##*/}"
  26. extract_archive "${SHELLBALL}" .
  27. ) || $err "mrc download/extract failure"
  28. "${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \
  29. -f "$_dest" -r RO_SECTION || $err "extract_mrc: cbfstool $_dest"
  30. [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0
  31. }
  32. extract_partition()
  33. {
  34. printf "Extracting ROOT-A partition\n"
  35. ROOTP=$( printf "unit\nB\nprint\nquit\n" | \
  36. parted "${1%.zip}" 2>/dev/null | grep "ROOT-A" )
  37. START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) ))
  38. SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) ))
  39. dd if="${1%.zip}" of="root-a.ext2" bs=1024 \
  40. skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \
  41. $err "extract_partition, dd ${1%.zip}, root-a.ext2"
  42. printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \
  43. | debugfs "root-a.ext2" || $err "can't extract shellball"
  44. }
  45. extract_refcode()
  46. {
  47. _refdest="${CONFIG_REFCODE_BLOB_FILE##*../}"
  48. [ -f "$_refdest" ] && return 0
  49. # cbfstool changed the attributes scheme for stage files,
  50. # incompatible with older versions before coreboot 4.14,
  51. # so we need coreboot 4.13 cbfstool for certain refcode files
  52. [ -n "$cbfstoolref" ] || \
  53. $err "extract_refcode $board: MRC_refcode_cbtree not set"
  54. mkdir -p "${_refdest%/*}" || \
  55. $err "extract_refcode $board: !mkdir -p ${_refdest%/*}"
  56. "$cbfstoolref" "$appdir/bios.bin" extract \
  57. -m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \
  58. || $err "extract_refcode $board: !cbfstoolref $_refdest"
  59. # enable the Intel GbE device, if told by offset MRC_refcode_gbe
  60. [ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \
  61. of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \
  62. $err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0
  63. }