From ca8ba744ace89a98d06a346a5933d0ce9c09b11f Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Tue, 29 Apr 2025 21:00:33 +0200 Subject: [PATCH] fw/defaultapp: Introduce simple default app To retain the default behaviour from Bellatrix, we introduce a simple default app. If used on flash app slot 0 we get the same behaviour as in Bellatrix, that is, waiting for an app from the client. --- hw/application_fpga/fw/README.md | 3 + hw/application_fpga/fw/defaultapp/Makefile | 73 ++++++++++++++++++++++ hw/application_fpga/fw/defaultapp/main.c | 19 ++++++ 3 files changed, 95 insertions(+) create mode 100644 hw/application_fpga/fw/defaultapp/Makefile create mode 100644 hw/application_fpga/fw/defaultapp/main.c diff --git a/hw/application_fpga/fw/README.md b/hw/application_fpga/fw/README.md index 9058514..dc1476e 100644 --- a/hw/application_fpga/fw/README.md +++ b/hw/application_fpga/fw/README.md @@ -794,6 +794,9 @@ $ picocom /dev/ttyACM1 or similar. +- `fw/defaultapp`: Immediately resets the TKey with the intention to + start an app from the client, replicating the behaviour of earlier + generations. - `fw/testapp`: Runs through a couple of tests that are now impossible to do in the `testfw`. - `fw/reset_test`: Interactively test different reset scenarios. diff --git a/hw/application_fpga/fw/defaultapp/Makefile b/hw/application_fpga/fw/defaultapp/Makefile new file mode 100644 index 0000000..fd904d3 --- /dev/null +++ b/hw/application_fpga/fw/defaultapp/Makefile @@ -0,0 +1,73 @@ +P := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +LIBDIR ?= ../../tkey-libs +OBJCOPY ?= llvm-objcopy +CC = clang +CFLAGS = \ + -target riscv32-unknown-none-elf \ + -march=rv32iczmmul \ + -mabi=ilp32 \ + -mcmodel=medany \ + -static \ + -std=gnu99 \ + -Os \ + -ffast-math \ + -fno-common \ + -fno-builtin-printf \ + -fno-builtin-putchar \ + -fno-builtin-memcpy \ + -nostdlib \ + -mno-relax \ + -Wall \ + -Wpedantic \ + -Wno-language-extension-token \ + -Werror \ + -flto \ + -g \ + -I $(LIBDIR)/include \ + -I $(LIBDIR) + +AS = clang + +ASFLAGS = \ + -target riscv32-unknown-none-elf \ + -march=rv32iczmmul \ + -mabi=ilp32 \ + -mno-relax + +LDFLAGS = \ + -T $(LIBDIR)/app.lds \ + -L $(LIBDIR) -lcrt0 -lcommon -lmonocypher -lblake2s + +.PHONY: all +all: defaultapp.bin + +# Turn elf into bin for device +%.bin: %.elf + $(OBJCOPY) --input-target=elf32-littleriscv --output-target=binary $^ $@ + chmod a-x $@ + +.PHONY: tkey-libs +tkey-libs: + make -C $(LIBDIR) + +DEFAULTAPP_FMTFILES = *.[ch] + +DEFAULTAPP_OBJS = \ + $(P)/main.o \ + ../testapp/syscall.o \ + +defaultapp.elf: tkey-libs $(DEFAULTAPP_OBJS) + $(CC) $(CFLAGS) $(DEFAULTAPP_OBJS) $(LDFLAGS) -o $@ + +.PHONY: fmt +fmt: + clang-format --dry-run --ferror-limit=0 $(DEFAULTAPP_FMTFILES) + clang-format --verbose -i $(DEFAULT_FMTFILES) + +.PHONY: checkfmt +checkfmt: + clang-format --dry-run --ferror-limit=0 --Werror $(DEFAULT_FMTFILES) + +.PHONY: clean +clean: + rm -f defaultapp.* $(DEFAULTAPP_OBJS) diff --git a/hw/application_fpga/fw/defaultapp/main.c b/hw/application_fpga/fw/defaultapp/main.c new file mode 100644 index 0000000..a6c7eec --- /dev/null +++ b/hw/application_fpga/fw/defaultapp/main.c @@ -0,0 +1,19 @@ +// Copyright (C) 2025 - Tillitis AB +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "../testapp/syscall.h" +#include "../tk1/reset.h" +#include "../tk1/syscall_num.h" + +int main(void) +{ + struct reset rst = {0}; + + led_set(LED_BLUE); + + rst.type = START_CLIENT; + syscall(TK1_SYSCALL_RESET, (uint32_t)&rst, 0, 0); +}