From c089fb9b79a8c419570e3829b1c6bb8f3232ea93 Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Fri, 6 Sep 2024 12:46:18 +0200 Subject: [PATCH] fw: simplify how to enable QEMU debug in firmware. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- hw/application_fpga/Makefile | 7 ++++++- hw/application_fpga/fw/tk1/lib.c | 2 +- hw/application_fpga/fw/tk1/lib.h | 18 +++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index 9906750f..692e5f7d 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/tk1/lib.c b/hw/application_fpga/fw/tk1/lib.c index 61289a29..38e8ab79 100644 --- a/hw/application_fpga/fw/tk1/lib.c +++ b/hw/application_fpga/fw/tk1/lib.c @@ -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 b7944b3d..27ec4125 100644 --- a/hw/application_fpga/fw/tk1/lib.h +++ b/hw/application_fpga/fw/tk1/lib.h @@ -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);