blobutil/download: split into small functions

This patch makes it easier to determine which part does what.
fsdg20230625
Leah Rowe 2023-04-01 13:06:35 +01:00
parent b10bfacf67
commit ed47c91453
1 changed files with 43 additions and 22 deletions

View File

@ -2,9 +2,9 @@
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# SPDX-FileCopyrightText: 2023 Leah Rowe <info@minifree.org>
# SPDX-License-Identifier: GPL-3.0-only
needs=""
board="${1}"
# A shorthand for each board, to avoid duplicating configs per flash size
board_short=${board%%_*mb}
@ -89,7 +89,7 @@ Download_needed(){
for need in ${needs}; do
case ${need} in
*ME*)
Extract_me || _failed="${_failed} me"
Download_me || _failed="${_failed} me"
;;
*MRC*)
./download mrc || _failed="${_failed} mrc"
@ -102,40 +102,61 @@ Download_needed(){
fi
}
Extract_me(){
Download_me() {
printf "Downloading neutered ME for board: `%s`\n" ${board}
Fetch_update || return 1
Extract_me || return 1
return 0
}
Fetch_update() {
printf "Fetching vendor update for board: `%s`\n" ${board}
_me_destination=${CONFIG_ME_BIN_PATH#../../}
if [ -f "${_me_destination}" ]; then
printf 'me already downloaded\n'
return 0
fi
if [ -z "${dl_url+x}" ]; then
printf 'no me download available for this board\n'
printf "No vendor update specified for board: `%s`\n" ${board}
return 1
fi
Vendor_checksum blobs/me.exe || \
curl ${dl_url} > blobs/me.exe || curl ${dl_url_bkup} > blobs/me.exe
Vendor_checksum blobs/me.exe || Fail \
"Cannot guarantee intergity of vendor update for board: `${board}`"
return 0
}
Vendor_checksum() {
if [ ! -f "blobs/me.exe" ]; then
printf "Vendor update not found on disk for board: `%s`\n" ${board}
return 1
fi
if [ "$(sha1sum blobs/me.exe | awk '{print $1}')" != "${dl_hash}" ]; then
printf "Bad checksum on vendor update for board: `%s`\n" ${board}
rm blobs/me.exe
return 1
fi
return 0
}
Extract_me(){
printf "Extracting neutered ME for ${board}\n"
if [ ! -d "${_me_destination%/*}" ]; then
mkdir -p ${_me_destination%/*}
fi
printf "Extracting neutered me for ${board}\n"
# Delete old me downloads in case user is building for multiple boards
if [ -f "blobs/me.exe" ]; then
rm blobs/me.exe
fi
if [ -d "blobs/app" ]; then
rm -r blobs/app
fi
curl ${dl_url} > blobs/me.exe || curl ${dl_url_bkup} > blobs/me.exe
if [ "$(sha1sum blobs/me.exe | awk '{print $1}')" != "${dl_hash}" ]; then
printf 'checksum of downloaded me did not mactch\ncorrupted me downloaded or wrong me for board\n'
rm blobs/me.exe
return 1
if [ -f "${_me_destination}" ]; then
printf 'me already downloaded\n'
return 0
fi
printf 'extracting and stripping intel management engine\n'