blob: 94133a22b5f51bee61f4d73b5dc529044e39b090 [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
15# This script is intended to be called mainly form archive_build.sh, where
16# these files are added to the factory install artifacts generated on buildbot.
17
18# --- BEGIN COMMON.SH BOILERPLATE ---
19# Load common CrOS utilities. Inside the chroot this file is installed in
20# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
21# location.
22find_common_sh() {
23 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
24 local path
25
26 SCRIPT_ROOT=
27 for path in "${common_paths[@]}"; do
28 if [ -r "${path}/common.sh" ]; then
29 SCRIPT_ROOT=${path}
30 break
31 fi
32 done
33}
34
35find_common_sh
Brian Harringd5d5dbf2011-07-11 16:36:21 -070036. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
Nick Sanders119677f2011-06-03 01:04:08 -070037# --- END COMMON.SH BOILERPLATE ---
38# Script must be run inside the chroot.
39restart_in_chroot_if_needed "$@"
40
41get_default_board
42
43DEFINE_string board "${DEFAULT_BOARD}" \
44 "The board to build an image for."
David James4dd4c542011-08-10 10:19:47 -070045DEFINE_string image "" "Path to the image to use"
Nick Sanders119677f2011-06-03 01:04:08 -070046
47# Parse command line.
48FLAGS "$@" || exit 1
49eval set -- "${FLAGS_ARGV}"
50
51set -e
52# build_packages artifact output.
53SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
54# build_image artifact output.
55IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images"
Nick Sanders119677f2011-06-03 01:04:08 -070056
David James4dd4c542011-08-10 10:19:47 -070057if [ -n "${FLAGS_image}" ]; then
58 cd $(dirname "${FLAGS_image}")
59 INSTALL_SHIM=$(basename "${FLAGS_image}")
60else
61 cd ${IMAGES_DIR}/${FLAGS_board}/latest
62 # Canonical install shim name.
63 INSTALL_SHIM="factory_install_shim.bin"
64fi
Nick Sanders119677f2011-06-03 01:04:08 -070065
66if [ ! -f "${INSTALL_SHIM}" ]; then
67 echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!"
68 exit 1
69fi
70
71# Generate staging dir for netboot files.
72sudo rm -rf netboot
73mkdir -p netboot
74
Nick Sanders119677f2011-06-03 01:04:08 -070075# Get netboot firmware.
Nick Sanders119677f2011-06-03 01:04:08 -070076# TODO(nsanders): Set default IP here when userspace
77# env modification is available.
Grant Grundler7c4328a2011-06-22 10:24:42 -070078# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
79# When ARM generic goes away, delete the test.
Stefan Reinauerb3921532011-09-07 16:34:02 -070080if [ -r "${SYSROOT}/firmware/legacy_image.bin" ]; then
Grant Grundler7c4328a2011-06-22 10:24:42 -070081 echo "Copying netboot firmware legacy_image.bin"
Stefan Reinauerb3921532011-09-07 16:34:02 -070082 cp "${SYSROOT}/firmware/legacy_image.bin" "netboot"
Nick Sandersfa28c162011-07-19 01:48:57 -070083 cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot"
Grant Grundler7c4328a2011-06-22 10:24:42 -070084else
Stefan Reinauerb3921532011-09-07 16:34:02 -070085 echo "Skipping legacy fw: ${SYSROOT}/firmware/legacy_image.bin not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070086fi
Nick Sanders119677f2011-06-03 01:04:08 -070087
Nick Sanders119677f2011-06-03 01:04:08 -070088# Prepare to mount rootfs.
89umount_loop() {
90 sudo umount r || true
91 sudo umount s || true
92 false
93}
94
95echo "Unpack factory install shim partitions"
96./unpack_partitions.sh "${INSTALL_SHIM}"
97
98# Genrate clean mountpoints.
99sudo rm -rf r s
100mkdir -p r s
101
102# Clean ROified filesystem headers, and mount.
103trap "umount_loop" EXIT
104enable_rw_mount part_3
105sudo mount -o loop part_3 r
106sudo mount -o loop part_1 s
107echo "Mount install shim rootfs (partition 3)"
108
Nick Sanders2027ca82011-08-09 00:48:29 -0700109# Get netboot kernel.
110echo "Generating netboot kernel vmlinux.uimg"
111cp "r/boot/vmlinux.uimg" "netboot"
112
113echo "Add lsb-factory"
Nick Sanders119677f2011-06-03 01:04:08 -0700114# Copy factory config file.
115# TODO(nsanders): switch this to u-boot env var config.
116LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
117sudo mkdir -p "r/${LSB_FACTORY_DIR}"
118sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
119
120# Clean up mounts.
121trap - EXIT
122sudo umount r s
123sudo rm -rf r s
124
125# Generate an initrd fo u-boot to load.
126gzip -9 -c part_3 > ext2_rootfs.gz
127echo "Generating netboot rootfs initrd.uimg"
128# U-boot's uimg wrapper specifies where we will load the blob into memory.
129# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
130# so we want to unpack it there.
131mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
132 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
133 netboot/initrd.uimg
134
135# Cleanup
136rm -rf ext2_rootfs.gz part_*