blob: 7dcd9843948ab8af0d7e7dcb6454ec02295d3039 [file] [log] [blame]
#!/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.
set -e
function HELP() {
echo "Usage: hikey-efi-boot-image [options] <tools-images-hikey960>"
echo " See: /docs/targets/hikey960-uefi.md for more info"
echo
echo " -b build-dir Use specified build directory"
echo " -r ramdisk Use specified ramdisk file"
echo " -m Add mexec option to command line"
echo " -f Flash image, then boot image"
echo " -h For help"
exit 1
}
ZIRCON_SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ZIRCON_DIR="${ZIRCON_SCRIPTS_DIR}/.."
MEMBASE=0x00000000
KERNEL_OFFSET=0x00080000
RAMDISK_OFFSET=0x07c00000
DT_OFFSET=0x07a00000
CMDLINE="TERM=uart"
while getopts "b:r:mfh" FLAG; do
case $FLAG in
b) BUILD_DIR="${OPTARG}";;
r) RAMDISK="${OPTARG}";;
m) CMDLINE+=" netsvc.netboot=true";;
f) FLASH="flash";;
h) HELP;;
\?)
echo unrecognized option
HELP
;;
esac
done
shift $((OPTIND - 1))
if [ "$#" -lt 1 ]; then
echo "not enough arguments"
HELP
fi
BUILD_DIR="${BUILD_DIR:-/build-zircon-hikey960-arm64}"
KERNEL="${BUILD_DIR}/zircon.bin-dtb"
RAMDISK="${RAMDISK:-${BUILD_DIR}/bootdata.bin}"
OUT_IMAGE="${BUILD_DIR}/boot.img"
DTB_FILE="${ZIRCON_DIR}/kernel/target/hikey960/device-tree.dtb"
DT_IMAGE="${BUILD_DIR}/dt.img"
MKBOOTIMG="${1}/build-from-source/mkbootimg"
if [ ! -e "${MKBOOTIMG}" ]; then
echo "mkbootimg not found at path ${MKBOOTIMG}"
HELP
fi
# tools-images-hikey960 found at:
# https://github.com/96boards-hikey/tools-images-hikey960
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
fastboot $FLASH boot $OUT_IMAGE
if [ -n "${FLASH}" ]; then
# Can't guarantee that the target has written image to flash before the
# fastboot command completes, so short delay here before reboot.
sleep 1
fastboot reboot
fi