make_factory_package: support using firmware updater from release rootfs

For most use case, we want to use the firmware updater from release image
rootfs. It'd be more convenient if make_factory_package extracts updater from
release image by default.

BUG=chromium-os:21512
TEST=./make_factory_package --release RELEASE --factory FACTORY --hwid none
     # success, seeing "firmware: XXXX" in output
     ./make_factory_package --release RELEASE --factory FACTORY --hwid none --firmware none
     # success, not seeing firmware in mini-omaha configuration
     ./make_factory_package --release RELEASE --factory FACTORY --hwid none --firmware FIRMWARE
     # success, seeing "firmware: XXXX" in mini-omaha configuration
     ./make_factory_package --release RELEASE --factory FACTORY --hwid none \
       --diskimg ssd.img
     # success, no firmware messages
     ./make_factory_package --release RELEASE --factory FACTORY --hwid none \
       --diskimg ssd.img --firmware FIRMWARE
     # failure as expected - firmware is not supported in --diskimg.

Change-Id: Ic368031a8a5ece89e3e7fd56e2ee4fd1143a67a7
Reviewed-on: https://gerrit.chromium.org/gerrit/10561
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
This commit is contained in:
Hung-Te Lin 2011-10-11 15:09:37 +08:00 committed by Gerrit
parent d1b808a6ae
commit e7c2d1c82b
2 changed files with 53 additions and 1 deletions

View File

@ -199,6 +199,7 @@ image_mount_partition() {
local part_num="$2"
local mount_point="$3"
local mount_opt="$4"
local mount_ext="$5"
local offset="$(image_part_offset "$file" "$part_num")" ||
image_die "failed to find partition #$part_num from: $file"
local size="$(image_part_size "$file" "$part_num")" ||
@ -211,6 +212,7 @@ image_mount_partition() {
sudo mount \
-o "loop,offset=$((offset * 512)),sizelimit=$((size * 512)),$mount_opt" \
$mount_ext \
"$file" \
"$mount_point"
}

View File

@ -42,6 +42,7 @@ DEFINE_string factory "" \
"Directory and file containing factory image: /path/chromiumos_test_image.bin"
DEFINE_string firmware_updater "" \
"Firmware updater (shellball) into the server configuration,"\
" or leave empty (default) for the updater in release image (--release), "\
" or '$FLAGS_NONE' to prevent running firmware updater."
DEFINE_string hwid_updater "" \
"The component list updater for HWID validation,"\
@ -75,6 +76,9 @@ USAGE: $0 [flags] args
Note environment variables with prefix MFP_ are for reserved for internal use.
"
# Internal variables
ENABLE_FIRMWARE_UPDATER=$FLAGS_TRUE
# Parse command line
FLAGS "$@" || exit 1
ORIGINAL_PARAMS="$@"
@ -137,6 +141,22 @@ check_parameters() {
check_file_param FLAGS_release ""
check_file_param FLAGS_factory ""
# Pre-parse parameter default values
case "${FLAGS_firmware_updater}" in
$FLAGS_NONE )
ENABLE_FIRMWARE_UPDATER=$FLAGS_FALSE
;;
"" )
# Empty value means "enable updater from rootfs" for all modes except
# --diskimg mode.
if [ -n "${FLAGS_diskimg}" ]; then
ENABLE_FIRMWARE_UPDATER=$FLAGS_FALSE
else
FLAGS_firmware_updater=$FLAGS_NONE
fi
;;
esac
# All remaining parameters must be checked:
# install_shim, firmware, hwid_updater, complete_script.
@ -259,6 +279,32 @@ prepare_release_image() {
fi
}
# Prepares firmware updater from specified file source or release rootfs.
prepare_firmware_updater() {
local image="$(readlink -f "$1")"
if [ -f "$FLAGS_firmware_updater" ]; then
return
fi
local fwupdater="$(mktemp --tmpdir)"
local temp_mount="$(mktemp -d --tmpdir)"
local updater_path="/usr/sbin/chromeos-firmwareupdate"
local src_file="$temp_mount$updater_path"
image_add_temp "$fwupdater"
image_add_temp "$temp_mount"
# 'ext2' is required to prevent accidentally modifying image
image_mount_partition "$image" "3" "$temp_mount" "ro" "-t ext2" ||
die "Cannot mount partition #3 (rootfs) in release image: $image"
[ -f "$src_file" ] ||
die "No firmware updater in release image: $image"
cp "$src_file" "$fwupdater" ||
die "Failed to copy firmware updater from release image $image."
image_umount_partition "$temp_mount"
info "Prepared firmware updater from release image: $image:3#$updater_path"
FLAGS_firmware_updater="$fwupdater"
}
prepare_img() {
local outdev="$(readlink -f "$FLAGS_diskimg")"
local sectors="$FLAGS_sectors"
@ -711,9 +757,13 @@ main() {
check_parameters
setup_environment
if [ "$FLAGS_detect_release_image" = "$FLAGS_TRUE" ]; then
if [ "$FLAGS_detect_release_image" = $FLAGS_TRUE ]; then
prepare_release_image "$FLAGS_release"
fi
if [ "$ENABLE_FIRMWARE_UPDATER" = $FLAGS_TRUE ]; then
prepare_firmware_updater "$FLAGS_release"
fi
if [ -n "$FLAGS_usbimg" ]; then
generate_usbimg