source.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2001
  4. * Kyle Harris, kharris@nexus-tech.net
  5. */
  6. /*
  7. * The "source" command allows to define "script images", i. e. files
  8. * that contain command sequences that can be executed by the command
  9. * interpreter. It returns the exit status of the last command
  10. * executed from the script. This is very similar to running a shell
  11. * script in a UNIX shell, hence the name for the command.
  12. */
  13. /* #define DEBUG */
  14. #include <common.h>
  15. #include <command.h>
  16. #include <env.h>
  17. #include <image.h>
  18. #include <log.h>
  19. #include <malloc.h>
  20. #include <mapmem.h>
  21. #include <asm/byteorder.h>
  22. #include <asm/io.h>
  23. static int do_source(struct cmd_tbl *cmdtp, int flag, int argc,
  24. char *const argv[])
  25. {
  26. ulong addr;
  27. int rcode;
  28. const char *fit_uname = NULL, *confname = NULL;
  29. /* Find script image */
  30. if (argc < 2) {
  31. addr = CONFIG_SYS_LOAD_ADDR;
  32. debug("* source: default load address = 0x%08lx\n", addr);
  33. #if defined(CONFIG_FIT)
  34. } else if (fit_parse_subimage(argv[1], image_load_addr, &addr,
  35. &fit_uname)) {
  36. debug("* source: subimage '%s' from FIT image at 0x%08lx\n",
  37. fit_uname, addr);
  38. } else if (fit_parse_conf(argv[1], image_load_addr, &addr, &confname)) {
  39. debug("* source: config '%s' from FIT image at 0x%08lx\n",
  40. confname, addr);
  41. #endif
  42. } else {
  43. addr = hextoul(argv[1], NULL);
  44. debug("* source: cmdline image address = 0x%08lx\n", addr);
  45. }
  46. printf ("## Executing script at %08lx\n", addr);
  47. rcode = cmd_source_script(addr, fit_uname, confname);
  48. return rcode;
  49. }
  50. #ifdef CONFIG_SYS_LONGHELP
  51. static char source_help_text[] =
  52. #if defined(CONFIG_FIT)
  53. "[<addr>][:[<image>]|#[<config>]]\n"
  54. "\t- Run script starting at addr\n"
  55. "\t- A FIT config name or subimage name may be specified with : or #\n"
  56. "\t (like bootm). If the image or config name is omitted, the\n"
  57. "\t default is used.";
  58. #else
  59. "[<addr>]\n"
  60. "\t- Run script starting at addr";
  61. #endif
  62. #endif
  63. U_BOOT_CMD(
  64. source, 2, 0, do_source,
  65. "run script from memory", source_help_text
  66. );