blob: 52aa3a222ed90b52a3dc46bd085535d3a9a52c2d [file] [log] [blame]
Miguel Young de la Sota95142f72020-04-23 14:14:32 -04001// 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 Trippel961b2cd2021-12-14 22:28:58 +00005#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 Sota95142f72020-04-23 14:14:32 -04007
Miguel Young de la Sota95142f72020-04-23 14:14:32 -04008#include <stdint.h>
9
Miguel Young de la Sota9e237df2020-10-01 15:08:51 -040010#include "sw/device/lib/dif/dif_hmac.h"
Miguel Young de la Sota95142f72020-04-23 14:14:32 -040011
12/**
13 * The total size of a spiflash frame.
14 */
Eunchan Kimb08ac672021-02-05 15:12:51 -080015#define SPIFLASH_RAW_BUFFER_SIZE 2048
Miguel Young de la Sota95142f72020-04-23 14:14:32 -040016
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 */
43typedef struct spiflash_frame_header {
44 /**
45 * SHA256 of the entire frame_t message starting at the `frame_num` offset.
46 */
Miguel Young de la Sota9e237df2020-10-01 15:08:51 -040047 dif_hmac_digest_t hash;
Miguel Young de la Sota95142f72020-04-23 14:14:32 -040048 /**
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 */
63typedef 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 Trippel961b2cd2021-12-14 22:28:58 +000077#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_ROM_SPIFLASH_FRAME_H_