| #!/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. |
| |
| 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) |
| |
| 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" |
| ${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 mmc0 |
| ${FASTBOOT_TOOL} erase mmc0boot0 |
| ${FASTBOOT_TOOL} erase mmc0boot1 |
| } |
| |
| flash_images() { |
| pushd ${PRODUCT_OUT} |
| ${FASTBOOT_TOOL} erase mmc0 |
| ${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 ROOTFS rootfs.img |
| popd |
| } |
| |
| ln -sf ${SCRIPT_DIR}/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 |