| 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 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 ESP_IMG="${IMAGEDIR}/esp.image" | 96 ESP_IMG="${IMAGEDIR}/esp.image" |
| 97 if [[ ! -s ${ESP_IMG} ]]; then | 97 if [[ ! -s ${ESP_IMG} ]]; then |
| 98 error "Can't find ${ESP_IMG}" | 98 error "Can't find ${ESP_IMG}" |
| 99 exit 1 | 99 exit 1 |
| 100 fi | 100 fi |
| 101 | 101 |
| 102 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM | 102 # 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. | 103 # systems will use a U-Boot script temporarily, but it goes in the same place. |
| 104 if [[ "$ARCH" = "arm" ]]; then | 104 if [[ "$ARCH" = "arm" ]]; then |
| 105 # We need to know the location and size of the kernel so we can create the | 105 PMBRCODE=/dev/zero |
| 106 # 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 | |
| 108 # script and install it for real. A bit awkward, but this is only temporary. | |
| 109 echo "Installing fake GPT first, to calculate locations..." | |
| 110 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG /dev/zero $ESP_IMG | |
| 111 | |
| 112 # Create the U-Boot script to copy the kernel into memory and boot it. | |
| 113 KERNEL_OFFSET=$(printf "0x%08x" ${START_KERN_A}) | |
| 114 KERNEL_SECS_HEX=$(printf "0x%08x" ${NUM_KERN_SECTORS}) | |
| 115 | |
| 116 BOOTARGS="root=/dev/mmcblk1p3" | |
| 117 BOOTARGS="${BOOTARGS} init=/sbin/init" | |
| 118 BOOTARGS="${BOOTARGS} console=ttySAC2,115200" | |
| 119 BOOTARGS="${BOOTARGS} mem=1024M" | |
| 120 BOOTARGS="${BOOTARGS} rootwait" | |
| 121 | |
| 122 MBR_SCRIPT="${IMAGEDIR}/mbr_script" | |
| 123 echo -e "echo\necho ---- ChromeOS Boot ----\necho\n" \ | |
| 124 "setenv bootargs ${BOOTARGS}\n" \ | |
| 125 "mmc read 1 C0008000 $KERNEL_OFFSET $KERNEL_SECS_HEX\n" \ | |
| 126 "bootm C0008000" > ${MBR_SCRIPT} | |
| 127 MKIMAGE="/usr/bin/mkimage" | |
| 128 if [[ -f "$MKIMAGE".gz ]]; then | |
| 129 sudo gunzip "$MKIMAGE".gz | |
| 130 fi | |
| 131 if [[ -x "$MKIMAGE" ]]; then | |
| 132 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" | |
| 133 "$MKIMAGE" -A "${ARCH}" -O linux -T script -a 0 -e 0 -n "COS boot" \ | |
| 134 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} | |
| 135 MBR_IMG=${IMAGEDIR}/mbr.img | |
| 136 dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | |
| 137 if="$MBR_SCRIPT_UIMG" of="$MBR_IMG" conv=notrunc | |
| 138 hexdump -v -C "$MBR_IMG" | |
| 139 else | |
| 140 echo "Error: u-boot mkimage not found or not executable." | |
| 141 exit 1 | |
| 142 fi | |
| 143 PMBRCODE=${MBR_IMG} | |
| 144 else | 106 else |
| 145 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) | 107 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) |
| 146 fi | 108 fi |
| 147 | 109 |
| 148 # Create the GPT. This has the side-effect of setting some global vars | 110 # 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). | 111 # describing the partition table entries (see the comments in the source). |
| 150 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG | 112 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG |
| 151 | 113 |
| 114 if [[ "$ARCH" = "arm" ]]; then |
| 115 # assume /dev/mmcblk1. we could not get this from ${OUTDEV} |
| 116 DEVICE=1 |
| 117 MBR_SCRIPT_UIMG=$(make_arm_mbr ${START_KERN_A} ${NUM_KERN_SECTORS} ${DEVICE}) |
| 118 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ |
| 119 if="$MBR_SCRIPT_UIMG" of=${OUTDEV} conv=notrunc |
| 120 fi |
| 121 |
| 152 # Emit helpful scripts for testers, etc. | 122 # Emit helpful scripts for testers, etc. |
| 153 ${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" | 123 ${SCRIPTS_DIR}/emit_gpt_scripts.sh "${OUTDEV}" "${IMAGEDIR}" |
| 154 | 124 |
| 155 sudo= | 125 sudo= |
| 156 if [ ! -w "$OUTDEV" ] ; then | 126 if [ ! -w "$OUTDEV" ] ; then |
| 157 # use sudo when writing to a block device. | 127 # use sudo when writing to a block device. |
| 158 sudo=sudo | 128 sudo=sudo |
| 159 fi | 129 fi |
| 160 | 130 |
| 161 # Now populate the partitions. | 131 # Now populate the partitions. |
| 162 echo "Copying stateful partition..." | 132 echo "Copying stateful partition..." |
| 163 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | 133 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ |
| 164 seek=${START_STATEFUL} | 134 seek=${START_STATEFUL} |
| 165 | 135 |
| 166 echo "Copying kernel..." | 136 echo "Copying kernel..." |
| 167 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} | 137 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} |
| 168 | 138 |
| 169 echo "Copying rootfs..." | 139 echo "Copying rootfs..." |
| 170 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A
} | 140 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ROOTFS_A
} |
| 171 | 141 |
| 172 echo "Copying EFI system partition..." | 142 echo "Copying EFI system partition..." |
| 173 $sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} | 143 $sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} |
| 174 | 144 |
| 175 # Clean up temporary files. | 145 # Clean up temporary files. |
| 176 if [[ -n "${MBR_IMG:-}" ]]; then | 146 if [[ -n "${MBR_IMG:-}" ]]; then |
| 177 rm "${MBR_IMG}" | 147 rm "${MBR_IMG}" |
| 178 fi | 148 fi |
| OLD | NEW |