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