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