spl.c 4.2 KB

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