mrc.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_mrc()
  7. {
  8. [ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set"
  9. [ -z "${CONFIG_MRC_FILE}" ] && \
  10. $err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set"
  11. SHELLBALL="chromeos-firmwareupdate-${MRC_board}"
  12. (
  13. x_ cd "${appdir}"
  14. extract_partition "${MRC_url##*/}"
  15. extract_archive "${SHELLBALL}" .
  16. ) || $err "mrc download/extract failure"
  17. "${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \
  18. -f "$_dest" -r RO_SECTION || $err "extract_mrc: cbfstool $_dest"
  19. [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0
  20. }
  21. extract_partition()
  22. {
  23. printf "Extracting ROOT-A partition\n"
  24. ROOTP=$( printf "unit\nB\nprint\nquit\n" | \
  25. parted "${1%.zip}" 2>/dev/null | grep "ROOT-A" )
  26. START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) ))
  27. SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) ))
  28. dd if="${1%.zip}" of="root-a.ext2" bs=1024 \
  29. skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \
  30. $err "extract_partition, dd ${1%.zip}, root-a.ext2"
  31. printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \
  32. | debugfs "root-a.ext2" || $err "can't extract shellball"
  33. }
  34. extract_refcode()
  35. {
  36. _refdest="${CONFIG_REFCODE_BLOB_FILE##*../}"
  37. [ -f "$_refdest" ] && return 0
  38. # cbfstool changed the attributes scheme for stage files,
  39. # incompatible with older versions before coreboot 4.14,
  40. # so we need coreboot 4.13 cbfstool for certain refcode files
  41. [ -n "$cbfstoolref" ] || \
  42. $err "extract_refcode $board: MRC_refcode_cbtree not set"
  43. mkdir -p "${_refdest%/*}" || \
  44. $err "extract_refcode $board: !mkdir -p ${_refdest%/*}"
  45. "$cbfstoolref" "$appdir/bios.bin" extract \
  46. -m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \
  47. || $err "extract_refcode $board: !cbfstoolref $_refdest"
  48. # enable the Intel GbE device, if told by offset MRC_refcode_gbe
  49. [ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \
  50. of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \
  51. $err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0
  52. }