Commit 1648a37505e84fc4e5268b026c3f1db862107e00

Authored by Simon Schwarz
Committed by Albert ARIBAUD
1 parent 19db9be4aa

Add cmd_spl command

This adds a spl command to the u-boot.

Related config:
CONFIG_CMD_SPL
	activate/deactivate the command
CONFIG_CMD_SPL_NAND_OFS
	Offset in NAND to use

Signed-off-by: Simon Schwarz <simonschwarzcor@gmail.com>
Signed-off-by: Stefano Babic <sbabic@denx.de>
CC: Tom Rini <tom.rini@gmail.com>
CC: Wolfgang Denk <wd@denx.de>

Showing 5 changed files with 253 additions and 0 deletions Side-by-side Diff

... ... @@ -162,6 +162,7 @@
162 162 endif
163 163 COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
164 164 COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
  165 +COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o
165 166  
166 167 # others
167 168 ifdef CONFIG_DDR_SPD
  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 +
  24 +#include <common.h>
  25 +#include <command.h>
  26 +#include <cmd_spl.h>
  27 +
  28 +DECLARE_GLOBAL_DATA_PTR;
  29 +
  30 +static const char **subcmd_list[] = {
  31 +
  32 + [SPL_EXPORT_FDT] = (const char * []) {
  33 +#ifdef CONFIG_OF_LIBFDT
  34 + "start",
  35 + "loados",
  36 + #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  37 + "ramdisk",
  38 + #endif
  39 + "fdt",
  40 + "cmdline",
  41 + "bdt",
  42 + "prep",
  43 +#endif
  44 + NULL,
  45 + },
  46 + [SPL_EXPORT_ATAGS] = (const char * []) {
  47 +#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  48 + defined(CONFIG_CMDLINE_TAG) || \
  49 + defined(CONFIG_INITRD_TAG) || \
  50 + defined(CONFIG_SERIAL_TAG) || \
  51 + defined(CONFIG_REVISION_TAG)
  52 + "start",
  53 + "loados",
  54 +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  55 + "ramdisk",
  56 +#endif
  57 + "cmdline",
  58 + "bdt",
  59 + "prep",
  60 +#endif
  61 + NULL,
  62 + },
  63 + NULL
  64 +};
  65 +
  66 +/* Calls bootm with the parameters given */
  67 +static int call_bootm(int argc, char * const argv[], const char *subcommand[])
  68 +{
  69 + char *bootm_argv[5];
  70 +
  71 + int i = 0;
  72 + int ret = 0;
  73 + int j;
  74 +
  75 + /* create paramter array */
  76 + bootm_argv[0] = "do_bootm";
  77 + switch (argc) {
  78 + case 3:
  79 + bootm_argv[4] = argv[2]; /* fdt addr */
  80 + case 2:
  81 + bootm_argv[3] = argv[1]; /* initrd addr */
  82 + case 1:
  83 + bootm_argv[2] = argv[0]; /* kernel addr */
  84 + }
  85 +
  86 +
  87 + /*
  88 + * - do the work -
  89 + * exec subcommands of do_bootm to init the images
  90 + * data structure
  91 + */
  92 + while (subcommand[i] != NULL) {
  93 + bootm_argv[1] = (char *)subcommand[i];
  94 + debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
  95 + for (j = 0; j < argc; j++)
  96 + debug("%s ", bootm_argv[j + 2]);
  97 + debug("\n");
  98 +
  99 + ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
  100 + bootm_argv);
  101 + debug("Subcommand retcode: %d\n", ret);
  102 + i++;
  103 + }
  104 +
  105 + if (ret) {
  106 + printf("ERROR prep subcommand failed!\n");
  107 + return -1;
  108 + }
  109 +
  110 + return 0;
  111 +}
  112 +
  113 +static cmd_tbl_t cmd_spl_export_sub[] = {
  114 + U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
  115 + U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
  116 +};
  117 +
  118 +static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  119 +{
  120 + const cmd_tbl_t *c;
  121 +
  122 + if (argc < 2) /* no subcommand */
  123 + return cmd_usage(cmdtp);
  124 +
  125 + c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0],
  126 + ARRAY_SIZE(cmd_spl_export_sub));
  127 + if ((c) && ((int)c->cmd <= SPL_EXPORT_LAST)) {
  128 + argc -= 2;
  129 + argv += 2;
  130 + if (call_bootm(argc, argv, subcmd_list[(int)c->cmd]))
  131 + return -1;
  132 + switch ((int)c->cmd) {
  133 + case SPL_EXPORT_FDT:
  134 + printf("Argument image is now in RAM: 0x%p\n",
  135 + (void *)images.ft_addr);
  136 + break;
  137 + case SPL_EXPORT_ATAGS:
  138 + printf("Argument image is now in RAM at: 0x%p\n",
  139 + (void *)gd->bd->bi_boot_params);
  140 + break;
  141 + }
  142 + } else {
  143 + /* Unrecognized command */
  144 + return cmd_usage(cmdtp);
  145 + }
  146 +
  147 + return 0;
  148 +}
  149 +
  150 +static cmd_tbl_t cmd_spl_sub[] = {
  151 + U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
  152 +};
  153 +
  154 +static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  155 +{
  156 + const cmd_tbl_t *c;
  157 + int cmd;
  158 +
  159 + if (argc < 2) /* no subcommand */
  160 + return cmd_usage(cmdtp);
  161 +
  162 + c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub));
  163 + if (c) {
  164 + cmd = (int)c->cmd;
  165 + switch (cmd) {
  166 + case SPL_EXPORT:
  167 + argc--;
  168 + argv++;
  169 + if (spl_export(cmdtp, flag, argc, argv))
  170 + printf("Subcommand failed\n");
  171 + break;
  172 + default:
  173 + /* unrecognized command */
  174 + return cmd_usage(cmdtp);
  175 + }
  176 + } else {
  177 + /* Unrecognized command */
  178 + return cmd_usage(cmdtp);
  179 + }
  180 + return 0;
  181 +}
  182 +
  183 +U_BOOT_CMD(
  184 + spl, 6 , 1, do_spl, "SPL configuration",
  185 + "export <img=atags|fdt> [kernel_addr] [initrd_addr] "
  186 + "[fdt_addr if <img> = fdt] - export a kernel parameter image\n"
  187 + "\t initrd_img can be set to \"-\" if fdt_addr without initrd img is"
  188 + "used");
