Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 1 | #!/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. |
| 22 | find_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 | |
| 35 | find_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. |
| 39 | restart_in_chroot_if_needed "$@" |
| 40 | |
| 41 | get_default_board |
| 42 | |
| 43 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 44 | "The board to build an image for." |
| 45 | |
| 46 | # Parse command line. |
| 47 | FLAGS "$@" || exit 1 |
| 48 | eval set -- "${FLAGS_ARGV}" |
| 49 | |
| 50 | set -e |
| 51 | # build_packages artifact output. |
| 52 | SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" |
| 53 | # build_image artifact output. |
| 54 | IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images" |
| 55 | # Canonical install shim name. |
| 56 | INSTALL_SHIM="factory_install_shim.bin" |
| 57 | |
| 58 | cd ${IMAGES_DIR}/${FLAGS_board}/latest |
| 59 | |
| 60 | if [ ! -f "${INSTALL_SHIM}" ]; then |
| 61 | echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!" |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | # Generate staging dir for netboot files. |
| 66 | sudo rm -rf netboot |
| 67 | mkdir -p netboot |
| 68 | |
| 69 | # Get netboot kernel. |
| 70 | echo "Generating netboot kernel vmlinux.uimg" |
| 71 | cp "${SYSROOT}/boot/vmlinux.uimg" "netboot" |
| 72 | |
| 73 | # Get netboot firmware. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 74 | # TODO(nsanders): Set default IP here when userspace |
| 75 | # env modification is available. |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame^] | 76 | # TODO(nsanders): ARM generic doesn't build chromeos-u-boot package. |
| 77 | # When ARM generic goes away, delete the test. |
| 78 | if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ] |
| 79 | echo "Copying netboot firmware legacy_image.bin" |
| 80 | cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot" |
| 81 | else |
| 82 | echo "Skipping: ${SYSROOT}/u-boot/legacy_image.bin firmware not present?" |
| 83 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 84 | |
| 85 | # Prepare to mount rootfs. |
| 86 | umount_loop() { |
| 87 | sudo umount r || true |
| 88 | sudo umount s || true |
| 89 | false |
| 90 | } |
| 91 | |
| 92 | echo "Unpack factory install shim partitions" |
| 93 | ./unpack_partitions.sh "${INSTALL_SHIM}" |
| 94 | |
| 95 | # Genrate clean mountpoints. |
| 96 | sudo rm -rf r s |
| 97 | mkdir -p r s |
| 98 | |
| 99 | # Clean ROified filesystem headers, and mount. |
| 100 | trap "umount_loop" EXIT |
| 101 | enable_rw_mount part_3 |
| 102 | sudo mount -o loop part_3 r |
| 103 | sudo mount -o loop part_1 s |
| 104 | echo "Mount install shim rootfs (partition 3)" |
| 105 | |
| 106 | # Copy factory config file. |
| 107 | # TODO(nsanders): switch this to u-boot env var config. |
| 108 | LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc" |
| 109 | sudo mkdir -p "r/${LSB_FACTORY_DIR}" |
| 110 | sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}" |
| 111 | |
| 112 | # Clean up mounts. |
| 113 | trap - EXIT |
| 114 | sudo umount r s |
| 115 | sudo rm -rf r s |
| 116 | |
| 117 | # Generate an initrd fo u-boot to load. |
| 118 | gzip -9 -c part_3 > ext2_rootfs.gz |
| 119 | echo "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. |
| 123 | mkimage -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 |
| 128 | rm -rf ext2_rootfs.gz part_* |