From 1f81c9bdb6db01de9074e1c5d51606bcad06f8dc Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Mon, 17 Mar 2025 15:47:19 +0100 Subject: [PATCH] Add resetinfo handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decide where to start from with data from resetinfo part of FW_RAM. Co-authored-by: Jonas Thörnblad Co-authored-by: Mikael Ågren --- hw/application_fpga/fw/tk1/main.c | 31 +++++++++++--------------- hw/application_fpga/fw/tk1/resetinfo.h | 30 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 hw/application_fpga/fw/tk1/resetinfo.h diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index bb9a7f0..98d54ee 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -19,6 +19,7 @@ #include "proto.h" #include "state.h" #include "syscall_enable.h" +#include "resetinfo.h" // clang-format off static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST; @@ -37,7 +38,7 @@ static volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER static volatile uint32_t *timer_ctrl = (volatile uint32_t *)TK1_MMIO_TIMER_CTRL; static volatile uint32_t *ram_addr_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_ADDR_RAND; static volatile uint32_t *ram_data_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_DATA_RAND; -static volatile uint8_t *startfrom = (volatile uint8_t *)0xd0000000bb9; /// FW_RAM after stack +static volatile struct reset *resetinfo = (volatile struct reset *)TK1_MMIO_RESETINFO_BASE; // clang-format on struct partition_table part_table; @@ -50,17 +51,7 @@ struct context { bool use_uss; // Use USS? uint8_t uss[32]; // User Supplied Secret, if any uint8_t flash_slot; // App is loaded from flash slot number - bool verify; // Verify? - uint8_t ver_digest[32]; // Verify loaded app against this digest -}; - -enum reset_start { - START_FLASH1 = 1, - START_FLASH2 = 2, - START_FLASH1_VER = 3, - START_FLASH2_VER = 4, - START_CLIENT = 5, - START_CLIENT_VER = 6, + volatile uint8_t *ver_digest; // Verify loaded app against this digest }; static void print_hw_version(void); @@ -466,36 +457,40 @@ static int compute_app_digest(uint8_t *digest) static enum state start_where(struct context *ctx) { // Where do we start? Read resetinfo 'startfrom' - switch (*startfrom) { + switch (resetinfo->type) { + case START_DEFAULT: + // fallthrough case START_FLASH1: ctx->flash_slot = 1; + ctx->ver_digest = NULL; return FW_STATE_LOAD_FLASH; case START_FLASH2: ctx->flash_slot = 2; + ctx->ver_digest = NULL; return FW_STATE_LOAD_FLASH; case START_FLASH1_VER: ctx->flash_slot = 1; - ctx->verify = true; - // ctx.ver_digest = ... + ctx->ver_digest = resetinfo->app_digest; return FW_STATE_LOAD_FLASH; case START_FLASH2_VER: ctx->flash_slot = 2; - ctx->verify = true; - // ctx.ver_digest = ... + ctx->ver_digest = resetinfo->app_digest; return FW_STATE_LOAD_FLASH; case START_CLIENT: + ctx->ver_digest = NULL; + return FW_STATE_WAITCOMMAND; case START_CLIENT_VER: - ctx->verify = true; + ctx->ver_digest = resetinfo->app_digest; return FW_STATE_WAITCOMMAND; diff --git a/hw/application_fpga/fw/tk1/resetinfo.h b/hw/application_fpga/fw/tk1/resetinfo.h new file mode 100644 index 0000000..787bb33 --- /dev/null +++ b/hw/application_fpga/fw/tk1/resetinfo.h @@ -0,0 +1,30 @@ +// Copyright (C) 2025 - Tillitis AB +// SPDX-License-Identifier: GPL-2.0-only + +#ifndef TKEY_RESETINFO_H +#define TKEY_RESETINFO_H + +#include + + +#define TK1_MMIO_RESETINFO_BASE 0xd0000f00 +#define TK1_MMIO_RESETINFO_SIZE 0x100 + + +enum reset_start { + START_DEFAULT = 0, // Probably cold boot + START_FLASH1 = 1, + START_FLASH2 = 2, + START_FLASH1_VER = 3, + START_FLASH2_VER = 4, + START_CLIENT = 5, + START_CLIENT_VER = 6, +}; + +struct reset { + uint32_t type; // Reset type + uint8_t app_digest[32]; // Program digest + uint8_t next_app_data[220]; // Data to leave around for next app +}; + +#endif