blob: 4ae5012f3710240a6a029cf6a1e126572c84f850 [file] [log] [blame]
#!/bin/bash
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
SCRIPT_DIR=$(dirname $0)
FLASHTOOLS_DIR=${SCRIPT_DIR}/flashtools
FBTOOL=${FLASHTOOLS_DIR}/fbtool.py
EXCELSIOR_DEBUG_RESET_TOOL=${FLASHTOOLS_DIR}/debug_board_reset.py
DOWNLOAD_AGENT_CONFIG=${FLASHTOOLS_DIR}/dl_addr.ini
FASTBOOT_TOOL=$(which fastboot)
USERSPACE_ARCH=arm64
if [ -z ${FASTBOOT_TOOL} ]; then
echo "Fastboot is not found on this machine. Install fastboot before running this script"; exit 1
fi
if [ -z ${PRODUCT_OUT} ]; then
echo "PRODUCT_OUT not set, make sure to source board/setup.sh before running this script"; exit 1
fi
reset_excelsior () {
${EXCELSIOR_DEBUG_RESET_TOOL} &
}
reset_excelsior_to_rom() {
echo "Reset Excelsior to ROM"
LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 python3 ${EXCELSIOR_DEBUG_RESET_TOOL} --rom &
}
load_lk_to_ram() {
echo "Load LK to rom and boot LK"
${FBTOOL} -f ${PRODUCT_OUT}/dl_addr.ini
}
erase_mmc() {
echo "Erase EMMC"
${FASTBOOT_TOOL} erase mmc0boot0
${FASTBOOT_TOOL} erase mmc0boot1
}
flash_images() {
pushd ${PRODUCT_OUT}
${FASTBOOT_TOOL} flash mmc0 GPT_EMMC
${FASTBOOT_TOOL} flash mmc0boot0 lk.img
${FASTBOOT_TOOL} flash TEE1 tz.img
${FASTBOOT_TOOL} flash BOOTIMG1 boot.img
${FASTBOOT_TOOL} flash BOOT boot_${USERSPACE_ARCH}.img
${FASTBOOT_TOOL} flash ROOTFS rootfs_${USERSPACE_ARCH}.img
popd
}
ln -sf ${ROOTDIR}/board/flashtools/dl_addr.ini ${PRODUCT_OUT}/dl_addr.ini
reset_excelsior_to_rom
sleep 1
load_lk_to_ram
sleep 1
erase_mmc
sleep 1
flash_images
sleep 1
${FASTBOOT_TOOL} reboot