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 factory_install ${FLAGS_FALSE} \ | 25 DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
26 "Whether to generate a factory install shim." | 26 "Whether to generate a factory install shim." |
27 DEFINE_boolean factory ${FLAGS_FALSE} \ | 27 DEFINE_boolean factory ${FLAGS_FALSE} \ |
28 "Whether to generate a factory runin image. Implies aututest and test" | 28 "Whether to generate a factory runin image. Implies aututest and test" |
29 DEFINE_boolean install_autotest ${FLAGS_FALSE} \ | |
30 "Whether to install autotest to the stateful partition." | |
31 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ | 29 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ |
32 "Copy the kernel to the fourth partition." | 30 "Copy the kernel to the fourth partition." |
33 DEFINE_boolean test_image "${FLAGS_FALSE}" \ | 31 DEFINE_boolean test_image "${FLAGS_FALSE}" \ |
34 "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." |
35 DEFINE_string build_root "/build" \ | 33 DEFINE_string build_root "/build" \ |
36 "The root location for board sysroots." | 34 "The root location for board sysroots." |
37 | 35 |
38 # Parse command line | 36 # Parse command line |
39 FLAGS "$@" || exit 1 | 37 FLAGS "$@" || exit 1 |
40 eval set -- "${FLAGS_ARGV}" | 38 eval set -- "${FLAGS_ARGV}" |
41 | 39 |
42 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then | 40 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then |
43 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then | 41 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then |
44 echo "Factory test image is incompatible with factory install shim." | 42 echo "Factory test image is incompatible with factory install shim." |
45 exit 1 | 43 exit 1 |
46 fi | 44 fi |
47 fi | 45 fi |
48 | 46 |
49 # Require autotest for manucaturing image. | 47 # Require autotest for manucaturing image. |
50 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then | 48 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then |
51 echo "Factory image requires --install_autotest and --test_image, setting." | 49 echo "Factory image requires --test_image, setting." |
52 FLAGS_install_autotest=${FLAGS_TRUE} | |
53 FLAGS_test_image=${FLAGS_TRUE} | 50 FLAGS_test_image=${FLAGS_TRUE} |
54 fi | 51 fi |
55 | 52 |
56 # Require test for for factory install shim. | 53 # Require test for for factory install shim. |
57 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then | 54 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then |
58 echo "Factory install shim requires --test_image, setting." | 55 echo "Factory install shim requires --test_image, setting." |
59 FLAGS_test_image=${FLAGS_TRUE} | 56 FLAGS_test_image=${FLAGS_TRUE} |
60 fi | 57 fi |
61 | 58 |
62 | 59 |
63 # Inside the chroot, so output to usb.img in the same dir as the other | |
64 # Script can be run either inside or outside the chroot. | |
65 if [ ${INSIDE_CHROOT} -eq 1 ] | |
66 then | |
67 SYSROOT="${FLAGS_build_root}/${FLAGS_board}" | |
68 else | |
69 SYSROOT="${DEFAULT_CHROOT_DIR}${FLAGS_build_root}/${FLAGS_board}" | |
70 echo "Caching sudo authentication" | |
71 sudo -v | |
72 echo "Done" | |
73 fi | |
74 AUTOTEST_SRC="${SYSROOT}/usr/local/autotest" | |
75 | |
76 # Die on any errors. | 60 # Die on any errors. |
77 set -e | 61 set -e |
78 | 62 |
79 # No board, no default and no image set then we can't find the image | 63 # No board, no default and no image set then we can't find the image |
80 if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then | 64 if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then |
81 setup_board_warning | 65 setup_board_warning |
82 exit 1 | 66 exit 1 |
83 fi | 67 fi |
84 | 68 |
85 # We have a board name but no image set. Use image at default location | 69 # We have a board name but no image set. Use image at default location |
(...skipping 26 matching lines...) Expand all Loading... |
112 function do_cleanup { | 96 function do_cleanup { |
113 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" | 97 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" |
114 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then | 98 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then |
115 sudo umount "${STATEFUL_DIR}" | 99 sudo umount "${STATEFUL_DIR}" |
116 sudo losetup -d "${STATEFUL_LOOP_DEV}" | 100 sudo losetup -d "${STATEFUL_LOOP_DEV}" |
117 rmdir "${STATEFUL_DIR}" | 101 rmdir "${STATEFUL_DIR}" |
118 echo "Cleaned" | 102 echo "Cleaned" |
119 fi | 103 fi |
120 } | 104 } |
121 | 105 |
122 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then | |
123 echo "Detecting autotest at ${AUTOTEST_SRC}" | |
124 if [ -d ${AUTOTEST_SRC} ] | |
125 then | |
126 # Figure out how to loop mount the stateful partition. It's always | |
127 # partition 1 on the disk image. | |
128 offset=$(partoffset "${SRC_IMAGE}" 1) | |
129 | |
130 stateful_loop_dev=$(sudo losetup -f) | |
131 if [ -z "${stateful_loop_dev}" ] | |
132 then | |
133 echo "No free loop device. Free up a loop device or reboot. exiting." | |
134 exit 1 | |
135 fi | |
136 STATEFUL_LOOP_DEV=$stateful_loop_dev | |
137 trap do_cleanup INT TERM EXIT | |
138 | |
139 echo "Mounting ${STATEFUL_DIR} loopback" | |
140 sudo losetup -o $(( $offset * 512 )) "${stateful_loop_dev}" "${SRC_IMAGE}" | |
141 sudo mount "${stateful_loop_dev}" "${STATEFUL_DIR}" | |
142 stateful_root="${STATEFUL_DIR}/dev_image" | |
143 | |
144 echo "Install autotest into stateful partition..." | |
145 autotest_client="/home/autotest-client" | |
146 sudo mkdir -p "${stateful_root}${autotest_client}" | |
147 sudo ln -sf /mnt/stateful_partition/dev_image${autotest_client} \ | |
148 ${stateful_root}/autotest | |
149 | |
150 sudo cp -fpru ${AUTOTEST_SRC}/client/* \ | |
151 "${stateful_root}/${autotest_client}" | |
152 sudo chmod 755 "${stateful_root}/${autotest_client}" | |
153 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" | |
154 | |
155 sudo umount ${STATEFUL_DIR} | |
156 sudo losetup -d "${stateful_loop_dev}" | |
157 trap - INT TERM EXIT | |
158 rmdir "${STATEFUL_DIR}" | |
159 else | |
160 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." | |
161 echo "Please call build_autotest.sh inside chroot first." | |
162 exit -1 | |
163 fi | |
164 fi | |
165 | |
166 | 106 |
167 # If we're asked to modify the image for test, then let's make a copy and | 107 # If we're asked to modify the image for test, then let's make a copy and |
168 # modify that instead. | 108 # modify that instead. |
169 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then | 109 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then |
170 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ | 110 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ |
171 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then | 111 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then |
172 # Copy it. | 112 # Copy it. |
173 echo "Creating test image from original..." | 113 echo "Creating test image from original..." |
174 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" | 114 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" |
175 | 115 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" | 196 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" |
257 echo "where /dev/sdX is the entire drive." | 197 echo "where /dev/sdX is the entire drive." |
258 if [ ${INSIDE_CHROOT} -eq 1 ] | 198 if [ ${INSIDE_CHROOT} -eq 1 ] |
259 then | 199 then |
260 example=$(basename "${FLAGS_to}") | 200 example=$(basename "${FLAGS_to}") |
261 echo "NOTE: Since you are currently inside the chroot, and you'll need to" | 201 echo "NOTE: Since you are currently inside the chroot, and you'll need to" |
262 echo "run dd outside the chroot, the path to the USB image will be" | 202 echo "run dd outside the chroot, the path to the USB image will be" |
263 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." | 203 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." |
264 fi | 204 fi |
265 fi | 205 fi |
OLD | NEW |