x509_tbbr.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2018-2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <assert.h>
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <common/debug.h>
  11. #include <lib/cassert.h>
  12. #include <sfp.h>
  13. #include <tools_share/tbbr_oid.h>
  14. #include <plat/common/platform.h>
  15. #include "plat_common.h"
  16. extern char nxp_rotpk_hash[], nxp_rotpk_hash_end[];
  17. int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len,
  18. unsigned int *flags)
  19. {
  20. *key_ptr = nxp_rotpk_hash;
  21. *key_len = nxp_rotpk_hash_end - nxp_rotpk_hash;
  22. *flags = ROTPK_IS_HASH;
  23. return 0;
  24. }
  25. int plat_get_nv_ctr(void *cookie, unsigned int *nv_ctr)
  26. {
  27. const char *oid;
  28. uint32_t uid_num;
  29. uint32_t val = 0U;
  30. assert(cookie != NULL);
  31. assert(nv_ctr != NULL);
  32. oid = (const char *)cookie;
  33. if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) {
  34. uid_num = 3U;
  35. } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) {
  36. uid_num = 4U;
  37. } else {
  38. return 1;
  39. }
  40. val = sfp_read_oem_uid(uid_num);
  41. INFO("SFP Value read is %x from UID %d\n", val, uid_num);
  42. if (val == 0U) {
  43. *nv_ctr = 0U;
  44. } else {
  45. *nv_ctr = (32U - __builtin_clz(val));
  46. }
  47. INFO("NV Counter value for UID %d is %d\n", uid_num, *nv_ctr);
  48. return 0;
  49. }
  50. int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr)
  51. {
  52. const char *oid;
  53. uint32_t uid_num, sfp_val;
  54. assert(cookie != NULL);
  55. /* Counter values upto 32 are supported */
  56. if (nv_ctr > 32U) {
  57. return 1;
  58. }
  59. oid = (const char *)cookie;
  60. if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) {
  61. uid_num = 3U;
  62. } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) {
  63. uid_num = 4U;
  64. } else {
  65. return 1;
  66. }
  67. sfp_val = (1U << (nv_ctr - 1));
  68. if (sfp_write_oem_uid(uid_num, sfp_val) == 1) {
  69. /* Enable POVDD on board */
  70. if (board_enable_povdd()) {
  71. sfp_program_fuses();
  72. }
  73. /* Disable POVDD on board */
  74. board_disable_povdd();
  75. } else {
  76. ERROR("Invalid OEM UID sent.\n");
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
  82. {
  83. return get_mbedtls_heap_helper(heap_addr, heap_size);
  84. }