mrc.sh 2.1 KB

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