spl.c 4.2 KB

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