contrib/firmware/repack_fw_tars: Add support for EC component manifest
When the EC component manifest (component_manifest.json) exists in the
firmware tarball, it needs to be repacked together with the EC image to
be uploaded to the Binary Component Server (BCS). Therefore, add support
for repacking it.
BUG=b:309821164
TEST=Ran repack_fw_tars with tarball with component_manifest.json
TEST=Ran repack_fw_tars with tarball without component_manifest.json
Change-Id: I4c5d69a999c87e891ba8e2a0fc6f6ec58545d062
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/5108528
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Yidi Lin <yidilin@chromium.org>
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Tested-by: Yu-Ping Wu <yupingso@chromium.org>
(cherry picked from commit 9071f11824b5414444aa0dbb237e10c474fcb4fe)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/5960136
Tested-by: Clark Chung <ckclark@chromium.org>
Reviewed-by: Tzu-Min Sun <jimmysun@chromium.org>
Commit-Queue: Tzu-Min Sun <jimmysun@chromium.org>
Auto-Submit: Clark Chung <ckclark@chromium.org>
diff --git a/contrib/firmware/repack_fw_tars b/contrib/firmware/repack_fw_tars
index d07b891..3e235db 100755
--- a/contrib/firmware/repack_fw_tars
+++ b/contrib/firmware/repack_fw_tars
@@ -31,9 +31,10 @@
set -e
make_tar() {
- local file=$1
- local tar=$2
- tar -cjvf "${tar}" -C "$(dirname "${file}")" "$(basename "${file}")"
+ local tar=$1
+ local dir=$2
+ local files=("${@:3}")
+ tar -cjvf "${tar}" -C "${dir}" "${files[@]}"
}
make_fw_tar() {
@@ -44,6 +45,7 @@
local output=$4
local ap="${fw_dir}/image-${model}.bin"
local ec="${fw_dir}/${model}/ec.bin"
+ local ec_manifest="${fw_dir}/${model}/component_manifest.json"
local ecrw="${ecrw_dir}/${model}/ec.bin"
local model_uc="${model^}"
local version
@@ -60,10 +62,19 @@
"${SWAP_EC_RW}" --image "${ap}" --ec "${ecrw}" > /dev/null
fi
+ # Make AP tar
local ap_tar="${output}/${model_uc}.${version}.tbz2"
local ec_tar="${output}/${model_uc}_EC.${version}.tbz2"
- make_tar "${ap}" "${ap_tar}"
- make_tar "${ec}" "${ec_tar}"
+ make_tar "${ap_tar}" "$(dirname "${ap}")" "$(basename "${ap}")"
+
+ # Make EC tar
+ local ec_files=("$(basename "${ec}")")
+ if [ -f "${ec_manifest}" ]; then
+ ec_files+=("$(basename "${ec_manifest}")")
+ else
+ warn "$(basename "${ec_manifest}") not found for ${model}"
+ fi
+ make_tar "${ec_tar}" "$(dirname "${ec}")" "${ec_files[@]}"
}
main() {
@@ -87,17 +98,24 @@
temp_dir=$(mktemp -d)
local ap_temp_dir="${temp_dir}/ap"
- local ap_files=()
- local ec_files=()
- for model in "${models[@]}"; do
- ap_files+=("image-${model}.bin")
- ec_files+=("${model}/ec.bin")
+ # Files such as component_manifest.json may not exist in the tarball,
+ # so we cannot pass the file name to tar as "tar -xjf ${tarball} FILES".
+ # Instead, we exclude a few patterns to save some space.
+ local excluded_files=(
+ "cbfs-ro-compress/*"
+ "*/coreboot*/*"
+ "*/depthcharge/*"
+ "*/libpayload*/*"
+ )
+ local opts=()
+
+ for file in "${excluded_files[@]}"; do
+ opts+=("--exclude" "${file}")
done
info "Extracting images to ${ap_temp_dir}..."
mkdir "${ap_temp_dir}"
- (cd "${ap_temp_dir}" &&
- tar -xjf "${tarball}" "${ap_files[@]}" "${ec_files[@]}")
+ (cd "${ap_temp_dir}" && tar -xjf "${tarball}" "${opts[@]}")
# Extract from EC tarball
local ecrw_temp_dir
@@ -107,7 +125,7 @@
info "Extracting EC images to ${ecrw_temp_dir}..."
mkdir "${ecrw_temp_dir}"
ecrw_tarball=$(readlink -f "${FLAGS_ecrw}")
- (cd "${ecrw_temp_dir}" && tar -xjf "${ecrw_tarball}" "${ec_files[@]}")
+ (cd "${ecrw_temp_dir}" && tar -xjf "${ecrw_tarball}" "${opts[@]}")
fi
for model in "${models[@]}"; do