util/chromeos/crosfirmware: format with shfmt
Clean up formatting using shfmt Change-Id: I46ce84668bfb4ea3df179317e2848b6bb75d8d5c Signed-off-by: Matt DeVillier <matt.devillier@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/61617 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sean Rhodes <sean@starlabs.systems>
This commit is contained in:
parent
d00cfcb0a1
commit
1dc1a56a5d
|
@ -28,93 +28,88 @@ exit_if_dependencies_are_missing() {
|
||||||
exit_if_uninstalled "unzip" "unzip"
|
exit_if_uninstalled "unzip" "unzip"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_inventory()
|
get_inventory() {
|
||||||
{
|
|
||||||
_conf=$1
|
_conf=$1
|
||||||
_url=https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf
|
_url=https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf
|
||||||
|
|
||||||
echo "Downloading recovery image inventory..."
|
echo "Downloading recovery image inventory..."
|
||||||
|
|
||||||
curl -s "$_url" > $_conf
|
curl -s "$_url" >$_conf
|
||||||
}
|
}
|
||||||
|
|
||||||
download_image()
|
download_image() {
|
||||||
{
|
|
||||||
_url=$1
|
_url=$1
|
||||||
_file=$2
|
_file=$2
|
||||||
|
|
||||||
echo "Downloading recovery image"
|
echo "Downloading recovery image"
|
||||||
curl "$_url" > "$_file.zip"
|
curl "$_url" >"$_file.zip"
|
||||||
echo "Decompressing recovery image"
|
echo "Decompressing recovery image"
|
||||||
unzip -q "$_file.zip"
|
unzip -q "$_file.zip"
|
||||||
rm "$_file.zip"
|
rm "$_file.zip"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_partition()
|
extract_partition() {
|
||||||
{
|
|
||||||
NAME=$1
|
NAME=$1
|
||||||
FILE=$2
|
FILE=$2
|
||||||
ROOTFS=$3
|
ROOTFS=$3
|
||||||
_bs=1024
|
_bs=1024
|
||||||
|
|
||||||
echo "Extracting ROOT-A partition"
|
echo "Extracting ROOT-A partition"
|
||||||
ROOTP=$( printf "unit\nB\nprint\nquit\n" | \
|
ROOTP=$(printf "unit\nB\nprint\nquit\n" |
|
||||||
parted $FILE 2>/dev/null | grep $NAME )
|
parted $FILE 2>/dev/null | grep $NAME)
|
||||||
|
|
||||||
if [ "$ROOTP" == "" ]; then
|
if [ "$ROOTP" == "" ]; then
|
||||||
# Automatic extraction failed, likely due to parted detecting
|
# Automatic extraction failed, likely due to parted detecting
|
||||||
# overlapping partitions. Fall back to using fdisk and assume
|
# overlapping partitions. Fall back to using fdisk and assume
|
||||||
# ROOT-A is partition #3
|
# ROOT-A is partition #3
|
||||||
echo "(Extracting via parted failed; falling back to fdisk)"
|
echo "(Extracting via parted failed; falling back to fdisk)"
|
||||||
_ssize=$(printf "p q" | fdisk $FILE | grep "Sector size" | \
|
_ssize=$(printf "p q" | fdisk $FILE | grep "Sector size" |
|
||||||
cut -f2 -d: | cut -f2 -d ' ')
|
cut -f2 -d: | cut -f2 -d ' ')
|
||||||
_start=$(printf "p q" | fdisk $FILE | grep "bin3" | tr -s ' ' | \
|
_start=$(printf "p q" | fdisk $FILE | grep "bin3" | tr -s ' ' |
|
||||||
cut -f2 -d ' ')
|
cut -f2 -d ' ')
|
||||||
_nsec=$(printf "p q" | fdisk $FILE | grep "bin3" | tr -s ' ' | \
|
_nsec=$(printf "p q" | fdisk $FILE | grep "bin3" | tr -s ' ' |
|
||||||
cut -f4 -d ' ')
|
cut -f4 -d ' ')
|
||||||
START=$(($_ssize * $_start))
|
START=$(($_ssize * $_start))
|
||||||
SIZE=$(($_ssize * $_nsec))
|
SIZE=$(($_ssize * $_nsec))
|
||||||
else
|
else
|
||||||
START=$(( $( echo $ROOTP | cut -f2 -d\ | tr -d "B" ) ))
|
START=$(($(echo $ROOTP | cut -f2 -d\ | tr -d "B")))
|
||||||
SIZE=$(( $( echo $ROOTP | cut -f4 -d\ | tr -d "B" ) ))
|
SIZE=$(($(echo $ROOTP | cut -f4 -d\ | tr -d "B")))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dd if=$FILE of=$ROOTFS bs=$_bs skip=$(( $START / $_bs )) \
|
dd if=$FILE of=$ROOTFS bs=$_bs skip=$(($START / $_bs)) \
|
||||||
count=$(( $SIZE / $_bs )) > /dev/null 2>&1
|
count=$(($SIZE / $_bs)) >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_shellball()
|
extract_shellball() {
|
||||||
{
|
|
||||||
ROOTFS=$1
|
ROOTFS=$1
|
||||||
SHELLBALL=$2
|
SHELLBALL=$2
|
||||||
|
|
||||||
echo "Extracting chromeos-firmwareupdate"
|
echo "Extracting chromeos-firmwareupdate"
|
||||||
printf "cd /usr/sbin\ndump chromeos-firmwareupdate $SHELLBALL\nquit" | \
|
printf "cd /usr/sbin\ndump chromeos-firmwareupdate $SHELLBALL\nquit" |
|
||||||
debugfs $ROOTFS > /dev/null 2>&1
|
debugfs $ROOTFS >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_coreboot()
|
extract_coreboot() {
|
||||||
{
|
|
||||||
_shellball=$1
|
_shellball=$1
|
||||||
_unpacked=$( mktemp -d )
|
_unpacked=$(mktemp -d)
|
||||||
|
|
||||||
echo "Extracting coreboot image"
|
echo "Extracting coreboot image"
|
||||||
if ! sh $_shellball --unpack $_unpacked > /dev/null 2>&1; then
|
if ! sh $_shellball --unpack $_unpacked >/dev/null 2>&1; then
|
||||||
sh $_shellball --sb_extract $_unpacked > /dev/null 2>&1
|
sh $_shellball --sb_extract $_unpacked >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d $_unpacked/models/ ]; then
|
if [ -d $_unpacked/models/ ]; then
|
||||||
_version=$( cat $_unpacked/VERSION | grep -m 1 -e Model.*$_board -A5 \
|
_version=$(cat $_unpacked/VERSION | grep -m 1 -e Model.*$_board -A5 |
|
||||||
| grep "BIOS (RW) version:" | cut -f2 -d: | tr -d \ )
|
grep "BIOS (RW) version:" | cut -f2 -d: | tr -d \ )
|
||||||
if [ "$_version" == "" ]; then
|
if [ "$_version" == "" ]; then
|
||||||
_version=$( cat $_unpacked/VERSION | grep -m 1 -e Model.*$_board -A5 \
|
_version=$(cat $_unpacked/VERSION | grep -m 1 -e Model.*$_board -A5 |
|
||||||
| grep "BIOS version:" | cut -f2 -d: | tr -d \ )
|
grep "BIOS version:" | cut -f2 -d: | tr -d \ )
|
||||||
fi
|
fi
|
||||||
_bios_image=$(grep "IMAGE_MAIN" $_unpacked/models/$_board/setvars.sh \
|
_bios_image=$(grep "IMAGE_MAIN" $_unpacked/models/$_board/setvars.sh |
|
||||||
| cut -f2 -d\")
|
cut -f2 -d\")
|
||||||
else
|
else
|
||||||
_version=$( cat $_unpacked/VERSION | grep BIOS\ version: | \
|
_version=$(cat $_unpacked/VERSION | grep BIOS\ version: |
|
||||||
cut -f2 -d: | tr -d \ )
|
cut -f2 -d: | tr -d \ )
|
||||||
_bios_image=bios.bin
|
_bios_image=bios.bin
|
||||||
fi
|
fi
|
||||||
if cp $_unpacked/$_bios_image coreboot-$_version.bin; then
|
if cp $_unpacked/$_bios_image coreboot-$_version.bin; then
|
||||||
|
@ -124,8 +119,7 @@ extract_coreboot()
|
||||||
rm $_shellball
|
rm $_shellball
|
||||||
}
|
}
|
||||||
|
|
||||||
do_one_board()
|
do_one_board() {
|
||||||
{
|
|
||||||
_board=$1
|
_board=$1
|
||||||
_url=$2
|
_url=$2
|
||||||
_file=$3
|
_file=$3
|
||||||
|
@ -148,25 +142,25 @@ BOARD=$1
|
||||||
exit_if_dependencies_are_missing
|
exit_if_dependencies_are_missing
|
||||||
|
|
||||||
if [ "$BOARD" == "all" ]; then
|
if [ "$BOARD" == "all" ]; then
|
||||||
CONF=$( mktemp )
|
CONF=$(mktemp)
|
||||||
get_inventory $CONF
|
get_inventory $CONF
|
||||||
|
|
||||||
grep ^name= $CONF| while read _line; do
|
grep ^name= $CONF | while read _line; do
|
||||||
name=$( echo $_line | cut -f2 -d= )
|
name=$(echo $_line | cut -f2 -d=)
|
||||||
echo Processing board $name
|
echo Processing board $name
|
||||||
eval $( grep -v hwid= $CONF | grep -A11 "$_line" | \
|
eval $(grep -v hwid= $CONF | grep -A11 "$_line" |
|
||||||
grep '\(url=\|file=\)' )
|
grep '\(url=\|file=\)')
|
||||||
BOARD=$( echo $url | cut -f3 -d_ )
|
BOARD=$(echo $url | cut -f3 -d_)
|
||||||
do_one_board $BOARD $url $file
|
do_one_board $BOARD $url $file
|
||||||
done
|
done
|
||||||
|
|
||||||
rm "$CONF"
|
rm "$CONF"
|
||||||
elif [ "$BOARD" != "" ]; then
|
elif [ "$BOARD" != "" ]; then
|
||||||
CONF=$( mktemp )
|
CONF=$(mktemp)
|
||||||
get_inventory $CONF
|
get_inventory $CONF
|
||||||
|
|
||||||
echo Processing board $BOARD
|
echo Processing board $BOARD
|
||||||
eval $( grep -i $BOARD -A8 $CONF | grep '\(url=\|file=\)' )
|
eval $(grep -i $BOARD -A8 $CONF | grep '\(url=\|file=\)')
|
||||||
do_one_board $BOARD $url $file
|
do_one_board $BOARD $url $file
|
||||||
|
|
||||||
rm "$CONF"
|
rm "$CONF"
|
||||||
|
|
Loading…
Reference in New Issue