OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 # |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 # |
| 7 |
| 8 # Load common constants. This should be the first executable line. |
| 9 # The path to common.sh should be relative to your script's location. |
| 10 . "$(dirname "$0")/common.sh" |
| 11 |
| 12 # Load functions and constants for chromeos-install |
| 13 . "$(dirname "$0")/chromeos-common.sh" |
| 14 |
| 15 # Script must be run inside the chroot. |
| 16 assert_inside_chroot |
| 17 |
| 18 get_default_board |
| 19 |
| 20 # Flags. |
| 21 DEFINE_string arch "" \ |
| 22 "The target architecture (\"arm\" or \"x86\")." |
| 23 DEFINE_string board "$DEFAULT_BOARD" \ |
| 24 "The board to build an image for." |
| 25 DEFINE_string board_root "" \ |
| 26 "The build directory, needed to find tools for ARM." |
| 27 |
| 28 # Usage. |
| 29 FLAGS_HELP=$(cat <<EOF |
| 30 |
| 31 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV |
| 32 |
| 33 This takes the image components in IMAGEDIR and creates a bootable, |
| 34 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. |
| 35 |
| 36 EOF |
| 37 ) |
| 38 |
| 39 # Parse command line. |
| 40 FLAGS "$@" || exit 1 |
| 41 eval set -- "${FLAGS_ARGV}" |
| 42 |
| 43 if [[ -z "$FLAGS_board" ]] ; then |
| 44 error "--board is required." |
| 45 exit 1 |
| 46 fi |
| 47 |
| 48 if [[ -z "$1" || -z "$2" ]] ; then |
| 49 flags_help |
| 50 exit 1 |
| 51 fi |
| 52 IMAGEDIR="$1" |
| 53 OUTDEV="$2" |
| 54 |
| 55 if [[ -n "$FLAGS_arch" ]]; then |
| 56 ARCH=${FLAGS_arch} |
| 57 else |
| 58 # Figure out ARCH from the given toolchain. |
| 59 # TODO: Move to common.sh as a function after scripts are switched over. |
| 60 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') |
| 61 case "$TC_ARCH" in |
| 62 arm*) |
| 63 ARCH="arm" |
| 64 ;; |
| 65 *86) |
| 66 ARCH="x86" |
| 67 ;; |
| 68 *) |
| 69 error "Unable to determine ARCH from toolchain: $CHOST" |
| 70 exit 1 |
| 71 esac |
| 72 fi |
| 73 |
| 74 if [[ -z "$FLAGS_board_root" ]]; then |
| 75 FLAGS_board_root="/build/${FLAGS_board}" |
| 76 fi |
| 77 |
| 78 # Only now can we die on error. shflags functions leak non-zero error codes, |
| 79 # so will die prematurely if 'set -e' is specified before now. |
| 80 set -e |
| 81 # Die on uninitialized variables. |
| 82 set -u |
| 83 |
| 84 # Check for missing parts. |
| 85 ROOTFS_IMG="${IMAGEDIR}/rootfs.image" |
| 86 if [[ ! -s ${ROOTFS_IMG} ]]; then |
| 87 error "Can't find ${ROOTFS_IMG}" |
| 88 exit 1 |
| 89 fi |
| 90 |
| 91 KERNEL_IMG="${IMAGEDIR}/vmlinuz.image" |
| 92 if [[ ! -s ${KERNEL_IMG} ]]; then |
| 93 error "Can't find ${KERNEL_IMG}" |
| 94 exit 1 |
| 95 fi |
| 96 |
| 97 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" |
| 98 if [[ ! -s ${STATEFUL_IMG} ]]; then |
| 99 error "Can't find ${STATEFUL_IMG}" |
| 100 exit 1 |
| 101 fi |
| 102 |
| 103 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM |
| 104 # systems will use a U-Boot script temporarily, but it goes in the same place. |
| 105 if [[ "$ARCH" = "arm" ]]; then |
| 106 # U-Boot script copies the kernel into memory, then boots it. |
| 107 KERNEL_OFFSET=$(printf "0x%08x" ${START_KERN_A}) |
| 108 KERNEL_SECS_HEX=$(printf "0x%08x" ${NUM_KERN_BLOCKS}) |
| 109 MBR_SCRIPT="${IMAGEDIR}/mbr_script" |
| 110 echo -e "echo\necho ---- ChromeOS Boot ----\necho\n" \ |
| 111 "mmc read 1 C0008000 $KERNEL_OFFSET $KERNEL_SECS_HEX\n" \ |
| 112 "bootm C0008000" > ${MBR_SCRIPT} |
| 113 MKIMAGE="${FLAGS_board_root}/u-boot/mkimage" |
| 114 if [[ -f "$MKIMAGE".gz ]]; then |
| 115 sudo gunzip "$MKIMAGE".gz |
| 116 fi |
| 117 if [[ -x "$MKIMAGE" ]]; then |
| 118 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" |
| 119 "$MKIMAGE" -A "${ARCH}" -O linux -T script -a 0 -e 0 -n "COS boot" \ |
| 120 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} |
| 121 MBR_IMG=${IMAGEDIR}/mbr.img |
| 122 dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ |
| 123 if="$MBR_SCRIPT_UIMG" of="$MBR_IMG" conv=notrunc |
| 124 hexdump -v -C "$MBR_IMG" |
| 125 else |
| 126 echo "Error: u-boot mkimage not found or not executable." |
| 127 fi |
| 128 PMBRCODE=${MBR_IMG} |
| 129 else |
| 130 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) |
| 131 fi |
| 132 |
| 133 # Create the GPT. This has the side-effect of setting some global vars |
| 134 # describing the partition table entries (see the comments in the source). |
| 135 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE |
| 136 |
| 137 # Now populate the partitions. |
| 138 echo "Copying stateful partition..." |
| 139 dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_STATEFUL} |
| 140 |
| 141 echo "Copying kernel..." |
| 142 dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} |
| 143 |
| 144 echo "Copying rootfs..." |
| 145 dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A} |
| 146 |
OLD | NEW |