2 * (C) Copyright 2000, 2001
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
34 static int fpga_get_op(char *opstr);
44 /* ------------------------------------------------------------------------- */
46 * fpga <op> <device number> <data addr> <datasize>
47 * where op is 'load', 'dump', or 'info'
48 * If there is no device number field, the fpga environment variable is used.
49 * If there is no data addr field, the fpgadata environment variable is used.
50 * The info command requires no data address field.
52 int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
54 int op, dev = FPGA_INVALID_DEVICE;
56 void *fpga_data = NULL;
57 char *devstr = getenv("fpga");
58 char *datastr = getenv("fpgadata");
61 #if defined(CONFIG_FIT)
62 const char *fit_uname = NULL;
67 dev = (int) simple_strtoul(devstr, NULL, 16);
69 fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
72 case 5: /* fpga <op> <dev> <data> <datasize> */
73 data_size = simple_strtoul(argv[4], NULL, 16);
75 case 4: /* fpga <op> <dev> <data> */
76 #if defined(CONFIG_FIT)
77 if (fit_parse_subimage(argv[3], (ulong)fpga_data,
78 &fit_addr, &fit_uname)) {
79 fpga_data = (void *)fit_addr;
80 debug("* fpga: subimage '%s' from FIT image ",
82 debug("at 0x%08lx\n", fit_addr);
86 fpga_data = (void *)simple_strtoul(argv[3], NULL, 16);
87 debug("* fpga: cmdline image address = 0x%08lx\n",
90 debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data);
92 case 3: /* fpga <op> <dev | data addr> */
93 dev = (int)simple_strtoul(argv[2], NULL, 16);
94 debug("%s: device = %d\n", __func__, dev);
95 /* FIXME - this is a really weak test */
96 if ((argc == 3) && (dev > fpga_count())) {
97 /* must be buffer ptr */
98 debug("%s: Assuming buffer pointer in arg 3\n",
101 #if defined(CONFIG_FIT)
102 if (fit_parse_subimage(argv[2], (ulong)fpga_data,
103 &fit_addr, &fit_uname)) {
104 fpga_data = (void *)fit_addr;
105 debug("* fpga: subimage '%s' from FIT image ",
107 debug("at 0x%08lx\n", fit_addr);
111 fpga_data = (void *)dev;
112 debug("* fpga: cmdline image addr = 0x%08lx\n",
116 debug("%s: fpga_data = 0x%x\n",
117 __func__, (uint)fpga_data);
118 dev = FPGA_INVALID_DEVICE; /* reset device num */
121 case 2: /* fpga <op> */
122 op = (int)fpga_get_op(argv[1]);
126 debug("%s: Too many or too few args (%d)\n", __func__, argc);
127 op = FPGA_NONE; /* force usage display */
131 if (dev == FPGA_INVALID_DEVICE) {
132 puts("FPGA device not specified\n");
143 if (!fpga_data || !data_size)
153 puts("Wrong parameters for FPGA request\n");
159 return CMD_RET_USAGE;
166 rc = fpga_load(dev, fpga_data, data_size);
170 rc = fpga_loadbitstream(dev, fpga_data, data_size);
174 switch (genimg_get_format(fpga_data)) {
175 case IMAGE_FORMAT_LEGACY:
177 image_header_t *hdr =
178 (image_header_t *)fpga_data;
181 data = (ulong)image_get_data(hdr);
182 data_size = image_get_data_size(hdr);
183 rc = fpga_load(dev, (void *)data, data_size);
186 #if defined(CONFIG_FIT)
187 case IMAGE_FORMAT_FIT:
189 const void *fit_hdr = (const void *)fpga_data;
191 const void *fit_data;
193 if (fit_uname == NULL) {
194 puts("No FIT subimage unit name\n");
198 if (!fit_check_format(fit_hdr)) {
199 puts("Bad FIT image format\n");
203 /* get fpga component image node offset */
204 noffset = fit_image_get_node(fit_hdr,
207 printf("Can't find '%s' FIT subimage\n",
212 /* verify integrity */
213 if (!fit_image_verify(fit_hdr, noffset)) {
214 puts ("Bad Data Hash\n");
218 /* get fpga subimage data address and length */
219 if (fit_image_get_data(fit_hdr, noffset,
220 &fit_data, &data_size)) {
221 puts("Fpga subimage data not found\n");
225 rc = fpga_load(dev, fit_data, data_size);
230 puts("** Unknown image type\n");
237 rc = fpga_dump(dev, fpga_data, data_size);
241 printf("Unknown operation\n");
242 return CMD_RET_USAGE;
248 * Map op to supported operations. We don't use a table since we
249 * would just have to relocate it from flash anyway.
251 static int fpga_get_op(char *opstr)
255 if (!strcmp("info", opstr))
257 else if (!strcmp("loadb", opstr))
259 else if (!strcmp("load", opstr))
261 else if (!strcmp("loadmk", opstr))
263 else if (!strcmp("dump", opstr))
267 printf("Unknown fpga operation \"%s\"\n", opstr);
272 U_BOOT_CMD(fpga, 6, 1, do_fpga,
273 "loadable FPGA image support",
274 "[operation type] [device number] [image address] [image size]\n"
276 " dump\t[dev]\t\t\tLoad device to memory buffer\n"
277 " info\t[dev]\t\t\tlist known device information\n"
278 " load\t[dev] [address] [size]\tLoad device from memory buffer\n"
279 " loadb\t[dev] [address] [size]\t"
280 "Load device from bitstream buffer (Xilinx only)\n"
281 " loadmk [dev] [address]\tLoad device generated with mkimage"
282 #if defined(CONFIG_FIT)
284 "\tFor loadmk operating on FIT format uImage address must include\n"
285 "\tsubimage unit name in the form of addr:<subimg_uname>"