Skip to content

Commit

Permalink
util: Add disk flashing utility
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsc96 committed Oct 23, 2024
1 parent ef6dea6 commit 1b1d64b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
23 changes: 23 additions & 0 deletions util/flash_disk.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Cheshire disk flashing script for use with GDB.

target extended-remote localhost:3333

# Load flashing program
load sw/boot/flash.spm.elf

# Load disk image to DRAM
eval "restore %s binary 0x80000000", $img

# Write flash parameters to scratch regs
set *0x03000000=$target
set *0x03000004=0x80000000
set *0x03000008=$offs
set *0x0300000c=$len

# Launch payload and quit after return
continue
quit
33 changes: 33 additions & 0 deletions util/flash_disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env bash
#
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Cheshire disk flashing script invoking OpenOCD and GDB.
#
# Arguments:
# $1: target board
# $2: target disk
# $3: (optional): disk image
# $4: (optional): copy length
# $5: (optional): copy offset

set -e

# Determine the image name and size
img=${3:-sw/boot/linux.${1}.gpt.bin}
# Ensure the image exists and determine rounded-up size
len=${4:-$(stat -c%s ${img})}
len=$((len/512+1))

# Run OpenOCD and GDB
openocd -f util/openocd.${1}.tcl &
sleep 2
riscv64-unknown-elf-gdb --batch \
-ex "set \$target = ${2:-1}" \
-ex "set \$img = \"${img}\"" \
-ex "set \$len = ${len}" \
-ex "set \$offs = ${5:-0}" \
-ex "source util/flash_disk.gdb"
wait
8 changes: 7 additions & 1 deletion util/openocd.common.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ riscv set_command_timeout_sec 120

riscv set_prefer_sba off

# Exit when debugger detaches
$_TARGETNAME configure -event gdb-detach {
echo "GDB detached; ending debugging session."
shutdown
}

# Try enabling address translation (only works for newer versions)
if { [catch { riscv set_enable_virtual on } ] } {
echo "Warning: This version of OpenOCD does not support address translation.\
Expand All @@ -31,4 +37,4 @@ if { [catch { riscv set_enable_virtual on } ] } {

init
halt
echo "Ready for Remote Connections"
echo "Ready for Remote Connections."

0 comments on commit 1b1d64b

Please sign in to comment.