~ubuntu-branches/ubuntu/saucy/u-boot/saucy

« back to all changes in this revision

Viewing changes to common/cmd_spl.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-01 18:07:19 UTC
  • mfrom: (16.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20120501180719-rjntk3287im4a0ns
Tags: 2012.04.01-1
* New upstream version.
  - Update mipsel-native-endianness.diff.
  - Update no-error-on-set-but-unused-variables.diff (partially merged).
  - Drop kirkwood_spi-irq_mask.diff (merged).
  - Drop kirkwood-disable-l2c.diff (merged).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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");