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 # Script to generate a Chromium OS update for use by the update engine. | 7 # Script to generate a Chromium OS update for use by the update engine. |
8 # If a source .bin is specified, the update is assumed to be a delta update. | 8 # If a source .bin is specified, the update is assumed to be a delta update. |
9 | 9 |
10 # Load common constants. This should be the first executable line. | 10 # Load common constants. This should be the first executable line. |
11 # The path to common.sh should be relative to your script's location. | 11 # The path to common.sh should be relative to your script's location. |
12 . "$(dirname "$0")/common.sh" | 12 . "$(dirname "$0")/common.sh" |
13 | 13 |
14 # Load functions and constants for chromeos-install | 14 # Load functions and constants for chromeos-install |
15 . "$(dirname "$0")/chromeos-common.sh" | 15 . "$(dirname "$0")/chromeos-common.sh" |
16 | 16 |
17 SRC_MNT="" | 17 SRC_MNT="" |
18 DST_MNT="" | 18 DST_MNT="" |
19 SRC_KERNEL="" | 19 SRC_KERNEL="" |
20 SRC_ROOT="" | 20 SRC_ROOT="" |
21 DST_KERNEL="" | 21 DST_KERNEL="" |
22 DST_ROOT="" | 22 DST_ROOT="" |
23 STATE_MNT="" | 23 STATE_MNT="" |
24 STATE_LOOP_DEV="" | 24 STATE_LOOP_DEV="" |
25 | 25 |
26 # Pass an arg to not exit 1 at the end | 26 # Pass an arg to not exit 1 at the end |
27 cleanup() { | 27 cleanup() { |
28 set +e | 28 set +e |
29 echo "Cleaning up" | 29 #echo "Cleaning up" |
adlr
2010/11/17 20:43:25
delete the line or the '#'
| |
30 if [ -n "$SRC_MNT" ]; then | 30 if [ -n "$SRC_MNT" ]; then |
31 sudo umount -d "$SRC_MNT" | 31 sudo umount -d "$SRC_MNT" |
32 [ -d "$SRC_MNT" ] && rmdir "$SRC_MNT" | 32 [ -d "$SRC_MNT" ] && rmdir "$SRC_MNT" |
33 SRC_MNT="" | 33 SRC_MNT="" |
34 fi | 34 fi |
35 if [ -n "$DST_MNT" ]; then | 35 if [ -n "$DST_MNT" ]; then |
36 sudo umount -d "$DST_MNT" | 36 sudo umount -d "$DST_MNT" |
37 [ -d "$DST_MNT" ] && rmdir "$DST_MNT" | 37 [ -d "$DST_MNT" ] && rmdir "$DST_MNT" |
38 DST_MNT="" | 38 DST_MNT="" |
39 fi | 39 fi |
(...skipping 27 matching lines...) Expand all Loading... | |
67 local bs=512 | 67 local bs=512 |
68 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) | 68 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) |
69 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ | 69 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ |
70 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then | 70 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then |
71 bs=$((2 * 1024 * 1024)) | 71 bs=$((2 * 1024 * 1024)) |
72 offset=$(($offset / $sectors_per_two_mib)) | 72 offset=$(($offset / $sectors_per_two_mib)) |
73 length=$(($length / $sectors_per_two_mib)) | 73 length=$(($length / $sectors_per_two_mib)) |
74 else | 74 else |
75 warn "partition offset or length not at 2MiB boundary" | 75 warn "partition offset or length not at 2MiB boundary" |
76 fi | 76 fi |
77 dd if="$filename" of="$temp_file" bs=$bs count="$length" skip="$offset" | 77 dd if="$filename" of="$temp_file" bs=$bs count="$length" skip="$offset" 2>/dev /null |
adlr
2010/11/17 20:43:25
wrap to 80 cols
| |
78 } | 78 } |
79 | 79 |
80 patch_kernel() { | 80 patch_kernel() { |
81 local IMAGE="$1" | 81 local IMAGE="$1" |
82 local KERN_FILE="$2" | 82 local KERN_FILE="$2" |
83 | 83 |
84 echo "Patching kernel " $KERN_FILE | |
85 echo " into" $IMAGE | |
adlr
2010/11/17 20:43:25
delete extra after echo and add one after 'into'?
| |
84 STATE_LOOP_DEV=$(sudo losetup -f) | 86 STATE_LOOP_DEV=$(sudo losetup -f) |
85 [ -n "$STATE_LOOP_DEV" ] || die "no free loop device" | 87 [ -n "$STATE_LOOP_DEV" ] || die "no free loop device" |
86 local offset=$(partoffset "${IMAGE}" 1) | 88 local offset=$(partoffset "${IMAGE}" 1) |
87 offset=$(($offset * 512)) | 89 offset=$(($offset * 512)) |
88 sudo losetup -o "$offset" "$STATE_LOOP_DEV" "$IMAGE" | 90 sudo losetup -o "$offset" "$STATE_LOOP_DEV" "$IMAGE" |
89 STATE_MNT=$(mktemp -d /tmp/state.XXXXXX) | 91 STATE_MNT=$(mktemp -d /tmp/state.XXXXXX) |
90 sudo mount --read-only "$STATE_LOOP_DEV" "$STATE_MNT" | 92 sudo mount --read-only "$STATE_LOOP_DEV" "$STATE_MNT" |
91 dd if="$STATE_MNT"/vmlinuz_hd.vblock of="$KERN_FILE" conv=notrunc | 93 dd if="$STATE_MNT"/vmlinuz_hd.vblock of="$KERN_FILE" conv=notrunc 2>/dev/null |
92 sudo umount "$STATE_MNT" | 94 sudo umount "$STATE_MNT" |
93 STATE_MNT="" | 95 STATE_MNT="" |
94 sudo losetup -d "$STATE_LOOP_DEV" | 96 sudo losetup -d "$STATE_LOOP_DEV" |
95 STATE_LOOP_DEV="" | 97 STATE_LOOP_DEV="" |
96 } | 98 } |
97 | 99 |
98 extract_kern_root() { | 100 extract_kern_root() { |
99 local bin_file="$1" | 101 local bin_file="$1" |
100 local kern_out="$2" | 102 local kern_out="$2" |
101 local root_out="$3" | 103 local root_out="$3" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 echo Done extracting kernel/root | 158 echo Done extracting kernel/root |
157 exit 0 | 159 exit 0 |
158 fi | 160 fi |
159 | 161 |
160 DELTA=$FLAGS_TRUE | 162 DELTA=$FLAGS_TRUE |
161 [ -n "$FLAGS_output" ] || die \ | 163 [ -n "$FLAGS_output" ] || die \ |
162 "Error: you must specify an output filename with --output FILENAME" | 164 "Error: you must specify an output filename with --output FILENAME" |
163 | 165 |
164 if [ -z "$FLAGS_src_image" ]; then | 166 if [ -z "$FLAGS_src_image" ]; then |
165 DELTA=$FLAGS_FALSE | 167 DELTA=$FLAGS_FALSE |
166 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then | |
167 echo "Generating an old-style full update" | |
168 else | |
169 echo "Generating a new-style full update" | |
170 fi | |
171 fi | 168 fi |
172 | 169 |
173 if [ "$DELTA" -eq "$FLAGS_TRUE" -o "$FLAGS_old_style" -eq "$FLAGS_FALSE" ]; then | 170 if [ "$DELTA" -eq "$FLAGS_TRUE" -o "$FLAGS_old_style" -eq "$FLAGS_FALSE" ]; then |
174 echo "Generating a delta update" | 171 echo "Generating a delta update" |
175 | 172 |
176 # Sanity check that the real generator exists: | 173 # Sanity check that the real generator exists: |
177 GENERATOR="$(which delta_generator)" | 174 GENERATOR="$(which delta_generator)" |
178 [ -x "$GENERATOR" ] || die "can't find delta_generator" | 175 [ -x "$GENERATOR" ] || die "can't find delta_generator" |
179 | 176 |
180 trap cleanup INT TERM EXIT | 177 trap cleanup INT TERM EXIT |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 | 217 |
221 trap - INT TERM EXIT | 218 trap - INT TERM EXIT |
222 cleanup noexit | 219 cleanup noexit |
223 | 220 |
224 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then | 221 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then |
225 echo "Done generating delta." | 222 echo "Done generating delta." |
226 else | 223 else |
227 echo "Done generating new style full update." | 224 echo "Done generating new style full update." |
228 fi | 225 fi |
229 else | 226 else |
230 echo "Generating full update" | 227 echo "Generating old-style full update" |
231 | 228 |
232 trap cleanup INT TERM EXIT | 229 trap cleanup INT TERM EXIT |
233 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) | 230 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) |
234 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 231 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
235 patch_kernel "$FLAGS_image" "$DST_KERNEL" | 232 patch_kernel "$FLAGS_image" "$DST_KERNEL" |
236 fi | 233 fi |
237 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) | 234 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) |
238 | 235 |
239 GENERATOR="$(dirname "$0")/mk_memento_images.sh" | 236 GENERATOR="$(dirname "$0")/mk_memento_images.sh" |
240 | 237 |
241 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" | 238 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" |
242 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" | 239 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" |
243 | 240 |
244 trap - INT TERM EXIT | 241 trap - INT TERM EXIT |
245 cleanup noexit | 242 cleanup noexit |
246 echo "Done generating full update." | 243 echo "Done generating full update." |
247 fi | 244 fi |
OLD | NEW |