blob: 479145c173d222c3e1a0b5721242a8863cd119c1 [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.
74echo "Generating netboot firmware"
75# TODO(nsanders): Set default IP here when userspace
76# env modification is available.
77cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot"
78
79# Prepare to mount rootfs.
80umount_loop() {
81 sudo umount r || true
82 sudo umount s || true
83 false
84}
85
86echo "Unpack factory install shim partitions"
87./unpack_partitions.sh "${INSTALL_SHIM}"
88
89# Genrate clean mountpoints.
90sudo rm -rf r s
91mkdir -p r s
92
93# Clean ROified filesystem headers, and mount.
94trap "umount_loop" EXIT
95enable_rw_mount part_3
96sudo mount -o loop part_3 r
97sudo mount -o loop part_1 s
98echo "Mount install shim rootfs (partition 3)"
99
100# Copy factory config file.
101# TODO(nsanders): switch this to u-boot env var config.
102LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
103sudo mkdir -p "r/${LSB_FACTORY_DIR}"
104sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
105
106# Clean up mounts.
107trap - EXIT
108sudo umount r s
109sudo rm -rf r s
110
111# Generate an initrd fo u-boot to load.
112gzip -9 -c part_3 > ext2_rootfs.gz
113echo "Generating netboot rootfs initrd.uimg"
114# U-boot's uimg wrapper specifies where we will load the blob into memory.
115# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
116# so we want to unpack it there.
117mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
118 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
119 netboot/initrd.uimg
120
121# Cleanup
122rm -rf ext2_rootfs.gz part_*