blob: 2d1eb1ac4b68fa43494b398649448a77ea13aa7b [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."
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.
Elly Jonesc871ba22011-06-22 14:58:55 -040080if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ]; then
Grant Grundler7c4328a2011-06-22 10:24:42 -070081 echo "Copying netboot firmware legacy_image.bin"
82 cp "${SYSROOT}/u-boot/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
Nick Sandersdaebdee2011-08-02 03:42:04 -070085 echo "Skipping legacy fw: ${SYSROOT}/u-boot/legacy_image.bin not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070086fi
Nick Sanders119677f2011-06-03 01:04:08 -070087
Nick Sandersdaebdee2011-08-02 03:42:04 -070088# Get HWID bundle if available.
89hwid_dir="usr/share/chromeos-hwid"
90sudo rm -rf hwid
91mkdir -p hwid
92if updater_files=$(ls "${SYSROOT}/${hwid_dir}/" | grep updater_); then
93 echo "Copying HWID bundles: $updater_files"
94 for file in $updater_files; do
95 cp "${SYSROOT}/${hwid_dir}/${file}" "hwid/"
96 done
97else
98 echo "Skipping HWID: ${SYSROOT}/${hwid_dir}/" \
99 "does not contain updater"
100fi
101
102
Nick Sanders119677f2011-06-03 01:04:08 -0700103# Prepare to mount rootfs.
104umount_loop() {
105 sudo umount r || true
106 sudo umount s || true
107 false
108}
109
110echo "Unpack factory install shim partitions"
111./unpack_partitions.sh "${INSTALL_SHIM}"
112
113# Genrate clean mountpoints.
114sudo rm -rf r s
115mkdir -p r s
116
117# Clean ROified filesystem headers, and mount.
118trap "umount_loop" EXIT
119enable_rw_mount part_3
120sudo mount -o loop part_3 r
121sudo mount -o loop part_1 s
122echo "Mount install shim rootfs (partition 3)"
123
Nick Sanders2027ca82011-08-09 00:48:29 -0700124# Get netboot kernel.
125echo "Generating netboot kernel vmlinux.uimg"
126cp "r/boot/vmlinux.uimg" "netboot"
127
128echo "Add lsb-factory"
Nick Sanders119677f2011-06-03 01:04:08 -0700129# Copy factory config file.
130# TODO(nsanders): switch this to u-boot env var config.
131LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
132sudo mkdir -p "r/${LSB_FACTORY_DIR}"
133sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
134
135# Clean up mounts.
136trap - EXIT
137sudo umount r s
138sudo rm -rf r s
139
140# Generate an initrd fo u-boot to load.
141gzip -9 -c part_3 > ext2_rootfs.gz
142echo "Generating netboot rootfs initrd.uimg"
143# U-boot's uimg wrapper specifies where we will load the blob into memory.
144# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
145# so we want to unpack it there.
146mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
147 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
148 netboot/initrd.uimg
149
150# Cleanup
151rm -rf ext2_rootfs.gz part_*