| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # | 2 # |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 # Load common constants. This should be the first executable line. | 7 # Load common constants. This should be the first executable line. |
| 8 # The path to common.sh should be relative to your script's location. | 8 # The path to common.sh should be relative to your script's location. |
| 9 . "$(dirname "$0")/common.sh" | 9 . "$(dirname "$0")/common.sh" |
| 10 | 10 |
| 11 # Load functions and constants for chromeos-install | 11 # Load functions and constants for chromeos-install |
| 12 . "$(dirname "$0")/chromeos-common.sh" | 12 . "$(dirname "$0")/chromeos-common.sh" |
| 13 | 13 |
| 14 # Script must be run inside the chroot. | 14 # Script must be run inside the chroot. |
| 15 assert_inside_chroot | 15 assert_inside_chroot |
| 16 | 16 |
| 17 get_default_board | 17 get_default_board |
| 18 | 18 |
| 19 # Flags. | 19 # Flags. |
| 20 DEFINE_string arch "" \ | 20 DEFINE_string arch "" \ |
| 21 "The target architecture (\"arm\" or \"x86\")." | 21 "The target architecture (\"arm\" or \"x86\")." |
| 22 DEFINE_string board "$DEFAULT_BOARD" \ | 22 DEFINE_string board "$DEFAULT_BOARD" \ |
| 23 "The board to build an image for." | 23 "The board to build an image for." |
| 24 DEFINE_string board_root "" \ | 24 DEFINE_string board_root "" \ |
| 25 "The build directory, needed to find tools for ARM." | 25 "The build directory, needed to find tools for ARM." |
| 26 | 26 |
| 27 # Usage. | 27 # Usage. |
| 28 FLAGS_HELP=$(cat <<EOF | 28 FLAGS_HELP=$(cat <<EOF |
| 29 | 29 |
| 30 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV | 30 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV |
| 31 | 31 |
| 32 This takes the image components in IMAGEDIR and creates a bootable, | 32 This takes the image components in IMAGEDIR and creates a bootable, |
| 33 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. | 33 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. |
| 34 | 34 |
| 35 EOF | 35 EOF |
| 36 ) | 36 ) |
| 37 | 37 |
| 38 # Parse command line. | 38 # Parse command line. |
| 39 FLAGS "$@" || exit 1 | 39 FLAGS "$@" || exit 1 |
| 40 eval set -- "${FLAGS_ARGV}" | 40 eval set -- "${FLAGS_ARGV}" |
| 41 | 41 |
| 42 if [[ -z "$FLAGS_board" ]] ; then | 42 if [[ -z "$FLAGS_board" ]] ; then |
| 43 error "--board is required." | 43 error "--board is required." |
| 44 exit 1 | 44 exit 1 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 error "Can't find ${KERNEL_IMG}" | 92 error "Can't find ${KERNEL_IMG}" |
| 93 exit 1 | 93 exit 1 |
| 94 fi | 94 fi |
| 95 | 95 |
| 96 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" | 96 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" |
| 97 if [[ ! -s ${STATEFUL_IMG} ]]; then | 97 if [[ ! -s ${STATEFUL_IMG} ]]; then |
| 98 error "Can't find ${STATEFUL_IMG}" | 98 error "Can't find ${STATEFUL_IMG}" |
| 99 exit 1 | 99 exit 1 |
| 100 fi | 100 fi |
| 101 | 101 |
| 102 ESP_IMG="${IMAGEDIR}/esp.image" |
| 103 if [[ ! -s ${ESP_IMG} ]]; then |
| 104 error "Can't find ${ESP_IMG}" |
| 105 exit 1 |
| 106 fi |
| 107 |
| 102 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM | 108 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM |
| 103 # systems will use a U-Boot script temporarily, but it goes in the same place. | 109 # systems will use a U-Boot script temporarily, but it goes in the same place. |
| 104 if [[ "$ARCH" = "arm" ]]; then | 110 if [[ "$ARCH" = "arm" ]]; then |
| 105 # We need to know the location and size of the kernel so we can create the | 111 # We need to know the location and size of the kernel so we can create the |
| 106 # U-Boot script to point to it. Let's create one fake GPT first which will | 112 # U-Boot script to point to it. Let's create one fake GPT first which will |
| 107 # set the appropriate environment variables. Then we can create the correct | 113 # set the appropriate environment variables. Then we can create the correct |
| 108 # script and install it for real. A bit awkward, but this is only temporary. | 114 # script and install it for real. A bit awkward, but this is only temporary. |
| 109 echo "Installing fake GPT first, to calculate locations..." | 115 echo "Installing fake GPT first, to calculate locations..." |
| 110 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG /dev/zero | 116 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG /dev/zero $ESP_IMG |
| 111 | 117 |
| 112 # Create the U-Boot script to copy the kernel into memory and boot it. | 118 # Create the U-Boot script to copy the kernel into memory and boot it. |
| 113 KERNEL_OFFSET=$(printf "0x%08x" ${START_KERN_A}) | 119 KERNEL_OFFSET=$(printf "0x%08x" ${START_KERN_A}) |
| 114 KERNEL_SECS_HEX=$(printf "0x%08x" ${NUM_KERN_SECTORS}) | 120 KERNEL_SECS_HEX=$(printf "0x%08x" ${NUM_KERN_SECTORS}) |
| 115 | 121 |
| 116 BOOTARGS="root=/dev/mmcblk1p3" | 122 BOOTARGS="root=/dev/mmcblk1p3" |
| 117 BOOTARGS="${BOOTARGS} init=/sbin/init" | 123 BOOTARGS="${BOOTARGS} init=/sbin/init" |
| 118 BOOTARGS="${BOOTARGS} console=ttySAC2,115200" | 124 BOOTARGS="${BOOTARGS} console=ttySAC2,115200" |
| 119 BOOTARGS="${BOOTARGS} mem=1024M" | 125 BOOTARGS="${BOOTARGS} mem=1024M" |
| 120 BOOTARGS="${BOOTARGS} rootwait" | 126 BOOTARGS="${BOOTARGS} rootwait" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 echo "Error: u-boot mkimage not found or not executable." | 146 echo "Error: u-boot mkimage not found or not executable." |
| 141 exit 1 | 147 exit 1 |
| 142 fi | 148 fi |
| 143 PMBRCODE=${MBR_IMG} | 149 PMBRCODE=${MBR_IMG} |
| 144 else | 150 else |
| 145 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) | 151 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) |
| 146 fi | 152 fi |
| 147 | 153 |
| 148 # Create the GPT. This has the side-effect of setting some global vars | 154 # Create the GPT. This has the side-effect of setting some global vars |
| 149 # describing the partition table entries (see the comments in the source). | 155 # describing the partition table entries (see the comments in the source). |
| 150 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE | 156 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG |
| 151 | 157 |
| 152 # Emit helpful scripts for testers, etc. | 158 # Emit helpful scripts for testers, etc. |
| 153 ${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" | 159 ${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" |
| 154 | 160 |
| 155 sudo= | 161 sudo= |
| 156 if [ ! -w "$OUTDEV" ] ; then | 162 if [ ! -w "$OUTDEV" ] ; then |
| 157 # use sudo when writing to a block device. | 163 # use sudo when writing to a block device. |
| 158 sudo=sudo | 164 sudo=sudo |
| 159 fi | 165 fi |
| 160 | 166 |
| 161 # Now populate the partitions. | 167 # Now populate the partitions. |
| 162 echo "Copying stateful partition..." | 168 echo "Copying stateful partition..." |
| 163 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | 169 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ |
| 164 seek=${START_STATEFUL} | 170 seek=${START_STATEFUL} |
| 165 | 171 |
| 166 echo "Copying kernel..." | 172 echo "Copying kernel..." |
| 167 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} | 173 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} |
| 168 | 174 |
| 169 echo "Copying rootfs..." | 175 echo "Copying rootfs..." |
| 170 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A
} | 176 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A
} |
| 171 | 177 |
| 178 echo "Copying EFI system partition..." |
| 179 dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} |
| 180 |
| 172 # Clean up temporary files. | 181 # Clean up temporary files. |
| 173 if [[ -n "${MBR_IMG:-}" ]]; then | 182 if [[ -n "${MBR_IMG:-}" ]]; then |
| 174 rm "${MBR_IMG}" | 183 rm "${MBR_IMG}" |
| 175 fi | 184 fi |
| OLD | NEW |