doc/README.commands.spl
  1 +The spl command is used to export a boot parameter image to RAM. Later
  2 +it may implement more functions connected to the SPL.
  3 +
  4 +SUBCOMMAND EXPORT
  5 +To execute the command everything has to be in place as if bootm should be
  6 +used. (kernel image, initrd-image, fdt-image etc.)
  7 +
  8 +export has two subcommands:
  9 + atags: exports the ATAGS
  10 + fdt: exports the FDT
  11 +
  12 +Call is:
  13 +spl export <ftd|atags> [kernel_addr] [initrd_addr] [fdt_addr if fdt]
  14 +
  15 +
  16 +TYPICAL CALL
  17 +
  18 +on OMAP3:
  19 +nandecc hw
  20 +nand read 0x82000000 0x280000 0x400000 /* Read kernel image from NAND*/
  21 +spl export atags /* export ATAGS */
  22 +nand erase 0x680000 0x20000 /* erase - one page */
  23 +nand write 0x80000100 0x680000 0x20000 /* write the image - one page */
  24 +
  25 +call with FDT:
  26 +nandecc hw
  27 +nand read 0x82000000 0x280000 0x400000 /* Read kernel image from NAND*/
  28 +tftpboot 0x80000100 devkit8000.dtb /* Read fdt */
  29 +spl export fdt 0x82000000 - 0x80000100 /* export FDT */
  30 +nand erase 0x680000 0x20000 /* erase - one page */
  31 +nand write <adress shown by spl export> 0x680000 0x20000
  1 +/* Copyright (C) 2011
  2 + * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  3 + *
  4 + * See file CREDITS for list of people who contributed to this
  5 + * project.
  6 + *
  7 + * This program is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU General Public License as
  9 + * published by the Free Software Foundation; either version 2 of
  10 + * the License, or (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20 + * MA 02111-1307 USA
  21 + */
  22 +#ifndef _NAND_SPL_H_
  23 +#define _NAND_SPL_H_
  24 +
  25 +#define SPL_EXPORT (0x00000001)
  26 +
  27 +#define SPL_EXPORT_FDT (0x00000001)
  28 +#define SPL_EXPORT_ATAGS (0x00000002)
  29 +#define SPL_EXPORT_LAST SPL_EXPORT_ATAGS
  30 +
  31 +#endif /* _NAND_SPL_H_ */
... ... @@ -268,6 +268,8 @@
268 268 #endif
269 269 } bootm_headers_t;
270 270  
  271 +extern bootm_headers_t images;
  272 +
271 273 /*
272 274 * Some systems (for example LWMON) have very short watchdog periods;
273 275 * we must make sure to split long operations like memmove() or