cmd_spl.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (C) 2011
  3. * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <cmd_spl.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. static const char **subcmd_list[] = {
  28. [SPL_EXPORT_FDT] = (const char * []) {
  29. #ifdef CONFIG_OF_LIBFDT
  30. "start",
  31. "loados",
  32. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  33. "ramdisk",
  34. #endif
  35. "fdt",
  36. "cmdline",
  37. "bdt",
  38. "prep",
  39. #endif
  40. NULL,
  41. },
  42. [SPL_EXPORT_ATAGS] = (const char * []) {
  43. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  44. defined(CONFIG_CMDLINE_TAG) || \
  45. defined(CONFIG_INITRD_TAG) || \
  46. defined(CONFIG_SERIAL_TAG) || \
  47. defined(CONFIG_REVISION_TAG)
  48. "start",
  49. "loados",
  50. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  51. "ramdisk",
  52. #endif
  53. "cmdline",
  54. "bdt",
  55. "prep",
  56. #endif
  57. NULL,
  58. },
  59. NULL
  60. };
  61. /* Calls bootm with the parameters given */
  62. static int call_bootm(int argc, char * const argv[], const char *subcommand[])
  63. {
  64. char *bootm_argv[5];
  65. int i = 0;
  66. int ret = 0;
  67. int j;
  68. /* create paramter array */
  69. bootm_argv[0] = "do_bootm";
  70. switch (argc) {
  71. case 3:
  72. bootm_argv[4] = argv[2]; /* fdt addr */
  73. case 2:
  74. bootm_argv[3] = argv[1]; /* initrd addr */
  75. case 1:
  76. bootm_argv[2] = argv[0]; /* kernel addr */
  77. }
  78. /*
  79. * - do the work -
  80. * exec subcommands of do_bootm to init the images
  81. * data structure
  82. */
  83. while (subcommand[i] != NULL) {
  84. bootm_argv[1] = (char *)subcommand[i];
  85. debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
  86. for (j = 0; j < argc; j++)
  87. debug("%s ", bootm_argv[j + 2]);
  88. debug("\n");
  89. ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
  90. bootm_argv);
  91. debug("Subcommand retcode: %d\n", ret);
  92. i++;
  93. }
  94. if (ret) {
  95. printf("ERROR prep subcommand failed!\n");
  96. return -1;
  97. }
  98. return 0;
  99. }
  100. static cmd_tbl_t cmd_spl_export_sub[] = {
  101. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
  102. U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
  103. };
  104. static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  105. {
  106. const cmd_tbl_t *c;
  107. if (argc < 2) /* no subcommand */
  108. return cmd_usage(cmdtp);
  109. c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
  110. ARRAY_SIZE(cmd_spl_export_sub));
  111. if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
  112. argc -= 2;
  113. argv += 2;
  114. if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
  115. return -1;
  116. switch ((int)c->cmd) {
  117. #ifdef CONFIG_OF_LIBFDT
  118. case SPL_EXPORT_FDT:
  119. printf("Argument image is now in RAM: 0x%p\n",
  120. (void *)images.ft_addr);
  121. break;
  122. #endif
  123. case SPL_EXPORT_ATAGS:
  124. printf("Argument image is now in RAM at: 0x%p\n",
  125. (void *)gd->bd->bi_boot_params);
  126. break;
  127. }
  128. } else {
  129. /* Unrecognized command */
  130. return cmd_usage(cmdtp);
  131. }
  132. return 0;
  133. }
  134. static cmd_tbl_t cmd_spl_sub[] = {
  135. U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  136. };
  137. static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  138. {
  139. const cmd_tbl_t *c;
  140. int cmd;
  141. if (argc < 2) /* no subcommand */
  142. return cmd_usage(cmdtp);
  143. c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
  144. if (c) {
  145. cmd = (int)c->cmd;
  146. switch (cmd) {
  147. case SPL_EXPORT:
  148. argc--;
  149. argv++;
  150. if (spl_export(cmdtp, flag, argc, argv))
  151. printf("Subcommand failed\n");
  152. break;
  153. default:
  154. /* unrecognized command */
  155. return cmd_usage(cmdtp);
  156. }
  157. } else {
  158. /* Unrecognized command */
  159. return cmd_usage(cmdtp);
  160. }
  161. return 0;
  162. }
  163. U_BOOT_CMD(
  164. spl, 6 , 1, do_spl, "SPL configuration",
  165. "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n"
  166. "\timg\t\t\"atags\" or \"fdt\"\n"
  167. "\tkernel_addr\taddress where a kernel image is stored.\n"
  168. "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n"
  169. "\tinitrd_addr\taddress of initial ramdisk\n"
  170. "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n"
  171. "\tfdt_addr\tin case of fdt, the address of the device tree.\n"
  172. );