Clean up temporary files and directories, add utilities.

Remove the temporary rootfs.image file and others that are left by build_image and related scripts. Also added tool to emit scripts that can pack and unpack the combined disk image.

Review URL: http://codereview.chromium.org/1567013
This commit is contained in:
Bill Richardson 2010-03-31 19:20:24 -07:00
parent faefea3359
commit 6dcea16492
5 changed files with 79 additions and 6 deletions

View File

@ -130,6 +130,7 @@ if [[ "$ARCH" = "arm" ]]; then
hexdump -v -C "$MBR_IMG" hexdump -v -C "$MBR_IMG"
else else
echo "Error: u-boot mkimage not found or not executable." echo "Error: u-boot mkimage not found or not executable."
exit 1
fi fi
PMBRCODE=${MBR_IMG} PMBRCODE=${MBR_IMG}
else else
@ -140,6 +141,9 @@ fi
# describing the partition table entries (see the comments in the source). # describing the partition table entries (see the comments in the source).
install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE 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. # Now populate the partitions.
echo "Copying stateful partition..." echo "Copying stateful partition..."
dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_STATEFUL} 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..." echo "Copying rootfs..."
dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A} 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

View File

@ -69,7 +69,6 @@ IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
MBR_IMG="${OUTPUT_DIR}/mbr.image"
OUTPUT_IMG="${OUTPUT_DIR}/chromiumos_image.bin" OUTPUT_IMG="${OUTPUT_DIR}/chromiumos_image.bin"
BOARD="${FLAGS_board}" BOARD="${FLAGS_board}"
@ -323,7 +322,7 @@ fi
# Extract the kernel from the root filesystem for use by the GPT image. Legacy # 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 # BIOS will use the kernel in the rootfs (via syslinux), ChromeOS BIOS will use
# the kernel partition. # 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? #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here?
"${SCRIPTS_DIR}/customize_rootfs" \ "${SCRIPTS_DIR}/customize_rootfs" \
@ -355,8 +354,11 @@ cleanup_rootfs_loop
# Create the GPT-formatted image # Create the GPT-formatted image
${SCRIPTS_DIR}/build_gpt.sh \ ${SCRIPTS_DIR}/build_gpt.sh \
--arch=${ARCH} --board=${FLAGS_board} --board_root=${BOARD_ROOT} \ --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}" OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
echo "Done. Image created in ${OUTPUT_DIR}" echo "Done. Image created in ${OUTPUT_DIR}"

57
emit_gpt_scripts.sh Executable file
View File

@ -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

View File

@ -18,7 +18,7 @@ get_default_board
# Flags # Flags
DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built"
DEFINE_string from "" \ DEFINE_string from "" \
"Directory containing rootfs.image and mbr.image" "Directory containing chromiumos_image.bin"
DEFINE_string to "" "${DEFAULT_TO_HELP}" DEFINE_string to "" "${DEFAULT_TO_HELP}"
DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y"
DEFINE_boolean install_autotest ${FLAGS_FALSE} \ DEFINE_boolean install_autotest ${FLAGS_FALSE} \
@ -26,7 +26,7 @@ DEFINE_boolean install_autotest ${FLAGS_FALSE} \
DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ DEFINE_boolean copy_kernel ${FLAGS_FALSE} \
"Copy the kernel to the fourth partition." "Copy the kernel to the fourth partition."
DEFINE_boolean test_image "${FLAGS_FALSE}" \ 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" \ DEFINE_string build_root "/build" \
"The root location for board sysroots." "The root location for board sysroots."
@ -100,12 +100,14 @@ if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then
fi fi
STATEFUL_DIR="${FLAGS_from}/stateful_partition" STATEFUL_DIR="${FLAGS_from}/stateful_partition"
mkdir -p "${STATEFUL_DIR}"
function do_cleanup { function do_cleanup {
echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}"
if [ "${STATEFUL_LOOP_DEV}" != "" ]; then if [ "${STATEFUL_LOOP_DEV}" != "" ]; then
sudo umount "${STATEFUL_DIR}" sudo umount "${STATEFUL_DIR}"
sudo losetup -d "${STATEFUL_LOOP_DEV}" sudo losetup -d "${STATEFUL_LOOP_DEV}"
rmdir "${STATEFUL_DIR}"
echo "Cleaned" echo "Cleaned"
fi fi
} }
@ -144,6 +146,7 @@ if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then
sudo umount ${STATEFUL_DIR} sudo umount ${STATEFUL_DIR}
sudo losetup -d "${stateful_loop_dev}" sudo losetup -d "${stateful_loop_dev}"
trap - INT TERM EXIT trap - INT TERM EXIT
rmdir "${STATEFUL_DIR}"
else else
echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed."
echo "Please call make_autotest.sh inside chroot first." echo "Please call make_autotest.sh inside chroot first."

View File

@ -75,6 +75,8 @@ cleanup() {
cleanup_rootfs_loop cleanup_rootfs_loop
fi fi
rmdir "${ROOT_FS_DIR}"
# Turn die on error back on. # Turn die on error back on.
set -e set -e
} }
@ -94,11 +96,12 @@ else
fi fi
set -e set -e
trap cleanup EXIT
ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs
mkdir -p "${ROOT_FS_DIR}" mkdir -p "${ROOT_FS_DIR}"
trap cleanup EXIT
# Figure out how to loop mount the rootfs partition. It should be partition 3 # Figure out how to loop mount the rootfs partition. It should be partition 3
# on the disk image. # on the disk image.
offset=$(partoffset "${FLAGS_image}" 3) offset=$(partoffset "${FLAGS_image}" 3)