From 90a91ba1bab301f7da48ad8e7c6b699aa1efed08 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Fri, 29 Aug 2025 09:41:45 +0200 Subject: [PATCH] build: Create and use a complete filesystem image - Create a flash image in flash_image.bin, useful for both a real TKey and QEMU. - Use flash_image.bin directly in prog_flash for a real TKey, which also flashes the bitstream. - Remove building of tools/default_partition.bin. - Update documentation about the tool use. - We keep the load_preloaded_app.sh for development purposes, but it's no longer used in the build. --- hw/application_fpga/Makefile | 19 +++++++++---------- hw/application_fpga/fw/README.md | 5 +---- hw/application_fpga/tools/README.md | 16 ++++++++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index a485985..1b8a026 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -126,8 +126,7 @@ PICORV32_SRCS = \ FIRMWARE_DEPS = \ $(P)/fw/tk1/proto.h \ - $(P)/fw/tk1/mgmt_app_digest.h \ - tools/default_partition.bin + $(P)/fw/tk1/mgmt_app_digest.h FIRMWARE_OBJS = \ $(P)/fw/tk1/main.o \ @@ -220,15 +219,15 @@ tkey-libs: $(DEFAULT_APP): make -C apps -# Partititon table for the firmware's filesystem -tools/default_partition.bin: tools/tkeyimage/tkeyimage $(DEFAULT_APP) - ./tools/tkeyimage/tkeyimage -app0 $(DEFAULT_APP) -o $@ +# Build a complete filesystem image +flash_image.bin: tools/tkeyimage/tkeyimage $(DEFAULT_APP) + ./tools/tkeyimage/tkeyimage -f -app0 $(DEFAULT_APP) -o $@ $(FIRMWARE_OBJS): $(FIRMWARE_DEPS) $(TESTFW_OBJS): $(FIRMWARE_DEPS) #firmware.elf: CFLAGS += -DTKEY_DEBUG -firmware.elf: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/firmware.lds +firmware.elf: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/firmware.lds flash_image.bin $(CC) $(CFLAGS) $(FIRMWARE_OBJS) $(LDFLAGS) -o $@ > $(basename $@).map simfirmware.elf: CFLAGS += -DSIMULATION @@ -239,7 +238,7 @@ 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: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/qemu_firmware.lds +qemu_firmware.elf: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/qemu_firmware.lds flash_image.bin $(CC) $(CFLAGS) $(FIRMWARE_OBJS) $(QEMU_LDFLAGS) -o $@ > $(basename $@).map # Generate the file containing the digest for the obligatory default @@ -504,9 +503,9 @@ tb_application_fpga: $(SIM_VERILOG_SRCS) \ # FPGA device programming. #------------------------------------------------------------------- -prog_flash: check-hardware application_fpga.bin tools/default_partition.bin +prog_flash: check-hardware application_fpga.bin flash_image.bin + tillitis-iceprog flash_image.bin tillitis-iceprog application_fpga.bin - (cd tools && ./load_preloaded_app.sh 0 $(DEFAULT_APP)) .PHONY: prog_flash prog_flash_bs: check-hardware application_fpga.bin @@ -546,7 +545,7 @@ clean: clean_sim clean_fw clean_tb rm -rf tools/tpt/__pycache__ make -C apps clean rm -f fw/tk1/mgmt_app_digest.h - rm -f tools/default_partition.bin + rm -f flash_image.bin .PHONY: clean diff --git a/hw/application_fpga/fw/README.md b/hw/application_fpga/fw/README.md index 85d8cb4..7b66bb2 100644 --- a/hw/application_fpga/fw/README.md +++ b/hw/application_fpga/fw/README.md @@ -784,10 +784,7 @@ There are a couple of test apps, see `../apps`. The TKey supports a simple filesystem. The `tkeyimage` tool is used to parse or generate partition table or -entire filesystems for the TKey. - -The table and the pre-loaded app can loaded on flash with the -`load_preloaded_app.sh` tool. +entire filesystem images for the TKey. The fileystem layout looks like this: diff --git a/hw/application_fpga/tools/README.md b/hw/application_fpga/tools/README.md index d419260..c9bceb6 100644 --- a/hw/application_fpga/tools/README.md +++ b/hw/application_fpga/tools/README.md @@ -8,13 +8,15 @@ We have developed some tools necessary for the build. - `b2s`: Compute and print a BLAKE2s digest over a file. Used for the digest of the app in app slot 0 included in the firmware. -- `default_partition.bin`: Default partition table for the flash. - - `load_preloaded_app.sh`: Script to load two copies of the partition table to flash and a pre-loaded to app slot 0 or 1. Needs `default_partition.bin`, generated with `tkeyimage` and the binary - of the device app to load. Call like: `./load_preloaded_app 0 - path/to/binary`. + of the device app to load. Call like: + + ``` + ./tkeyimage/tkeyimage -app0 path/to/binary -o default_partition.bin + ./load_preloaded_app 0 path/to/binary + ``` - `makehex.py`: Used to build hex version of firmware ROM for FPGA bitstream build. @@ -26,8 +28,10 @@ We have developed some tools necessary for the build. - `run_pnr.sh`: Script to run place and route with `nextpnr` in order to find a routing seed that will meet desired timing. -- `tkeyimage`: Utility to create and parse flash images with a TKey - filesystem or the partition table +- `tkeyimage`: Utility to create and parse a partition table or entire + flash images with a TKey filesystem. You can flash the image with + the [iceprog tool](https://github.com/tillitis/icestorm/). Remember + to flash the flash image first and the FPGA bitstream afterwards. - `tpt/tpt.py`: Utility to create the Unique Device Secret (UDS) and Unique Device Identity (UDI) interactively.