|  | #!/usr/bin/env bash | 
|  |  | 
|  | # Copyright 2017 The Fuchsia Authors | 
|  | # | 
|  | # Use of this source code is governed by a MIT-style | 
|  | # license that can be found in the LICENSE file or at | 
|  | # https://opensource.org/licenses/MIT | 
|  |  | 
|  | # Uploads boot image (kernel+ramdisk) into RAM of a hikey960 which is in fastboot | 
|  | #  mode, and then executes image. Requires that the hikey be equiped with UEFI | 
|  | #  bootloader. | 
|  | #  Assumes this is run from the zircon source directory. | 
|  |  | 
|  | ZIRCON_DIR=. | 
|  | ZIRCON_BUILD=${ZIRCON_DIR}/build-zircon-hikey960-arm64 | 
|  |  | 
|  | KERNEL=${ZIRCON_BUILD}/zircon.bin-dtb | 
|  | RAMDISK=${ZIRCON_BUILD}/bootdata.bin | 
|  |  | 
|  | OUT_IMAGE=${ZIRCON_BUILD}/boot.img | 
|  | DTB_FILE=${ZIRCON_DIR}/kernel/target/hikey960/device-tree.dtb | 
|  | DT_IMAGE=${ZIRCON_BUILD}/dt.img | 
|  |  | 
|  | MEMBASE=0x00000000 | 
|  | KERNEL_OFFSET=0x00080000 | 
|  | RAMDISK_OFFSET=0x07c00000 | 
|  | DT_OFFSET=0x07a00000 | 
|  |  | 
|  | CMDLINE="TERM=uart" | 
|  |  | 
|  | function HELP() { | 
|  | echo "Usage: hikey-efi-boot-image [options] <uefi repo path>" | 
|  | echo "  See: /docs/targets/hikey960-uefi.md for more info" | 
|  | echo | 
|  | echo "  -b bootdata     Use specified bootdata file" | 
|  | echo "  -m              Add mexec option to command line" | 
|  | echo "  -h              For help" | 
|  | exit 1 | 
|  | } | 
|  |  | 
|  | while getopts "b:mh" FLAG; do | 
|  | case $FLAG in | 
|  | b) RAMDISK="$OPTARG";; | 
|  | m) CMDLINE+=" netsvc.netboot=true";; | 
|  | h) HELP;; | 
|  | \?) | 
|  | echo unrecognized option | 
|  | HELP | 
|  | ;; | 
|  | esac | 
|  | done | 
|  | shift $((OPTIND-1)) | 
|  |  | 
|  | if [ "$#" -lt 1 ]; then | 
|  | echo "not enough arguments" | 
|  | HELP | 
|  | fi | 
|  |  | 
|  | # where the hikey repos live | 
|  | HIKEY_DIR=$1 | 
|  | MKBOOTIMG=${HIKEY_DIR}/tools-images-hikey960/build-from-source/mkbootimg | 
|  |  | 
|  | if [ ! -e ${MKBOOTIMG} ]; then | 
|  | echo "mkbootimg not found at path ${MKBOOTIMG}" | 
|  | HELP | 
|  | fi | 
|  |  | 
|  | # mkdtimg and mkbootimg can be found at: | 
|  | #  https://github.com/96boards-hikey/tools-images-hikey960/tree/master/build-from-source | 
|  |  | 
|  | echo using mkbootimg at ${MKBOOTIMG} | 
|  | ${MKBOOTIMG} --kernel $KERNEL \ | 
|  | --kernel_offset $KERNEL_OFFSET \ | 
|  | --base $MEMBASE \ | 
|  | --ramdisk_offset $RAMDISK_OFFSET \ | 
|  | --ramdisk "$RAMDISK" \ | 
|  | --tags_offset $DT_OFFSET \ | 
|  | --cmdline "$CMDLINE" \ | 
|  | -o $OUT_IMAGE || exit 1 | 
|  |  | 
|  | fastboot boot $OUT_IMAGE || exit 1 |