blob: b7cb3371bf9ab317dcd5a703ad122dfd0a99177d [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.
Nick Sanders119677f2011-06-03 01:04:08 -070046# TODO(nsanders): Set default IP here when userspace
47# env modification is available.
Grant Grundler7c4328a2011-06-22 10:24:42 -070048# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
49# When ARM generic goes away, delete the test.
Vic Yange72689e2013-01-27 16:00:11 +080050if ls "${SYSROOT}"/firmware/nv_image-*.bin >/dev/null 2>&1; then
51 echo "Copying netboot firmware nv_image-*.bin"
52 cp -v "${SYSROOT}"/firmware/nv_image-*.bin "netboot"
Grant Grundler7c4328a2011-06-22 10:24:42 -070053else
Vic Yange72689e2013-01-27 16:00:11 +080054 echo "Skipping netboot firmware: " \
55 "${SYSROOT}/firmware/nv_image-*.bin not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070056fi
Nick Sanders119677f2011-06-03 01:04:08 -070057
Vic Yang90e3b252013-01-09 18:34:35 +080058# Create temporary emerge root
59temp_build_path="$(mktemp -d bk_XXXXXXXX)"
60if ! [ -d "${temp_build_path}" ]; then
61 echo "Failed to create temporary directory."
62 exit 1
63fi
64
Vic Yang7397b8d2013-01-27 13:24:24 +080065# Build initramfs network boot image
66echo "Building kernel"
67export USE='vfat netboot_ramfs i2cdev tpm'
Vic Yang90e3b252013-01-09 18:34:35 +080068export EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
69emerge_custom_kernel ${temp_build_path}
70
Vic Yang7397b8d2013-01-27 13:24:24 +080071# Place kernel image under 'netboot'
Vic Yang90e3b252013-01-09 18:34:35 +080072echo "Generating netboot kernel vmlinux.uimg"
Vic Yang3450deb2012-05-18 11:57:06 +080073if [ "${ARCH}" = "arm" ]; then
Vic Yang90e3b252013-01-09 18:34:35 +080074 cp "${temp_build_path}"/boot/vmlinux.uimg netboot/
Vic Yang3450deb2012-05-18 11:57:06 +080075else
Vic Yang3450deb2012-05-18 11:57:06 +080076 # U-boot put kernel image at 0x100000. We load it at 0x3000000 because
77 # 0x3000000 is safe enough not to overlap with image at 0x100000.
Vic Yang7397b8d2013-01-27 13:24:24 +080078 mkimage -A x86 -O linux -T kernel -n "Linux kernel" -C none \
Vic Yang3450deb2012-05-18 11:57:06 +080079 -d "${temp_build_path}"/boot/vmlinuz \
80 -a 0x03000000 -e 0x03000000 netboot/vmlinux.uimg
Vic Yang3450deb2012-05-18 11:57:06 +080081fi
Nick Sanders2027ca82011-08-09 00:48:29 -070082
Vic Yang90e3b252013-01-09 18:34:35 +080083sudo rm -rf "${temp_build_path}"