diff --git a/lib/cros_image_common.sh b/lib/cros_image_common.sh index d550240889..cd278b809a 100644 --- a/lib/cros_image_common.sh +++ b/lib/cros_image_common.sh @@ -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" } diff --git a/make_factory_package.sh b/make_factory_package.sh index 0d2e8ecac8..477cace5d8 100755 --- a/make_factory_package.sh +++ b/make_factory_package.sh @@ -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