Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000, 2001 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * FPGA support |
| 9 | */ |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 12 | #include <fpga.h> |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 13 | #include <fs.h> |
wdenk | 525d7b6 | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 14 | #include <malloc.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 15 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 16 | /* Local defines */ |
Michal Simek | 20d6b95 | 2017-01-06 11:20:54 +0100 | [diff] [blame] | 17 | enum { |
| 18 | FPGA_NONE = -1, |
| 19 | FPGA_INFO, |
| 20 | FPGA_LOAD, |
| 21 | FPGA_LOADB, |
| 22 | FPGA_DUMP, |
| 23 | FPGA_LOADMK, |
| 24 | FPGA_LOADP, |
| 25 | FPGA_LOADBP, |
| 26 | FPGA_LOADFS, |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 27 | FPGA_LOADS, |
Michal Simek | 20d6b95 | 2017-01-06 11:20:54 +0100 | [diff] [blame] | 28 | }; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 29 | |
Michal Simek | a255597 | 2018-05-30 10:00:40 +0200 | [diff] [blame^] | 30 | /* |
| 31 | * Map op to supported operations. We don't use a table since we |
| 32 | * would just have to relocate it from flash anyway. |
| 33 | */ |
| 34 | static int fpga_get_op(char *opstr) |
| 35 | { |
| 36 | int op = FPGA_NONE; |
| 37 | |
| 38 | if (!strcmp("info", opstr)) |
| 39 | op = FPGA_INFO; |
| 40 | else if (!strcmp("loadb", opstr)) |
| 41 | op = FPGA_LOADB; |
| 42 | else if (!strcmp("load", opstr)) |
| 43 | op = FPGA_LOAD; |
| 44 | #if defined(CONFIG_CMD_FPGA_LOADP) |
| 45 | else if (!strcmp("loadp", opstr)) |
| 46 | op = FPGA_LOADP; |
| 47 | #endif |
| 48 | #if defined(CONFIG_CMD_FPGA_LOADBP) |
| 49 | else if (!strcmp("loadbp", opstr)) |
| 50 | op = FPGA_LOADBP; |
| 51 | #endif |
| 52 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 53 | else if (!strcmp("loadfs", opstr)) |
| 54 | op = FPGA_LOADFS; |
| 55 | #endif |
| 56 | #if defined(CONFIG_CMD_FPGA_LOADMK) |
| 57 | else if (!strcmp("loadmk", opstr)) |
| 58 | op = FPGA_LOADMK; |
| 59 | #endif |
| 60 | else if (!strcmp("dump", opstr)) |
| 61 | op = FPGA_DUMP; |
| 62 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 63 | else if (!strcmp("loads", opstr)) |
| 64 | op = FPGA_LOADS; |
| 65 | #endif |
| 66 | |
| 67 | return op; |
| 68 | } |
| 69 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 70 | /* ------------------------------------------------------------------------- */ |
| 71 | /* command form: |
| 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. |
| 77 | */ |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 78 | int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 79 | { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 80 | int op, dev = FPGA_INVALID_DEVICE; |
| 81 | size_t data_size = 0; |
| 82 | void *fpga_data = NULL; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 83 | char *devstr = env_get("fpga"); |
| 84 | char *datastr = env_get("fpgadata"); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 85 | int rc = FPGA_FAIL; |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 86 | int wrong_parms = 0; |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 87 | #if defined(CONFIG_FIT) |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 88 | const char *fit_uname = NULL; |
| 89 | ulong fit_addr; |
| 90 | #endif |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 91 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 92 | fpga_fs_info fpga_fsinfo; |
| 93 | fpga_fsinfo.fstype = FS_TYPE_ANY; |
| 94 | #endif |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 95 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 96 | struct fpga_secure_info fpga_sec_info; |
| 97 | |
| 98 | memset(&fpga_sec_info, 0, sizeof(fpga_sec_info)); |
| 99 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 100 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 101 | if (devstr) |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 102 | dev = (int) simple_strtoul(devstr, NULL, 16); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 103 | if (datastr) |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 104 | fpga_data = (void *)simple_strtoul(datastr, NULL, 16); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 105 | |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 106 | if (argc > 9 || argc < 2) { |
| 107 | debug("%s: Too many or too few args (%d)\n", __func__, argc); |
| 108 | return CMD_RET_USAGE; |
| 109 | } |
| 110 | |
Michal Simek | a255597 | 2018-05-30 10:00:40 +0200 | [diff] [blame^] | 111 | op = fpga_get_op(argv[1]); |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 112 | |
| 113 | switch (op) { |
Michal Simek | 2c66019 | 2018-05-30 09:57:42 +0200 | [diff] [blame] | 114 | case FPGA_NONE: |
| 115 | printf("Unknown fpga operation \"%s\"\n", argv[1]); |
| 116 | return CMD_RET_USAGE; |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 117 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 118 | case FPGA_LOADFS: |
| 119 | if (argc < 9) |
| 120 | return CMD_RET_USAGE; |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 121 | fpga_fsinfo.blocksize = (unsigned int) |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 122 | simple_strtoul(argv[5], NULL, 16); |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 123 | fpga_fsinfo.interface = argv[6]; |
| 124 | fpga_fsinfo.dev_part = argv[7]; |
| 125 | fpga_fsinfo.filename = argv[8]; |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 126 | argc = 5; |
| 127 | break; |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 128 | #endif |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 129 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 130 | case FPGA_LOADS: |
| 131 | if (argc < 7) |
| 132 | return CMD_RET_USAGE; |
| 133 | if (argc == 8) |
| 134 | fpga_sec_info.userkey_addr = (u8 *)(uintptr_t) |
| 135 | simple_strtoull(argv[7], |
| 136 | NULL, 16); |
| 137 | fpga_sec_info.encflag = (u8)simple_strtoul(argv[6], NULL, 16); |
| 138 | fpga_sec_info.authflag = (u8)simple_strtoul(argv[5], NULL, 16); |
| 139 | argc = 5; |
| 140 | break; |
| 141 | #endif |
Siva Durga Prasad Paladugu | 8f039b1 | 2018-05-31 15:10:21 +0530 | [diff] [blame] | 142 | default: |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | switch (argc) { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 147 | case 5: /* fpga <op> <dev> <data> <datasize> */ |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 148 | data_size = simple_strtoul(argv[4], NULL, 16); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 149 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 150 | case 4: /* fpga <op> <dev> <data> */ |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 151 | #if defined(CONFIG_FIT) |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 152 | if (fit_parse_subimage(argv[3], (ulong)fpga_data, |
| 153 | &fit_addr, &fit_uname)) { |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 154 | fpga_data = (void *)fit_addr; |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 155 | debug("* fpga: subimage '%s' from FIT image ", |
| 156 | fit_uname); |
| 157 | debug("at 0x%08lx\n", fit_addr); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 158 | } else |
| 159 | #endif |
| 160 | { |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 161 | fpga_data = (void *)simple_strtoul(argv[3], NULL, 16); |
Stefano Babic | b69b9a5 | 2011-12-28 06:47:01 +0000 | [diff] [blame] | 162 | debug("* fpga: cmdline image address = 0x%08lx\n", |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 163 | (ulong)fpga_data); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 164 | } |
Michal Simek | 77bb86d | 2016-01-05 13:51:48 +0100 | [diff] [blame] | 165 | debug("%s: fpga_data = 0x%lx\n", __func__, (ulong)fpga_data); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 166 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 167 | case 3: /* fpga <op> <dev | data addr> */ |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 168 | dev = (int)simple_strtoul(argv[2], NULL, 16); |
Stefano Babic | b69b9a5 | 2011-12-28 06:47:01 +0000 | [diff] [blame] | 169 | debug("%s: device = %d\n", __func__, dev); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 170 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 171 | |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 172 | if (dev == FPGA_INVALID_DEVICE) { |
| 173 | puts("FPGA device not specified\n"); |
| 174 | op = FPGA_NONE; |
| 175 | } |
| 176 | |
| 177 | switch (op) { |
| 178 | case FPGA_NONE: |
| 179 | case FPGA_INFO: |
| 180 | break; |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 181 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 182 | case FPGA_LOADFS: |
| 183 | /* Blocksize can be zero */ |
| 184 | if (!fpga_fsinfo.interface || !fpga_fsinfo.dev_part || |
| 185 | !fpga_fsinfo.filename) |
| 186 | wrong_parms = 1; |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 187 | break; |
| 188 | #endif |
| 189 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 190 | case FPGA_LOADS: |
| 191 | if (fpga_sec_info.authflag >= FPGA_NO_ENC_OR_NO_AUTH && |
| 192 | fpga_sec_info.encflag >= FPGA_NO_ENC_OR_NO_AUTH) { |
| 193 | puts("ERR: use <fpga load> for NonSecure bitstream\n"); |
| 194 | wrong_parms = 1; |
| 195 | } |
| 196 | |
| 197 | if (fpga_sec_info.encflag == FPGA_ENC_USR_KEY && |
| 198 | !fpga_sec_info.userkey_addr) { |
| 199 | wrong_parms = 1; |
| 200 | puts("ERR:User key not provided\n"); |
| 201 | } |
| 202 | break; |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 203 | #endif |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 204 | case FPGA_LOAD: |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 205 | case FPGA_LOADP: |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 206 | case FPGA_LOADB: |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 207 | case FPGA_LOADBP: |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 208 | case FPGA_DUMP: |
| 209 | if (!fpga_data || !data_size) |
| 210 | wrong_parms = 1; |
| 211 | break; |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 212 | #if defined(CONFIG_CMD_FPGA_LOADMK) |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 213 | case FPGA_LOADMK: |
| 214 | if (!fpga_data) |
| 215 | wrong_parms = 1; |
| 216 | break; |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 217 | #endif |
Stefano Babic | 67d7f56 | 2010-10-19 09:22:52 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if (wrong_parms) { |
| 221 | puts("Wrong parameters for FPGA request\n"); |
| 222 | op = FPGA_NONE; |
| 223 | } |
| 224 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 225 | switch (op) { |
| 226 | case FPGA_NONE: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 227 | return CMD_RET_USAGE; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 228 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 229 | case FPGA_INFO: |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 230 | rc = fpga_info(dev); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 231 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 232 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 233 | case FPGA_LOAD: |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 234 | rc = fpga_load(dev, fpga_data, data_size, BIT_FULL); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 235 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 236 | |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 237 | #if defined(CONFIG_CMD_FPGA_LOADP) |
| 238 | case FPGA_LOADP: |
| 239 | rc = fpga_load(dev, fpga_data, data_size, BIT_PARTIAL); |
| 240 | break; |
| 241 | #endif |
| 242 | |
wdenk | 310b4fc | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 243 | case FPGA_LOADB: |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 244 | rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_FULL); |
wdenk | 310b4fc | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 245 | break; |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 246 | |
| 247 | #if defined(CONFIG_CMD_FPGA_LOADBP) |
| 248 | case FPGA_LOADBP: |
| 249 | rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_PARTIAL); |
| 250 | break; |
| 251 | #endif |
wdenk | 310b4fc | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 252 | |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 253 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 254 | case FPGA_LOADFS: |
| 255 | rc = fpga_fsload(dev, fpga_data, data_size, &fpga_fsinfo); |
| 256 | break; |
| 257 | #endif |
| 258 | |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 259 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 260 | case FPGA_LOADS: |
| 261 | rc = fpga_loads(dev, fpga_data, data_size, &fpga_sec_info); |
| 262 | break; |
| 263 | #endif |
| 264 | |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 265 | #if defined(CONFIG_CMD_FPGA_LOADMK) |
Stefan Roese | 5f1cf2d | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 266 | case FPGA_LOADMK: |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 267 | switch (genimg_get_format(fpga_data)) { |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 268 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 269 | case IMAGE_FORMAT_LEGACY: |
| 270 | { |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 271 | image_header_t *hdr = |
| 272 | (image_header_t *)fpga_data; |
| 273 | ulong data; |
Michal Simek | ead2d42 | 2013-10-04 10:51:01 +0200 | [diff] [blame] | 274 | uint8_t comp; |
| 275 | |
| 276 | comp = image_get_comp(hdr); |
| 277 | if (comp == IH_COMP_GZIP) { |
Michal Simek | be09b94 | 2014-07-16 10:30:50 +0200 | [diff] [blame] | 278 | #if defined(CONFIG_GZIP) |
Michal Simek | ead2d42 | 2013-10-04 10:51:01 +0200 | [diff] [blame] | 279 | ulong image_buf = image_get_data(hdr); |
| 280 | data = image_get_load(hdr); |
| 281 | ulong image_size = ~0UL; |
Stefan Roese | 5f1cf2d | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 282 | |
Michal Simek | ead2d42 | 2013-10-04 10:51:01 +0200 | [diff] [blame] | 283 | if (gunzip((void *)data, ~0UL, |
| 284 | (void *)image_buf, |
| 285 | &image_size) != 0) { |
| 286 | puts("GUNZIP: error\n"); |
| 287 | return 1; |
| 288 | } |
| 289 | data_size = image_size; |
Michal Simek | be09b94 | 2014-07-16 10:30:50 +0200 | [diff] [blame] | 290 | #else |
| 291 | puts("Gunzip image is not supported\n"); |
| 292 | return 1; |
| 293 | #endif |
Michal Simek | ead2d42 | 2013-10-04 10:51:01 +0200 | [diff] [blame] | 294 | } else { |
| 295 | data = (ulong)image_get_data(hdr); |
| 296 | data_size = image_get_data_size(hdr); |
| 297 | } |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 298 | rc = fpga_load(dev, (void *)data, data_size, |
| 299 | BIT_FULL); |
Stefan Roese | 5f1cf2d | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 300 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 301 | break; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 302 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 303 | #if defined(CONFIG_FIT) |
| 304 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 305 | { |
| 306 | const void *fit_hdr = (const void *)fpga_data; |
| 307 | int noffset; |
Wolfgang Denk | 74f9b38 | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 308 | const void *fit_data; |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 309 | |
| 310 | if (fit_uname == NULL) { |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 311 | puts("No FIT subimage unit name\n"); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 312 | return 1; |
| 313 | } |
| 314 | |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 315 | if (!fit_check_format(fit_hdr)) { |
| 316 | puts("Bad FIT image format\n"); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 317 | return 1; |
| 318 | } |
| 319 | |
| 320 | /* get fpga component image node offset */ |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 321 | noffset = fit_image_get_node(fit_hdr, |
| 322 | fit_uname); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 323 | if (noffset < 0) { |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 324 | printf("Can't find '%s' FIT subimage\n", |
| 325 | fit_uname); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 326 | return 1; |
| 327 | } |
| 328 | |
| 329 | /* verify integrity */ |
Simon Glass | 7428ad1 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 330 | if (!fit_image_verify(fit_hdr, noffset)) { |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 331 | puts ("Bad Data Hash\n"); |
| 332 | return 1; |
| 333 | } |
| 334 | |
| 335 | /* get fpga subimage data address and length */ |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 336 | if (fit_image_get_data(fit_hdr, noffset, |
| 337 | &fit_data, &data_size)) { |
| 338 | puts("Fpga subimage data not found\n"); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 339 | return 1; |
| 340 | } |
| 341 | |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 342 | rc = fpga_load(dev, fit_data, data_size, |
| 343 | BIT_FULL); |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 344 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 345 | break; |
| 346 | #endif |
| 347 | default: |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 348 | puts("** Unknown image type\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 349 | rc = FPGA_FAIL; |
| 350 | break; |
Stefan Roese | 5f1cf2d | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 351 | } |
| 352 | break; |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 353 | #endif |
Stefan Roese | 5f1cf2d | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 354 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 355 | case FPGA_DUMP: |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 356 | rc = fpga_dump(dev, fpga_data, data_size); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 357 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 358 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 359 | default: |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 360 | printf("Unknown operation\n"); |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 361 | return CMD_RET_USAGE; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 362 | } |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 363 | return rc; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 366 | #if defined(CONFIG_CMD_FPGA_LOADFS) || defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 367 | U_BOOT_CMD(fpga, 9, 1, do_fpga, |
| 368 | #else |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 369 | U_BOOT_CMD(fpga, 6, 1, do_fpga, |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 370 | #endif |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 371 | "loadable FPGA image support", |
| 372 | "[operation type] [device number] [image address] [image size]\n" |
| 373 | "fpga operations:\n" |
Michal Simek | 70da592 | 2015-01-26 08:52:27 +0100 | [diff] [blame] | 374 | " dump\t[dev] [address] [size]\tLoad device to memory buffer\n" |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 375 | " info\t[dev]\t\t\tlist known device information\n" |
| 376 | " load\t[dev] [address] [size]\tLoad device from memory buffer\n" |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 377 | #if defined(CONFIG_CMD_FPGA_LOADP) |
| 378 | " loadp\t[dev] [address] [size]\t" |
| 379 | "Load device from memory buffer with partial bitstream\n" |
| 380 | #endif |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 381 | " loadb\t[dev] [address] [size]\t" |
| 382 | "Load device from bitstream buffer (Xilinx only)\n" |
Michal Simek | 64c7098 | 2014-05-02 13:43:39 +0200 | [diff] [blame] | 383 | #if defined(CONFIG_CMD_FPGA_LOADBP) |
| 384 | " loadbp\t[dev] [address] [size]\t" |
| 385 | "Load device from bitstream buffer with partial bitstream" |
| 386 | "(Xilinx only)\n" |
| 387 | #endif |
Siva Durga Prasad Paladugu | 9112b4c | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 388 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 389 | "Load device from filesystem (FAT by default) (Xilinx only)\n" |
| 390 | " loadfs [dev] [address] [image size] [blocksize] <interface>\n" |
| 391 | " [<dev[:part]>] <filename>\n" |
| 392 | #endif |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 393 | #if defined(CONFIG_CMD_FPGA_LOADMK) |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 394 | " loadmk [dev] [address]\tLoad device generated with mkimage" |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 395 | #if defined(CONFIG_FIT) |
Michal Simek | a888af7 | 2013-04-26 13:10:07 +0200 | [diff] [blame] | 396 | "\n" |
| 397 | "\tFor loadmk operating on FIT format uImage address must include\n" |
| 398 | "\tsubimage unit name in the form of addr:<subimg_uname>" |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 399 | #endif |
Siva Durga Prasad Paladugu | adc11de | 2014-03-14 16:35:38 +0530 | [diff] [blame] | 400 | #endif |
Siva Durga Prasad Paladugu | cce0cb0 | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 401 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 402 | "Load encrypted bitstream (Xilinx only)\n" |
| 403 | " loads [dev] [address] [size] [auth-OCM-0/DDR-1/noauth-2]\n" |
| 404 | " [enc-devkey(0)/userkey(1)/nenc(2) [Userkey address]\n" |
| 405 | "Loads the secure bistreams(authenticated/encrypted/both\n" |
| 406 | "authenticated and encrypted) of [size] from [address].\n" |
| 407 | "The auth-OCM/DDR flag specifies to perform authentication\n" |
| 408 | "in OCM or in DDR. 0 for OCM, 1 for DDR, 2 for no authentication.\n" |
| 409 | "The enc flag specifies which key to be used for decryption\n" |
| 410 | "0-device key, 1-user key, 2-no encryption.\n" |
| 411 | "The optional Userkey address specifies from which address key\n" |
| 412 | "has to be used for decryption if user key is selected.\n" |
| 413 | "NOTE: the sceure bitstream has to be created using xilinx\n" |
| 414 | "bootgen tool only.\n" |
| 415 | #endif |
Marian Balakowicz | d79162d | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 416 | ); |