From e9e585f33096dd3abe34a728a1566dd3db9358c1 Mon Sep 17 00:00:00 2001 From: Antoine Labour Date: Thu, 1 Apr 2010 15:57:57 -0700 Subject: [PATCH] Add a --to option to build_image That way we can directly build an image onto a usb stick/sd card without a separate step. Also, add mounting of /sys into the chroot that is needed by build_gpt on a block device. Review URL: http://codereview.chromium.org/1521012 --- build_gpt.sh | 15 +++++++++++---- build_image | 4 +++- enter_chroot.sh | 7 +++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/build_gpt.sh b/build_gpt.sh index d9346202f0..02be98c2ba 100755 --- a/build_gpt.sh +++ b/build_gpt.sh @@ -144,15 +144,22 @@ install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE # Emit helpful scripts for testers, etc. ${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" +sudo= +if [ ! -w "$OUTDEV" ] ; then + # use sudo when writing to a block device. + sudo=sudo +fi + # Now populate the partitions. echo "Copying stateful partition..." -dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_STATEFUL} +$sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ + seek=${START_STATEFUL} echo "Copying kernel..." -dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} - +$sudo 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} +$sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A} # Clean up temporary files. if [[ -n "${MBR_IMG:-}" ]]; then diff --git a/build_image b/build_image index b6b665a6b5..b1f8fe6e84 100755 --- a/build_image +++ b/build_image @@ -37,6 +37,8 @@ DEFINE_integer jobs -1 \ "How many packages to build in parallel at maximum." DEFINE_boolean statefuldev $FLAGS_FALSE \ "Install development packages on stateful partition -- still experimental" +DEFINE_string to "" \ + "The target image file or device" DEFINE_boolean withtest $FLAGS_FALSE \ "Include packages required for testing and prepare image for testing" @@ -69,7 +71,7 @@ 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" -OUTPUT_IMG="${OUTPUT_DIR}/chromiumos_image.bin" +OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin} BOARD="${FLAGS_board}" BOARD_ROOT="${FLAGS_build_root}/${BOARD}" diff --git a/enter_chroot.sh b/enter_chroot.sh index 33aad4bea3..6ad51fa44c 100755 --- a/enter_chroot.sh +++ b/enter_chroot.sh @@ -84,6 +84,13 @@ function setup_env { die "Could not mount $MOUNTED_PATH" fi + MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] + then + sudo mount none -t sysfs "$MOUNTED_PATH" || \ + die "Could not mount $MOUNTED_PATH" + fi + MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/dev/pts")" if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] then