flatcar-scripts/make_netboot.sh
Brian Harring 7f175a59e1 common.sh: output a backtrace and debug information on failure.
Currently, if set -e spots a nonzero exit we basically have
no real debug information- it just stops immediately without stating
where or why.  This forces our scripts to be stupidly verbose so
we can track roughly where they were, thus when they fail we can
use that information to localize the rough exit point.

Instead we should be traping that set -e induced exit and
outputing necessary debug information to run it down.  This includes
outputing the relevant stack trace, or at least what we can get of
it.

The 'die' function is now enhanced to automatically dump the trace
that lead to it.  For most consumers this is desired- however for
commandline parsing induced dies ("--board is missing" for example),
the trace is noise.  For those cases, a 'die_notrace' function was
added that retains the original non-backtrace behaviour.

Example output via instrumenting cros_generate_breakpad_symbols
w/ the failing command '/bin/false' (nonzero exit code).

Before:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
<no output at all, just exit code 1>

With this CL:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
ERROR   : script called: ./cros_generate_breakpad_symbols 'monkeys' '--board=x86-alex'
ERROR   : Backtrace:  (most recent call is last)
ERROR   :   file cros_generate_breakpad_symbols, line 207, called: main 'monkeys' '--board=x86-alex'
ERROR   :   file cros_generate_breakpad_symbols, line 163, called: die_err_trap '/bin/false' '1'
ERROR   :
ERROR   : Command failed:
ERROR   :   Command '/bin/false' exited with nonzero code: 1

BUG=chromium-os:30598
TEST=inject a failing command into a script, verify the output.
TEST=inject a 'command not found', verify the output
TEST=cbuildbot x86-generic-full --remote
TEST=cbuildbot arm-tegra2-full --remote
TEST=cbuildbot chromiumos-sdk --remote

Change-Id: I517ffde4d1bb7e2310a74f5a6455b53ba2dea86c
Reviewed-on: https://gerrit.chromium.org/gerrit/17225
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: Brian Harring <ferringb@chromium.org>
2012-05-07 17:19:41 -07:00

117 lines
3.4 KiB
Bash
Executable File

#!/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" || { echo "Unable to load common.sh"; exit 1; }
# Script must be run inside the chroot.
restart_in_chroot_if_needed "$@"
get_default_board
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}"
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 [ -r "${SYSROOT}/firmware/legacy_image.bin" ]; then
echo "Copying netboot firmware legacy_image.bin"
cp "${SYSROOT}/firmware/legacy_image.bin" "netboot"
cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot"
else
echo "Skipping legacy fw: ${SYSROOT}/firmware/legacy_image.bin not present?"
fi
# Prepare to mount rootfs.
umount_loop() {
sudo umount r || true
sudo 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)"
# Get netboot kernel.
echo "Generating netboot kernel vmlinux.uimg"
cp "r/boot/vmlinux.uimg" "netboot"
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
sudo 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 arm -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_*