blob: b512d73185794922667b5a0a7a6dac4ba0815b08 [file] [log] [blame]
Nick Sanders119677f2011-06-03 01:04:08 -07001#!/bin/bash
2
3# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
4# 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."
45
46# Parse command line.
47FLAGS "$@" || exit 1
48eval set -- "${FLAGS_ARGV}"
49
50set -e
51# build_packages artifact output.
52SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
53# build_image artifact output.
54IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images"
55# Canonical install shim name.
56INSTALL_SHIM="factory_install_shim.bin"
57
58cd ${IMAGES_DIR}/${FLAGS_board}/latest
59
60if [ ! -f "${INSTALL_SHIM}" ]; then
61 echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!"
62 exit 1
63fi
64
65# Generate staging dir for netboot files.
66sudo rm -rf netboot
67mkdir -p netboot
68
69# Get netboot kernel.
70echo "Generating netboot kernel vmlinux.uimg"
71cp "${SYSROOT}/boot/vmlinux.uimg" "netboot"
72
73# Get netboot firmware.
Nick Sanders119677f2011-06-03 01:04:08 -070074# TODO(nsanders): Set default IP here when userspace
75# env modification is available.
Grant Grundler7c4328a2011-06-22 10:24:42 -070076# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
77# When ARM generic goes away, delete the test.
Elly Jonesc871ba22011-06-22 14:58:55 -040078if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ]; then
Grant Grundler7c4328a2011-06-22 10:24:42 -070079 echo "Copying netboot firmware legacy_image.bin"
80 cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot"
Nick Sandersfa28c162011-07-19 01:48:57 -070081 cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot"
Grant Grundler7c4328a2011-06-22 10:24:42 -070082else
83 echo "Skipping: ${SYSROOT}/u-boot/legacy_image.bin firmware not present?"
84fi
Nick Sanders119677f2011-06-03 01:04:08 -070085
86# Prepare to mount rootfs.
87umount_loop() {
88 sudo umount r || true
89 sudo umount s || true
90 false
91}
92
93echo "Unpack factory install shim partitions"
94./unpack_partitions.sh "${INSTALL_SHIM}"
95
96# Genrate clean mountpoints.
97sudo rm -rf r s
98mkdir -p r s
99
100# Clean ROified filesystem headers, and mount.
101trap "umount_loop" EXIT
102enable_rw_mount part_3
103sudo mount -o loop part_3 r
104sudo mount -o loop part_1 s
105echo "Mount install shim rootfs (partition 3)"
106
107# Copy factory config file.
108# TODO(nsanders): switch this to u-boot env var config.
109LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
110sudo mkdir -p "r/${LSB_FACTORY_DIR}"
111sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
112
113# Clean up mounts.
114trap - EXIT
115sudo umount r s
116sudo rm -rf r s
117
118# Generate an initrd fo u-boot to load.
119gzip -9 -c part_3 > ext2_rootfs.gz
120echo "Generating netboot rootfs initrd.uimg"
121# U-boot's uimg wrapper specifies where we will load the blob into memory.
122# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
123# so we want to unpack it there.
124mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
125 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
126 netboot/initrd.uimg
127
128# Cleanup
129rm -rf ext2_rootfs.gz part_*