mrc.sh 2.2 KB

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