spl.c 4.2 KB

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