cmd_esbc_validate.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2015 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <fsl_validate.h>
  8. int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
  9. char * const argv[])
  10. {
  11. if (fsl_check_boot_mode_secure() == 0) {
  12. printf("Boot Mode is Non-Secure. Not entering spin loop.\n");
  13. return 0;
  14. }
  15. printf("Core is entering spin loop.\n");
  16. loop:
  17. goto loop;
  18. return 0;
  19. }
  20. #ifndef CONFIG_SPL_BUILD
  21. static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
  22. char * const argv[])
  23. {
  24. char *hash_str = NULL;
  25. uintptr_t haddr;
  26. int ret;
  27. uintptr_t img_addr = 0;
  28. char buf[20];
  29. if (argc < 2)
  30. return cmd_usage(cmdtp);
  31. else if (argc > 2)
  32. /* Second arg - Optional - Hash Str*/
  33. hash_str = argv[2];
  34. /* First argument - header address -32/64bit */
  35. haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16);
  36. /* With esbc_validate command, Image address must be
  37. * part of header. So, the function is called
  38. * by passing this argument as 0.
  39. */
  40. ret = fsl_secboot_validate(haddr, hash_str, &img_addr);
  41. /* Need to set "img_addr" even if validation failure.
  42. * Required when SB_EN in RCW set and non-fatal error
  43. * to continue U-Boot
  44. */
  45. sprintf(buf, "%lx", img_addr);
  46. env_set("img_addr", buf);
  47. if (ret)
  48. return 1;
  49. printf("esbc_validate command successful\n");
  50. return 0;
  51. }
  52. /***************************************************/
  53. static char esbc_validate_help_text[] =
  54. "esbc_validate hdr_addr <hash_val> - Validates signature using\n"
  55. " RSA verification\n"
  56. " $hdr_addr Address of header of the image\n"
  57. " to be validated.\n"
  58. " $hash_val -Optional\n"
  59. " It provides Hash of public/srk key to be\n"
  60. " used to verify signature.\n";
  61. U_BOOT_CMD(
  62. esbc_validate, 3, 0, do_esbc_validate,
  63. "Validates signature on a given image using RSA verification",
  64. esbc_validate_help_text
  65. );
  66. U_BOOT_CMD(
  67. esbc_halt, 1, 0, do_esbc_halt,
  68. "Put the core in spin loop (Secure Boot Only)",
  69. ""
  70. );
  71. #endif