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