xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_trusted_boot.c (revision 0a0a7a9ac82cb79af91f098cedc69cc67bca3978)
1 /*
2  * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <stdint.h>
9 #include <string.h>
10 
11 #include <lib/mmio.h>
12 #include <plat/arm/common/plat_arm.h>
13 #include <plat/common/platform.h>
14 #include <platform_def.h>
15 #include <tools_share/tbbr_oid.h>
16 
17 /*
18  * Return the ROTPK hash in the following ASN.1 structure in DER format:
19  *
20  * AlgorithmIdentifier  ::=  SEQUENCE  {
21  *     algorithm         OBJECT IDENTIFIER,
22  *     parameters        ANY DEFINED BY algorithm OPTIONAL
23  * }
24  *
25  * DigestInfo ::= SEQUENCE {
26  *     digestAlgorithm   AlgorithmIdentifier,
27  *     digest            OCTET STRING
28  * }
29  */
30 int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len,
31 			unsigned int *flags)
32 {
33 	return arm_get_rotpk_info(cookie, key_ptr, key_len, flags);
34 }
35 
36 /*
37  * Store a new non-volatile counter value.
38  *
39  * On some FVP versions, the non-volatile counters are read-only so this
40  * function will always fail.
41  *
42  * Return: 0 = success, Otherwise = error
43  */
44 int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr)
45 {
46 	const char *oid;
47 	uintptr_t nv_ctr_addr;
48 
49 	assert(cookie != NULL);
50 
51 	oid = (const char *)cookie;
52 	if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) {
53 		nv_ctr_addr = TFW_NVCTR_BASE;
54 	} else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) {
55 		nv_ctr_addr = NTFW_CTR_BASE;
56 	} else {
57 		return 1;
58 	}
59 
60 	mmio_write_32(nv_ctr_addr, nv_ctr);
61 
62 	/*
63 	 * If the FVP models a locked counter then its value cannot be updated
64 	 * and the above write operation has been silently ignored.
65 	 */
66 	return (mmio_read_32(nv_ctr_addr) == nv_ctr) ? 0 : 1;
67 }
68