From 955c7e4736df124646424aead8afc8c6c1035568 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Thu, 13 Mar 2025 16:02:02 +0100 Subject: [PATCH] Add hardcoded preloaded app size - Enable TKEY_DEBUG - Wait for something on CDC before continuing --- hw/application_fpga/Makefile | 2 +- hw/application_fpga/fw/tk1/main.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index 3a6db4b..a5c5819 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -195,7 +195,7 @@ tkey-libs: $(FIRMWARE_OBJS): $(FIRMWARE_DEPS) $(TESTFW_OBJS): $(FIRMWARE_DEPS) -#firmware.elf: CFLAGS += -DTKEY_DEBUG +firmware.elf: CFLAGS += -DTKEY_DEBUG firmware.elf: tkey-libs $(FIRMWARE_OBJS) $(P)/fw/tk1/firmware.lds $(CC) $(CFLAGS) $(FIRMWARE_OBJS) $(LDFLAGS) -o $@ > $(basename $@).map diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index 5197489..7ded86a 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -496,6 +496,21 @@ int main(void) scramble_ram(); + // Wait for terminal program and a character to be typed + enum ioend endpoint = IO_NONE; + uint8_t available = 0; + uint8_t in = 0; + + if (readselect(IO_CDC, &endpoint, &available) < 0) { + // readselect failed! I/O broken? Just redblink. + assert(1 == 2); + } + + if (read(IO_CDC, &in, 1, 1) < 0) { + // read failed! I/O broken? Just redblink. + assert(1 == 2); + } + if (part_table_read(&part_table) != 0) { // Couldn't read or create partition table assert(1 != 2); @@ -506,6 +521,10 @@ int main(void) run(&ctx); #endif + // Lie and tell filesystem we have a 128 kiB device app on + // flash. + part_table.pre_app_data.size = 0x20000; + // Just start the preloaded app. if (preload_load(&part_table) == -1) { state = FW_STATE_FAIL;