blob: d795c42887dc26a933dd4e8265abbfa428b31f0f [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
Nick Sanders119677f2011-06-03 01:04:08 -070069# Get netboot firmware.
Nick Sanders119677f2011-06-03 01:04:08 -070070# TODO(nsanders): Set default IP here when userspace
71# env modification is available.
Grant Grundler7c4328a2011-06-22 10:24:42 -070072# TODO(nsanders): ARM generic doesn't build chromeos-u-boot package.
73# When ARM generic goes away, delete the test.
Elly Jonesc871ba22011-06-22 14:58:55 -040074if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ]; then
Grant Grundler7c4328a2011-06-22 10:24:42 -070075 echo "Copying netboot firmware legacy_image.bin"
76 cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot"
Nick Sandersfa28c162011-07-19 01:48:57 -070077 cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot"
Grant Grundler7c4328a2011-06-22 10:24:42 -070078else
Nick Sandersdaebdee2011-08-02 03:42:04 -070079 echo "Skipping legacy fw: ${SYSROOT}/u-boot/legacy_image.bin not present?"
Grant Grundler7c4328a2011-06-22 10:24:42 -070080fi
Nick Sanders119677f2011-06-03 01:04:08 -070081
Nick Sandersdaebdee2011-08-02 03:42:04 -070082# Get HWID bundle if available.
83hwid_dir="usr/share/chromeos-hwid"
84sudo rm -rf hwid
85mkdir -p hwid
86if updater_files=$(ls "${SYSROOT}/${hwid_dir}/" | grep updater_); then
87 echo "Copying HWID bundles: $updater_files"
88 for file in $updater_files; do
89 cp "${SYSROOT}/${hwid_dir}/${file}" "hwid/"
90 done
91else
92 echo "Skipping HWID: ${SYSROOT}/${hwid_dir}/" \
93 "does not contain updater"
94fi
95
96
Nick Sanders119677f2011-06-03 01:04:08 -070097# Prepare to mount rootfs.
98umount_loop() {
99 sudo umount r || true
100 sudo umount s || true
101 false
102}
103
104echo "Unpack factory install shim partitions"
105./unpack_partitions.sh "${INSTALL_SHIM}"
106
107# Genrate clean mountpoints.
108sudo rm -rf r s
109mkdir -p r s
110
111# Clean ROified filesystem headers, and mount.
112trap "umount_loop" EXIT
113enable_rw_mount part_3
114sudo mount -o loop part_3 r
115sudo mount -o loop part_1 s
116echo "Mount install shim rootfs (partition 3)"
117
Nick Sanders2027ca82011-08-09 00:48:29 -0700118# Get netboot kernel.
119echo "Generating netboot kernel vmlinux.uimg"
120cp "r/boot/vmlinux.uimg" "netboot"
121
122echo "Add lsb-factory"
Nick Sanders119677f2011-06-03 01:04:08 -0700123# Copy factory config file.
124# TODO(nsanders): switch this to u-boot env var config.
125LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc"
126sudo mkdir -p "r/${LSB_FACTORY_DIR}"
127sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
128
129# Clean up mounts.
130trap - EXIT
131sudo umount r s
132sudo rm -rf r s
133
134# Generate an initrd fo u-boot to load.
135gzip -9 -c part_3 > ext2_rootfs.gz
136echo "Generating netboot rootfs initrd.uimg"
137# U-boot's uimg wrapper specifies where we will load the blob into memory.
138# tftp boot's default root address is set to 0x12008000 in legacy_image.bin,
139# so we want to unpack it there.
140mkimage -A arm -O linux -T ramdisk -a 0x12008000 \
141 -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \
142 netboot/initrd.uimg
143
144# Cleanup
145rm -rf ext2_rootfs.gz part_*