diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index 9906750..692e5f7 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -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 #------------------------------------------------------------------- diff --git a/hw/application_fpga/fw/README.md b/hw/application_fpga/fw/README.md index 989b46b..6a1de76 100644 --- a/hw/application_fpga/fw/README.md +++ b/hw/application_fpga/fw/README.md @@ -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 diff --git a/hw/application_fpga/fw/tk1/lib.c b/hw/application_fpga/fw/tk1/lib.c index 61289a2..c7c98ae 100644 --- a/hw/application_fpga/fw/tk1/lib.c +++ b/hw/application_fpga/fw/tk1/lib.c @@ -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"))); diff --git a/hw/application_fpga/fw/tk1/lib.h b/hw/application_fpga/fw/tk1/lib.h index b7944b3..245a16d 100644 --- a/hw/application_fpga/fw/tk1/lib.h +++ b/hw/application_fpga/fw/tk1/lib.h @@ -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);