Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug tools #118

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ build-lpc55-nk3xn:
- docker
stage: build
script:
- echo "This script should not be that long. These commands should be kept in Makefile or other runner"
- rustup target add thumbv8m.main-none-eabi
- rustup +nightly-2022-11-13 target add thumbv8m.main-none-eabi
- mkdir -p artifacts nk3xn
Expand All @@ -60,6 +61,7 @@ build-lpc55-nk3xn:
- make -C runners/embedded build-nk3xn
- cp ./runners/embedded/artifacts/runner-lpc55-nk3xn.bin nk3xn/firmware-nk3xn-lpc55-$VERSION.bin
- zip nk3xn-raw.zip nk3xn/*
- zip artifacts/nk3xn-report.zip ./runners/embedded/artifacts/*extra* ./runners/embedded/artifacts/*symbols*
- cp nk3xn-raw.zip artifacts
after_script:
- git archive --format zip --output artifacts/nitrokey-3-firmware.zip --prefix nitrokey-3-firmware/ HEAD
Expand All @@ -78,6 +80,7 @@ build-nrf52-nk3mini:
- docker
stage: build
script:
- echo "This script should not be that long. These commands should be kept in Makefile or other runner"
- apt-get install -y python3 python3-toml zip
- rustup target add thumbv7em-none-eabihf
- rustup +nightly-2022-11-13 target add thumbv7em-none-eabihf
Expand Down
25 changes: 20 additions & 5 deletions runners/embedded/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CFG_VAL_SOC = $(shell python3 -c 'import toml; print(toml.load("$(CFG_PATH)")["p
ARTIFACTS = artifacts
LOG ?= build-$(BUILD_ID).err.log
SYMBOLS ?= symbols-$(BUILD_ID).txt
EXTRA ?= extra-$(BUILD_ID).txt

# input files and outputs
SRCS = $(shell find src -name "*.rs" )
Expand Down Expand Up @@ -120,11 +121,14 @@ clean-all:
rm -f firmware.hex mbr.hex bootloader.hex
rm -rf artifacts cfg.toml

elf-size-analyze.py:
wget https://raw.githubusercontent.com/jedrzejboczar/elf-size-analyze/master/elf-size-analyze.py

###############################################################################
#### actual build, clean, reset, program targets
###############################################################################

build: build-banner $(SRCS) check-var-BOARD check-var-BUILD_PROFILE check-var-SOC
build: build-banner $(SRCS) check-var-BOARD check-var-BUILD_PROFILE check-var-SOC elf-size-analyze.py

cargo --version

Expand All @@ -138,16 +142,27 @@ build: build-banner $(SRCS) check-var-BOARD check-var-BUILD_PROFILE check-var-SO
--features $(COMMA_FEATURES) \
--quiet

cargo install cargo-bloat
cargo bloat --release --target $(TARGET) \
--features $(COMMA_FEATURES) \
-n 50 > $(EXTRA)-cargo-bloat
cargo bloat --release --target $(TARGET) \
--features $(COMMA_FEATURES) \
--crates -n 50 >> $(EXTRA)-cargo-bloat

cp $(RAW_OUT) ./$(OUT_ELF)

$(GNU_TARGET)-nm ./$(OUT_ELF) | grep ' [ABbDdRrTt] ' | sort | c++filt > $(SYMBOLS)

python3 ./elf-size-analyze.py -t arm-none-eabi- ./$(OUT_ELF) -R -H -m 50 -w 0 > $(EXTRA)-sizes-detailed
python3 ./elf-size-analyze.py -t arm-none-eabi- ./$(OUT_ELF) -F -H -m 100 -w 0 >> $(EXTRA)-sizes-detailed
$(GNU_TARGET)-nm ./$(OUT_ELF) | grep ' [ABbDdRrTt] ' | sort | c++filt > $(SYMBOLS)
$(GNU_TARGET)-nm -B -l -r --size-sort --print-size -t d ./$(OUT_ELF) | grep ' [ABbDdRrTt] ' | sort -k2rn | c++filt > $(EXTRA)-sizes
arm-none-eabi-objdump -t ./$(OUT_ELF) | grep -Fv ".text" | sort -k5rn | c++filt > $(EXTRA)-objdump-sizes
cat $(GNU_TARGET)-arch-symbols.txt >> $(SYMBOLS)

$(GNU_TARGET)-objcopy -O binary ./$(OUT_ELF) ./$(OUT_BIN)
$(GNU_TARGET)-objcopy -O ihex ./$(OUT_ELF) ./$(OUT_IHEX)
$(GNU_TARGET)-readelf -l ./$(OUT_ELF) | grep LOAD
$(GNU_TARGET)-readelf -l ./$(OUT_ELF) | grep LOAD | tee $(EXTRA)-load

clean: clean-banner check-var-BOARD check-var-BUILD_PROFILE
rm -f ./$(OUT_BIN) ./$(OUT_ELF) ./$(OUT_IHEX) $(RAW_OUT) $(SYMBOLS) $(LOG)
rm -f ./$(OUT_BIN) ./$(OUT_ELF) ./$(OUT_IHEX) $(RAW_OUT) $(SYMBOLS) $(LOG) $(EXTRA)*

20 changes: 20 additions & 0 deletions runners/lpc55/debug/print_msp.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set history save on
set confirm off
set pagination off

define lmsp
while (1)
# f
i r msp
step 100
end
end


# dir src/
target extended-remote :2331
# file runner-lpc55-nk3xn.elf
# load runner-lpc55-nk3xn.elf
monitor reset
# file artifacts/runner-lpc55-nk3xn.elf
source print_msp.py
24 changes: 24 additions & 0 deletions runners/lpc55/debug/print_msp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import gdb


class WalkMSP(gdb.Command):

def __init__(self):
super(WalkMSP, self).__init__("walkmsp", gdb.COMMAND_USER)

def invoke(self, args, from_tty):
print(args)
while True:
try:
# gdb.execute("f")
gdb.execute("p/x $msp")
gdb.execute("stepi 100")
except KeyboardInterrupt:
break
except gdb.error:
continue
except Exception:
pass


WalkMSP()
20 changes: 20 additions & 0 deletions update/Robin-scripts/lpc55-builder/scripts/usbwait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

echo -n "Waiting for USB device: $@ "
sleep 1
for i in `seq 1 10`
do
for id in $@
do
if lsusb -d $id
then
exit 0
fi
echo -n "."
sleep 1
done
done

echo
echo "Error: Device not found" >&2
exit 1
43 changes: 43 additions & 0 deletions update/Robin-scripts/lpc55-builder/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# test.sh is the relevant script
# you’ll have to update the variables
# and you have to update the jlink-erase-reset.txt to point to the provisioner


# fully erase via debugger
# flash old v1.2.2 provisioner via debugger
# reset via debugger and boot into firmware
# provisioner firmware sets up file system
# reboot to bootloader
# flash test firmware via bootloader
# reboot into firmware mode

RUNNER=/home/sz/work/nitrokey-3-firmware/runners/embedded
BINARY=$(RUNNER)/artifacts/runner-lpc55-nk3xn.bin
# LPC55_BUILDER=/tmp/lpc55-builder
LPC55_BUILDER=$(PWD)

all: prov
-rm "$(BINARY)"
cd $(RUNNER) && git checkout -- Cargo.lock
# cd $(RUNNER) && cargo update -p trussed
# cd $(RUNNER) && cargo update
make -C "$(RUNNER)" build-nk3xn FEATURES=alpha
# make -C "$(RUNNER)" build-nk3xn FEATURES=opcard,trussed/clients-3

ls -lh /tmp/provisioner-nk3xn-lpc55-v1.2.2.bin
JLinkExe -device LPC55S69_M33_0 -if SWD -autoconnect 1 -speed 4000 -CommandFile "$(LPC55_BUILDER)"/jlink-erase-reset.txt
./scripts/usbwait.sh 20a0:42b2

nitropy nk3 reboot --bootloader
./scripts/usbwait.sh 20a0:42dd 1fc9:0021

lpc55 write-flash "$(BINARY)"
sha256sum "$(BINARY)"
lpc55 reboot
./scripts/usbwait.sh 20a0:42b2

# alias for the full path
prov: /tmp/provisioner-nk3xn-lpc55-v1.2.2.bin

/tmp/provisioner-nk3xn-lpc55-v1.2.2.bin:
cp ../provisioner-nk3xn-lpc55-v1.2.2.bin /tmp/