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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 # Determine build version. | 61 # Determine build version. |
62 . "${SCRIPTS_DIR}/chromeos_version.sh" | 62 . "${SCRIPTS_DIR}/chromeos_version.sh" |
63 | 63 |
64 # Use canonical path since some tools (e.g. mount) do not like symlinks. | 64 # Use canonical path since some tools (e.g. mount) do not like symlinks. |
65 # Append build attempt to output directory. | 65 # Append build attempt to output directory. |
66 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" | 66 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
67 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" | 67 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
68 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" | 68 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
69 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 69 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
70 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin} | 70 |
| 71 # If we are creating a developer image, also create a pristine image with a |
| 72 # different name. |
| 73 DEVELOPER_IMAGE_NAME= |
| 74 PRISTINE_IMAGE_NAME=chromiumos_image.bin |
| 75 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then |
| 76 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
| 77 DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
| 78 fi |
| 79 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} |
71 | 80 |
72 BOARD="${FLAGS_board}" | 81 BOARD="${FLAGS_board}" |
73 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 82 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
74 | 83 |
75 LOOP_DEV= | 84 LOOP_DEV= |
76 STATEFUL_LOOP_DEV= | 85 STATEFUL_LOOP_DEV= |
77 ESP_LOOP_DEV= | 86 ESP_LOOP_DEV= |
78 | 87 |
79 # What cross-build are we targeting? | 88 # What cross-build are we targeting? |
80 . "${BOARD_ROOT}/etc/make.conf.board_setup" | 89 . "${BOARD_ROOT}/etc/make.conf.board_setup" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 SURE="${SURE:0:1}" # Get just the first character | 165 SURE="${SURE:0:1}" # Get just the first character |
157 if [ "${SURE}" == "y" ] ; then | 166 if [ "${SURE}" == "y" ] ; then |
158 sudo rm -rf "$OUTPUT_DIR" | 167 sudo rm -rf "$OUTPUT_DIR" |
159 echo "Deleted $OUTPUT_DIR" | 168 echo "Deleted $OUTPUT_DIR" |
160 else | 169 else |
161 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ | 170 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ |
162 "until you successfully build another image or delete this directory" | 171 "until you successfully build another image or delete this directory" |
163 fi | 172 fi |
164 } | 173 } |
165 | 174 |
| 175 # $1 - Directory where developer rootfs is mounted. |
| 176 # $2 - Directory where developer stateful_partition is mounted. |
| 177 developer_cleanup() { |
| 178 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2" |
| 179 delete_prompt |
| 180 } |
| 181 |
| 182 # Creates a new image based on $OUTPUT_IMG with additional developer packages. |
| 183 create_developer_image() { |
| 184 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev" |
| 185 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image" |
| 186 local output_img="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" |
| 187 |
| 188 # Create stateful partition of the same size as the rootfs. |
| 189 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image" |
| 190 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev" |
| 191 |
| 192 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT |
| 193 |
| 194 # Mount a new copy of the base image. |
| 195 echo "Creating developer image from base image $OUTPUT_IMG" |
| 196 cp "$OUTPUT_IMG" "$output_img" |
| 197 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \ |
| 198 --image "$DEVELOPER_IMAGE_NAME" -r "$root_fs_dir" -s "$stateful_dir" |
| 199 |
| 200 # Determine the root dir for developer packages. |
| 201 local root_dev_dir="$root_fs_dir" |
| 202 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \ |
| 203 root_dev_dir="$root_fs_dir/usr/local" |
| 204 |
| 205 # Install developer packages described in chromeos-dev. |
| 206 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ |
| 207 --root="$root_dev_dir" --root-deps=rdeps \ |
| 208 --usepkgonly chromeos-dev $EMERGE_JOBS |
| 209 |
| 210 # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
| 211 sudo /sbin/ldconfig -r "$root_fs_dir" |
| 212 |
| 213 # Mark the image as a developer image (input to chromeos_startup). |
| 214 sudo mkdir -p "$root_fs_dir/root" |
| 215 sudo touch "$root_fs_dir/root/.dev_mode" |
| 216 |
| 217 # Additional changes to developer image. |
| 218 |
| 219 # The ldd tool is a useful shell script but lives in glibc; just copy it. |
| 220 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" |
| 221 |
| 222 # If vim is installed, then a vi symlink would probably help. |
| 223 if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then |
| 224 sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi" |
| 225 fi |
| 226 |
| 227 # Check that the image has been correctly created. |
| 228 "${SCRIPTS_DIR}/test_image" \ |
| 229 --root="$root_fs_dir" \ |
| 230 --target="$ARCH" |
| 231 |
| 232 trap - EXIT |
| 233 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir" |
| 234 echo "Developer image built and stored at $output_img" |
| 235 } |
| 236 |
166 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 237 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
167 # be installed on the stateful dir. On a Chromium OS system, this will | 238 # be installed on the stateful dir. On a Chromium OS system, this will |
168 # translate to /usr/local | 239 # translate to /usr/local |
169 DEV_IMAGE_ROOT= | 240 DEV_IMAGE_ROOT= |
170 | 241 |
171 trap "cleanup && delete_prompt" EXIT | 242 trap "cleanup && delete_prompt" EXIT |
172 | 243 |
173 mkdir -p "$ROOT_FS_DIR" | 244 mkdir -p "$ROOT_FS_DIR" |
174 | 245 |
175 # Create and format the root file system. | 246 # Create and format the root file system. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" | 366 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" |
296 | 367 |
297 # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the | 368 # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the |
298 # runtime packages for chrome os. This builds up a chrome os image from binary | 369 # runtime packages for chrome os. This builds up a chrome os image from binary |
299 # packages with runtime dependencies only. We use INSTALL_MASK to trim the | 370 # packages with runtime dependencies only. We use INSTALL_MASK to trim the |
300 # image size as much as possible. | 371 # image size as much as possible. |
301 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ | 372 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ |
302 --root="$ROOT_FS_DIR" --root-deps=rdeps \ | 373 --root="$ROOT_FS_DIR" --root-deps=rdeps \ |
303 --usepkgonly chromeos $EMERGE_JOBS | 374 --usepkgonly chromeos $EMERGE_JOBS |
304 | 375 |
305 # Determine the root dir for development packages. | |
306 ROOT_DEV_DIR="$ROOT_FS_DIR" | |
307 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local" | |
308 | |
309 # Install development packages. | |
310 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then | |
311 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ | |
312 --root="$ROOT_DEV_DIR" --root-deps=rdeps \ | |
313 --usepkgonly chromeos-dev $EMERGE_JOBS | |
314 | |
315 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch | |
316 # Flag will mount /usr/local on target device | |
317 sudo mkdir -p "$ROOT_FS_DIR/root" | |
318 | |
319 # The ldd tool is a useful shell script but lives in glibc; just copy it. | |
320 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin" | |
321 fi | |
322 | |
323 # Extract the kernel from the root filesystem for use by the GPT image. Legacy | 376 # Extract the kernel from the root filesystem for use by the GPT image. Legacy |
324 # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will | 377 # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will |
325 # use the kernel partition. | 378 # use the kernel partition. |
326 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" | 379 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" |
327 | 380 |
328 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI | 381 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
329 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk | 382 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk |
330 # images the same for both x86 and ARM. | 383 # images the same for both x86 and ARM. |
331 ESP_IMG=${OUTPUT_DIR}/esp.image | 384 ESP_IMG=${OUTPUT_DIR}/esp.image |
332 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code | 385 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code |
(...skipping 21 matching lines...) Expand all Loading... |
354 menuentry "local image A" { | 407 menuentry "local image A" { |
355 linux $grubpartA/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartA ro noresume noswap i915.modeset=1 loglevel=1 | 408 linux $grubpartA/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartA ro noresume noswap i915.modeset=1 loglevel=1 |
356 } | 409 } |
357 | 410 |
358 menuentry "local image B" { | 411 menuentry "local image B" { |
359 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1 | 412 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1 |
360 } | 413 } |
361 | 414 |
362 EOF | 415 EOF |
363 | 416 |
364 # By default, dev mode should be activated for either development builds or | |
365 # test builds. | |
366 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then | |
367 sudo touch "$ROOT_FS_DIR/root/.dev_mode" | |
368 | |
369 # Re-run ldconfig to fix /etc/ldconfig.so.cache. | |
370 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" | |
371 fi | |
372 | |
373 # Perform any customizations on the root file system that are needed. | 417 # Perform any customizations on the root file system that are needed. |
374 "${SCRIPTS_DIR}/customize_rootfs" \ | 418 "${SCRIPTS_DIR}/customize_rootfs" \ |
375 --root="$ROOT_FS_DIR" \ | 419 --root="$ROOT_FS_DIR" \ |
376 --target="$ARCH" \ | 420 --target="$ARCH" \ |
377 --board="$BOARD" | 421 --board="$BOARD" |
378 | 422 |
379 # Don't test the factory install shim. | 423 # Don't test the factory install shim. |
380 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then | 424 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then |
381 # Check that the image has been correctly created. | 425 # Check that the image has been correctly created. |
382 "${SCRIPTS_DIR}/test_image" \ | 426 "${SCRIPTS_DIR}/test_image" \ |
(...skipping 18 matching lines...) Expand all Loading... |
401 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ | 445 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
402 "${OUTPUT_DIR}" \ | 446 "${OUTPUT_DIR}" \ |
403 "${OUTPUT_IMG}" | 447 "${OUTPUT_IMG}" |
404 | 448 |
405 # Clean up temporary files. | 449 # Clean up temporary files. |
406 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 450 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
407 "${ESP_IMG}" | 451 "${ESP_IMG}" |
408 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" | 452 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" |
409 | 453 |
410 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 454 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
| 455 |
| 456 # Create a developer image based on the chromium os base image |
| 457 [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_developer_image |
| 458 trap - EXIT |
| 459 |
411 echo "Done. Image created in ${OUTPUT_DIR}" | 460 echo "Done. Image created in ${OUTPUT_DIR}" |
| 461 echo "Chromium OS image created as $PRISTINE_IMAGE_NAME" |
| 462 if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then |
| 463 echo "Developer image created as $DEVELOPER_IMAGE_NAME" |
| 464 fi |
412 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 465 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
413 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 466 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
414 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 467 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
415 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 468 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
416 echo "from the scripts directory where you entered the chroot." | 469 echo "from the scripts directory where you entered the chroot." |
417 | |
418 trap - EXIT | |
OLD | NEW |