diff --git a/build_gpt.sh b/build_gpt.sh index f9179b2b8d..d9346202f0 100755 --- a/build_gpt.sh +++ b/build_gpt.sh @@ -130,6 +130,7 @@ if [[ "$ARCH" = "arm" ]]; then hexdump -v -C "$MBR_IMG" else echo "Error: u-boot mkimage not found or not executable." + exit 1 fi PMBRCODE=${MBR_IMG} else @@ -140,6 +141,9 @@ fi # describing the partition table entries (see the comments in the source). install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE +# Emit helpful scripts for testers, etc. +${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" + # Now populate the partitions. echo "Copying stateful partition..." dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_STATEFUL} @@ -150,3 +154,7 @@ dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} echo "Copying rootfs..." dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A} +# Clean up temporary files. +if [[ -n "${MBR_IMG:-}" ]]; then + rm "${MBR_IMG}" +fi diff --git a/build_image b/build_image index dbe62a74be..b6b665a6b5 100755 --- a/build_image +++ b/build_image @@ -69,7 +69,6 @@ IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" -MBR_IMG="${OUTPUT_DIR}/mbr.image" OUTPUT_IMG="${OUTPUT_DIR}/chromiumos_image.bin" BOARD="${FLAGS_board}" @@ -323,7 +322,7 @@ fi # Extract the kernel from the root filesystem for use by the GPT image. Legacy # BIOS will use the kernel in the rootfs (via syslinux), ChromeOS BIOS will use # the kernel partition. -sudo cp -f ${ROOT_FS_DIR}/boot/vmlinuz ${OUTPUT_DIR}/vmlinuz.image +sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here? "${SCRIPTS_DIR}/customize_rootfs" \ @@ -355,8 +354,11 @@ cleanup_rootfs_loop # Create the GPT-formatted image ${SCRIPTS_DIR}/build_gpt.sh \ --arch=${ARCH} --board=${FLAGS_board} --board_root=${BOARD_ROOT} \ - ${OUTPUT_DIR} ${OUTPUT_IMG} + "${OUTPUT_DIR}" "${OUTPUT_IMG}" +# Clean up temporary files. +rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" +rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" echo "Done. Image created in ${OUTPUT_DIR}" diff --git a/emit_gpt_scripts.sh b/emit_gpt_scripts.sh new file mode 100755 index 0000000000..4fea63d175 --- /dev/null +++ b/emit_gpt_scripts.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Emit scripts to pack and unpack the partitions from a GPT disk image. + +# Load common constants. This should be the first executable line. +# The path to common.sh should be relative to your script's location. +. "$(dirname "$0")/common.sh" +. "$(dirname "$0")/chromeos-common.sh" + +set -e + +# Usage +IMAGE=${1:-} +DIR=${2:-} +if [[ -z "$IMAGE" || -z "$DIR" ]]; then + echo "Usage: $0 GPT_DEVICE DIRECTORY" 1>&2 + exit 1 +fi + +PACK="${DIR}/pack_partitions.sh" +UNPACK="${DIR}/unpack_partitions.sh" + +TMP=$(mktemp) +sudo $GPT -r show -l "$IMAGE" > $TMP + +HEADER='#!/bin/sh -eu +# File generated by emit_gpt_scripts.sh. Do not edit. +TARGET=${1:-} +if [[ -z "$TARGET" ]]; then + echo "Usage: $0 DEVICE" 1>&2 + exit 1 +fi +set -x' + +echo "$HEADER" > "$PACK" +echo "$HEADER" > "$UNPACK" +cat $TMP | sed -e 's/^/# /' >> "$PACK" +cat $TMP | sed -e 's/^/# /' >> "$UNPACK" + +sort -n -k 3 $TMP | \ + grep 'GPT part -' | \ + while read start size part x x x label x; do \ + file="part_$part" + loc="\"\$TARGET\"" + echo "sudo dd if=$loc of=$file bs=512 skip=$start count=$size" \ + >> "$UNPACK" + echo \ + "sudo dd if=$file of=$loc bs=512 seek=$start count=$size conv=notrunc" \ + >> "$PACK" + done + +chmod +x "$PACK" "$UNPACK" + +rm $TMP diff --git a/image_to_usb.sh b/image_to_usb.sh index 60ade0ccbd..b881e1a946 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -18,7 +18,7 @@ get_default_board # Flags DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" DEFINE_string from "" \ - "Directory containing rootfs.image and mbr.image" + "Directory containing chromiumos_image.bin" DEFINE_string to "" "${DEFAULT_TO_HELP}" DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" DEFINE_boolean install_autotest ${FLAGS_FALSE} \ @@ -26,7 +26,7 @@ DEFINE_boolean install_autotest ${FLAGS_FALSE} \ DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ "Copy the kernel to the fourth partition." DEFINE_boolean test_image "${FLAGS_FALSE}" \ - "Uses test image if available, otherwise creates one as rootfs_test.image." + "Copies normal image to chromiumos_test_image.bin, modifies it for test." DEFINE_string build_root "/build" \ "The root location for board sysroots." @@ -100,12 +100,14 @@ if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then fi STATEFUL_DIR="${FLAGS_from}/stateful_partition" +mkdir -p "${STATEFUL_DIR}" function do_cleanup { echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" if [ "${STATEFUL_LOOP_DEV}" != "" ]; then sudo umount "${STATEFUL_DIR}" sudo losetup -d "${STATEFUL_LOOP_DEV}" + rmdir "${STATEFUL_DIR}" echo "Cleaned" fi } @@ -144,6 +146,7 @@ if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then sudo umount ${STATEFUL_DIR} sudo losetup -d "${stateful_loop_dev}" trap - INT TERM EXIT + rmdir "${STATEFUL_DIR}" else echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." echo "Please call make_autotest.sh inside chroot first." diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index c38fc92117..8d778e9d2f 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -75,6 +75,8 @@ cleanup() { cleanup_rootfs_loop fi + rmdir "${ROOT_FS_DIR}" + # Turn die on error back on. set -e } @@ -94,11 +96,12 @@ else fi set -e -trap cleanup EXIT ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs mkdir -p "${ROOT_FS_DIR}" +trap cleanup EXIT + # Figure out how to loop mount the rootfs partition. It should be partition 3 # on the disk image. offset=$(partoffset "${FLAGS_image}" 3)