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. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 extract_partition_to_temp_file() { | 56 extract_partition_to_temp_file() { |
57 local filename="$1" | 57 local filename="$1" |
58 local partition="$2" | 58 local partition="$2" |
59 local temp_file="$3" | 59 local temp_file="$3" |
60 if [ -z "$temp_file" ]; then | 60 if [ -z "$temp_file" ]; then |
61 temp_file=$(mktemp /tmp/cros_generate_update_payload.XXXXXX) | 61 temp_file=$(mktemp /tmp/cros_generate_update_payload.XXXXXX) |
62 echo "$temp_file" | 62 echo "$temp_file" |
63 fi | 63 fi |
64 | 64 |
65 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors | 65 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors |
66 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors | 66 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors |
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 |
(...skipping 17 matching lines...) Expand all Loading... |
92 sudo umount "$STATE_MNT" | 92 sudo umount "$STATE_MNT" |
93 STATE_MNT="" | 93 STATE_MNT="" |
94 sudo losetup -d "$STATE_LOOP_DEV" | 94 sudo losetup -d "$STATE_LOOP_DEV" |
95 STATE_LOOP_DEV="" | 95 STATE_LOOP_DEV="" |
96 } | 96 } |
97 | 97 |
98 extract_kern_root() { | 98 extract_kern_root() { |
99 local bin_file="$1" | 99 local bin_file="$1" |
100 local kern_out="$2" | 100 local kern_out="$2" |
101 local root_out="$3" | 101 local root_out="$3" |
102 | 102 |
103 if [ -z "$kern_out" ]; then | 103 if [ -z "$kern_out" ]; then |
104 die "missing kernel output filename" | 104 die "missing kernel output filename" |
105 fi | 105 fi |
106 if [ -z "$root_out" ]; then | 106 if [ -z "$root_out" ]; then |
107 die "missing root output filename" | 107 die "missing root output filename" |
108 fi | 108 fi |
109 | 109 |
110 extract_partition_to_temp_file "$bin_file" 2 "$kern_out" | 110 extract_partition_to_temp_file "$bin_file" 2 "$kern_out" |
111 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 111 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
112 patch_kernel "$bin_file" "$kern_out" | 112 patch_kernel "$bin_file" "$kern_out" |
113 fi | 113 fi |
114 extract_partition_to_temp_file "$bin_file" 3 "$root_out" | 114 extract_partition_to_temp_file "$bin_file" 3 "$root_out" |
115 } | 115 } |
116 | 116 |
117 DEFINE_string image "" "The image that should be sent to clients." | 117 DEFINE_string image "" "The image that should be sent to clients." |
118 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ | 118 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ |
119 a delta update." | 119 a delta update." |
120 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." | 120 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." |
121 DEFINE_string output "" "Output file" | 121 DEFINE_string output "" "Output file" |
122 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ | 122 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ |
123 with the patch from the stateful partition (default: false)" | 123 with the patch from the stateful partition (default: false)" |
124 DEFINE_string private_key "" "Path to private key in .pem format." | 124 DEFINE_string private_key "" "Path to private key in .pem format." |
125 DEFINE_boolean extract "$FLAGS_FALSE" "If set, extract old/new kernel/rootfs \ | 125 DEFINE_boolean extract "$FLAGS_FALSE" "If set, extract old/new kernel/rootfs \ |
126 to [old|new]_[kern|root].dat. Useful for debugging (default: false)" | 126 to [old|new]_[kern|root].dat. Useful for debugging (default: false)" |
| 127 DEFINE_boolean full_kernel "$FLAGS_FALSE" "Generate a full kernel update even \ |
| 128 if generating a delta update (default: false)" |
127 | 129 |
128 # Parse command line | 130 # Parse command line |
129 FLAGS "$@" || exit 1 | 131 FLAGS "$@" || exit 1 |
130 eval set -- "${FLAGS_ARGV}" | 132 eval set -- "${FLAGS_ARGV}" |
131 | 133 |
132 set -e | 134 set -e |
133 | 135 |
134 if [ -n "$FLAGS_src_image" ]; then | 136 if [ -n "$FLAGS_src_image" ]; then |
135 # We need to be in the chroot for generating delta images | 137 # We need to be in the chroot for generating delta images |
136 assert_inside_chroot | 138 assert_inside_chroot |
(...skipping 27 matching lines...) Expand all Loading... |
164 | 166 |
165 if [ "$DELTA" -eq "$FLAGS_TRUE" -o "$FLAGS_old_style" -eq "$FLAGS_FALSE" ]; then | 167 if [ "$DELTA" -eq "$FLAGS_TRUE" -o "$FLAGS_old_style" -eq "$FLAGS_FALSE" ]; then |
166 echo "Generating a delta update" | 168 echo "Generating a delta update" |
167 | 169 |
168 # Sanity check that the real generator exists: | 170 # Sanity check that the real generator exists: |
169 GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator" | 171 GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator" |
170 [ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable" | 172 [ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable" |
171 | 173 |
172 trap cleanup INT TERM EXIT | 174 trap cleanup INT TERM EXIT |
173 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then | 175 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then |
174 SRC_KERNEL=$(extract_partition_to_temp_file "$FLAGS_src_image" 2) | 176 if [ "$FLAGS_full_kernel" -eq "$FLAGS_FALSE" ]; then |
175 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 177 SRC_KERNEL=$(extract_partition_to_temp_file "$FLAGS_src_image" 2) |
176 patch_kernel "$FLAGS_src_image" "$SRC_KERNEL" | 178 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
| 179 patch_kernel "$FLAGS_src_image" "$SRC_KERNEL" |
| 180 fi |
| 181 echo md5sum of src kernel: |
| 182 md5sum "$SRC_KERNEL" |
| 183 else |
| 184 echo "Generating a full kernel update." |
177 fi | 185 fi |
178 SRC_ROOT=$(extract_partition_to_temp_file "$FLAGS_src_image" 3) | 186 SRC_ROOT=$(extract_partition_to_temp_file "$FLAGS_src_image" 3) |
179 | 187 |
180 echo md5sum of src kernel: | |
181 md5sum "$SRC_KERNEL" | |
182 echo md5sum of src root: | 188 echo md5sum of src root: |
183 md5sum "$SRC_ROOT" | 189 md5sum "$SRC_ROOT" |
184 fi | 190 fi |
185 | 191 |
186 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) | 192 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) |
187 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 193 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
188 patch_kernel "$FLAGS_image" "$DST_KERNEL" | 194 patch_kernel "$FLAGS_image" "$DST_KERNEL" |
189 fi | 195 fi |
190 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) | 196 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) |
191 | 197 |
192 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then | 198 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then |
193 SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX) | 199 SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX) |
194 sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT" | 200 sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT" |
195 | 201 |
196 DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX) | 202 DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX) |
197 sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT" | 203 sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT" |
198 | 204 |
199 sudo "$GENERATOR" \ | 205 sudo "$GENERATOR" \ |
200 -new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ | 206 -new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ |
201 -old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \ | 207 -old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \ |
202 -out_file "$FLAGS_output" -private_key "$FLAGS_private_key" | 208 -out_file "$FLAGS_output" -private_key "$FLAGS_private_key" |
203 else | 209 else |
204 "$GENERATOR" \ | 210 "$GENERATOR" \ |
205 -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ | 211 -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ |
206 -out_file "$FLAGS_output" -private_key "$FLAGS_private_key" | 212 -out_file "$FLAGS_output" -private_key "$FLAGS_private_key" |
207 fi | 213 fi |
208 | 214 |
209 trap - INT TERM EXIT | 215 trap - INT TERM EXIT |
210 cleanup noexit | 216 cleanup noexit |
211 | 217 |
212 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then | 218 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then |
213 echo "Done generating delta." | 219 echo "Done generating delta." |
214 else | 220 else |
215 echo "Done generating new style full update." | 221 echo "Done generating new style full update." |
216 fi | 222 fi |
217 else | 223 else |
218 echo "Generating full update" | 224 echo "Generating full update" |
219 | 225 |
220 trap cleanup INT TERM EXIT | 226 trap cleanup INT TERM EXIT |
221 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) | 227 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) |
222 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 228 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
223 patch_kernel "$FLAGS_image" "$DST_KERNEL" | 229 patch_kernel "$FLAGS_image" "$DST_KERNEL" |
224 fi | 230 fi |
225 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) | 231 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) |
226 | 232 |
227 GENERATOR="$(dirname "$0")/mk_memento_images.sh" | 233 GENERATOR="$(dirname "$0")/mk_memento_images.sh" |
228 | 234 |
229 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" | 235 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" |
230 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" | 236 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" |
231 | 237 |
232 trap - INT TERM EXIT | 238 trap - INT TERM EXIT |
233 cleanup noexit | 239 cleanup noexit |
234 echo "Done generating full update." | 240 echo "Done generating full update." |
235 fi | 241 fi |
OLD | NEW |