1 /***************************************************************************
2 * Copyright (C) 2015 Robert Jordens <jordens@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
23 #include <jtag/jtag.h>
24 #include <flash/nor/spi.h>
25 #include <helper/time_support.h>
27 #define JTAGSPI_MAX_TIMEOUT 3000
30 struct jtagspi_flash_bank {
32 struct flash_device dev;
35 bool always_4byte; /* use always 4-byte address except for basic read 0x03 */
37 unsigned int addr_len; /* address length in bytes */
40 FLASH_BANK_COMMAND_HANDLER(jtagspi_flash_bank_command)
42 struct jtagspi_flash_bank *info;
45 return ERROR_COMMAND_SYNTAX_ERROR;
47 info = malloc(sizeof(struct jtagspi_flash_bank));
49 LOG_ERROR("no memory for flash bank info");
53 bank->driver_priv = info;
57 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->ir);
62 static void jtagspi_set_ir(struct flash_bank *bank)
64 struct jtagspi_flash_bank *info = bank->driver_priv;
65 struct scan_field field;
66 uint8_t buf[4] = { 0 };
68 LOG_DEBUG("loading jtagspi ir");
69 buf_set_u32(buf, 0, info->tap->ir_length, info->ir);
70 field.num_bits = info->tap->ir_length;
71 field.out_value = buf;
72 field.in_value = NULL;
73 jtag_add_ir_scan(info->tap, &field, TAP_IDLE);
76 static void flip_u8(const uint8_t *in, uint8_t *out, unsigned int len)
78 for (unsigned int i = 0; i < len; i++)
79 out[i] = flip_u32(in[i], 8);
82 static int jtagspi_cmd(struct flash_bank *bank, uint8_t cmd,
83 uint8_t *write_buffer, unsigned int write_len, uint8_t *data_buffer, int data_len)
85 assert(write_buffer || write_len == 0);
86 assert(data_buffer || data_len == 0);
88 struct scan_field fields[6];
90 LOG_DEBUG("cmd=0x%02x write_len=%d data_len=%d", cmd, write_len, data_len);
92 /* negative data_len == read operation */
93 const bool is_read = (data_len < 0);
98 const uint8_t marker = 1;
99 fields[n].num_bits = 1;
100 fields[n].out_value = ▮
101 fields[n].in_value = NULL;
104 /* transfer length = cmd + address + read/write,
105 * -1 due to the counter implementation */
106 uint8_t xfer_bits[4];
107 h_u32_to_be(xfer_bits, ((sizeof(cmd) + write_len + data_len) * CHAR_BIT) - 1);
108 flip_u8(xfer_bits, xfer_bits, sizeof(xfer_bits));
109 fields[n].num_bits = sizeof(xfer_bits) * CHAR_BIT;
110 fields[n].out_value = xfer_bits;
111 fields[n].in_value = NULL;
114 flip_u8(&cmd, &cmd, sizeof(cmd));
115 fields[n].num_bits = sizeof(cmd) * CHAR_BIT;
116 fields[n].out_value = &cmd;
117 fields[n].in_value = NULL;
121 flip_u8(write_buffer, write_buffer, write_len);
122 fields[n].num_bits = write_len * CHAR_BIT;
123 fields[n].out_value = write_buffer;
124 fields[n].in_value = NULL;
130 fields[n].num_bits = jtag_tap_count_enabled();
131 fields[n].out_value = NULL;
132 fields[n].in_value = NULL;
135 fields[n].out_value = NULL;
136 fields[n].in_value = data_buffer;
138 flip_u8(data_buffer, data_buffer, data_len);
139 fields[n].out_value = data_buffer;
140 fields[n].in_value = NULL;
142 fields[n].num_bits = data_len * CHAR_BIT;
146 jtagspi_set_ir(bank);
147 /* passing from an IR scan to SHIFT-DR clears BYPASS registers */
148 struct jtagspi_flash_bank *info = bank->driver_priv;
149 jtag_add_dr_scan(info->tap, n, fields, TAP_IDLE);
150 int retval = jtag_execute_queue();
153 flip_u8(data_buffer, data_buffer, data_len);
157 COMMAND_HANDLER(jtagspi_handle_set)
159 struct flash_bank *bank = NULL;
160 struct jtagspi_flash_bank *info = NULL;
161 struct flash_sector *sectors = NULL;
163 unsigned int index = 1;
166 LOG_DEBUG("%s", __func__);
168 /* there are 6 mandatory arguments:
169 * devname, size_in_bytes, pagesize, read_cmd, unused, pprog_cmd */
170 if (index + 6 > CMD_ARGC) {
171 command_print(CMD, "jtagspi: not enough arguments");
172 return ERROR_COMMAND_SYNTAX_ERROR;
175 retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
176 if (ERROR_OK != retval)
178 info = bank->driver_priv;
180 /* invalidate all old info */
183 bank->num_sectors = 0;
186 bank->sectors = NULL;
187 info->always_4byte = false;
188 info->probed = false;
190 memset(&info->dev, 0, sizeof(info->dev));
192 strncpy(info->devname, CMD_ARGV[index++], sizeof(info->devname) - 1);
193 info->devname[sizeof(info->devname) - 1] = '\0';
195 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[index++], temp);
196 info->dev.size_in_bytes = temp;
197 if ((temp & (temp - 1)) || (temp < (1UL << 8))) {
198 command_print(CMD, "jtagspi: device size must be 2^n with n >= 8");
199 return ERROR_COMMAND_SYNTAX_ERROR;
202 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[index++], temp);
203 info->dev.pagesize = temp;
204 if (info->dev.pagesize == 0)
205 info->dev.pagesize = SPIFLASH_DEF_PAGESIZE;
206 if ((temp & (temp - 1)) || (temp > info->dev.size_in_bytes)) {
207 command_print(CMD, "jtagspi: page size must be 2^n and <= device size");
208 return ERROR_COMMAND_SYNTAX_ERROR;
211 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], info->dev.read_cmd);
212 if ((info->dev.read_cmd != 0x03) &&
213 (info->dev.read_cmd != 0x13)) {
214 command_print(CMD, "jtagspi: only 0x03/0x13 READ allowed");
215 return ERROR_COMMAND_SYNTAX_ERROR;
218 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], info->dev.qread_cmd);
220 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], info->dev.pprog_cmd);
221 if ((info->dev.pprog_cmd != 0x02) &&
222 (info->dev.pprog_cmd != 0x12)) {
223 command_print(CMD, "jtagspi: only 0x02/0x12 PPRG allowed");
224 return ERROR_COMMAND_SYNTAX_ERROR;
227 /* remaining params are optional */
228 if (index < CMD_ARGC)
229 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], info->dev.chip_erase_cmd);
231 info->dev.chip_erase_cmd = 0x00;
233 if (index < CMD_ARGC) {
234 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[index++], temp);
235 info->dev.sectorsize = temp;
236 if ((info->dev.sectorsize > info->dev.size_in_bytes) ||
237 (info->dev.sectorsize < info->dev.pagesize) || (temp & (temp - 1))) {
238 command_print(CMD, "jtagspi: sector size must be 2^n and <= device size");
239 return ERROR_COMMAND_SYNTAX_ERROR;
242 if (index < CMD_ARGC)
243 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], info->dev.erase_cmd);
245 command_print(CMD, "jtagspi: erase command missing");
246 return ERROR_COMMAND_SYNTAX_ERROR;
249 /* no sector size / sector erase cmd given, treat whole bank as a single sector */
250 info->dev.erase_cmd = 0x00;
251 info->dev.sectorsize = info->dev.size_in_bytes;
254 if (index < CMD_ARGC) {
255 command_print(CMD, "jtagspi: extra arguments");
256 return ERROR_COMMAND_SYNTAX_ERROR;
259 /* set correct size value */
260 bank->size = info->dev.size_in_bytes;
262 /* calculate address length in bytes */
263 if (bank->size <= (1UL << 8))
265 else if (bank->size <= (1UL << 16))
267 else if (bank->size <= (1UL << 24))
271 LOG_WARNING("4-byte addresses needed, might need extra command to enable");
274 /* create and fill sectors array */
276 info->dev.size_in_bytes / info->dev.sectorsize;
277 sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
279 LOG_ERROR("Not enough memory");
283 for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
284 sectors[sector].offset = sector * (info->dev.sectorsize);
285 sectors[sector].size = info->dev.sectorsize;
286 sectors[sector].is_erased = -1;
287 sectors[sector].is_protected = 0;
290 bank->sectors = sectors;
291 info->dev.name = info->devname;
292 if (info->dev.size_in_bytes / 4096)
293 LOG_INFO("flash \'%s\' id = unknown\nflash size = %" PRIu32 " kbytes",
294 info->dev.name, info->dev.size_in_bytes / 1024);
296 LOG_INFO("flash \'%s\' id = unknown\nflash size = %" PRIu32 " bytes",
297 info->dev.name, info->dev.size_in_bytes);
303 COMMAND_HANDLER(jtagspi_handle_cmd)
305 struct flash_bank *bank;
306 unsigned int index = 1;
308 uint8_t num_write, num_read, write_buffer[max], read_buffer[1 << CHAR_BIT];
310 char temp[4], output[(2 + max + (1 << CHAR_BIT)) * 3 + 8];
313 LOG_DEBUG("%s", __func__);
316 command_print(CMD, "jtagspi: not enough arguments");
317 return ERROR_COMMAND_SYNTAX_ERROR;
320 num_write = CMD_ARGC - 2;
321 if (num_write > max) {
322 LOG_ERROR("at most %d bytes may be send", max);
323 return ERROR_COMMAND_SYNTAX_ERROR;
326 retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
327 if (ERROR_OK != retval)
330 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index++], num_read);
332 snprintf(output, sizeof(output), "spi: ");
333 for (ptr = &write_buffer[0] ; index < CMD_ARGC; index++) {
334 COMMAND_PARSE_NUMBER(u8, CMD_ARGV[index], data);
336 snprintf(temp, sizeof(temp), "%02" PRIx8 " ", data);
337 strncat(output, temp, sizeof(output) - strlen(output) - 1);
339 strncat(output, "-> ", sizeof(output) - strlen(output) - 1);
341 /* process command */
342 ptr = &read_buffer[0];
343 jtagspi_cmd(bank, write_buffer[0], &write_buffer[1], num_write - 1, ptr, -num_read);
344 if (retval != ERROR_OK)
347 for ( ; num_read > 0; num_read--) {
348 snprintf(temp, sizeof(temp), "%02" PRIx8 " ", *ptr++);
349 strncat(output, temp, sizeof(output) - strlen(output) - 1);
351 command_print(CMD, "%s", output);
356 COMMAND_HANDLER(jtagspi_handle_always_4byte)
358 struct flash_bank *bank;
359 struct jtagspi_flash_bank *jtagspi_info;
362 LOG_DEBUG("%s", __func__);
364 if ((CMD_ARGC != 1) && (CMD_ARGC != 2))
365 return ERROR_COMMAND_SYNTAX_ERROR;
367 retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
368 if (ERROR_OK != retval)
371 jtagspi_info = bank->driver_priv;
374 command_print(CMD, jtagspi_info->always_4byte ? "on" : "off");
376 COMMAND_PARSE_BOOL(CMD_ARGV[1], jtagspi_info->always_4byte, "on", "off");
381 static int jtagspi_probe(struct flash_bank *bank)
383 struct jtagspi_flash_bank *info = bank->driver_priv;
384 struct flash_sector *sectors;
385 const struct flash_device *p;
387 uint32_t id, sectorsize;
391 bank->sectors = NULL;
393 info->probed = false;
395 if (!bank->target->tap) {
396 LOG_ERROR("Target has no JTAG tap");
399 info->tap = bank->target->tap;
401 jtagspi_cmd(bank, SPIFLASH_READ_ID, NULL, 0, in_buf, -3);
402 /* the table in spi.c has the manufacturer byte (first) as the lsb */
403 id = le_to_h_u24(in_buf);
405 memset(&info->dev, 0, sizeof(info->dev));
406 for (p = flash_devices; p->name ; p++)
407 if (p->device_id == id) {
408 memcpy(&info->dev, p, sizeof(info->dev));
413 LOG_ERROR("Unknown flash device (ID 0x%06" PRIx32 ")", id & 0xFFFFFF);
417 LOG_INFO("Found flash device \'%s\' (ID 0x%06" PRIx32 ")",
418 info->dev.name, info->dev.device_id & 0xFFFFFF);
420 /* Set correct size value */
421 bank->size = info->dev.size_in_bytes;
423 /* calculate address length in bytes */
424 if (bank->size <= (1UL << 8))
426 else if (bank->size <= (1UL << 16))
428 else if (bank->size <= (1UL << 24))
432 LOG_WARNING("4-byte addresses needed, might need extra command to enable");
435 /* if no sectors, treat whole bank as single sector */
436 sectorsize = info->dev.sectorsize ?
437 info->dev.sectorsize : info->dev.size_in_bytes;
439 /* create and fill sectors array */
440 bank->num_sectors = info->dev.size_in_bytes / sectorsize;
441 sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
443 LOG_ERROR("not enough memory");
447 for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
448 sectors[sector].offset = sector * sectorsize;
449 sectors[sector].size = sectorsize;
450 sectors[sector].is_erased = -1;
451 sectors[sector].is_protected = 0;
454 bank->sectors = sectors;
459 static int jtagspi_auto_probe(struct flash_bank *bank)
461 struct jtagspi_flash_bank *info = bank->driver_priv;
465 return jtagspi_probe(bank);
468 static int jtagspi_read_status(struct flash_bank *bank, uint32_t *status)
471 int err = jtagspi_cmd(bank, SPIFLASH_READ_STATUS, NULL, 0, &buf, -1);
472 if (err == ERROR_OK) {
474 LOG_DEBUG("status=0x%02" PRIx8, *status);
479 static int jtagspi_wait(struct flash_bank *bank, int timeout_ms)
481 int64_t t0 = timeval_ms();
485 dt = timeval_ms() - t0;
487 uint32_t status = (uint32_t)-1;
488 int retval = jtagspi_read_status(bank, &status);
489 if (retval != ERROR_OK)
492 if ((status & SPIFLASH_BSY_BIT) == 0) {
493 LOG_DEBUG("waited %" PRId64 " ms", dt);
497 } while (dt <= timeout_ms);
499 LOG_ERROR("timeout, device still busy");
503 static int jtagspi_write_enable(struct flash_bank *bank)
505 jtagspi_cmd(bank, SPIFLASH_WRITE_ENABLE, NULL, 0, NULL, 0);
507 uint32_t status = (uint32_t)-1;
508 int retval = jtagspi_read_status(bank, &status);
509 if (retval != ERROR_OK)
512 if ((status & SPIFLASH_WE_BIT) == 0) {
513 LOG_ERROR("Cannot enable write to flash. Status=0x%02" PRIx8, status);
519 static int jtagspi_bulk_erase(struct flash_bank *bank)
521 struct jtagspi_flash_bank *info = bank->driver_priv;
523 int64_t t0 = timeval_ms();
525 if (info->dev.chip_erase_cmd == 0x00)
526 return ERROR_FLASH_OPER_UNSUPPORTED;
528 retval = jtagspi_write_enable(bank);
529 if (retval != ERROR_OK)
532 jtagspi_cmd(bank, info->dev.chip_erase_cmd, NULL, 0, NULL, 0);
533 if (retval != ERROR_OK)
536 retval = jtagspi_wait(bank, bank->num_sectors * JTAGSPI_MAX_TIMEOUT);
537 LOG_INFO("took %" PRId64 " ms", timeval_ms() - t0);
541 static uint8_t *fill_addr(uint32_t addr, unsigned int addr_len, uint8_t *buffer)
543 for (buffer += addr_len; addr_len > 0; --addr_len) {
551 static int jtagspi_sector_erase(struct flash_bank *bank, unsigned int sector)
553 struct jtagspi_flash_bank *info = bank->driver_priv;
555 uint8_t addr[sizeof(uint32_t)];
556 int64_t t0 = timeval_ms();
558 retval = jtagspi_write_enable(bank);
559 if (retval != ERROR_OK)
562 /* ATXP032/064/128 use always 4-byte addresses except for 0x03 read */
563 unsigned int addr_len = info->always_4byte ? 4 : info->addr_len;
565 retval = jtagspi_cmd(bank, info->dev.erase_cmd, fill_addr(bank->sectors[sector].offset, addr_len, addr),
567 if (retval != ERROR_OK)
570 retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
571 LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
575 static int jtagspi_erase(struct flash_bank *bank, unsigned int first,
578 struct jtagspi_flash_bank *info = bank->driver_priv;
579 int retval = ERROR_OK;
581 LOG_DEBUG("erase from sector %u to sector %u", first, last);
583 if ((last < first) || (last >= bank->num_sectors)) {
584 LOG_ERROR("Flash sector invalid");
585 return ERROR_FLASH_SECTOR_INVALID;
588 if (!(info->probed)) {
589 LOG_ERROR("Flash bank not probed");
590 return ERROR_FLASH_BANK_NOT_PROBED;
593 for (unsigned int sector = first; sector <= last; sector++) {
594 if (bank->sectors[sector].is_protected) {
595 LOG_ERROR("Flash sector %u protected", sector);
600 if (first == 0 && last == (bank->num_sectors - 1) &&
601 info->dev.chip_erase_cmd != 0x00 &&
602 info->dev.chip_erase_cmd != info->dev.erase_cmd) {
603 LOG_DEBUG("Trying bulk erase.");
604 retval = jtagspi_bulk_erase(bank);
605 if (retval == ERROR_OK)
608 LOG_WARNING("Bulk flash erase failed. Falling back to sector erase.");
611 if (info->dev.erase_cmd == 0x00)
612 return ERROR_FLASH_OPER_UNSUPPORTED;
614 for (unsigned int sector = first; sector <= last; sector++) {
615 retval = jtagspi_sector_erase(bank, sector);
616 if (retval != ERROR_OK) {
617 LOG_ERROR("Sector erase failed.");
625 static int jtagspi_protect(struct flash_bank *bank, int set, unsigned int first,
628 for (unsigned int sector = first; sector <= last; sector++)
629 bank->sectors[sector].is_protected = set;
633 static int jtagspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
635 struct jtagspi_flash_bank *info = bank->driver_priv;
636 uint32_t pagesize, currsize;
637 uint8_t addr[sizeof(uint32_t)];
640 if (!(info->probed)) {
641 LOG_ERROR("Flash bank not probed.");
642 return ERROR_FLASH_BANK_NOT_PROBED;
645 /* if no sectorsize, use reasonable default */
646 pagesize = info->dev.sectorsize ? info->dev.sectorsize : info->dev.pagesize;
648 pagesize = (info->dev.size_in_bytes <= SPIFLASH_DEF_PAGESIZE) ?
649 info->dev.size_in_bytes : SPIFLASH_DEF_PAGESIZE;
651 /* ATXP032/064/128 use always 4-byte addresses except for 0x03 read */
652 unsigned int addr_len = ((info->dev.read_cmd != 0x03) && info->always_4byte) ? 4 : info->addr_len;
655 /* length up to end of current page */
656 currsize = ((offset + pagesize) & ~(pagesize - 1)) - offset;
657 /* but no more than remaining size */
658 currsize = (count < currsize) ? count : currsize;
660 retval = jtagspi_cmd(bank, info->dev.read_cmd, fill_addr(offset, addr_len, addr),
661 addr_len, buffer, -currsize);
662 if (retval != ERROR_OK) {
663 LOG_ERROR("page read error");
666 LOG_DEBUG("read page at 0x%08" PRIx32, offset);
674 static int jtagspi_page_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
676 struct jtagspi_flash_bank *info = bank->driver_priv;
677 uint8_t addr[sizeof(uint32_t)];
680 retval = jtagspi_write_enable(bank);
681 if (retval != ERROR_OK)
684 /* ATXP032/064/128 use always 4-byte addresses except for 0x03 read */
685 unsigned int addr_len = ((info->dev.read_cmd != 0x03) && info->always_4byte) ? 4 : info->addr_len;
687 retval = jtagspi_cmd(bank, info->dev.pprog_cmd, fill_addr(offset, addr_len, addr),
688 addr_len, (uint8_t *) buffer, count);
689 if (retval != ERROR_OK)
691 return jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
694 static int jtagspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
696 struct jtagspi_flash_bank *info = bank->driver_priv;
697 uint32_t pagesize, currsize;
700 if (!(info->probed)) {
701 LOG_ERROR("Flash bank not probed.");
702 return ERROR_FLASH_BANK_NOT_PROBED;
705 /* if no write pagesize, use reasonable default */
706 pagesize = info->dev.pagesize ? info->dev.pagesize : SPIFLASH_DEF_PAGESIZE;
709 /* length up to end of current page */
710 currsize = ((offset + pagesize) & ~(pagesize - 1)) - offset;
711 /* but no more than remaining size */
712 currsize = (count < currsize) ? count : currsize;
714 retval = jtagspi_page_write(bank, buffer, offset, currsize);
715 if (retval != ERROR_OK) {
716 LOG_ERROR("page write error");
719 LOG_DEBUG("wrote page at 0x%08" PRIx32, offset);
727 static int jtagspi_info(struct flash_bank *bank, struct command_invocation *cmd)
729 struct jtagspi_flash_bank *info = bank->driver_priv;
731 if (!(info->probed)) {
732 command_print_sameline(cmd, "\nJTAGSPI flash bank not probed yet\n");
736 command_print_sameline(cmd, "flash \'%s\', device id = 0x%06" PRIx32
737 ", flash size = %" PRIu32 " %sbytes\n(page size = %" PRIu32
738 ", read = 0x%02" PRIx8 ", qread = 0x%02" PRIx8
739 ", pprog = 0x%02" PRIx8 ", mass_erase = 0x%02" PRIx8
740 ", sector size = %" PRIu32 " %sbytes, sector_erase = 0x%02" PRIx8 ")",
741 info->dev.name, info->dev.device_id & 0xFFFFFF,
742 bank->size / 4096 ? bank->size / 1024 : bank->size,
743 bank->size / 4096 ? "k" : "", info->dev.pagesize,
744 info->dev.read_cmd, info->dev.qread_cmd,
745 info->dev.pprog_cmd, info->dev.chip_erase_cmd,
746 info->dev.sectorsize / 4096 ?
747 info->dev.sectorsize / 1024 : info->dev.sectorsize,
748 info->dev.sectorsize / 4096 ? "k" : "",
749 info->dev.erase_cmd);
754 static const struct command_registration jtagspi_exec_command_handlers[] = {
757 .handler = jtagspi_handle_set,
758 .mode = COMMAND_EXEC,
759 .usage = "bank_id name chip_size page_size read_cmd unused pprg_cmd "
760 "[ mass_erase_cmd ] [ sector_size sector_erase_cmd ]",
761 .help = "Set device parameters if not autodetected.",
765 .handler = jtagspi_handle_cmd,
766 .mode = COMMAND_EXEC,
767 .usage = "bank_id num_resp cmd_byte ...",
768 .help = "Send low-level command cmd_byte and following bytes, read num_bytes.",
771 .name = "always_4byte",
772 .handler = jtagspi_handle_always_4byte,
773 .mode = COMMAND_EXEC,
774 .usage = "bank_id [ on | off ]",
775 .help = "Use always 4-byte address except for basic 0x03.",
778 COMMAND_REGISTRATION_DONE
781 static const struct command_registration jtagspi_command_handlers[] = {
785 .help = "jtagspi command group",
787 .chain = jtagspi_exec_command_handlers,
789 COMMAND_REGISTRATION_DONE
792 const struct flash_driver jtagspi_flash = {
794 .commands = jtagspi_command_handlers,
795 .flash_bank_command = jtagspi_flash_bank_command,
796 .erase = jtagspi_erase,
797 .protect = jtagspi_protect,
798 .write = jtagspi_write,
799 .read = jtagspi_read,
800 .probe = jtagspi_probe,
801 .auto_probe = jtagspi_auto_probe,
802 .erase_check = default_flash_blank_check,
803 .info = jtagspi_info,
804 .free_driver_priv = default_flash_free_driver_priv,