Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Chris Sosa | 2eb73c0 | 2011-09-01 18:48:38 -0700 | [diff] [blame^] | 3 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 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 |
Brian Harring | d5d5dbf | 2011-07-11 16:36:21 -0700 | [diff] [blame] | 36 | . "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; } |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 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." |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 45 | DEFINE_string image "" "Path to the image to use" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 46 | |
| 47 | # Parse command line. |
| 48 | FLAGS "$@" || exit 1 |
| 49 | eval set -- "${FLAGS_ARGV}" |
| 50 | |
| 51 | set -e |
| 52 | # build_packages artifact output. |
| 53 | SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" |
| 54 | # build_image artifact output. |
| 55 | IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 56 | |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 57 | if [ -n "${FLAGS_image}" ]; then |
| 58 | cd $(dirname "${FLAGS_image}") |
| 59 | INSTALL_SHIM=$(basename "${FLAGS_image}") |
| 60 | else |
| 61 | cd ${IMAGES_DIR}/${FLAGS_board}/latest |
| 62 | # Canonical install shim name. |
| 63 | INSTALL_SHIM="factory_install_shim.bin" |
| 64 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 65 | |
| 66 | if [ ! -f "${INSTALL_SHIM}" ]; then |
| 67 | echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!" |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | # Generate staging dir for netboot files. |
| 72 | sudo rm -rf netboot |
| 73 | mkdir -p netboot |
| 74 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 75 | # Get netboot firmware. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 76 | # TODO(nsanders): Set default IP here when userspace |
| 77 | # env modification is available. |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 78 | # TODO(nsanders): ARM generic doesn't build chromeos-u-boot package. |
| 79 | # When ARM generic goes away, delete the test. |
Elly Jones | c871ba2 | 2011-06-22 14:58:55 -0400 | [diff] [blame] | 80 | if [ -r "${SYSROOT}/u-boot/legacy_image.bin" ]; then |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 81 | echo "Copying netboot firmware legacy_image.bin" |
| 82 | cp "${SYSROOT}/u-boot/legacy_image.bin" "netboot" |
Nick Sanders | fa28c16 | 2011-07-19 01:48:57 -0700 | [diff] [blame] | 83 | cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot" |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 84 | else |
Nick Sanders | daebdee | 2011-08-02 03:42:04 -0700 | [diff] [blame] | 85 | echo "Skipping legacy fw: ${SYSROOT}/u-boot/legacy_image.bin not present?" |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 86 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 87 | |
Nick Sanders | daebdee | 2011-08-02 03:42:04 -0700 | [diff] [blame] | 88 | # Get HWID bundle if available. |
Hung-Te Lin | 0288219 | 2011-08-30 19:45:32 +0800 | [diff] [blame] | 89 | # TODO(hungte) Move this to chromite because HWID bundles should be archived for |
| 90 | # every factory archive instead of builds with netboot. |
Nick Sanders | daebdee | 2011-08-02 03:42:04 -0700 | [diff] [blame] | 91 | hwid_dir="usr/share/chromeos-hwid" |
| 92 | sudo rm -rf hwid |
| 93 | mkdir -p hwid |
Hung-Te Lin | 0288219 | 2011-08-30 19:45:32 +0800 | [diff] [blame] | 94 | if hwid_files=$(ls "${SYSROOT}/${hwid_dir}/" | grep ^hwid_bundle); then |
| 95 | echo "Copying HWID bundles: $hwid_files" |
| 96 | for file in $hwid_files; do |
Nick Sanders | daebdee | 2011-08-02 03:42:04 -0700 | [diff] [blame] | 97 | cp "${SYSROOT}/${hwid_dir}/${file}" "hwid/" |
| 98 | done |
| 99 | else |
| 100 | echo "Skipping HWID: ${SYSROOT}/${hwid_dir}/" \ |
Hung-Te Lin | 0288219 | 2011-08-30 19:45:32 +0800 | [diff] [blame] | 101 | "does not contain HWID bundle" |
Nick Sanders | daebdee | 2011-08-02 03:42:04 -0700 | [diff] [blame] | 102 | fi |
| 103 | |
| 104 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 105 | # Prepare to mount rootfs. |
| 106 | umount_loop() { |
| 107 | sudo umount r || true |
| 108 | sudo umount s || true |
| 109 | false |
| 110 | } |
| 111 | |
| 112 | echo "Unpack factory install shim partitions" |
| 113 | ./unpack_partitions.sh "${INSTALL_SHIM}" |
| 114 | |
| 115 | # Genrate clean mountpoints. |
| 116 | sudo rm -rf r s |
| 117 | mkdir -p r s |
| 118 | |
| 119 | # Clean ROified filesystem headers, and mount. |
| 120 | trap "umount_loop" EXIT |
| 121 | enable_rw_mount part_3 |
| 122 | sudo mount -o loop part_3 r |
| 123 | sudo mount -o loop part_1 s |
| 124 | echo "Mount install shim rootfs (partition 3)" |
| 125 | |
Nick Sanders | 2027ca8 | 2011-08-09 00:48:29 -0700 | [diff] [blame] | 126 | # Get netboot kernel. |
| 127 | echo "Generating netboot kernel vmlinux.uimg" |
| 128 | cp "r/boot/vmlinux.uimg" "netboot" |
| 129 | |
| 130 | echo "Add lsb-factory" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 131 | # Copy factory config file. |
| 132 | # TODO(nsanders): switch this to u-boot env var config. |
| 133 | LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc" |
| 134 | sudo mkdir -p "r/${LSB_FACTORY_DIR}" |
| 135 | sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}" |
| 136 | |
| 137 | # Clean up mounts. |
| 138 | trap - EXIT |
| 139 | sudo umount r s |
| 140 | sudo rm -rf r s |
| 141 | |
| 142 | # Generate an initrd fo u-boot to load. |
| 143 | gzip -9 -c part_3 > ext2_rootfs.gz |
| 144 | echo "Generating netboot rootfs initrd.uimg" |
| 145 | # U-boot's uimg wrapper specifies where we will load the blob into memory. |
| 146 | # tftp boot's default root address is set to 0x12008000 in legacy_image.bin, |
| 147 | # so we want to unpack it there. |
| 148 | mkimage -A arm -O linux -T ramdisk -a 0x12008000 \ |
| 149 | -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \ |
| 150 | netboot/initrd.uimg |
| 151 | |
| 152 | # Cleanup |
| 153 | rm -rf ext2_rootfs.gz part_* |