chore(*): remove unused scripts

bin/cros_update_image.sh
  cros_show_stacks
  image_to_usb.sh
  make_netboot.sh
  mod_image_for_recovery.sh
  update_kernel.sh
This commit is contained in:
Brandon Philips 2013-07-26 08:40:08 -07:00
parent 7ed28ac286
commit 0ece58228f
6 changed files with 0 additions and 1173 deletions

View File

@ -1,75 +0,0 @@
#!/bin/bash
# Copyright (c) 2012 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.
# Usage:
# update_image.sh [image_to_update] [packages...]
usage()
{
cat <<EOF
usage:
update_image.sh [image_to_update] [packages...]
EOF
}
if [[ $# < 2 ]]; then
echo "Not enough arguments supplied."
usage
exit 1
fi
if [[ -f /home/${USER}/trunk/src/scripts/.default_board ]]; then
BOARD=$( cat /home/${USER}/trunk/src/scripts/.default_board )
else
BOARD=st1q
fi
IMAGE=$( readlink -f ${1} )
IMAGE_DIR=$( dirname "${IMAGE}" )
shift
PKGS=$@
if [[ -z "${IMAGE}" || ! -f ${IMAGE} ]]; then
echo "Missing required argument 'image_to_update'"
usage
exit 1
fi
cd ${IMAGE_DIR}
if ! [[ -x ./unpack_partitions.sh && -x ./pack_partitions.sh ]]; then
echo "Could not find image manipulation scripts."
exit 1
fi
./unpack_partitions.sh ${IMAGE}
mkdir -p ./rootfs
mkdir -p ./stateful_part
mkdir -p ./orig_partitions
rm -rf ./orig_partitions/*
cp ./part_* ./orig_partitions
sudo mount -o loop part_3 rootfs
sudo mount -o loop part_1 stateful_part
sudo mount --bind stateful_part/dev_image rootfs/usr/local
sudo mount --bind stateful_part/var_overlay rootfs/var
emerge-${BOARD} --root="./rootfs" \
--root-deps=rdeps --nodeps --usepkgonly ${PKGS}
#if the kernel is one of the packages that got updated
#we need to update the kernel partition as well.
if [[ ${PKGS/kernel/} != ${PKGS} ]]; then
rm -rf part_2
sudo dd if="/dev/zero" of=part_2 bs=512 count=8192
sudo dd if="./rootfs/boot/vmlinuz" of=part_2 bs=512 count=8192 conv=notrunc
fi
safe_umount rootfs/usr/local
safe_umount rootfs/var
safe_umount rootfs
safe_umount stateful_part
./pack_partitions.sh ${IMAGE}
cd -

View File

@ -1,168 +0,0 @@
#!/bin/bash
# Copyright (c) 2010 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 stackdumps from a machine or dmp files.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
. "${SCRIPT_ROOT}/remote_access.sh" || exit 1
assert_inside_chroot
MINIDUMP_DUMP=/usr/bin/minidump_dump
MINIDUMP_STACKWALK=/usr/bin/minidump_stackwalk
USING_REMOTE=0
DEFINE_string board "${DEFAULT_BOARD}" \
"The board for which you are building autotest"
DEFINE_string breakpad_root "" \
"Path to root of breakpad symbols if pre-existing symbols should be used"
DEFINE_boolean clean ${FLAGS_FALSE} \
"Remove crash reports from remote system after showing stacks"
usage() {
echo "usage: $(basename $0) [--remote=<IP>] [dump...]"
echo "Specify either a remote IP of a ChromeOS device to gather "
echo "all crash reports from, or list crash reports"
exit 1
}
# Clean up remote access and temp files.
cleanup() {
[ ${USING_REMOTE} -eq 1 ] && cleanup_remote_access
rm -rf "${TMP}"
}
# Echoes kind of crash (minidump or kcrash).
get_kind() {
local kind="${1##*.}"
if [ "${kind}" = "dmp" ]; then
kind="minidump"
fi
echo ${kind}
}
# Generate symbols for the given module list.
# Args:
# $1 - file with a "module" per line. A module is the full target's
# path to a DSO or executable that was loaded during a crash.
generate_symbols() {
local modules_file="$1"
local modules=""
local any_missing=0
local module_count=0
for module in $(sort -u "${modules_file}"); do
local text_file="/build/${FLAGS_board}/${module}"
local debug_file="/build/${FLAGS_board}/usr/lib/debug/${module}.debug"
if [ -f "${text_file}" ] && [ -f "${debug_file}" ]; then
modules="${modules} ${text_file}"
module_count=$((module_count + 1))
else
if [ ${any_missing} -eq 0 ]; then
warn "Some modules are missing debug information:"
any_missing=1
fi
warn "* ${text_file}"
fi
done
if [ ${module_count} -gt 0 ]; then
info "Generating breakpad symbols for ${module_count} modules"
${SCRIPTS_DIR}/cros_generate_breakpad_symbols --board=${FLAGS_board} \
${modules}
fi
}
main() {
FLAGS "$@" || usage
local basename=$(basename "$0")
TMP=$(mktemp -d /tmp/${basename}.XXXX)
trap cleanup EXIT INT TERM
if [ -n "${FLAGS_remote}" ]; then
remote_access_init
USING_REMOTE=1
learn_board
local crashes=""
# File spec of all interesting crashes. /home/chronos... is
# listed separately from /mnt/stateful_partition/home/chronos/...
# because the former may be a mount point for the cryptohome.
# This allows us to get crashes from the currently logged in
# user as well as from non-logged in users at once. We remove
# duplicate crashes (in case cryptohome is not mounted) below.
local remote_crash_dirs=" \
/var/spool/crash \
/home/chronos/user/crash \
/mnt/stateful_partition/home/chronos/user/crash"
local remote_crash_patterns=""
for remote_crash_dir in ${remote_crash_dirs}; do
remote_crash_patterns="${remote_crash_patterns} \
${remote_crash_dir}/*.{dmp,kcrash}"
done
remote_sh "ls -1 ${remote_crash_patterns}" 2> /dev/null
local crashes=${REMOTE_OUT}
# Remove duplicates.
local unique_crashes=""
local crash_count=0
for crash in ${crashes}; do
local crash_short=$(basename ${crash})
if echo "${unique_crashes}" | grep -v -q "${crash_short}"; then
unique_crashes="${unique_crashes} ${crash}"
crash_count=$((crash_count + 1))
fi
done
if [ ${crash_count} -eq 0 ]; then
info "No crashes found on device."
exit 0
fi
info "Copying back ${crash_count} crashes."
crashes="${unique_crashes}"
local filesfrom="${TMP}/filesfrom"
FLAGS_ARGV=""
for crash in ${crashes}; do
echo "${crash}" >> "${filesfrom}"
FLAGS_ARGV="${FLAGS_ARGV} '${TMP}/$(basename ${crash})'"
done
remote_rsync_from "${filesfrom}" "${TMP}"
if [ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]; then
remote_sh "rm -rf ${remote_crash_dirs}"
fi
else
[ -n "${FLAGS_ARGV}" ] || usage
[ -n "${FLAGS_board}" ] || die_notrace "--board is required."
fi
local modules_file="${TMP}/modules"
for dump in ${FLAGS_ARGV}; do
dump=$(remove_quotes "${dump}")
if [ $(get_kind "${dump}") == "minidump" ]; then
# Find all DSOs and executables listed in lines like:
# (code_file) = "/usr/lib/mylib.so"
${MINIDUMP_DUMP} "${dump}" 2>/dev/null \
| grep code_file \
| sed 's/.*= "\(.*\)"/\1/' \
>> "${modules_file}"
fi
done
if [ -z "${FLAGS_breakpad_root}" ]; then
generate_symbols "${modules_file}"
FLAGS_breakpad_root=/build/${FLAGS_board}/usr/lib/debug/breakpad
fi
for dump in ${FLAGS_ARGV}; do
dump=$(remove_quotes "${dump}")
if [ $(get_kind "${dump}") = "minidump" ]; then
info "Dumping stack for $(basename ${dump}) with ${FLAGS_breakpad_root}:"
${MINIDUMP_STACKWALK} "${dump}" "${FLAGS_breakpad_root}" 2> /dev/null
else
info "Dumping kcrash $(basename ${dump}):"
cat "${dump}"
fi
echo ""
done
}
main "$@"

View File

@ -1,379 +0,0 @@
#!/bin/bash
# Copyright (c) 2010 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 convert the output of build_image.sh to a usb or SD image.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
# Load functions and constants for chromeos-install
[ -f /usr/lib/installer/chromeos-common.sh ] && \
INSTALLER_ROOT=/usr/lib/installer || \
INSTALLER_ROOT=$(dirname "$(readlink -f "$0")")
. "${INSTALLER_ROOT}/chromeos-common.sh" || exit 1
# In case chromeos-common.sh doesn't support MMC yet
declare -F list_mmc_disks >/dev/null || list_mmc_disks() { true; }
# Flags
DEFINE_string board "${DEFAULT_BOARD}" \
"board for which the image was built"
DEFINE_string from "" \
"directory containing the image, or image full pathname (empty: latest found)"
DEFINE_string to "" \
"write to a specific disk or image file (empty: auto-detect)"
DEFINE_string to_product "" \
"find target device with product name matching a string (accepts wildcards)"
DEFINE_boolean yes ${FLAGS_FALSE} \
"don't ask questions, just write to the target device specified by --to" \
y
DEFINE_boolean force_copy ${FLAGS_FALSE} \
"always rebuild test image"
DEFINE_boolean force_non_usb ${FLAGS_FALSE} \
"force writing even if target device doesn't appear to be a USB/MMC disk"
DEFINE_boolean factory_install ${FLAGS_FALSE} \
"Install the factory install shim"
DEFINE_boolean factory ${FLAGS_FALSE} \
"Install a factory test image"
DEFINE_boolean copy_kernel ${FLAGS_FALSE} \
"copy the kernel to the fourth partition"
DEFINE_boolean test_image "${FLAGS_FALSE}" \
"Install a test image"
DEFINE_string image_name "" \
"image base name (empty: auto-detect)" \
i
DEFINE_boolean install ${FLAGS_FALSE} \
"install to the USB/MMC device"
DEFINE_string arch "" \
"architecture for which the image was built (derived from board if empty)"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ $# -gt 0 ]; then
die_notrace "Arguments aren't currently supported in image_to_usb."
fi
# Generates a descriptive string of a removable device. Includes the
# manufacturer (if non-empty), product and a human-readable size.
get_disk_string() {
local disk="${1##*/}"
local manufacturer_string=$(get_disk_info $disk manufacturer)
local product_string=$(get_disk_info $disk product)
local disk_size=$(sudo fdisk -l /dev/$disk 2>/dev/null | grep Disk |
head -n 1 | cut -d' ' -f3-4 | sed 's/,//g')
# I've seen one case where manufacturer only contains spaces, hence the test.
if [ -n "${manufacturer_string// }" ]; then
echo -n "${manufacturer_string} "
fi
echo "${product_string}, ${disk_size}"
}
# Prompt for user confirmation. Default is no, which will gracefully terminate
# the script.
are_you_sure() {
local sure
read -p "Are you sure (y/N)? " sure
if [ "${sure}" != "y" ]; then
echo "Ok, better safe than sorry."
exit
fi
}
# Prohibit mutually exclusive factory/install flags.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} -a \
${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
die_notrace "Factory test image is incompatible with factory install shim"
fi
# Allow --from /foo/file.bin
if [ -f "${FLAGS_from}" ]; then
pathname=$(dirname "${FLAGS_from}")
filename=$(basename "${FLAGS_from}")
FLAGS_image_name="${filename}"
FLAGS_from="${pathname}"
fi
# Require autotest for manucaturing image.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
echo "Factory image requires --test_image, setting."
FLAGS_test_image=${FLAGS_TRUE}
fi
# Require test for for factory install shim.
if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
echo "Factory install shim requires --test_image, setting."
FLAGS_test_image=${FLAGS_TRUE}
fi
# Die on any errors.
switch_to_strict_mode
# No board, no default and no image set then we can't find the image
if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then
setup_board_warning
exit 1
fi
# No board set during install
if [ -z "${FLAGS_board}" ] && [ ${FLAGS_install} -eq ${FLAGS_TRUE} ]; then
setup_board_warning
exit 1
fi
# Install can only be done from inside the chroot.
if [ ${FLAGS_install} -eq ${FLAGS_TRUE} ] && [ ${INSIDE_CHROOT} -ne 1 ]; then
die_notrace "--install can only be used inside the chroot"
fi
# We have a board name but no image set. Use image at default location
if [ -z "${FLAGS_from}" ]; then
FLAGS_from="$($SCRIPT_ROOT/get_latest_image.sh --board=${FLAGS_board})"
fi
if [ ! -d "${FLAGS_from}" ] ; then
die_notrace "Cannot find image directory ${FLAGS_from}"
fi
# TODO(garnold) This code reinstates the previous default value for --to, which
# some users relied upon to trigger target device auto-detection. It should be
# removed once we're sure that all users have adapted to simply not specifying
# --to. The instructions emitted by build_image were changed accordingly.
if [ "${FLAGS_to}" == "/dev/sdX" ]; then
warn "the use of --to=/dev/sdX is deprecated, just omit --to instead"
FLAGS_to=""
fi
# No target provided, attempt autodetection.
if [ -z "${FLAGS_to}" ]; then
if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then
die_notrace "For your own safety, --yes can only be used with --to"
fi
if [ -z "${FLAGS_to_product}" ]; then
echo "No target device specified, autodetecting..."
else
echo "Looking for target devices matching '${FLAGS_to_product}'..."
fi
# Obtain list of USB and MMC device names.
disk_list=( $(list_usb_disks) $(list_mmc_disks) )
# Build list of descriptive strings for detected devices.
unset disk_string_list
for disk in "${disk_list[@]}"; do
# If --to_product was used, match against provided string.
# Note: we intentionally use [[ ... != ... ]] to allow pattern matching on
# the product string.
if [ -n "${FLAGS_to_product}" ] &&
[[ "$(get_disk_info ${disk} product)" != ${FLAGS_to_product} ]]; then
continue
fi
disk_string=$(get_disk_string /dev/${disk})
disk_string_list=( "${disk_string_list[@]}"
"/dev/${disk}: ${disk_string}" )
done
# If no (matching) devices found, quit.
if (( ! ${#disk_string_list[*]} )); then
if [ -z "${FLAGS_to_product}" ]; then
die_notrace "No USB/MMC devices could be detected"
else
die_notrace "No matching USB/MMC devices could be detected"
fi
fi
# Prompt for selection, or autoselect if only one device was found.
if (( ${#disk_string_list[*]} > 1 )); then
PS3="Select a target device: "
select disk_string in "${disk_string_list[@]}"; do
if [ -z "${disk_string}" ]; then
die_notrace "Invalid selection"
fi
break
done
else
disk_string="${disk_string_list}"
echo "Found ${disk_string}"
fi
FLAGS_to="${disk_string%%:*}"
elif [ -n "${FLAGS_to_product}" ]; then
die_notrace "Cannot specify both --to and --to_product"
fi
# Guess ARCH if it's unset
if [ "${FLAGS_arch}" = "" ]; then
if echo "${FLAGS_board}" | grep -qs "x86"; then
FLAGS_arch=INTEL
else
FLAGS_arch=ARM
fi
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.
FLAGS_from=`eval readlink -f ${FLAGS_from}`
FLAGS_to=`eval readlink -f ${FLAGS_to}`
# Check whether target device is USB/MMC, and obtain a string descriptor for it.
unset disk_string
if [ -b "${FLAGS_to}" -o -c "${FLAGS_to}" ]; then
if list_usb_disks | grep -q '^'${FLAGS_to##*/}'$' ||
list_mmc_disks | grep -q '^'${FLAGS_to##*/}'$'; then
disk_string=$(get_disk_string ${FLAGS_to})
elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then
# Safeguard against writing to a real non-USB disk or non-SD disk
die_notrace "${FLAGS_to} does not appear to be a USB/MMC disk," \
"use --force_non_usb to override"
fi
fi
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
mkdir -p "${STATEFUL_DIR}"
# Figure out which image to use.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
SRC_IMAGE="${FLAGS_from}/${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
elif [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]; then
SRC_IMAGE="${FLAGS_from}/${CHROMEOS_TEST_IMAGE_NAME}"
else
# Auto-detect and select an image name if none provided.
if [ -z "${FLAGS_image_name}" ]; then
echo "No image name specified, autodetecting..."
# Resolve the default image full path (see though symlinks), make sure
# it's present.
default_image_path=$(readlink -f "${FLAGS_from}/${CHROMEOS_IMAGE_NAME}")
if [ ! -f "${default_image_path}" ]; then
default_image_path="MISSING"
fi
# The list of candidate image names.
image_candidate_list=( "${CHROMEOS_DEVELOPER_IMAGE_NAME}"
"${CHROMEOS_RECOVERY_IMAGE_NAME}"
"${CHROMEOS_TEST_IMAGE_NAME}"
"${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
"${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}" )
# Obtain list of available images that can be used.
unset image_list
is_got_default=0
for image_candidate in "${image_candidate_list[@]}"; do
image_candidate_path="${FLAGS_from}/${image_candidate}"
if [ -f "${image_candidate_path}" ]; then
if [ "${image_candidate_path}" == "${default_image_path}" ]; then
# This is the default image, list it first.
image_list=( "${image_candidate}" "${image_list[@]}" )
is_got_default=1
else
image_list=( "${image_list[@]}" "${image_candidate}" )
fi
fi
done
# Figure out what to do with the resulting list of images.
declare -i num_images=${#image_list[*]}
if (( num_images == 0 )); then
die_notrace "No candidate images could be detected"
elif (( num_images == 1 )) && [ ${is_got_default} == 1 ]; then
# Found a single image that is the default image, just select it.
image="${image_list[0]}"
echo "Found default image ${image}"
else
# Select one from a list of available images; default to the first.
PS3="Select an image [1]: "
choose image "${image_list[0]}" "ERROR" "${image_list[@]}"
if [ "${image}" == "ERROR" ]; then
die_notrace "Invalid selection"
fi
fi
FLAGS_image_name="${image}"
fi
# Use the selected image.
SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}"
fi
# Make sure that the selected image exists.
if [ ! -f "${SRC_IMAGE}" ]; then
die_notrace "Image not found: ${SRC_IMAGE}"
fi
# Let's do it.
if [ -b "${FLAGS_to}" -o -c "${FLAGS_to}" ]; then
# Output to a block device (i.e., a real USB key / SD card), so need sudo dd
if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then
echo "Copying image ${SRC_IMAGE} to device ${FLAGS_to}..."
else
echo "Installing image ${SRC_IMAGE} to device ${FLAGS_to}..."
fi
# Warn if it looks like they supplied a partition as the destination.
if echo "${FLAGS_to}" | grep -q '[0-9]$'; then
drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//')
if [ -b "${drive}" ]; then
warn "${FLAGS_to} looks like a partition; did you mean ${drive}?"
fi
fi
# Make sure this is really what the user wants, before nuking the device.
if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ]; then
warning_str="this will erase all data on ${FLAGS_to}"
if [ -n "${disk_string}" ]; then
warning_str="${warning_str}: ${disk_string}"
else
warning_str="${warning_str}, which does not appear to be a USB/MMC disk!"
fi
warn "${warning_str}"
are_you_sure
fi
mount_list=$(mount | grep ^"${FLAGS_to}" | awk '{print $1}')
if [ -n "${mount_list}" ]; then
echo "Attempting to unmount any mounts on the target device..."
for i in ${mount_list}; do
if safe_umount "$i" 2>&1 >/dev/null | grep "not found"; then
die_notrace "$i needs to be unmounted outside the chroot"
fi
done
sleep 3
fi
if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then
sudo $(pv_cat_cmd) "${SRC_IMAGE}" |
sudo dd of="${FLAGS_to}" bs=4M oflag=sync status=noxfer
sync
else
"/build/${FLAGS_board}/usr/sbin/chromeos-install" \
--yes \
--skip_src_removable \
--skip_dst_removable \
--arch="${FLAGS_arch}" \
--payload_image="${SRC_IMAGE}" \
--dst="${FLAGS_to}"
fi
elif [[ "${FLAGS_to}" == /dev/* ]]; then
# Did the user attempt to write to a non-existent block device?
die_notrace "Target device ${FLAGS_to} does not exist"
else
# Output to a file, so just make a copy.
if [ "${SRC_IMAGE}" != "${FLAGS_to}" ]; then
echo "Copying image ${SRC_IMAGE} to file ${FLAGS_to}..."
$(pv_cat_cmd) "${SRC_IMAGE}" >"${FLAGS_to}"
fi
info "To copy onto a USB/MMC drive /dev/sdX, use: "
info " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync"
fi
echo "Done."

View File

@ -1,154 +0,0 @@
#!/bin/bash
# Copyright (c) 2011 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.
# make_netboot.sh --board=[board]
#
# This script validates that the current latest image is an install shim,
# and generates a netboot image from it. This pulls the u-boot kernel
# image bundle (uimg), the legacy firmware for netbooting, and the install
# shim kernel image, bundled as a uboot gz/uimg, and places them in a
# "netboot" subfolder.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/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 "" "Path to the image to use"
# 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
# build_packages artifact output.
SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
# build_image artifact output.
IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images"
if [ -n "${FLAGS_image}" ]; then
cd $(dirname "${FLAGS_image}")
INSTALL_SHIM=$(basename "${FLAGS_image}")
else
cd ${IMAGES_DIR}/${FLAGS_board}/latest
# Canonical install shim name.
INSTALL_SHIM="factory_install_shim.bin"
fi
if [ ! -f "${INSTALL_SHIM}" ]; then
echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!"
exit 1
fi
# Generate staging dir for netboot files.
sudo rm -rf netboot
mkdir -p netboot
# Get netboot firmware.
# TODO(nsanders): Set default IP here when userspace
# env modification is available.
# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
# When ARM generic goes away, delete the test.
if ls "${SYSROOT}"/firmware/nv_image-*.bin >/dev/null 2>&1; then
echo "Copying netboot firmware nv_image-*.bin"
cp -v "${SYSROOT}"/firmware/nv_image-*.bin "netboot"
else
echo "Skipping netboot firmware: " \
"${SYSROOT}/firmware/nv_image-*.bin not present?"
fi
# Prepare to mount rootfs.
umount_loop() {
safe_umount r || true
safe_umount s || true
false
}
echo "Unpack factory install shim partitions"
./unpack_partitions.sh "${INSTALL_SHIM}"
# Genrate clean mountpoints.
sudo rm -rf r s
mkdir -p r s
# Clean ROified filesystem headers, and mount.
trap "umount_loop" EXIT
enable_rw_mount part_3
sudo mount -o loop part_3 r
sudo mount -o loop part_1 s
echo "Mount install shim rootfs (partition 3)"
if [ "${ARCH}" = "arm" ]; then
export MKIMAGE_ARCH="arm"
else
export MKIMAGE_ARCH="x86" # including amd64
fi
# Get netboot kernel.
echo "Building kernel"
# Create temporary emerge root
temp_build_path="$(mktemp -d bk_XXXXXXXX)"
if ! [ -d "${temp_build_path}" ]; then
echo "Failed to create temporary directory."
exit 1
fi
# Emerge network boot kernel
# We don't want to build whole install shim everytime we run this script,
# and thus we only build kernel here. If this script is run against install
# shim with different kernel version, this might not work. But as we don't
# upgrade kernel so often, this is probably fine.
export USE='vfat blkdevram fbconsole i2cdev'
export EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
emerge_custom_kernel ${temp_build_path}
# Generate kernel uImage
echo "Generating netboot kernel vmlinux.uimg"
if [ "${ARCH}" = "arm" ]; then
cp "${temp_build_path}"/boot/vmlinux.uimg netboot/
else
# U-boot put kernel image at 0x100000. We load it at 0x3000000 because
# 0x3000000 is safe enough not to overlap with image at 0x100000.
mkimage -A "${MKIMAGE_ARCH}" -O linux -T kernel -n "Linux kernel" -C none \
-d "${temp_build_path}"/boot/vmlinuz \
-a 0x03000000 -e 0x03000000 netboot/vmlinux.uimg
fi
# Clean up temporary emerge root
sudo rm -rf "${temp_build_path}"
echo "Add lsb-factory"
# Copy factory config file.
# TODO(nsanders): switch this to u-boot env var config.
LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
sudo mkdir -p "r/${LSB_FACTORY_DIR}"
sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
# Clean up mounts.
trap - EXIT
safe_umount r s
sudo rm -rf r s
# Generate an initrd fo u-boot to load.
gzip -9 -c part_3 > ext2_rootfs.gz
echo "Generating netboot rootfs initrd.uimg"
# U-boot's uimg wrapper specifies where we will load the blob into memory.
# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
# so we want to unpack it there.
mkimage -A "${MKIMAGE_ARCH}" -O linux -T ramdisk -a 0x12008000 \
-n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
netboot/initrd.uimg
# Cleanup
rm -rf ext2_rootfs.gz part_*

View File

@ -1,211 +0,0 @@
#!/bin/bash
# Copyright (c) 2011 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.
# This script modifies a base image to act as a recovery installer.
# If no kernel image is supplied, it will build a devkeys signed recovery
# kernel. Alternatively, a signed recovery kernel can be used to
# create a Chromium OS recovery image.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
. "${SCRIPT_ROOT}/build_library/disk_layout_util.sh" || exit 1
# Default recovery kernel name.
RECOVERY_KERNEL_NAME=recovery_vmlinuz.image
DEFINE_string board "$DEFAULT_BOARD" \
"board for which the image was built" \
b
DEFINE_integer statefulfs_sectors 4096 \
"number of sectors in stateful filesystem when minimizing"
DEFINE_string kernel_outfile "" \
"emit recovery kernel to path/file ($RECOVERY_KERNEL_NAME if empty)"
DEFINE_string image "" \
"source image to use ($CHROMEOS_IMAGE_NAME if empty)"
DEFINE_string to "" \
"emit recovery image to path/file ($CHROMEOS_RECOVERY_IMAGE_NAME if empty)"
DEFINE_boolean sync_keys $FLAGS_TRUE \
"update install kernel with the vblock from stateful"
DEFINE_boolean minimize_image $FLAGS_TRUE \
"create a minimized recovery image from source image"
DEFINE_boolean modify_in_place $FLAGS_FALSE \
"modify source image in place"
DEFINE_integer jobs -1 \
"how many packages to build in parallel at maximum" \
j
DEFINE_string build_root "/build" \
"root location for board sysroots"
DEFINE_string keys_dir "/usr/share/vboot/devkeys" \
"directory containing the signing keys"
DEFINE_boolean verbose $FLAGS_FALSE \
"log all commands to stdout" v
DEFINE_boolean decrypt_stateful $FLAGS_FALSE \
"request a decryption of the stateful partition (implies --nominimize_image)"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
# Make debugging with -v easy.
set -x
fi
# We need space for copying decrypted files to the recovery image, so force
# --nominimize_image when using --decrypt_stateful.
if [ $FLAGS_decrypt_stateful -eq $FLAGS_TRUE ]; then
FLAGS_minimize_image=$FLAGS_FALSE
fi
# Load board options.
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
EMERGE_BOARD_CMD="emerge-$BOARD"
get_install_vblock() {
# If it exists, we need to copy the vblock over to stateful
# This is the real vblock and not the recovery vblock.
local stateful_offset=$(partoffset "$FLAGS_image" 1)
local stateful_mnt=$(mktemp -d)
local out=$(mktemp)
set +e
sudo mount -o ro,loop,offset=$((stateful_offset * 512)) \
"$FLAGS_image" $stateful_mnt
sudo cp "$stateful_mnt/vmlinuz_hd.vblock" "$out"
sudo chown $USER "$out"
safe_umount "$stateful_mnt"
rmdir "$stateful_mnt"
switch_to_strict_mode
echo "$out"
}
maybe_resize_stateful() {
# If we're not minimizing, then just copy and go.
if [ $FLAGS_minimize_image -eq $FLAGS_FALSE ]; then
return 0
fi
# Rebuild the image with a 1 sector stateful partition
local err=0
local small_stateful=$(mktemp)
dd if=/dev/zero of="$small_stateful" bs=512 \
count=${FLAGS_statefulfs_sectors} 1>&2
trap "rm $small_stateful" RETURN
# Don't bother with ext3 for such a small image.
/sbin/mkfs.ext2 -F -b 4096 "$small_stateful" 1>&2
# If it exists, we need to copy the vblock over to stateful
# This is the real vblock and not the recovery vblock.
local new_stateful_mnt=$(mktemp -d)
set +e
sudo mount -o loop $small_stateful $new_stateful_mnt
sudo cp "$INSTALL_VBLOCK" "$new_stateful_mnt/vmlinuz_hd.vblock"
safe_umount "$new_stateful_mnt"
rmdir "$new_stateful_mnt"
switch_to_strict_mode
# Create a recovery image of the right size
# TODO(wad) Make the developer script case create a custom GPT with
# just the kernel image and stateful.
update_partition_table "${FLAGS_image}" "$small_stateful" \
${FLAGS_statefulfs_sectors} \
"${RECOVERY_IMAGE}" 1>&2
return $err
}
cleanup() {
set +e
if [ "$FLAGS_image" != "$RECOVERY_IMAGE" ]; then
rm "$RECOVERY_IMAGE"
fi
rm "$INSTALL_VBLOCK"
}
# Main process begins here.
set -u
# No image was provided, use standard latest image path.
if [ -z "$FLAGS_image" ]; then
DEFAULT_IMAGE_DIR="$($SCRIPT_ROOT/get_latest_image.sh --board=$BOARD)"
FLAGS_image="$DEFAULT_IMAGE_DIR/$CHROMEOS_IMAGE_NAME"
fi
# Turn path into an absolute path.
FLAGS_image=$(readlink -f "$FLAGS_image")
# Abort early if we can't find the image.
if [ ! -f "$FLAGS_image" ]; then
die_notrace "Image not found: $FLAGS_image"
fi
IMAGE_DIR="$(dirname "$FLAGS_image")"
IMAGE_NAME="$(basename "$FLAGS_image")"
RECOVERY_IMAGE="${FLAGS_to:-$IMAGE_DIR/$CHROMEOS_RECOVERY_IMAGE_NAME}"
RECOVERY_KERNEL_IMAGE=\
"${FLAGS_kernel_outfile:-$IMAGE_DIR/$RECOVERY_KERNEL_NAME}"
RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock"
STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
SCRIPTS_DIR=${SCRIPT_ROOT}
# Mounts gpt image and sets up var, /usr/local and symlinks.
# If there's a dev payload, mount stateful
# offset=$(partoffset "${FLAGS_from}/${filename}" 1)
# sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
# "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}"
# If not, resize stateful to 1 sector.
#
if [ $FLAGS_modify_in_place -eq $FLAGS_TRUE ]; then
if [ $FLAGS_minimize_image -eq $FLAGS_TRUE ]; then
die_notrace "Cannot use --modify_in_place and --minimize_image together."
fi
RECOVERY_IMAGE="${FLAGS_image}"
else
cp "${FLAGS_image}" "${RECOVERY_IMAGE}"
fi
echo "Creating recovery image from ${FLAGS_image}"
INSTALL_VBLOCK=$(get_install_vblock)
if [ -z "$INSTALL_VBLOCK" ]; then
die "Could not copy the vblock from stateful."
fi
# Build the recovery kernel.
FACTORY_ROOT="${BOARD_ROOT}/factory-root"
RECOVERY_KERNEL_FLAGS="fbconsole initramfs vfat tpm i2cdev"
USE="${RECOVERY_KERNEL_FLAGS}" emerge_custom_kernel "$FACTORY_ROOT" ||
failboat "Cannot emerge custom kernel"
trap cleanup EXIT
maybe_resize_stateful # Also copies the image if needed.
if [ $FLAGS_decrypt_stateful -eq $FLAGS_TRUE ]; then
stateful_mnt=$(mktemp -d)
offset=$(partoffset "${RECOVERY_IMAGE}" 1)
sudo mount -o loop,offset=$(( offset * 512 )) \
"${RECOVERY_IMAGE}" "${stateful_mnt}"
echo -n "1" | sudo tee "${stateful_mnt}"/decrypt_stateful >/dev/null
sudo umount "$stateful_mnt"
rmdir "$stateful_mnt"
fi
install_recovery_kernel
okboat
echo "Recovery image created at $RECOVERY_IMAGE"
print_time_elapsed
trap - EXIT

View File

@ -1,186 +0,0 @@
#!/bin/bash
# Copyright (c) 2009-2011 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 update the kernel on a live running ChromiumOS instance.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
. "${SCRIPT_ROOT}/remote_access.sh" || exit 1
# Script must be run inside the chroot.
restart_in_chroot_if_needed "$@"
DEFINE_string board "" "Override board reported by target"
DEFINE_string device "" "Override boot device reported by target"
DEFINE_string partition "" "Override kernel partition reported by target"
DEFINE_string arch "" "Override architecture reported by target"
DEFINE_boolean reboot $FLAGS_TRUE "Reboot system after update"
DEFINE_boolean vboot $FLAGS_TRUE "Update the vboot kernel"
# Parse command line.
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
cleanup() {
cleanup_remote_access
rm -rf "${TMP}"
}
learn_device() {
[ -n "${FLAGS_device}" ] && return
remote_sh df /mnt/stateful_partition
FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//)
info "Target reports root device is ${FLAGS_device}"
}
# Ask the target what the kernel partition is
learn_partition_and_ro() {
[ -n "${FLAGS_partition}" ] && return
! remote_sh rootdev
if [ "${REMOTE_OUT%%-*}" == "/dev/dm" ]; then
remote_sh rootdev -s
REMOTE_VERITY=${FLAGS_TRUE}
info "System is using verity: not updating firmware"
else
REMOTE_VERITY=${FLAGS_FALSE}
info "System is not using verity: updating firmware and modules"
fi
if [ "${REMOTE_OUT}" == "${FLAGS_device}3" ]; then
FLAGS_partition="${FLAGS_device}2"
else
FLAGS_partition="${FLAGS_device}4"
fi
if [ -z "${FLAGS_partition}" ]; then
die "Partition required"
fi
if [ ${REMOTE_VERITY} -eq ${FLAGS_TRUE} ]; then
info "Target reports kernel partition is ${FLAGS_partition}"
if [ ${FLAGS_vboot} -eq ${FLAGS_FALSE} ]; then
die "Must update vboot when target is using verity"
fi
fi
}
make_kernelimage() {
local bootloader_path
local kernel_image
if [[ "${FLAGS_arch}" == "arm" ]]; then
name="bootloader.bin"
bootloader_path="${SRC_ROOT}/build/images/${FLAGS_board}/latest/${name}"
kernel_image="/build/${FLAGS_board}/boot/vmlinux.uimg"
else
bootloader_path="/lib64/bootstub/bootstub.efi"
kernel_image="/build/${FLAGS_board}/boot/vmlinuz"
fi
vbutil_kernel --pack $TMP/new_kern.bin \
--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--version 1 \
--config "${SRC_ROOT}/build/images/${FLAGS_board}/latest/config.txt" \
--bootloader "${bootloader_path}" \
--vmlinuz "${kernel_image}" \
--arch "${FLAGS_arch}"
}
copy_kernelimage() {
remote_sh dd of="${FLAGS_partition}" bs=4K < "${TMP}/new_kern.bin"
}
check_kernelbuildtime() {
local version=$(readlink "/build/${FLAGS_board}/boot/vmlinuz" | cut -d- -f2-)
local build_dir="/build/${FLAGS_board}/lib/modules/${version}/build"
if [ "${build_dir}/Makefile" -nt "/build/${FLAGS_board}/boot/vmlinuz" ]; then
warn "Your build directory has been built more recently than"
warn "the installed kernel being updated to. Did you forget to"
warn "run 'cros_workon_make chromeos-kernel --install'?"
fi
}
main() {
trap cleanup EXIT
TMP=$(mktemp -d /tmp/update_kernel.XXXXXX)
remote_access_init
learn_arch
learn_board
learn_device
learn_partition_and_ro
remote_sh uname -r -v
old_kernel="${REMOTE_OUT}"
check_kernelbuildtime
if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then
make_kernelimage
fi
if [[ ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]]; then
remote_sh mount -o remount,rw /
echo "copying kernel"
remote_send_to /build/"${FLAGS_board}"/boot/ /boot/
# ARM does not have the syslinux directory, so skip it when the
# partition or the syslinux vmlinuz target is missing.
echo "updating syslinux kernel"
remote_sh grep $(echo ${FLAGS_device}12 | cut -d/ -f3) /proc/partitions
if [ $(echo "$REMOTE_OUT" | wc -l) -eq 1 ]; then
remote_sh mkdir -p /tmp/12
remote_sh mount ${FLAGS_device}12 /tmp/12
if [ "$FLAGS_partition" = "${FLAGS_device}2" ]; then
target="/tmp/12/syslinux/vmlinuz.A"
else
target="/tmp/12/syslinux/vmlinuz.B"
fi
remote_sh "test ! -f $target || cp /boot/vmlinuz $target"
remote_sh umount /tmp/12
remote_sh rmdir /tmp/12
fi
echo "copying modules"
remote_send_to /build/"${FLAGS_board}"/lib/modules/ /lib/modules/
echo "copying firmware"
remote_send_to /build/"${FLAGS_board}"/lib/firmware/ /lib/firmware/
fi
if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then
info "Copying vboot kernel image"
copy_kernelimage
else
info "Skipping update of vboot (per request)"
fi
# An early kernel panic can prevent the normal sync on reboot. Explicitly
# sync for safety to avoid random file system corruption.
remote_sh sync
if [ ${FLAGS_reboot} -eq ${FLAGS_TRUE} ]; then
echo "rebooting"
remote_reboot
remote_sh uname -r -v
info "old kernel: ${old_kernel}"
info "new kernel: ${REMOTE_OUT}"
else
info "Not rebooting (per request)"
fi
}
main "$@"