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