Software APIs
flash_info_fields.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_MANUF_LIB_FLASH_INFO_FIELDS_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_MANUF_LIB_FLASH_INFO_FIELDS_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/status.h"
12 
13 #include "ast_regs.h" // Generated.
14 
15 typedef struct flash_info_field {
16  uint32_t partition;
17  uint32_t bank;
18  uint32_t page;
19  uint32_t byte_offset;
21 
22 enum {
23  /**
24  * AST Calibration Data Size - Bank 0, Page 0
25  *
26  * Number of AST calibration words that will be stored in flash / OTP.
27  */
28  kFlashInfoAstCalibrationDataSizeInBytes =
29  AST_REGAL_REG_OFFSET + sizeof(uint32_t),
30  kFlashInfoAstCalibrationDataSizeIn32BitWords =
31  kFlashInfoAstCalibrationDataSizeInBytes / sizeof(uint32_t),
32 
33  // Creator/Owner Seeds - Bank 0, Pages 1 and 2
34  kFlashInfoKeySeedSizeIn32BitWords = 32 / sizeof(uint32_t),
35 
36  // Wafer Authentication Secret - Bank 0, Page 3
37  kFlashInfoWaferAuthSecretSizeIn32BitWords = 32 / sizeof(uint32_t),
38 
39  // Attestation key gen seed indices
40  kFlashInfoFieldUdsKeySeedIdx = 0,
41  kFlashInfoFieldCdi0KeySeedIdx = 1,
42  kFlashInfoFieldCdi1KeySeedIdx = 2,
43  kFlashInfoFieldTpmEkKeySeedIdx = 3,
44 };
45 
46 extern const flash_info_field_t kFlashInfoFieldDeviceId;
47 extern const flash_info_field_t kFlashInfoFieldManufState;
48 extern const flash_info_field_t kFlashInfoFieldAstCalibrationData;
49 extern const flash_info_field_t kFlashInfoFieldCharacterizationData;
50 extern const flash_info_field_t kFlashInfoFieldCreatorSeed;
51 extern const flash_info_field_t kFlashInfoFieldOwnerSeed;
52 extern const flash_info_field_t kFlashInfoFieldWaferAuthSecret;
53 extern const flash_info_field_t kFlashInfoFieldUdsAttestationKeySeed;
54 extern const flash_info_field_t kFlashInfoFieldCdi0AttestationKeySeed;
55 extern const flash_info_field_t kFlashInfoFieldCdi1AttestationKeySeed;
56 extern const flash_info_field_t kFlashInfoFieldTpmEkAttestationKeySeed;
57 extern const flash_info_field_t kFlashInfoFieldTpmCekAttestationKeySeed;
58 extern const flash_info_field_t kFlashInfoFieldTpmCikAttestationKeySeed;
59 extern const flash_info_field_t kFlashInfoFieldDevSeedSeed;
60 extern const flash_info_field_t kFlashInfoFieldAttestationKeyGenVersion;
61 
62 /**
63  * Reads info flash page field.
64  *
65  * Assumes the page containing the field has already been configured for read
66  * access.
67  *
68  * @param flash_state Flash controller instance.
69  * @param field Flash info field information.
70  * @param[out] data_out Output buffer.
71  * @param num_words Number of words to read from flash and write to `data_out`.
72  * @return The result of the operation.
73  */
75 status_t manuf_flash_info_field_read(dif_flash_ctrl_state_t *flash_state,
76  flash_info_field_t field,
77  uint32_t *data_out, size_t num_words);
78 
79 /**
80  * Write info flash page field.
81  *
82  * Assumes the page containing the field has already been configured for
83  * write/erase access.
84  *
85  * @param flash_state Flash controller instance.
86  * @param field Flash info field information.
87  * @param data_in Input buffer.
88  * @param num_words Number of words to read from flash and write to `data_out`.
89  * @param erase_page_before_write Whether to erase the page before writing it.
90  * @return The result of the operation.
91  */
93 status_t manuf_flash_info_field_write(dif_flash_ctrl_state_t *flash_state,
94  flash_info_field_t field,
95  uint32_t *data_in, size_t num_words,
96  bool erase_page_before_write);
97 
98 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_MANUF_LIB_FLASH_INFO_FIELDS_H_