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

Side by Side Diff: build_image

Issue 2804012: Fixed formatting in build_image $VAR -> ${VAR}. (Closed) Base URL: ssh://git@chromiumos-git/crosutils.git
Patch Set: Add punctuation to comments. Created 10 years, 6 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
« 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 build a bootable keyfob-based chromeos system image from within 7 # Script to build a bootable keyfob-based chromeos system image from within
8 # a chromiumos setup. This assumes that all needed packages have been built into 8 # a chromiumos setup. This assumes that all needed packages have been built into
9 # the given target's root with binary packages turned on. This script will 9 # the given target's root with binary packages turned on. This script will
10 # build the Chrome OS image using only pre-built binary packages. 10 # build the Chrome OS image using only pre-built binary packages.
11 11
12 # Load common constants. This should be the first executable line. 12 # Load common constants. This should be the first executable line.
13 # The path to common.sh should be relative to your script's location. 13 # The path to common.sh should be relative to your script's location.
14 . "$(dirname "$0")/common.sh" 14 . "$(dirname "$0")/common.sh"
15 15
16 # Script must be run inside the chroot. 16 # Script must be run inside the chroot.
17 restart_in_chroot_if_needed $* 17 restart_in_chroot_if_needed $*
18 18
19 get_default_board 19 get_default_board
20 20
21 # Flags. 21 # Flags.
22 DEFINE_string board "$DEFAULT_BOARD" \ 22 DEFINE_string board "${DEFAULT_BOARD}" \
23 "The board to build an image for." 23 "The board to build an image for."
24 DEFINE_string build_root "/build" \ 24 DEFINE_string build_root "/build" \
25 "The root location for board sysroots." 25 "The root location for board sysroots."
26 DEFINE_integer build_attempt 1 \ 26 DEFINE_integer build_attempt 1 \
27 "The build attempt for this image build." 27 "The build attempt for this image build."
28 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ 28 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
29 "Directory in which to place image result directories (named by version)" 29 "Directory in which to place image result directories (named by version)"
30 DEFINE_boolean replace $FLAGS_FALSE \ 30 DEFINE_boolean replace ${FLAGS_FALSE} \
31 "Overwrite existing output, if any." 31 "Overwrite existing output, if any."
32 DEFINE_boolean withdev $FLAGS_TRUE \ 32 DEFINE_boolean withdev ${FLAGS_TRUE} \
33 "Include useful developer friendly utilities in the image." 33 "Include useful developer friendly utilities in the image."
34 DEFINE_boolean installmask $FLAGS_TRUE \ 34 DEFINE_boolean installmask ${FLAGS_TRUE} \
35 "Use INSTALL_MASK to shrink the resulting image." 35 "Use INSTALL_MASK to shrink the resulting image."
36 DEFINE_integer jobs -1 \ 36 DEFINE_integer jobs -1 \
37 "How many packages to build in parallel at maximum." 37 "How many packages to build in parallel at maximum."
38 DEFINE_boolean statefuldev $FLAGS_TRUE \ 38 DEFINE_boolean statefuldev ${FLAGS_TRUE} \
39 "Install development packages on stateful partition rather than the rootfs" 39 "Install development packages on stateful partition rather than the rootfs"
40 DEFINE_string to "" \ 40 DEFINE_string to "" \
41 "The target image file or device" 41 "The target image file or device"
42 DEFINE_boolean factory_install $FLAGS_FALSE \ 42 DEFINE_boolean factory_install ${FLAGS_FALSE} \
43 "Build a smaller image to overlay the factory install shim on; this argument \ 43 "Build a smaller image to overlay the factory install shim on; this argument \
44 is also required in image_to_usb." 44 is also required in image_to_usb."
45 DEFINE_string arm_extra_bootargs "" \ 45 DEFINE_string arm_extra_bootargs "" \
46 "Additional command line options to pass to the ARM kernel." 46 "Additional command line options to pass to the ARM kernel."
47 DEFINE_boolean recovery $FLAGS_FALSE \ 47 DEFINE_boolean recovery ${FLAGS_FALSE} \
48 "Build a recovery image. Default: False." 48 "Build a recovery image. Default: False."
49 DEFINE_integer rootfs_partition_size 1024 \ 49 DEFINE_integer rootfs_partition_size 1024 \
50 "rootfs parition size in MBs." 50 "rootfs parition size in MBs."
51 DEFINE_integer rootfs_size 720 \ 51 DEFINE_integer rootfs_size 720 \
52 "rootfs filesystem size in MBs." 52 "rootfs filesystem size in MBs."
53 53
54 # Parse command line. 54 # Parse command line.
55 FLAGS "$@" || exit 1 55 FLAGS "$@" || exit 1
56 eval set -- "${FLAGS_ARGV}" 56 eval set -- "${FLAGS_ARGV}"
57 57
58 # Only now can we die on error. shflags functions leak non-zero error codes, 58 # Only now can we die on error. shflags functions leak non-zero error codes,
59 # so will die prematurely if 'set -e' is specified before now. 59 # so will die prematurely if 'set -e' is specified before now.
60 set -e 60 set -e
61 61
62 if [ -z "$FLAGS_board" ] ; then 62 if [ -z "${FLAGS_board}" ] ; then
63 error "--board is required." 63 error "--board is required."
64 exit 1 64 exit 1
65 fi 65 fi
66 66
67 if [ "$FLAGS_rootfs_size" -gt "$FLAGS_rootfs_partition_size" ] ; then 67 if [ "${FLAGS_rootfs_size}" -gt "${FLAGS_rootfs_partition_size}" ] ; then
68 error "rootfs (${FLAGS_rootfs_size} MB) is bigger than partition (${FLAGS_root fs_partition_size} MB)." 68 error "rootfs (${FLAGS_rootfs_size} MB) is bigger than partition (${FLAGS_root fs_partition_size} MB)."
69 exit 1 69 exit 1
70 fi 70 fi
71 71
72 EMERGE_CMD="emerge" 72 EMERGE_CMD="emerge"
73 EMERGE_BOARD_CMD="emerge-${FLAGS_board}" 73 EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
74 TOP_SCRIPTS_DIR="$(dirname $0)" 74 TOP_SCRIPTS_DIR="$(dirname $0)"
75 if [ -e "${TOP_SCRIPTS_DIR}/.emerge" ]; then 75 if [ -e "${TOP_SCRIPTS_DIR}/.emerge" ]; then
76 echo "Using alternate emerge" 76 echo "Using alternate emerge"
77 . "${TOP_SCRIPTS_DIR}/.emerge" 77 . "${TOP_SCRIPTS_DIR}/.emerge"
78 fi 78 fi
79 79
80 # Determine build version. 80 # Determine build version.
81 . "${SCRIPTS_DIR}/chromeos_version.sh" 81 . "${SCRIPTS_DIR}/chromeos_version.sh"
82 82
83 # Use canonical path since some tools (e.g. mount) do not like symlinks. 83 # Use canonical path since some tools (e.g. mount) do not like symlinks.
84 # Append build attempt to output directory. 84 # Append build attempt to output directory.
85 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" 85 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
86 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" 86 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
87 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" 87 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
88 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" 88 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
89 89
90 # If we are creating a developer image, also create a pristine image with a 90 # If we are creating a developer image, also create a pristine image with a
91 # different name. 91 # different name.
92 DEVELOPER_IMAGE_NAME= 92 DEVELOPER_IMAGE_NAME=
93 PRISTINE_IMAGE_NAME=chromiumos_image.bin 93 PRISTINE_IMAGE_NAME=chromiumos_image.bin
94 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then 94 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
95 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin 95 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin
96 DEVELOPER_IMAGE_NAME=chromiumos_image.bin 96 DEVELOPER_IMAGE_NAME=chromiumos_image.bin
97 fi 97 fi
98 98
99 # If we are creating a recovery image, rename pristine image 99 # If we are creating a recovery image, rename pristine image.
100 if [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ]; then 100 if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then
101 PRISTINE_IMAGE_NAME=recovery_image.bin 101 PRISTINE_IMAGE_NAME=recovery_image.bin
102 fi 102 fi
103 103
104 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} 104 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}}
105 105
106 BOARD="${FLAGS_board}" 106 BOARD="${FLAGS_board}"
107 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" 107 BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
108 108
109 LOOP_DEV= 109 LOOP_DEV=
110 STATEFUL_LOOP_DEV= 110 STATEFUL_LOOP_DEV=
111 ESP_LOOP_DEV= 111 ESP_LOOP_DEV=
112 112
113 # What cross-build are we targeting? 113 # What cross-build are we targeting?
114 . "${BOARD_ROOT}/etc/make.conf.board_setup" 114 . "${BOARD_ROOT}/etc/make.conf.board_setup"
115 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} 115 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
116 116
117 # Figure out ARCH from the given toolchain. 117 # Figure out ARCH from the given toolchain.
118 # TODO: Move to common.sh as a function after scripts are switched over. 118 # TODO: Move to common.sh as a function after scripts are switched over.
119 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') 119 TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
120 case "$TC_ARCH" in 120 case "${TC_ARCH}" in
121 arm*) 121 arm*)
122 ARCH="arm" 122 ARCH="arm"
123 ;; 123 ;;
124 *86) 124 *86)
125 ARCH="x86" 125 ARCH="x86"
126 ;; 126 ;;
127 *) 127 *)
128 error "Unable to determine ARCH from toolchain: $CHOST" 128 error "Unable to determine ARCH from toolchain: ${CHOST}"
129 exit 1 129 exit 1
130 esac 130 esac
131 131
132 # Hack to fix bug where x86_64 CHOST line gets incorrectly added. 132 # Hack to fix bug where x86_64 CHOST line gets incorrectly added.
133 # ToDo(msb): remove this hack. 133 # ToDo(msb): remove this hack.
134 PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" 134 PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
135 sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" 135 sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
136 136
137 # Handle existing directory. 137 # Handle existing directory.
138 if [[ -e "$OUTPUT_DIR" ]]; then 138 if [[ -e "${OUTPUT_DIR}" ]]; then
139 if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then 139 if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
140 sudo rm -rf "$OUTPUT_DIR" 140 sudo rm -rf "${OUTPUT_DIR}"
141 else 141 else
142 echo "Directory $OUTPUT_DIR already exists." 142 echo "Directory ${OUTPUT_DIR} already exists."
143 echo "Use --build_attempt option to specify an unused attempt." 143 echo "Use --build_attempt option to specify an unused attempt."
144 echo "Or use --replace if you want to overwrite this directory." 144 echo "Or use --replace if you want to overwrite this directory."
145 exit 1 145 exit 1
146 fi 146 fi
147 fi 147 fi
148 148
149 # Create the output directory. 149 # Create the output directory.
150 mkdir -p "$OUTPUT_DIR" 150 mkdir -p "${OUTPUT_DIR}"
151 151
152 cleanup_rootfs_loop() { 152 cleanup_rootfs_loop() {
153 sudo umount -d "$ROOT_FS_DIR" 153 sudo umount -d "${ROOT_FS_DIR}"
154 } 154 }
155 155
156 cleanup_stateful_fs_loop() { 156 cleanup_stateful_fs_loop() {
157 sudo umount "${ROOT_FS_DIR}/usr/local" 157 sudo umount "${ROOT_FS_DIR}/usr/local"
158 sudo umount "${ROOT_FS_DIR}/var" 158 sudo umount "${ROOT_FS_DIR}/var"
159 sudo umount -d "${STATEFUL_DIR}" 159 sudo umount -d "${STATEFUL_DIR}"
160 } 160 }
161 161
162 cleanup_esp_loop() { 162 cleanup_esp_loop() {
163 sudo umount -d "$ESP_DIR" 163 sudo umount -d "${ESP_DIR}"
164 } 164 }
165 165
166 cleanup() { 166 cleanup() {
167 # Disable die on error. 167 # Disable die on error.
168 set +e 168 set +e
169 169
170 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then 170 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then
171 cleanup_stateful_fs_loop 171 cleanup_stateful_fs_loop
172 fi 172 fi
173 173
174 if [[ -n "$LOOP_DEV" ]]; then 174 if [[ -n "${LOOP_DEV}" ]]; then
175 cleanup_rootfs_loop 175 cleanup_rootfs_loop
176 fi 176 fi
177 177
178 if [[ -n "$ESP_LOOP_DEV" ]]; then 178 if [[ -n "${ESP_LOOP_DEV}" ]]; then
179 cleanup_esp_loop 179 cleanup_esp_loop
180 fi 180 fi
181 181
182 # Turn die on error back on. 182 # Turn die on error back on.
183 set -e 183 set -e
184 } 184 }
185 185
186 delete_prompt() { 186 delete_prompt() {
187 echo "An error occurred in your build so your latest output directory" \ 187 echo "An error occurred in your build so your latest output directory" \
188 "is invalid." 188 "is invalid."
189 read -p "Would you like to delete the output directory (y/N)? " SURE 189 read -p "Would you like to delete the output directory (y/N)? " SURE
190 SURE="${SURE:0:1}" # Get just the first character 190 SURE="${SURE:0:1}" # Get just the first character.
191 if [ "${SURE}" == "y" ] ; then 191 if [ "${SURE}" == "y" ] ; then
192 sudo rm -rf "$OUTPUT_DIR" 192 sudo rm -rf "${OUTPUT_DIR}"
193 echo "Deleted $OUTPUT_DIR" 193 echo "Deleted ${OUTPUT_DIR}"
194 else 194 else
195 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ 195 echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \
196 "until you successfully build another image or delete this directory" 196 "until you successfully build another image or delete this directory"
197 fi 197 fi
198 } 198 }
199 199
200 # $1 - Directory where developer rootfs is mounted. 200 # $1 - Directory where developer rootfs is mounted.
201 # $2 - Directory where developer stateful_partition is mounted. 201 # $2 - Directory where developer stateful_partition is mounted.
202 developer_cleanup() { 202 developer_cleanup() {
203 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2" 203 "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2"
204 delete_prompt 204 delete_prompt
205 } 205 }
206 206
207 # Creates a modified image based on $OUTPUT_IMG with additional packages. 207 # Creates a modified image based on ${OUTPUT_IMG} with additional packages.
208 create_mod_image() { 208 create_mod_image() {
209 local image_type=$1 209 local image_type=$1
210 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev" 210 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev"
211 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image" 211 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image"
212 local image_to_mount=${DEVELOPER_IMAGE_NAME} 212 local image_to_mount=${DEVELOPER_IMAGE_NAME}
213 local output_img="${OUTPUT_DIR}/${image_to_mount}" 213 local output_img="${OUTPUT_DIR}/${image_to_mount}"
214 214
215 # Create stateful partition of the same size as the rootfs. 215 # Create stateful partition of the same size as the rootfs.
216 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image" 216 local stateful_img="${OUTPUT_DIR}/stateful_partition_dev.image"
217 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev" 217 local stateful_dir="${OUTPUT_DIR}/stateful_partition_dev"
218 local file_to_touch=".dev_mode" 218 local file_to_touch=".dev_mode"
219 219
220 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT 220 trap "developer_cleanup \"${root_fs_dir}\" \"${stateful_dir}\"" EXIT
221 221
222 if [ "$image_type" == "dev" ]; then 222 if [ "${image_type}" == "dev" ]; then
223 # Mount a new copy of the base image. 223 # Mount a new copy of the base image.
224 echo "Creating developer image from base image $OUTPUT_IMG" 224 echo "Creating developer image from base image ${OUTPUT_IMG}"
225 cp "$OUTPUT_IMG" "$output_img" 225 cp "${OUTPUT_IMG}" "${output_img}"
226 elif [ "$image_type" == "recovery" ]; then 226 elif [ "${image_type}" == "recovery" ]; then
227 image_to_mount=$PRISTINE_IMAGE_NAME 227 image_to_mount=${PRISTINE_IMAGE_NAME}
228 file_to_touch=".recovery_installer" 228 file_to_touch=".recovery_installer"
229 fi 229 fi
230 230
231 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \ 231 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
232 --image "$image_to_mount" -r "$root_fs_dir" -s "$stateful_dir" 232 --image "${image_to_mount}" -r "${root_fs_dir}" -s "${stateful_dir}"
233 233
234 if [ "$image_type" == "dev" ]; then 234 if [ "${image_type}" == "dev" ]; then
235 # Determine the root dir for developer packages. 235 # Determine the root dir for developer packages.
236 local root_dev_dir="$root_fs_dir" 236 local root_dev_dir="${root_fs_dir}"
237 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \ 237 [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \
238 root_dev_dir="$root_fs_dir/usr/local" 238 root_dev_dir="${root_fs_dir}/usr/local"
239 239
240 # Install developer packages described in chromeos-dev. 240 # Install developer packages described in chromeos-dev.
241 sudo INSTALL_MASK="$INSTALL_MASK" ${EMERGE_BOARD_CMD} \ 241 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
242 --root="$root_dev_dir" --root-deps=rdeps \ 242 --root="${root_dev_dir}" --root-deps=rdeps \
243 --usepkgonly chromeos-dev $EMERGE_JOBS 243 --usepkgonly chromeos-dev ${EMERGE_JOBS}
244 elif [ "$image_type" == "recovery" ]; then 244 elif [ "${image_type}" == "recovery" ]; then
245 # Install recovery installer 245 # Install recovery installer.
246 sudo ${EMERGE_BOARD_CMD} --root=$root_fs_dir --usepkgonly \ 246 sudo ${EMERGE_BOARD_CMD} --root=${root_fs_dir} --usepkgonly \
247 --root-deps=rdeps --nodeps chromeos-recovery 247 --root-deps=rdeps --nodeps chromeos-recovery
248 fi 248 fi
249 249
250 # Re-run ldconfig to fix /etc/ldconfig.so.cache. 250 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
251 sudo /sbin/ldconfig -r "$root_fs_dir" 251 sudo /sbin/ldconfig -r "${root_fs_dir}"
252 252
253 # Mark the image as a developer image (input to chromeos_startup). 253 # Mark the image as a developer image (input to chromeos_startup).
254 sudo mkdir -p "$root_fs_dir/root" 254 sudo mkdir -p "${root_fs_dir}/root"
255 sudo touch "$root_fs_dir/root/$file_to_touch" 255 sudo touch "${root_fs_dir}/root/${file_to_touch}"
256 256
257 if [ "$image_type" == "dev" ]; then 257 if [ "${image_type}" == "dev" ]; then
258 # Additional changes to developer image. 258 # Additional changes to developer image.
259 259
260 # The ldd tool is a useful shell script but lives in glibc; just copy it. 260 # The ldd tool is a useful shell script but lives in glibc; just copy it.
261 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" 261 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin"
262 262
263 # If vim is installed, then a vi symlink would probably help. 263 # If vim is installed, then a vi symlink would probably help.
264 if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then 264 if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then
265 sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi" 265 sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi"
266 fi 266 fi
267 267
268 # Check that the image has been correctly created. Only do it if not 268 # Check that the image has been correctly created. Only do it if not
269 # building a factory install image, as the INSTALL_MASK for it will 269 # building a factory install image, as the INSTALL_MASK for it will
270 # make test_image fail. 270 # make test_image fail.
271 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then 271 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
272 "${SCRIPTS_DIR}/test_image" \ 272 "${SCRIPTS_DIR}/test_image" \
273 --root="$root_fs_dir" \ 273 --root="${root_fs_dir}" \
274 --target="$ARCH" 274 --target="${ARCH}"
275 fi 275 fi
276 echo "Developer image built and stored at $output_img" 276 echo "Developer image built and stored at ${output_img}"
277 fi 277 fi
278 278
279 trap - EXIT 279 trap - EXIT
280 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir" 280 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${root_fs_dir}" -s "${stateful_dir}"
281 sudo rm -rf "$root_fs_dir" "$stateful_dir" 281 sudo rm -rf "${root_fs_dir}" "${stateful_dir}"
282 } 282 }
283 283
284 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will 284 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
285 # be installed on the stateful dir. On a Chromium OS system, this will 285 # be installed on the stateful dir. On a Chromium OS system, this will
286 # translate to /usr/local 286 # translate to /usr/local.
287 DEV_IMAGE_ROOT= 287 DEV_IMAGE_ROOT=
288 288
289 trap "cleanup && delete_prompt" EXIT 289 trap "cleanup && delete_prompt" EXIT
290 290
291 mkdir -p "$ROOT_FS_DIR" 291 mkdir -p "${ROOT_FS_DIR}"
292 292
293 # Create and format the root file system. 293 # Create and format the root file system.
294 294
295 # Check for loop device before creating image. 295 # Check for loop device before creating image.
296 LOOP_DEV=$(sudo losetup -f) 296 LOOP_DEV=$(sudo losetup -f)
297 if [ -z "$LOOP_DEV" ] ; then 297 if [ -z "${LOOP_DEV}" ] ; then
298 echo "No free loop device. Free up a loop device or reboot. exiting. " 298 echo "No free loop device. Free up a loop device or reboot. exiting. "
299 exit 1 299 exit 1
300 fi 300 fi
301 301
302 # Create root file system disk image to fit on a 1GB memory stick. 302 # Create root file system disk image to fit on a 1GB memory stick.
303 # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. 303 # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
304 if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then 304 if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then
305 ROOT_SIZE_BYTES=$((1024 * 1024 * 300)) 305 ROOT_SIZE_BYTES=$((1024 * 1024 * 300))
306 else 306 else
307 ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) 307 ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size}))
308 fi 308 fi
309 309
310 dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) 310 dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
311 sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG" 311 sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}"
312 sudo mkfs.ext3 "$LOOP_DEV" 312 sudo mkfs.ext3 "${LOOP_DEV}"
313 313
314 # Tune and mount rootfs. 314 # Tune and mount rootfs.
315 UUID=$(uuidgen) 315 UUID=$(uuidgen)
316 DISK_LABEL="C-KEYFOB" 316 DISK_LABEL="C-KEYFOB"
317 sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV" 317 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${LOOP_DEV}"
318 sudo mount "$LOOP_DEV" "$ROOT_FS_DIR" 318 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}"
319 319
320 # Create stateful partition of the same size as the rootfs. 320 # Create stateful partition of the same size as the rootfs.
321 STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image" 321 STATEFUL_IMG="${OUTPUT_DIR}/stateful_partition.image"
322 STATEFUL_DIR="$OUTPUT_DIR/stateful_partition" 322 STATEFUL_DIR="${OUTPUT_DIR}/stateful_partition"
323 STATEFUL_LOOP_DEV=$(sudo losetup -f) 323 STATEFUL_LOOP_DEV=$(sudo losetup -f)
324 if [ -z "$STATEFUL_LOOP_DEV" ] ; then 324 if [ -z "${STATEFUL_LOOP_DEV}" ] ; then
325 echo "No free loop device. Free up a loop device or reboot. exiting. " 325 echo "No free loop device. Free up a loop device or reboot. exiting. "
326 exit 1 326 exit 1
327 fi 327 fi
328 dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) 328 dd if=/dev/zero of="${STATEFUL_IMG}" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
329 sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG" 329 sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_IMG}"
330 sudo mkfs.ext3 "$STATEFUL_LOOP_DEV" 330 sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}"
331 sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \ 331 sudo tune2fs -L "C-STATE" -U "${UUID}" -c 0 -i 0 \
332 "$STATEFUL_LOOP_DEV" 332 "${STATEFUL_LOOP_DEV}"
333 333
334 # Mount the stateful partition. 334 # Mount the stateful partition.
335 mkdir -p "$STATEFUL_DIR" 335 mkdir -p "${STATEFUL_DIR}"
336 sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR" 336 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_DIR}"
337 337
338 # Set dev image root now that we have mounted the stateful partition we created 338 # Set dev image root now that we have mounted the stateful partition
339 DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image" 339 # we created.
340 DEV_IMAGE_ROOT="${STATEFUL_DIR}/dev_image"
340 341
341 # Turn root file system into bootable image. 342 # Turn root file system into bootable image.
342 if [[ "$ARCH" = "x86" ]]; then 343 if [[ "${ARCH}" = "x86" ]]; then
343 # Setup extlinux configuration. 344 # Setup extlinux configuration.
344 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev 345 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
345 # in the initramfs. When we figure that out, switch to root=UUID=$UUID. 346 # in the initramfs. When we figure that out, switch to root=UUID=${UUID}.
346 sudo mkdir -p "$ROOT_FS_DIR"/boot 347 sudo mkdir -p "${ROOT_FS_DIR}"/boot
347 # TODO(adlr): use initramfs for booting. 348 # TODO(adlr): use initramfs for booting.
348 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf 349 cat <<EOF | sudo dd of="${ROOT_FS_DIR}"/boot/extlinux.conf
349 DEFAULT chromeos-usb 350 DEFAULT chromeos-usb
350 PROMPT 0 351 PROMPT 0
351 TIMEOUT 0 352 TIMEOUT 0
352 353
353 label chromeos-usb 354 label chromeos-usb
354 menu label chromeos-usb 355 menu label chromeos-usb
355 kernel vmlinuz 356 kernel vmlinuz
356 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 r o noresume noswap i915.modeset=1 loglevel=1 cros_legacy 357 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 r o noresume noswap i915.modeset=1 loglevel=1 cros_legacy
357 358
358 label chromeos-hd 359 label chromeos-hd
359 menu label chromeos-hd 360 menu label chromeos-hd
360 kernel vmlinuz 361 kernel vmlinuz
361 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro n oresume noswap i915.modeset=1 loglevel=1 cros_legacy 362 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro n oresume noswap i915.modeset=1 loglevel=1 cros_legacy
362 EOF 363 EOF
363 364
364 # Make partition bootable and label it. 365 # Make partition bootable and label it.
365 sudo extlinux -z --install "${ROOT_FS_DIR}/boot" 366 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
366 fi 367 fi
367 368
368 # -- Install packages into the root file system -- 369 # -- Install packages into the root file system --
369 370
370 # We need to install libc manually from the cross toolchain. 371 # We need to install libc manually from the cross toolchain.
371 # TODO: Improve this? We only want libc and not the whole toolchain. 372 # TODO: Improve this? We only want libc and not the whole toolchain.
372 PKGDIR="/var/lib/portage/pkgs/cross/" 373 PKGDIR="/var/lib/portage/pkgs/cross/"
373 sudo tar jxvpf \ 374 sudo tar jxvpf \
374 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ 375 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
375 -C "$ROOT_FS_DIR" --strip-components=3 \ 376 -C "${ROOT_FS_DIR}" --strip-components=3 \
376 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o 377 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
377 378
378 # We need to install libstdc++ manually from the cross toolchain. 379 # We need to install libstdc++ manually from the cross toolchain.
379 # TODO: Figure out a better way of doing this? 380 # TODO: Figure out a better way of doing this?
380 sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" 381 sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
381 sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib" 382 sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
382 383
383 INSTALL_MASK="" 384 INSTALL_MASK=""
384 if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then 385 if [[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] ; then
385 INSTALL_MASK="$DEFAULT_INSTALL_MASK" 386 INSTALL_MASK="${DEFAULT_INSTALL_MASK}"
386 fi 387 fi
387 388
388 # Reduce the size of factory install shim. 389 # Reduce the size of factory install shim.
389 # TODO: Build a separated ebuild for the factory install shim to reduce size. 390 # TODO: Build a separated ebuild for the factory install shim to reduce size.
390 if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then 391 if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then
391 INSTALL_MASK="$INSTALL_MASK $FACTORY_INSTALL_MASK" 392 INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}"
392 fi 393 fi
393 394
394 if [[ $FLAGS_jobs -ne -1 ]]; then 395 if [[ ${FLAGS_jobs} -ne -1 ]]; then
395 EMERGE_JOBS="--jobs=$FLAGS_jobs" 396 EMERGE_JOBS="--jobs=${FLAGS_jobs}"
396 fi 397 fi
397 398
398 # Prepare stateful partition with some pre-created directories 399 # Prepare stateful partition with some pre-created directories.
399 sudo mkdir -p "${DEV_IMAGE_ROOT}" 400 sudo mkdir -p "${DEV_IMAGE_ROOT}"
400 sudo mkdir -p "${STATEFUL_DIR}/var" 401 sudo mkdir -p "${STATEFUL_DIR}/var"
401 402
402 # Create symlinks so that /usr/local/usr based directories are symlinked to 403 # Create symlinks so that /usr/local/usr based directories are symlinked to
403 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. 404 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
404 setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \ 405 setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \
405 "${STATEFUL_DIR}" 406 "${STATEFUL_DIR}"
406 407
407 # Perform binding rather than symlinking because directories must exist 408 # Perform binding rather than symlinking because directories must exist
408 # on rootfs so that we can bind at run-time since rootfs is read-only 409 # on rootfs so that we can bind at run-time since rootfs is read-only.
409 echo "Binding directories from stateful partition onto the rootfs" 410 echo "Binding directories from stateful partition onto the rootfs"
410 sudo mkdir -p "${ROOT_FS_DIR}/usr/local" 411 sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
411 sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" 412 sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
412 sudo mkdir -p "${ROOT_FS_DIR}/var" 413 sudo mkdir -p "${ROOT_FS_DIR}/var"
413 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" 414 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
414 sudo mkdir -p "${ROOT_FS_DIR}/dev" 415 sudo mkdir -p "${ROOT_FS_DIR}/dev"
415 416
416 # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the 417 # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkgonly" all of the
417 # runtime packages for chrome os. This builds up a chrome os image from binary 418 # runtime packages for chrome os. This builds up a chrome os image from binary
418 # packages with runtime dependencies only. We use INSTALL_MASK to trim the 419 # packages with runtime dependencies only. We use INSTALL_MASK to trim the
419 # image size as much as possible. 420 # image size as much as possible.
420 sudo INSTALL_MASK="$INSTALL_MASK" ${EMERGE_BOARD_CMD} \ 421 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
421 --root="$ROOT_FS_DIR" --root-deps=rdeps \ 422 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
422 --usepkgonly chromeos $EMERGE_JOBS 423 --usepkgonly chromeos ${EMERGE_JOBS}
423 424
424 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI 425 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
425 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk 426 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk
426 # images the same for both x86 and ARM. 427 # images the same for both x86 and ARM.
427 ESP_IMG=${OUTPUT_DIR}/esp.image 428 ESP_IMG=${OUTPUT_DIR}/esp.image
428 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code 429 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
429 # it to 16M for now. 430 # it to 16M for now.
430 ESP_BLOCKS=16384 431 ESP_BLOCKS=16384
431 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} 432 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
432 ESP_DIR=${OUTPUT_DIR}/esp 433 ESP_DIR=${OUTPUT_DIR}/esp
433 ESP_LOOP_DEV=$(sudo losetup -f) 434 ESP_LOOP_DEV=$(sudo losetup -f)
434 if [ -z "$ESP_LOOP_DEV" ] ; then 435 if [ -z "${ESP_LOOP_DEV}" ] ; then
435 echo "No free loop device. Free up a loop device or reboot. exiting. " 436 echo "No free loop device. Free up a loop device or reboot. exiting. "
436 exit 1 437 exit 1
437 fi 438 fi
438 mkdir -p "${ESP_DIR}" 439 mkdir -p "${ESP_DIR}"
439 sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}" 440 sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
440 sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}" 441 sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
441 sudo mkdir -p "${ESP_DIR}/efi/boot" 442 sudo mkdir -p "${ESP_DIR}/efi/boot"
442 sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \ 443 sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
443 part_gpt fat ext2 normal boot sh chain configfile linux 444 part_gpt fat ext2 normal boot sh chain configfile linux
444 cat <<'EOF' | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg" 445 cat <<'EOF' | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
(...skipping 11 matching lines...) Expand all
456 } 457 }
457 458
458 menuentry "Alternate USB Boot" { 459 menuentry "Alternate USB Boot" {
459 linux (hd0,3)/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootw ait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1 cros_efi 460 linux (hd0,3)/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootw ait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1 cros_efi
460 } 461 }
461 462
462 EOF 463 EOF
463 464
464 # FIXME: At the moment, we're working on signed images for x86 only. ARM will 465 # FIXME: At the moment, we're working on signed images for x86 only. ARM will
465 # support this before shipping, but at the moment they don't. 466 # support this before shipping, but at the moment they don't.
466 if [[ "$ARCH" = "x86" ]]; then 467 if [[ "${ARCH}" = "x86" ]]; then
467 468
468 # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will 469 # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will
469 # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS BIOS 470 # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS BIOS
470 # will use a separate signed kernel partition, which we'll create now. 471 # will use a separate signed kernel partition, which we'll create now.
471 # FIXME: remove serial output, debugging messages 472 # FIXME: remove serial output, debugging messages.
472 cat <<'EOF' > "${OUTPUT_DIR}/config.txt" 473 cat <<'EOF' > "${OUTPUT_DIR}/config.txt"
473 earlyprintk=serial,ttyS0,115200 474 earlyprintk=serial,ttyS0,115200
474 console=ttyS0,115200 475 console=ttyS0,115200
475 init=/sbin/init 476 init=/sbin/init
476 add_efi_memmap 477 add_efi_memmap
477 boot=local 478 boot=local
478 rootwait 479 rootwait
479 root=/dev/sd%D%P 480 root=/dev/sd%D%P
480 ro 481 ro
481 noresume 482 noresume
482 noswap 483 noswap
483 i915.modeset=1 484 i915.modeset=1
484 loglevel=7 485 loglevel=7
485 cros_secure 486 cros_secure
486 EOF 487 EOF
487 488
488 # FIXME: We need to specify the real keys and certs here! 489 # FIXME: We need to specify the real keys and certs here!
489 SIG_DIR="${SRC_ROOT}/platform/vboot_reference/tests/testkeys" 490 SIG_DIR="${SRC_ROOT}/platform/vboot_reference/tests/testkeys"
490 491
491 # Wrap the public keys with VbPublicKey headers 492 # Wrap the public keys with VbPublicKey headers.
492 vbutil_key --pack \ 493 vbutil_key --pack \
493 --in "${SIG_DIR}/key_rsa2048.keyb" \ 494 --in "${SIG_DIR}/key_rsa2048.keyb" \
494 --version 1 --algorithm 4 \ 495 --version 1 --algorithm 4 \
495 --out "${OUTPUT_DIR}/key_alg4.vbpubk" 496 --out "${OUTPUT_DIR}/key_alg4.vbpubk"
496 497
497 vbutil_key --pack \ 498 vbutil_key --pack \
498 --in "${SIG_DIR}/key_rsa4096.keyb" \ 499 --in "${SIG_DIR}/key_rsa4096.keyb" \
499 --version 1 --algorithm 8 \ 500 --version 1 --algorithm 8 \
500 --out "${OUTPUT_DIR}/key_alg8.vbpubk" 501 --out "${OUTPUT_DIR}/key_alg8.vbpubk"
501 502
502 vbutil_keyblock --pack "${OUTPUT_DIR}/data4_sign8.keyblock" \ 503 vbutil_keyblock --pack "${OUTPUT_DIR}/data4_sign8.keyblock" \
503 --datapubkey "${OUTPUT_DIR}/key_alg4.vbpubk" \ 504 --datapubkey "${OUTPUT_DIR}/key_alg4.vbpubk" \
504 --signprivate "${SIG_DIR}/key_rsa4096.pem" \ 505 --signprivate "${SIG_DIR}/key_rsa4096.pem" \
505 --algorithm 8 --flags 3 506 --algorithm 8 --flags 3
506 507
507 # Verify the keyblock 508 # Verify the keyblock.
508 vbutil_keyblock --unpack "${OUTPUT_DIR}/data4_sign8.keyblock" \ 509 vbutil_keyblock --unpack "${OUTPUT_DIR}/data4_sign8.keyblock" \
509 --signpubkey "${OUTPUT_DIR}/key_alg8.vbpubk" 510 --signpubkey "${OUTPUT_DIR}/key_alg8.vbpubk"
510 511
511 # Sign the kernel: 512 # Sign the kernel:
512 vbutil_kernel --pack "${OUTPUT_DIR}/vmlinuz.image" \ 513 vbutil_kernel --pack "${OUTPUT_DIR}/vmlinuz.image" \
513 --keyblock "${OUTPUT_DIR}/data4_sign8.keyblock" \ 514 --keyblock "${OUTPUT_DIR}/data4_sign8.keyblock" \
514 --signprivate "${SIG_DIR}/key_rsa2048.pem" \ 515 --signprivate "${SIG_DIR}/key_rsa2048.pem" \
515 --version 1 \ 516 --version 1 \
516 --config "${OUTPUT_DIR}/config.txt" \ 517 --config "${OUTPUT_DIR}/config.txt" \
517 --bootloader /lib64/bootstub/bootstub.efi \ 518 --bootloader /lib64/bootstub/bootstub.efi \
518 --vmlinuz "${ROOT_FS_DIR}/boot/vmlinuz" 519 --vmlinuz "${ROOT_FS_DIR}/boot/vmlinuz"
519 520
520 # And verify it 521 # And verify it.
521 vbutil_kernel --verify "${OUTPUT_DIR}/vmlinuz.image" \ 522 vbutil_kernel --verify "${OUTPUT_DIR}/vmlinuz.image" \
522 --signpubkey "${OUTPUT_DIR}/key_alg8.vbpubk" 523 --signpubkey "${OUTPUT_DIR}/key_alg8.vbpubk"
523 524
524 else 525 else
525 # FIXME: For now, ARM just uses the unsigned kernel by itself. 526 # FIXME: For now, ARM just uses the unsigned kernel by itself.
526 cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" 527 cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
527 fi 528 fi
528 529
529 530
530 # Perform any customizations on the root file system that are needed. 531 # Perform any customizations on the root file system that are needed.
531 "${SCRIPTS_DIR}/customize_rootfs" \ 532 "${SCRIPTS_DIR}/customize_rootfs" \
532 --root="$ROOT_FS_DIR" \ 533 --root="${ROOT_FS_DIR}" \
533 --target="$ARCH" \ 534 --target="${ARCH}" \
534 --board="$BOARD" 535 --board="${BOARD}"
535 536
536 # Don't test the factory install shim. 537 # Don't test the factory install shim.
537 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then 538 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
538 # Check that the image has been correctly created. 539 # Check that the image has been correctly created.
539 "${SCRIPTS_DIR}/test_image" \ 540 "${SCRIPTS_DIR}/test_image" \
540 --root="$ROOT_FS_DIR" \ 541 --root="${ROOT_FS_DIR}" \
541 --target="$ARCH" 542 --target="${ARCH}"
542 fi 543 fi
543 544
544 # Clean up symlinks so they work on a running target rooted at "/". 545 # Clean up symlinks so they work on a running target rooted at "/".
545 # Here development packages are rooted at /usr/local. However, do not 546 # Here development packages are rooted at /usr/local. However, do not
546 # create /usr/local or /var on host (already exist on target). 547 # create /usr/local or /var on host (already exist on target).
547 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}" 548 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}"
548 549
549 # Cleanup loop devices. 550 # Cleanup loop devices.
550 cleanup 551 cleanup
551 552
552 trap delete_prompt EXIT 553 trap delete_prompt EXIT
553 554
554 RECOVERY="--norecovery" 555 RECOVERY="--norecovery"
555 if [[ ${FLAGS_recovery} -eq $FLAGS_TRUE ]]; then 556 if [[ ${FLAGS_recovery} -eq ${FLAGS_TRUE} ]]; then
556 RECOVERY="--recovery" 557 RECOVERY="--recovery"
557 fi 558 fi
558 559
559 # Create the GPT-formatted image 560 # Create the GPT-formatted image.
560 ${SCRIPTS_DIR}/build_gpt.sh \ 561 ${SCRIPTS_DIR}/build_gpt.sh \
561 --arch=${ARCH} \ 562 --arch=${ARCH} \
562 --board=${FLAGS_board} \ 563 --board=${FLAGS_board} \
563 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ 564 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
564 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ 565 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \
565 ${RECOVERY} \ 566 ${RECOVERY} \
566 "${OUTPUT_DIR}" \ 567 "${OUTPUT_DIR}" \
567 "${OUTPUT_IMG}" 568 "${OUTPUT_IMG}"
568 569
569 # Create a recovery image based on the chromium os base image 570 # Create a recovery image based on the chromium os base image.
570 [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ] && create_mod_image "recovery" 571 [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ] && create_mod_image "recovery"
571 trap - EXIT 572 trap - EXIT
572 573
573 # Create a developer image based on the chromium os base image 574 # Create a developer image based on the chromium os base image.
574 [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_mod_image "dev" 575 [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] && create_mod_image "dev"
575 trap - EXIT 576 trap - EXIT
576 577
577 # FIXME: only signing things for x86 right now. 578 # FIXME: only signing things for x86 right now.
578 if [[ "$ARCH" = "x86" ]]; then 579 if [[ "${ARCH}" = "x86" ]]; then
579 # Verify the final image 580 # Verify the final image.
580 load_kernel_test "${OUTPUT_IMG}" "${OUTPUT_DIR}/key_alg8.vbpubk" 581 load_kernel_test "${OUTPUT_IMG}" "${OUTPUT_DIR}/key_alg8.vbpubk"
581 fi 582 fi
582 583
583 # Clean up temporary files. 584 # Clean up temporary files.
584 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ 585 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
585 "${ESP_IMG}" "${OUTPUT_DIR}/data4_sign8.keyblock" \ 586 "${ESP_IMG}" "${OUTPUT_DIR}/data4_sign8.keyblock" \
586 "${OUTPUT_DIR}/key_alg4.vbpubk" "${OUTPUT_DIR}/key_alg8.vbpubk" 587 "${OUTPUT_DIR}/key_alg4.vbpubk" "${OUTPUT_DIR}/key_alg8.vbpubk"
587 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" 588 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
588 589
589 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" 590 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
590 591
591 echo "Done. Image created in ${OUTPUT_DIR}" 592 echo "Done. Image created in ${OUTPUT_DIR}"
592 echo "Chromium OS image created as $PRISTINE_IMAGE_NAME" 593 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
593 if [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ]; then 594 if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then
594 echo "Recovery image created as $PRISTINE_IMAGE_NAME" 595 echo "Recovery image created as ${PRISTINE_IMAGE_NAME}"
595 fi 596 fi
596 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then 597 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
597 echo "Developer image created as $DEVELOPER_IMAGE_NAME" 598 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
598 fi 599 fi
599 600
600 print_time_elapsed 601 print_time_elapsed
601 602
602 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" 603 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
603 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" 604 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
604 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" 605 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
605 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" 606 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
606 echo "from the scripts directory where you entered the chroot." 607 echo "from the scripts directory where you entered the chroot."
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