cmd_esbc_validate.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <env.h>
  8. #include <fsl_validate.h>
  9. int do_esbc_halt(struct cmd_tbl *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. #ifndef CONFIG_SPL_BUILD
  22. static int do_esbc_validate(struct cmd_tbl *cmdtp, int flag, int argc,
  23. char *const argv[])
  24. {
  25. char *hash_str = NULL;
  26. uintptr_t haddr;
  27. int ret;
  28. uintptr_t img_addr = 0;
  29. char buf[20];
  30. if (argc < 2)
  31. return cmd_usage(cmdtp);
  32. else if (argc > 2)
  33. /* Second arg - Optional - Hash Str*/
  34. hash_str = argv[2];
  35. /* First argument - header address -32/64bit */
  36. haddr = (uintptr_t)hextoul(argv[1], NULL);
  37. /* With esbc_validate command, Image address must be
  38. * part of header. So, the function is called
  39. * by passing this argument as 0.
  40. */
  41. ret = fsl_secboot_validate(haddr, hash_str, &img_addr);
  42. /* Need to set "img_addr" even if validation failure.
  43. * Required when SB_EN in RCW set and non-fatal error
  44. * to continue U-Boot
  45. */
  46. sprintf(buf, "%lx", img_addr);
  47. env_set("img_addr", buf);
  48. if (ret)
  49. return 1;
  50. printf("esbc_validate command successful\n");
  51. return 0;
  52. }
  53. /***************************************************/
  54. static char esbc_validate_help_text[] =
  55. "esbc_validate hdr_addr <hash_val> - Validates signature using\n"
  56. " RSA verification\n"
  57. " $hdr_addr Address of header of the image\n"
  58. " to be validated.\n"
  59. " $hash_val -Optional\n"
  60. " It provides Hash of public/srk key to be\n"
  61. " used to verify signature.\n";
  62. U_BOOT_CMD(
  63. esbc_validate, 3, 0, do_esbc_validate,
  64. "Validates signature on a given image using RSA verification",
  65. esbc_validate_help_text
  66. );
  67. U_BOOT_CMD(
  68. esbc_halt, 1, 0, do_esbc_halt,
  69. "Put the core in spin loop (Secure Boot Only)",
  70. ""
  71. );
  72. #endif