cmd_spl.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. case SPL_EXPORT_FDT:
  118. printf("Argument image is now in RAM: 0x%p\n",
  119. (void *)images.ft_addr);
  120. break;
  121. case SPL_EXPORT_ATAGS:
  122. printf("Argument image is now in RAM at: 0x%p\n",
  123. (void *)gd->bd->bi_boot_params);
  124. break;
  125. }
  126. } else {
  127. /* Unrecognized command */
  128. return cmd_usage(cmdtp);
  129. }
  130. return 0;
  131. }
  132. static cmd_tbl_t cmd_spl_sub[] = {
  133. U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  134. };
  135. static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  136. {
  137. const cmd_tbl_t *c;
  138. int cmd;
  139. if (argc < 2) /* no subcommand */
  140. return cmd_usage(cmdtp);
  141. c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
  142. if (c) {
  143. cmd = (int)c->cmd;
  144. switch (cmd) {
  145. case SPL_EXPORT:
  146. argc--;
  147. argv++;
  148. if (spl_export(cmdtp, flag, argc, argv))
  149. printf("Subcommand failed\n");
  150. break;
  151. default:
  152. /* unrecognized command */
  153. return cmd_usage(cmdtp);
  154. }
  155. } else {
  156. /* Unrecognized command */
  157. return cmd_usage(cmdtp);
  158. }
  159. return 0;
  160. }
  161. U_BOOT_CMD(
  162. spl, 6 , 1, do_spl, "SPL configuration",
  163. "export <img=atags|fdt> [kernel_addr] [initrd_addr] "
  164. "[fdt_addr if <img> = fdt] - export a kernel parameter image\n"
  165. "\t initrd_img can be set to \"-\" if fdt_addr without initrd img is"
  166. "used");