fvp_r_trusted_boot.c 1.8 KB

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