bsec_svc.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2016-2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <drivers/st/bsec.h>
  8. #include <drivers/st/bsec2_reg.h>
  9. #include <platform_def.h>
  10. #include <stm32mp1_smc.h>
  11. #include "bsec_svc.h"
  12. uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3,
  13. uint32_t *ret_otp_value)
  14. {
  15. uint32_t result;
  16. uint32_t tmp_data = 0U;
  17. switch (x1) {
  18. case STM32_SMC_READ_SHADOW:
  19. result = bsec_read_otp(ret_otp_value, x2);
  20. break;
  21. case STM32_SMC_PROG_OTP:
  22. *ret_otp_value = 0U;
  23. result = bsec_program_otp(x3, x2);
  24. break;
  25. case STM32_SMC_WRITE_SHADOW:
  26. *ret_otp_value = 0U;
  27. result = bsec_write_otp(x3, x2);
  28. break;
  29. case STM32_SMC_READ_OTP:
  30. *ret_otp_value = 0U;
  31. result = bsec_read_otp(&tmp_data, x2);
  32. if (result != BSEC_OK) {
  33. break;
  34. }
  35. result = bsec_shadow_read_otp(ret_otp_value, x2);
  36. if (result != BSEC_OK) {
  37. break;
  38. }
  39. result = bsec_write_otp(tmp_data, x2);
  40. break;
  41. default:
  42. return STM32_SMC_INVALID_PARAMS;
  43. }
  44. return (result == BSEC_OK) ? STM32_SMC_OK : STM32_SMC_FAILED;
  45. }