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 <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. #ifdef CONFIG_SUPPORT_PASSING_ATAGS
  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 struct cmd_tbl 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(struct cmd_tbl *cmdtp, int flag, int argc,
  89. char *const argv[])
  90. {
  91. const struct cmd_tbl *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 struct cmd_tbl cmd_spl_sub[] = {
  127. U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  128. };
  129. static int do_spl(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  130. {
  131. const struct cmd_tbl *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. );