Skip to content

Commit

Permalink
fw: simplify how to enable QEMU debug in firmware.
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
dehanj and agren committed Sep 6, 2024
1 parent 35052e5 commit c089fb9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
7 changes: 6 additions & 1 deletion hw/application_fpga/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

#-------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion hw/application_fpga/fw/tk1/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
18 changes: 9 additions & 9 deletions hw/application_fpga/fw/tk1/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c089fb9

Please sign in to comment.