Chromium Code Reviews| Index: make_factory_package.sh |
| diff --git a/make_factory_package.sh b/make_factory_package.sh |
| index 0eb200e52a5141e27784bd2915cae7d487075570..2ab379f547600fa7dea6e156895fc5d5fa501a54 100755 |
| --- a/make_factory_package.sh |
| +++ b/make_factory_package.sh |
| @@ -34,6 +34,9 @@ DEFINE_string release "" \ |
| "Directory and file containing release image: /path/chromiumos_image.bin" |
| DEFINE_string subfolder "" \ |
| "If set, the name of the subfolder to put the payload items inside" |
| +DEFINE_string diskimg "" \ |
| + "If set, the name of the diskimage file to output" |
| +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
|
| # Parse command line |
| FLAGS "$@" || exit 1 |
| @@ -80,6 +83,21 @@ FACTORY_DIR="$(dirname "${FLAGS_factory}")" |
| RELEASE_IMAGE="$(basename "${FLAGS_release}")" |
| FACTORY_IMAGE="$(basename "${FLAGS_factory}")" |
| +prepare_img() { |
| + local outdev="$FLAGS_diskimg" |
| + local sectors="$FLAGS_sectors" |
| + local force_full="true" |
| + |
| + # We'll need some code to put in the PMBR, for booting on legacy BIOS. |
| + local pmbrcode="gptmbr.bin" |
| + 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.
|
| + sudo dd bs=512 count=1 if="${FLAGS_release}" of="${pmbrcode}" |
| + fi |
| + |
| + image_dump_partial_file /dev/zero 0 "${sectors}" | |
| + dd of="${outdev}" bs=8M |
| + 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
|
| +} |
| prepare_omaha() { |
| sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz" |
| @@ -145,9 +163,6 @@ compress_and_hash_partition() { |
| fi |
| } |
| -# Clean up stale config and data files. |
| -prepare_omaha |
| - |
| # Decide if we should unpack partition |
| if image_has_part_tools; then |
| IMAGE_IS_UNPACKED= |
| @@ -159,103 +174,157 @@ else |
| IMAGE_IS_UNPACKED=1 |
| fi |
| -# Get the release image. |
| -pushd "${RELEASE_DIR}" >/dev/null |
| -echo "Generating omaha release image from ${FLAGS_release}" |
| -echo "Generating omaha factory image from ${FLAGS_factory}" |
| -echo "Output omaha image to ${OMAHA_DATA_DIR}" |
| -echo "Output omaha config to ${OMAHA_CONF}" |
| +partition_copy() { |
| + local src="$1" |
| + local srcpart="$2" |
| + local dst="$3" |
| + local dstpart="$4" |
| -prepare_dir |
| + local srcoffset=$(partoffset "${src}" "${srcpart}") |
| + local dstoffset=$(partoffset "${dst}" "${dstpart}") |
| + local length=$(partsize "${src}" "${srcpart}") |
| -if [ -n "${IMAGE_IS_UNPACKED}" ]; then |
| - echo "Unpacking image ${RELEASE_IMAGE} ..." >&2 |
| - sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null |
| -fi |
| + image_dump_partition "${src}" "${srcpart}" | |
| + dd of="${dst}" bs=512 seek="${length}" conv=notrunc |
| +} |
| -release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")" |
| -sudo chmod a+rw update.gz |
| -mv update.gz rootfs-release.gz |
| -mv rootfs-release.gz "${OMAHA_DATA_DIR}" |
| -echo "release: ${release_hash}" |
| +generate_img() { |
| + local outdev="$FLAGS_diskimg" |
| + local sectors="$FLAGS_sectors" |
| -oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")" |
| -mv oem.gz "${OMAHA_DATA_DIR}" |
| -echo "oem: ${oem_hash}" |
| + prepare_img |
| -efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")" |
| -mv efi.gz "${OMAHA_DATA_DIR}" |
| -echo "efi: ${efi_hash}" |
| + # Get the release image. |
| + pushd "${RELEASE_DIR}" >/dev/null |
| -popd >/dev/null |
| + echo "Release Kernel" |
| + partition_copy "${RELEASE_IMAGE}" 2 "${outdev}" 4 |
| -# Go to retrieve the factory test image. |
| -pushd "${FACTORY_DIR}" >/dev/null |
| -prepare_dir |
| + echo "Release Rootfs" |
| + partition_copy "${RELEASE_IMAGE}" 3 "${outdev}" 5 |
| -if [ -n "${IMAGE_IS_UNPACKED}" ]; then |
| - echo "Unpacking image ${FACTORY_IMAGE} ..." >&2 |
| - sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null |
| -fi |
| + echo "OEM parition" |
| + partition_copy "${RELEASE_IMAGE}" 8 "${outdev}" 8 |
| + echo "EFI Partition" |
| + partition_copy "${RELEASE_IMAGE}" 12 "${outdev}" 12 |
| + |
| + popd >/dev/null |
| -test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")" |
| -sudo chmod a+rw update.gz |
| -mv update.gz rootfs-test.gz |
| -mv rootfs-test.gz "${OMAHA_DATA_DIR}" |
| -echo "test: ${test_hash}" |
| + # Go to retrieve the factory test image. |
| + pushd "${FACTORY_DIR}" >/dev/null |
| -state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")" |
| -mv state.gz "${OMAHA_DATA_DIR}" |
| -echo "state: ${state_hash}" |
| + echo "Factory Kernel" |
| + partition_copy "${FACTORY_IMAGE}" 2 "${outdev}" 2 |
| + echo "Factory Rootfs" |
| + partition_copy "${FACTORY_IMAGE}" 3 "${outdev}" 3 |
| + echo "Factory Stateful" |
| + partition_copy "${FACTORY_IMAGE}" 1 "${outdev}" 1 |
| + |
| + echo "Generated Image at $outdev." |
| + echo "Done" |
| +} |
| -popd >/dev/null |
| +generate_omaha() { |
| + # Clean up stale config and data files. |
|
Nick Sanders
2010/12/23 04:05:54
Everythign below this line is unchanged except for
|
| + prepare_omaha |
| -if [ -n "${FLAGS_firmware_updater}" ]; then |
| - SHELLBALL="${FLAGS_firmware_updater}" |
| - if [ ! -f "$SHELLBALL" ]; then |
| - echo "Failed to find firmware updater: $SHELLBALL." |
| - exit 1 |
| + # Get the release image. |
| + pushd "${RELEASE_DIR}" >/dev/null |
| + echo "Generating omaha release image from ${FLAGS_release}" |
| + echo "Generating omaha factory image from ${FLAGS_factory}" |
| + echo "Output omaha image to ${OMAHA_DATA_DIR}" |
| + echo "Output omaha config to ${OMAHA_CONF}" |
| + |
| + prepare_dir |
| + |
| + if [ -n "${IMAGE_IS_UNPACKED}" ]; then |
| + echo "Unpacking image ${RELEASE_IMAGE} ..." >&2 |
| + sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null |
| fi |
| - firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")" |
| - mv firmware.gz "${OMAHA_DATA_DIR}" |
| - echo "firmware: ${firmware_hash}" |
| -fi |
| + release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")" |
| + sudo chmod a+rw update.gz |
| + mv update.gz rootfs-release.gz |
| + mv rootfs-release.gz "${OMAHA_DATA_DIR}" |
| + echo "release: ${release_hash}" |
| -# If the file does exist and we are using the subfolder flag we are going to |
| -# append another config. |
| -if [ -n "${FLAGS_subfolder}" ] && |
| - [ -f "${OMAHA_CONF}" ]; then |
| - # Remove the ']' from the last line of the file so we can add another config. |
| - while [ -s "${OMAHA_CONF}" ]; do |
| - # If the last line is null |
| - if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then |
| - sed -i '$d' "${OMAHA_CONF}" |
| - elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then |
| - sed -i '$d' "${OMAHA_CONF}" |
| - else |
| - break |
| + oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")" |
| + mv oem.gz "${OMAHA_DATA_DIR}" |
| + echo "oem: ${oem_hash}" |
| + |
| + efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")" |
| + mv efi.gz "${OMAHA_DATA_DIR}" |
| + echo "efi: ${efi_hash}" |
| + |
| + popd >/dev/null |
| + |
| + # Go to retrieve the factory test image. |
| + pushd "${FACTORY_DIR}" >/dev/null |
| + prepare_dir |
| + |
| + if [ -n "${IMAGE_IS_UNPACKED}" ]; then |
| + echo "Unpacking image ${FACTORY_IMAGE} ..." >&2 |
| + sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null |
| + fi |
| + |
| + test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")" |
| + sudo chmod a+rw update.gz |
| + mv update.gz rootfs-test.gz |
| + mv rootfs-test.gz "${OMAHA_DATA_DIR}" |
| + echo "test: ${test_hash}" |
| + |
| + state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")" |
| + mv state.gz "${OMAHA_DATA_DIR}" |
| + echo "state: ${state_hash}" |
| + |
| + popd >/dev/null |
| + |
| + if [ -n "${FLAGS_firmware_updater}" ]; then |
| + SHELLBALL="${FLAGS_firmware_updater}" |
| + if [ ! -f "$SHELLBALL" ]; then |
| + echo "Failed to find firmware updater: $SHELLBALL." |
| + exit 1 |
| fi |
| - done |
| - # Remove the last ] |
| - if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then |
| - sed -i '$d' "${OMAHA_CONF}" |
| + firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")" |
| + mv firmware.gz "${OMAHA_DATA_DIR}" |
| + echo "firmware: ${firmware_hash}" |
| fi |
| - # If the file is empty, create it from scratch |
| - if [ ! -s "${OMAHA_CONF}" ]; then |
| + # If the file does exist and we are using the subfolder flag we are going to |
| + # append another config. |
| + if [ -n "${FLAGS_subfolder}" ] && |
| + [ -f "${OMAHA_CONF}" ]; then |
| + # Remove the ']' from the last line of the file so we can add another config. |
| + while [ -s "${OMAHA_CONF}" ]; do |
| + # If the last line is null |
| + if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then |
| + sed -i '$d' "${OMAHA_CONF}" |
| + elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then |
| + sed -i '$d' "${OMAHA_CONF}" |
| + else |
| + break |
| + fi |
| + done |
| + |
| + # Remove the last ] |
| + if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then |
| + sed -i '$d' "${OMAHA_CONF}" |
| + fi |
| + |
| + # If the file is empty, create it from scratch |
| + if [ ! -s "${OMAHA_CONF}" ]; then |
| + echo "config = [" >"${OMAHA_CONF}" |
| + fi |
| + else |
| echo "config = [" >"${OMAHA_CONF}" |
| fi |
| -else |
| - echo "config = [" >"${OMAHA_CONF}" |
| -fi |
| -if [ -n "${FLAGS_subfolder}" ]; then |
| - subfolder="${FLAGS_subfolder}/" |
| -fi |
| + if [ -n "${FLAGS_subfolder}" ]; then |
| + subfolder="${FLAGS_subfolder}/" |
| + fi |
| -echo -n "{ |
| + echo -n "{ |
| 'qual_ids': set([\"${FLAGS_board}\"]), |
| 'factory_image': '${subfolder}rootfs-test.gz', |
| 'factory_checksum': '${test_hash}', |
| @@ -268,20 +337,28 @@ echo -n "{ |
| 'stateimg_image': '${subfolder}state.gz', |
| 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}" |
| -if [ -n "${FLAGS_firmware_updater}" ] ; then |
| - echo -n " |
| + if [ -n "${FLAGS_firmware_updater}" ] ; then |
| + echo -n " |
| 'firmware_image': '${subfolder}firmware.gz', |
| 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}" |
| -fi |
| + fi |
| -echo -n " |
| + echo -n " |
| }, |
| ] |
| " >>"${OMAHA_CONF}" |
| -echo "The miniomaha server lives in src/platform/dev. |
| + echo "The miniomaha server lives in src/platform/dev. |
| To validate the configutarion, run: |
| python2.6 devserver.py --factory_config miniomaha.conf \ |
| --validate_factory_config |
| To run the server: |
| python2.6 devserver.py --factory_config miniomaha.conf" |
| +} |
| + |
| +# Main |
| +if [ -n "$FLAGS_diskimg" ]; then |
| + generate_img |
| +else |
| + generate_omaha |
| +fi |