#!/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. # # 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" # Load functions and constants for chromeos-install . "$(dirname "$0")/chromeos-common.sh" # Script must be run inside the chroot. assert_inside_chroot get_default_board # Flags. DEFINE_string arch "" \ "The target architecture (\"arm\" or \"x86\")." DEFINE_string board "$DEFAULT_BOARD" \ "The board to build an image for." DEFINE_string board_root "" \ "The build directory, needed to find tools for ARM." # Usage. FLAGS_HELP=$(cat < ${MBR_SCRIPT} MKIMAGE="${FLAGS_board_root}/u-boot/mkimage" if [[ -f "$MKIMAGE".gz ]]; then sudo gunzip "$MKIMAGE".gz fi if [[ -x "$MKIMAGE" ]]; then MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" "$MKIMAGE" -A "${ARCH}" -O linux -T script -a 0 -e 0 -n "COS boot" \ -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} MBR_IMG=${IMAGEDIR}/mbr.img dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ if="$MBR_SCRIPT_UIMG" of="$MBR_IMG" conv=notrunc hexdump -v -C "$MBR_IMG" else echo "Error: u-boot mkimage not found or not executable." exit 1 fi PMBRCODE=${MBR_IMG} else PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) fi # Create the GPT. This has the side-effect of setting some global vars # 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}" sudo= if [ ! -w "$OUTDEV" ] ; then # use sudo when writing to a block device. sudo=sudo fi # Now populate the partitions. echo "Copying stateful partition..." $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ seek=${START_STATEFUL} echo "Copying kernel..." $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} echo "Copying rootfs..." $sudo 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