Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Chris Sosa | 2eb73c0 | 2011-09-01 18:48:38 -0700 | [diff] [blame] | 3 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # make_netboot.sh --board=[board] |
| 8 | # |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 9 | # This script builds a kernel image bundle with the factory install shim |
| 10 | # included as initramfs. Generated image, along with the netboot firmware |
| 11 | # are placed in a "netboot" subfolder. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 12 | |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame] | 13 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
David James | 359d3e1 | 2012-07-10 13:09:48 -0700 | [diff] [blame] | 14 | . "${SCRIPT_ROOT}/common.sh" || exit 1 |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame] | 15 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 16 | # Script must be run inside the chroot. |
| 17 | restart_in_chroot_if_needed "$@" |
| 18 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 19 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 20 | "The board to build an image for." |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 21 | DEFINE_string image_dir "" "Path to the folder to store netboot images." |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 22 | |
| 23 | # Parse command line. |
| 24 | FLAGS "$@" || exit 1 |
| 25 | eval set -- "${FLAGS_ARGV}" |
| 26 | |
Vic Yang | 3450deb | 2012-05-18 11:57:06 +0800 | [diff] [blame] | 27 | . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 |
| 28 | . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 |
| 29 | |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 30 | switch_to_strict_mode |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 31 | # build_packages artifact output. |
| 32 | SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" |
| 33 | # build_image artifact output. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 34 | |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 35 | if [ -n "${FLAGS_image_dir}" ]; then |
| 36 | cd ${FLAGS_image_dir} |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 37 | else |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 38 | cd "${CHROOT_TRUNK_DIR}"/src/build/images/"${FLAGS_board}"/latest |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | # Generate staging dir for netboot files. |
| 42 | sudo rm -rf netboot |
| 43 | mkdir -p netboot |
| 44 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 45 | # Get netboot firmware. |
Hung-Te Lin | ba7dc67 | 2016-11-17 17:54:27 +0800 | [diff] [blame^] | 46 | FIRMWARE_PATH="/firmware/image.net.bin" |
| 47 | if [ -f "${SYSROOT}${FIRMWARE_PATH}" ]; then |
| 48 | echo "Copying netboot firmware ${FIRMWARE_PATH}..." |
| 49 | cp -v "${SYSROOT}${FIRMWARE_PATH}" netboot/ |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 50 | else |
Hung-Te Lin | ba7dc67 | 2016-11-17 17:54:27 +0800 | [diff] [blame^] | 51 | echo "Skipping netboot firmware: ${SYSROOT}${FIRMWARE_PATH} not present?" |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 52 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 53 | |
Vic Yang | 90e3b25 | 2013-01-09 18:34:35 +0800 | [diff] [blame] | 54 | # Create temporary emerge root |
| 55 | temp_build_path="$(mktemp -d bk_XXXXXXXX)" |
| 56 | if ! [ -d "${temp_build_path}" ]; then |
| 57 | echo "Failed to create temporary directory." |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 61 | # Build initramfs network boot image |
| 62 | echo "Building kernel" |
Hung-Te Lin | ff887de | 2016-08-24 10:31:25 +0800 | [diff] [blame] | 63 | export USE="fbconsole vtconsole factory_netboot_ramfs tpm i2cdev vfat" |
Vic Yang | 90e3b25 | 2013-01-09 18:34:35 +0800 | [diff] [blame] | 64 | export EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
| 65 | emerge_custom_kernel ${temp_build_path} |
| 66 | |
Vic Yang | 7397b8d | 2013-01-27 13:24:24 +0800 | [diff] [blame] | 67 | # Place kernel image under 'netboot' |
Hung-Te Lin | ba7dc67 | 2016-11-17 17:54:27 +0800 | [diff] [blame^] | 68 | KERNEL_PATH="/boot/vmlinuz" |
| 69 | if [ -f "${temp_build_path}${KERNEL_PATH}" ]; then |
| 70 | echo "Generating netboot kernel ${KERNEL_PATH}" |
| 71 | cp -v "${temp_build_path}${KERNEL_PATH}" netboot/ |
Vic Yang | 3450deb | 2012-05-18 11:57:06 +0800 | [diff] [blame] | 72 | else |
Hung-Te Lin | ba7dc67 | 2016-11-17 17:54:27 +0800 | [diff] [blame^] | 73 | echo "No ${KERNEL_PATH} found in your board." |
Vic Yang | 3450deb | 2012-05-18 11:57:06 +0800 | [diff] [blame] | 74 | fi |
Nick Sanders | 2027ca8 | 2011-08-09 00:48:29 -0700 | [diff] [blame] | 75 | |
Vic Yang | 90e3b25 | 2013-01-09 18:34:35 +0800 | [diff] [blame] | 76 | sudo rm -rf "${temp_build_path}" |