2 * (C) Copyright 2000, 2001
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
5 * SPDX-License-Identifier: GPL-2.0+
17 static int fpga_get_op(char *opstr);
27 /* ------------------------------------------------------------------------- */
29 * fpga <op> <device number> <data addr> <datasize>
30 * where op is 'load', 'dump', or 'info'
31 * If there is no device number field, the fpga environment variable is used.
32 * If there is no data addr field, the fpgadata environment variable is used.
33 * The info command requires no data address field.
35 int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
37 int op, dev = FPGA_INVALID_DEVICE;
39 void *fpga_data = NULL;
40 char *devstr = getenv("fpga");
41 char *datastr = getenv("fpgadata");
44 #if defined(CONFIG_FIT)
45 const char *fit_uname = NULL;
50 dev = (int) simple_strtoul(devstr, NULL, 16);
52 fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
55 case 5: /* fpga <op> <dev> <data> <datasize> */
56 data_size = simple_strtoul(argv[4], NULL, 16);
58 case 4: /* fpga <op> <dev> <data> */
59 #if defined(CONFIG_FIT)
60 if (fit_parse_subimage(argv[3], (ulong)fpga_data,
61 &fit_addr, &fit_uname)) {
62 fpga_data = (void *)fit_addr;
63 debug("* fpga: subimage '%s' from FIT image ",
65 debug("at 0x%08lx\n", fit_addr);
69 fpga_data = (void *)simple_strtoul(argv[3], NULL, 16);
70 debug("* fpga: cmdline image address = 0x%08lx\n",
73 debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data);
75 case 3: /* fpga <op> <dev | data addr> */
76 dev = (int)simple_strtoul(argv[2], NULL, 16);
77 debug("%s: device = %d\n", __func__, dev);
78 /* FIXME - this is a really weak test */
79 if ((argc == 3) && (dev > fpga_count())) {
80 /* must be buffer ptr */
81 debug("%s: Assuming buffer pointer in arg 3\n",
84 #if defined(CONFIG_FIT)
85 if (fit_parse_subimage(argv[2], (ulong)fpga_data,
86 &fit_addr, &fit_uname)) {
87 fpga_data = (void *)fit_addr;
88 debug("* fpga: subimage '%s' from FIT image ",
90 debug("at 0x%08lx\n", fit_addr);
94 fpga_data = (void *)dev;
95 debug("* fpga: cmdline image addr = 0x%08lx\n",
99 debug("%s: fpga_data = 0x%x\n",
100 __func__, (uint)fpga_data);
101 dev = FPGA_INVALID_DEVICE; /* reset device num */
104 case 2: /* fpga <op> */
105 op = (int)fpga_get_op(argv[1]);
109 debug("%s: Too many or too few args (%d)\n", __func__, argc);
110 op = FPGA_NONE; /* force usage display */
114 if (dev == FPGA_INVALID_DEVICE) {
115 puts("FPGA device not specified\n");
126 if (!fpga_data || !data_size)
136 puts("Wrong parameters for FPGA request\n");
142 return CMD_RET_USAGE;
149 rc = fpga_load(dev, fpga_data, data_size);
153 rc = fpga_loadbitstream(dev, fpga_data, data_size);
157 switch (genimg_get_format(fpga_data)) {
158 case IMAGE_FORMAT_LEGACY:
160 image_header_t *hdr =
161 (image_header_t *)fpga_data;
164 data = (ulong)image_get_data(hdr);
165 data_size = image_get_data_size(hdr);
166 rc = fpga_load(dev, (void *)data, data_size);
169 #if defined(CONFIG_FIT)
170 case IMAGE_FORMAT_FIT:
172 const void *fit_hdr = (const void *)fpga_data;
174 const void *fit_data;
176 if (fit_uname == NULL) {
177 puts("No FIT subimage unit name\n");
181 if (!fit_check_format(fit_hdr)) {
182 puts("Bad FIT image format\n");
186 /* get fpga component image node offset */
187 noffset = fit_image_get_node(fit_hdr,
190 printf("Can't find '%s' FIT subimage\n",
195 /* verify integrity */
196 if (!fit_image_verify(fit_hdr, noffset)) {
197 puts ("Bad Data Hash\n");
201 /* get fpga subimage data address and length */
202 if (fit_image_get_data(fit_hdr, noffset,
203 &fit_data, &data_size)) {
204 puts("Fpga subimage data not found\n");
208 rc = fpga_load(dev, fit_data, data_size);
213 puts("** Unknown image type\n");
220 rc = fpga_dump(dev, fpga_data, data_size);
224 printf("Unknown operation\n");
225 return CMD_RET_USAGE;
231 * Map op to supported operations. We don't use a table since we
232 * would just have to relocate it from flash anyway.
234 static int fpga_get_op(char *opstr)
238 if (!strcmp("info", opstr))
240 else if (!strcmp("loadb", opstr))
242 else if (!strcmp("load", opstr))
244 else if (!strcmp("loadmk", opstr))
246 else if (!strcmp("dump", opstr))
250 printf("Unknown fpga operation \"%s\"\n", opstr);
255 U_BOOT_CMD(fpga, 6, 1, do_fpga,
256 "loadable FPGA image support",
257 "[operation type] [device number] [image address] [image size]\n"
259 " dump\t[dev]\t\t\tLoad device to memory buffer\n"
260 " info\t[dev]\t\t\tlist known device information\n"
261 " load\t[dev] [address] [size]\tLoad device from memory buffer\n"
262 " loadb\t[dev] [address] [size]\t"
263 "Load device from bitstream buffer (Xilinx only)\n"
264 " loadmk [dev] [address]\tLoad device generated with mkimage"
265 #if defined(CONFIG_FIT)
267 "\tFor loadmk operating on FIT format uImage address must include\n"
268 "\tsubimage unit name in the form of addr:<subimg_uname>"