Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 |
| 4 | * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de> |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | #include <cmd_spl.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | static const char **subcmd_list[] = { |
| 15 | |
| 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 | #if defined(CONFIG_SETUP_MEMORY_TAGS) || \ |
| 32 | defined(CONFIG_CMDLINE_TAG) || \ |
| 33 | defined(CONFIG_INITRD_TAG) || \ |
| 34 | defined(CONFIG_SERIAL_TAG) || \ |
| 35 | defined(CONFIG_REVISION_TAG) |
| 36 | "start", |
| 37 | "loados", |
| 38 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 39 | "ramdisk", |
| 40 | #endif |
| 41 | "cmdline", |
| 42 | "bdt", |
| 43 | "prep", |
| 44 | #endif |
| 45 | NULL, |
| 46 | }, |
| 47 | NULL |
| 48 | }; |
| 49 | |
| 50 | /* Calls bootm with the parameters given */ |
| 51 | static int call_bootm(int argc, char * const argv[], const char *subcommand[]) |
| 52 | { |
| 53 | char *bootm_argv[5]; |
| 54 | |
| 55 | int i = 0; |
| 56 | int ret = 0; |
| 57 | int j; |
| 58 | |
| 59 | /* create paramter array */ |
| 60 | bootm_argv[0] = "do_bootm"; |
| 61 | switch (argc) { |
| 62 | case 3: |
| 63 | bootm_argv[4] = argv[2]; /* fdt addr */ |
| 64 | case 2: |
| 65 | bootm_argv[3] = argv[1]; /* initrd addr */ |
| 66 | case 1: |
| 67 | bootm_argv[2] = argv[0]; /* kernel addr */ |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | * - do the work - |
| 73 | * exec subcommands of do_bootm to init the images |
| 74 | * data structure |
| 75 | */ |
| 76 | while (subcommand[i] != NULL) { |
| 77 | bootm_argv[1] = (char *)subcommand[i]; |
| 78 | debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]); |
| 79 | for (j = 0; j < argc; j++) |
| 80 | debug("%s ", bootm_argv[j + 2]); |
| 81 | debug("\n"); |
| 82 | |
| 83 | ret = do_bootm(find_cmd("do_bootm"), 0, argc+2, |
| 84 | bootm_argv); |
| 85 | debug("Subcommand retcode: %d\n", ret); |
| 86 | i++; |
| 87 | } |
| 88 | |
| 89 | if (ret) { |
| 90 | printf("ERROR prep subcommand failed!\n"); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static cmd_tbl_t cmd_spl_export_sub[] = { |
| 98 | U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""), |
| 99 | U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""), |
| 100 | }; |
| 101 | |
| 102 | static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 103 | { |
| 104 | const cmd_tbl_t *c; |
| 105 | |
| 106 | if (argc < 2) /* no subcommand */ |
| 107 | return cmd_usage(cmdtp); |
| 108 | |
| 109 | c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0], |
| 110 | ARRAY_SIZE(cmd_spl_export_sub)); |
York Sun | d1f2ee7 | 2017-08-15 11:14:42 -0700 | [diff] [blame] | 111 | if ((c) && ((long)c->cmd <= SPL_EXPORT_LAST)) { |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 112 | argc -= 2; |
| 113 | argv += 2; |
York Sun | d1f2ee7 | 2017-08-15 11:14:42 -0700 | [diff] [blame] | 114 | if (call_bootm(argc, argv, subcmd_list[(long)c->cmd])) |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 115 | return -1; |
York Sun | d1f2ee7 | 2017-08-15 11:14:42 -0700 | [diff] [blame] | 116 | switch ((long)c->cmd) { |
Łukasz Majewski | bf3d58b | 2012-12-06 05:23:38 +0000 | [diff] [blame] | 117 | #ifdef CONFIG_OF_LIBFDT |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 118 | case SPL_EXPORT_FDT: |
| 119 | printf("Argument image is now in RAM: 0x%p\n", |
| 120 | (void *)images.ft_addr); |
Anatolij Gustschin | 767cb74a | 2017-08-17 21:01:48 +0200 | [diff] [blame] | 121 | env_set_addr("fdtargsaddr", images.ft_addr); |
| 122 | env_set_hex("fdtargslen", fdt_totalsize(images.ft_addr)); |
York Sun | b65ac63 | 2017-09-28 08:42:11 -0700 | [diff] [blame] | 123 | #ifdef CONFIG_CMD_SPL_WRITE_SIZE |
Anatolij Gustschin | 767cb74a | 2017-08-17 21:01:48 +0200 | [diff] [blame] | 124 | if (fdt_totalsize(images.ft_addr) > |
| 125 | CONFIG_CMD_SPL_WRITE_SIZE) |
| 126 | puts("WARN: FDT size > CMD_SPL_WRITE_SIZE\n"); |
York Sun | b65ac63 | 2017-09-28 08:42:11 -0700 | [diff] [blame] | 127 | #endif |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 128 | break; |
Łukasz Majewski | bf3d58b | 2012-12-06 05:23:38 +0000 | [diff] [blame] | 129 | #endif |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 130 | case SPL_EXPORT_ATAGS: |
| 131 | printf("Argument image is now in RAM at: 0x%p\n", |
| 132 | (void *)gd->bd->bi_boot_params); |
| 133 | break; |
| 134 | } |
| 135 | } else { |
| 136 | /* Unrecognized command */ |
| 137 | return cmd_usage(cmdtp); |
| 138 | } |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static cmd_tbl_t cmd_spl_sub[] = { |
| 144 | U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""), |
| 145 | }; |
| 146 | |
| 147 | static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 148 | { |
| 149 | const cmd_tbl_t *c; |
| 150 | int cmd; |
| 151 | |
| 152 | if (argc < 2) /* no subcommand */ |
| 153 | return cmd_usage(cmdtp); |
| 154 | |
| 155 | c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub)); |
| 156 | if (c) { |
York Sun | d1f2ee7 | 2017-08-15 11:14:42 -0700 | [diff] [blame] | 157 | cmd = (long)c->cmd; |
Simon Schwarz | 1648a37 | 2012-03-15 04:01:34 +0000 | [diff] [blame] | 158 | switch (cmd) { |
| 159 | case SPL_EXPORT: |
| 160 | argc--; |
| 161 | argv++; |
| 162 | if (spl_export(cmdtp, flag, argc, argv)) |
| 163 | printf("Subcommand failed\n"); |
| 164 | break; |
| 165 | default: |
| 166 | /* unrecognized command */ |
| 167 | return cmd_usage(cmdtp); |
| 168 | } |
| 169 | } else { |
| 170 | /* Unrecognized command */ |
| 171 | return cmd_usage(cmdtp); |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | U_BOOT_CMD( |
| 177 | spl, 6 , 1, do_spl, "SPL configuration", |
Stefano Babic | 28786eb | 2013-02-23 00:53:27 +0000 | [diff] [blame] | 178 | "export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr]\n" |
| 179 | "\timg\t\t\"atags\" or \"fdt\"\n" |
| 180 | "\tkernel_addr\taddress where a kernel image is stored.\n" |
| 181 | "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n" |
| 182 | "\tinitrd_addr\taddress of initial ramdisk\n" |
| 183 | "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n" |
| 184 | "\tfdt_addr\tin case of fdt, the address of the device tree.\n" |
| 185 | ); |