Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_integer sectors 31277232 "Size of image in sectors" | |
|
Hung-Te
2010/12/23 07:02:20
I'd prefer to calculate this instead of manually a
Nick Sanders
2010/12/28 22:52:31
As we are creating the disk image, we don't know w
Hung-Te
2010/12/29 07:48:19
We are creating the disk image from existing parti
| |
| 37 | 40 |
| 38 # Parse command line | 41 # Parse command line |
| 39 FLAGS "$@" || exit 1 | 42 FLAGS "$@" || exit 1 |
| 40 eval set -- "${FLAGS_ARGV}" | 43 eval set -- "${FLAGS_ARGV}" |
| 41 | 44 |
| 42 if [ ! -f "${FLAGS_release}" ]; then | 45 if [ ! -f "${FLAGS_release}" ]; then |
| 43 echo "Cannot find image file ${FLAGS_release}" | 46 echo "Cannot find image file ${FLAGS_release}" |
| 44 exit 1 | 47 exit 1 |
| 45 fi | 48 fi |
| 46 | 49 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 73 sudo -v | 76 sudo -v |
| 74 echo "Done" | 77 echo "Done" |
| 75 fi | 78 fi |
| 76 | 79 |
| 77 # Use this image as the source image to copy | 80 # Use this image as the source image to copy |
| 78 RELEASE_DIR="$(dirname "${FLAGS_release}")" | 81 RELEASE_DIR="$(dirname "${FLAGS_release}")" |
| 79 FACTORY_DIR="$(dirname "${FLAGS_factory}")" | 82 FACTORY_DIR="$(dirname "${FLAGS_factory}")" |
| 80 RELEASE_IMAGE="$(basename "${FLAGS_release}")" | 83 RELEASE_IMAGE="$(basename "${FLAGS_release}")" |
| 81 FACTORY_IMAGE="$(basename "${FLAGS_factory}")" | 84 FACTORY_IMAGE="$(basename "${FLAGS_factory}")" |
| 82 | 85 |
| 86 prepare_img() { | |
| 87 local outdev="$FLAGS_diskimg" | |
| 88 local sectors="$FLAGS_sectors" | |
| 89 local force_full="true" | |
| 90 | |
| 91 # We'll need some code to put in the PMBR, for booting on legacy BIOS. | |
| 92 local pmbrcode="gptmbr.bin" | |
| 93 if ! [ -e gptmbr.bin ]; then | |
|
Nick Sanders
2010/12/23 04:05:54
Where might be a good location for this file? Shou
Hung-Te
2010/12/23 07:02:20
PMBR from release images should be good enough.
bu
Nick Sanders
2010/12/28 22:52:31
makes sense. done.
| |
| 94 sudo dd bs=512 count=1 if="${FLAGS_release}" of="${pmbrcode}" | |
| 95 fi | |
| 96 | |
| 97 image_dump_partial_file /dev/zero 0 "${sectors}" | | |
| 98 dd of="${outdev}" bs=8M | |
| 99 install_gpt "${outdev}" 0 0 "${pmbrcode}" 0 "${force_full}" | |
|
Nick Sanders
2010/12/23 04:05:54
Probably only works in the chroot, not sure that t
| |
| 100 } | |
| 83 | 101 |
| 84 prepare_omaha() { | 102 prepare_omaha() { |
| 85 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz" | 103 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz" |
| 86 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-release.gz" | 104 sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-release.gz" |
| 87 rm -rf "${OMAHA_DATA_DIR}/efi.gz" | 105 rm -rf "${OMAHA_DATA_DIR}/efi.gz" |
| 88 rm -rf "${OMAHA_DATA_DIR}/oem.gz" | 106 rm -rf "${OMAHA_DATA_DIR}/oem.gz" |
| 89 rm -rf "${OMAHA_DATA_DIR}/state.gz" | 107 rm -rf "${OMAHA_DATA_DIR}/state.gz" |
| 90 if [ ! -d "${OMAHA_DATA_DIR}" ]; then | 108 if [ ! -d "${OMAHA_DATA_DIR}" ]; then |
| 91 mkdir -p "${OMAHA_DATA_DIR}" | 109 mkdir -p "${OMAHA_DATA_DIR}" |
| 92 fi | 110 fi |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 local output_file="$3" | 156 local output_file="$3" |
| 139 | 157 |
| 140 if [ -n "${IMAGE_IS_UNPACKED}" ]; then | 158 if [ -n "${IMAGE_IS_UNPACKED}" ]; then |
| 141 compress_and_hash_file "part_$part_num" "$output_file" | 159 compress_and_hash_file "part_$part_num" "$output_file" |
| 142 else | 160 else |
| 143 image_dump_partition "$input_file" "$part_num" | | 161 image_dump_partition "$input_file" "$part_num" | |
| 144 compress_and_hash_file "" "$output_file" | 162 compress_and_hash_file "" "$output_file" |
| 145 fi | 163 fi |
| 146 } | 164 } |
| 147 | 165 |
| 148 # Clean up stale config and data files. | |
| 149 prepare_omaha | |
| 150 | |
| 151 # Decide if we should unpack partition | 166 # Decide if we should unpack partition |
| 152 if image_has_part_tools; then | 167 if image_has_part_tools; then |
| 153 IMAGE_IS_UNPACKED= | 168 IMAGE_IS_UNPACKED= |
| 154 else | 169 else |
| 155 #TODO(hungte) Currently we run unpack_partitions.sh if part_tools are not | 170 #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 | 171 # found. If the format of unpack_partitions.sh is reliable, we can prevent |
| 157 # creating temporary files. See image_part_offset for more information. | 172 # creating temporary files. See image_part_offset for more information. |
| 158 echo "WARNING: cannot find partition tools. Using unpack_partitions.sh." >&2 | 173 echo "WARNING: cannot find partition tools. Using unpack_partitions.sh." >&2 |
| 159 IMAGE_IS_UNPACKED=1 | 174 IMAGE_IS_UNPACKED=1 |
| 160 fi | 175 fi |
| 161 | 176 |
| 162 # Get the release image. | 177 partition_copy() { |
| 163 pushd "${RELEASE_DIR}" >/dev/null | 178 local src="$1" |
| 164 echo "Generating omaha release image from ${FLAGS_release}" | 179 local srcpart="$2" |
| 165 echo "Generating omaha factory image from ${FLAGS_factory}" | 180 local dst="$3" |
| 166 echo "Output omaha image to ${OMAHA_DATA_DIR}" | 181 local dstpart="$4" |
| 167 echo "Output omaha config to ${OMAHA_CONF}" | |
| 168 | 182 |
| 169 prepare_dir | 183 local srcoffset=$(partoffset "${src}" "${srcpart}") |
| 184 local dstoffset=$(partoffset "${dst}" "${dstpart}") | |
| 185 local length=$(partsize "${src}" "${srcpart}") | |
| 170 | 186 |
| 171 if [ -n "${IMAGE_IS_UNPACKED}" ]; then | 187 image_dump_partition "${src}" "${srcpart}" | |
| 172 echo "Unpacking image ${RELEASE_IMAGE} ..." >&2 | 188 dd of="${dst}" bs=512 seek="${length}" conv=notrunc |
| 173 sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null | 189 } |
| 174 fi | |
| 175 | 190 |
| 176 release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")" | 191 generate_img() { |
| 177 sudo chmod a+rw update.gz | 192 local outdev="$FLAGS_diskimg" |
| 178 mv update.gz rootfs-release.gz | 193 local sectors="$FLAGS_sectors" |
| 179 mv rootfs-release.gz "${OMAHA_DATA_DIR}" | |
| 180 echo "release: ${release_hash}" | |
| 181 | 194 |
| 182 oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")" | 195 prepare_img |
| 183 mv oem.gz "${OMAHA_DATA_DIR}" | |
| 184 echo "oem: ${oem_hash}" | |
| 185 | 196 |
| 186 efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")" | 197 # Get the release image. |
| 187 mv efi.gz "${OMAHA_DATA_DIR}" | 198 pushd "${RELEASE_DIR}" >/dev/null |
| 188 echo "efi: ${efi_hash}" | |
| 189 | 199 |
| 190 popd >/dev/null | 200 echo "Release Kernel" |
| 201 partition_copy "${RELEASE_IMAGE}" 2 "${outdev}" 4 | |
| 191 | 202 |
| 192 # Go to retrieve the factory test image. | 203 echo "Release Rootfs" |
| 193 pushd "${FACTORY_DIR}" >/dev/null | 204 partition_copy "${RELEASE_IMAGE}" 3 "${outdev}" 5 |
| 194 prepare_dir | |
| 195 | 205 |
| 196 if [ -n "${IMAGE_IS_UNPACKED}" ]; then | 206 echo "OEM parition" |
| 197 echo "Unpacking image ${FACTORY_IMAGE} ..." >&2 | 207 partition_copy "${RELEASE_IMAGE}" 8 "${outdev}" 8 |
| 198 sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null | 208 echo "EFI Partition" |
| 199 fi | 209 partition_copy "${RELEASE_IMAGE}" 12 "${outdev}" 12 |
| 200 | 210 |
| 201 test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")" | 211 popd >/dev/null |
| 202 sudo chmod a+rw update.gz | |
| 203 mv update.gz rootfs-test.gz | |
| 204 mv rootfs-test.gz "${OMAHA_DATA_DIR}" | |
| 205 echo "test: ${test_hash}" | |
| 206 | 212 |
| 207 state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")" | 213 # Go to retrieve the factory test image. |
| 208 mv state.gz "${OMAHA_DATA_DIR}" | 214 pushd "${FACTORY_DIR}" >/dev/null |
| 209 echo "state: ${state_hash}" | |
| 210 | 215 |
| 211 popd >/dev/null | 216 echo "Factory Kernel" |
| 217 partition_copy "${FACTORY_IMAGE}" 2 "${outdev}" 2 | |
| 218 echo "Factory Rootfs" | |
| 219 partition_copy "${FACTORY_IMAGE}" 3 "${outdev}" 3 | |
| 220 echo "Factory Stateful" | |
| 221 partition_copy "${FACTORY_IMAGE}" 1 "${outdev}" 1 | |
| 212 | 222 |
| 213 if [ -n "${FLAGS_firmware_updater}" ]; then | 223 echo "Generated Image at $outdev." |
| 214 SHELLBALL="${FLAGS_firmware_updater}" | 224 echo "Done" |
| 215 if [ ! -f "$SHELLBALL" ]; then | 225 } |
| 216 echo "Failed to find firmware updater: $SHELLBALL." | 226 |
| 217 exit 1 | 227 generate_omaha() { |
| 228 # Clean up stale config and data files. | |
|
Nick Sanders
2010/12/23 04:05:54
Everythign below this line is unchanged except for
| |
| 229 prepare_omaha | |
| 230 | |
| 231 # Get the release image. | |
| 232 pushd "${RELEASE_DIR}" >/dev/null | |
| 233 echo "Generating omaha release image from ${FLAGS_release}" | |
| 234 echo "Generating omaha factory image from ${FLAGS_factory}" | |
| 235 echo "Output omaha image to ${OMAHA_DATA_DIR}" | |
| 236 echo "Output omaha config to ${OMAHA_CONF}" | |
| 237 | |
| 238 prepare_dir | |
| 239 | |
| 240 if [ -n "${IMAGE_IS_UNPACKED}" ]; then | |
| 241 echo "Unpacking image ${RELEASE_IMAGE} ..." >&2 | |
| 242 sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null | |
| 218 fi | 243 fi |
| 219 | 244 |
| 220 firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")" | 245 release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")" |
| 221 mv firmware.gz "${OMAHA_DATA_DIR}" | 246 sudo chmod a+rw update.gz |
| 222 echo "firmware: ${firmware_hash}" | 247 mv update.gz rootfs-release.gz |
| 223 fi | 248 mv rootfs-release.gz "${OMAHA_DATA_DIR}" |
| 249 echo "release: ${release_hash}" | |
| 224 | 250 |
| 225 # If the file does exist and we are using the subfolder flag we are going to | 251 oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")" |
| 226 # append another config. | 252 mv oem.gz "${OMAHA_DATA_DIR}" |
| 227 if [ -n "${FLAGS_subfolder}" ] && | 253 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 | 254 |
| 241 # Remove the last ] | 255 efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")" |
| 242 if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then | 256 mv efi.gz "${OMAHA_DATA_DIR}" |
| 243 sed -i '$d' "${OMAHA_CONF}" | 257 echo "efi: ${efi_hash}" |
| 258 | |
| 259 popd >/dev/null | |
| 260 | |
| 261 # Go to retrieve the factory test image. | |
| 262 pushd "${FACTORY_DIR}" >/dev/null | |
| 263 prepare_dir | |
| 264 | |
| 265 if [ -n "${IMAGE_IS_UNPACKED}" ]; then | |
| 266 echo "Unpacking image ${FACTORY_IMAGE} ..." >&2 | |
| 267 sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null | |
| 244 fi | 268 fi |
| 245 | 269 |
| 246 # If the file is empty, create it from scratch | 270 test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")" |
| 247 if [ ! -s "${OMAHA_CONF}" ]; then | 271 sudo chmod a+rw update.gz |
| 272 mv update.gz rootfs-test.gz | |
| 273 mv rootfs-test.gz "${OMAHA_DATA_DIR}" | |
| 274 echo "test: ${test_hash}" | |
| 275 | |
| 276 state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")" | |
| 277 mv state.gz "${OMAHA_DATA_DIR}" | |
| 278 echo "state: ${state_hash}" | |
| 279 | |
| 280 popd >/dev/null | |
| 281 | |
| 282 if [ -n "${FLAGS_firmware_updater}" ]; then | |
| 283 SHELLBALL="${FLAGS_firmware_updater}" | |
| 284 if [ ! -f "$SHELLBALL" ]; then | |
| 285 echo "Failed to find firmware updater: $SHELLBALL." | |
| 286 exit 1 | |
| 287 fi | |
| 288 | |
| 289 firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")" | |
| 290 mv firmware.gz "${OMAHA_DATA_DIR}" | |
| 291 echo "firmware: ${firmware_hash}" | |
| 292 fi | |
| 293 | |
| 294 # If the file does exist and we are using the subfolder flag we are going to | |
| 295 # append another config. | |
| 296 if [ -n "${FLAGS_subfolder}" ] && | |
| 297 [ -f "${OMAHA_CONF}" ]; then | |
| 298 # Remove the ']' from the last line of the file so we can add another config . | |
| 299 while [ -s "${OMAHA_CONF}" ]; do | |
| 300 # If the last line is null | |
| 301 if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then | |
| 302 sed -i '$d' "${OMAHA_CONF}" | |
| 303 elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then | |
| 304 sed -i '$d' "${OMAHA_CONF}" | |
| 305 else | |
| 306 break | |
| 307 fi | |
| 308 done | |
| 309 | |
| 310 # Remove the last ] | |
| 311 if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then | |
| 312 sed -i '$d' "${OMAHA_CONF}" | |
| 313 fi | |
| 314 | |
| 315 # If the file is empty, create it from scratch | |
| 316 if [ ! -s "${OMAHA_CONF}" ]; then | |
| 317 echo "config = [" >"${OMAHA_CONF}" | |
| 318 fi | |
| 319 else | |
| 248 echo "config = [" >"${OMAHA_CONF}" | 320 echo "config = [" >"${OMAHA_CONF}" |
| 249 fi | 321 fi |
| 250 else | |
| 251 echo "config = [" >"${OMAHA_CONF}" | |
| 252 fi | |
| 253 | 322 |
| 254 if [ -n "${FLAGS_subfolder}" ]; then | 323 if [ -n "${FLAGS_subfolder}" ]; then |
| 255 subfolder="${FLAGS_subfolder}/" | 324 subfolder="${FLAGS_subfolder}/" |
| 256 fi | 325 fi |
| 257 | 326 |
| 258 echo -n "{ | 327 echo -n "{ |
| 259 'qual_ids': set([\"${FLAGS_board}\"]), | 328 'qual_ids': set([\"${FLAGS_board}\"]), |
| 260 'factory_image': '${subfolder}rootfs-test.gz', | 329 'factory_image': '${subfolder}rootfs-test.gz', |
| 261 'factory_checksum': '${test_hash}', | 330 'factory_checksum': '${test_hash}', |
| 262 'release_image': '${subfolder}rootfs-release.gz', | 331 'release_image': '${subfolder}rootfs-release.gz', |
| 263 'release_checksum': '${release_hash}', | 332 'release_checksum': '${release_hash}', |
| 264 'oempartitionimg_image': '${subfolder}oem.gz', | 333 'oempartitionimg_image': '${subfolder}oem.gz', |
| 265 'oempartitionimg_checksum': '${oem_hash}', | 334 'oempartitionimg_checksum': '${oem_hash}', |
| 266 'efipartitionimg_image': '${subfolder}efi.gz', | 335 'efipartitionimg_image': '${subfolder}efi.gz', |
| 267 'efipartitionimg_checksum': '${efi_hash}', | 336 'efipartitionimg_checksum': '${efi_hash}', |
| 268 'stateimg_image': '${subfolder}state.gz', | 337 'stateimg_image': '${subfolder}state.gz', |
| 269 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}" | 338 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}" |
| 270 | 339 |
| 271 if [ -n "${FLAGS_firmware_updater}" ] ; then | 340 if [ -n "${FLAGS_firmware_updater}" ] ; then |
| 272 echo -n " | 341 echo -n " |
| 273 'firmware_image': '${subfolder}firmware.gz', | 342 'firmware_image': '${subfolder}firmware.gz', |
| 274 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}" | 343 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}" |
| 275 fi | 344 fi |
| 276 | 345 |
| 277 echo -n " | 346 echo -n " |
| 278 }, | 347 }, |
| 279 ] | 348 ] |
| 280 " >>"${OMAHA_CONF}" | 349 " >>"${OMAHA_CONF}" |
| 281 | 350 |
| 282 echo "The miniomaha server lives in src/platform/dev. | 351 echo "The miniomaha server lives in src/platform/dev. |
| 283 To validate the configutarion, run: | 352 To validate the configutarion, run: |
| 284 python2.6 devserver.py --factory_config miniomaha.conf \ | 353 python2.6 devserver.py --factory_config miniomaha.conf \ |
| 285 --validate_factory_config | 354 --validate_factory_config |
| 286 To run the server: | 355 To run the server: |
| 287 python2.6 devserver.py --factory_config miniomaha.conf" | 356 python2.6 devserver.py --factory_config miniomaha.conf" |
| 357 } | |
| 358 | |
| 359 # Main | |
| 360 if [ -n "$FLAGS_diskimg" ]; then | |
| 361 generate_img | |
| 362 else | |
| 363 generate_omaha | |
| 364 fi | |
| OLD | NEW |