blob: b8d97f196d1c9f69abde2128717ebf9b303c0543 [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#
9# This script validates that the current latest image is an install shim,
10# and generates a netboot image from it. This pulls the u-boot kernel
11# image bundle (uimg), the legacy firmware for netbooting, and the install
12# shim kernel image, bundled as a uboot gz/uimg, and places them in a
13# "netboot" subfolder.
14
Brian Harringaa13ea42012-03-15 18:31:03 -070015SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
Brian Harringd5d5dbf2011-07-11 16:36:21 -070016. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
Brian Harringaa13ea42012-03-15 18:31:03 -070017
Nick Sanders119677f2011-06-03 01:04:08 -070018# Script must be run inside the chroot.
19restart_in_chroot_if_needed "$@"
20
21get_default_board
22
23DEFINE_string board "${DEFAULT_BOARD}" \
24 "The board to build an image for."
David James4dd4c542011-08-10 10:19:47 -070025DEFINE_string image "" "Path to the image to use"
Nick Sanders119677f2011-06-03 01:04:08 -070026
27# Parse command line.
28FLAGS "$@" || exit 1
29eval set -- "${FLAGS_ARGV}"
30
31set -e
32# build_packages artifact output.
33SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
34# build_image artifact output.
35IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images"
Nick Sanders119677f2011-06-03 01:04:08 -070036
David James4dd4c542011-08-10 10:19:47 -070037if [ -n "${FLAGS_image}" ]; then
38 cd $(dirname "${FLAGS_image}")
39 INSTALL_SHIM=$(basename "${FLAGS_image}")
40else
41 cd ${IMAGES_DIR}/${FLAGS_board}/latest
42 # Canonical install shim name.
43 INSTALL_SHIM="factory_install_shim.bin"
44fi
Nick Sanders119677f2011-06-03 01:04:08 -070045
46if [ ! -f "${INSTALL_SHIM}" ]; then
47 echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!"
48 exit 1
49fi
50
51# Generate staging dir for netboot files.
52sudo rm -rf netboot
53mkdir -p netboot
54
Nick Sanders119677f2011-06-03 01:04:08 -070055# Get netboot firmware.
Nick Sanders119677f2011-06-03 01:04:08 -070056# TODO(nsanders): Set default IP here when userspace
57# env modification is available.
Grant Grundler7c4328a2011-06-22 10:24:42 -070058# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
59# When ARM generic goes away, delete the test.
Stefan Reinauerb3921532011-09-07 16:34:02 -070060if [ -r "${SYSROOT}/firmware/legacy_image.bin" ]; then
Grant Grundler7c4328a2011-06-22 10:24:42 -070061 echo "Copying netboot firmware legacy_image.bin"
Stefan Reinauerb3921532011-09-07 16:34:02 -070062 cp "${SYSROOT}/firmware/legacy_image.bin" "netboot"
Nick Sandersfa28c162011-07-19 01:48:57 -070063 cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot"
Grant Grundler7c4328a2011-06-22 10:24:42 -070064else
Stefan Reinauerb3921532011-09-07 16:34:02 -070065 echo "Skipping legacy fw: ${SYSROOT}/firmware/legacy_image.bin not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070066fi
Nick Sanders119677f2011-06-03 01:04:08 -070067
Nick Sanders119677f2011-06-03 01:04:08 -070068# Prepare to mount rootfs.
69umount_loop() {
70 sudo umount r || true
71 sudo umount s || true
72 false
73}
74
75echo "Unpack factory install shim partitions"
76./unpack_partitions.sh "${INSTALL_SHIM}"
77
78# Genrate clean mountpoints.
79sudo rm -rf r s
80mkdir -p r s
81
82# Clean ROified filesystem headers, and mount.
83trap "umount_loop" EXIT
84enable_rw_mount part_3
85sudo mount -o loop part_3 r
86sudo mount -o loop part_1 s
87echo "Mount install shim rootfs (partition 3)"
88
Nick Sanders2027ca82011-08-09 00:48:29 -070089# Get netboot kernel.
90echo "Generating netboot kernel vmlinux.uimg"
91cp "r/boot/vmlinux.uimg" "netboot"
92
93echo "Add lsb-factory"
Nick Sanders119677f2011-06-03 01:04:08 -070094# Copy factory config file.
95# TODO(nsanders): switch this to u-boot env var config.
96LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
97sudo mkdir -p "r/${LSB_FACTORY_DIR}"
98sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
99
100# Clean up mounts.
101trap - EXIT
102sudo umount r s
103sudo rm -rf r s
104
105# Generate an initrd fo u-boot to load.
106gzip -9 -c part_3 > ext2_rootfs.gz
107echo "Generating netboot rootfs initrd.uimg"
108# U-boot's uimg wrapper specifies where we will load the blob into memory.
109# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
110# so we want to unpack it there.
111mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
112 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
113 netboot/initrd.uimg
114
115# Cleanup
116rm -rf ext2_rootfs.gz part_*