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 restart_in_chroot_if_needed $* | 15 restart_in_chroot_if_needed $* |
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 arm_extra_bootargs "" \ | 24 DEFINE_string arm_extra_bootargs "" \ |
25 "Additional command line options to pass to the ARM kernel." | 25 "Additional command line options to pass to the ARM kernel." |
26 DEFINE_boolean recovery $FLAGS_FALSE \ | |
27 "Build GPT for a recovery image. Default: False." | |
28 DEFINE_integer rootfs_partition_size 1024 \ | 26 DEFINE_integer rootfs_partition_size 1024 \ |
29 "rootfs parition size in MBs." | 27 "rootfs parition size in MBs." |
30 | 28 |
31 # Usage. | 29 # Usage. |
32 FLAGS_HELP=$(cat <<EOF | 30 FLAGS_HELP=$(cat <<EOF |
33 | 31 |
34 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV | 32 Usage: $(basename $0) [flags] IMAGEDIR OUTDEV |
35 | 33 |
36 This takes the image components in IMAGEDIR and creates a bootable, | 34 This takes the image components in IMAGEDIR and creates a bootable, |
37 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. | 35 GPT-formatted image in OUTDEV. OUTDEV can be a file or block device. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 esac | 72 esac |
75 fi | 73 fi |
76 | 74 |
77 # Only now can we die on error. shflags functions leak non-zero error codes, | 75 # Only now can we die on error. shflags functions leak non-zero error codes, |
78 # so will die prematurely if 'set -e' is specified before now. | 76 # so will die prematurely if 'set -e' is specified before now. |
79 set -e | 77 set -e |
80 # Die on uninitialized variables. | 78 # Die on uninitialized variables. |
81 set -u | 79 set -u |
82 | 80 |
83 # Check for missing parts. | 81 # Check for missing parts. |
84 # For recovery image, only populate ROOT-A and KERN-A | |
85 ROOTFS_IMG="${IMAGEDIR}/rootfs.image" | 82 ROOTFS_IMG="${IMAGEDIR}/rootfs.image" |
86 if [[ ! -s ${ROOTFS_IMG} ]]; then | 83 if [[ ! -s ${ROOTFS_IMG} ]]; then |
87 error "Can't find ${ROOTFS_IMG}" | 84 error "Can't find ${ROOTFS_IMG}" |
88 exit 1 | 85 exit 1 |
89 fi | 86 fi |
90 | 87 |
91 KERNEL_IMG="${IMAGEDIR}/vmlinuz.image" | 88 KERNEL_IMG="${IMAGEDIR}/vmlinuz.image" |
92 if [[ ! -s ${KERNEL_IMG} ]]; then | 89 if [[ ! -s ${KERNEL_IMG} ]]; then |
93 error "Can't find ${KERNEL_IMG}" | 90 error "Can't find ${KERNEL_IMG}" |
94 exit 1 | 91 exit 1 |
95 fi | 92 fi |
96 | 93 |
97 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" | 94 STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image" |
98 if [ ! -s ${STATEFUL_IMG} ] && [ ${FLAGS_recovery} -eq $FLAGS_FALSE ]; then | 95 if [ ! -s ${STATEFUL_IMG} ]; then |
99 error "Can't find ${STATEFUL_IMG}" | 96 error "Can't find ${STATEFUL_IMG}" |
100 exit 1 | 97 exit 1 |
101 fi | 98 fi |
102 | 99 |
103 ESP_IMG="${IMAGEDIR}/esp.image" | 100 ESP_IMG="${IMAGEDIR}/esp.image" |
104 if [ ! -s ${ESP_IMG} ] && [ ${FLAGS_recovery} -eq $FLAGS_FALSE ]; then | 101 if [ ! -s ${ESP_IMG} ]; then |
105 error "Can't find ${ESP_IMG}" | 102 error "Can't find ${ESP_IMG}" |
106 exit 1 | 103 exit 1 |
107 fi | 104 fi |
108 | 105 |
109 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM | 106 # We'll need some code to put in the PMBR, for booting on legacy BIOS. Some ARM |
110 # systems will use a U-Boot script temporarily, but it goes in the same place. | 107 # systems will use a U-Boot script temporarily, but it goes in the same place. |
111 if [[ "$ARCH" = "arm" ]]; then | 108 if [[ "$ARCH" = "arm" ]]; then |
112 PMBRCODE=/dev/zero | 109 PMBRCODE=/dev/zero |
113 else | 110 else |
114 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) | 111 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) |
115 fi | 112 fi |
116 | 113 |
117 # Create the GPT. This has the side-effect of setting some global vars | 114 # Create the GPT. This has the side-effect of setting some global vars |
118 # describing the partition table entries (see the comments in the source). | 115 # describing the partition table entries (see the comments in the source). |
119 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG \ | 116 install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG \ |
120 false $FLAGS_recovery $FLAGS_rootfs_partition_size | 117 false $FLAGS_rootfs_partition_size |
121 | 118 |
122 if [[ "$ARCH" = "arm" ]]; then | 119 if [[ "$ARCH" = "arm" ]]; then |
123 # assume /dev/mmcblk1. we could not get this from ${OUTDEV} | 120 # assume /dev/mmcblk1. we could not get this from ${OUTDEV} |
124 DEVICE=1 | 121 DEVICE=1 |
125 MBR_SCRIPT_UIMG=$(make_arm_mbr \ | 122 MBR_SCRIPT_UIMG=$(make_arm_mbr \ |
126 ${START_KERN_A} \ | 123 ${START_KERN_A} \ |
127 ${NUM_KERN_SECTORS} \ | 124 ${NUM_KERN_SECTORS} \ |
128 ${DEVICE} \ | 125 ${DEVICE} \ |
129 "${FLAGS_arm_extra_bootargs}") | 126 "${FLAGS_arm_extra_bootargs}") |
130 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | 127 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ |
(...skipping 14 matching lines...) Expand all Loading... |
145 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | 142 $sudo dd if=${STATEFUL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ |
146 seek=${START_STATEFUL} | 143 seek=${START_STATEFUL} |
147 | 144 |
148 echo "Copying kernel..." | 145 echo "Copying kernel..." |
149 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} | 146 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_KERN_A} |
150 | 147 |
151 echo "Copying rootfs..." | 148 echo "Copying rootfs..." |
152 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | 149 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \ |
153 seek=${START_ROOTFS_A} | 150 seek=${START_ROOTFS_A} |
154 | 151 |
155 # TODO(tgao): write a script to populate ROOT-B and KERN-B with user-specified | |
156 # rootfs and kernel. Do NOT remove if block below until then (otherwise | |
157 # chromeos-installer will fail b/c it expects to install from partition B) | |
158 if [ ${FLAGS_recovery} -eq $FLAGS_TRUE ]; then | |
159 echo "Copying kernel B..." | |
160 $sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | |
161 seek=${START_KERN_B} | |
162 | |
163 echo "Copying rootfs B..." | |
164 $sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \ | |
165 seek=${START_ROOTFS_B} | |
166 fi | |
167 | |
168 echo "Copying EFI system partition..." | 152 echo "Copying EFI system partition..." |
169 $sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} | 153 $sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP} |
170 | 154 |
171 # Clean up temporary files. | 155 # Clean up temporary files. |
172 if [[ -n "${MBR_IMG:-}" ]]; then | 156 if [[ -n "${MBR_IMG:-}" ]]; then |
173 rm "${MBR_IMG}" | 157 rm "${MBR_IMG}" |
174 fi | 158 fi |
OLD | NEW |