Software APIs
boot_svc_msg.h
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOT_SVC_BOOT_SVC_MSG_H_
6#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOT_SVC_BOOT_SVC_MSG_H_
7
9#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_empty.h"
10#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_header.h"
11#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_min_bl0_sec_ver.h"
12#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_next_boot_bl0_slot.h"
13#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_ownership_activate.h"
14#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_ownership_unlock.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif // __cplusplus
19
20/**
21 * Table of boot services request and response types.
22 *
23 * Columns: Data type, `boot_svc_msg_t` union field name.
24 * We use an X macro to generate the assertion that checks
25 * the value of `CHIP_BOOT_SVC_MSG_SIZE_MAX`.
26 */
27// clang-format off
28#define BOOT_SVC_MSGS_DEFINE(X) \
29 /**
30 * Empty boot services message.
31 */ \
32 X(boot_svc_empty_t, empty) \
33 /**
34 * Next Boot BL0 Slot request and response.
35 */ \
36 X(boot_svc_next_boot_bl0_slot_req_t, next_boot_bl0_slot_req) \
37 X(boot_svc_next_boot_bl0_slot_res_t, next_boot_bl0_slot_res) \
38 /**
39 * Set Minimum Security Version request and response.
40 */ \
41 X(boot_svc_min_bl0_sec_ver_req_t, min_bl0_sec_ver_req) \
42 X(boot_svc_min_bl0_sec_ver_res_t, min_bl0_sec_ver_res) \
43 /**
44 * Ownership Activate
45 */ \
46 X(boot_svc_ownership_activate_req_t, ownership_activate_req) \
47 X(boot_svc_ownership_activate_res_t, ownership_activate_res) \
48 /**
49 * Ownership Unlock
50 */ \
51 X(boot_svc_ownership_unlock_req_t, ownership_unlock_req) \
52 X(boot_svc_ownership_unlock_res_t, ownership_unlock_res)
53// clang-format on
54
55/**
56 * Helper macro for declaring fields for boot services messages
57 *
58 * @param type_ Data type.
59 * @param field_name_ `boot_svc_msg_t` union field name.
60 */
61#define BOOT_SVC_MSG_FIELD(type_, field_name_) type_ field_name_;
62
63/**
64 * A Boot Services message.
65 *
66 * This is defined as a union where the common initial sequence is a
67 * `boot_svc_header_t`. This makes it possible to store and read different types
68 * of messages to the same location without invoking undefined behavior.
69 */
70typedef union boot_svc_msg {
71 /**
72 * Common initial sequence.
73 */
74 boot_svc_header_t header;
75 /**
76 * Boot services request and response messages.
77 */
78 BOOT_SVC_MSGS_DEFINE(BOOT_SVC_MSG_FIELD);
79} boot_svc_msg_t;
80
81OT_ASSERT_SIZE(boot_svc_msg_t, 256);
82
83/**
84 * Helper macro for generating the equalities for checking that the value of
85 * `CHIP_BOOT_SVC_MSG_SIZE_MAX` is equal to the size of at least one of the boot
86 * services messages.
87 *
88 * Note that the macro expands to an incomplete expression that must be
89 * terminated with `false`.
90 *
91 * @param type_ Data type.
92 * @param field_name_ `boot_svc_msg_t` union field name.
93 */
94#define BOOT_SVC_SIZE_EQ_(type_, field_name_) \
95 sizeof(type_) == CHIP_BOOT_SVC_MSG_SIZE_MAX ||
96
97static_assert(BOOT_SVC_MSGS_DEFINE(BOOT_SVC_SIZE_EQ_) false,
98 "CHIP_BOOT_SVC_MSG_SIZE_MAX must equal to the size of at least "
99 "one of the boot services messages");
100
101#undef BOOT_SVC_SIZE_EQ_
102
103/**
104 * Helper macro for generating the inequalities for checking that the value of
105 * `CHIP_BOOT_SVC_MSG_SIZE_MAX` is greater than or equal to the sizes of all
106 * boot services messages.
107 *
108 * Note that the macro expands to an incomplete expression that must be
109 * terminated with `true`.
110 *
111 * @param type_ Data type.
112 * @param field_name_ `boot_svc_msg_t` union field name.
113 */
114#define BOOT_SVC_SIZE_LE_(type_, field_name_) \
115 sizeof(type_) <= CHIP_BOOT_SVC_MSG_SIZE_MAX &&
116
117static_assert(BOOT_SVC_MSGS_DEFINE(BOOT_SVC_SIZE_LE_) true,
118 "CHIP_BOOT_SVC_MSG_SIZE_MAX must be greater than or equal to the "
119 "sizes of all of the boot services messages");
120
121#undef BOOT_SVC_SIZE_LE_
122
123#ifdef __cplusplus
124} // extern "C"
125#endif // __cplusplus
126
127#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOT_SVC_BOOT_SVC_MSG_H_