#!/bin/bash
## script to trace a binary via CoreSight.

## set variables
source=etm0
sink=tmc_etr0
cpucore=0
binary=~/hikey_snapshot/testprogram

cd /sys/bus/coresight/devices/

##start trace
echo "1" | sudo tee $sink/enable_sink > /dev/null
echo "1" | sudo tee $source/enable_source > /dev/null

##run binary on chosen core
taskset -c $cpucore $binary

##stop trace
echo "0" | sudo tee $source/enable_source > /dev/null
echo "0" | sudo tee $sink/enable_sink > /dev/null

##reset all earlier configurations
echo "1" | sudo tee $source/reset > /dev/null

##collect trace
sudo dd if=/dev/$sink of=~/hikey_snapshot/cstrace.bin
