blob: 1a51a05b712d325c74d3f6212b5d0c4010ecc670 [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"))
Mike Frysinger58e2db52019-09-27 15:02:47 -040014. "${SCRIPT_ROOT}/build_library/build_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.
Cheng-Han Yang414cb152019-07-10 17:35:09 +080046FIRMWARE_PATTERN="firmware/image*.net.bin"
47FIRMWARE_PATHS=("${SYSROOT}"/${FIRMWARE_PATTERN})
48# When there is no netboot firmware found, filename expansion fails and the
49# array still contains the original pattern string, so we need to check if the
50# first file in the array actually exists to know if we find any firmware.
51if [ -e "${FIRMWARE_PATHS[0]}" ]; then
52 for firmware_path in "${FIRMWARE_PATHS[@]}"; do
53 echo "Copying netboot firmware ${firmware_path}..."
54 cp -v "${firmware_path}" netboot/
55 done
Grant Grundler7c4328a2011-06-22 10:24:42 -070056else
Cheng-Han Yang414cb152019-07-10 17:35:09 +080057 echo "Skipping netboot firmware: ${SYSROOT}/${FIRMWARE_PATTERN} not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070058fi
Nick Sanders119677f2011-06-03 01:04:08 -070059
Vic Yang90e3b252013-01-09 18:34:35 +080060# Create temporary emerge root
61temp_build_path="$(mktemp -d bk_XXXXXXXX)"
62if ! [ -d "${temp_build_path}" ]; then
63 echo "Failed to create temporary directory."
64 exit 1
65fi
66
Vic Yang7397b8d2013-01-27 13:24:24 +080067# Build initramfs network boot image
68echo "Building kernel"
Hung-Te Linff887de2016-08-24 10:31:25 +080069export USE="fbconsole vtconsole factory_netboot_ramfs tpm i2cdev vfat"
Vic Yang90e3b252013-01-09 18:34:35 +080070export EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
71emerge_custom_kernel ${temp_build_path}
72
Vic Yang7397b8d2013-01-27 13:24:24 +080073# Place kernel image under 'netboot'
Hung-Te Linba7dc672016-11-17 17:54:27 +080074KERNEL_PATH="/boot/vmlinuz"
75if [ -f "${temp_build_path}${KERNEL_PATH}" ]; then
76 echo "Generating netboot kernel ${KERNEL_PATH}"
77 cp -v "${temp_build_path}${KERNEL_PATH}" netboot/
Vic Yang3450deb2012-05-18 11:57:06 +080078else
Hung-Te Linba7dc672016-11-17 17:54:27 +080079 echo "No ${KERNEL_PATH} found in your board."
Vic Yang3450deb2012-05-18 11:57:06 +080080fi
Nick Sanders2027ca82011-08-09 00:48:29 -070081
Vic Yang90e3b252013-01-09 18:34:35 +080082sudo rm -rf "${temp_build_path}"