mrc.sh 2.0 KB

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