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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * FPGA support |
| 27 | */ |
| 28 | #include <common.h> |
| 29 | #include <command.h> |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 30 | #if defined(CONFIG_CMD_NET) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 31 | #include <net.h> |
| 32 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 33 | #include <fpga.h> |
wdenk | c3d2b4b | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 34 | #include <malloc.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 35 | |
| 36 | #if 0 |
| 37 | #define FPGA_DEBUG |
| 38 | #endif |
| 39 | |
| 40 | #ifdef FPGA_DEBUG |
| 41 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 42 | #else |
| 43 | #define PRINTF(fmt,args...) |
| 44 | #endif |
| 45 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 46 | /* Local functions */ |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 47 | static int fpga_get_op (char *opstr); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 48 | |
| 49 | /* Local defines */ |
| 50 | #define FPGA_NONE -1 |
| 51 | #define FPGA_INFO 0 |
| 52 | #define FPGA_LOAD 1 |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 53 | #define FPGA_LOADB 2 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 54 | #define FPGA_DUMP 3 |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 55 | #define FPGA_LOADMK 4 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 56 | |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 57 | /* Convert bitstream data and load into the fpga */ |
| 58 | int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size) |
| 59 | { |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 60 | #if defined(CONFIG_FPGA_XILINX) |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 61 | unsigned int length; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 62 | unsigned int swapsize; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 63 | char buffer[80]; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 64 | unsigned char *dataptr; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 65 | unsigned int i; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 66 | int rc; |
| 67 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 68 | dataptr = (unsigned char *)fpgadata; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 69 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 70 | /* skip the first bytes of the bitsteam, their meaning is unknown */ |
| 71 | length = (*dataptr << 8) + *(dataptr+1); |
| 72 | dataptr+=2; |
| 73 | dataptr+=length; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 74 | |
| 75 | /* get design name (identifier, length, string) */ |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 76 | length = (*dataptr << 8) + *(dataptr+1); |
| 77 | dataptr+=2; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 78 | if (*dataptr++ != 0x61) { |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 79 | PRINTF ("%s: Design name identifier not recognized in bitstream\n", |
| 80 | __FUNCTION__ ); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 81 | return FPGA_FAIL; |
| 82 | } |
| 83 | |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 84 | length = (*dataptr << 8) + *(dataptr+1); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 85 | dataptr+=2; |
| 86 | for(i=0;i<length;i++) |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 87 | buffer[i] = *dataptr++; |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 88 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 89 | printf(" design filename = \"%s\"\n", buffer); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 90 | |
| 91 | /* get part number (identifier, length, string) */ |
| 92 | if (*dataptr++ != 0x62) { |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 93 | printf("%s: Part number identifier not recognized in bitstream\n", |
| 94 | __FUNCTION__ ); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 95 | return FPGA_FAIL; |
| 96 | } |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 97 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 98 | length = (*dataptr << 8) + *(dataptr+1); |
| 99 | dataptr+=2; |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 100 | for(i=0;i<length;i++) |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 101 | buffer[i] = *dataptr++; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 102 | printf(" part number = \"%s\"\n", buffer); |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 103 | |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 104 | /* get date (identifier, length, string) */ |
| 105 | if (*dataptr++ != 0x63) { |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 106 | printf("%s: Date identifier not recognized in bitstream\n", |
| 107 | __FUNCTION__); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 108 | return FPGA_FAIL; |
| 109 | } |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 110 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 111 | length = (*dataptr << 8) + *(dataptr+1); |
| 112 | dataptr+=2; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 113 | for(i=0;i<length;i++) |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 114 | buffer[i] = *dataptr++; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 115 | printf(" date = \"%s\"\n", buffer); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 116 | |
| 117 | /* get time (identifier, length, string) */ |
| 118 | if (*dataptr++ != 0x64) { |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 119 | printf("%s: Time identifier not recognized in bitstream\n",__FUNCTION__); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 120 | return FPGA_FAIL; |
| 121 | } |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 122 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 123 | length = (*dataptr << 8) + *(dataptr+1); |
| 124 | dataptr+=2; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 125 | for(i=0;i<length;i++) |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 126 | buffer[i] = *dataptr++; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 127 | printf(" time = \"%s\"\n", buffer); |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 128 | |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 129 | /* get fpga data length (identifier, length) */ |
| 130 | if (*dataptr++ != 0x65) { |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 131 | printf("%s: Data length identifier not recognized in bitstream\n", |
| 132 | __FUNCTION__); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 133 | return FPGA_FAIL; |
| 134 | } |
Wolfgang Denk | 8f79e4c | 2005-08-10 15:14:32 +0200 | [diff] [blame] | 135 | swapsize = ((unsigned int) *dataptr <<24) + |
| 136 | ((unsigned int) *(dataptr+1) <<16) + |
| 137 | ((unsigned int) *(dataptr+2) <<8 ) + |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 138 | ((unsigned int) *(dataptr+3) ) ; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 139 | dataptr+=4; |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 140 | printf(" bytes in bitstream = %d\n", swapsize); |
wdenk | a562e1b | 2005-01-09 18:21:42 +0000 | [diff] [blame] | 141 | |
Matthias Fuchs | c26acc1 | 2007-12-27 17:13:11 +0100 | [diff] [blame] | 142 | rc = fpga_load(dev, dataptr, swapsize); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 143 | return rc; |
| 144 | #else |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 145 | printf("Bitstream support only for Xilinx devices\n"); |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 146 | return FPGA_FAIL; |
| 147 | #endif |
| 148 | } |
| 149 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 150 | /* ------------------------------------------------------------------------- */ |
| 151 | /* command form: |
| 152 | * fpga <op> <device number> <data addr> <datasize> |
| 153 | * where op is 'load', 'dump', or 'info' |
| 154 | * If there is no device number field, the fpga environment variable is used. |
| 155 | * If there is no data addr field, the fpgadata environment variable is used. |
| 156 | * The info command requires no data address field. |
| 157 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 158 | 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] | 159 | { |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 160 | int op, dev = FPGA_INVALID_DEVICE; |
| 161 | size_t data_size = 0; |
| 162 | void *fpga_data = NULL; |
| 163 | char *devstr = getenv ("fpga"); |
| 164 | char *datastr = getenv ("fpgadata"); |
| 165 | int rc = FPGA_FAIL; |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 166 | #if defined (CONFIG_FIT) |
| 167 | const char *fit_uname = NULL; |
| 168 | ulong fit_addr; |
| 169 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 170 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 171 | if (devstr) |
| 172 | dev = (int) simple_strtoul (devstr, NULL, 16); |
| 173 | if (datastr) |
| 174 | fpga_data = (void *) simple_strtoul (datastr, NULL, 16); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 175 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 176 | switch (argc) { |
| 177 | case 5: /* fpga <op> <dev> <data> <datasize> */ |
| 178 | data_size = simple_strtoul (argv[4], NULL, 16); |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 179 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 180 | case 4: /* fpga <op> <dev> <data> */ |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 181 | #if defined(CONFIG_FIT) |
| 182 | if (fit_parse_subimage (argv[3], (ulong)fpga_data, |
| 183 | &fit_addr, &fit_uname)) { |
| 184 | fpga_data = (void *)fit_addr; |
| 185 | debug ("* fpga: subimage '%s' from FIT image at 0x%08lx\n", |
| 186 | fit_uname, fit_addr); |
| 187 | } else |
| 188 | #endif |
| 189 | { |
| 190 | fpga_data = (void *) simple_strtoul (argv[3], NULL, 16); |
| 191 | debug ("* fpga: cmdline image address = 0x%08lx\n", (ulong)fpga_data); |
| 192 | } |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 193 | PRINTF ("%s: fpga_data = 0x%x\n", __FUNCTION__, (uint) fpga_data); |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 194 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 195 | case 3: /* fpga <op> <dev | data addr> */ |
| 196 | dev = (int) simple_strtoul (argv[2], NULL, 16); |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 197 | PRINTF ("%s: device = %d\n", __FUNCTION__, dev); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 198 | /* FIXME - this is a really weak test */ |
| 199 | if ((argc == 3) && (dev > fpga_count ())) { /* must be buffer ptr */ |
Wolfgang Denk | 8f79e4c | 2005-08-10 15:14:32 +0200 | [diff] [blame] | 200 | PRINTF ("%s: Assuming buffer pointer in arg 3\n", |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 201 | __FUNCTION__); |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 202 | |
| 203 | #if defined(CONFIG_FIT) |
| 204 | if (fit_parse_subimage (argv[2], (ulong)fpga_data, |
| 205 | &fit_addr, &fit_uname)) { |
| 206 | fpga_data = (void *)fit_addr; |
| 207 | debug ("* fpga: subimage '%s' from FIT image at 0x%08lx\n", |
| 208 | fit_uname, fit_addr); |
| 209 | } else |
| 210 | #endif |
| 211 | { |
| 212 | fpga_data = (void *) dev; |
| 213 | debug ("* fpga: cmdline image address = 0x%08lx\n", (ulong)fpga_data); |
| 214 | } |
| 215 | |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 216 | PRINTF ("%s: fpga_data = 0x%x\n", |
| 217 | __FUNCTION__, (uint) fpga_data); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 218 | dev = FPGA_INVALID_DEVICE; /* reset device num */ |
| 219 | } |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 220 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 221 | case 2: /* fpga <op> */ |
| 222 | op = (int) fpga_get_op (argv[1]); |
| 223 | break; |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 224 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 225 | default: |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 226 | PRINTF ("%s: Too many or too few args (%d)\n", |
| 227 | __FUNCTION__, argc); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 228 | op = FPGA_NONE; /* force usage display */ |
| 229 | break; |
| 230 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 231 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 232 | switch (op) { |
| 233 | case FPGA_NONE: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 234 | return cmd_usage(cmdtp); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 235 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 236 | case FPGA_INFO: |
| 237 | rc = fpga_info (dev); |
| 238 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 239 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 240 | case FPGA_LOAD: |
| 241 | rc = fpga_load (dev, fpga_data, data_size); |
| 242 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 243 | |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 244 | case FPGA_LOADB: |
| 245 | rc = fpga_loadbitstream(dev, fpga_data, data_size); |
| 246 | break; |
| 247 | |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 248 | case FPGA_LOADMK: |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 249 | switch (genimg_get_format (fpga_data)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 250 | case IMAGE_FORMAT_LEGACY: |
| 251 | { |
| 252 | image_header_t *hdr = (image_header_t *)fpga_data; |
| 253 | ulong data; |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 254 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 255 | data = (ulong)image_get_data (hdr); |
| 256 | data_size = image_get_data_size (hdr); |
| 257 | rc = fpga_load (dev, (void *)data, data_size); |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 258 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 259 | break; |
| 260 | #if defined(CONFIG_FIT) |
| 261 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 262 | { |
| 263 | const void *fit_hdr = (const void *)fpga_data; |
| 264 | int noffset; |
| 265 | void *fit_data; |
| 266 | |
| 267 | if (fit_uname == NULL) { |
| 268 | puts ("No FIT subimage unit name\n"); |
| 269 | return 1; |
| 270 | } |
| 271 | |
| 272 | if (!fit_check_format (fit_hdr)) { |
| 273 | puts ("Bad FIT image format\n"); |
| 274 | return 1; |
| 275 | } |
| 276 | |
| 277 | /* get fpga component image node offset */ |
| 278 | noffset = fit_image_get_node (fit_hdr, fit_uname); |
| 279 | if (noffset < 0) { |
| 280 | printf ("Can't find '%s' FIT subimage\n", fit_uname); |
| 281 | return 1; |
| 282 | } |
| 283 | |
| 284 | /* verify integrity */ |
| 285 | if (!fit_image_check_hashes (fit_hdr, noffset)) { |
| 286 | puts ("Bad Data Hash\n"); |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | /* get fpga subimage data address and length */ |
| 291 | if (fit_image_get_data (fit_hdr, noffset, &fit_data, &data_size)) { |
| 292 | puts ("Could not find fpga subimage data\n"); |
| 293 | return 1; |
| 294 | } |
| 295 | |
| 296 | rc = fpga_load (dev, fit_data, data_size); |
| 297 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 298 | break; |
| 299 | #endif |
| 300 | default: |
| 301 | puts ("** Unknown image type\n"); |
| 302 | rc = FPGA_FAIL; |
| 303 | break; |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 304 | } |
| 305 | break; |
| 306 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 307 | case FPGA_DUMP: |
| 308 | rc = fpga_dump (dev, fpga_data, data_size); |
| 309 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 310 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 311 | default: |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 312 | printf ("Unknown operation\n"); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 313 | return cmd_usage(cmdtp); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 314 | } |
| 315 | return (rc); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 316 | } |
| 317 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 318 | /* |
| 319 | * Map op to supported operations. We don't use a table since we |
| 320 | * would just have to relocate it from flash anyway. |
| 321 | */ |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 322 | static int fpga_get_op (char *opstr) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 323 | { |
| 324 | int op = FPGA_NONE; |
| 325 | |
| 326 | if (!strcmp ("info", opstr)) { |
| 327 | op = FPGA_INFO; |
wdenk | 30ce5ab | 2005-01-09 18:12:51 +0000 | [diff] [blame] | 328 | } else if (!strcmp ("loadb", opstr)) { |
| 329 | op = FPGA_LOADB; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 330 | } else if (!strcmp ("load", opstr)) { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 331 | op = FPGA_LOAD; |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 332 | } else if (!strcmp ("loadmk", opstr)) { |
| 333 | op = FPGA_LOADMK; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 334 | } else if (!strcmp ("dump", opstr)) { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 335 | op = FPGA_DUMP; |
| 336 | } |
| 337 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 338 | if (op == FPGA_NONE) { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 339 | printf ("Unknown fpga operation \"%s\"\n", opstr); |
| 340 | } |
| 341 | return op; |
| 342 | } |
| 343 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 344 | U_BOOT_CMD (fpga, 6, 1, do_fpga, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 345 | "loadable FPGA image support", |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 346 | "fpga [operation type] [device number] [image address] [image size]\n" |
| 347 | "fpga operations:\n" |
Wolfgang Denk | 8b019da | 2005-08-08 00:14:41 +0200 | [diff] [blame] | 348 | "\tinfo\tlist known device information\n" |
| 349 | "\tload\tLoad device from memory buffer\n" |
| 350 | "\tloadb\tLoad device from bitstream buffer (Xilinx devices only)\n" |
Stefan Roese | f0ff469 | 2006-08-15 14:15:51 +0200 | [diff] [blame] | 351 | "\tloadmk\tLoad device generated with mkimage\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 352 | "\tdump\tLoad device to memory buffer" |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 353 | #if defined(CONFIG_FIT) |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 354 | "\n" |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 355 | "\tFor loadmk operating on FIT format uImage address must include\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 356 | "\tsubimage unit name in the form of addr:<subimg_uname>" |
Marian Balakowicz | c28c4d1 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 357 | #endif |
| 358 | ); |