blob: c7734fe93710c927666bc8d011336613d1d7af2e [file] [log] [blame]
Nick Sanders119677f2011-06-03 01:04:08 -07001#!/bin/bash
2
Chris Sosa2eb73c02011-09-01 18:48:38 -07003# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Nick Sanders119677f2011-06-03 01:04:08 -07004# 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 Yang7397b8d2013-01-27 13:24:24 +08009# 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 Sanders119677f2011-06-03 01:04:08 -070012
Brian Harringaa13ea42012-03-15 18:31:03 -070013SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
David James359d3e12012-07-10 13:09:48 -070014. "${SCRIPT_ROOT}/common.sh" || exit 1
Brian Harringaa13ea42012-03-15 18:31:03 -070015
Nick Sanders119677f2011-06-03 01:04:08 -070016# Script must be run inside the chroot.
17restart_in_chroot_if_needed "$@"
18
Nick Sanders119677f2011-06-03 01:04:08 -070019DEFINE_string board "${DEFAULT_BOARD}" \
20 "The board to build an image for."
Vic Yang7397b8d2013-01-27 13:24:24 +080021DEFINE_string image_dir "" "Path to the folder to store netboot images."
Nick Sanders119677f2011-06-03 01:04:08 -070022
23# Parse command line.
24FLAGS "$@" || exit 1
25eval set -- "${FLAGS_ARGV}"
26
Vic Yang3450deb2012-05-18 11:57:06 +080027. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
28. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
29
Brian Harring7f175a52012-03-02 05:37:00 -080030switch_to_strict_mode
Nick Sanders119677f2011-06-03 01:04:08 -070031# build_packages artifact output.
32SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
33# build_image artifact output.
Nick Sanders119677f2011-06-03 01:04:08 -070034
Vic Yang7397b8d2013-01-27 13:24:24 +080035if [ -n "${FLAGS_image_dir}" ]; then
36 cd ${FLAGS_image_dir}
David James4dd4c542011-08-10 10:19:47 -070037else
Vic Yang7397b8d2013-01-27 13:24:24 +080038 cd "${CHROOT_TRUNK_DIR}"/src/build/images/"${FLAGS_board}"/latest
Nick Sanders119677f2011-06-03 01:04:08 -070039fi
40
41# Generate staging dir for netboot files.
42sudo rm -rf netboot
43mkdir -p netboot
44
Nick Sanders119677f2011-06-03 01:04:08 -070045# Get netboot firmware.
Hung-Te Linba7dc672016-11-17 17:54:27 +080046FIRMWARE_PATH="/firmware/image.net.bin"
47if [ -f "${SYSROOT}${FIRMWARE_PATH}" ]; then
48 echo "Copying netboot firmware ${FIRMWARE_PATH}..."
49 cp -v "${SYSROOT}${FIRMWARE_PATH}" netboot/
Grant Grundler7c4328a2011-06-22 10:24:42 -070050else
Hung-Te Linba7dc672016-11-17 17:54:27 +080051 echo "Skipping netboot firmware: ${SYSROOT}${FIRMWARE_PATH} not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070052fi
Nick Sanders119677f2011-06-03 01:04:08 -070053
Vic Yang90e3b252013-01-09 18:34:35 +080054# Create temporary emerge root
55temp_build_path="$(mktemp -d bk_XXXXXXXX)"
56if ! [ -d "${temp_build_path}" ]; then
57 echo "Failed to create temporary directory."
58 exit 1
59fi
60
Vic Yang7397b8d2013-01-27 13:24:24 +080061# Build initramfs network boot image
62echo "Building kernel"
Hung-Te Linff887de2016-08-24 10:31:25 +080063export USE="fbconsole vtconsole factory_netboot_ramfs tpm i2cdev vfat"
Vic Yang90e3b252013-01-09 18:34:35 +080064export EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
65emerge_custom_kernel ${temp_build_path}
66
Vic Yang7397b8d2013-01-27 13:24:24 +080067# Place kernel image under 'netboot'
Hung-Te Linba7dc672016-11-17 17:54:27 +080068KERNEL_PATH="/boot/vmlinuz"
69if [ -f "${temp_build_path}${KERNEL_PATH}" ]; then
70 echo "Generating netboot kernel ${KERNEL_PATH}"
71 cp -v "${temp_build_path}${KERNEL_PATH}" netboot/
Vic Yang3450deb2012-05-18 11:57:06 +080072else
Hung-Te Linba7dc672016-11-17 17:54:27 +080073 echo "No ${KERNEL_PATH} found in your board."
Vic Yang3450deb2012-05-18 11:57:06 +080074fi
Nick Sanders2027ca82011-08-09 00:48:29 -070075
Vic Yang90e3b252013-01-09 18:34:35 +080076sudo rm -rf "${temp_build_path}"