diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index 8f40c1e..453d4a9 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -106,7 +106,6 @@ PICORV32_SRCS = \ FIRMWARE_DEPS = \ $(P)/fw/tk1_mem.h \ - $(P)/fw/tk1/types.h \ $(P)/fw/tk1/lib.h \ $(P)/fw/tk1/proto.h \ $(P)/fw/tk1/assert.h \ diff --git a/hw/application_fpga/fw/testfw/main.c b/hw/application_fpga/fw/testfw/main.c index 5ed6076..e25ff18 100644 --- a/hw/application_fpga/fw/testfw/main.c +++ b/hw/application_fpga/fw/testfw/main.c @@ -6,9 +6,11 @@ #include "../tk1/blake2s/blake2s.h" #include "../tk1/lib.h" #include "../tk1/proto.h" -#include "../tk1/types.h" #include "../tk1_mem.h" +#include +#include + // clang-format off volatile uint32_t *tk1name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0; volatile uint32_t *tk1name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1; diff --git a/hw/application_fpga/fw/tk1/Makefile b/hw/application_fpga/fw/tk1/Makefile index 68b8261..ef6f949 100644 --- a/hw/application_fpga/fw/tk1/Makefile +++ b/hw/application_fpga/fw/tk1/Makefile @@ -1,5 +1,5 @@ # Uses ../.clang-format -FMTFILES=main.c lib.h lib.c proto.h proto.c types.h assert.c assert.h led.c led.h +FMTFILES=main.c lib.h lib.c proto.h proto.c assert.c assert.h led.c led.h .PHONY: fmt fmt: clang-format --dry-run --ferror-limit=0 $(FMTFILES) diff --git a/hw/application_fpga/fw/tk1/blake2s/blake2s.c b/hw/application_fpga/fw/tk1/blake2s/blake2s.c index b46ad8a..120ae45 100644 --- a/hw/application_fpga/fw/tk1/blake2s/blake2s.c +++ b/hw/application_fpga/fw/tk1/blake2s/blake2s.c @@ -6,10 +6,12 @@ // A simple blake2s Reference Implementation. //====================================================================== -#include "../types.h" #include "../lib.h" #include "blake2s.h" +#include +#include + // Dummy printf() for verbose mode static void printf(const char *format, ...) { diff --git a/hw/application_fpga/fw/tk1/blake2s/blake2s.h b/hw/application_fpga/fw/tk1/blake2s/blake2s.h index 3156669..d8ed8ea 100644 --- a/hw/application_fpga/fw/tk1/blake2s/blake2s.h +++ b/hw/application_fpga/fw/tk1/blake2s/blake2s.h @@ -4,7 +4,8 @@ #ifndef BLAKE2S_H #define BLAKE2S_H -#include "../types.h" +#include +#include // state context typedef struct { diff --git a/hw/application_fpga/fw/tk1/led.c b/hw/application_fpga/fw/tk1/led.c index 023bafa..e1ad663 100644 --- a/hw/application_fpga/fw/tk1/led.c +++ b/hw/application_fpga/fw/tk1/led.c @@ -5,7 +5,7 @@ #include "led.h" #include "../tk1_mem.h" -#include "types.h" +#include static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; diff --git a/hw/application_fpga/fw/tk1/led.h b/hw/application_fpga/fw/tk1/led.h index d2c162e..e0e4514 100644 --- a/hw/application_fpga/fw/tk1/led.h +++ b/hw/application_fpga/fw/tk1/led.h @@ -7,7 +7,8 @@ #define LED_H #include "../tk1_mem.h" -#include "types.h" + +#include // clang-format off #define LED_BLACK 0 diff --git a/hw/application_fpga/fw/tk1/lib.c b/hw/application_fpga/fw/tk1/lib.c index 5399dbb..c992be7 100644 --- a/hw/application_fpga/fw/tk1/lib.c +++ b/hw/application_fpga/fw/tk1/lib.c @@ -5,7 +5,8 @@ #include "lib.h" #include "assert.h" -#include "types.h" +#include +#include #ifdef QEMU_CONSOLE struct { diff --git a/hw/application_fpga/fw/tk1/lib.h b/hw/application_fpga/fw/tk1/lib.h index 2d3d7e3..2f0c95c 100644 --- a/hw/application_fpga/fw/tk1/lib.h +++ b/hw/application_fpga/fw/tk1/lib.h @@ -6,7 +6,8 @@ #ifndef LIB_H #define LIB_H -#include "types.h" +#include +#include #ifdef QEMU_CONSOLE void htif_putc(char ch); diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index 524b0dc..87fd703 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -9,7 +9,10 @@ #include "lib.h" #include "proto.h" #include "state.h" -#include "types.h" + +#include +#include +#include // clang-format off static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST; @@ -37,14 +40,14 @@ struct context { uint32_t left; // Bytes left to receive uint8_t digest[32]; // Program digest uint8_t *loadaddr; // Where we are currently loading a TKey program - uint8_t use_uss; // Use USS? + bool use_uss; // Use USS? uint8_t uss[32]; // User Supplied Secret, if any }; static void print_hw_version(void); static void print_digest(uint8_t *md); static uint32_t rnd_word(void); -static void compute_cdi(const uint8_t *digest, const uint8_t use_uss, +static void compute_cdi(const uint8_t *digest, const bool use_uss, const uint8_t *uss); static void copy_name(uint8_t *buf, const size_t bufsiz, const uint32_t word); static enum state initial_commands(const struct frame_header *hdr, @@ -89,7 +92,7 @@ static uint32_t rnd_word(void) } // CDI = blake2s(uds, blake2s(app), uss) -static void compute_cdi(const uint8_t *digest, const uint8_t use_uss, +static void compute_cdi(const uint8_t *digest, const bool use_uss, const uint8_t *uss) { uint32_t local_uds[8] = {0}; @@ -121,7 +124,7 @@ static void compute_cdi(const uint8_t *digest, const uint8_t use_uss, blake2s_update(&secure_ctx, digest, 32); // Possibly hash in the USS as well - if (use_uss != 0) { + if (use_uss) { blake2s_update(&secure_ctx, uss, 32); } @@ -217,10 +220,10 @@ static enum state initial_commands(const struct frame_header *hdr, // Do we have a USS at all? if (cmd[5] != 0) { // Yes - ctx->use_uss = TRUE; + ctx->use_uss = true; memcpy_s(ctx->uss, 32, &cmd[6], 32); } else { - ctx->use_uss = FALSE; + ctx->use_uss = false; } rsp[0] = STATUS_OK; @@ -410,7 +413,7 @@ int main(void) */ ctx.loadaddr = (uint8_t *)TK1_RAM_BASE; /*@+mustfreeonly@*/ - ctx.use_uss = FALSE; + ctx.use_uss = false; scramble_ram(); diff --git a/hw/application_fpga/fw/tk1/proto.c b/hw/application_fpga/fw/tk1/proto.c index 1a6e450..5bf9c23 100644 --- a/hw/application_fpga/fw/tk1/proto.c +++ b/hw/application_fpga/fw/tk1/proto.c @@ -9,7 +9,9 @@ #include "led.h" #include "lib.h" #include "state.h" -#include "types.h" + +#include +#include // clang-format off static volatile uint32_t *can_rx = (volatile uint32_t *)TK1_MMIO_UART_RX_STATUS; diff --git a/hw/application_fpga/fw/tk1/proto.h b/hw/application_fpga/fw/tk1/proto.h index 971bbd9..bd2b305 100644 --- a/hw/application_fpga/fw/tk1/proto.h +++ b/hw/application_fpga/fw/tk1/proto.h @@ -3,7 +3,8 @@ * SPDX-License-Identifier: GPL-2.0-only */ -#include "types.h" +#include +#include #ifndef PROTO_H #define PROTO_H diff --git a/hw/application_fpga/fw/tk1/types.h b/hw/application_fpga/fw/tk1/types.h deleted file mode 100644 index 9a1fcff..0000000 --- a/hw/application_fpga/fw/tk1/types.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2022 - Tillitis AB - * SPDX-License-Identifier: GPL-2.0-only - */ - -#ifndef TYPES_H -#define TYPES_H - -typedef unsigned int uintptr_t; -typedef unsigned long long uint64_t; -typedef unsigned int uint32_t; -typedef int int32_t; -typedef long long int64_t; -typedef unsigned char uint8_t; -typedef unsigned long size_t; - -#define NULL ((char *)0) - -#define FALSE 0 -#define TRUE !FALSE - -#endif