blob: 890a8cc0463d08bf0b32f3b41358f9b22662c0ac [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
36. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
37# --- 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.
78if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ]
79 echo "Copying netboot firmware legacy_image.bin"
80 cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot"
81else
82 echo "Skipping: ${SYSROOT}/u-boot/legacy_image.bin firmware not present?"
83fi
Nick Sanders119677f2011-06-03 01:04:08 -070084
85# Prepare to mount rootfs.
86umount_loop() {
87 sudo umount r || true
88 sudo umount s || true
89 false
90}
91
92echo "Unpack factory install shim partitions"
93./unpack_partitions.sh "${INSTALL_SHIM}"
94
95# Genrate clean mountpoints.
96sudo rm -rf r s
97mkdir -p r s
98
99# Clean ROified filesystem headers, and mount.
100trap "umount_loop" EXIT
101enable_rw_mount part_3
102sudo mount -o loop part_3 r
103sudo mount -o loop part_1 s
104echo "Mount install shim rootfs (partition 3)"
105
106# Copy factory config file.
107# TODO(nsanders): switch this to u-boot env var config.
108LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
109sudo mkdir -p "r/${LSB_FACTORY_DIR}"
110sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
111
112# Clean up mounts.
113trap - EXIT
114sudo umount r s
115sudo rm -rf r s
116
117# Generate an initrd fo u-boot to load.
118gzip -9 -c part_3 > ext2_rootfs.gz
119echo "Generating netboot rootfs initrd.uimg"
120# U-boot's uimg wrapper specifies where we will load the blob into memory.
121# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
122# so we want to unpack it there.
123mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
124 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
125 netboot/initrd.uimg
126
127# Cleanup
128rm -rf ext2_rootfs.gz part_*