[c21cc26] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 | #
|
---|
| 4 | # Copyright (c) 2021 Martin Decky
|
---|
| 5 | # All rights reserved.
|
---|
| 6 | #
|
---|
| 7 | # Redistribution and use in source and binary forms, with or without
|
---|
| 8 | # modification, are permitted provided that the following conditions
|
---|
| 9 | # are met:
|
---|
| 10 | #
|
---|
| 11 | # - Redistributions of source code must retain the above copyright
|
---|
| 12 | # notice, this list of conditions and the following disclaimer.
|
---|
| 13 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | # documentation and/or other materials provided with the distribution.
|
---|
| 16 | # - The name of the author may not be used to endorse or promote products
|
---|
| 17 | # derived from this software without specific prior written permission.
|
---|
| 18 | #
|
---|
| 19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | #
|
---|
| 30 |
|
---|
| 31 | # This script allows to deploy HelenOS conveniently to the HiKey 960 board
|
---|
| 32 | # using the fastboot protocol. The fastboot mechanism is provided as a part
|
---|
| 33 | # of the default UEFI firmware on HiKey 960.
|
---|
| 34 | #
|
---|
| 35 | # The implementation of the fastboot mechanism on HiKey 960 has several
|
---|
| 36 | # quirks and this script tries to accommodate for them:
|
---|
| 37 | #
|
---|
| 38 | # * The boot image must be compressed by GZip. Uncompressed boot images are
|
---|
| 39 | # rejected.
|
---|
| 40 | #
|
---|
| 41 | # * The compressed boot image must end with a device tree blob (even if
|
---|
| 42 | # the device tree is not actually processed). A missing device tree blob
|
---|
| 43 | # crashes the fastboot mechanism.
|
---|
| 44 | #
|
---|
| 45 | # * A RAM disk must be included in the final fastboot image. A missing RAM
|
---|
| 46 | # disk crashes the fastboot mechanism. We use a fake blob for that purpose.
|
---|
| 47 |
|
---|
| 48 | check_error() {
|
---|
| 49 | if [ "$1" -ne "0" ] ; then
|
---|
| 50 | echo
|
---|
| 51 | echo "Error: $2"
|
---|
| 52 |
|
---|
| 53 | exit 1
|
---|
| 54 | fi
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | SCRIPT_DIR="$(readlink -f $(dirname "$0"))"
|
---|
| 58 |
|
---|
| 59 | if [ "$#" -lt "1" ] ; then
|
---|
| 60 | echo "Usage: $0 <image.boot>"
|
---|
| 61 | exit 2
|
---|
| 62 | fi
|
---|
| 63 |
|
---|
| 64 | IMAGE="$1"
|
---|
| 65 | IMAGE_GZ="${IMAGE}.gz"
|
---|
| 66 | IMAGE_GZ_DTB="${IMAGE_GZ}+dtb"
|
---|
| 67 | IMAGE_FASTBOOT="${IMAGE}.fastboot"
|
---|
| 68 |
|
---|
| 69 | if [ ! -f "${IMAGE}" ] ; then
|
---|
| 70 | echo "Error: ${IMAGE} is not a file"
|
---|
| 71 | exit 3
|
---|
| 72 | fi
|
---|
| 73 |
|
---|
| 74 | # Compress the image
|
---|
| 75 | gzip -c "${IMAGE}" > "${IMAGE_GZ}"
|
---|
| 76 | check_error $? "Compressing ${IMAGE}"
|
---|
| 77 |
|
---|
| 78 | # Append the DTB
|
---|
| 79 | cat "${IMAGE_GZ}" "${SCRIPT_DIR}/hi3660-hikey960.dtb" > "${IMAGE_GZ_DTB}"
|
---|
| 80 | check_error $? "Appending DTB to ${IMAGE_GZ}"
|
---|
| 81 |
|
---|
| 82 | # Create the fastboot image with a fake "RAM disk"
|
---|
| 83 | "${SCRIPT_DIR}/mkfastboot" --kernel ${IMAGE_GZ_DTB} --ramdisk "${SCRIPT_DIR}/hikey960.rd" --base 0x0 --tags-addr 0x07a00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000 --output "${IMAGE_FASTBOOT}"
|
---|
| 84 | check_error $? "Converting ${IMAGE_GZ_DTB} to a fastboot image"
|
---|
| 85 |
|
---|
| 86 | # Deploy the fastboot image on a HiKey 960 board connected to the host machine
|
---|
| 87 | fastboot boot "${IMAGE_FASTBOOT}"
|
---|
| 88 | check_error $? "Deploying ${IMAGE_FASTBOOT}"
|
---|