cmds.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2023, Advanced Micro Devices, Inc.
  4. *
  5. * Michal Simek <michal.simek@amd.com>
  6. */
  7. #include <cpu_func.h>
  8. #include <command.h>
  9. #include <common.h>
  10. #include <log.h>
  11. #include <memalign.h>
  12. #include <versalpl.h>
  13. #include <zynqmp_firmware.h>
  14. /**
  15. * do_versalnet_load_pdi - Handle the "versalnet load pdi" command-line command
  16. * @cmdtp: Command data struct pointer
  17. * @flag: Command flag
  18. * @argc: Command-line argument count
  19. * @argv: Array of command-line arguments
  20. *
  21. * Processes the Versal NET load pdi command
  22. *
  23. * Return: return 0 on success, Error value if command fails.
  24. * CMD_RET_USAGE incase of incorrect/missing parameters.
  25. */
  26. static int do_versalnet_load_pdi(struct cmd_tbl *cmdtp, int flag, int argc,
  27. char * const argv[])
  28. {
  29. u32 buf_lo, buf_hi;
  30. u32 ret_payload[PAYLOAD_ARG_CNT];
  31. ulong addr, *pdi_buf;
  32. size_t len;
  33. int ret;
  34. if (argc != cmdtp->maxargs) {
  35. debug("pdi_load: incorrect parameters passed\n");
  36. return CMD_RET_USAGE;
  37. }
  38. addr = simple_strtol(argv[1], NULL, 16);
  39. if (!addr) {
  40. debug("pdi_load: zero pdi_data address\n");
  41. return CMD_RET_USAGE;
  42. }
  43. len = hextoul(argv[2], NULL);
  44. if (!len) {
  45. debug("pdi_load: zero size\n");
  46. return CMD_RET_USAGE;
  47. }
  48. pdi_buf = (ulong *)ALIGN((ulong)addr, ARCH_DMA_MINALIGN);
  49. if ((ulong)addr != (ulong)pdi_buf) {
  50. memcpy((void *)pdi_buf, (void *)addr, len);
  51. debug("Pdi addr:0x%lx aligned to 0x%lx\n",
  52. addr, (ulong)pdi_buf);
  53. }
  54. flush_dcache_range((ulong)pdi_buf, (ulong)pdi_buf + len);
  55. buf_lo = lower_32_bits((ulong)pdi_buf);
  56. buf_hi = upper_32_bits((ulong)pdi_buf);
  57. ret = xilinx_pm_request(VERSAL_PM_LOAD_PDI, VERSAL_PM_PDI_TYPE, buf_lo,
  58. buf_hi, 0, ret_payload);
  59. if (ret)
  60. printf("PDI load failed with err: 0x%08x\n", ret);
  61. return cmd_process_error(cmdtp, ret);
  62. }
  63. static char versalnet_help_text[] =
  64. "loadpdi addr len - Load pdi image\n"
  65. "load pdi image at ddr address 'addr' with pdi image size 'len'\n"
  66. ;
  67. U_BOOT_CMD_WITH_SUBCMDS(versalnet, "Versal NET sub-system", versalnet_help_text,
  68. U_BOOT_SUBCMD_MKENT(loadpdi, 3, 1,
  69. do_versalnet_load_pdi));