spl.c 4.1 KB

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