From 9d36acde0813329c3c4c0beaf863ae51ab2d07e6 Mon Sep 17 00:00:00 2001 From: dehanj Date: Thu, 14 Mar 2024 15:07:42 +0100 Subject: [PATCH 1/2] FW: Force the CPU to hang on errors --- hw/application_fpga/application_fpga.bin.sha256 | 2 +- hw/application_fpga/firmware.bin.sha512 | 2 +- hw/application_fpga/fw/tk1/assert.c | 5 ++++- hw/application_fpga/fw/tk1/main.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/application_fpga/application_fpga.bin.sha256 b/hw/application_fpga/application_fpga.bin.sha256 index e0485583..f777369d 100644 --- a/hw/application_fpga/application_fpga.bin.sha256 +++ b/hw/application_fpga/application_fpga.bin.sha256 @@ -1 +1 @@ -d2970828269b3ba7f09fb73b8592b08814dfe8c8087b00b0659feb516bb00f33 application_fpga.bin +84de63425720086b1a576e40d71a4a41eec5502736b732f4992d8f21829aec3e application_fpga.bin diff --git a/hw/application_fpga/firmware.bin.sha512 b/hw/application_fpga/firmware.bin.sha512 index 71e2a456..845a4dde 100644 --- a/hw/application_fpga/firmware.bin.sha512 +++ b/hw/application_fpga/firmware.bin.sha512 @@ -1 +1 @@ -3769540390ee3d990ea3f9e4cc9a0d1af5bcaebb82218185a78c39c6bf01d9cdc305ba253a1fb9f3f9fcc63d97c8e5f34bbb1f7bec56a8f246f1d2239867b623 firmware.bin +aad49235ab60b732a45bbedf5774c543df1b40d52b226ffc41bc6c3e2dbbb3963e810f0a52ccf7ba4689b414f1cb941076b896a47d2377fb61c1976bdbcebe17 firmware.bin diff --git a/hw/application_fpga/fw/tk1/assert.c b/hw/application_fpga/fw/tk1/assert.c index 43628aed..adce820b 100644 --- a/hw/application_fpga/fw/tk1/assert.c +++ b/hw/application_fpga/fw/tk1/assert.c @@ -20,6 +20,9 @@ void assert_fail(const char *assertion, const char *file, unsigned int line, htif_puts(function); htif_lf(); - forever_redflash(); + // Force illegal instruction to halt CPU + asm volatile("unimp"); + // Not reached + __builtin_unreachable(); } diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index 99f447fc..2aa6240d 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -431,7 +431,7 @@ int main() htif_puts("firmware state 0x"); htif_puthex(state); htif_lf(); - forever_redflash(); + assert(1 == 2); break; // Not reached } } From e2bd38c54095fbd27ddb4f14430341531bf2d9ce Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Mon, 18 Mar 2024 16:19:59 +0100 Subject: [PATCH 2/2] fw: Remove unusued forever_redflash() Since we now use assert() and feed the CPU an unimplemented instruction we have no need for this. --- hw/application_fpga/fw/tk1/led.c | 12 ------------ hw/application_fpga/fw/tk1/led.h | 1 - 2 files changed, 13 deletions(-) diff --git a/hw/application_fpga/fw/tk1/led.c b/hw/application_fpga/fw/tk1/led.c index 5f2c5fba..023bafad 100644 --- a/hw/application_fpga/fw/tk1/led.c +++ b/hw/application_fpga/fw/tk1/led.c @@ -13,15 +13,3 @@ void set_led(uint32_t led_value) { *led = led_value; } - -void forever_redflash() -{ - int led_on = 0; - - for (;;) { - *led = led_on ? LED_RED : LED_BLACK; - for (volatile int i = 0; i < 800000; i++) { - } - led_on = !led_on; - } -} diff --git a/hw/application_fpga/fw/tk1/led.h b/hw/application_fpga/fw/tk1/led.h index 358690de..d2c162e3 100644 --- a/hw/application_fpga/fw/tk1/led.h +++ b/hw/application_fpga/fw/tk1/led.h @@ -18,5 +18,4 @@ // clang-format on void set_led(uint32_t led_value); -void forever_redflash(); #endif