OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
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 chromiumos_image.bin" |
22 DEFINE_string to "" "${DEFAULT_TO_HELP}" | 22 DEFINE_string to "" "${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} \ |
| 26 "Write out image even if target (--to) doesn't look like a USB disk" |
25 DEFINE_boolean factory_install ${FLAGS_FALSE} \ | 27 DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
26 "Whether to generate a factory install shim." | 28 "Whether to generate a factory install shim." |
27 DEFINE_boolean factory ${FLAGS_FALSE} \ | 29 DEFINE_boolean factory ${FLAGS_FALSE} \ |
28 "Whether to generate a factory runin image. Implies aututest and test" | 30 "Whether to generate a factory runin image. Implies aututest and test" |
29 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ | 31 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ |
30 "Copy the kernel to the fourth partition." | 32 "Copy the kernel to the fourth partition." |
31 DEFINE_boolean test_image "${FLAGS_FALSE}" \ | 33 DEFINE_boolean test_image "${FLAGS_FALSE}" \ |
32 "Copies normal image to chromiumos_test_image.bin, modifies it for test." | 34 "Copies normal image to chromiumos_test_image.bin, modifies it for test." |
33 DEFINE_string image_name "chromiumos_image.bin" \ | 35 DEFINE_string image_name "chromiumos_image.bin" \ |
34 "Base name of the image" i | 36 "Base name of the image" i |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" | 76 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" |
75 fi | 77 fi |
76 | 78 |
77 if [ ! -d "${FLAGS_from}" ] ; then | 79 if [ ! -d "${FLAGS_from}" ] ; then |
78 echo "Cannot find image directory ${FLAGS_from}" | 80 echo "Cannot find image directory ${FLAGS_from}" |
79 exit 1 | 81 exit 1 |
80 fi | 82 fi |
81 | 83 |
82 if [ -z "${FLAGS_to}" ]; then | 84 if [ -z "${FLAGS_to}" ]; then |
83 echo "You must specify a file or device to write to using --to." | 85 echo "You must specify a file or device to write to using --to." |
| 86 disks=$(list_usb_disks) |
| 87 if [ -n "$disks" ]; then |
| 88 echo "Available USB disks:" |
| 89 for disk in $disks; do |
| 90 echo " /dev/$disk:" |
| 91 echo " Manufacturer: $(get_disk_info $disk manufacturer)" |
| 92 echo " Product: $(get_disk_info $disk product)" |
| 93 done |
| 94 fi |
84 exit 1 | 95 exit 1 |
85 fi | 96 fi |
86 | 97 |
87 # Convert args to paths. Need eval to un-quote the string so that shell | 98 # Convert args to paths. Need eval to un-quote the string so that shell |
88 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. | 99 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. |
89 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 100 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
90 FLAGS_to=`eval readlink -f ${FLAGS_to}` | 101 FLAGS_to=`eval readlink -f ${FLAGS_to}` |
91 | 102 |
| 103 # One last check to make sure user is not shooting themselves in the foot |
| 104 if [ -b "${FLAGS_to}" ] && |
| 105 ! list_usb_disks | grep -q '^'${FLAGS_to##*/}'$' && |
| 106 [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ] |
| 107 then |
| 108 # Safeguard against writing to a real non-USB disk |
| 109 echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!" |
| 110 echo " To override this safeguard, use the --force_non_usb flag" |
| 111 exit 1 |
| 112 fi |
| 113 |
92 # Use this image as the source image to copy | 114 # Use this image as the source image to copy |
93 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" | 115 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" |
94 | 116 |
95 STATEFUL_DIR="${FLAGS_from}/stateful_partition" | 117 STATEFUL_DIR="${FLAGS_from}/stateful_partition" |
96 mkdir -p "${STATEFUL_DIR}" | 118 mkdir -p "${STATEFUL_DIR}" |
97 | 119 |
98 function do_cleanup { | 120 function do_cleanup { |
99 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" | 121 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" |
100 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then | 122 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then |
101 sudo umount "${STATEFUL_DIR}" | 123 sudo umount "${STATEFUL_DIR}" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" | 220 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" |
199 echo "where /dev/sdX is the entire drive." | 221 echo "where /dev/sdX is the entire drive." |
200 if [ ${INSIDE_CHROOT} -eq 1 ] | 222 if [ ${INSIDE_CHROOT} -eq 1 ] |
201 then | 223 then |
202 example=$(basename "${FLAGS_to}") | 224 example=$(basename "${FLAGS_to}") |
203 echo "NOTE: Since you are currently inside the chroot, and you'll need to" | 225 echo "NOTE: Since you are currently inside the chroot, and you'll need to" |
204 echo "run dd outside the chroot, the path to the USB image will be" | 226 echo "run dd outside the chroot, the path to the USB image will be" |
205 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." | 227 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." |
206 fi | 228 fi |
207 fi | 229 fi |
OLD | NEW |