| 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 # Load common constants. This should be the first executable line. | |
| 8 # The path to common.sh should be relative to your script's location. | |
| 9 . "/usr/lib/crosutils/common.sh" | |
| 10 | |
| 11 # Load functions and constants for chromeos-install | |
| 12 . "/usr/lib/installer/chromeos-common.sh" | |
| 13 | |
| 14 # Script must be run inside the chroot. | |
| 15 restart_in_chroot_if_needed $* | |
| 16 | |
| 17 get_default_board | |
| 18 | |
| 19 # Flags. | |
| 20 DEFINE_string arch "" \ | |
| 21 "The target architecture (\"arm\" or \"x86\")." | |
| 22 DEFINE_string board "$DEFAULT_BOARD" \ | |
| 23 "The board to build an image for." | |
| 24 DEFINE_string arm_extra_bootargs "" \ | |
| 25 "Additional command line options to pass to the ARM kernel." | |
| 26 DEFINE_integer rootfs_partition_size 1024 \ | |
| 27 "rootfs parition size in MBs." | |
| 28 | |
| 29 # Usage. | |
| 30 FLAGS_HELP=$(cat <<EOF | |
| 31 | |
| 32 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV | |
| 33 | |
| 34 This takes the image components in IMAGEDIR and creates a bootable, | |
| 35 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. | |
| 36 | |
| 37 EOF | |
| 38 ) | |
| 39 | |
| 40 # Parse command line. | |
| 41 FLAGS "$@" || exit 1 | |
| 42 eval set -- "${FLAGS_ARGV}" | |
| 43 | |
| 44 if [[ -z "$FLAGS_board" ]] ; then | |
| 45 error "--board is required." | |
| 46 exit 1 | |
| 47 fi | |
| 48 | |
| 49 if [[ -z "$1" || -z "$2" ]] ; then | |
| 50 flags_help | |
| 51 exit 1 | |
| 52 fi | |
| 53 IMAGEDIR="$1" | |
| 54 OUTDEV="$2" | |
| 55 | |
| 56 if [[ -n "$FLAGS_arch" ]]; then | |
| 57 ARCH=${FLAGS_arch} | |
| 58 else | |
| 59 # Figure out ARCH from the given toolchain. | |
| 60 # TODO: Move to common.sh as a function after scripts are switched over. | |
| 61 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') | |
| 62 case "$TC_ARCH" in | |
| 63 arm*) | |
| 64 ARCH="arm" | |
| 65 ;; | |
| 66 *86) | |
| 67 ARCH="x86" | |
| 68 ;; | |
| 69 *) | |
| 70 error "Unable to determine ARCH from toolchain: $CHOST" | |
| 71 exit 1 | |
| 72 esac | |
| 73 fi | |
| 74 | |
| 75 # Only now can we die on error. shflags functions leak non-zero error codes, | |
| 76 # so will die prematurely if 'set -e' is specified before now. | |
| 77 set -e | |
| 78 # Die on uninitialized variables. | |
| 79 set -u | |
| 80 | |
| 81 # Check for missing parts. | |
| 82 ROOTFS_IMG="${IMAGEDIR}/rootfs.image" | |
| 83 if [[ ! -s ${ROOTFS_IMG} ]]; then | |
| 84 error "Can't find ${ROOTFS_IMG}" | |
| 85 exit 1 | |
| 86 fi | |
| 87 | |
| 88 KERNEL_IMG="${IMAGEDIR}/vmlinuz.image" | |
| 89 if [[ ! -s ${KERNEL_IMG} ]]; then | |
| 90 error "Can't find ${KERNEL_IMG}" | |
| 91 exit 1 | |
| 92 fi | |
| 93 | |
| 94 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" | |
| 95 if [ ! -s ${STATEFUL_IMG} ]; then | |
| 96 error "Can't find ${STATEFUL_IMG}" | |
| 97 exit 1 | |
| 98 fi | |
| 99 | |
| 100 OEM_IMG="${IMAGEDIR}/partner_partition.image" | |
| 101 if [[ ! -s ${OEM_IMG} ]]; then | |
| 102 error "Can't find ${OEM_IMG}" | |
| 103 exit 1 | |
| 104 fi | |
| 105 | |
| 106 ESP_IMG="${IMAGEDIR}/esp.image" | |
| 107 if [ ! -s ${ESP_IMG} ]; then | |
| 108 error "Can't find ${ESP_IMG}" | |
| 109 exit 1 | |
| 110 fi | |
| 111 | |
| 112 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM | |
| 113 # systems will use a U-Boot script temporarily, but it goes in the same place. | |
| 114 if [[ "$ARCH" = "arm" ]]; then | |
| 115 PMBRCODE=/dev/zero | |
| 116 else | |
| 117 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) | |
| 118 fi | |
| 119 | |
| 120 # Create the GPT. This has the side-effect of setting some global vars | |
| 121 # describing the partition table entries (see the comments in the source). | |
| 122 install_gpt $OUTDEV $(numsectors $ROOTFS_IMG) $(numsectors $STATEFUL_IMG) \ | |
| 123 $PMBRCODE $(numsectors $ESP_IMG) false $FLAGS_rootfs_partition_size | |
| 124 | |
| 125 if [[ "$ARCH" = "arm" ]]; then | |
| 126 # assume /dev/mmcblk1. we could not get this from ${OUTDEV} | |
| 127 DEVICE=1 | |
| 128 MBR_SCRIPT_UIMG=$(make_arm_mbr \ | |
| 129 ${START_KERN_A} \ | |
| 130 ${NUM_KERN_SECTORS} \ | |
| 131 ${DEVICE} \ | |
| 132 "${FLAGS_arm_extra_bootargs}") | |
| 133 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | |
| 134 if="$MBR_SCRIPT_UIMG" of=${OUTDEV} conv=notrunc | |
| 135 fi | |
| 136 | |
| 137 # Emit helpful scripts for testers, etc. | |
| 138 /usr/bin/cros_emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" | |
| 139 | |
| 140 sudo= | |
| 141 if [ ! -w "$OUTDEV" ] ; then | |
| 142 # use sudo when writing to a block device. | |
| 143 sudo=sudo | |
| 144 fi | |
| 145 | |
| 146 # Now populate the partitions. | |
| 147 echo "Copying stateful partition..." | |
| 148 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | |
| 149 seek=${START_STATEFUL} | |
| 150 | |
| 151 echo "Copying OEM partition..." | |
| 152 $sudo dd if=${OEM_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_OEM} | |
| 153 | |
| 154 echo "Copying kernel..." | |
| 155 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} | |
| 156 | |
| 157 echo "Copying rootfs..." | |
| 158 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | |
| 159 seek=${START_ROOTFS_A} | |
| 160 | |
| 161 echo "Copying EFI system partition..." | |
| 162 $sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} | |
| 163 | |
| 164 # Clean up temporary files. | |
| 165 if [[ -n "${MBR_IMG:-}" ]]; then | |
| 166 rm "${MBR_IMG}" | |
| 167 fi | |
| OLD | NEW |