blob: 9e5c61061e3471c4ee018b7fb06adeaee25e2466 [file] [log] [blame]
#!/bin/bash
#
# Copyright 2020 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="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DRAM_SIZE=2G
function die {
echo "$@" >/dev/stderr
exit 1
}
function load_fastboot {
local files_dir="$1"
python3 "${files_dir}/flashtools/debug_board_reset.py" --rom &
sleep 1
pushd "${files_dir}"
python3 "${files_dir}/flashtools/fbtool.py" -f "${files_dir}/dl_addr.ini"
sleep 1
popd
}
function ensure_files_present {
local found_all_files=true
local files_dir="$1"; shift
local link_dir="$1"; shift
local files=(
"dl_addr.ini"
"flashtools/debug_board_reset.py"
"flashtools/dl_addr.ini"
"flashtools/fbtool.py"
"lk.bin"
)
if [[ "${PRODUCT_OUT}" == "${files_dir}" ]]; then
ln -sf "${ROOTDIR}/board/flashtools/dl_addr.ini" "${files_dir}/dl_addr.ini"
rm -f "${files_dir}/flashtools"
ln -sf "${ROOTDIR}/board/flashtools" "${files_dir}/flashtools"
fi
for file in "${files_dir}/*"; do
ln -sf ${file} "${link_dir}"
done
# LK needs to be handled separatedly for now.
if [[ -f "${files_dir}/lk_${DRAM_SIZE}.bin" ]]; then
ln -sf "${files_dir}/lk_${DRAM_SIZE}.bin" "${link_dir}/lk.bin"
else
echo "lk_${DRAM_SIZE}.bin is missing!"
found_all_files=""
fi
for file in "${files[@]}"; do
if [[ ! -f "${link_dir}/${file}" ]]; then
echo "${file} is missing!"
found_all_files=""
fi
done
if [[ -z "${found_all_files}" ]]; then
die "Required files are missing. Can not continue."
fi
}
function main {
local usage=$(cat <<EOF
Usage: enable_lk_fastboot.sh [-d <files_dir>]
-d <files_dir> Boot LK with files from <files_dir> (defaults to current dir)
-o Boot LK on the old boards.
EOF
)
local files_dir # -d <files_dir>
local lk_fastboot # -l
local args=$(getopt hod: $*)
set -- $args
for i; do
case "$1" in
-d) # files dir
files_dir="$2"
shift 2
;;
-o) # old board
DRAM_SIZE=1G
shift 1
;;
--) # end of args
shift
break
;;
*) # help
die "${usage}"
;;
esac
done
if [[ -z "${files_dir}" ]]; then
if [[ -n "${PRODUCT_OUT}" ]]; then
files_dir="${PRODUCT_OUT}"
else
files_dir="${SCRIPT_DIR}"
fi
fi
link_dir=$(mktemp -d)
trap 'rm -rf ${link_dir}' EXIT
ensure_files_present "${files_dir}" "${link_dir}"
load_fastboot "${link_dir}"
}
main "$@"