1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000, 2001
4 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
31 * Map op to supported operations. We don't use a table since we
32 * would just have to relocate it from flash anyway.
34 static int fpga_get_op(char *opstr
)
38 if (!strcmp("info", opstr
))
40 else if (!strcmp("loadb", opstr
))
42 else if (!strcmp("load", opstr
))
44 #if defined(CONFIG_CMD_FPGA_LOADP)
45 else if (!strcmp("loadp", opstr
))
48 #if defined(CONFIG_CMD_FPGA_LOADBP)
49 else if (!strcmp("loadbp", opstr
))
52 #if defined(CONFIG_CMD_FPGA_LOADFS)
53 else if (!strcmp("loadfs", opstr
))
56 #if defined(CONFIG_CMD_FPGA_LOADMK)
57 else if (!strcmp("loadmk", opstr
))
60 else if (!strcmp("dump", opstr
))
62 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
63 else if (!strcmp("loads", opstr
))
70 /* ------------------------------------------------------------------------- */
72 * fpga <op> <device number> <data addr> <datasize>
73 * where op is 'load', 'dump', or 'info'
74 * If there is no device number field, the fpga environment variable is used.
75 * If there is no data addr field, the fpgadata environment variable is used.
76 * The info command requires no data address field.
78 int do_fpga(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
80 int op
, dev
= FPGA_INVALID_DEVICE
;
82 void *fpga_data
= NULL
;
83 char *devstr
= env_get("fpga");
84 char *datastr
= env_get("fpgadata");
87 #if defined(CONFIG_FIT)
88 const char *fit_uname
= NULL
;
91 #if defined(CONFIG_CMD_FPGA_LOADFS)
92 fpga_fs_info fpga_fsinfo
;
93 fpga_fsinfo
.fstype
= FS_TYPE_ANY
;
95 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
96 struct fpga_secure_info fpga_sec_info
;
98 memset(&fpga_sec_info
, 0, sizeof(fpga_sec_info
));
102 dev
= (int) simple_strtoul(devstr
, NULL
, 16);
104 fpga_data
= (void *)simple_strtoul(datastr
, NULL
, 16);
106 if (argc
> 9 || argc
< 2) {
107 debug("%s: Too many or too few args (%d)\n", __func__
, argc
);
108 return CMD_RET_USAGE
;
111 op
= fpga_get_op(argv
[1]);
115 printf("Unknown fpga operation \"%s\"\n", argv
[1]);
116 return CMD_RET_USAGE
;
117 #if defined(CONFIG_CMD_FPGA_LOADFS)
120 return CMD_RET_USAGE
;
121 fpga_fsinfo
.blocksize
= (unsigned int)
122 simple_strtoul(argv
[5], NULL
, 16);
123 fpga_fsinfo
.interface
= argv
[6];
124 fpga_fsinfo
.dev_part
= argv
[7];
125 fpga_fsinfo
.filename
= argv
[8];
129 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
132 return CMD_RET_USAGE
;
134 fpga_sec_info
.userkey_addr
= (u8
*)(uintptr_t)
135 simple_strtoull(argv
[7],
137 fpga_sec_info
.encflag
= (u8
)simple_strtoul(argv
[6], NULL
, 16);
138 fpga_sec_info
.authflag
= (u8
)simple_strtoul(argv
[5], NULL
, 16);
147 case 5: /* fpga <op> <dev> <data> <datasize> */
148 data_size
= simple_strtoul(argv
[4], NULL
, 16);
150 case 4: /* fpga <op> <dev> <data> */
151 #if defined(CONFIG_FIT)
152 if (fit_parse_subimage(argv
[3], (ulong
)fpga_data
,
153 &fit_addr
, &fit_uname
)) {
154 fpga_data
= (void *)fit_addr
;
155 debug("* fpga: subimage '%s' from FIT image ",
157 debug("at 0x%08lx\n", fit_addr
);
161 fpga_data
= (void *)simple_strtoul(argv
[3], NULL
, 16);
162 debug("* fpga: cmdline image address = 0x%08lx\n",
165 debug("%s: fpga_data = 0x%lx\n", __func__
, (ulong
)fpga_data
);
167 case 3: /* fpga <op> <dev | data addr> */
168 dev
= (int)simple_strtoul(argv
[2], NULL
, 16);
169 debug("%s: device = %d\n", __func__
, dev
);
172 if (dev
== FPGA_INVALID_DEVICE
) {
173 puts("FPGA device not specified\n");
174 return CMD_RET_USAGE
;
180 #if defined(CONFIG_CMD_FPGA_LOADFS)
182 /* Blocksize can be zero */
183 if (!fpga_fsinfo
.interface
|| !fpga_fsinfo
.dev_part
||
184 !fpga_fsinfo
.filename
)
188 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
190 if (fpga_sec_info
.authflag
>= FPGA_NO_ENC_OR_NO_AUTH
&&
191 fpga_sec_info
.encflag
>= FPGA_NO_ENC_OR_NO_AUTH
) {
192 puts("ERR: use <fpga load> for NonSecure bitstream\n");
196 if (fpga_sec_info
.encflag
== FPGA_ENC_USR_KEY
&&
197 !fpga_sec_info
.userkey_addr
) {
199 puts("ERR:User key not provided\n");
208 if (!fpga_data
|| !data_size
)
211 #if defined(CONFIG_CMD_FPGA_LOADMK)
220 puts("Wrong parameters for FPGA request\n");
221 return CMD_RET_USAGE
;
230 rc
= fpga_load(dev
, fpga_data
, data_size
, BIT_FULL
);
233 #if defined(CONFIG_CMD_FPGA_LOADP)
235 rc
= fpga_load(dev
, fpga_data
, data_size
, BIT_PARTIAL
);
240 rc
= fpga_loadbitstream(dev
, fpga_data
, data_size
, BIT_FULL
);
243 #if defined(CONFIG_CMD_FPGA_LOADBP)
245 rc
= fpga_loadbitstream(dev
, fpga_data
, data_size
, BIT_PARTIAL
);
249 #if defined(CONFIG_CMD_FPGA_LOADFS)
251 rc
= fpga_fsload(dev
, fpga_data
, data_size
, &fpga_fsinfo
);
255 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
257 rc
= fpga_loads(dev
, fpga_data
, data_size
, &fpga_sec_info
);
261 #if defined(CONFIG_CMD_FPGA_LOADMK)
263 switch (genimg_get_format(fpga_data
)) {
264 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
265 case IMAGE_FORMAT_LEGACY
:
267 image_header_t
*hdr
=
268 (image_header_t
*)fpga_data
;
272 comp
= image_get_comp(hdr
);
273 if (comp
== IH_COMP_GZIP
) {
274 #if defined(CONFIG_GZIP)
275 ulong image_buf
= image_get_data(hdr
);
276 data
= image_get_load(hdr
);
277 ulong image_size
= ~0UL;
279 if (gunzip((void *)data
, ~0UL,
282 puts("GUNZIP: error\n");
285 data_size
= image_size
;
287 puts("Gunzip image is not supported\n");
291 data
= (ulong
)image_get_data(hdr
);
292 data_size
= image_get_data_size(hdr
);
294 rc
= fpga_load(dev
, (void *)data
, data_size
,
299 #if defined(CONFIG_FIT)
300 case IMAGE_FORMAT_FIT
:
302 const void *fit_hdr
= (const void *)fpga_data
;
304 const void *fit_data
;
306 if (fit_uname
== NULL
) {
307 puts("No FIT subimage unit name\n");
311 if (!fit_check_format(fit_hdr
)) {
312 puts("Bad FIT image format\n");
316 /* get fpga component image node offset */
317 noffset
= fit_image_get_node(fit_hdr
,
320 printf("Can't find '%s' FIT subimage\n",
325 /* verify integrity */
326 if (!fit_image_verify(fit_hdr
, noffset
)) {
327 puts ("Bad Data Hash\n");
331 /* get fpga subimage data address and length */
332 if (fit_image_get_data(fit_hdr
, noffset
,
333 &fit_data
, &data_size
)) {
334 puts("Fpga subimage data not found\n");
338 rc
= fpga_load(dev
, fit_data
, data_size
,
344 puts("** Unknown image type\n");
352 rc
= fpga_dump(dev
, fpga_data
, data_size
);
356 printf("Unknown operation\n");
357 return CMD_RET_USAGE
;
362 #if defined(CONFIG_CMD_FPGA_LOADFS) || defined(CONFIG_CMD_FPGA_LOAD_SECURE)
363 U_BOOT_CMD(fpga
, 9, 1, do_fpga
,
365 U_BOOT_CMD(fpga
, 6, 1, do_fpga
,
367 "loadable FPGA image support",
368 "[operation type] [device number] [image address] [image size]\n"
370 " dump\t[dev] [address] [size]\tLoad device to memory buffer\n"
371 " info\t[dev]\t\t\tlist known device information\n"
372 " load\t[dev] [address] [size]\tLoad device from memory buffer\n"
373 #if defined(CONFIG_CMD_FPGA_LOADP)
374 " loadp\t[dev] [address] [size]\t"
375 "Load device from memory buffer with partial bitstream\n"
377 " loadb\t[dev] [address] [size]\t"
378 "Load device from bitstream buffer (Xilinx only)\n"
379 #if defined(CONFIG_CMD_FPGA_LOADBP)
380 " loadbp\t[dev] [address] [size]\t"
381 "Load device from bitstream buffer with partial bitstream"
384 #if defined(CONFIG_CMD_FPGA_LOADFS)
385 "Load device from filesystem (FAT by default) (Xilinx only)\n"
386 " loadfs [dev] [address] [image size] [blocksize] <interface>\n"
387 " [<dev[:part]>] <filename>\n"
389 #if defined(CONFIG_CMD_FPGA_LOADMK)
390 " loadmk [dev] [address]\tLoad device generated with mkimage"
391 #if defined(CONFIG_FIT)
393 "\tFor loadmk operating on FIT format uImage address must include\n"
394 "\tsubimage unit name in the form of addr:<subimg_uname>"
397 #if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
398 "Load encrypted bitstream (Xilinx only)\n"
399 " loads [dev] [address] [size] [auth-OCM-0/DDR-1/noauth-2]\n"
400 " [enc-devkey(0)/userkey(1)/nenc(2) [Userkey address]\n"
401 "Loads the secure bistreams(authenticated/encrypted/both\n"
402 "authenticated and encrypted) of [size] from [address].\n"
403 "The auth-OCM/DDR flag specifies to perform authentication\n"
404 "in OCM or in DDR. 0 for OCM, 1 for DDR, 2 for no authentication.\n"
405 "The enc flag specifies which key to be used for decryption\n"
406 "0-device key, 1-user key, 2-no encryption.\n"
407 "The optional Userkey address specifies from which address key\n"
408 "has to be used for decryption if user key is selected.\n"
409 "NOTE: the sceure bitstream has to be created using xilinx\n"
410 "bootgen tool only.\n"