Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
|
sosa
2010/11/30 22:01:43
2009-2010
| |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Script to convert the output of build_image.sh to a usb image. | 7 # Script to convert the output of build_image.sh to a usb image. |
| 8 | 8 |
| 9 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
| 10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
| 11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
| 12 | 12 |
| 13 # Load functions and constants for chromeos-install | 13 # Load functions and constants for chromeos-install |
| 14 . "$(dirname "$0")/chromeos-common.sh" | 14 . "$(dirname "$0")/chromeos-common.sh" |
| 15 | 15 |
| 16 get_default_board | 16 get_default_board |
| 17 | 17 |
| 18 # Flags | 18 # Flags |
| 19 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" | 19 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" |
| 20 DEFINE_string from "" \ | 20 DEFINE_string from "" \ |
| 21 "Directory containing chromiumos_image.bin" | 21 "Directory containing ${CHROMEOS_IMAGE_NAME}" |
| 22 DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" | 22 DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" |
| 23 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" | 23 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" |
| 24 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" | 24 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" |
| 25 DEFINE_boolean force_non_usb ${FLAGS_FALSE} \ | 25 DEFINE_boolean force_non_usb ${FLAGS_FALSE} \ |
| 26 "Write out image even if target (--to) doesn't look like a USB disk" | 26 "Write out image even if target (--to) doesn't look like a USB disk" |
| 27 DEFINE_boolean factory_install ${FLAGS_FALSE} \ | 27 DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
| 28 "Whether to generate a factory install shim." | 28 "Whether to generate a factory install shim." |
| 29 DEFINE_boolean factory ${FLAGS_FALSE} \ | 29 DEFINE_boolean factory ${FLAGS_FALSE} \ |
| 30 "Whether to generate a factory runin image. Implies aututest and test" | 30 "Whether to generate a factory runin image. Implies aututest and test" |
| 31 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ | 31 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ |
| 32 "Copy the kernel to the fourth partition." | 32 "Copy the kernel to the fourth partition." |
| 33 DEFINE_boolean test_image "${FLAGS_FALSE}" \ | 33 DEFINE_boolean test_image "${FLAGS_FALSE}" \ |
| 34 "Copies normal image to chromiumos_test_image.bin, modifies it for test." | 34 "Copies normal image to ${CHROMEOS_TEST_IMAGE_NAME}, modifies it for test." |
| 35 DEFINE_string image_name "chromiumos_image.bin" \ | 35 DEFINE_string image_name "${CHROMEOS_IMAGE_NAME}" \ |
| 36 "Base name of the image" i | 36 "Base name of the image" i |
| 37 DEFINE_string build_root "/build" \ | 37 DEFINE_string build_root "/build" \ |
| 38 "The root location for board sysroots." | 38 "The root location for board sysroots." |
| 39 DEFINE_boolean install ${FLAGS_FALSE} "Install to the usb device." | 39 DEFINE_boolean install ${FLAGS_FALSE} "Install to the usb device." |
| 40 DEFINE_string arch "" "Architecture of the image." | 40 DEFINE_string arch "" "Architecture of the image." |
| 41 | 41 |
| 42 # Parse command line | 42 # Parse command line |
| 43 FLAGS "$@" || exit 1 | 43 FLAGS "$@" || exit 1 |
| 44 eval set -- "${FLAGS_ARGV}" | 44 eval set -- "${FLAGS_ARGV}" |
| 45 | 45 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 74 | 74 |
| 75 # No board set during install | 75 # No board set during install |
| 76 if [ -z "${FLAGS_board}" ] && [ ${FLAGS_install} -eq ${FLAGS_TRUE} ]; then | 76 if [ -z "${FLAGS_board}" ] && [ ${FLAGS_install} -eq ${FLAGS_TRUE} ]; then |
| 77 setup_board_warning | 77 setup_board_warning |
| 78 exit 1 | 78 exit 1 |
| 79 fi | 79 fi |
| 80 | 80 |
| 81 # We have a board name but no image set. Use image at default location | 81 # We have a board name but no image set. Use image at default location |
| 82 if [ -z "${FLAGS_from}" ]; then | 82 if [ -z "${FLAGS_from}" ]; then |
| 83 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 83 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
| 84 | |
| 85 # get latest image directory | |
|
sosa
2010/11/30 22:01:43
s/get/Get
| |
| 84 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" | 86 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" |
| 85 fi | 87 fi |
| 86 | 88 |
| 87 if [ ! -d "${FLAGS_from}" ] ; then | 89 if [ ! -d "${FLAGS_from}" ] ; then |
| 88 echo "Cannot find image directory ${FLAGS_from}" | 90 echo "Cannot find image directory ${FLAGS_from}" |
| 89 exit 1 | 91 exit 1 |
| 90 fi | 92 fi |
| 91 | 93 |
| 92 if [ "${FLAGS_to}" == "/dev/sdX" ]; then | 94 if [ "${FLAGS_to}" == "/dev/sdX" ]; then |
| 93 echo "You must specify a file or device to write to using --to." | 95 echo "You must specify a file or device to write to using --to." |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 124 disk_manufacturer=$(get_disk_info ${FLAGS_to##*/} manufacturer) | 126 disk_manufacturer=$(get_disk_info ${FLAGS_to##*/} manufacturer) |
| 125 disk_product=$(get_disk_info ${FLAGS_to##*/} product) | 127 disk_product=$(get_disk_info ${FLAGS_to##*/} product) |
| 126 elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then | 128 elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then |
| 127 # Safeguard against writing to a real non-USB disk | 129 # Safeguard against writing to a real non-USB disk |
| 128 echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!" | 130 echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!" |
| 129 echo " To override this safeguard, use the --force_non_usb flag" | 131 echo " To override this safeguard, use the --force_non_usb flag" |
| 130 exit 1 | 132 exit 1 |
| 131 fi | 133 fi |
| 132 fi | 134 fi |
| 133 | 135 |
| 134 # Use this image as the source image to copy | |
| 135 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" | |
| 136 | |
| 137 STATEFUL_DIR="${FLAGS_from}/stateful_partition" | 136 STATEFUL_DIR="${FLAGS_from}/stateful_partition" |
| 138 mkdir -p "${STATEFUL_DIR}" | 137 mkdir -p "${STATEFUL_DIR}" |
| 139 | 138 |
| 140 function do_cleanup { | 139 function do_cleanup { |
| 141 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" | 140 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" |
| 142 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then | 141 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then |
| 143 sudo umount "${STATEFUL_DIR}" | 142 sudo umount "${STATEFUL_DIR}" |
| 144 sudo losetup -d "${STATEFUL_LOOP_DEV}" | 143 sudo losetup -d "${STATEFUL_LOOP_DEV}" |
| 145 rmdir "${STATEFUL_DIR}" | 144 rmdir "${STATEFUL_DIR}" |
| 146 echo "Cleaned" | 145 echo "Cleaned" |
| 147 fi | 146 fi |
| 148 } | 147 } |
| 149 | 148 |
| 149 # Use this image as the source image to copy | |
| 150 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" | |
|
sjg
2010/11/30 21:07:29
This was moved to make the script more similar to
| |
| 150 | 151 |
| 151 # If we're asked to modify the image for test, then let's make a copy and | |
| 152 # modify that instead. | |
| 153 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then | 152 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then |
| 154 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ | 153 # make a test image as requested, this will modify SRC_IMAGE |
|
sosa
2010/11/30 22:01:43
s/make/Make also why are we modifying the src imag
sjg
2010/12/01 00:57:05
We will change it to point to the test image.
| |
| 155 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then | 154 prepare_test_image |
| 156 # Copy it. | |
| 157 echo "Creating test image from original..." | |
| 158 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" | |
| 159 | |
| 160 # Check for manufacturing image. | |
| 161 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then | |
| 162 EXTRA_ARGS="--factory" | |
| 163 fi | |
| 164 | |
| 165 # Check for instqall shim. | |
| 166 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then | |
| 167 EXTRA_ARGS="--factory_install" | |
| 168 fi | |
| 169 | |
| 170 # Modify it. Pass --yes so that mod_image_for_test.sh won't ask us if we | |
| 171 # really want to modify the image; the user gave their assent already with | |
| 172 # --test-image and the original image is going to be preserved. | |
| 173 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \ | |
| 174 "${FLAGS_from}/chromiumos_test_image.bin" --board=${FLAGS_board} \ | |
| 175 ${EXTRA_ARGS} --yes | |
| 176 echo "Done with mod_image_for_test." | |
| 177 else | |
| 178 echo "Using cached test image." | |
| 179 fi | |
| 180 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | |
| 181 echo "Source test image is: ${SRC_IMAGE}" | |
| 182 fi | 155 fi |
| 183 | 156 |
| 184 | |
| 185 # Let's do it. | 157 # Let's do it. |
| 186 if [ -b "${FLAGS_to}" ] | 158 if [ -b "${FLAGS_to}" ] |
| 187 then | 159 then |
| 188 # Output to a block device (i.e., a real USB key), so need sudo dd | 160 # Output to a block device (i.e., a real USB key), so need sudo dd |
| 189 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then | 161 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then |
| 190 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." | 162 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." |
| 191 else | 163 else |
| 192 echo "Installing USB image ${SRC_IMAGE} to device ${FLAGS_to}..." | 164 echo "Installing USB image ${SRC_IMAGE} to device ${FLAGS_to}..." |
| 193 fi | 165 fi |
| 194 | 166 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 echo "Done." | 235 echo "Done." |
| 264 else | 236 else |
| 265 # Output to a file, so just make a copy. | 237 # Output to a file, so just make a copy. |
| 266 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." | 238 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." |
| 267 cp -f "${SRC_IMAGE}" "${FLAGS_to}" | 239 cp -f "${SRC_IMAGE}" "${FLAGS_to}" |
| 268 | 240 |
| 269 echo "Done. To copy to a USB drive, do something like:" | 241 echo "Done. To copy to a USB drive, do something like:" |
| 270 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync" | 242 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync" |
| 271 echo "where /dev/sdX is the entire drive." | 243 echo "where /dev/sdX is the entire drive." |
| 272 fi | 244 fi |
| OLD | NEW |