spl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2011
  3. * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <cmd_spl.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. static const char **subcmd_list[] = {
  12. [SPL_EXPORT_FDT] = (const char * []) {
  13. #ifdef CONFIG_OF_LIBFDT
  14. "start",
  15. "loados",
  16. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  17. "ramdisk",
  18. #endif
  19. "fdt",
  20. "cmdline",
  21. "bdt",
  22. "prep",
  23. #endif
  24. NULL,
  25. },
  26. [SPL_EXPORT_ATAGS] = (const char * []) {
  27. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  28. defined(CONFIG_CMDLINE_TAG) || \
  29. defined(CONFIG_INITRD_TAG) || \
  30. defined(CONFIG_SERIAL_TAG) || \
  31. defined(CONFIG_REVISION_TAG)
  32. "start",
  33. "loados",
  34. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  35. "ramdisk",
  36. #endif
  37. "cmdline",
  38. "bdt",
  39. "prep",
  40. #endif
  41. NULL,
  42. },
  43. NULL
  44. };
  45. /* Calls bootm with the parameters given */
  46. static int call_bootm(int argc, char * const argv[], const char *subcommand[])
  47. {
  48. char *bootm_argv[5];
  49. int i = 0;
  50. int ret = 0;
  51. int j;
  52. /* create paramter array */
  53. bootm_argv[0] = "do_bootm";
  54. switch (argc) {
  55. case 3:
  56. bootm_argv[4] = argv[2]; /* fdt addr */
  57. case 2:
  58. bootm_argv[3] = argv[1]; /* initrd addr */
  59. case 1:
  60. bootm_argv[2] = argv[0]; /* kernel addr */
  61. }
  62. /*
  63. * - do the work -
  64. * exec subcommands of do_bootm to init the images
  65. * data structure
  66. */
  67. while (subcommand[i] != NULL) {
  68. bootm_argv[1] = (char *)subcommand[i];
  69. debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
  70. for (j = 0; j < argc; j++)
  71. debug("%s ", bootm_argv[j + 2]);
  72. debug("\n");
  73. ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
  74. bootm_argv);
  75. debug("Subcommand retcode: %d\n", ret);
  76. i++;
  77. }
  78. if (ret) {
  79. printf("ERROR prep subcommand failed!\n");
  80. return -1;
  81. }
  82. return 0;
  83. }
  84. static cmd_tbl_t cmd_spl_export_sub[] = {
  85. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
  86. U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
  87. };
  88. static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  89. {
  90. const cmd_tbl_t *c;
  91. if (argc < 2) /* no subcommand */
  92. return cmd_usage(cmdtp);
  93. c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
  94. ARRAY_SIZE(cmd_spl_export_sub));
  95. if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
  96. argc -= 2;
  97. argv += 2;
  98. if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
  99. return -1;
  100. switch ((int)c->cmd) {
  101. #ifdef CONFIG_OF_LIBFDT
  102. case SPL_EXPORT_FDT:
  103. printf("Argument image is now in RAM: 0x%p\n",
  104. (void *)images.ft_addr);
  105. break;
  106. #endif
  107. case SPL_EXPORT_ATAGS:
  108. printf("Argument image is now in RAM at: 0x%p\n",
  109. (void *)gd->bd->bi_boot_params);
  110. break;
  111. }
  112. } else {
  113. /* Unrecognized command */
  114. return cmd_usage(cmdtp);
  115. }
  116. return 0;
  117. }
  118. static cmd_tbl_t cmd_spl_sub[] = {
  119. U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  120. };
  121. static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  122. {
  123. const cmd_tbl_t *c;
  124. int cmd;
  125. if (argc < 2) /* no subcommand */
  126. return cmd_usage(cmdtp);
  127. c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
  128. if (c) {
  129. cmd = (int)c->cmd;
  130. switch (cmd) {
  131. case SPL_EXPORT:
  132. argc--;
  133. argv++;
  134. if (spl_export(cmdtp, flag, argc, argv))
  135. printf("Subcommand failed\n");
  136. break;
  137. default:
  138. /* unrecognized command */
  139. return cmd_usage(cmdtp);
  140. }
  141. } else {
  142. /* Unrecognized command */
  143. return cmd_usage(cmdtp);
  144. }
  145. return 0;
  146. }
  147. U_BOOT_CMD(
  148. spl, 6 , 1, do_spl, "SPL configuration",
  149. "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
  150. "\timg\t\t\"atags\" or \"fdt\"\n"
  151. "\tkernel_addr\taddress where a kernel image is stored.\n"
  152. "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
  153. "\tinitrd_addr\taddress of initial ramdisk\n"
  154. "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
  155. "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
  156. );