From 7c982f739842fa7fceeda40448ec7a7c3056c0a1 Mon Sep 17 00:00:00 2001 From: Nick Sanders Date: Wed, 19 May 2010 22:17:08 -0700 Subject: [PATCH] Update factory installer, factory test * Fix build breaks * Update to work with EFI bios Review URL: http://codereview.chromium.org/2132008 --- image_to_usb.sh | 62 +-------- make_factory_package.sh | 155 +++++++++++++++++++++ mod_for_factory_scripts/200patchInitScript | 27 +--- mod_for_factory_scripts/400configAutotest | 2 +- mod_for_factory_scripts/500copyQualDb | 2 +- mod_image_for_test.sh | 51 ++++++- 6 files changed, 205 insertions(+), 94 deletions(-) create mode 100755 make_factory_package.sh diff --git a/image_to_usb.sh b/image_to_usb.sh index d1ac0b28a2..cd11df764c 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -26,8 +26,6 @@ DEFINE_boolean factory_install ${FLAGS_FALSE} \ "Whether to generate a factory install shim." DEFINE_boolean factory ${FLAGS_FALSE} \ "Whether to generate a factory runin image. Implies aututest and test" -DEFINE_boolean install_autotest ${FLAGS_FALSE} \ - "Whether to install autotest to the stateful partition." DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ "Copy the kernel to the fourth partition." DEFINE_boolean test_image "${FLAGS_FALSE}" \ @@ -48,8 +46,7 @@ fi # Require autotest for manucaturing image. if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then - echo "Factory image requires --install_autotest and --test_image, setting." - FLAGS_install_autotest=${FLAGS_TRUE} + echo "Factory image requires --test_image, setting." FLAGS_test_image=${FLAGS_TRUE} fi @@ -60,19 +57,6 @@ if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then fi -# Inside the chroot, so output to usb.img in the same dir as the other -# Script can be run either inside or outside the chroot. -if [ ${INSIDE_CHROOT} -eq 1 ] -then - SYSROOT="${FLAGS_build_root}/${FLAGS_board}" -else - SYSROOT="${DEFAULT_CHROOT_DIR}${FLAGS_build_root}/${FLAGS_board}" - echo "Caching sudo authentication" - sudo -v - echo "Done" -fi -AUTOTEST_SRC="${SYSROOT}/usr/local/autotest" - # Die on any errors. set -e @@ -119,50 +103,6 @@ function do_cleanup { fi } -if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then - echo "Detecting autotest at ${AUTOTEST_SRC}" - if [ -d ${AUTOTEST_SRC} ] - then - # Figure out how to loop mount the stateful partition. It's always - # partition 1 on the disk image. - offset=$(partoffset "${SRC_IMAGE}" 1) - - stateful_loop_dev=$(sudo losetup -f) - if [ -z "${stateful_loop_dev}" ] - then - echo "No free loop device. Free up a loop device or reboot. exiting." - exit 1 - fi - STATEFUL_LOOP_DEV=$stateful_loop_dev - trap do_cleanup INT TERM EXIT - - echo "Mounting ${STATEFUL_DIR} loopback" - sudo losetup -o $(( $offset * 512 )) "${stateful_loop_dev}" "${SRC_IMAGE}" - sudo mount "${stateful_loop_dev}" "${STATEFUL_DIR}" - stateful_root="${STATEFUL_DIR}/dev_image" - - echo "Install autotest into stateful partition..." - autotest_client="/home/autotest-client" - sudo mkdir -p "${stateful_root}${autotest_client}" - sudo ln -sf /mnt/stateful_partition/dev_image${autotest_client} \ - ${stateful_root}/autotest - - sudo cp -fpru ${AUTOTEST_SRC}/client/* \ - "${stateful_root}/${autotest_client}" - sudo chmod 755 "${stateful_root}/${autotest_client}" - sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" - - sudo umount ${STATEFUL_DIR} - sudo losetup -d "${stateful_loop_dev}" - trap - INT TERM EXIT - rmdir "${STATEFUL_DIR}" - else - echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." - echo "Please call build_autotest.sh inside chroot first." - exit -1 - fi -fi - # If we're asked to modify the image for test, then let's make a copy and # modify that instead. diff --git a/make_factory_package.sh b/make_factory_package.sh new file mode 100755 index 0000000000..005fd255c8 --- /dev/null +++ b/make_factory_package.sh @@ -0,0 +1,155 @@ +#!/bin/bash + +# Copyright (c) 2009 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. + +# Script to generate a factory install partition set and miniomaha.conf +# file from a release image and a factory image. This creates a server +# configuration that can be installed using a factory install shim. +# +# miniomaha lives in src/platform/dev/ and miniomaha partition sets live +# in src/platform/dev/static. + +# Load common constants. This should be the first executable line. +# The path to common.sh should be relative to your script's location. +. "$(dirname "$0")/common.sh" + +# Load functions and constants for chromeos-install +. "$(dirname "$0")/chromeos-common.sh" + +get_default_board + +# Flags +DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" +DEFINE_string factory "" \ + "Directory and file containing factory image: /path/chromiumos_test_image.bin" +DEFINE_string release "" \ + "Directory and file containing release image: /path/chromiumos_image.bin" + + +# Parse command line +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + +if [ ! -f "${FLAGS_release}" ] ; then + echo "Cannot find image file ${FLAGS_release}" + exit 1 +fi + +if [ ! -f "${FLAGS_factory}" ] ; then + echo "Cannot find image file ${FLAGS_factory}" + exit 1 +fi + +# Convert args to paths. Need eval to un-quote the string so that shell +# chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. +OMAHA_DIR=${SRC_ROOT}/platform/dev +OMAHA_DATA_DIR=${OMAHA_DIR}/static/ + +if [ ${INSIDE_CHROOT} -eq 0 ]; then + echo "Caching sudo authentication" + sudo -v + echo "Done" +fi + +# Use this image as the source image to copy +RELEASE_DIR=`dirname ${FLAGS_release}` +FACTORY_DIR=`dirname ${FLAGS_factory}` +RELEASE_IMAGE=`basename ${FLAGS_release}` +FACTORY_IMAGE=`basename ${FLAGS_factory}` + + +prepare_omaha() { + sudo rm -rf ${OMAHA_DATA_DIR}/rootfs-test.gz + sudo rm -rf ${OMAHA_DATA_DIR}/rootfs-release.gz + rm -rf ${OMAHA_DATA_DIR}/efi.gz + rm -rf ${OMAHA_DATA_DIR}/oem.gz + rm -rf ${OMAHA_DATA_DIR}/state.gz + rm -rf ${OMAHA_DIR}/miniomaha.conf +} + +prepare_dir() { + sudo rm -rf rootfs-test.gz + sudo rm -rf rootfs-release.gz + rm -rf efi.gz + rm -rf oem.gz + rm -rf state.gz +} + + +# Clean up stale config and data files. +prepare_omaha + +# Get the release image. +pushd ${RELEASE_DIR} +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_DIR}/miniomaha.conf" + +prepare_dir + +sudo ./unpack_partitions.sh ${RELEASE_IMAGE} &> /dev/null +release_hash=`sudo ${SCRIPTS_DIR}/mk_memento_images.sh part_2 part_3 \ + | grep hash | awk '{print $4}'` +sudo chmod a+rw update.gz +mv update.gz rootfs-release.gz +mv rootfs-release.gz ${OMAHA_DATA_DIR} +echo "release: ${release_hash}" + +cat part_8 | gzip -9 > oem.gz +oem_hash=`cat oem.gz | openssl sha1 -binary | openssl base64` +mv oem.gz ${OMAHA_DATA_DIR} +echo "oem: ${oem_hash}" + +cat part_12 | gzip -9 > efi.gz +efi_hash=`cat efi.gz | openssl sha1 -binary | openssl base64` +mv efi.gz ${OMAHA_DATA_DIR} +echo "efi: ${efi_hash}" + +popd + +# Go to retrieve the factory test image. +pushd ${FACTORY_DIR} +prepare_dir + + +sudo ./unpack_partitions.sh ${FACTORY_IMAGE} &> /dev/null +test_hash=`sudo ${SCRIPTS_DIR}//mk_memento_images.sh part_2 part_3 \ + | grep hash | awk '{print $4}'` +sudo chmod a+rw update.gz +mv update.gz rootfs-test.gz +mv rootfs-test.gz ${OMAHA_DATA_DIR} +echo "test: ${test_hash}" + +cat part_1 | gzip -9 > state.gz +state_hash=`cat state.gz | openssl sha1 -binary | openssl base64` +mv state.gz ${OMAHA_DATA_DIR} +echo "state: ${state_hash}" + +echo " +config = [ + { + 'qual_ids': set([\"${FLAGS_board}\"]), + 'factory_image': 'rootfs-test.gz', + 'factory_checksum': '${test_hash}', + 'release_image': 'rootfs-release.gz', + 'release_checksum': '${release_hash}', + 'oempartitionimg_image': 'oem.gz', + 'oempartitionimg_checksum': '${oem_hash}', + 'efipartitionimg_image': 'efi.gz', + 'efipartitionimg_checksum': '${efi_hash}', + 'stateimg_image': 'state.gz', + 'stateimg_checksum': '${state_hash}' + }, +] +" > ${OMAHA_DIR}/miniomaha.conf + +popd +echo "The miniomaha server lives in src/platform/dev" +echo "to validate the configutarion, run:" +echo " python2.6 devserver.py --factory_config miniomaha.conf \ +--validate_factory_config" +echo "To run the server:" +echo " python2.6 devserver.py --factory_config miniomaha.conf" diff --git a/mod_for_factory_scripts/200patchInitScript b/mod_for_factory_scripts/200patchInitScript index 17f0598ea8..cd877e56a5 100755 --- a/mod_for_factory_scripts/200patchInitScript +++ b/mod_for_factory_scripts/200patchInitScript @@ -7,6 +7,7 @@ echo "Applying patch to init scripts." pushd ${ROOT_FS_DIR} +touch ${ROOT_FS_DIR}/root/.factory_test patch -d ${ROOT_FS_DIR} -Np1 < /dev/tty1 end script EOF -patch -d ${ROOT_FS_DIR} -Np1 < /sys/devices/virtual/graphics/fbcon/cursor_blink -+# echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink - - # Since we defer udev until later in the boot process, we pre-populate /dev - # with the set of devices needed for X and other early services to run. - cp -a -f /lib/chromiumos/devices/* /dev - --# Splash screen! --if [ -x /usr/bin/ply-image ] --then -- /usr/bin/ply-image /usr/share/chromeos-assets/images/login_splash.png & --fi -- - mount -n -t tmpfs tmp /tmp - mount -n -t tmpfs -onosuid,nodev shmfs /dev/shm - mount -n -t devpts -onoexec,nosuid,gid=5,mode=0620 devpts /dev/pts -EOF - popd diff --git a/mod_for_factory_scripts/400configAutotest b/mod_for_factory_scripts/400configAutotest index 5eb3b86a40..b702bc0741 100755 --- a/mod_for_factory_scripts/400configAutotest +++ b/mod_for_factory_scripts/400configAutotest @@ -6,7 +6,7 @@ echo "Create global_config.ini in autotest directory." -GLOBAL_CONFIG="${STATEFUL_DIR}/home/autotest-client/global_config.ini" +GLOBAL_CONFIG="${ROOT_FS_DIR}/usr/local/autotest/global_config.ini" if [ -f "${GLOBAL_CONFIG}" ]; then echo -e "File ${GLOBAL_CONFIG} already exists." diff --git a/mod_for_factory_scripts/500copyQualDb b/mod_for_factory_scripts/500copyQualDb index b75932b2ac..cf734e0f59 100755 --- a/mod_for_factory_scripts/500copyQualDb +++ b/mod_for_factory_scripts/500copyQualDb @@ -11,7 +11,7 @@ # QUALDB can be a full path of the file, or a specified directory # /tmp/run_remote_tests.XXXX, or a default wildcard one /tmp/run_remote_tests.*. -COMPONENTS_FILE="${STATEFUL_DIR}/usr/local/autotest/site_tests/"\ +COMPONENTS_FILE="${ROOT_FS_DIR}/usr/local/autotest/site_tests/"\ "hardware_Components/qualified_components" # If QUALDB is a default wildcard directory, try to use the most recent one. diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 53907eb6b6..b106c05beb 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -20,17 +20,20 @@ get_default_board DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b DEFINE_boolean factory $FLAGS_FALSE \ - "Modify the image for manufacturing testing" f + "Modify the image for manufacturing testing" f DEFINE_boolean factory_install $FLAGS_FALSE \ "Modify the image for factory install shim" DEFINE_string image "" "Location of the rootfs raw image file" i DEFINE_boolean installmask $FLAGS_TRUE \ - "Use INSTALL_MASK to shrink the resulting image." m + "Use INSTALL_MASK to shrink the resulting image." m DEFINE_integer jobs -1 \ - "How many packages to build in parallel at maximum." j + "How many packages to build in parallel at maximum." j DEFINE_string qualdb "/tmp/run_remote_tests.*" \ "Location of qualified component file" d DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y +DEFINE_string build_root "/build" \ + "The root location for board sysroots." + # Parse command line FLAGS "$@" || exit 1 @@ -91,6 +94,35 @@ emerge_chromeos_test() { --usepkgonly chromeos-test $EMERGE_JOBS } + +install_autotest() { + SYSROOT="${FLAGS_build_root}/${FLAGS_board}" + AUTOTEST_SRC="${SYSROOT}/usr/local/autotest" + stateful_root="${ROOT_FS_DIR}/usr/local" + autotest_client="/autotest" + + echo "Install autotest into stateful partition from $AUTOTEST_SRC" + + sudo mkdir -p "${stateful_root}${autotest_client}" + sudo mkdir -p "/tmp/autotest" + sudo rm -rf /tmp/autotest/* + + sudo cp -fpru ${AUTOTEST_SRC}/client/* \ + "/tmp/autotest" + # Remove outrageously large tests. + # TODO(nsanders): is there a better way to do this? + sudo rm -rf /tmp/autotest/deps/realtimecomm_playground + sudo rm -rf /tmp/autotest/tests/ltp + sudo rm -rf /tmp/autotest/site_tests/graphics_O3DSelenium + sudo rm -rf /tmp/autotest/realtimecomm_GTalk* + sudo rm -rf /tmp/autotest/site_tests/platform_StackProtector + + sudo cp -fpru /tmp/autotest/* \ + "${stateful_root}/${autotest_client}" + sudo chmod 755 "${stateful_root}/${autotest_client}" + sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" +} + # main process begins here. # Make sure this is really what the user wants, before nuking the device @@ -125,7 +157,7 @@ if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then # Run factory setup script to modify the image. sudo emerge-${FLAGS_board} --root=$ROOT_FS_DIR --usepkgonly \ - --root-deps=rdeps chromeos-factoryinstall + --root-deps=rdeps --nodeps chromeos-factoryinstall # Set factory server if necessary. if [ "${FACTORY_SERVER}" != "" ]; then @@ -143,14 +175,23 @@ else "${MOD_TEST_ROOT}/test_setup.sh" if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then + install_autotest + MOD_FACTORY_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts" # Run factory setup script to modify the image sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ - STATEFUL_DIR="${STATEFUL_DIR}/dev_image" QUALDB="${FLAGS_qualdb}" \ + QUALDB="${FLAGS_qualdb}" \ "${MOD_FACTORY_ROOT}/factory_setup.sh" fi fi +# Let's have a look at the image just in case.. +if [ "${VERIFY}" = "true" ]; then + pushd "${ROOT_FS_DIR}" + bash + popd +fi + cleanup trap - EXIT