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

Side by Side Diff: src/scripts/image_to_usb.sh

Issue 1542011: Allow boot directly into mfg test. (Closed)
Patch Set: check that CL is attached to tracker Created 10 years, 8 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
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.
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"
25 DEFINE_boolean factory ${FLAGS_FALSE} \
26 "Whether to generate a factory runin image. Implies aututest and test"
24 DEFINE_boolean install_autotest ${FLAGS_FALSE} \ 27 DEFINE_boolean install_autotest ${FLAGS_FALSE} \
25 "Whether to install autotest to the stateful partition." 28 "Whether to install autotest to the stateful partition."
26 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ 29 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \
27 "Copy the kernel to the fourth partition." 30 "Copy the kernel to the fourth partition."
28 DEFINE_boolean test_image "${FLAGS_FALSE}" \ 31 DEFINE_boolean test_image "${FLAGS_FALSE}" \
29 "Copies normal image to chromiumos_test_image.bin, modifies it for test." 32 "Copies normal image to chromiumos_test_image.bin, modifies it for test."
30 DEFINE_string build_root "/build" \ 33 DEFINE_string build_root "/build" \
31 "The root location for board sysroots." 34 "The root location for board sysroots."
32 35
33 # Parse command line 36 # Parse command line
34 FLAGS "$@" || exit 1 37 FLAGS "$@" || exit 1
35 eval set -- "${FLAGS_ARGV}" 38 eval set -- "${FLAGS_ARGV}"
36 39
40 # Require autotest for manucaturing image.
41 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
42 echo "Factory image requires --install_autotest and --test_image, setting."
43 FLAGS_install_autotest=${FLAGS_TRUE}
44 FLAGS_test_image=${FLAGS_TRUE}
45 fi
46
37 # Inside the chroot, so output to usb.img in the same dir as the other 47 # Inside the chroot, so output to usb.img in the same dir as the other
38 # Script can be run either inside or outside the chroot. 48 # Script can be run either inside or outside the chroot.
39 if [ ${INSIDE_CHROOT} -eq 1 ] 49 if [ ${INSIDE_CHROOT} -eq 1 ]
40 then 50 then
41 SYSROOT="${FLAGS_build_root}/${FLAGS_board}" 51 SYSROOT="${FLAGS_build_root}/${FLAGS_board}"
42 else 52 else
43 SYSROOT="${DEFAULT_CHROOT_DIR}${FLAGS_build_root}/${FLAGS_board}" 53 SYSROOT="${DEFAULT_CHROOT_DIR}${FLAGS_build_root}/${FLAGS_board}"
44 fi 54 fi
45 AUTOTEST_SRC="${SYSROOT}/usr/local/autotest" 55 AUTOTEST_SRC="${SYSROOT}/usr/local/autotest"
46 56
(...skipping 30 matching lines...) Expand all
77 # Outside the chroot, so output to the default device for a usb key. 87 # Outside the chroot, so output to the default device for a usb key.
78 FLAGS_to="/dev/sdb" 88 FLAGS_to="/dev/sdb"
79 fi 89 fi
80 fi 90 fi
81 91
82 # Convert args to paths. Need eval to un-quote the string so that shell 92 # Convert args to paths. Need eval to un-quote the string so that shell
83 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. 93 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work.
84 FLAGS_from=`eval readlink -f ${FLAGS_from}` 94 FLAGS_from=`eval readlink -f ${FLAGS_from}`
85 FLAGS_to=`eval readlink -f ${FLAGS_to}` 95 FLAGS_to=`eval readlink -f ${FLAGS_to}`
86 96
97 # Done evaluating arguments, lets go!
98 echo "Caching sudo authentication"
99 sudo -v
100 echo "Done"
101
87 # Use this image as the source image to copy 102 # Use this image as the source image to copy
88 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" 103 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin"
89 104
90 # If we're asked to modify the image for test, then let's make a copy and 105 # If we're asked to modify the image for test, then let's make a copy and
91 # modify that instead. 106 # modify that instead.
92 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then 107 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then
93 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] ; then 108 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \
109 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then
94 # Copy it. 110 # Copy it.
95 echo "Creating test image from original..." 111 echo "Creating test image from original..."
96 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" 112 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin"
113
114 # Check for manufacturing image.
115 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
116 FACTORY_ARGS="--factory"
117 fi
118 # Check for yes
119 if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ] ; then
120 YES="--yes"
121 fi
122
123
97 # Modify it. 124 # Modify it.
98 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \ 125 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \
99 "${FLAGS_from}/chromiumos_test_image.bin" --yes 126 "${FLAGS_from}/chromiumos_test_image.bin" ${FACTORY_ARGS} ${YES}
127 echo "Done with mod_image_for_test."
128 else
129 echo "Using cached test image."
100 fi 130 fi
101 # Use it.
102 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" 131 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin"
132 echo "Source test image is: ${SRC_IMAGE}"
103 fi 133 fi
104 134
105 STATEFUL_DIR="${FLAGS_from}/stateful_partition" 135 STATEFUL_DIR="${FLAGS_from}/stateful_partition"
106 mkdir -p "${STATEFUL_DIR}" 136 mkdir -p "${STATEFUL_DIR}"
107 137
108 function do_cleanup { 138 function do_cleanup {
109 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" 139 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}"
110 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then 140 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then
111 sudo umount "${STATEFUL_DIR}" 141 sudo umount "${STATEFUL_DIR}"
112 sudo losetup -d "${STATEFUL_LOOP_DEV}" 142 sudo losetup -d "${STATEFUL_LOOP_DEV}"
(...skipping 20 matching lines...) Expand all
133 trap do_cleanup INT TERM EXIT 163 trap do_cleanup INT TERM EXIT
134 164
135 echo "Mounting ${STATEFUL_DIR} loopback" 165 echo "Mounting ${STATEFUL_DIR} loopback"
136 sudo losetup -o $(( $offset * 512 )) "${stateful_loop_dev}" "${SRC_IMAGE}" 166 sudo losetup -o $(( $offset * 512 )) "${stateful_loop_dev}" "${SRC_IMAGE}"
137 sudo mount "${stateful_loop_dev}" "${STATEFUL_DIR}" 167 sudo mount "${stateful_loop_dev}" "${STATEFUL_DIR}"
138 stateful_root="${STATEFUL_DIR}/dev_image" 168 stateful_root="${STATEFUL_DIR}/dev_image"
139 169
140 echo "Install autotest into stateful partition..." 170 echo "Install autotest into stateful partition..."
141 autotest_client="/home/autotest-client" 171 autotest_client="/home/autotest-client"
142 sudo mkdir -p "${stateful_root}${autotest_client}" 172 sudo mkdir -p "${stateful_root}${autotest_client}"
173 sudo ln -sf /mnt/stateful_partition/dev_image${autotest_client} \
174 ${stateful_root}/autotest
143 175
144 sudo cp -fpru ${AUTOTEST_SRC}/client/* \ 176 sudo cp -fpru ${AUTOTEST_SRC}/client/* \
145 "${stateful_root}/${autotest_client}" 177 "${stateful_root}/${autotest_client}"
146 sudo chmod 755 "${stateful_root}/${autotest_client}" 178 sudo chmod 755 "${stateful_root}/${autotest_client}"
147 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" 179 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}"
148 180
149 sudo umount ${STATEFUL_DIR} 181 sudo umount ${STATEFUL_DIR}
150 sudo losetup -d "${stateful_loop_dev}" 182 sudo losetup -d "${stateful_loop_dev}"
151 trap - INT TERM EXIT 183 trap - INT TERM EXIT
152 rmdir "${STATEFUL_DIR}" 184 rmdir "${STATEFUL_DIR}"
153 else 185 else
154 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." 186 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed."
155 echo "Please call make_autotest.sh inside chroot first." 187 echo "Please call build_autotest.sh inside chroot first."
156 exit -1 188 exit -1
157 fi 189 fi
158 fi 190 fi
159 191
160 192
161 # Let's do it. 193 # Let's do it.
162 if [ -b "${FLAGS_to}" ] 194 if [ -b "${FLAGS_to}" ]
163 then 195 then
164 # Output to a block device (i.e., a real USB key), so need sudo dd 196 # Output to a block device (i.e., a real USB key), so need sudo dd
165 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." 197 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..."
166 198
167 # Warn if it looks like they supplied a partition as the destination. 199 # Warn if it looks like they supplied a partition as the destination.
168 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then 200 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then
169 local drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') 201 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//')
170 if [ -b "${drive}" ]; then 202 if [ -b "${drive}" ]; then
171 echo 203 echo
172 echo "NOTE: It looks like you may have supplied a partition as the " 204 echo "NOTE: It looks like you may have supplied a partition as the "
173 echo "destination. This script needs to write to the drive's device " 205 echo "destination. This script needs to write to the drive's device "
174 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." 206 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})."
175 echo 207 echo
176 fi 208 fi
177 fi 209 fi
178 210
179 # Make sure this is really what the user wants, before nuking the device 211 # Make sure this is really what the user wants, before nuking the device
(...skipping 30 matching lines...) Expand all
210 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" 242 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M"
211 echo "where /dev/sdb is the entire keyfob." 243 echo "where /dev/sdb is the entire keyfob."
212 if [ ${INSIDE_CHROOT} -eq 1 ] 244 if [ ${INSIDE_CHROOT} -eq 1 ]
213 then 245 then
214 example=$(basename "${FLAGS_to}") 246 example=$(basename "${FLAGS_to}")
215 echo "NOTE: Since you are currently inside the chroot, and you'll need to" 247 echo "NOTE: Since you are currently inside the chroot, and you'll need to"
216 echo "run dd outside the chroot, the path to the USB image will be" 248 echo "run dd outside the chroot, the path to the USB image will be"
217 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." 249 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)."
218 fi 250 fi
219 fi 251 fi
OLDNEW
« no previous file with comments | « src/platform/memento_softwareupdate/memento_updater.sh ('k') | src/scripts/mod_for_factory_scripts/factory.patch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698