| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # SPDX-FileCopyrightText: 2021 Martin Decky
|
|---|
| 4 | #
|
|---|
| 5 | # SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 6 | #
|
|---|
| 7 |
|
|---|
| 8 | # This script allows to deploy HelenOS conveniently to the HiKey 960 board
|
|---|
| 9 | # using the fastboot protocol. The fastboot mechanism is provided as a part
|
|---|
| 10 | # of the default UEFI firmware on HiKey 960.
|
|---|
| 11 | #
|
|---|
| 12 | # The implementation of the fastboot mechanism on HiKey 960 has several
|
|---|
| 13 | # quirks and this script tries to accommodate for them:
|
|---|
| 14 | #
|
|---|
| 15 | # * The boot image must be compressed by GZip. Uncompressed boot images are
|
|---|
| 16 | # rejected.
|
|---|
| 17 | #
|
|---|
| 18 | # * The compressed boot image must end with a device tree blob (even if
|
|---|
| 19 | # the device tree is not actually processed). A missing device tree blob
|
|---|
| 20 | # crashes the fastboot mechanism.
|
|---|
| 21 | #
|
|---|
| 22 | # * A RAM disk must be included in the final fastboot image. A missing RAM
|
|---|
| 23 | # disk crashes the fastboot mechanism. We use a fake blob for that purpose.
|
|---|
| 24 |
|
|---|
| 25 | check_error() {
|
|---|
| 26 | if [ "$1" -ne "0" ] ; then
|
|---|
| 27 | echo
|
|---|
| 28 | echo "Error: $2"
|
|---|
| 29 |
|
|---|
| 30 | exit 1
|
|---|
| 31 | fi
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | SCRIPT_DIR="$(readlink -f $(dirname "$0"))"
|
|---|
| 35 |
|
|---|
| 36 | if [ "$#" -lt "1" ] ; then
|
|---|
| 37 | echo "Usage: $0 <image.boot>"
|
|---|
| 38 | exit 2
|
|---|
| 39 | fi
|
|---|
| 40 |
|
|---|
| 41 | IMAGE="$1"
|
|---|
| 42 | IMAGE_GZ="${IMAGE}.gz"
|
|---|
| 43 | IMAGE_GZ_DTB="${IMAGE_GZ}+dtb"
|
|---|
| 44 | IMAGE_FASTBOOT="${IMAGE}.fastboot"
|
|---|
| 45 |
|
|---|
| 46 | if [ ! -f "${IMAGE}" ] ; then
|
|---|
| 47 | echo "Error: ${IMAGE} is not a file"
|
|---|
| 48 | exit 3
|
|---|
| 49 | fi
|
|---|
| 50 |
|
|---|
| 51 | # Compress the image
|
|---|
| 52 | gzip -c "${IMAGE}" > "${IMAGE_GZ}"
|
|---|
| 53 | check_error $? "Compressing ${IMAGE}"
|
|---|
| 54 |
|
|---|
| 55 | # Append the DTB
|
|---|
| 56 | cat "${IMAGE_GZ}" "${SCRIPT_DIR}/hi3660-hikey960.dtb" > "${IMAGE_GZ_DTB}"
|
|---|
| 57 | check_error $? "Appending DTB to ${IMAGE_GZ}"
|
|---|
| 58 |
|
|---|
| 59 | # Create the fastboot image with a fake "RAM disk"
|
|---|
| 60 | "${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}"
|
|---|
| 61 | check_error $? "Converting ${IMAGE_GZ_DTB} to a fastboot image"
|
|---|
| 62 |
|
|---|
| 63 | # Deploy the fastboot image on a HiKey 960 board connected to the host machine
|
|---|
| 64 | fastboot boot "${IMAGE_FASTBOOT}"
|
|---|
| 65 | check_error $? "Deploying ${IMAGE_FASTBOOT}"
|
|---|