Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: image_to_usb.sh

Issue 3337020: image_to_usb: Add an option to install to the USB stick. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git
Patch Set: Throw error for board undefined case. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 18 matching lines...) Expand all
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 chromiumos_test_image.bin, modifies it for test."
35 DEFINE_string image_name "chromiumos_image.bin" \ 35 DEFINE_string image_name "chromiumos_image.bin" \
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."
40 DEFINE_string arch "" "Architecture of the image."
39 41
40 # Parse command line 42 # Parse command line
41 FLAGS "$@" || exit 1 43 FLAGS "$@" || exit 1
42 eval set -- "${FLAGS_ARGV}" 44 eval set -- "${FLAGS_ARGV}"
43 45
44 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then 46 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
45 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then 47 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
46 echo "Factory test image is incompatible with factory install shim." 48 echo "Factory test image is incompatible with factory install shim."
47 exit 1 49 exit 1
48 fi 50 fi
(...skipping 14 matching lines...) Expand all
63 65
64 # Die on any errors. 66 # Die on any errors.
65 set -e 67 set -e
66 68
67 # No board, no default and no image set then we can't find the image 69 # No board, no default and no image set then we can't find the image
68 if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then 70 if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then
69 setup_board_warning 71 setup_board_warning
70 exit 1 72 exit 1
71 fi 73 fi
72 74
75 # No board set during install
76 if [ -z "${FLAGS_board}" ] && [ ${FLAGS_install} -eq ${FLAGS_TRUE} ]; then
77 setup_board_warning
78 exit 1
79 fi
80
73 # 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
74 if [ -z "${FLAGS_from}" ]; then 82 if [ -z "${FLAGS_from}" ]; then
75 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" 83 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
76 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" 84 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)"
77 fi 85 fi
78 86
79 if [ ! -d "${FLAGS_from}" ] ; then 87 if [ ! -d "${FLAGS_from}" ] ; then
80 echo "Cannot find image directory ${FLAGS_from}" 88 echo "Cannot find image directory ${FLAGS_from}"
81 exit 1 89 exit 1
82 fi 90 fi
83 91
84 if [ "${FLAGS_to}" == "/dev/sdX" ]; then 92 if [ "${FLAGS_to}" == "/dev/sdX" ]; then
85 echo "You must specify a file or device to write to using --to." 93 echo "You must specify a file or device to write to using --to."
86 disks=$(list_usb_disks) 94 disks=$(list_usb_disks)
87 if [ -n "$disks" ]; then 95 if [ -n "$disks" ]; then
88 echo "Available USB disks:" 96 echo "Available USB disks:"
89 for disk in $disks; do 97 for disk in $disks; do
90 echo " /dev/$disk:" 98 echo " /dev/$disk:"
91 echo " Manufacturer: $(get_disk_info $disk manufacturer)" 99 echo " Manufacturer: $(get_disk_info $disk manufacturer)"
92 echo " Product: $(get_disk_info $disk product)" 100 echo " Product: $(get_disk_info $disk product)"
93 echo " Size: $[$(cat /sys/block/$disk/size) * 512] bytes" 101 echo " Size: $[$(cat /sys/block/$disk/size) * 512] bytes"
94 done 102 done
95 fi 103 fi
96 exit 1 104 exit 1
97 fi 105 fi
98 106
107 # Guess ARCH if it's unset
108 if [ "${FLAGS_arch}" = "" ]; then
109 if echo "${FLAGS_board}" | grep -qs "x86"; then
110 FLAGS_arch=INTEL
111 else
112 FLAGS_arch=ARM
113 fi
114 fi
115
99 # Convert args to paths. Need eval to un-quote the string so that shell 116 # Convert args to paths. Need eval to un-quote the string so that shell
100 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. 117 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work.
101 FLAGS_from=`eval readlink -f ${FLAGS_from}` 118 FLAGS_from=`eval readlink -f ${FLAGS_from}`
102 FLAGS_to=`eval readlink -f ${FLAGS_to}` 119 FLAGS_to=`eval readlink -f ${FLAGS_to}`
103 120
104 # One last check to make sure user is not shooting themselves in the foot 121 # One last check to make sure user is not shooting themselves in the foot
105 if [ -b "${FLAGS_to}" ]; then 122 if [ -b "${FLAGS_to}" ]; then
106 if list_usb_disks | grep -q '^'${FLAGS_to##*/}'$'; then 123 if list_usb_disks | grep -q '^'${FLAGS_to##*/}'$'; then
107 disk_manufacturer=$(get_disk_info ${FLAGS_to##*/} manufacturer) 124 disk_manufacturer=$(get_disk_info ${FLAGS_to##*/} manufacturer)
108 disk_product=$(get_disk_info ${FLAGS_to##*/} product) 125 disk_product=$(get_disk_info ${FLAGS_to##*/} product)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 fi 179 fi
163 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" 180 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin"
164 echo "Source test image is: ${SRC_IMAGE}" 181 echo "Source test image is: ${SRC_IMAGE}"
165 fi 182 fi
166 183
167 184
168 # Let's do it. 185 # Let's do it.
169 if [ -b "${FLAGS_to}" ] 186 if [ -b "${FLAGS_to}" ]
170 then 187 then
171 # Output to a block device (i.e., a real USB key), so need sudo dd 188 # Output to a block device (i.e., a real USB key), so need sudo dd
172 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." 189 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then
190 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..."
191 else
192 echo "Installing USB image ${SRC_IMAGE} to device ${FLAGS_to}..."
193 fi
173 194
174 # Warn if it looks like they supplied a partition as the destination. 195 # Warn if it looks like they supplied a partition as the destination.
175 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then 196 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then
176 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') 197 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//')
177 if [ -b "${drive}" ]; then 198 if [ -b "${drive}" ]; then
178 echo 199 echo
179 echo "NOTE: It looks like you may have supplied a partition as the " 200 echo "NOTE: It looks like you may have supplied a partition as the "
180 echo "destination. This script needs to write to the drive's device " 201 echo "destination. This script needs to write to the drive's device "
181 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." 202 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})."
182 echo 203 echo
(...skipping 23 matching lines...) Expand all
206 echo 227 echo
207 echo "The device you have specified is already mounted at some point " 228 echo "The device you have specified is already mounted at some point "
208 echo "that is not visible from inside the chroot. Please unmount the " 229 echo "that is not visible from inside the chroot. Please unmount the "
209 echo "device manually from outside the chroot and try again." 230 echo "device manually from outside the chroot and try again."
210 echo 231 echo
211 exit 1 232 exit 1
212 fi 233 fi
213 done 234 done
214 sleep 3 235 sleep 3
215 236
216 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." 237 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then
217 sudo dd if="${SRC_IMAGE}" of="${FLAGS_to}" bs=4M 238 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..."
218 sync 239 sudo dd if="${SRC_IMAGE}" of="${FLAGS_to}" bs=4M
240 sync
241 else
242 if [ ${INSIDE_CHROOT} -ne 1 ]; then
243 echo "Installation must be done from inside the chroot."
244 exit 1
245 fi
246 #TODO(kwaters): fix when verified root works on ARM
247 [ "${FLAGS_arch}" = "ARM" ] && SKIP_VBLOCK="--skip_vblock"
219 248
249 echo "Installing ${SRC_IMAGE} to ${FLAGS_to}..."
250 "${FLAGS_build_root}/${FLAGS_board}/usr/sbin/chromeos-install" \
251 --yes \
252 --skip_src_removable \
253 --skip_dst_removable \
254 ${SKIP_VBLOCK:-} \
255 --arch="${FLAGS_arch}" \
256 --payload_image="${SRC_IMAGE}" \
257 --dst="${FLAGS_to}"
258 fi
220 echo "Done." 259 echo "Done."
221 else 260 else
222 # Output to a file, so just make a copy. 261 # Output to a file, so just make a copy.
223 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." 262 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..."
224 cp -f "${SRC_IMAGE}" "${FLAGS_to}" 263 cp -f "${SRC_IMAGE}" "${FLAGS_to}"
225 264
226 echo "Done. To copy to a USB drive, outside the chroot, do something like:" 265 echo "Done. To copy to a USB drive, outside the chroot, do something like:"
227 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" 266 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M"
228 echo "where /dev/sdX is the entire drive." 267 echo "where /dev/sdX is the entire drive."
229 if [ ${INSIDE_CHROOT} -eq 1 ] 268 if [ ${INSIDE_CHROOT} -eq 1 ]
230 then 269 then
231 example=$(basename "${FLAGS_to}") 270 example=$(basename "${FLAGS_to}")
232 echo "NOTE: Since you are currently inside the chroot, and you'll need to" 271 echo "NOTE: Since you are currently inside the chroot, and you'll need to"
233 echo "run dd outside the chroot, the path to the USB image will be" 272 echo "run dd outside the chroot, the path to the USB image will be"
234 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." 273 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)."
235 fi 274 fi
236 fi 275 fi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698