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 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. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 80 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
81 | 81 |
82 # If we are creating a developer image, also create a pristine image with a | 82 # If we are creating a developer image, also create a pristine image with a |
83 # different name. | 83 # different name. |
84 DEVELOPER_IMAGE_NAME= | 84 DEVELOPER_IMAGE_NAME= |
85 PRISTINE_IMAGE_NAME=chromiumos_image.bin | 85 PRISTINE_IMAGE_NAME=chromiumos_image.bin |
86 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then | 86 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then |
87 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin | 87 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
88 DEVELOPER_IMAGE_NAME=chromiumos_image.bin | 88 DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
89 fi | 89 fi |
| 90 |
| 91 # If we are creating a recovery image, rename pristine image |
| 92 if [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ]; then |
| 93 PRISTINE_IMAGE_NAME=recovery_image.bin |
| 94 fi |
| 95 |
90 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} | 96 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} |
91 | 97 |
92 BOARD="${FLAGS_board}" | 98 BOARD="${FLAGS_board}" |
93 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 99 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
94 | 100 |
95 LOOP_DEV= | 101 LOOP_DEV= |
96 STATEFUL_LOOP_DEV= | 102 STATEFUL_LOOP_DEV= |
97 ESP_LOOP_DEV= | 103 ESP_LOOP_DEV= |
98 | 104 |
99 # What cross-build are we targeting? | 105 # What cross-build are we targeting? |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 fi | 192 fi |
187 } | 193 } |
188 | 194 |
189 # $1 - Directory where developer rootfs is mounted. | 195 # $1 - Directory where developer rootfs is mounted. |
190 # $2 - Directory where developer stateful_partition is mounted. | 196 # $2 - Directory where developer stateful_partition is mounted. |
191 developer_cleanup() { | 197 developer_cleanup() { |
192 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2" | 198 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2" |
193 delete_prompt | 199 delete_prompt |
194 } | 200 } |
195 | 201 |
196 # Creates a new image based on $OUTPUT_IMG with additional developer packages. | 202 # Creates a modified image based on $OUTPUT_IMG with additional packages. |
197 create_developer_image() { | 203 create_mod_image() { |
| 204 local image_type=$1 |
198 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev" | 205 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev" |
199 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image" | 206 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image" |
200 local output_img="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" | 207 local image_to_mount=${DEVELOPER_IMAGE_NAME} |
| 208 local output_img="${OUTPUT_DIR}/${image_to_mount}" |
201 | 209 |
202 # Create stateful partition of the same size as the rootfs. | 210 # Create stateful partition of the same size as the rootfs. |
203 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image" | 211 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image" |
204 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev" | 212 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev" |
| 213 local file_to_touch=".dev_mode" |
205 | 214 |
206 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT | 215 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT |
207 | 216 |
208 # Mount a new copy of the base image. | 217 if [ "$image_type" == "dev" ]; then |
209 echo "Creating developer image from base image $OUTPUT_IMG" | 218 # Mount a new copy of the base image. |
210 cp "$OUTPUT_IMG" "$output_img" | 219 echo "Creating developer image from base image $OUTPUT_IMG" |
| 220 cp "$OUTPUT_IMG" "$output_img" |
| 221 elif [ "$image_type" == "recovery" ]; then |
| 222 image_to_mount=$PRISTINE_IMAGE_NAME |
| 223 file_to_touch=".recovery_installer" |
| 224 fi |
| 225 |
211 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \ | 226 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \ |
212 --image "$DEVELOPER_IMAGE_NAME" -r "$root_fs_dir" -s "$stateful_dir" | 227 --image "$image_to_mount" -r "$root_fs_dir" -s "$stateful_dir" |
213 | 228 |
214 # Determine the root dir for developer packages. | 229 if [ "$image_type" == "dev" ]; then |
215 local root_dev_dir="$root_fs_dir" | 230 # Determine the root dir for developer packages. |
216 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \ | 231 local root_dev_dir="$root_fs_dir" |
217 root_dev_dir="$root_fs_dir/usr/local" | 232 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \ |
| 233 root_dev_dir="$root_fs_dir/usr/local" |
218 | 234 |
219 # Install developer packages described in chromeos-dev. | 235 # Install developer packages described in chromeos-dev. |
220 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ | 236 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ |
221 --root="$root_dev_dir" --root-deps=rdeps \ | 237 --root="$root_dev_dir" --root-deps=rdeps \ |
222 --usepkgonly chromeos-dev $EMERGE_JOBS | 238 --usepkgonly chromeos-dev $EMERGE_JOBS |
| 239 elif [ "$image_type" == "recovery" ]; then |
| 240 # Install recovery installer |
| 241 sudo emerge-${BOARD} --root=$root_fs_dir --usepkgonly \ |
| 242 --root-deps=rdeps --nodeps chromeos-recovery |
| 243 fi |
223 | 244 |
224 # Re-run ldconfig to fix /etc/ldconfig.so.cache. | 245 # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
225 sudo /sbin/ldconfig -r "$root_fs_dir" | 246 sudo /sbin/ldconfig -r "$root_fs_dir" |
226 | 247 |
227 # Mark the image as a developer image (input to chromeos_startup). | 248 # Mark the image as a developer image (input to chromeos_startup). |
228 sudo mkdir -p "$root_fs_dir/root" | 249 sudo mkdir -p "$root_fs_dir/root" |
229 sudo touch "$root_fs_dir/root/.dev_mode" | 250 sudo touch "$root_fs_dir/root/$file_to_touch" |
230 | 251 |
231 # Additional changes to developer image. | 252 if [ "$image_type" == "dev" ]; then |
| 253 # Additional changes to developer image. |
232 | 254 |
233 # The ldd tool is a useful shell script but lives in glibc; just copy it. | 255 # The ldd tool is a useful shell script but lives in glibc; just copy it. |
234 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" | 256 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" |
235 | 257 |
236 # TODO: Temporarily create fake xterm symlink until we do proper xinitrc | 258 # TODO: Temporarily create fake xterm symlink until we do proper xinitrc |
237 local aterm="$root_fs_dir/usr/local/bin/aterm" | 259 local aterm="$root_fs_dir/usr/local/bin/aterm" |
238 if [[ -f "${aterm}" ]]; then | 260 if [[ -f "${aterm}" ]]; then |
239 sudo chmod 0755 "$aterm" | 261 sudo chmod 0755 "$aterm" |
240 sudo ln -s aterm "${root_fs_dir}/usr/local/bin/xterm" | 262 sudo ln -s aterm "${root_fs_dir}/usr/local/bin/xterm" |
241 fi | 263 fi |
242 | 264 |
243 # If vim is installed, then a vi symlink would probably help. | 265 # If vim is installed, then a vi symlink would probably help. |
244 if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then | 266 if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then |
245 sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi" | 267 sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi" |
246 fi | 268 fi |
247 | 269 |
248 # Check that the image has been correctly created. Only do it if not | 270 # Check that the image has been correctly created. Only do it if not |
249 # building a factory install image, as the INSTALL_MASK for it will | 271 # building a factory install image, as the INSTALL_MASK for it will |
250 # make test_image fail. | 272 # make test_image fail. |
251 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then | 273 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then |
252 "${SCRIPTS_DIR}/test_image" \ | 274 "${SCRIPTS_DIR}/test_image" \ |
253 --root="$root_fs_dir" \ | 275 --root="$root_fs_dir" \ |
254 --target="$ARCH" | 276 --target="$ARCH" |
| 277 fi |
| 278 echo "Developer image built and stored at $output_img" |
255 fi | 279 fi |
256 | 280 |
257 trap - EXIT | 281 trap - EXIT |
258 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir" | 282 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir" |
259 sudo rm -rf "$root_fs_dir" "$stateful_dir" | 283 sudo rm -rf "$root_fs_dir" "$stateful_dir" |
260 echo "Developer image built and stored at $output_img" | |
261 } | 284 } |
262 | 285 |
263 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 286 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
264 # be installed on the stateful dir. On a Chromium OS system, this will | 287 # be installed on the stateful dir. On a Chromium OS system, this will |
265 # translate to /usr/local | 288 # translate to /usr/local |
266 DEV_IMAGE_ROOT= | 289 DEV_IMAGE_ROOT= |
267 | 290 |
268 trap "cleanup && delete_prompt" EXIT | 291 trap "cleanup && delete_prompt" EXIT |
269 | 292 |
270 mkdir -p "$ROOT_FS_DIR" | 293 mkdir -p "$ROOT_FS_DIR" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 "${OUTPUT_DIR}" \ | 534 "${OUTPUT_DIR}" \ |
512 "${OUTPUT_IMG}" | 535 "${OUTPUT_IMG}" |
513 | 536 |
514 # Clean up temporary files. | 537 # Clean up temporary files. |
515 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 538 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
516 "${ESP_IMG}" | 539 "${ESP_IMG}" |
517 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" | 540 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" |
518 | 541 |
519 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 542 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
520 | 543 |
| 544 # Create a recovery image based on the chromium os base image |
| 545 [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ] && create_mod_image "recovery" |
| 546 trap - EXIT |
| 547 |
521 # Create a developer image based on the chromium os base image | 548 # Create a developer image based on the chromium os base image |
522 [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_developer_image | 549 [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_mod_image "dev" |
523 trap - EXIT | 550 trap - EXIT |
524 | 551 |
525 # be quiet again | 552 # be quiet again |
526 set +x | 553 set +x |
527 | 554 |
528 echo "Done. Image created in ${OUTPUT_DIR}" | 555 echo "Done. Image created in ${OUTPUT_DIR}" |
529 echo "Chromium OS image created as $PRISTINE_IMAGE_NAME" | 556 echo "Chromium OS image created as $PRISTINE_IMAGE_NAME" |
| 557 if [ "$FLAGS_recovery" -eq "$FLAGS_TRUE" ]; then |
| 558 echo "Recovery image created as $PRISTINE_IMAGE_NAME" |
| 559 fi |
530 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then | 560 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then |
531 echo "Developer image created as $DEVELOPER_IMAGE_NAME" | 561 echo "Developer image created as $DEVELOPER_IMAGE_NAME" |
532 fi | 562 fi |
533 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 563 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
534 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 564 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
535 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 565 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
536 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 566 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
537 echo "from the scripts directory where you entered the chroot." | 567 echo "from the scripts directory where you entered the chroot." |
OLD | NEW |