1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#!/bin/bash
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -o nounset
set -o errexit
#@ Various commands to emulate arm code using qemu
#@
#@ Note: this script is not meant to be run as
#@ tools/trusted_cross_toolchains/qemu_tool_arm.sh
#@ but rather as:
#@ toolchain/linux_x86/arm_trusted/qemu_tool_arm.sh
# From a qemu build based on qemu-0.10.1.tar.gz
readonly SDK_ROOT=$(dirname $0)
readonly QEMU=${SDK_ROOT}/qemu-arm
readonly QEMU_STOCK=/usr/bin/qemu-arm
readonly QEMU_JAIL=${SDK_ROOT}
# Hook for adding stuff like timeout wrappers
readonly QEMU_PREFIX_HOOK=${QEMU_PREFIX_HOOK:-}
# NOTE: some useful debugging options for qemu:
# env vars:
# QEMU_STRACE=1
# args:
# -strace
# -d out_asm,in_asm,op,int,exec,cpu
# c.f. cpu_log_items in qemu-XXX/exec.c
readonly QEMU_ARGS="-cpu cortex-a9"
readonly QEMU_ARGS_DEBUG="-d in_asm,int,exec,cpu"
readonly QEMU_ARGS_DEBUG_SR="-d in_asm,int,exec,cpu,service_runtime"
######################################################################
# Helpers
######################################################################
Banner() {
echo "######################################################################"
echo $*
echo "######################################################################"
}
Usage() {
egrep "^#@" $0 | cut --bytes=3-
}
CheckPrerequisites () {
if [[ ! -d ${QEMU_JAIL} ]] ; then
echo "ERROR: no proper root-jail directory found"
exit -1
fi
}
Hints() {
echo
echo "traces can be found in /tmp/qemu.log"
echo "for faster execution disable sel_ldr validation"
echo
}
######################################################################
#@
#@ help
#@
#@ print help for all modes
help () {
Usage
}
#@
#@ run
#@
#@ run emulation using a locally patched qemu
run() {
CheckPrerequisites
exec ${QEMU_PREFIX_HOOK} ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} "$@"
}
#@
#@ run_stock
#@
#@ run emulation using the stock qemu
run_stock() {
exec ${QEMU_PREFIX_HOOK} ${QEMU_STOCK} -L ${QEMU_JAIL} ${QEMU_ARGS} "$@"
}
#@
#@ run_debug
#@
#@ run emulation but also generate trace in /tmp
run_debug() {
Hints
CheckPrerequisites
exec ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} ${QEMU_ARGS_DEBUG} "$@"
}
#@
#@ run_debug_service_runtime
#@
#@ run emulation but also generate trace in /tmp even for service_runtime
run_debug_service_runtime() {
Hints
CheckPrerequisites
exec ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} ${QEMU_ARGS_DEBUG_SR} "$@"
}
#@
#@ install_stock
#@
#@ install stock qemu emulator (for user mode)
install_stock_qemu() {
sudo apt-get install qemu-user
}
######################################################################
if [[ "$0" == *run_under_qemu_arm ]] ; then
run "$@"
elif [[ $# -eq 0 ]] ; then
echo "you must specify a mode on the commandline:"
echo
Usage
exit -1
elif [[ "$(type -t $1)" != "function" ]]; then
echo "ERROR: unknown function '$1'." >&2
echo "For help, try:"
echo " $0 help"
exit 1
else
"$@"
fi
|