From 48108cb3a2564ee96777f7d9b63af85d732390e7 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Tue, 13 May 2025 15:49:19 +0200 Subject: [PATCH] fw: Build qemu_firmware with different linker script The qemu_firmware is too large for the real hardware's 8k of ROM. The emulator, however, has lots of ROM. Use a different linker script for to reflect this. --- hw/application_fpga/Makefile | 9 +- hw/application_fpga/fw/tk1/qemu_firmware.lds | 87 ++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 hw/application_fpga/fw/tk1/qemu_firmware.lds diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index 8a27968..6782424 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -185,6 +185,11 @@ LDFLAGS = \ -Wl,--cref,-M \ -L $(LIBDIR) -lcommon -lblake2s +QEMU_LDFLAGS = \ + -T $(P)/fw/tk1/qemu_firmware.lds \ + -Wl,--cref,-M \ + -L $(LIBDIR) -lcommon -lblake2s + # Common libraries the firmware and testfw depend on. See # https://github.com/tillitis/tkey-libs/ .PHONY: tkey-libs @@ -206,8 +211,8 @@ qemu_firmware.elf: CFLAGS += -DQEMU_DEBUG qemu_firmware.elf: ASFLAGS += -DQEMU_DEBUG qemu_firmware.elf: CFLAGS += -DQEMU_SYSCALL qemu_firmware.elf: ASFLAGS += -DQEMU_SYSCALL -qemu_firmware.elf: firmware.elf - mv firmware.elf qemu_firmware.elf +qemu_firmware.elf: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/qemu_firmware.lds + $(CC) $(CFLAGS) $(FIRMWARE_OBJS) $(QEMU_LDFLAGS) -o $@ > $(basename $@).map # Create compile_commands.json for clangd and LSP .PHONY: clangd diff --git a/hw/application_fpga/fw/tk1/qemu_firmware.lds b/hw/application_fpga/fw/tk1/qemu_firmware.lds new file mode 100644 index 0000000..73a63f5 --- /dev/null +++ b/hw/application_fpga/fw/tk1/qemu_firmware.lds @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2022, 2023 - Tillitis AB + * SPDX-License-Identifier: GPL-2.0-only +*/ + +OUTPUT_ARCH("riscv") +ENTRY(_start) + +/* Define stack size */ +STACK_SIZE = 3000; + +MEMORY +{ + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128k + FWRAM (rw) : ORIGIN = 0xd0000000, LENGTH = 0xF00 /* 3840 B */ + RESETINFO (rw) : ORIGIN = 0xd0000F00, LENGTH = 0x100 /* 256 B (part of FW_RAM area) */ + RAM (rwx) : ORIGIN = 0x40000000, LENGTH = 0x20000 /* 128 KB */ +} + +SECTIONS +{ + .text.init : + { + *(.text.init) + } >ROM + + .htif : + { + . = ALIGN(0x00000000); + *(.htif) + } >ROM + + .text : + { + . = ALIGN(4); + _stext = .; + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.srodata) /* .srodata sections (constants, strings, etc.) */ + *(.srodata*) /* .srodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + _etext = .; + } >ROM + + .stack (NOLOAD) : + { + . = ALIGN(16); + _sstack = .; + . += STACK_SIZE; + . = ALIGN(16); + _estack = .; + } >FWRAM + + .data : + { + . = ALIGN(4); + _sdata = .; + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.sdata) /* .sdata sections */ + *(.sdata*) /* .sdata* sections */ + . = ALIGN(4); + _edata = .; + } >FWRAM AT>ROM + _sidata = LOADADDR(.data); + + /* Uninitialized data section */ + .bss : + { + . = ALIGN(4); + _sbss = .; + *(.bss) + *(.bss*) + *(.sbss) + *(.sbss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + } >FWRAM +} + +_sfwram = ORIGIN(FWRAM); +_efwram = ORIGIN(FWRAM) + LENGTH(FWRAM); +_sresetinfo = ORIGIN(RESETINFO); +_eresetinfo = ORIGIN(RESETINFO) + LENGTH(RESETINFO);