1 /* 2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef BL1_1_OTP_H 9 #define BL1_1_OTP_H 10 11 #include <stdint.h> 12 #include <stddef.h> 13 14 #include "fih.h" 15 #include "crypto_key_defs.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #ifndef BL1_2_HASH_SIZE 22 #define BL1_2_HASH_SIZE 32 23 #endif /* BL1_2_HASH_SIZE */ 24 25 #ifndef BL2_HASH_SIZE 26 #define BL2_HASH_SIZE 32 27 #endif /* BL1_2_HASH_SIZE */ 28 29 #ifndef TFM_OTP_NV_COUNTER_NUMBER 30 #define TFM_OTP_NV_COUNTER_NUMBER 4u 31 #endif /* !TFM_OTP_NV_COUNTER_NUMBER */ 32 33 #ifndef TFM_OTP_NV_COUNTER_SIZE_IN_BITS 34 #define TFM_OTP_NV_COUNTER_SIZE_IN_BITS 32u 35 #endif /* !TFM_OTP_NV_COUNTER_SIZE_IN_BITS */ 36 37 /* Use ceiling division so we always have at least the correct amount of bits */ 38 #define TFM_OTP_NV_COUNTER_BYTES ((TFM_OTP_NV_COUNTER_SIZE_IN_BITS + 7) / 8) 39 40 enum tfm_bl1_nv_counter_id_t { 41 BL1_NV_COUNTER_ID_BL2_IMAGE, 42 }; 43 44 /* Initialise OTP system */ 45 fih_int bl1_otp_init(void); 46 47 /* Get hash of OTP bootloader image */ 48 fih_int bl1_otp_read_bl1_2_image_hash(uint8_t *hash); 49 50 /* Get hash of OTP bootloader image */ 51 fih_int bl1_otp_read_bl2_image_hash(uint8_t *hash); 52 53 /* Gets value of NV counter */ 54 fih_int bl1_otp_read_nv_counter(enum tfm_bl1_nv_counter_id_t counter_id, 55 uint32_t *count); 56 57 /* Sets value of NV counter, if greater than current */ 58 fih_int bl1_otp_write_nv_counter(enum tfm_bl1_nv_counter_id_t counter_id, 59 uint32_t count); 60 61 /* Load the key with the given ID into the key buf */ 62 fih_int bl1_otp_read_key(enum tfm_bl1_key_id_t key_id, uint8_t *key_buf); 63 64 #ifdef __cplusplus 65 } 66 #endif 67 68 #endif /* BL1_1_OTP_H */ 69