cmd_esbc_validate.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <fsl_validate.h>
  9. static int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
  10. char * const argv[])
  11. {
  12. if (fsl_check_boot_mode_secure() == 0) {
  13. printf("Boot Mode is Non-Secure. Not entering spin loop.\n");
  14. return 0;
  15. }
  16. printf("Core is entering spin loop.\n");
  17. loop:
  18. goto loop;
  19. return 0;
  20. }
  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. if (argc < 2)
  28. return cmd_usage(cmdtp);
  29. else if (argc > 2)
  30. /* Second arg - Optional - Hash Str*/
  31. hash_str = argv[2];
  32. /* First argument - header address -32/64bit */
  33. haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16);
  34. /* With esbc_validate command, Image address must be
  35. * part of header. So, the function is called
  36. * by passing this argument as 0.
  37. */
  38. ret = fsl_secboot_validate(haddr, hash_str, 0);
  39. if (ret)
  40. return 1;
  41. printf("esbc_validate command successful\n");
  42. return 0;
  43. }
  44. /***************************************************/
  45. static char esbc_validate_help_text[] =
  46. "esbc_validate hdr_addr <hash_val> - Validates signature using\n"
  47. " RSA verification\n"
  48. " $hdr_addr Address of header of the image\n"
  49. " to be validated.\n"
  50. " $hash_val -Optional\n"
  51. " It provides Hash of public/srk key to be\n"
  52. " used to verify signature.\n";
  53. U_BOOT_CMD(
  54. esbc_validate, 3, 0, do_esbc_validate,
  55. "Validates signature on a given image using RSA verification",
  56. esbc_validate_help_text
  57. );
  58. U_BOOT_CMD(
  59. esbc_halt, 1, 0, do_esbc_halt,
  60. "Put the core in spin loop (Secure Boot Only)",
  61. ""
  62. );