1 /*
2 * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include <stdint.h>
9 #include "tfm_plat_otp.h"
10
11 #ifdef BL2
12
get_rotpk_hash(enum tfm_otp_element_id_t id,uint8_t * rotpk_hash,uint32_t * rotpk_hash_size)13 static enum tfm_plat_err_t get_rotpk_hash(enum tfm_otp_element_id_t id,
14 uint8_t* rotpk_hash,
15 uint32_t* rotpk_hash_size)
16 {
17 enum tfm_plat_err_t err;
18 size_t otp_size;
19
20 err = tfm_plat_otp_read(id, *rotpk_hash_size, rotpk_hash);
21 if (err != TFM_PLAT_ERR_SUCCESS) {
22 return err;
23 }
24
25 err = tfm_plat_otp_get_size(id, &otp_size);
26 if (err != TFM_PLAT_ERR_SUCCESS) {
27 return err;
28 }
29
30 *rotpk_hash_size = otp_size;
31
32 return TFM_PLAT_ERR_SUCCESS;
33 }
34
35 enum tfm_plat_err_t
tfm_plat_get_rotpk_hash(uint8_t image_id,uint8_t * rotpk_hash,uint32_t * rotpk_hash_size)36 tfm_plat_get_rotpk_hash(uint8_t image_id,
37 uint8_t *rotpk_hash,
38 uint32_t *rotpk_hash_size)
39 {
40 switch(image_id) {
41 case 0:
42 return get_rotpk_hash(PLAT_OTP_ID_BL2_ROTPK_0, rotpk_hash,
43 rotpk_hash_size);
44 case 1:
45 return get_rotpk_hash(PLAT_OTP_ID_BL2_ROTPK_1, rotpk_hash,
46 rotpk_hash_size);
47 case 2:
48 return get_rotpk_hash(PLAT_OTP_ID_BL2_ROTPK_2, rotpk_hash,
49 rotpk_hash_size);
50 case 3:
51 return get_rotpk_hash(PLAT_OTP_ID_BL2_ROTPK_3, rotpk_hash,
52 rotpk_hash_size);
53 default:
54 return TFM_PLAT_ERR_INVALID_INPUT;
55 }
56
57 return TFM_PLAT_ERR_SYSTEM_ERR;
58 }
59
60 #endif /* BL2 */
61