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 | |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame^] | 15 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
Brian Harring | d5d5dbf | 2011-07-11 16:36:21 -0700 | [diff] [blame] | 16 | . "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; } |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame^] | 17 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 18 | # Script must be run inside the chroot. |
| 19 | restart_in_chroot_if_needed "$@" |
| 20 | |
| 21 | get_default_board |
| 22 | |
| 23 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 24 | "The board to build an image for." |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 25 | DEFINE_string image "" "Path to the image to use" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 26 | |
| 27 | # Parse command line. |
| 28 | FLAGS "$@" || exit 1 |
| 29 | eval set -- "${FLAGS_ARGV}" |
| 30 | |
| 31 | set -e |
| 32 | # build_packages artifact output. |
| 33 | SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" |
| 34 | # build_image artifact output. |
| 35 | IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 36 | |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 37 | if [ -n "${FLAGS_image}" ]; then |
| 38 | cd $(dirname "${FLAGS_image}") |
| 39 | INSTALL_SHIM=$(basename "${FLAGS_image}") |
| 40 | else |
| 41 | cd ${IMAGES_DIR}/${FLAGS_board}/latest |
| 42 | # Canonical install shim name. |
| 43 | INSTALL_SHIM="factory_install_shim.bin" |
| 44 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 45 | |
| 46 | if [ ! -f "${INSTALL_SHIM}" ]; then |
| 47 | echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!" |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | # Generate staging dir for netboot files. |
| 52 | sudo rm -rf netboot |
| 53 | mkdir -p netboot |
| 54 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 55 | # Get netboot firmware. |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 56 | # TODO(nsanders): Set default IP here when userspace |
| 57 | # env modification is available. |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 58 | # TODO(nsanders): ARM generic doesn't build chromeos-u-boot package. |
| 59 | # When ARM generic goes away, delete the test. |
Stefan Reinauer | b392153 | 2011-09-07 16:34:02 -0700 | [diff] [blame] | 60 | if [ -r "${SYSROOT}/firmware/legacy_image.bin" ]; then |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 61 | echo "Copying netboot firmware legacy_image.bin" |
Stefan Reinauer | b392153 | 2011-09-07 16:34:02 -0700 | [diff] [blame] | 62 | cp "${SYSROOT}/firmware/legacy_image.bin" "netboot" |
Nick Sanders | fa28c16 | 2011-07-19 01:48:57 -0700 | [diff] [blame] | 63 | cp "${GCLIENT_ROOT}/chroot/usr/bin/update_firmware_vars.py" "netboot" |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 64 | else |
Stefan Reinauer | b392153 | 2011-09-07 16:34:02 -0700 | [diff] [blame] | 65 | echo "Skipping legacy fw: ${SYSROOT}/firmware/legacy_image.bin not present?" |
Grant Grundler | 7c4328a | 2011-06-22 10:24:42 -0700 | [diff] [blame] | 66 | fi |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 67 | |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 68 | # Prepare to mount rootfs. |
| 69 | umount_loop() { |
| 70 | sudo umount r || true |
| 71 | sudo umount s || true |
| 72 | false |
| 73 | } |
| 74 | |
| 75 | echo "Unpack factory install shim partitions" |
| 76 | ./unpack_partitions.sh "${INSTALL_SHIM}" |
| 77 | |
| 78 | # Genrate clean mountpoints. |
| 79 | sudo rm -rf r s |
| 80 | mkdir -p r s |
| 81 | |
| 82 | # Clean ROified filesystem headers, and mount. |
| 83 | trap "umount_loop" EXIT |
| 84 | enable_rw_mount part_3 |
| 85 | sudo mount -o loop part_3 r |
| 86 | sudo mount -o loop part_1 s |
| 87 | echo "Mount install shim rootfs (partition 3)" |
| 88 | |
Nick Sanders | 2027ca8 | 2011-08-09 00:48:29 -0700 | [diff] [blame] | 89 | # Get netboot kernel. |
| 90 | echo "Generating netboot kernel vmlinux.uimg" |
| 91 | cp "r/boot/vmlinux.uimg" "netboot" |
| 92 | |
| 93 | echo "Add lsb-factory" |
Nick Sanders | 119677f | 2011-06-03 01:04:08 -0700 | [diff] [blame] | 94 | # Copy factory config file. |
| 95 | # TODO(nsanders): switch this to u-boot env var config. |
| 96 | LSB_FACTORY_DIR="mnt/stateful_partition/dev_image/etc" |
| 97 | sudo mkdir -p "r/${LSB_FACTORY_DIR}" |
| 98 | sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}" |
| 99 | |
| 100 | # Clean up mounts. |
| 101 | trap - EXIT |
| 102 | sudo umount r s |
| 103 | sudo rm -rf r s |
| 104 | |
| 105 | # Generate an initrd fo u-boot to load. |
| 106 | gzip -9 -c part_3 > ext2_rootfs.gz |
| 107 | echo "Generating netboot rootfs initrd.uimg" |
| 108 | # U-boot's uimg wrapper specifies where we will load the blob into memory. |
| 109 | # tftp boot's default root address is set to 0x12008000 in legacy_image.bin, |
| 110 | # so we want to unpack it there. |
| 111 | mkimage -A arm -O linux -T ramdisk -a 0x12008000 \ |
| 112 | -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \ |
| 113 | netboot/initrd.uimg |
| 114 | |
| 115 | # Cleanup |
| 116 | rm -rf ext2_rootfs.gz part_* |