mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-09 05:56:58 +02:00
Allow disk image target for copy machine.
BUG=10531 TEST=build and imaged a mario Change-Id: I60790f178159d707f610ba1668c29179a6c32e61 Review URL: http://codereview.chromium.org/6050006
This commit is contained in:
parent
b1d17e24eb
commit
607c0780c0
@ -168,3 +168,23 @@ image_umount_partition() {
|
|||||||
|
|
||||||
umount -d "$mount_point"
|
umount -d "$mount_point"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Copy a partition from one image to another.
|
||||||
|
image_partition_copy() {
|
||||||
|
local src="$1"
|
||||||
|
local srcpart="$2"
|
||||||
|
local dst="$3"
|
||||||
|
local dstpart="$4"
|
||||||
|
|
||||||
|
local srcoffset=$(image_part_offset "${src}" "${srcpart}")
|
||||||
|
local dstoffset=$(image_part_offset "${dst}" "${dstpart}")
|
||||||
|
local length=$(image_part_size "${src}" "${srcpart}")
|
||||||
|
local dstlength=$(image_part_size "${dst}" "${dstpart}")
|
||||||
|
|
||||||
|
if [ "${length}" -gt "${dstlength}" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
image_dump_partition "${src}" "${srcpart}" |
|
||||||
|
dd of="${dst}" bs=512 seek="${dstoffset}" conv=notrunc
|
||||||
|
}
|
||||||
|
@ -34,6 +34,11 @@ DEFINE_string release "" \
|
|||||||
"Directory and file containing release image: /path/chromiumos_image.bin"
|
"Directory and file containing release image: /path/chromiumos_image.bin"
|
||||||
DEFINE_string subfolder "" \
|
DEFINE_string subfolder "" \
|
||||||
"If set, the name of the subfolder to put the payload items inside"
|
"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_boolean preserve ${FLAGS_FALSE} \
|
||||||
|
"If set, reuse the diskimage file, if available"
|
||||||
|
DEFINE_integer sectors 31277232 "Size of image in sectors"
|
||||||
|
|
||||||
# Parse command line
|
# Parse command line
|
||||||
FLAGS "$@" || exit 1
|
FLAGS "$@" || exit 1
|
||||||
@ -80,6 +85,35 @@ FACTORY_DIR="$(dirname "${FLAGS_factory}")"
|
|||||||
RELEASE_IMAGE="$(basename "${FLAGS_release}")"
|
RELEASE_IMAGE="$(basename "${FLAGS_release}")"
|
||||||
FACTORY_IMAGE="$(basename "${FLAGS_factory}")"
|
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.
|
||||||
|
echo "Fetch PMBR"
|
||||||
|
local pmbrcode="$(mktemp -d)/gptmbr.bin"
|
||||||
|
sudo dd bs=512 count=1 if="${FLAGS_release}" of="${pmbrcode}" status=noxfer
|
||||||
|
|
||||||
|
echo "Prepare base disk image"
|
||||||
|
# Create an output file if requested, or if none exists.
|
||||||
|
if [ -b "${outdev}" ] ; then
|
||||||
|
echo "Using block device ${outdev}"
|
||||||
|
elif [ ! -e "${outdev}" -o \
|
||||||
|
"$(stat -c %s ${outdev})" != "$(( ${sectors} * 512 ))" -o \
|
||||||
|
"$FLAGS_preserve" = "$FLAGS_FALSE" ]; then
|
||||||
|
echo "Generating empty image file"
|
||||||
|
image_dump_partial_file /dev/zero 0 "${sectors}" |
|
||||||
|
dd of="${outdev}" bs=8M
|
||||||
|
else
|
||||||
|
echo "Reusing $outdev"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create GPT partition table.
|
||||||
|
install_gpt "${outdev}" 0 0 "${pmbrcode}" 0 "${force_full}"
|
||||||
|
# Activate the correct partition.
|
||||||
|
cgpt add -i 2 -S 1 -P 1 "${outdev}"
|
||||||
|
}
|
||||||
|
|
||||||
prepare_omaha() {
|
prepare_omaha() {
|
||||||
sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz"
|
sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz"
|
||||||
@ -145,9 +179,6 @@ compress_and_hash_partition() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean up stale config and data files.
|
|
||||||
prepare_omaha
|
|
||||||
|
|
||||||
# Decide if we should unpack partition
|
# Decide if we should unpack partition
|
||||||
if image_has_part_tools; then
|
if image_has_part_tools; then
|
||||||
IMAGE_IS_UNPACKED=
|
IMAGE_IS_UNPACKED=
|
||||||
@ -159,58 +190,98 @@ else
|
|||||||
IMAGE_IS_UNPACKED=1
|
IMAGE_IS_UNPACKED=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the release image.
|
generate_img() {
|
||||||
pushd "${RELEASE_DIR}" >/dev/null
|
local outdev="$FLAGS_diskimg"
|
||||||
echo "Generating omaha release image from ${FLAGS_release}"
|
local sectors="$FLAGS_sectors"
|
||||||
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
|
prepare_img
|
||||||
|
|
||||||
if [ -n "${IMAGE_IS_UNPACKED}" ]; then
|
# Get the release image.
|
||||||
|
pushd "${RELEASE_DIR}" >/dev/null
|
||||||
|
|
||||||
|
echo "Release Kernel"
|
||||||
|
image_partition_copy "${RELEASE_IMAGE}" 2 "${outdev}" 4
|
||||||
|
|
||||||
|
echo "Release Rootfs"
|
||||||
|
image_partition_copy "${RELEASE_IMAGE}" 3 "${outdev}" 5
|
||||||
|
|
||||||
|
echo "OEM parition"
|
||||||
|
image_partition_copy "${RELEASE_IMAGE}" 8 "${outdev}" 8
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
# Go to retrieve the factory test image.
|
||||||
|
pushd "${FACTORY_DIR}" >/dev/null
|
||||||
|
|
||||||
|
echo "Factory Kernel"
|
||||||
|
image_partition_copy "${FACTORY_IMAGE}" 2 "${outdev}" 2
|
||||||
|
echo "Factory Rootfs"
|
||||||
|
image_partition_copy "${FACTORY_IMAGE}" 3 "${outdev}" 3
|
||||||
|
echo "Factory Stateful"
|
||||||
|
image_partition_copy "${FACTORY_IMAGE}" 1 "${outdev}" 1
|
||||||
|
echo "EFI Partition"
|
||||||
|
image_partition_copy "${FACTORY_IMAGE}" 12 "${outdev}" 12
|
||||||
|
|
||||||
|
echo "Generated Image at $outdev."
|
||||||
|
echo "Done"
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_omaha() {
|
||||||
|
# Clean up stale config and data files.
|
||||||
|
prepare_omaha
|
||||||
|
|
||||||
|
# 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
|
echo "Unpacking image ${RELEASE_IMAGE} ..." >&2
|
||||||
sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
|
sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")"
|
release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")"
|
||||||
sudo chmod a+rw update.gz
|
sudo chmod a+rw update.gz
|
||||||
mv update.gz rootfs-release.gz
|
mv update.gz rootfs-release.gz
|
||||||
mv rootfs-release.gz "${OMAHA_DATA_DIR}"
|
mv rootfs-release.gz "${OMAHA_DATA_DIR}"
|
||||||
echo "release: ${release_hash}"
|
echo "release: ${release_hash}"
|
||||||
|
|
||||||
oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")"
|
oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")"
|
||||||
mv oem.gz "${OMAHA_DATA_DIR}"
|
mv oem.gz "${OMAHA_DATA_DIR}"
|
||||||
echo "oem: ${oem_hash}"
|
echo "oem: ${oem_hash}"
|
||||||
|
|
||||||
efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")"
|
popd >/dev/null
|
||||||
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
|
||||||
|
|
||||||
# Go to retrieve the factory test image.
|
if [ -n "${IMAGE_IS_UNPACKED}" ]; then
|
||||||
pushd "${FACTORY_DIR}" >/dev/null
|
|
||||||
prepare_dir
|
|
||||||
|
|
||||||
if [ -n "${IMAGE_IS_UNPACKED}" ]; then
|
|
||||||
echo "Unpacking image ${FACTORY_IMAGE} ..." >&2
|
echo "Unpacking image ${FACTORY_IMAGE} ..." >&2
|
||||||
sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null
|
sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")"
|
test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")"
|
||||||
sudo chmod a+rw update.gz
|
sudo chmod a+rw update.gz
|
||||||
mv update.gz rootfs-test.gz
|
mv update.gz rootfs-test.gz
|
||||||
mv rootfs-test.gz "${OMAHA_DATA_DIR}"
|
mv rootfs-test.gz "${OMAHA_DATA_DIR}"
|
||||||
echo "test: ${test_hash}"
|
echo "test: ${test_hash}"
|
||||||
|
|
||||||
state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")"
|
state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")"
|
||||||
mv state.gz "${OMAHA_DATA_DIR}"
|
mv state.gz "${OMAHA_DATA_DIR}"
|
||||||
echo "state: ${state_hash}"
|
echo "state: ${state_hash}"
|
||||||
|
|
||||||
popd >/dev/null
|
efi_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 12 "efi.gz")"
|
||||||
|
mv efi.gz "${OMAHA_DATA_DIR}"
|
||||||
|
echo "efi: ${efi_hash}"
|
||||||
|
|
||||||
if [ -n "${FLAGS_firmware_updater}" ]; then
|
popd >/dev/null
|
||||||
|
|
||||||
|
if [ -n "${FLAGS_firmware_updater}" ]; then
|
||||||
SHELLBALL="${FLAGS_firmware_updater}"
|
SHELLBALL="${FLAGS_firmware_updater}"
|
||||||
if [ ! -f "$SHELLBALL" ]; then
|
if [ ! -f "$SHELLBALL" ]; then
|
||||||
echo "Failed to find firmware updater: $SHELLBALL."
|
echo "Failed to find firmware updater: $SHELLBALL."
|
||||||
@ -220,13 +291,14 @@ if [ -n "${FLAGS_firmware_updater}" ]; then
|
|||||||
firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")"
|
firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")"
|
||||||
mv firmware.gz "${OMAHA_DATA_DIR}"
|
mv firmware.gz "${OMAHA_DATA_DIR}"
|
||||||
echo "firmware: ${firmware_hash}"
|
echo "firmware: ${firmware_hash}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the file does exist and we are using the subfolder flag we are going to
|
# If the file does exist and we are using the subfolder flag we are going to
|
||||||
# append another config.
|
# append another config.
|
||||||
if [ -n "${FLAGS_subfolder}" ] &&
|
if [ -n "${FLAGS_subfolder}" ] &&
|
||||||
[ -f "${OMAHA_CONF}" ]; then
|
[ -f "${OMAHA_CONF}" ]; then
|
||||||
# Remove the ']' from the last line of the file so we can add another config.
|
# Remove the ']' from the last line of the file
|
||||||
|
# so we can add another config.
|
||||||
while [ -s "${OMAHA_CONF}" ]; do
|
while [ -s "${OMAHA_CONF}" ]; do
|
||||||
# If the last line is null
|
# If the last line is null
|
||||||
if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then
|
if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then
|
||||||
@ -247,15 +319,15 @@ if [ -n "${FLAGS_subfolder}" ] &&
|
|||||||
if [ ! -s "${OMAHA_CONF}" ]; then
|
if [ ! -s "${OMAHA_CONF}" ]; then
|
||||||
echo "config = [" >"${OMAHA_CONF}"
|
echo "config = [" >"${OMAHA_CONF}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "config = [" >"${OMAHA_CONF}"
|
echo "config = [" >"${OMAHA_CONF}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${FLAGS_subfolder}" ]; then
|
if [ -n "${FLAGS_subfolder}" ]; then
|
||||||
subfolder="${FLAGS_subfolder}/"
|
subfolder="${FLAGS_subfolder}/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "{
|
echo -n "{
|
||||||
'qual_ids': set([\"${FLAGS_board}\"]),
|
'qual_ids': set([\"${FLAGS_board}\"]),
|
||||||
'factory_image': '${subfolder}rootfs-test.gz',
|
'factory_image': '${subfolder}rootfs-test.gz',
|
||||||
'factory_checksum': '${test_hash}',
|
'factory_checksum': '${test_hash}',
|
||||||
@ -268,20 +340,28 @@ echo -n "{
|
|||||||
'stateimg_image': '${subfolder}state.gz',
|
'stateimg_image': '${subfolder}state.gz',
|
||||||
'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}"
|
'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}"
|
||||||
|
|
||||||
if [ -n "${FLAGS_firmware_updater}" ] ; then
|
if [ -n "${FLAGS_firmware_updater}" ] ; then
|
||||||
echo -n "
|
echo -n "
|
||||||
'firmware_image': '${subfolder}firmware.gz',
|
'firmware_image': '${subfolder}firmware.gz',
|
||||||
'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}"
|
'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "
|
echo -n "
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
" >>"${OMAHA_CONF}"
|
" >>"${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:
|
To validate the configutarion, run:
|
||||||
python2.6 devserver.py --factory_config miniomaha.conf \
|
python2.6 devserver.py --factory_config miniomaha.conf \
|
||||||
--validate_factory_config
|
--validate_factory_config
|
||||||
To run the server:
|
To run the server:
|
||||||
python2.6 devserver.py --factory_config miniomaha.conf"
|
python2.6 devserver.py --factory_config miniomaha.conf"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
if [ -n "$FLAGS_diskimg" ]; then
|
||||||
|
generate_img
|
||||||
|
else
|
||||||
|
generate_omaha
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user