security.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * K3: Security functions
  4. *
  5. * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
  6. * Andrew F. Davis <afd@ti.com>
  7. */
  8. #include <common.h>
  9. #include <cpu_func.h>
  10. #include <dm.h>
  11. #include <hang.h>
  12. #include <image.h>
  13. #include <log.h>
  14. #include <asm/cache.h>
  15. #include <linux/soc/ti/ti_sci_protocol.h>
  16. #include <mach/spl.h>
  17. #include <spl.h>
  18. #include <asm/arch/sys_proto.h>
  19. void board_fit_image_post_process(void **p_image, size_t *p_size)
  20. {
  21. struct ti_sci_handle *ti_sci = get_ti_sci_handle();
  22. struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
  23. u64 image_addr;
  24. u32 image_size;
  25. int ret;
  26. image_addr = (uintptr_t)*p_image;
  27. image_size = *p_size;
  28. debug("Authenticating image at address 0x%016llx\n", image_addr);
  29. debug("Authenticating image of size %d bytes\n", image_size);
  30. flush_dcache_range((unsigned long)image_addr,
  31. ALIGN((unsigned long)image_addr + image_size,
  32. ARCH_DMA_MINALIGN));
  33. /* Authenticate image */
  34. ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
  35. if (ret) {
  36. printf("Authentication failed!\n");
  37. hang();
  38. }
  39. if (image_size)
  40. invalidate_dcache_range((unsigned long)image_addr,
  41. ALIGN((unsigned long)image_addr +
  42. image_size, ARCH_DMA_MINALIGN));
  43. /*
  44. * The image_size returned may be 0 when the authentication process has
  45. * moved the image. When this happens no further processing on the
  46. * image is needed or often even possible as it may have also been
  47. * placed behind a firewall when moved.
  48. */
  49. *p_size = image_size;
  50. /*
  51. * Output notification of successful authentication to re-assure the
  52. * user that the secure code is being processed as expected. However
  53. * suppress any such log output in case of building for SPL and booting
  54. * via YMODEM. This is done to avoid disturbing the YMODEM serial
  55. * protocol transactions.
  56. */
  57. if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
  58. IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
  59. spl_boot_device() == BOOT_DEVICE_UART))
  60. printf("Authentication passed\n");
  61. }