mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-10-01 01:45:38 -04:00
fw: simplify how to enable QEMU debug in firmware.
- Remove the define `NOCONSOLE`, add define `QEMU_CONSOLE` - Inverse the use of it, add the define to have QEMU debug output in fw. - Add a make target `qemu_firmware.elf` which builds the firmware with QEMU console enabled. Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
parent
35052e50cb
commit
613316f53e
@ -44,7 +44,7 @@ CC = clang
|
||||
CFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 \
|
||||
-static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf \
|
||||
-fno-builtin-putchar -fno-builtin-memcpy -nostdlib -mno-relax -Wall \
|
||||
-Wpedantic -Wno-language-extension-token -flto -g -DNOCONSOLE
|
||||
-Wpedantic -Wno-language-extension-token -flto -g
|
||||
|
||||
AS = clang
|
||||
ASFLAGS = -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mno-relax
|
||||
@ -151,6 +151,10 @@ $(TESTFW_OBJS): $(FIRMWARE_DEPS)
|
||||
firmware.elf: $(FIRMWARE_OBJS) $(P)/fw/tk1/firmware.lds
|
||||
$(CC) $(CFLAGS) $(FIRMWARE_OBJS) $(LDFLAGS) -o $@
|
||||
|
||||
qemu_firmware.elf: CFLAGS += -DQEMU_CONSOLE
|
||||
qemu_firmware.elf: firmware.elf
|
||||
mv firmware.elf qemu_firmware.elf
|
||||
|
||||
.PHONY: check
|
||||
check:
|
||||
clang-tidy -header-filter=.* -checks=cert-* $(FIRMWARE_SOURCES) -- $(CFLAGS)
|
||||
@ -359,6 +363,7 @@ clean_fw:
|
||||
rm -f $(FIRMWARE_OBJS)
|
||||
rm -f testfw.{elf,elf.map,bin,hex}
|
||||
rm -f $(TESTFW_OBJS)
|
||||
rm -f qemu_firmware.elf
|
||||
.PHONY: clean_fw
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
@ -286,11 +286,12 @@ for the tools you need. The easiest is probably to use your OCI image,
|
||||
also useful for debugging the firmware. You can attach GDB, use
|
||||
breakpoints, et cetera.
|
||||
|
||||
If you want to use plain debug prints you can remove `-DNOCONSOLE`
|
||||
from the `CFLAGS` in the Makefile and using the helper functions in
|
||||
`lib.c` like `htif_puts()` `htif_putinthex()` `htif_hexdump()` and
|
||||
friends for printf-like debugging. Note that these functions are only
|
||||
usable in qemu.
|
||||
There is a special make target for QEMU: `qemu_firmware.elf`, which
|
||||
sets `-DQEMU_CONSOLE`, so you can use plain debug prints using the
|
||||
helper functions in `lib.c` like `htif_puts()` `htif_putinthex()`
|
||||
`htif_hexdump()` and friends. Note that these functions are only
|
||||
usable in qemu and that you might need to `make clean` before
|
||||
building, if you have already built before.
|
||||
|
||||
### Test firmware
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 - Tillitis AB
|
||||
* Copyright (C) 2022-2024 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "assert.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef NOCONSOLE
|
||||
#ifdef QEMU_CONSOLE
|
||||
struct {
|
||||
uint32_t arr[2];
|
||||
} static volatile tohost __attribute__((section(".htif")));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 - Tillitis AB
|
||||
* Copyright (C) 2022-2024 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
@ -8,21 +8,21 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef NOCONSOLE
|
||||
#define htif_putc(ch)
|
||||
#define htif_lf()
|
||||
#define htif_puthex(c)
|
||||
#define htif_putinthex(n)
|
||||
#define htif_puts(s)
|
||||
#define htif_hexdump(buf, len)
|
||||
#else
|
||||
#ifdef QEMU_CONSOLE
|
||||
void htif_putc(char ch);
|
||||
void htif_lf();
|
||||
void htif_puthex(uint8_t c);
|
||||
void htif_putinthex(const uint32_t n);
|
||||
void htif_puts(const char *s);
|
||||
void htif_hexdump(void *buf, int len);
|
||||
#endif
|
||||
#else
|
||||
#define htif_putc(ch)
|
||||
#define htif_lf()
|
||||
#define htif_puthex(c)
|
||||
#define htif_putinthex(n)
|
||||
#define htif_puts(s)
|
||||
#define htif_hexdump(buf, len)
|
||||
#endif /* QEMU_CONSOLE */
|
||||
|
||||
void *memset(void *dest, int c, unsigned n);
|
||||
void memcpy_s(void *dest, size_t destsize, const void *src, size_t n);
|
||||
|
Loading…
Reference in New Issue
Block a user