OLD | NEW |
---|---|
1 #!/bin/sh -ex | 1 #!/bin/sh -ex |
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 . "$(dirname "$0")/chromeos-common.sh" | 7 . "$(dirname "$0")/chromeos-common.sh" |
8 . "/opt/google/memento_updater/memento_updater_logging.sh" | 8 . "/opt/google/memento_updater/memento_updater_logging.sh" |
9 . "/opt/google/memento_updater/find_omaha.sh" | 9 . "/opt/google/memento_updater/find_omaha.sh" |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 if ! echo "${RESULT}" | grep -Eq "(failed|unavailable)"; then | 63 if ! echo "${RESULT}" | grep -Eq "(failed|unavailable)"; then |
64 log "Success, time set to $(date)" | 64 log "Success, time set to $(date)" |
65 return 0 | 65 return 0 |
66 fi | 66 fi |
67 | 67 |
68 log $(echo "${RESULT}" | grep -E "(failed|unavailable)") | 68 log $(echo "${RESULT}" | grep -E "(failed|unavailable)") |
69 log "Failed to set time" | 69 log "Failed to set time" |
70 return 1 | 70 return 1 |
71 } | 71 } |
72 | 72 |
73 list_ethernet_interface() { | |
74 local candidates=$(ifconfig | grep 'Link encap:Ethernet' | cut -d ' ' -f 1) | |
Hung-Te
2011/03/30 09:17:53
Please quote the $() to "$()", if you use "local".
Che-Liang Chiou
2011/03/30 09:54:38
Done. Just for curious: why local needs quote? (do
Hung-Te
2011/03/30 10:34:40
bash and dash interpret "local" and $() in differe
| |
75 for candidate in $candidates; do | |
76 # output if it is not a wifi interface | |
77 if ! iw $candidate info > /dev/null 2>&1; then | |
Hung-Te
2011/03/30 09:17:53
>/dev/null, no need for the space.
Che-Liang Chiou
2011/03/30 09:54:38
Done.
| |
78 echo $candidate | |
79 fi | |
80 done | |
81 } | |
82 | |
73 log "Starting Factory Installer." | 83 log "Starting Factory Installer." |
74 | 84 |
75 log "Checking for Firmware Write Protect" | 85 log "Checking for Firmware Write Protect" |
76 | 86 |
77 # Only ChromeOS machines have meaninful output here. | 87 # Only ChromeOS machines have meaninful output here. |
78 if crossystem hwid >/dev/null; then | 88 if crossystem hwid >/dev/null; then |
79 # Check for physical firmware write protect. We'll only | 89 # Check for physical firmware write protect. We'll only |
80 # clear this stuff if the case is open. | 90 # clear this stuff if the case is open. |
81 if [ "$(crossystem wpsw_cur)" = "0" ]; then | 91 if [ "$(crossystem wpsw_cur)" = "0" ]; then |
82 # Ensure that flash chips are in a known good state. | 92 # Ensure that flash chips are in a known good state. |
83 clear_fwwp | 93 clear_fwwp |
84 | 94 |
85 # Ensure that we can wipe TPM if necessary. | 95 # Ensure that we can wipe TPM if necessary. |
86 clear_tpm | 96 clear_tpm |
87 fi | 97 fi |
88 fi | 98 fi |
89 | 99 |
100 # | |
101 # factory_install.sh implements two operations for assembly line | |
102 # operators: install (obviously) and reset. | |
103 # | |
104 # Somehow the way that operators switch between the two operations | |
105 # is by plugging in a ethernet cable. | |
Nick Sanders
2011/03/30 09:45:33
Thanks for adding the comment here:
Note that the
| |
106 # | |
107 # So we have to detect a possible ethernet connection here. | |
108 # | |
109 | |
110 ETHERNET_INTERFACES=$(list_ethernet_interface) | |
Hung-Te
2011/03/30 09:17:53
Please do this inside the while-loop, because oper
| |
111 | |
90 log "Waiting for ethernet connectivity to install" | 112 log "Waiting for ethernet connectivity to install" |
91 log "Or disable developer mode to factory reset." | 113 log "Or disable developer mode to factory reset." |
92 while ! ifconfig eth0 | grep -q "inet addr"; do | 114 while true; do |
115 connected=0 | |
116 for ethernet_interface in $ETHERNET_INTERFACES; do | |
117 if ifconfig $ethernet_interface | grep -q "inet addr"; then | |
118 log "$(ifconfig $ethernet_interface | grep 'inet addr')" | |
119 connected=1 | |
120 break | |
121 fi | |
122 done | |
123 if [ $connected -eq 1 ]; then | |
124 break | |
125 fi | |
126 | |
93 # If developer switch is flipped, go to "reset mode" instead of | 127 # If developer switch is flipped, go to "reset mode" instead of |
94 # network install mode. Make sure gpio can be read (gpio_setup may | 128 # network install mode. Make sure gpio can be read (gpio_setup may |
95 # fail if the device is not ready). | 129 # fail if the device is not ready). |
96 if [ "$(crossystem devsw_cur)" = "0" ]; then | 130 if [ "$(crossystem devsw_cur)" = "0" ]; then |
97 log "Performing factory reset" | 131 log "Performing factory reset" |
98 if ! /usr/sbin/factory_reset.sh; then | 132 if ! /usr/sbin/factory_reset.sh; then |
99 log "Factory reset failed." | 133 log "Factory reset failed." |
100 exit 1 | 134 exit 1 |
101 fi | 135 fi |
102 | 136 |
103 log "Done" | 137 log "Done" |
104 exit 0 | 138 exit 0 |
105 fi | 139 fi |
106 sleep 1 | 140 sleep 1 |
107 done | 141 done |
108 log "$(ifconfig eth0 | grep 'inet addr')" | |
109 | 142 |
110 set_time || exit 1 | 143 set_time || exit 1 |
111 | 144 |
112 # TODO(adlr): pick an install device in a matter that works on x86 and ARM. | 145 # TODO(crosbug:10680): replace arch detection with crossystem? |
113 # This works on x86 only, afaik. | 146 if uname -m | grep -q "^i.86\$"; then |
114 DST_DRIVE=/dev/sda | 147 ARCH="INTEL" |
148 elif [ $(uname -m ) = "x86_64" ]; then | |
149 ARCH="INTEL" | |
150 elif [ $(uname -m ) = "armv7l" ]; then | |
151 ARCH="ARM" | |
152 else | |
153 log "Error: Failed to auto detect architecture" | |
154 exit 1 | |
155 fi | |
156 | |
157 if [ "$ARCH" = "INTEL" ]; then | |
158 DST_DRIVE=/dev/sda | |
159 else | |
160 DST_DRIVE=/dev/mmcblk0 | |
161 fi | |
115 DST_FACTORY_PART=3 | 162 DST_FACTORY_PART=3 |
116 DST_RELEASE_PART=5 | 163 DST_RELEASE_PART=5 |
117 DST_OEM_PART=8 | 164 DST_OEM_PART=8 |
118 DST_EFI_PART=12 | 165 DST_EFI_PART=12 |
119 DST_STATE_PART=1 | 166 DST_STATE_PART=1 |
120 DST_FIRMWARE=/tmp/firmware.sh | 167 DST_FIRMWARE=/tmp/firmware.sh |
121 | 168 |
122 # Light up screen in case you can't see our splash image. | 169 # Light up screen in case you can't see our splash image. |
123 LIGHTUP_SCREEN="/usr/sbin/lightup_screen" | 170 LIGHTUP_SCREEN="/usr/sbin/lightup_screen" |
124 if [ -x /usr/sbin/lightup_screen ]; then | 171 if [ -x "${LIGHTUP_SCREEN}" ]; then |
125 ${LIGHTUP_SCREEN} | 172 ${LIGHTUP_SCREEN} |
126 else | 173 else |
127 log "${LIGHTUP_SCREEN} does not exist or not executable" | 174 log "${LIGHTUP_SCREEN} does not exist or not executable" |
128 fi | 175 fi |
129 | 176 |
130 log "Factory Install: Setting partition table" | 177 log "Factory Install: Setting partition table" |
131 | 178 |
132 INST_FLAGS="--dst ${DST_DRIVE} --skip_rootfs --run_as_root --yes" | 179 INST_FLAGS="--dst ${DST_DRIVE} --skip_rootfs --run_as_root --yes" |
133 | 180 |
134 # in factory mode, we need both GPT_LAYOUT and PMBR_CODE always generated. | 181 # in factory mode, we need both GPT_LAYOUT and PMBR_CODE always generated. |
(...skipping 13 matching lines...) Expand all Loading... | |
148 log "FACTORY INSTALLER STOPPED." | 195 log "FACTORY INSTALLER STOPPED." |
149 exit 1 | 196 exit 1 |
150 fi | 197 fi |
151 | 198 |
152 /usr/sbin/chromeos-install $INST_FLAGS 2>&1 | cat >> "$MEMENTO_AU_LOG" | 199 /usr/sbin/chromeos-install $INST_FLAGS 2>&1 | cat >> "$MEMENTO_AU_LOG" |
153 | 200 |
154 # Load the new partition table. The autoupdater has trouble with loop devices. | 201 # Load the new partition table. The autoupdater has trouble with loop devices. |
155 sync | 202 sync |
156 echo 3 > /proc/sys/vm/drop_caches | 203 echo 3 > /proc/sys/vm/drop_caches |
157 /sbin/sfdisk -R "$DST_DRIVE" | 204 /sbin/sfdisk -R "$DST_DRIVE" |
205 partprobe # inform the OS of partition table changes | |
158 | 206 |
159 log "Done preparing disk" | 207 log "Done preparing disk" |
160 | 208 |
161 FACTORY_CHANNEL_ARG='--force_track=factory-channel' | 209 FACTORY_CHANNEL_ARG='--force_track=factory-channel' |
162 RELEASE_CHANNEL_ARG='--force_track=release-channel' | 210 RELEASE_CHANNEL_ARG='--force_track=release-channel' |
163 OEM_CHANNEL_ARG='--force_track=oempartitionimg-channel' | 211 OEM_CHANNEL_ARG='--force_track=oempartitionimg-channel' |
164 EFI_CHANNEL_ARG='--force_track=efipartitionimg-channel' | 212 EFI_CHANNEL_ARG='--force_track=efipartitionimg-channel' |
165 STATE_CHANNEL_ARG='--force_track=stateimg-channel' | 213 STATE_CHANNEL_ARG='--force_track=stateimg-channel' |
166 FIRMWARE_CHANNEL_ARG='--force_track=firmware-channel' | 214 FIRMWARE_CHANNEL_ARG='--force_track=firmware-channel' |
167 | 215 |
168 # Install the partitions | 216 # Install the partitions |
169 for i in EFI OEM STATE RELEASE FACTORY FIRMWARE; do | 217 for i in EFI OEM STATE RELEASE FACTORY FIRMWARE; do |
170 if [ "$i" = "FIRMWARE" ]; then | 218 if [ "$i" = "FIRMWARE" ]; then |
171 DST="${DST_FIRMWARE}" | 219 DST="${DST_FIRMWARE}" |
172 else | 220 else |
173 PART=$(eval "echo \$DST_${i}_PART") | 221 PART=$(eval "echo \$DST_${i}_PART") |
174 DST="${DST_DRIVE}${PART}" | 222 DST="$(make_partition_dev ${DST_DRIVE} ${PART})" |
175 fi | 223 fi |
176 | 224 |
177 log "Factory Install: Installing $i image to $DST" | 225 log "Factory Install: Installing $i image to $DST" |
178 | 226 |
179 CHANNEL_ARG=$(eval "echo \$${i}_CHANNEL_ARG") | 227 CHANNEL_ARG=$(eval "echo \$${i}_CHANNEL_ARG") |
180 KPART="none" | 228 KPART="none" |
181 if [ "$i" = "FACTORY" -o "$i" = "RELEASE" ]; then | 229 if [ "$i" = "FACTORY" -o "$i" = "RELEASE" ]; then |
182 # Set up kernel partition | 230 # Set up kernel partition |
183 KPART="" | 231 KPART="" |
184 fi | 232 fi |
(...skipping 24 matching lines...) Expand all Loading... | |
209 fi | 257 fi |
210 done | 258 done |
211 | 259 |
212 # Release image is not allowed to boot unless the factory test is passed | 260 # Release image is not allowed to boot unless the factory test is passed |
213 # otherwise the wipe and final verification can be skipped. | 261 # otherwise the wipe and final verification can be skipped. |
214 # TODO(hungte) do this in memento_updater or postinst may be better | 262 # TODO(hungte) do this in memento_updater or postinst may be better |
215 # TODO(hungte) make a better way to find location of cgpt | 263 # TODO(hungte) make a better way to find location of cgpt |
216 if ! cgpt add -i $((${DST_RELEASE_PART} - 1)) -P 0 -T 0 -S 0 ${DST_DRIVE}; then | 264 if ! cgpt add -i $((${DST_RELEASE_PART} - 1)) -P 0 -T 0 -S 0 ${DST_DRIVE}; then |
217 log "Factory Install: failed to lock release image. Destroy all kernels." | 265 log "Factory Install: failed to lock release image. Destroy all kernels." |
218 # Destroy kernels otherwise the system is still bootable. | 266 # Destroy kernels otherwise the system is still bootable. |
219 dd if=/dev/zero of=${DST_DRIVE}$((${DST_RELEASE_PART} - 1)) | 267 DST_RELEASE=$(make_partition_dev ${DST_DRIVE} $((${DST_RELEASE_PART} - 1))) |
220 dd if=/dev/zero of=${DST_DRIVE}$((${DST_FACTORY_PART} - 1)) | 268 DST_FACTORY=$(make_partition_dev ${DST_DRIVE} $((${DST_FACTORY_PART} - 1))) |
269 dd if=/dev/zero of=$DST_RELEASE | |
270 dd if=/dev/zero of=$DST_FACTORY | |
221 exit 1 | 271 exit 1 |
222 fi | 272 fi |
223 | 273 |
224 log "All done installing." | 274 log "All done installing." |
225 | 275 |
226 sleep 3 | 276 sleep 3 |
227 shutdown -r now | 277 shutdown -r now |
228 sleep 1d # sleep indefinitely to avoid respawning rather than shutting down | 278 sleep 1d # sleep indefinitely to avoid respawning rather than shutting down |
OLD | NEW |