Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 1 | // Copyright lowRISC contributors. |
| 2 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | |
Timothy Trippel | 961b2cd | 2021-12-14 22:28:58 +0000 | [diff] [blame^] | 5 | #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_ROM_SPIFLASH_FRAME_H_ |
| 6 | #define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_ROM_SPIFLASH_FRAME_H_ |
Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 7 | |
Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Miguel Young de la Sota | 9e237df | 2020-10-01 15:08:51 -0400 | [diff] [blame] | 10 | #include "sw/device/lib/dif/dif_hmac.h" |
Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * The total size of a spiflash frame. |
| 14 | */ |
Eunchan Kim | b08ac67 | 2021-02-05 15:12:51 -0800 | [diff] [blame] | 15 | #define SPIFLASH_RAW_BUFFER_SIZE 2048 |
Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * The EOF flag on a spiflash frame, indicating that a frame is the last one in |
| 19 | * the sequence. |
| 20 | */ |
| 21 | #define SPIFLASH_FRAME_EOF_MARKER 0x80000000 |
| 22 | |
| 23 | /** |
| 24 | * Extracts the "number" part of a `frame_num`. |
| 25 | */ |
| 26 | #define SPIFLASH_FRAME_NUM(k) ((k)&0xffffff) |
| 27 | |
| 28 | /** |
| 29 | * Checks whether a `frame_num` represents an EOF. |
| 30 | */ |
| 31 | #define SPIFLASH_FRAME_IS_EOF(k) (((k)&SPIFLASH_FRAME_EOF_MARKER) != 0) |
| 32 | |
| 33 | /** |
| 34 | * The length, in words, of a frame's data buffer. |
| 35 | */ |
| 36 | #define SPIFLASH_FRAME_DATA_WORDS \ |
| 37 | ((SPIFLASH_RAW_BUFFER_SIZE - sizeof(spiflash_frame_header_t)) / \ |
| 38 | sizeof(uint32_t)) |
| 39 | |
| 40 | /** |
| 41 | * A spiflash frame header. |
| 42 | */ |
| 43 | typedef struct spiflash_frame_header { |
| 44 | /** |
| 45 | * SHA256 of the entire frame_t message starting at the `frame_num` offset. |
| 46 | */ |
Miguel Young de la Sota | 9e237df | 2020-10-01 15:08:51 -0400 | [diff] [blame] | 47 | dif_hmac_digest_t hash; |
Miguel Young de la Sota | 95142f7 | 2020-04-23 14:14:32 -0400 | [diff] [blame] | 48 | /** |
| 49 | * Frame number starting at 0. The last frame should be OR'd with |
| 50 | * FRAME_EOF_MARKER. |
| 51 | */ |
| 52 | uint32_t frame_num; |
| 53 | /** |
| 54 | * Offset in flash, indexed from 0, where the frame should be |
| 55 | * written. |
| 56 | */ |
| 57 | uint32_t flash_offset; |
| 58 | } spiflash_frame_header_t; |
| 59 | |
| 60 | /** |
| 61 | * A spiflash frame, as it would arrive on the wire. |
| 62 | */ |
| 63 | typedef struct spiflash_frame { |
| 64 | /** |
| 65 | * Frame header. |
| 66 | */ |
| 67 | spiflash_frame_header_t header; |
| 68 | /** |
| 69 | * Frame data, word-aligned. |
| 70 | */ |
| 71 | uint32_t data[SPIFLASH_FRAME_DATA_WORDS]; |
| 72 | } spiflash_frame_t; |
| 73 | |
| 74 | _Static_assert(sizeof(spiflash_frame_t) == SPIFLASH_RAW_BUFFER_SIZE, |
| 75 | "spiflash_frame_t is the wrong size!"); |
| 76 | |
Timothy Trippel | 961b2cd | 2021-12-14 22:28:58 +0000 | [diff] [blame^] | 77 | #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_ROM_SPIFLASH_FRAME_H_ |