Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: make_factory_package.sh

Issue 6050006: Allow disk image target for copy machine. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: . Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/cros_image_common.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 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 factory install partition set and miniomaha.conf 7 # Script to generate a factory install partition set and miniomaha.conf
8 # file from a release image and a factory image. This creates a server 8 # file from a release image and a factory image. This creates a server
9 # configuration that can be installed using a factory install shim. 9 # configuration that can be installed using a factory install shim.
10 # 10 #
(...skipping 16 matching lines...) Expand all
27 # Flags 27 # Flags
28 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" 28 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built"
29 DEFINE_string factory "" \ 29 DEFINE_string factory "" \
30 "Directory and file containing factory image: /path/chromiumos_test_image.bin" 30 "Directory and file containing factory image: /path/chromiumos_test_image.bin"
31 DEFINE_string firmware_updater "" \ 31 DEFINE_string firmware_updater "" \
32 "If set, include the firmware shellball into the server configuration" 32 "If set, include the firmware shellball into the server configuration"
33 DEFINE_string release "" \ 33 DEFINE_string release "" \
34 "Directory and file containing release image: /path/chromiumos_image.bin" 34 "Directory and file containing release image: /path/chromiumos_image.bin"
35 DEFINE_string subfolder "" \ 35 DEFINE_string subfolder "" \
36 "If set, the name of the subfolder to put the payload items inside" 36 "If set, the name of the subfolder to put the payload items inside"
37 DEFINE_string diskimg "" \
38 "If set, the name of the diskimage file to output"
39 DEFINE_boolean preserve ${FLAGS_FALSE} \
40 "If set, reuse the diskimage file, if available"
41 DEFINE_integer sectors 31277232 "Size of image in sectors"
37 42
38 # Parse command line 43 # Parse command line
39 FLAGS "$@" || exit 1 44 FLAGS "$@" || exit 1
40 eval set -- "${FLAGS_ARGV}" 45 eval set -- "${FLAGS_ARGV}"
41 46
42 if [ ! -f "${FLAGS_release}" ]; then 47 if [ ! -f "${FLAGS_release}" ]; then
43 echo "Cannot find image file ${FLAGS_release}" 48 echo "Cannot find image file ${FLAGS_release}"
44 exit 1 49 exit 1
45 fi 50 fi
46 51
(...skipping 26 matching lines...) Expand all
73 sudo -v 78 sudo -v
74 echo "Done" 79 echo "Done"
75 fi 80 fi
76 81
77 # Use this image as the source image to copy 82 # Use this image as the source image to copy
78 RELEASE_DIR="$(dirname "${FLAGS_release}")" 83 RELEASE_DIR="$(dirname "${FLAGS_release}")"
79 FACTORY_DIR="$(dirname "${FLAGS_factory}")" 84 FACTORY_DIR="$(dirname "${FLAGS_factory}")"
80 RELEASE_IMAGE="$(basename "${FLAGS_release}")" 85 RELEASE_IMAGE="$(basename "${FLAGS_release}")"
81 FACTORY_IMAGE="$(basename "${FLAGS_factory}")" 86 FACTORY_IMAGE="$(basename "${FLAGS_factory}")"
82 87
88 prepare_img() {
89 local outdev="$FLAGS_diskimg"
90 local sectors="$FLAGS_sectors"
91 local force_full="true"
92
93 # We'll need some code to put in the PMBR, for booting on legacy BIOS.
94 echo "Fetch PMBR"
95 local pmbrcode="$(mktemp -d)/gptmbr.bin"
96 sudo dd bs=512 count=1 if="${FLAGS_release}" of="${pmbrcode}" status=noxfer
97
98 echo "Prepare base disk image"
99 # Create an output file if requested, or if none exists.
100 if [ -b "${outdev}" ] ; then
101 echo "Using block device ${outdev}"
102 elif [ ! -e "${outdev}" -o \
103 "$(stat -c %s ${outdev})" != "$(( ${sectors} * 512 ))" -o \
104 "$FLAGS_preserve" = "$FLAGS_FALSE" ]; then
105 echo "Generating empty image file"
106 image_dump_partial_file /dev/zero 0 "${sectors}" |
107 dd of="${outdev}" bs=8M
108 else
109 echo "Reusing $outdev"
110 fi
111
112 # Create GPT partition table.
113 install_gpt "${outdev}" 0 0 "${pmbrcode}" 0 "${force_full}"
114 # Activate the correct partition.
115 cgpt add -i 2 -S 1 -P 1 "${outdev}"
116 }
83 117
84 prepare_omaha() { 118 prepare_omaha() {
85 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz" 119 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz"
86 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-release.gz" 120 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-release.gz"
87 rm -rf "${OMAHA_DATA_DIR}/efi.gz" 121 rm -rf "${OMAHA_DATA_DIR}/efi.gz"
88 rm -rf "${OMAHA_DATA_DIR}/oem.gz" 122 rm -rf "${OMAHA_DATA_DIR}/oem.gz"
89 rm -rf "${OMAHA_DATA_DIR}/state.gz" 123 rm -rf "${OMAHA_DATA_DIR}/state.gz"
90 if [ ! -d "${OMAHA_DATA_DIR}" ]; then 124 if [ ! -d "${OMAHA_DATA_DIR}" ]; then
91 mkdir -p "${OMAHA_DATA_DIR}" 125 mkdir -p "${OMAHA_DATA_DIR}"
92 fi 126 fi
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 local output_file="$3" 172 local output_file="$3"
139 173
140 if [ -n "${IMAGE_IS_UNPACKED}" ]; then 174 if [ -n "${IMAGE_IS_UNPACKED}" ]; then
141 compress_and_hash_file "part_$part_num" "$output_file" 175 compress_and_hash_file "part_$part_num" "$output_file"
142 else 176 else
143 image_dump_partition "$input_file" "$part_num" | 177 image_dump_partition "$input_file" "$part_num" |
144 compress_and_hash_file "" "$output_file" 178 compress_and_hash_file "" "$output_file"
145 fi 179 fi
146 } 180 }
147 181
148 # Clean up stale config and data files.
149 prepare_omaha
150
151 # Decide if we should unpack partition 182 # Decide if we should unpack partition
152 if image_has_part_tools; then 183 if image_has_part_tools; then
153 IMAGE_IS_UNPACKED= 184 IMAGE_IS_UNPACKED=
154 else 185 else
155 #TODO(hungte) Currently we run unpack_partitions.sh if part_tools are not 186 #TODO(hungte) Currently we run unpack_partitions.sh if part_tools are not
156 # found. If the format of unpack_partitions.sh is reliable, we can prevent 187 # found. If the format of unpack_partitions.sh is reliable, we can prevent
157 # creating temporary files. See image_part_offset for more information. 188 # creating temporary files. See image_part_offset for more information.
158 echo "WARNING: cannot find partition tools. Using unpack_partitions.sh." >&2 189 echo "WARNING: cannot find partition tools. Using unpack_partitions.sh." >&2
159 IMAGE_IS_UNPACKED=1 190 IMAGE_IS_UNPACKED=1
160 fi 191 fi
161 192
162 # Get the release image. 193 generate_img() {
163 pushd "${RELEASE_DIR}" >/dev/null 194 local outdev="$FLAGS_diskimg"
164 echo "Generating omaha release image from ${FLAGS_release}" 195 local sectors="$FLAGS_sectors"
165 echo "Generating omaha factory image from ${FLAGS_factory}"
166 echo "Output omaha image to ${OMAHA_DATA_DIR}"
167 echo "Output omaha config to ${OMAHA_CONF}"
168 196
169 prepare_dir 197 prepare_img
170 198
171 if [ -n "${IMAGE_IS_UNPACKED}" ]; then 199 # Get the release image.
172 echo "Unpacking image ${RELEASE_IMAGE} ..." >&2 200 pushd "${RELEASE_DIR}" >/dev/null
173 sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
174 fi
175 201
176 release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")" 202 echo "Release Kernel"
177 sudo chmod a+rw update.gz 203 image_partition_copy "${RELEASE_IMAGE}" 2 "${outdev}" 4
178 mv update.gz rootfs-release.gz
179 mv rootfs-release.gz "${OMAHA_DATA_DIR}"
180 echo "release: ${release_hash}"
181 204
182 oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")" 205 echo "Release Rootfs"
183 mv oem.gz "${OMAHA_DATA_DIR}" 206 image_partition_copy "${RELEASE_IMAGE}" 3 "${outdev}" 5
184 echo "oem: ${oem_hash}"
185 207
186 efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")" 208 echo "OEM parition"
187 mv efi.gz "${OMAHA_DATA_DIR}" 209 image_partition_copy "${RELEASE_IMAGE}" 8 "${outdev}" 8
188 echo "efi: ${efi_hash}"
189 210
190 popd >/dev/null 211 popd >/dev/null
191 212
192 # Go to retrieve the factory test image. 213 # Go to retrieve the factory test image.
193 pushd "${FACTORY_DIR}" >/dev/null 214 pushd "${FACTORY_DIR}" >/dev/null
194 prepare_dir
195 215
196 if [ -n "${IMAGE_IS_UNPACKED}" ]; then 216 echo "Factory Kernel"
197 echo "Unpacking image ${FACTORY_IMAGE} ..." >&2 217 image_partition_copy "${FACTORY_IMAGE}" 2 "${outdev}" 2
198 sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null 218 echo "Factory Rootfs"
199 fi 219 image_partition_copy "${FACTORY_IMAGE}" 3 "${outdev}" 3
220 echo "Factory Stateful"
221 image_partition_copy "${FACTORY_IMAGE}" 1 "${outdev}" 1
222 echo "EFI Partition"
223 image_partition_copy "${FACTORY_IMAGE}" 12 "${outdev}" 12
200 224
201 test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")" 225 echo "Generated Image at $outdev."
202 sudo chmod a+rw update.gz 226 echo "Done"
203 mv update.gz rootfs-test.gz 227 }
204 mv rootfs-test.gz "${OMAHA_DATA_DIR}"
205 echo "test: ${test_hash}"
206 228
207 state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")" 229 generate_omaha() {
208 mv state.gz "${OMAHA_DATA_DIR}" 230 # Clean up stale config and data files.
209 echo "state: ${state_hash}" 231 prepare_omaha
210 232
211 popd >/dev/null 233 # Get the release image.
234 pushd "${RELEASE_DIR}" >/dev/null
235 echo "Generating omaha release image from ${FLAGS_release}"
236 echo "Generating omaha factory image from ${FLAGS_factory}"
237 echo "Output omaha image to ${OMAHA_DATA_DIR}"
238 echo "Output omaha config to ${OMAHA_CONF}"
212 239
213 if [ -n "${FLAGS_firmware_updater}" ]; then 240 prepare_dir
214 SHELLBALL="${FLAGS_firmware_updater}" 241
215 if [ ! -f "$SHELLBALL" ]; then 242 if [ -n "${IMAGE_IS_UNPACKED}" ]; then
216 echo "Failed to find firmware updater: $SHELLBALL." 243 echo "Unpacking image ${RELEASE_IMAGE} ..." >&2
217 exit 1 244 sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
218 fi 245 fi
219 246
220 firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")" 247 release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")"
221 mv firmware.gz "${OMAHA_DATA_DIR}" 248 sudo chmod a+rw update.gz
222 echo "firmware: ${firmware_hash}" 249 mv update.gz rootfs-release.gz
223 fi 250 mv rootfs-release.gz "${OMAHA_DATA_DIR}"
251 echo "release: ${release_hash}"
224 252
225 # If the file does exist and we are using the subfolder flag we are going to 253 oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")"
226 # append another config. 254 mv oem.gz "${OMAHA_DATA_DIR}"
227 if [ -n "${FLAGS_subfolder}" ] && 255 echo "oem: ${oem_hash}"
228 [ -f "${OMAHA_CONF}" ]; then
229 # Remove the ']' from the last line of the file so we can add another config.
230 while [ -s "${OMAHA_CONF}" ]; do
231 # If the last line is null
232 if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then
233 sed -i '$d' "${OMAHA_CONF}"
234 elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then
235 sed -i '$d' "${OMAHA_CONF}"
236 else
237 break
238 fi
239 done
240 256
241 # Remove the last ] 257 popd >/dev/null
242 if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then 258
243 sed -i '$d' "${OMAHA_CONF}" 259 # Go to retrieve the factory test image.
260 pushd "${FACTORY_DIR}" >/dev/null
261 prepare_dir
262
263 if [ -n "${IMAGE_IS_UNPACKED}" ]; then
264 echo "Unpacking image ${FACTORY_IMAGE} ..." >&2
265 sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null
244 fi 266 fi
245 267
246 # If the file is empty, create it from scratch 268 test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")"
247 if [ ! -s "${OMAHA_CONF}" ]; then 269 sudo chmod a+rw update.gz
270 mv update.gz rootfs-test.gz
271 mv rootfs-test.gz "${OMAHA_DATA_DIR}"
272 echo "test: ${test_hash}"
273
274 state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")"
275 mv state.gz "${OMAHA_DATA_DIR}"
276 echo "state: ${state_hash}"
277
278 efi_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 12 "efi.gz")"
279 mv efi.gz "${OMAHA_DATA_DIR}"
280 echo "efi: ${efi_hash}"
281
282 popd >/dev/null
283
284 if [ -n "${FLAGS_firmware_updater}" ]; then
285 SHELLBALL="${FLAGS_firmware_updater}"
286 if [ ! -f "$SHELLBALL" ]; then
287 echo "Failed to find firmware updater: $SHELLBALL."
288 exit 1
289 fi
290
291 firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")"
292 mv firmware.gz "${OMAHA_DATA_DIR}"
293 echo "firmware: ${firmware_hash}"
294 fi
295
296 # If the file does exist and we are using the subfolder flag we are going to
297 # append another config.
298 if [ -n "${FLAGS_subfolder}" ] &&
299 [ -f "${OMAHA_CONF}" ]; then
300 # Remove the ']' from the last line of the file
301 # so we can add another config.
302 while [ -s "${OMAHA_CONF}" ]; do
303 # If the last line is null
304 if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then
305 sed -i '$d' "${OMAHA_CONF}"
306 elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then
307 sed -i '$d' "${OMAHA_CONF}"
308 else
309 break
310 fi
311 done
312
313 # Remove the last ]
314 if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then
315 sed -i '$d' "${OMAHA_CONF}"
316 fi
317
318 # If the file is empty, create it from scratch
319 if [ ! -s "${OMAHA_CONF}" ]; then
320 echo "config = [" >"${OMAHA_CONF}"
321 fi
322 else
248 echo "config = [" >"${OMAHA_CONF}" 323 echo "config = [" >"${OMAHA_CONF}"
249 fi 324 fi
250 else
251 echo "config = [" >"${OMAHA_CONF}"
252 fi
253 325
254 if [ -n "${FLAGS_subfolder}" ]; then 326 if [ -n "${FLAGS_subfolder}" ]; then
255 subfolder="${FLAGS_subfolder}/" 327 subfolder="${FLAGS_subfolder}/"
256 fi 328 fi
257 329
258 echo -n "{ 330 echo -n "{
259 'qual_ids': set([\"${FLAGS_board}\"]), 331 'qual_ids': set([\"${FLAGS_board}\"]),
260 'factory_image': '${subfolder}rootfs-test.gz', 332 'factory_image': '${subfolder}rootfs-test.gz',
261 'factory_checksum': '${test_hash}', 333 'factory_checksum': '${test_hash}',
262 'release_image': '${subfolder}rootfs-release.gz', 334 'release_image': '${subfolder}rootfs-release.gz',
263 'release_checksum': '${release_hash}', 335 'release_checksum': '${release_hash}',
264 'oempartitionimg_image': '${subfolder}oem.gz', 336 'oempartitionimg_image': '${subfolder}oem.gz',
265 'oempartitionimg_checksum': '${oem_hash}', 337 'oempartitionimg_checksum': '${oem_hash}',
266 'efipartitionimg_image': '${subfolder}efi.gz', 338 'efipartitionimg_image': '${subfolder}efi.gz',
267 'efipartitionimg_checksum': '${efi_hash}', 339 'efipartitionimg_checksum': '${efi_hash}',
268 'stateimg_image': '${subfolder}state.gz', 340 'stateimg_image': '${subfolder}state.gz',
269 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}" 341 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}"
270 342
271 if [ -n "${FLAGS_firmware_updater}" ] ; then 343 if [ -n "${FLAGS_firmware_updater}" ] ; then
272 echo -n " 344 echo -n "
273 'firmware_image': '${subfolder}firmware.gz', 345 'firmware_image': '${subfolder}firmware.gz',
274 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}" 346 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}"
275 fi 347 fi
276 348
277 echo -n " 349 echo -n "
278 }, 350 },
279 ] 351 ]
280 " >>"${OMAHA_CONF}" 352 " >>"${OMAHA_CONF}"
281 353
282 echo "The miniomaha server lives in src/platform/dev. 354 echo "The miniomaha server lives in src/platform/dev.
283 To validate the configutarion, run: 355 To validate the configutarion, run:
284 python2.6 devserver.py --factory_config miniomaha.conf \ 356 python2.6 devserver.py --factory_config miniomaha.conf \
285 --validate_factory_config 357 --validate_factory_config
286 To run the server: 358 To run the server:
287 python2.6 devserver.py --factory_config miniomaha.conf" 359 python2.6 devserver.py --factory_config miniomaha.conf"
360 }
361
362 # Main
363 if [ -n "$FLAGS_diskimg" ]; then
364 generate_img
365 else
366 generate_omaha
367 fi
OLDNEW
« no previous file with comments | « lib/cros_image_common.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698