diff --git a/common.sh b/common.sh index 6b55b707dc..a11f257289 100644 --- a/common.sh +++ b/common.sh @@ -14,14 +14,6 @@ # and dpkg-buildpackage NUM_JOBS=`grep -c "^processor" /proc/cpuinfo` -# True if we have the 'pv' utility - also set up COMMON_PV_CAT for convenience -COMMON_PV_OK=1 -COMMON_PV_CAT=pv -pv -V >/dev/null 2>&1 || COMMON_PV_OK=0 -if [ $COMMON_PV_OK -eq 0 ]; then - COMMON_PV_CAT=cat -fi - # Store location of the calling script. TOP_SCRIPT_DIR="${TOP_SCRIPT_DIR:-$(dirname $0)}" @@ -132,12 +124,6 @@ else INSIDE_CHROOT=0 fi - -# Standard filenames -CHROMEOS_IMAGE_NAME="chromiumos_image.bin" -CHROMEOS_TEST_IMAGE_NAME="chromiumos_test_image.bin" - - # Directory locations inside the dev chroot CHROOT_TRUNK_DIR="/home/$USER/trunk" @@ -541,46 +527,3 @@ chroot_hacks_from_outside() { sudo bash -c "echo root ALL=\(ALL\) ALL >> \"${chroot_dir}/etc/sudoers\"" fi } - -# This function converts a chromiumos image into a test image, either -# in place or by copying to a new test image filename first. It honors -# the following flags (see mod_image_for_test.sh) -# -# --factory -# --factory_install -# --force_copy -# -# On entry, pass the directory containing the image, and the image filename -# On exit, it puts the pathname of the resulting test image into -# CHROMEOS_RETURN_VAL -# (yes this is ugly, but perhaps less ugly than the alternatives) -# -# Usage: -# SRC_IMAGE=$(prepare_test_image "directory" "imagefile") -prepare_test_image() { - # If we're asked to modify the image for test, then let's make a copy and - # modify that instead. - # Check for manufacturing image. - local args - - if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then - args="--factory" - fi - - # Check for install shim. - if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then - args="--factory_install" - fi - - # Check for forcing copy of image - if [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ]; then - args="${args} --force_copy" - fi - - # Modify the image for test, creating a new test image - "${SCRIPTS_DIR}/mod_image_for_test.sh" --board=${FLAGS_board} \ - --image="$1/$2" --noinplace ${args} - - # From now on we use the just-created test image - CHROMEOS_RETURN_VAL="$1/${CHROMEOS_TEST_IMAGE_NAME}" -} diff --git a/image_to_usb.sh b/image_to_usb.sh index 4b32ff8f88..19eefb1f63 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Copyright (c) 2009 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -18,7 +18,7 @@ get_default_board # Flags DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" DEFINE_string from "" \ - "Directory containing ${CHROMEOS_IMAGE_NAME}" + "Directory containing chromiumos_image.bin" DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" @@ -31,8 +31,8 @@ DEFINE_boolean factory ${FLAGS_FALSE} \ DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ "Copy the kernel to the fourth partition." DEFINE_boolean test_image "${FLAGS_FALSE}" \ - "Copies normal image to ${CHROMEOS_TEST_IMAGE_NAME}, modifies it for test." -DEFINE_string image_name "${CHROMEOS_IMAGE_NAME}" \ + "Copies normal image to chromiumos_test_image.bin, modifies it for test." +DEFINE_string image_name "chromiumos_image.bin" \ "Base name of the image" i DEFINE_string build_root "/build" \ "The root location for board sysroots." @@ -81,8 +81,6 @@ fi # We have a board name but no image set. Use image at default location if [ -z "${FLAGS_from}" ]; then IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" - - # Get latest image directory FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" fi @@ -133,6 +131,9 @@ if [ -b "${FLAGS_to}" ]; then fi fi +# Use this image as the source image to copy +SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" + STATEFUL_DIR="${FLAGS_from}/stateful_partition" mkdir -p "${STATEFUL_DIR}" @@ -146,18 +147,41 @@ function do_cleanup { fi } -if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then - # Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL - prepare_test_image "${FLAGS_from}" "${FLAGS_image_name}" - SRC_IMAGE="${CHROMEOS_RETURN_VAL}" - # No need to check with the user, as we are preserving the base image - FLAGS_yes="${FLAGS_TRUE}" -else - # Use the standard image - SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" +# If we're asked to modify the image for test, then let's make a copy and +# modify that instead. +if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then + if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ + [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then + # Copy it. + echo "Creating test image from original..." + cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" + + # Check for manufacturing image. + if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then + EXTRA_ARGS="--factory" + fi + + # Check for instqall shim. + if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then + EXTRA_ARGS="--factory_install" + fi + + # Modify it. Pass --yes so that mod_image_for_test.sh won't ask us if we + # really want to modify the image; the user gave their assent already with + # --test-image and the original image is going to be preserved. + "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \ + "${FLAGS_from}/chromiumos_test_image.bin" --board=${FLAGS_board} \ + ${EXTRA_ARGS} --yes + echo "Done with mod_image_for_test." + else + echo "Using cached test image." + fi + SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" + echo "Source test image is: ${SRC_IMAGE}" fi + # Let's do it. if [ -b "${FLAGS_to}" ] then @@ -211,9 +235,15 @@ then sleep 3 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then - echo "Copying with dd ${SRC_IMAGE} to ${FLAGS_to}..." - sudo ${COMMON_PV_CAT} "${SRC_IMAGE}" | - sudo dd of="${FLAGS_to}" bs=4M oflag=sync status=noxfer + echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." + if type pv >/dev/null 2>&1; then + # pv displays file size in k=1024 while dd uses k=1000. + # To prevent confusion, we suppress the summary report from dd. + sudo pv -ptreb -B 4m "${SRC_IMAGE}" | + sudo dd of="${FLAGS_to}" bs=4M oflag=sync status=noxfer + else + sudo dd if="${SRC_IMAGE}" of="${FLAGS_to}" bs=4M oflag=sync + fi sync else if [ ${INSIDE_CHROOT} -ne 1 ]; then @@ -234,7 +264,7 @@ then else # Output to a file, so just make a copy. echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." - ${COMMON_PV_CAT} "${SRC_IMAGE}" >"${FLAGS_to}" + cp -f "${SRC_IMAGE}" "${FLAGS_to}" echo "Done. To copy to a USB drive, do something like:" echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync" diff --git a/image_to_vm.sh b/image_to_vm.sh index 12f421a95e..2ff4984607 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -10,8 +10,6 @@ # Load common constants. This should be the first executable line. # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" - -# Load functions and constants for chromeos-install . "$(dirname "$0")/chromeos-common.sh" . "$(dirname "$0")/lib/cros_vm_constants.sh" @@ -42,7 +40,7 @@ DEFINE_string state_image "" \ DEFINE_integer statefulfs_size 2048 \ "Stateful partition size in MBs." DEFINE_boolean test_image "${FLAGS_FALSE}" \ - "Copies normal image to ${CHROMEOS_TEST_IMAGE_NAME}, modifies it for test." + "Copies normal image to chromiumos_test_image.bin, modifies it for test." DEFINE_string to "" \ "Destination folder for VM output file(s)" DEFINE_string vbox_disk "${DEFAULT_VBOX_DISK}" \ @@ -86,13 +84,39 @@ if [ -z "${FLAGS_to}" ] ; then FLAGS_to="${FLAGS_from}" fi +# Use this image as the source image to copy +SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" + +# If we're asked to modify the image for test, then let's make a copy and +# modify that instead. if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then - # Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL - prepare_test_image "${FLAGS_from}" "${CHROMEOS_IMAGE_NAME}" - SRC_IMAGE="${CHROMEOS_RETURN_VAL}" -else - # Use the standard image - SRC_IMAGE="${FLAGS_from}/${CHROMEOS_IMAGE_NAME}" + if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ + [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then + # Copy it. + echo "Creating test image from original..." + cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" + + # Check for manufacturing image. + if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then + EXTRA_ARGS="--factory" + fi + + # Check for install shim. + if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then + EXTRA_ARGS="--factory_install" + fi + + # Modify it. Pass --yes so that mod_image_for_test.sh won't ask us if we + # really want to modify the image; the user gave their assent already with + # --test-image and the original image is going to be preserved. + "${SCRIPTS_DIR}/mod_image_for_test.sh" --board=${FLAGS_board} --image \ + "${FLAGS_from}/chromiumos_test_image.bin" ${EXTRA_ARGS} --yes + echo "Done with mod_image_for_test." + else + echo "Using cached test image." + fi + SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" + echo "Source test image is: ${SRC_IMAGE}" fi # Memory units are in MBs diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 52bd99d3a7..97aa5e0cc7 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -33,12 +33,6 @@ DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y DEFINE_string build_root "/build" \ "The root location for board sysroots." DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" -DEFINE_boolean inplace $FLAGS_TRUE \ - "Modify/overwrite the image ${CHROMEOS_IMAGE_NAME} in place. \ -Otherwise the image will be copied to ${CHROMEOS_TEST_IMAGE_NAME} \ -if needed, and modified there" -DEFINE_boolean force_copy ${FLAGS_FALSE} \ - "Always rebuild test image if --noinplace" # Parse command line @@ -62,7 +56,7 @@ fi # We have a board name but no image set. Use image at default location if [ -z $FLAGS_image ] ; then IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" - FILENAME="${CHROMEOS_IMAGE_NAME}" + FILENAME="chromiumos_image.bin" FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}" fi @@ -161,25 +155,6 @@ install_autotest() { # main process begins here. -IMAGE_DIR="$(dirname "${FLAGS_image}")" - -# Copy the image to a test location if required -if [ ${FLAGS_inplace} -eq ${FLAGS_FALSE} ]; then - TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_TEST_IMAGE_NAME}" - if [ ! -f "${TEST_PATHNAME}" ] || \ - [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then - echo "Creating test image from original..." - ${COMMON_PV_CAT} "${FLAGS_image}" >"${TEST_PATHNAME}" \ - || die "Cannot copy ${FLAGS_image} to test image" - FLAGS_image="${TEST_PATHNAME}" - else - echo "Using cached test image" - fi - - # No need to confirm now, since we are not overwriting the main image - FLAGS_yes="$FLAGS_TRUE" -fi - # Make sure this is really what the user wants, before nuking the device if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE