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

Update test-apps to newer version of tkey-libs #2

Merged
merged 8 commits into from
Sep 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[*.{go,md}]
[*.md]
max_line_length = 70
11 changes: 4 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ jobs:
ci:
runs-on: ubuntu-latest
container:
image: ghcr.io/tillitis/tkey-builder:2
image: ghcr.io/tillitis/tkey-builder:4
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# fetch-depth: 0
persist-credentials: false

- name: Clone tkey-libs
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: tillitis/tkey-libs
ref: main
Expand All @@ -39,10 +39,7 @@ jobs:
make

- name: make
run: make -j LIBDIR=../tkey-libs

- name: lint go code
run: make lint
run: ./build.sh

- name: check fmt of c code
run: make -C apps checkfmt
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request: {}
# allow manual runs:
workflow_dispatch: {}

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
*.o
*.bin
*.elf
/tkey-ssh-agent
/tkey-ssh-agent.exe
/cmd/tkey-ssh-agent/rsrc_windows_amd64.syso
/tkey-ssh-agent-tray.exe
/cmd/tkey-ssh-agent-tray/rsrc_windows_amd64.syso
/tkey-runapp
/tkey-sign
/runsign.sh
/runtimer
/runrandom
/gotools/golangci-lint
/gotools/go-winres
test/venv
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ linters:
- gocognit
- nestif
- exhaustruct # TODO? annoying for now
- goerr113 # TODO enable later
- perfsprint
- err113 # TODO enable later
- godot
- depguard

issues:
max-issues-per-linter: 0
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reload-rules:
udevadm trigger

podman:
podman run --rm --mount type=bind,source=$(CURDIR),target=/src --mount type=bind,source=$(CURDIR)/../tkey-libs,target=/tkey-libs -w /src -it ghcr.io/tillitis/tkey-builder:2 make -j
podman run --rm --mount type=bind,source=$(CURDIR),target=/src --mount type=bind,source=$(CURDIR)/../tkey-libs,target=/tkey-libs -w /src -it ghcr.io/tillitis/tkey-builder:4 make -j

.PHONY: apps
apps:
Expand All @@ -35,6 +35,5 @@ clean:

.PHONY: lint
lint:
$(MAKE) -C gotools
GOOS=linux ./gotools/golangci-lint run
GOOS=windows ./gotools/golangci-lint run
golangci-lint run

15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ This repository contains some test and example applications for the

Client apps:

- `runtimer`: Control the `timer` device app.
- `runtimer`: Control the `timer` device app. NOTA BENE! Doesn't load
the `timer`. Please load it first with `tkey-runapp`.

Device apps:

Expand All @@ -17,8 +18,10 @@ Device apps:
[tkey-random-generator](https://github.com/tillitis/tkey-random-generator)
for something more polished.
- `blink`: A minimalistic example in assembly.
- `nx`: Test program for the execution monitor.
- `timer`: Example/test app on how to use the hardware timer.
- `nx`: Test program for the execution monitor. Should blink green
then immediately do a hardware trap and blink red forever.
- `timer`: Example/test app on how to use the hardware timer. Feed it
with data with `runtimer`.
- `touch`: Example/test app for the touch sensor. Cycles between
colours when touching.

Expand Down Expand Up @@ -50,7 +53,7 @@ If you want to do it manually, clone and build tkey-libs and
tkey-device-signer manually like this:

```
$ git clone -b v0.0.1 https://github.com/tillitis/tkey-libs
$ git clone -b v0.1.1 https://github.com/tillitis/tkey-libs
$ cd tkey-libs
$ make
```
Expand All @@ -71,14 +74,14 @@ your system.
If you want to use podman and you have `make` you can run:

```
$ podman pull ghcr.io/tillitis/tkey-builder:2
$ podman pull ghcr.io/tillitis/tkey-builder:4
$ make podman
```

or run podman directly with

```
$ podman run --rm --mount type=bind,source=$(CURDIR),target=/src --mount type=bind,source=$(CURDIR)/../tkey-libs,target=/tkey-libs -w /src -it ghcr.io/tillitis/tkey-builder:2 make -j
$ podman run --rm --mount type=bind,source=$(CURDIR),target=/src --mount type=bind,source=$(CURDIR)/../tkey-libs,target=/tkey-libs -w /src -it ghcr.io/tillitis/tkey-builder:4 make -j
```

## Licenses and SPDX tags
Expand Down
85 changes: 19 additions & 66 deletions apps/Makefile
Original file line number Diff line number Diff line change
@@ -1,78 +1,31 @@
OBJCOPY ?= llvm-objcopy

P := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIBDIR ?= $(P)/../../tkey-libs

CC = clang

INCLUDE=$(LIBDIR)/include

# If you want libcommon's qemu_puts() et cetera to output something on our QEMU
# debug port, remove -DNODEBUG below
CFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany \
-static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf \
-fno-builtin-putchar -nostdlib -mno-relax -flto -g \
-Wall -Werror=implicit-function-declaration \
-I $(INCLUDE) -I $(LIBDIR) \
-DNODEBUG

AS = clang
ASFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -mno-relax

LDFLAGS=-T $(LIBDIR)/app.lds -L $(LIBDIR)/libcommon/ -lcommon -L $(LIBDIR)/libcrt0/ -lcrt0

.PHONY: all
all: timer/app.bin rng_stream/app.bin blink/app.bin nx/app.bin touch/app.bin
all: timer rng_stream blink nx touch

# Turn elf into bin for device
%.bin: %.elf
$(OBJCOPY) --input-target=elf32-littleriscv --output-target=binary $^ $@
chmod a-x $@
%/app.bin:
$(MAKE) -C $(@D) all

show-%-hash: %/app.bin
cd $$(dirname $^) && sha512sum app.bin
blink: blink/app.bin

# A simpler timer app
TIMEROBJS = timer/main.o timer/app_proto.o
timer/app.elf: $(TIMEROBJS)
$(CC) $(CFLAGS) $(TIMEROBJS) $(LDFLAGS) -o $@
$(TIMEROBJS): $(INCLUDE)/tk1_mem.h timer/app_proto.h
nx: nx/app.bin

# Streaming RNG random number app
RNG_STREAM_OBJS=rng_stream/main.o
rng_stream/app.elf: $(RNG_STREAM_OBJS)
$(CC) $(CFLAGS) $(RNG_STREAM_OBJS) $(LDFLAGS) -o $@
$(RNG_STREAM_OBJS): $(INCLUDE)/tk1_mem.h
rng_stream: rng_stream/app.bin

NX_OBJS=nx/main.o
nx/app.elf: $(NX_OBJS)
$(CC) $(CFLAGS) $(NX_OBJS) $(LDFLAGS) -o $@
$(NX_OBJS): $(INCLUDE)/tk1_mem.h
timer: timer/app.bin

# Blinkenlights assembler app
blink/app.elf: blink/blink.o
ld.lld -o $@ blink/blink.o --oformat elf
touch: touch/app.bin

TOUCHOBJS = touch/main.o
touch/app.elf: $(LIBS) $(TOUCHOBJS)
$(CC) $(CFLAGS) $(TOUCHOBJS) $(LDFLAGS) -o $@
$(TOUCHOBJS): $(INCLUDE)/tk1_mem.h
.PHONY: checkfmt
checkfmt:
$(MAKE) -C nx checkfmt
$(MAKE) -C rng_stream checkfmt
$(MAKE) -C timer checkfmt
$(MAKE) -C touch checkfmt

.PHONY: clean
clean:
rm -f timer/app.bin timer/app.elf $(TIMEROBJS)
rm -f rng_stream/app.bin rng_stream/app.elf $(RNG_STREAM_OBJS)
rm -f blink/app.bin blink/app.elf blink/blink.o
rm -f nx/app.bin nx/app.elf nx/main.o
rm -f touch/app.bin touch/app.elf touch/main.o

# Uses ../.clang-format
FMTFILES=timer/*.[ch] rng_stream/*.[ch] nx/main.c touch/*.[ch]

.PHONY: fmt
fmt:
clang-format --dry-run --ferror-limit=0 $(FMTFILES)
clang-format --verbose -i $(FMTFILES)
.PHONY: checkfmt
checkfmt:
clang-format --dry-run --ferror-limit=0 --Werror $(FMTFILES)
$(MAKE) -C blink clean
$(MAKE) -C nx clean
$(MAKE) -C rng_stream clean
$(MAKE) -C timer clean
$(MAKE) -C touch clean
43 changes: 43 additions & 0 deletions apps/blink/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
OBJCOPY ?= llvm-objcopy

P := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIBDIR ?= $(P)/../../../tkey-libs

CC = clang

INCLUDE=$(LIBDIR)/include

# If you want libcommon's qemu_puts() et cetera to output something on our QEMU
# debug port, remove -DNODEBUG below
CFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany \
-static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf \
-fno-builtin-putchar -nostdlib -mno-relax -flto -g \
-Wall -Werror=implicit-function-declaration \
-I $(INCLUDE) -I $(LIBDIR) \
-DNODEBUG

AS = clang
ASFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -mno-relax

LDFLAGS=-T $(LIBDIR)/app.lds -L $(LIBDIR)/libcommon/ -lcommon -L $(LIBDIR)/libcrt0/ -lcrt0

.PHONY: all
all: app.bin

# Turn elf into bin for device
%.bin: %.elf
$(OBJCOPY) --input-target=elf32-littleriscv --output-target=binary $^ $@
chmod a-x $@

show-hash: app.bin
shasum -a 512 app.bin


# Blinkenlights assembler app
app.elf: blink.o
ld.lld -o $@ blink.o --oformat elf


.PHONY: clean
clean:
rm -f app.bin app.elf blink.o
2 changes: 1 addition & 1 deletion apps/blink/blink.S
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022 - Tillitis AB
// Copyright (C) 2022-2024 - Tillitis AB
// SPDX-License-Identifier: GPL-2.0-only

.section ".text.init"
Expand Down
52 changes: 52 additions & 0 deletions apps/nx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
OBJCOPY ?= llvm-objcopy

P := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIBDIR ?= $(P)/../../../tkey-libs

CC = clang

INCLUDE=$(LIBDIR)/include

# If you want libcommon's qemu_puts() et cetera to output something on our QEMU
# debug port, remove -DNODEBUG below
CFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany \
-static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf \
-fno-builtin-putchar -nostdlib -mno-relax -flto -g \
-Wall -Werror=implicit-function-declaration \
-I $(INCLUDE) -I $(LIBDIR) #-DQEMU_DEBUG

AS = clang
ASFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -mno-relax

LDFLAGS=-T $(LIBDIR)/app.lds -L $(LIBDIR) -lcommon -lcrt0

.PHONY: all
all: app.bin

# Turn elf into bin for device
%.bin: %.elf
$(OBJCOPY) --input-target=elf32-littleriscv --output-target=binary $^ $@
chmod a-x $@

show-hash: app.bin
shasum -a 512 app.bin

OBJS=main.o
app.elf: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@
$(OBJS): $(INCLUDE)/tkey/tk1_mem.h

.PHONY: clean
clean:
rm -f app.bin app.elf main.o

# Uses ../.clang-format
FMTFILES= main.c

.PHONY: fmt
fmt:
clang-format --dry-run --ferror-limit=0 $(FMTFILES)
clang-format --verbose -i $(FMTFILES)
.PHONY: checkfmt
checkfmt:
clang-format --dry-run --ferror-limit=0 --Werror $(FMTFILES)
7 changes: 4 additions & 3 deletions apps/nx/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 - Tillitis AB
// Copyright (C) 2023-2024 - Tillitis AB
// SPDX-License-Identifier: GPL-2.0-only

// Test of the execution monitor. Should blink green 5 times, then the
Expand All @@ -8,8 +8,9 @@
// monitor address. If it starts blinking green again after blinking
// white it was possible to turn it off.

#include <lib.h>
#include <tk1_mem.h>
#include <stdint.h>
#include <tkey/lib.h>
#include <tkey/tk1_mem.h>

// clang-format off
volatile uint32_t *cpu_mon_ctrl = (volatile uint32_t *)TK1_MMIO_TK1_CPU_MON_CTRL;
Expand Down
Loading