]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/fpga.c
2 * (C) Copyright 2000, 2001
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
5 * SPDX-License-Identifier: GPL-2.0+
18 static int fpga_get_op(char *opstr
);
33 /* ------------------------------------------------------------------------- */
35 * fpga <op> <device number> <data addr> <datasize>
36 * where op is 'load', 'dump', or 'info'
37 * If there is no device number field, the fpga environment variable is used.
38 * If there is no data addr field, the fpgadata environment variable is used.
39 * The info command requires no data address field.
41 int do_fpga(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
43 int op
, dev
= FPGA_INVALID_DEVICE
;
45 void *fpga_data
= NULL
;
46 char *devstr
= env_get("fpga");
47 char *datastr
= env_get("fpgadata");
50 #if defined(CONFIG_FIT)
51 const char *fit_uname
= NULL
;
54 #if defined(CONFIG_CMD_FPGA_LOADFS)
55 fpga_fs_info fpga_fsinfo
;
56 fpga_fsinfo
.fstype
= FS_TYPE_ANY
;
60 dev
= (int) simple_strtoul(devstr
, NULL
, 16);
62 fpga_data
= (void *)simple_strtoul(datastr
, NULL
, 16);
65 #if defined(CONFIG_CMD_FPGA_LOADFS)
67 fpga_fsinfo
.blocksize
= (unsigned int)
68 simple_strtoul(argv
[5], NULL
, 16);
69 fpga_fsinfo
.interface
= argv
[6];
70 fpga_fsinfo
.dev_part
= argv
[7];
71 fpga_fsinfo
.filename
= argv
[8];
73 case 5: /* fpga <op> <dev> <data> <datasize> */
74 data_size
= simple_strtoul(argv
[4], NULL
, 16);
76 case 4: /* fpga <op> <dev> <data> */
77 #if defined(CONFIG_FIT)
78 if (fit_parse_subimage(argv
[3], (ulong
)fpga_data
,
79 &fit_addr
, &fit_uname
)) {
80 fpga_data
= (void *)fit_addr
;
81 debug("* fpga: subimage '%s' from FIT image ",
83 debug("at 0x%08lx\n", fit_addr
);
87 fpga_data
= (void *)simple_strtoul(argv
[3], NULL
, 16);
88 debug("* fpga: cmdline image address = 0x%08lx\n",
91 debug("%s: fpga_data = 0x%lx\n", __func__
, (ulong
)fpga_data
);
93 case 3: /* fpga <op> <dev | data addr> */
94 dev
= (int)simple_strtoul(argv
[2], NULL
, 16);
95 debug("%s: device = %d\n", __func__
, dev
);
96 /* FIXME - this is a really weak test */
97 if ((argc
== 3) && (dev
> fpga_count())) {
98 /* must be buffer ptr */
99 debug("%s: Assuming buffer pointer in arg 3\n",
102 #if defined(CONFIG_FIT)
103 if (fit_parse_subimage(argv
[2], (ulong
)fpga_data
,
104 &fit_addr
, &fit_uname
)) {
105 fpga_data
= (void *)fit_addr
;
106 debug("* fpga: subimage '%s' from FIT image ",
108 debug("at 0x%08lx\n", fit_addr
);
112 fpga_data
= (void *)(uintptr_t)dev
;
113 debug("* fpga: cmdline image addr = 0x%08lx\n",
117 debug("%s: fpga_data = 0x%lx\n",
118 __func__
, (ulong
)fpga_data
);
119 dev
= FPGA_INVALID_DEVICE
; /* reset device num */
122 case 2: /* fpga <op> */
123 op
= (int)fpga_get_op(argv
[1]);
127 debug("%s: Too many or too few args (%d)\n", __func__
, argc
);
128 op
= FPGA_NONE
; /* force usage display */
132 if (dev
== FPGA_INVALID_DEVICE
) {
133 puts("FPGA device not specified\n");
141 #if defined(CONFIG_CMD_FPGA_LOADFS)
143 /* Blocksize can be zero */
144 if (!fpga_fsinfo
.interface
|| !fpga_fsinfo
.dev_part
||
145 !fpga_fsinfo
.filename
)
153 if (!fpga_data
|| !data_size
)
156 #if defined(CONFIG_CMD_FPGA_LOADMK)
165 puts("Wrong parameters for FPGA request\n");
171 return CMD_RET_USAGE
;
178 rc
= fpga_load(dev
, fpga_data
, data_size
, BIT_FULL
);
181 #if defined(CONFIG_CMD_FPGA_LOADP)
183 rc
= fpga_load(dev
, fpga_data
, data_size
, BIT_PARTIAL
);
188 rc
= fpga_loadbitstream(dev
, fpga_data
, data_size
, BIT_FULL
);
191 #if defined(CONFIG_CMD_FPGA_LOADBP)
193 rc
= fpga_loadbitstream(dev
, fpga_data
, data_size
, BIT_PARTIAL
);
197 #if defined(CONFIG_CMD_FPGA_LOADFS)
199 rc
= fpga_fsload(dev
, fpga_data
, data_size
, &fpga_fsinfo
);
203 #if defined(CONFIG_CMD_FPGA_LOADMK)
205 switch (genimg_get_format(fpga_data
)) {
206 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
207 case IMAGE_FORMAT_LEGACY
:
209 image_header_t
*hdr
=
210 (image_header_t
*)fpga_data
;
214 comp
= image_get_comp(hdr
);
215 if (comp
== IH_COMP_GZIP
) {
216 #if defined(CONFIG_GZIP)
217 ulong image_buf
= image_get_data(hdr
);
218 data
= image_get_load(hdr
);
219 ulong image_size
= ~0UL;
221 if (gunzip((void *)data
, ~0UL,
224 puts("GUNZIP: error\n");
227 data_size
= image_size
;
229 puts("Gunzip image is not supported\n");
233 data
= (ulong
)image_get_data(hdr
);
234 data_size
= image_get_data_size(hdr
);
236 rc
= fpga_load(dev
, (void *)data
, data_size
,
241 #if defined(CONFIG_FIT)
242 case IMAGE_FORMAT_FIT
:
244 const void *fit_hdr
= (const void *)fpga_data
;
246 const void *fit_data
;
248 if (fit_uname
== NULL
) {
249 puts("No FIT subimage unit name\n");
253 if (!fit_check_format(fit_hdr
)) {
254 puts("Bad FIT image format\n");
258 /* get fpga component image node offset */
259 noffset
= fit_image_get_node(fit_hdr
,
262 printf("Can't find '%s' FIT subimage\n",
267 /* verify integrity */
268 if (!fit_image_verify(fit_hdr
, noffset
)) {
269 puts ("Bad Data Hash\n");
273 /* get fpga subimage data address and length */
274 if (fit_image_get_data(fit_hdr
, noffset
,
275 &fit_data
, &data_size
)) {
276 puts("Fpga subimage data not found\n");
280 rc
= fpga_load(dev
, fit_data
, data_size
,
286 puts("** Unknown image type\n");
294 rc
= fpga_dump(dev
, fpga_data
, data_size
);
298 printf("Unknown operation\n");
299 return CMD_RET_USAGE
;
305 * Map op to supported operations. We don't use a table since we
306 * would just have to relocate it from flash anyway.
308 static int fpga_get_op(char *opstr
)
312 if (!strcmp("info", opstr
))
314 else if (!strcmp("loadb", opstr
))
316 else if (!strcmp("load", opstr
))
318 #if defined(CONFIG_CMD_FPGA_LOADP)
319 else if (!strcmp("loadp", opstr
))
322 #if defined(CONFIG_CMD_FPGA_LOADBP)
323 else if (!strcmp("loadbp", opstr
))
326 #if defined(CONFIG_CMD_FPGA_LOADFS)
327 else if (!strcmp("loadfs", opstr
))
330 #if defined(CONFIG_CMD_FPGA_LOADMK)
331 else if (!strcmp("loadmk", opstr
))
334 else if (!strcmp("dump", opstr
))
338 printf("Unknown fpga operation \"%s\"\n", opstr
);
343 #if defined(CONFIG_CMD_FPGA_LOADFS)
344 U_BOOT_CMD(fpga
, 9, 1, do_fpga
,
346 U_BOOT_CMD(fpga
, 6, 1, do_fpga
,
348 "loadable FPGA image support",
349 "[operation type] [device number] [image address] [image size]\n"
351 " dump\t[dev] [address] [size]\tLoad device to memory buffer\n"
352 " info\t[dev]\t\t\tlist known device information\n"
353 " load\t[dev] [address] [size]\tLoad device from memory buffer\n"
354 #if defined(CONFIG_CMD_FPGA_LOADP)
355 " loadp\t[dev] [address] [size]\t"
356 "Load device from memory buffer with partial bitstream\n"
358 " loadb\t[dev] [address] [size]\t"
359 "Load device from bitstream buffer (Xilinx only)\n"
360 #if defined(CONFIG_CMD_FPGA_LOADBP)
361 " loadbp\t[dev] [address] [size]\t"
362 "Load device from bitstream buffer with partial bitstream"
365 #if defined(CONFIG_CMD_FPGA_LOADFS)
366 "Load device from filesystem (FAT by default) (Xilinx only)\n"
367 " loadfs [dev] [address] [image size] [blocksize] <interface>\n"
368 " [<dev[:part]>] <filename>\n"
370 #if defined(CONFIG_CMD_FPGA_LOADMK)
371 " loadmk [dev] [address]\tLoad device generated with mkimage"
372 #if defined(CONFIG_FIT)
374 "\tFor loadmk operating on FIT format uImage address must include\n"
375 "\tsubimage unit name in the form of addr:<subimg_uname>"