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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 rm -f "$SRC_ROOT" | 50 rm -f "$SRC_ROOT" |
51 rm -f "$DST_KERNEL" | 51 rm -f "$DST_KERNEL" |
52 rm -f "$DST_ROOT" | 52 rm -f "$DST_ROOT" |
53 [ -n "$1" ] || exit 1 | 53 [ -n "$1" ] || exit 1 |
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=$(mktemp /tmp/generate_update_payload.XXXXXX) | 59 local temp_file=$(mktemp /tmp/generate_update_payload.XXXXXX) |
60 | 60 |
61 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors | 61 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors |
62 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors | 62 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors |
63 local bs=512 | 63 local bs=512 |
64 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) | 64 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) |
65 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ | 65 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ |
66 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then | 66 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then |
67 bs=$((2 * 1024 * 1024)) | 67 bs=$((2 * 1024 * 1024)) |
68 offset=$(($offset / $sectors_per_two_mib)) | 68 offset=$(($offset / $sectors_per_two_mib)) |
69 length=$(($length / $sectors_per_two_mib)) | 69 length=$(($length / $sectors_per_two_mib)) |
70 else | 70 else |
(...skipping 21 matching lines...) Expand all Loading... |
92 STATE_LOOP_DEV="" | 92 STATE_LOOP_DEV="" |
93 } | 93 } |
94 | 94 |
95 DEFINE_string image "" "The image that should be sent to clients." | 95 DEFINE_string image "" "The image that should be sent to clients." |
96 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ | 96 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ |
97 a delta update." | 97 a delta update." |
98 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." | 98 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." |
99 DEFINE_string output "" "Output file" | 99 DEFINE_string output "" "Output file" |
100 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ | 100 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ |
101 with the patch from the stateful partition (default: false)" | 101 with the patch from the stateful partition (default: false)" |
| 102 DEFINE_string private_key "" "Path to private key in .pem format." |
102 | 103 |
103 # Parse command line | 104 # Parse command line |
104 FLAGS "$@" || exit 1 | 105 FLAGS "$@" || exit 1 |
105 eval set -- "${FLAGS_ARGV}" | 106 eval set -- "${FLAGS_ARGV}" |
106 | 107 |
107 set -e | 108 set -e |
108 | 109 |
109 if [ -n "$FLAGS_src_image" ]; then | 110 if [ -n "$FLAGS_src_image" ]; then |
110 # We need to be in the chroot for generating delta images | 111 # We need to be in the chroot for generating delta images |
111 assert_inside_chroot | 112 assert_inside_chroot |
112 fi | 113 fi |
113 | 114 |
114 locate_gpt | 115 locate_gpt |
115 | 116 |
116 DELTA=$FLAGS_TRUE | 117 DELTA=$FLAGS_TRUE |
117 [ -n "$FLAGS_output" ] || die \ | 118 [ -n "$FLAGS_output" ] || die \ |
118 "Error: you must specify an output filename with --output FILENAME" | 119 "Error: you must specify an output filename with --output FILENAME" |
119 | 120 |
120 if [ -z "$FLAGS_src_image" ]; then | 121 if [ -z "$FLAGS_src_image" ]; then |
121 DELTA=$FLAGS_FALSE | 122 DELTA=$FLAGS_FALSE |
122 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then | 123 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then |
123 echo "Generating an old-style full update" | 124 echo "Generating an old-style full update" |
124 else | 125 else |
125 die "Generating a new-style full update not yet supported" | 126 die "Generating a new-style full update not yet supported" |
126 fi | 127 fi |
127 fi | 128 fi |
128 | 129 |
129 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then | 130 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then |
130 echo "Generating a delta update" | 131 echo "Generating a delta update" |
131 | 132 |
132 # Sanity check that the real generator exists: | 133 # Sanity check that the real generator exists: |
133 GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator" | 134 GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator" |
134 [ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable" | 135 [ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable" |
135 | 136 |
136 trap cleanup INT TERM EXIT | 137 trap cleanup INT TERM EXIT |
137 SRC_KERNEL=$(extract_partition_to_temp_file "$FLAGS_src_image" 2) | 138 SRC_KERNEL=$(extract_partition_to_temp_file "$FLAGS_src_image" 2) |
138 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 139 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
139 patch_kernel "$FLAGS_src_image" "$SRC_KERNEL" | 140 patch_kernel "$FLAGS_src_image" "$SRC_KERNEL" |
140 fi | 141 fi |
141 SRC_ROOT=$(extract_partition_to_temp_file "$FLAGS_src_image" 3) | 142 SRC_ROOT=$(extract_partition_to_temp_file "$FLAGS_src_image" 3) |
142 | 143 |
143 echo md5sum of src kernel: | 144 echo md5sum of src kernel: |
144 md5sum "$SRC_KERNEL" | 145 md5sum "$SRC_KERNEL" |
145 echo md5sum of src root: | 146 echo md5sum of src root: |
146 md5sum "$SRC_ROOT" | 147 md5sum "$SRC_ROOT" |
147 | 148 |
148 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) | 149 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) |
149 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 150 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
150 patch_kernel "$FLAGS_image" "$DST_KERNEL" | 151 patch_kernel "$FLAGS_image" "$DST_KERNEL" |
151 fi | 152 fi |
152 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) | 153 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) |
153 | 154 |
154 SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX) | 155 SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX) |
155 sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT" | 156 sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT" |
156 | 157 |
157 DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX) | 158 DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX) |
158 sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT" | 159 sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT" |
159 | 160 |
160 sudo "$GENERATOR" \ | 161 sudo "$GENERATOR" \ |
161 -new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ | 162 -new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \ |
162 -old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \ | 163 -old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \ |
163 -out_file "$FLAGS_output" | 164 -out_file "$FLAGS_output" -private_key "$FLAGS_private_key" |
164 | 165 |
165 trap - INT TERM EXIT | 166 trap - INT TERM EXIT |
166 cleanup noexit | 167 cleanup noexit |
167 echo "Done generating delta." | 168 echo "Done generating delta." |
168 else | 169 else |
169 echo "Generating full update" | 170 echo "Generating full update" |
170 | 171 |
171 trap cleanup INT TERM EXIT | 172 trap cleanup INT TERM EXIT |
172 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) | 173 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2) |
173 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then | 174 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
174 patch_kernel "$FLAGS_image" "$DST_KERNEL" | 175 patch_kernel "$FLAGS_image" "$DST_KERNEL" |
175 fi | 176 fi |
176 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) | 177 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) |
177 | 178 |
178 GENERATOR="$(dirname "$0")/mk_memento_images.sh" | 179 GENERATOR="$(dirname "$0")/mk_memento_images.sh" |
179 | 180 |
180 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" | 181 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" |
181 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" | 182 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" |
182 | 183 |
183 trap - INT TERM EXIT | 184 trap - INT TERM EXIT |
184 cleanup noexit | 185 cleanup noexit |
185 echo "Done generating full update." | 186 echo "Done generating full update." |
186 fi | 187 fi |
OLD | NEW |