Skip to content

Instantly share code, notes, and snippets.

@compenguy
compenguy / stacktrace.sh
Created March 29, 2017 23:46
Getting a stack trace in bash
function get_stack () {
STACK=""
local i message="${1:-""}"
local stack_size=${#FUNCNAME[@]}
# to avoid noise we start with 1 to skip the get_stack function
for (( i=1; i<$stack_size; i++ )); do
local func="${FUNCNAME[$i]}"
[ x$func = x ] && func=MAIN
local linen="${BASH_LINENO[$(( i - 1 ))]}"
local src="${BASH_SOURCE[$i]}"
@compenguy
compenguy / command_exists.sh
Created April 2, 2017 16:24
Test for command existence in sh/bash
function command_exists() {
command -v $1 >/dev/null 2>&1
}
if command_exists expect; then
echo "The \'expect\' utility exists!"
fi
@compenguy
compenguy / init_lede.sh
Created April 2, 2017 17:59
Super-rough script to generate a UEFI-ready LEDE disk image and boot QEMU with it
#!/bin/bash
LEDE_KERNEL="${HOME}/Downloads/lede-17.01.0-r3205-59508e3-x86-64-vmlinuz"
LEDE_KERNEL_URL="https://downloads.lede-project.org/releases/17.01.0/targets/x86/64/lede-17.01.0-r3205-59508e3-x86-64-vmlinuz"
LEDE_ROOT_IMG_GZ="${HOME}/Downloads/lede-17.01.0-r3205-59508e3-x86-64-combined-ext4.img.gz"
LEDE_ROOT_IMG=""
LEDE_ROOT_IMG_URL="https://downloads.lede-project.org/releases/17.01.0/targets/x86/64/lede-17.01.0-r3205-59508e3-x86-64-generic-rootfs.tar.gz"
QEMU_RAM_MEG="1024"
QEMU_DISK_IMG="${HOME}/sda.img"
@compenguy
compenguy / OpenOCD+BusBlasterv4.md
Last active July 27, 2021 20:13
OpenOCD + BusBlaster v4

Setup

  1. Install OpenOCD.
  2. Plug the JTAG cable into the Bus Blaster's adapter board and the target.
  3. Run
arm-none-eabi-gdb path/to/firmware.elf -ex 'target remote | openocd -c "gdb_port pipe;" -f ../jtag/busblaster.cfg'

(adjust paths as appropriate) to launch gdb.