| #!/bin/bash |
| # |
| # Copyright 2021 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # convert_image.sh --board=[board] --image_type=[type] --image_format=[format] |
| # |
| # This script converts a board's image(base, test, dev) to the specified format |
| # like vmdk, vhd so that the image can be used by platform other than GCP. |
| # |
| SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
| SCRIPT_ROOT=${SCRIPT_ROOT%cos} |
| . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 |
| |
| # Script must be run inside the chroot. |
| restart_in_chroot_if_needed "$@" |
| |
| DEFINE_string board "${DEFAULT_BOARD}" \ |
| "The board to build an image for." |
| DEFINE_string image_type "base" \ |
| "Image type to process, base, test or dev." |
| DEFINE_string image_format "" \ |
| "Image format to be converted to, vmdk or vhd." |
| DEFINE_string image_dir "" "Path to the folder to store netboot images." |
| |
| # Parse command line. |
| FLAGS "$@" || exit 1 |
| eval set -- "${FLAGS_ARGV}" |
| |
| . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 |
| . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 |
| |
| switch_to_strict_mode |
| |
| set -x |
| # build_packages artifact output. |
| SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" |
| # build_image artifact output. |
| |
| IMAGE_DIR="${CHROOT_TRUNK_DIR}"/src/build/images/"${FLAGS_board}"/latest |
| if [ -n "${FLAGS_image_dir}" ]; then |
| IMAGE_DIR=${FLAGS_image_dir} |
| fi |
| IMAGE_TYPE=${FLAGS_image_type} |
| |
| case ${FLAGS_image_format} in |
| "vmdk") |
| qemu-img convert -p -o subformat=streamOptimized -O vmdk\ |
| ${IMAGE_DIR}/chromiumos_${IMAGE_TYPE}_image.bin \ |
| ${IMAGE_DIR}/chromiumos_${IMAGE_TYPE}_image.vmdk |
| ;; |
| |
| "vhd") |
| qemu-img convert -f raw -o subformat=fixed,force_size -O vpc \ |
| ${IMAGE_DIR}/chromiumos_${IMAGE_TYPE}_image.bin \ |
| ${IMAGE_DIR}/chromiumos_${IMAGE_TYPE}_image.vhd |
| ;; |
| |
| *) |
| ;; |
| esac |