You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/06/15 22:04:12 UTC

[29/51] [partial] incubator-mynewt-site git commit: Fixed broken Quick Start link and added OpenOCD option for Arduino Primo debugging

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/cfi.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/cfi.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/cfi.h
new file mode 100755
index 0000000..5bd25e9
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/cfi.h
@@ -0,0 +1,164 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath                                    *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifndef CFI_H
+#define CFI_H
+
+#define CFI_STATUS_POLL_MASK_DQ5_DQ6_DQ7 0xE0 /* DQ5..DQ7 */
+#define CFI_STATUS_POLL_MASK_DQ6_DQ7     0xC0 /* DQ6..DQ7 */
+
+struct cfi_flash_bank {
+	int x16_as_x8;
+	int jedec_probe;
+	int not_cfi;
+	int probed;
+
+	enum target_endianness endianness;
+
+	uint16_t manufacturer;
+	uint16_t device_id;
+
+	uint8_t qry[3];
+
+	/* identification string */
+	uint16_t pri_id;
+	uint16_t pri_addr;
+	uint16_t alt_id;
+	uint16_t alt_addr;
+
+	/* device-system interface */
+	uint8_t vcc_min;
+	uint8_t vcc_max;
+	uint8_t vpp_min;
+	uint8_t vpp_max;
+	uint8_t word_write_timeout_typ;
+	uint8_t buf_write_timeout_typ;
+	uint8_t block_erase_timeout_typ;
+	uint8_t chip_erase_timeout_typ;
+	uint8_t word_write_timeout_max;
+	uint8_t buf_write_timeout_max;
+	uint8_t block_erase_timeout_max;
+	uint8_t chip_erase_timeout_max;
+
+	uint8_t status_poll_mask;
+
+	/* flash geometry */
+	uint32_t dev_size;
+	uint16_t interface_desc;
+	uint16_t max_buf_write_size;
+	uint8_t num_erase_regions;
+	uint32_t *erase_region_info;
+
+	void *pri_ext;
+	void *alt_ext;
+
+	/* calculated timeouts */
+	unsigned word_write_timeout;
+	unsigned buf_write_timeout;
+	unsigned block_erase_timeout;
+	unsigned chip_erase_timeout;
+};
+
+/* Intel primary extended query table
+ * as defined for the Advanced+ Boot Block Flash Memory (C3)
+ * and used by the linux kernel cfi driver (as of 2.6.14)
+ */
+struct cfi_intel_pri_ext {
+	uint8_t pri[3];
+	uint8_t major_version;
+	uint8_t minor_version;
+	uint32_t feature_support;
+	uint8_t suspend_cmd_support;
+	uint16_t blk_status_reg_mask;
+	uint8_t vcc_optimal;
+	uint8_t vpp_optimal;
+	uint8_t num_protection_fields;
+	uint16_t prot_reg_addr;
+	uint8_t fact_prot_reg_size;
+	uint8_t user_prot_reg_size;
+	uint8_t extra[0];
+};
+
+/* Spansion primary extended query table as defined for and used by
+ * the linux kernel cfi driver (as of 2.6.15)
+ */
+struct cfi_spansion_pri_ext {
+	uint8_t  pri[3];
+	uint8_t  major_version;
+	uint8_t  minor_version;
+	uint8_t  SiliconRevision; /* bits 1-0: Address Sensitive Unlock */
+	uint8_t  EraseSuspend;
+	uint8_t  BlkProt;
+	uint8_t  TmpBlkUnprotect;
+	uint8_t  BlkProtUnprot;
+	uint8_t  SimultaneousOps;
+	uint8_t  BurstMode;
+	uint8_t  PageMode;
+	uint8_t  VppMin;
+	uint8_t  VppMax;
+	uint8_t  TopBottom;
+	int _reversed_geometry;
+	uint32_t _unlock1;
+	uint32_t _unlock2;
+};
+
+/* Atmel primary extended query table as defined for and used by
+ * the linux kernel cfi driver (as of 2.6.20+)
+ */
+struct cfi_atmel_pri_ext {
+	uint8_t pri[3];
+	uint8_t major_version;
+	uint8_t minor_version;
+	uint8_t features;
+	uint8_t bottom_boot;
+	uint8_t burst_mode;
+	uint8_t page_mode;
+};
+
+enum {
+	CFI_UNLOCK_555_2AA,
+	CFI_UNLOCK_5555_2AAA,
+};
+
+struct cfi_unlock_addresses {
+	uint32_t unlock1;
+	uint32_t unlock2;
+};
+
+struct cfi_fixup {
+	uint16_t mfr;
+	uint16_t id;
+	void (*fixup)(struct flash_bank *bank, const void *param);
+	const void *param;
+};
+
+#define CFI_MFR_AMD		0x0001
+#define CFI_MFR_FUJITSU	0x0004
+#define CFI_MFR_ATMEL	0x001F
+#define CFI_MFR_ST		0x0020	/* STMicroelectronics */
+#define CFI_MFR_AMIC	0x0037
+#define CFI_MFR_SST		0x00BF
+#define CFI_MFR_MX		0x00C2
+#define CFI_MFR_EON		0x007F
+
+#define CFI_MFR_ANY		0xffff
+#define CFI_ID_ANY		0xffff
+
+#endif /* CFI_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.c
new file mode 100755
index 0000000..4410d5c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.c
@@ -0,0 +1,766 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath <Do...@gmx.de>              *
+ *   Copyright (C) 2007-2010 �yvind Harboe <oy...@zylin.com>       *
+ *   Copyright (C) 2008 by Spencer Oliver <sp...@spen-soft.co.uk>           *
+ *   Copyright (C) 2009 Zachary T Welch <zw...@superlucidity.net>             *
+ *   Copyright (C) 2010 by Antonio Borneo <bo...@gmail.com>       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <flash/common.h>
+#include <flash/nor/core.h>
+#include <flash/nor/imp.h>
+#include <target/image.h>
+
+/**
+ * @file
+ * Upper level of NOR flash framework.
+ * The lower level interfaces are to drivers.  These upper level ones
+ * primarily support access from Tcl scripts or from GDB.
+ */
+
+static struct flash_bank *flash_banks;
+
+int flash_driver_erase(struct flash_bank *bank, int first, int last)
+{
+	int retval;
+
+	retval = bank->driver->erase(bank, first, last);
+	if (retval != ERROR_OK)
+		LOG_ERROR("failed erasing sectors %d to %d", first, last);
+
+	return retval;
+}
+
+int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
+{
+	int retval;
+
+	/* callers may not supply illegal parameters ... */
+	if (first < 0 || first > last || last >= bank->num_sectors) {
+		LOG_ERROR("illegal sector range");
+		return ERROR_FAIL;
+	}
+
+	/* force "set" to 0/1 */
+	set = !!set;
+
+	/* DANGER!
+	 *
+	 * We must not use any cached information about protection state!!!!
+	 *
+	 * There are a million things that could change the protect state:
+	 *
+	 * the target could have reset, power cycled, been hot plugged,
+	 * the application could have run, etc.
+	 *
+	 * Drivers only receive valid sector range.
+	 */
+	retval = bank->driver->protect(bank, set, first, last);
+	if (retval != ERROR_OK)
+		LOG_ERROR("failed setting protection for areas %d to %d", first, last);
+
+	return retval;
+}
+
+int flash_driver_write(struct flash_bank *bank,
+	uint8_t *buffer, uint32_t offset, uint32_t count)
+{
+	int retval;
+
+	retval = bank->driver->write(bank, buffer, offset, count);
+	if (retval != ERROR_OK) {
+		LOG_ERROR(
+			"error writing to flash at address 0x%08" PRIx32 " at offset 0x%8.8" PRIx32,
+			bank->base,
+			offset);
+	}
+
+	return retval;
+}
+
+int flash_driver_read(struct flash_bank *bank,
+	uint8_t *buffer, uint32_t offset, uint32_t count)
+{
+	int retval;
+
+	LOG_DEBUG("call flash_driver_read()");
+
+	retval = bank->driver->read(bank, buffer, offset, count);
+	if (retval != ERROR_OK) {
+		LOG_ERROR(
+			"error reading to flash at address 0x%08" PRIx32 " at offset 0x%8.8" PRIx32,
+			bank->base,
+			offset);
+	}
+
+	return retval;
+}
+
+int default_flash_read(struct flash_bank *bank,
+	uint8_t *buffer, uint32_t offset, uint32_t count)
+{
+	return target_read_buffer(bank->target, offset + bank->base, count, buffer);
+}
+
+void flash_bank_add(struct flash_bank *bank)
+{
+	/* put flash bank in linked list */
+	unsigned bank_num = 0;
+	if (flash_banks) {
+		/* find last flash bank */
+		struct flash_bank *p = flash_banks;
+		while (NULL != p->next) {
+			bank_num += 1;
+			p = p->next;
+		}
+		p->next = bank;
+		bank_num += 1;
+	} else
+		flash_banks = bank;
+
+	bank->bank_number = bank_num;
+}
+
+struct flash_bank *flash_bank_list(void)
+{
+	return flash_banks;
+}
+
+struct flash_bank *get_flash_bank_by_num_noprobe(int num)
+{
+	struct flash_bank *p;
+	int i = 0;
+
+	for (p = flash_banks; p; p = p->next) {
+		if (i++ == num)
+			return p;
+	}
+	LOG_ERROR("flash bank %d does not exist", num);
+	return NULL;
+}
+
+int flash_get_bank_count(void)
+{
+	struct flash_bank *p;
+	int i = 0;
+	for (p = flash_banks; p; p = p->next)
+		i++;
+	return i;
+}
+
+struct flash_bank *get_flash_bank_by_name_noprobe(const char *name)
+{
+	unsigned requested = get_flash_name_index(name);
+	unsigned found = 0;
+
+	struct flash_bank *bank;
+	for (bank = flash_banks; NULL != bank; bank = bank->next) {
+		if (strcmp(bank->name, name) == 0)
+			return bank;
+		if (!flash_driver_name_matches(bank->driver->name, name))
+			continue;
+		if (++found < requested)
+			continue;
+		return bank;
+	}
+	return NULL;
+}
+
+int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
+{
+	struct flash_bank *bank;
+	int retval;
+
+	bank = get_flash_bank_by_name_noprobe(name);
+	if (bank != NULL) {
+		retval = bank->driver->auto_probe(bank);
+
+		if (retval != ERROR_OK) {
+			LOG_ERROR("auto_probe failed");
+			return retval;
+		}
+	}
+
+	*bank_result = bank;
+	return ERROR_OK;
+}
+
+int get_flash_bank_by_num(int num, struct flash_bank **bank)
+{
+	struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
+	int retval;
+
+	if (p == NULL)
+		return ERROR_FAIL;
+
+	retval = p->driver->auto_probe(p);
+
+	if (retval != ERROR_OK) {
+		LOG_ERROR("auto_probe failed");
+		return retval;
+	}
+	*bank = p;
+	return ERROR_OK;
+}
+
+/* lookup flash bank by address, bank not found is success, but
+ * result_bank is set to NULL. */
+int get_flash_bank_by_addr(struct target *target,
+	uint32_t addr,
+	bool check,
+	struct flash_bank **result_bank)
+{
+	struct flash_bank *c;
+
+	/* cycle through bank list */
+	for (c = flash_banks; c; c = c->next) {
+		if (c->target != target)
+			continue;
+
+		int retval;
+		retval = c->driver->auto_probe(c);
+
+		if (retval != ERROR_OK) {
+			LOG_ERROR("auto_probe failed");
+			return retval;
+		}
+		/* check whether address belongs to this flash bank */
+		if ((addr >= c->base) && (addr <= c->base + (c->size - 1))) {
+			*result_bank = c;
+			return ERROR_OK;
+		}
+	}
+	*result_bank = NULL;
+	if (check) {
+		LOG_ERROR("No flash at address 0x%08" PRIx32, addr);
+		return ERROR_FAIL;
+	}
+	return ERROR_OK;
+}
+
+static int default_flash_mem_blank_check(struct flash_bank *bank)
+{
+	struct target *target = bank->target;
+	const int buffer_size = 1024;
+	int i;
+	uint32_t nBytes;
+	int retval = ERROR_OK;
+
+	if (bank->target->state != TARGET_HALTED) {
+		LOG_ERROR("Target not halted");
+		return ERROR_TARGET_NOT_HALTED;
+	}
+
+	uint8_t *buffer = malloc(buffer_size);
+
+	for (i = 0; i < bank->num_sectors; i++) {
+		uint32_t j;
+		bank->sectors[i].is_erased = 1;
+
+		for (j = 0; j < bank->sectors[i].size; j += buffer_size) {
+			uint32_t chunk;
+			chunk = buffer_size;
+			if (chunk > (j - bank->sectors[i].size))
+				chunk = (j - bank->sectors[i].size);
+
+			retval = target_read_memory(target,
+					bank->base + bank->sectors[i].offset + j,
+					4,
+					chunk/4,
+					buffer);
+			if (retval != ERROR_OK)
+				goto done;
+
+			for (nBytes = 0; nBytes < chunk; nBytes++) {
+				if (buffer[nBytes] != 0xFF) {
+					bank->sectors[i].is_erased = 0;
+					break;
+				}
+			}
+		}
+	}
+
+done:
+	free(buffer);
+
+	return retval;
+}
+
+int default_flash_blank_check(struct flash_bank *bank)
+{
+	struct target *target = bank->target;
+	int i;
+	int retval;
+	int fast_check = 0;
+	uint32_t blank;
+
+	if (bank->target->state != TARGET_HALTED) {
+		LOG_ERROR("Target not halted");
+		return ERROR_TARGET_NOT_HALTED;
+	}
+
+	for (i = 0; i < bank->num_sectors; i++) {
+		uint32_t address = bank->base + bank->sectors[i].offset;
+		uint32_t size = bank->sectors[i].size;
+
+		retval = target_blank_check_memory(target, address, size, &blank);
+		if (retval != ERROR_OK) {
+			fast_check = 0;
+			break;
+		}
+		if (blank == 0xFF)
+			bank->sectors[i].is_erased = 1;
+		else
+			bank->sectors[i].is_erased = 0;
+		fast_check = 1;
+	}
+
+	if (!fast_check) {
+		LOG_USER("Running slow fallback erase check - add working memory");
+		return default_flash_mem_blank_check(bank);
+	}
+
+	return ERROR_OK;
+}
+
+/* Manipulate given flash region, selecting the bank according to target
+ * and address.  Maps an address range to a set of sectors, and issues
+ * the callback() on that set ... e.g. to erase or unprotect its members.
+ *
+ * (Note a current bad assumption:  that protection operates on the same
+ * size sectors as erase operations use.)
+ *
+ * The "pad_reason" parameter is a kind of boolean:  when it's NULL, the
+ * range must fit those sectors exactly.  This is clearly safe; it can't
+ * erase data which the caller said to leave alone, for example.  If it's
+ * non-NULL, rather than failing, extra data in the first and/or last
+ * sectors will be added to the range, and that reason string is used when
+ * warning about those additions.
+ */
+static int flash_iterate_address_range_inner(struct target *target,
+	char *pad_reason, uint32_t addr, uint32_t length,
+	int (*callback)(struct flash_bank *bank, int first, int last))
+{
+	struct flash_bank *c;
+	uint32_t last_addr = addr + length;	/* first address AFTER end */
+	int first = -1;
+	int last = -1;
+	int i;
+
+	int retval = get_flash_bank_by_addr(target, addr, true, &c);
+	if (retval != ERROR_OK)
+		return retval;
+
+	if (c->size == 0 || c->num_sectors == 0) {
+		LOG_ERROR("Bank is invalid");
+		return ERROR_FLASH_BANK_INVALID;
+	}
+
+	if (length == 0) {
+		/* special case, erase whole bank when length is zero */
+		if (addr != c->base) {
+			LOG_ERROR("Whole bank access must start at beginning of bank.");
+			return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
+		}
+
+		return callback(c, 0, c->num_sectors - 1);
+	}
+
+	/* check whether it all fits in this bank */
+	if (addr + length - 1 > c->base + c->size - 1) {
+		LOG_ERROR("Flash access does not fit into bank.");
+		return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
+	}
+
+	/** @todo: handle erasures that cross into adjacent banks */
+
+	addr -= c->base;
+	last_addr -= c->base;
+
+	for (i = 0; i < c->num_sectors; i++) {
+		struct flash_sector *f = c->sectors + i;
+		uint32_t end = f->offset + f->size;
+
+		/* start only on a sector boundary */
+		if (first < 0) {
+			/* scanned past the first sector? */
+			if (addr < f->offset)
+				break;
+
+			/* is this the first sector? */
+			if (addr == f->offset)
+				first = i;
+
+			/* Does this need head-padding?  If so, pad and warn;
+			 * or else force an error.
+			 *
+			 * Such padding can make trouble, since *WE* can't
+			 * ever know if that data was in use.  The warning
+			 * should help users sort out messes later.
+			 */
+			else if (addr < end && pad_reason) {
+				/* FIXME say how many bytes (e.g. 80 KB) */
+				LOG_WARNING("Adding extra %s range, "
+					"%#8.8x to %#8.8x",
+					pad_reason,
+					(unsigned) f->offset,
+					(unsigned) addr - 1);
+				first = i;
+			} else
+				continue;
+		}
+
+		/* is this (also?) the last sector? */
+		if (last_addr == end) {
+			last = i;
+			break;
+		}
+
+		/* Does this need tail-padding?  If so, pad and warn;
+		 * or else force an error.
+		 */
+		if (last_addr < end && pad_reason) {
+			/* FIXME say how many bytes (e.g. 80 KB) */
+			LOG_WARNING("Adding extra %s range, "
+				"%#8.8x to %#8.8x",
+				pad_reason,
+				(unsigned) last_addr,
+				(unsigned) end - 1);
+			last = i;
+			break;
+		}
+
+		/* MUST finish on a sector boundary */
+		if (last_addr <= f->offset)
+			break;
+	}
+
+	/* invalid start or end address? */
+	if (first == -1 || last == -1) {
+		LOG_ERROR("address range 0x%8.8x .. 0x%8.8x "
+			"is not sector-aligned",
+			(unsigned) (c->base + addr),
+			(unsigned) (c->base + last_addr - 1));
+		return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
+	}
+
+	/* The NOR driver may trim this range down, based on what
+	 * sectors are already erased/unprotected.  GDB currently
+	 * blocks such optimizations.
+	 */
+	return callback(c, first, last);
+}
+
+/* The inner fn only handles a single bank, we could be spanning
+ * multiple chips.
+ */
+static int flash_iterate_address_range(struct target *target,
+	char *pad_reason, uint32_t addr, uint32_t length,
+	int (*callback)(struct flash_bank *bank, int first, int last))
+{
+	struct flash_bank *c;
+	int retval = ERROR_OK;
+
+	/* Danger! zero-length iterations means entire bank! */
+	do {
+		retval = get_flash_bank_by_addr(target, addr, true, &c);
+		if (retval != ERROR_OK)
+			return retval;
+
+		uint32_t cur_length = length;
+		/* check whether it all fits in this bank */
+		if (addr + length - 1 > c->base + c->size - 1) {
+			LOG_DEBUG("iterating over more than one flash bank.");
+			cur_length = c->base + c->size - addr;
+		}
+		retval = flash_iterate_address_range_inner(target,
+				pad_reason, addr, cur_length,
+				callback);
+		if (retval != ERROR_OK)
+			break;
+
+		length -= cur_length;
+		addr += cur_length;
+	} while (length > 0);
+
+	return retval;
+}
+
+int flash_erase_address_range(struct target *target,
+	bool pad, uint32_t addr, uint32_t length)
+{
+	return flash_iterate_address_range(target, pad ? "erase" : NULL,
+		addr, length, &flash_driver_erase);
+}
+
+static int flash_driver_unprotect(struct flash_bank *bank, int first, int last)
+{
+	return flash_driver_protect(bank, 0, first, last);
+}
+
+int flash_unlock_address_range(struct target *target, uint32_t addr, uint32_t length)
+{
+	/* By default, pad to sector boundaries ... the real issue here
+	 * is that our (only) caller *permanently* removes protection,
+	 * and doesn't restore it.
+	 */
+	return flash_iterate_address_range(target, "unprotect",
+		addr, length, &flash_driver_unprotect);
+}
+
+static int compare_section(const void *a, const void *b)
+{
+	struct imagesection *b1, *b2;
+	b1 = *((struct imagesection **)a);
+	b2 = *((struct imagesection **)b);
+
+	if (b1->base_address == b2->base_address)
+		return 0;
+	else if (b1->base_address > b2->base_address)
+		return 1;
+	else
+		return -1;
+}
+
+int flash_write_unlock(struct target *target, struct image *image,
+	uint32_t *written, int erase, bool unlock)
+{
+	int retval = ERROR_OK;
+
+	int section;
+	uint32_t section_offset;
+	struct flash_bank *c;
+	int *padding;
+
+	section = 0;
+	section_offset = 0;
+
+	if (written)
+		*written = 0;
+
+	if (erase) {
+		/* assume all sectors need erasing - stops any problems
+		 * when flash_write is called multiple times */
+
+		flash_set_dirty();
+	}
+
+	/* allocate padding array */
+	padding = calloc(image->num_sections, sizeof(*padding));
+
+	/* This fn requires all sections to be in ascending order of addresses,
+	 * whereas an image can have sections out of order. */
+	struct imagesection **sections = malloc(sizeof(struct imagesection *) *
+			image->num_sections);
+	int i;
+	for (i = 0; i < image->num_sections; i++)
+		sections[i] = &image->sections[i];
+
+	qsort(sections, image->num_sections, sizeof(struct imagesection *),
+		compare_section);
+
+	/* loop until we reach end of the image */
+	while (section < image->num_sections) {
+		uint32_t buffer_size;
+		uint8_t *buffer;
+		int section_last;
+		uint32_t run_address = sections[section]->base_address + section_offset;
+		uint32_t run_size = sections[section]->size - section_offset;
+		int pad_bytes = 0;
+
+		if (sections[section]->size ==  0) {
+			LOG_WARNING("empty section %d", section);
+			section++;
+			section_offset = 0;
+			continue;
+		}
+
+		/* find the corresponding flash bank */
+		retval = get_flash_bank_by_addr(target, run_address, false, &c);
+		if (retval != ERROR_OK)
+			goto done;
+		if (c == NULL) {
+			LOG_WARNING("no flash bank found for address %" PRIx32, run_address);
+			section++;	/* and skip it */
+			section_offset = 0;
+			continue;
+		}
+
+		/* collect consecutive sections which fall into the same bank */
+		section_last = section;
+		padding[section] = 0;
+		while ((run_address + run_size - 1 < c->base + c->size - 1) &&
+				(section_last + 1 < image->num_sections)) {
+			/* sections are sorted */
+			assert(sections[section_last + 1]->base_address >= c->base);
+			if (sections[section_last + 1]->base_address >= (c->base + c->size)) {
+				/* Done with this bank */
+				break;
+			}
+
+			/* FIXME This needlessly touches sectors BETWEEN the
+			 * sections it's writing.  Without auto erase, it just
+			 * writes ones.  That WILL INVALIDATE data in cases
+			 * like Stellaris Tempest chips, corrupting internal
+			 * ECC codes; and at least FreeScale suggests issues
+			 * with that approach (in HC11 documentation).
+			 *
+			 * With auto erase enabled, data in those sectors will
+			 * be needlessly destroyed; and some of the limited
+			 * number of flash erase cycles will be wasted...
+			 *
+			 * In both cases, the extra writes slow things down.
+			 */
+
+			/* if we have multiple sections within our image,
+			 * flash programming could fail due to alignment issues
+			 * attempt to rebuild a consecutive buffer for the flash loader */
+			pad_bytes = (sections[section_last + 1]->base_address) - (run_address + run_size);
+			padding[section_last] = pad_bytes;
+			run_size += sections[++section_last]->size;
+			run_size += pad_bytes;
+
+			if (pad_bytes > 0)
+				LOG_INFO("Padding image section %d with %d bytes",
+					section_last-1,
+					pad_bytes);
+		}
+
+		if (run_address + run_size - 1 > c->base + c->size - 1) {
+			/* If we have more than one flash chip back to back, then we limit
+			 * the current write operation to the current chip.
+			 */
+			LOG_DEBUG("Truncate flash run size to the current flash chip.");
+
+			run_size = c->base + c->size - run_address;
+			assert(run_size > 0);
+		}
+
+		/* If we're applying any sector automagic, then pad this
+		 * (maybe-combined) segment to the end of its last sector.
+		 */
+		if (unlock || erase) {
+			int sector;
+			uint32_t offset_start = run_address - c->base;
+			uint32_t offset_end = offset_start + run_size;
+			uint32_t end = offset_end, delta;
+
+			for (sector = 0; sector < c->num_sectors; sector++) {
+				end = c->sectors[sector].offset
+					+ c->sectors[sector].size;
+				if (offset_end <= end)
+					break;
+			}
+
+			delta = end - offset_end;
+			padding[section_last] += delta;
+			run_size += delta;
+		}
+
+		/* allocate buffer */
+		buffer = malloc(run_size);
+		if (buffer == NULL) {
+			LOG_ERROR("Out of memory for flash bank buffer");
+			retval = ERROR_FAIL;
+			goto done;
+		}
+		buffer_size = 0;
+
+		/* read sections to the buffer */
+		while (buffer_size < run_size) {
+			size_t size_read;
+
+			size_read = run_size - buffer_size;
+			if (size_read > sections[section]->size - section_offset)
+				size_read = sections[section]->size - section_offset;
+
+			/* KLUDGE!
+			 *
+			 * #�%#"%�% we have to figure out the section # from the sorted
+			 * list of pointers to sections to invoke image_read_section()...
+			 */
+			intptr_t diff = (intptr_t)sections[section] - (intptr_t)image->sections;
+			int t_section_num = diff / sizeof(struct imagesection);
+
+			LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, "
+					"section_offset = %d, buffer_size = %d, size_read = %d",
+				(int)section, (int)t_section_num, (int)section_offset,
+				(int)buffer_size, (int)size_read);
+			retval = image_read_section(image, t_section_num, section_offset,
+					size_read, buffer + buffer_size, &size_read);
+			if (retval != ERROR_OK || size_read == 0) {
+				free(buffer);
+				goto done;
+			}
+
+			/* see if we need to pad the section */
+			while (padding[section]--)
+				(buffer + buffer_size)[size_read++] = c->default_padded_value;
+
+			buffer_size += size_read;
+			section_offset += size_read;
+
+			if (section_offset >= sections[section]->size) {
+				section++;
+				section_offset = 0;
+			}
+		}
+
+		retval = ERROR_OK;
+
+		if (unlock)
+			retval = flash_unlock_address_range(target, run_address, run_size);
+		if (retval == ERROR_OK) {
+			if (erase) {
+				/* calculate and erase sectors */
+				retval = flash_erase_address_range(target,
+						true, run_address, run_size);
+			}
+		}
+
+		if (retval == ERROR_OK) {
+			/* write flash sectors */
+			retval = flash_driver_write(c, buffer, run_address - c->base, run_size);
+		}
+
+		free(buffer);
+
+		if (retval != ERROR_OK) {
+			/* abort operation */
+			goto done;
+		}
+
+		if (written != NULL)
+			*written += run_size;	/* add run size to total written counter */
+	}
+
+done:
+	free(sections);
+	free(padding);
+
+	return retval;
+}
+
+int flash_write(struct target *target, struct image *image,
+	uint32_t *written, int erase)
+{
+	return flash_write_unlock(target, image, written, erase, false);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.h
new file mode 100755
index 0000000..726dd95
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/core.h
@@ -0,0 +1,211 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath <Do...@gmx.de>              *
+ *   Copyright (C) 2007,2008 �yvind Harboe <oy...@zylin.com>       *
+ *   Copyright (C) 2008 by Spencer Oliver <sp...@spen-soft.co.uk>           *
+ *   Copyright (C) 2009 Zachary T Welch <zw...@superlucidity.net>             *
+ *   Copyright (C) 2010 by Antonio Borneo <bo...@gmail.com>       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifndef FLASH_NOR_CORE_H
+#define FLASH_NOR_CORE_H
+
+#include <flash/common.h>
+
+/**
+ * @file
+ * Upper level NOR flash interfaces.
+ */
+
+struct image;
+
+#define FLASH_MAX_ERROR_STR	(128)
+
+/**
+ * Describes the geometry and status of a single flash sector
+ * within a flash bank.  A single bank typically consists of multiple
+ * sectors, each of which can be erased and protected independently.
+ */
+struct flash_sector {
+	/** Bus offset from start of the flash chip (in bytes). */
+	uint32_t offset;
+	/** Number of bytes in this flash sector. */
+	uint32_t size;
+	/**
+	 * Indication of erasure status: 0 = not erased, 1 = erased,
+	 * other = unknown.  Set by @c flash_driver_s::erase_check.
+	 */
+	int is_erased;
+	/**
+	 * Indication of protection status: 0 = unprotected/unlocked,
+	 * 1 = protected/locked, other = unknown.  Set by
+	 * @c flash_driver_s::protect_check.
+	 *
+	 * This information must be considered stale immediately.
+	 * A million things could make it stale: power cycle,
+	 * reset of target, code running on target, etc.
+	 */
+	int is_protected;
+};
+
+/**
+ * Provides details of a flash bank, available either on-chip or through
+ * a major interface.
+ *
+ * This structure will be passed as a parameter to the callbacks in the
+ * flash_driver_s structure, some of which may modify the contents of
+ * this structure of the area of flash that it defines.  Driver writers
+ * may use the @c driver_priv member to store additional data on a
+ * per-bank basis, if required.
+ */
+struct flash_bank {
+	const char *name;
+
+	struct target *target; /**< Target to which this bank belongs. */
+
+	struct flash_driver *driver; /**< Driver for this bank. */
+	void *driver_priv; /**< Private driver storage pointer */
+
+	int bank_number; /**< The 'bank' (or chip number) of this instance. */
+	uint32_t base; /**< The base address of this bank */
+	uint32_t size; /**< The size of this chip bank, in bytes */
+
+	int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
+	int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
+
+	/** Default padded value used, normally this matches the  flash
+	 * erased value. Defaults to 0xFF. */
+	uint8_t default_padded_value;
+
+	/**
+	 * The number of sectors on this chip.  This value will
+	 * be set intially to 0, and the flash driver must set this to
+	 * some non-zero value during "probe()" or "auto_probe()".
+	 */
+	int num_sectors;
+	/** Array of sectors, allocated and initilized by the flash driver */
+	struct flash_sector *sectors;
+
+	struct flash_bank *next; /**< The next flash bank on this chip */
+};
+
+/** Registers the 'flash' subsystem commands */
+int flash_register_commands(struct command_context *cmd_ctx);
+
+/**
+ * Erases @a length bytes in the @a target flash, starting at @a addr.
+ * The range @a addr to @a addr + @a length - 1 must be strictly
+ * sector aligned, unless @a pad is true.  Setting @a pad true extends
+ * the range, at beginning and/or end, if needed for sector alignment.
+ * @returns ERROR_OK if successful; otherwise, an error code.
+ */
+int flash_erase_address_range(struct target *target,
+		bool pad, uint32_t addr, uint32_t length);
+
+int flash_unlock_address_range(struct target *target, uint32_t addr,
+		uint32_t length);
+
+/**
+ * Writes @a image into the @a target flash.  The @a written parameter
+ * will contain the
+ * @param target The target with the flash to be programmed.
+ * @param image The image that will be programmed to flash.
+ * @param written On return, contains the number of bytes written.
+ * @param erase If non-zero, indicates the flash driver should first
+ * erase the corresponding banks or sectors before programming.
+ * @returns ERROR_OK if successful; otherwise, an error code.
+ */
+int flash_write(struct target *target,
+		struct image *image, uint32_t *written, int erase);
+
+/**
+ * Forces targets to re-examine their erase/protection state.
+ * This routine must be called when the system may modify the status.
+ */
+void flash_set_dirty(void);
+/** @returns The number of flash banks currently defined. */
+int flash_get_bank_count(void);
+/**
+ * Provides default read implementation for flash memory.
+ * @param bank The bank to read.
+ * @param buffer The data bytes read.
+ * @param offset The offset into the chip to read.
+ * @param count The number of bytes to read.
+ * @returns ERROR_OK if successful; otherwise, an error code.
+ */
+int default_flash_read(struct flash_bank *bank,
+		uint8_t *buffer, uint32_t offset, uint32_t count);
+/**
+ * Provides default erased-bank check handling. Checks to see if
+ * the flash driver knows they are erased; if things look uncertain,
+ * this routine will call default_flash_mem_blank_check() to confirm.
+ * @returns ERROR_OK if successful; otherwise, an error code.
+ */
+int default_flash_blank_check(struct flash_bank *bank);
+
+/**
+ * Returns the flash bank specified by @a name, which matches the
+ * driver name and a suffix (option) specify the driver-specific
+ * bank number. The suffix consists of the '.' and the driver-specific
+ * bank number: when two str9x banks are defined, then 'str9x.1' refers
+ * to the second.
+ */
+int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result);
+/**
+ * Returns the flash bank specified by @a name, which matches the
+ * driver name and a suffix (option) specify the driver-specific
+ * bank number. The suffix consists of the '.' and the driver-specific
+ * bank number: when two str9x banks are defined, then 'str9x.1' refers
+ * to the second.
+ */
+struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
+/**
+ * Returns the flash bank like get_flash_bank_by_name(), without probing.
+ * @param num The flash bank number.
+ * @param bank returned bank if fn returns ERROR_OK
+ * @returns ERROR_OK if successful
+ */
+int get_flash_bank_by_num(int num, struct flash_bank **bank);
+/**
+ * Retreives @a bank from a command argument, reporting errors parsing
+ * the bank identifier or retreiving the specified bank.  The bank
+ * may be identified by its bank number or by @c name.instance, where
+ * @a instance is driver-specific.
+ * @param name_index The index to the string in args containing the
+ * bank identifier.
+ * @param bank On output, contians a pointer to the bank or NULL.
+ * @returns ERROR_OK on success, or an error indicating the problem.
+ */
+COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
+		struct flash_bank **bank);
+/**
+ * Returns the flash bank like get_flash_bank_by_num(), without probing.
+ * @param num The flash bank number.
+ * @returns A struct flash_bank for flash bank @a num, or NULL.
+ */
+struct flash_bank *get_flash_bank_by_num_noprobe(int num);
+/**
+ * Returns the flash bank located at a specified address.
+ * @param target The target, presumed to contain one or more banks.
+ * @param addr An address that is within the range of the bank.
+ * @param check return ERROR_OK and result_bank NULL if the bank does not exist
+ * @returns The struct flash_bank located at @a addr, or NULL.
+ */
+int get_flash_bank_by_addr(struct target *target, uint32_t addr, bool check,
+		struct flash_bank **result_bank);
+
+#endif /* FLASH_NOR_CORE_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/driver.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/driver.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/driver.h
new file mode 100755
index 0000000..8f2e1cc
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/driver.h
@@ -0,0 +1,226 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath <Do...@gmx.de>              *
+ *   Copyright (C) 2007,2008 �yvind Harboe <oy...@zylin.com>       *
+ *   Copyright (C) 2008 by Spencer Oliver <sp...@spen-soft.co.uk>           *
+ *   Copyright (C) 2009 Zachary T Welch <zw...@superlucidity.net>             *
+ *   Copyright (C) 2010 by Antonio Borneo <bo...@gmail.com>       *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifndef FLASH_NOR_DRIVER_H
+#define FLASH_NOR_DRIVER_H
+
+struct flash_bank;
+
+#define __FLASH_BANK_COMMAND(name) \
+		COMMAND_HELPER(name, struct flash_bank *bank)
+
+/**
+ * @brief Provides the implementation-independent structure that defines
+ * all of the callbacks required by OpenOCD flash drivers.
+ *
+ * Driver authors must implement the routines defined here, providing an
+ * instance with the fields filled out.  After that, the instance must
+ * be registered in flash.c, so it can be used by the driver lookup system.
+ *
+ * Specifically, the user can issue the command: @par
+ * @code
+ * flash bank DRIVERNAME ...parameters...
+ * @endcode
+ *
+ * OpenOCD will search for the driver with a @c flash_driver_s::name
+ * that matches @c DRIVERNAME.
+ *
+ * The flash subsystem calls some of the other drivers routines a using
+ * corresponding static <code>flash_driver_<i>callback</i>()</code>
+ * routine in flash.c.
+ */
+struct flash_driver {
+	/**
+	 * Gives a human-readable name of this flash driver,
+	 * This field is used to select and initialize the driver.
+	 */
+	const char *name;
+
+	/**
+	 * Gives a human-readable description of arguments.
+	 */
+	const char *usage;
+
+	/**
+	 * An array of driver-specific commands to register.  When called
+	 * during the "flash bank" command, the driver can register addition
+	 * commands to support new flash chip functions.
+	 */
+	const struct command_registration *commands;
+
+	/**
+	 * Finish the "flash bank" command for @a bank.  The
+	 * @a bank parameter will have been filled in by the core flash
+	 * layer when this routine is called, and the driver can store
+	 * additional information in its struct flash_bank::driver_priv field.
+	 *
+	 * The CMD_ARGV are: @par
+	 * @code
+	 * CMD_ARGV[0] = bank
+	 * CMD_ARGV[1] = drivername {name above}
+	 * CMD_ARGV[2] = baseaddress
+	 * CMD_ARGV[3] = lengthbytes
+	 * CMD_ARGV[4] = chip_width_in bytes
+	 * CMD_ARGV[5] = bus_width_in_bytes
+	 * CMD_ARGV[6] = driver-specific parameters
+	 * @endcode
+	 *
+	 * For example, CMD_ARGV[4] = 2 (for 16 bit flash),
+	 *	CMD_ARGV[5] = 4 (for 32 bit bus).
+	 *
+	 * If extra arguments are provided (@a CMD_ARGC > 6), they will
+	 * start in @a CMD_ARGV[6].  These can be used to implement
+	 * driver-specific extensions.
+	 *
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	__FLASH_BANK_COMMAND((*flash_bank_command));
+
+	/**
+	 * Bank/sector erase routine (target-specific).  When
+	 * called, the flash driver should erase the specified sectors
+	 * using whatever means are at its disposal.
+	 *
+	 * @param bank The bank of flash to be erased.
+	 * @param first The number of the first sector to erase, typically 0.
+	 * @param last The number of the last sector to erase, typically N-1.
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*erase)(struct flash_bank *bank, int first, int last);
+
+	/**
+	 * Bank/sector protection routine (target-specific).
+	 *
+	 * When called, the driver should enable/disable protection
+	 * for MINIMUM the range covered by first..last sectors
+	 * inclusive. Some chips have alignment requirements will
+	 * cause the actual range to be protected / unprotected to
+	 * be larger than the first..last range.
+	 *
+	 * @param bank The bank to protect or unprotect.
+	 * @param set If non-zero, enable protection; if 0, disable it.
+	 * @param first The first sector to (un)protect, typicaly 0.
+	 * @param last The last sector to (un)project, typically N-1.
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*protect)(struct flash_bank *bank, int set, int first, int last);
+
+	/**
+	 * Program data into the flash.  Note CPU address will be
+	 * "bank->base + offset", while the physical address is
+	 * dependent upon current target MMU mappings.
+	 *
+	 * @param bank The bank to program
+	 * @param buffer The data bytes to write.
+	 * @param offset The offset into the chip to program.
+	 * @param count The number of bytes to write.
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*write)(struct flash_bank *bank,
+			const uint8_t *buffer, uint32_t offset, uint32_t count);
+
+	/**
+	 * Read data from the flash. Note CPU address will be
+	 * "bank->base + offset", while the physical address is
+	 * dependent upon current target MMU mappings.
+	 *
+	 * @param bank The bank to read.
+	 * @param buffer The data bytes read.
+	 * @param offset The offset into the chip to read.
+	 * @param count The number of bytes to read.
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	 int (*read)(struct flash_bank *bank,
+			uint8_t *buffer, uint32_t offset, uint32_t count);
+
+	/**
+	 * Probe to determine what kind of flash is present.
+	 * This is invoked by the "probe" script command.
+	 *
+	 * @param bank The bank to probe
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*probe)(struct flash_bank *bank);
+
+	/**
+	 * Check the erasure status of a flash bank.
+	 * When called, the driver routine must perform the required
+	 * checks and then set the @c flash_sector_s::is_erased field
+	 * for each of the flash banks's sectors.
+	 *
+	 * @param bank The bank to check
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*erase_check)(struct flash_bank *bank);
+
+	/**
+	 * Determine if the specific bank is "protected" or not.
+	 * When called, the driver routine must must perform the
+	 * required protection check(s) and then set the @c
+	 * flash_sector_s::is_protected field for each of the flash
+	 * bank's sectors.
+	 *
+	 * @param bank - the bank to check
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*protect_check)(struct flash_bank *bank);
+
+	/**
+	 * Display human-readable information about the flash
+	 * bank into the given buffer.  Drivers must be careful to avoid
+	 * overflowing the buffer.
+	 *
+	 * @param bank - the bank to get info about
+	 * @param char - where to put the text for the human to read
+	 * @param buf_size - the size of the human buffer.
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*info)(struct flash_bank *bank, char *buf, int buf_size);
+
+	/**
+	 * A more gentle flavor of filash_driver_s::probe, performing
+	 * setup with less noise.  Generally, driver routines should test
+	 * to see if the bank has already been probed; if it has, the
+	 * driver probably should not perform its probe a second time.
+	 *
+	 * This callback is often called from the inside of other
+	 * routines (e.g. GDB flash downloads) to autoprobe the flash as
+	 * it is programing the flash.
+	 *
+	 * @param bank - the bank to probe
+	 * @returns ERROR_OK if successful; otherwise, an error code.
+	 */
+	int (*auto_probe)(struct flash_bank *bank);
+};
+
+#define FLASH_BANK_COMMAND_HANDLER(name) \
+	static __FLASH_BANK_COMMAND(name)
+
+/**
+ * Find a NOR flash driver by its name.
+ * @param name The name of the requested driver.
+ * @returns The flash_driver called @c name, or NULL if not found.
+ */
+struct flash_driver *flash_driver_find_by_name(const char *name);
+
+#endif /* FLASH_NOR_DRIVER_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c
new file mode 100755
index 0000000..ddb0292
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c
@@ -0,0 +1,135 @@
+/***************************************************************************
+ *   Copyright (C) 2009 Zachary T Welch <zw...@superlucidity.net>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "imp.h"
+
+extern struct flash_driver aduc702x_flash;
+extern struct flash_driver aducm360_flash;
+extern struct flash_driver ambiqmicro_flash;
+extern struct flash_driver at91sam3_flash;
+extern struct flash_driver at91sam4_flash;
+extern struct flash_driver at91sam4l_flash;
+extern struct flash_driver at91sam7_flash;
+extern struct flash_driver at91samd_flash;
+extern struct flash_driver atsamv_flash;
+extern struct flash_driver avr_flash;
+extern struct flash_driver cfi_flash;
+extern struct flash_driver dsp5680xx_flash;
+extern struct flash_driver efm32_flash;
+extern struct flash_driver em357_flash;
+extern struct flash_driver faux_flash;
+extern struct flash_driver fm3_flash;
+extern struct flash_driver fm4_flash;
+extern struct flash_driver jtagspi_flash;
+extern struct flash_driver kinetis_flash;
+extern struct flash_driver kinetis_ke_flash;
+extern struct flash_driver lpc2000_flash;
+extern struct flash_driver lpc288x_flash;
+extern struct flash_driver lpc2900_flash;
+extern struct flash_driver lpcspifi_flash;
+extern struct flash_driver mdr_flash;
+extern struct flash_driver mrvlqspi_flash;
+extern struct flash_driver niietcm4_flash;
+extern struct flash_driver nrf51_flash;
+extern struct flash_driver nrf52_flash;
+extern struct flash_driver numicro_flash;
+extern struct flash_driver ocl_flash;
+extern struct flash_driver pic32mx_flash;
+extern struct flash_driver psoc4_flash;
+extern struct flash_driver sim3x_flash;
+extern struct flash_driver stellaris_flash;
+extern struct flash_driver stm32f1x_flash;
+extern struct flash_driver stm32f2x_flash;
+extern struct flash_driver stm32lx_flash;
+extern struct flash_driver stm32l4x_flash;
+extern struct flash_driver stmsmi_flash;
+extern struct flash_driver str7x_flash;
+extern struct flash_driver str9x_flash;
+extern struct flash_driver str9xpec_flash;
+extern struct flash_driver tms470_flash;
+extern struct flash_driver virtual_flash;
+extern struct flash_driver xmc1xxx_flash;
+extern struct flash_driver xmc4xxx_flash;
+
+/**
+ * The list of built-in flash drivers.
+ * @todo Make this dynamically extendable with loadable modules.
+ */
+static struct flash_driver *flash_drivers[] = {
+	&aduc702x_flash,
+	&aducm360_flash,
+	&ambiqmicro_flash,
+	&at91sam3_flash,
+	&at91sam4_flash,
+	&at91sam4l_flash,
+	&at91sam7_flash,
+	&at91samd_flash,
+	&atsamv_flash,
+	&avr_flash,
+	&cfi_flash,
+	&dsp5680xx_flash,
+	&efm32_flash,
+	&em357_flash,
+	&faux_flash,
+	&fm3_flash,
+	&fm4_flash,
+	&jtagspi_flash,
+	&kinetis_flash,
+	&kinetis_ke_flash,
+	&lpc2000_flash,
+	&lpc288x_flash,
+	&lpc2900_flash,
+	&lpcspifi_flash,
+	&mdr_flash,
+	&mrvlqspi_flash,
+	&niietcm4_flash,
+	&nrf51_flash,
+	&nrf52_flash,
+	&numicro_flash,
+	&ocl_flash,
+	&pic32mx_flash,
+	&psoc4_flash,
+	&sim3x_flash,
+	&stellaris_flash,
+	&stm32f1x_flash,
+	&stm32f2x_flash,
+	&stm32lx_flash,
+	&stm32l4x_flash,
+	&stmsmi_flash,
+	&str7x_flash,
+	&str9x_flash,
+	&str9xpec_flash,
+	&tms470_flash,
+	&virtual_flash,
+	&xmc1xxx_flash,
+	&xmc4xxx_flash,
+	NULL,
+};
+
+struct flash_driver *flash_driver_find_by_name(const char *name)
+{
+	for (unsigned i = 0; flash_drivers[i]; i++) {
+		if (strcmp(name, flash_drivers[i]->name) == 0)
+			return flash_drivers[i];
+	}
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.orig
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.orig b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.orig
new file mode 100755
index 0000000..c2ee02a
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.orig
@@ -0,0 +1,134 @@
+/***************************************************************************
+ *   Copyright (C) 2009 Zachary T Welch <zw...@superlucidity.net>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "imp.h"
+
+extern struct flash_driver aduc702x_flash;
+extern struct flash_driver aducm360_flash;
+extern struct flash_driver ambiqmicro_flash;
+extern struct flash_driver at91sam3_flash;
+extern struct flash_driver at91sam4_flash;
+extern struct flash_driver at91sam4l_flash;
+extern struct flash_driver at91sam7_flash;
+extern struct flash_driver at91samd_flash;
+extern struct flash_driver atsamv_flash;
+extern struct flash_driver avr_flash;
+extern struct flash_driver cfi_flash;
+extern struct flash_driver dsp5680xx_flash;
+extern struct flash_driver efm32_flash;
+extern struct flash_driver em357_flash;
+extern struct flash_driver faux_flash;
+extern struct flash_driver fm3_flash;
+extern struct flash_driver fm4_flash;
+extern struct flash_driver jtagspi_flash;
+extern struct flash_driver kinetis_flash;
+extern struct flash_driver kinetis_ke_flash;
+extern struct flash_driver lpc2000_flash;
+extern struct flash_driver lpc288x_flash;
+extern struct flash_driver lpc2900_flash;
+extern struct flash_driver lpcspifi_flash;
+extern struct flash_driver mdr_flash;
+extern struct flash_driver mrvlqspi_flash;
+extern struct flash_driver niietcm4_flash;
+extern struct flash_driver nrf51_flash;
+extern struct flash_driver nrf52_flash;
+extern struct flash_driver numicro_flash;
+extern struct flash_driver ocl_flash;
+extern struct flash_driver pic32mx_flash;
+extern struct flash_driver psoc4_flash;
+extern struct flash_driver sim3x_flash;
+extern struct flash_driver stellaris_flash;
+extern struct flash_driver stm32f1x_flash;
+extern struct flash_driver stm32f2x_flash;
+extern struct flash_driver stm32lx_flash;
+extern struct flash_driver stm32l4x_flash;
+extern struct flash_driver stmsmi_flash;
+extern struct flash_driver str7x_flash;
+extern struct flash_driver str9x_flash;
+extern struct flash_driver str9xpec_flash;
+extern struct flash_driver tms470_flash;
+extern struct flash_driver virtual_flash;
+extern struct flash_driver xmc1xxx_flash;
+extern struct flash_driver xmc4xxx_flash;
+
+/**
+ * The list of built-in flash drivers.
+ * @todo Make this dynamically extendable with loadable modules.
+ */
+static struct flash_driver *flash_drivers[] = {
+	&aduc702x_flash,
+	&aducm360_flash,
+	&ambiqmicro_flash,
+	&at91sam3_flash,
+	&at91sam4_flash,
+	&at91sam4l_flash,
+	&at91sam7_flash,
+	&at91samd_flash,
+	&atsamv_flash,
+	&avr_flash,
+	&cfi_flash,
+	&dsp5680xx_flash,
+	&efm32_flash,
+	&em357_flash,
+	&faux_flash,
+	&fm3_flash,
+	&fm4_flash,
+	&jtagspi_flash,
+	&kinetis_flash,
+	&kinetis_ke_flash,
+	&lpc2000_flash,
+	&lpc288x_flash,
+	&lpc2900_flash,
+	&lpcspifi_flash,
+	&mdr_flash,
+	&mrvlqspi_flash,
+	&niietcm4_flash,
+	&nrf51_flash,
+	&numicro_flash,
+	&ocl_flash,
+	&pic32mx_flash,
+	&psoc4_flash,
+	&sim3x_flash,
+	&stellaris_flash,
+	&stm32f1x_flash,
+	&stm32f2x_flash,
+	&stm32lx_flash,
+	&stm32l4x_flash,
+	&stmsmi_flash,
+	&str7x_flash,
+	&str9x_flash,
+	&str9xpec_flash,
+	&tms470_flash,
+	&virtual_flash,
+	&xmc1xxx_flash,
+	&xmc4xxx_flash,
+	NULL,
+};
+
+struct flash_driver *flash_driver_find_by_name(const char *name)
+{
+	for (unsigned i = 0; flash_drivers[i]; i++) {
+		if (strcmp(name, flash_drivers[i]->name) == 0)
+			return flash_drivers[i];
+	}
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.rej
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.rej b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.rej
new file mode 100644
index 0000000..8f69598
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/drivers.c.rej
@@ -0,0 +1,32 @@
+***************
+*** 58,63 ****
+  extern struct flash_driver mdr_flash;
+  extern struct flash_driver numicro_flash;
+  extern struct flash_driver nrf51_flash;
+  extern struct flash_driver mrvlqspi_flash;
+  extern struct flash_driver psoc4_flash;
+  extern struct flash_driver sim3x_flash;
+--- 58,64 ----
+  extern struct flash_driver mdr_flash;
+  extern struct flash_driver numicro_flash;
+  extern struct flash_driver nrf51_flash;
++ extern struct flash_driver nrf52_flash;
+  extern struct flash_driver mrvlqspi_flash;
+  extern struct flash_driver psoc4_flash;
+  extern struct flash_driver sim3x_flash;
+***************
+*** 106,111 ****
+  	&mdr_flash,
+  	&numicro_flash,
+  	&nrf51_flash,
+  	&mrvlqspi_flash,
+  	&psoc4_flash,
+  	&sim3x_flash,
+--- 107,113 ----
+  	&mdr_flash,
+  	&numicro_flash,
+  	&nrf51_flash,
++ 	&nrf52_flash,
+  	&mrvlqspi_flash,
+  	&psoc4_flash,
+  	&sim3x_flash,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/dsp5680xx_flash.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/dsp5680xx_flash.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/dsp5680xx_flash.c
new file mode 100755
index 0000000..693ff48
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/flash/nor/dsp5680xx_flash.c
@@ -0,0 +1,272 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Rodrigo L. Rosa                                 *
+ *   rodrigorosa.LG@gmail.com                                              *
+ *                                                                         *
+ *   Based on a file written by:                                           *
+ *   Kevin McGuire                                                         *
+ *   Marcel Wijlaars                                                       *
+ *   Michael Ashton                                                        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+/**
+ * @file   dsp5680xx_flash.c
+ * @author Rodrigo L. Rosa <ro...@gmail.com>
+ * @date   Thu Jun  9 18:21:58 2011
+ *
+ * @brief  This file implements the basic functions to run flashing commands
+ * from the TCL interface.
+ * It allows the user to flash the Freescale 5680xx DSP.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "imp.h"
+#include <helper/binarybuffer.h>
+#include <helper/time_support.h>
+#include <target/algorithm.h>
+#include <target/dsp5680xx.h>
+
+static int dsp5680xx_build_sector_list(struct flash_bank *bank)
+{
+	uint32_t offset = HFM_FLASH_BASE_ADDR;
+
+	bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
+	int i;
+
+	for (i = 0; i < bank->num_sectors; ++i) {
+		bank->sectors[i].offset = i * HFM_SECTOR_SIZE;
+		bank->sectors[i].size = HFM_SECTOR_SIZE;
+		offset += bank->sectors[i].size;
+		bank->sectors[i].is_erased = -1;
+		bank->sectors[i].is_protected = -1;
+	}
+	LOG_USER("%s not tested yet.", __func__);
+	return ERROR_OK;
+
+}
+
+/* flash bank dsp5680xx 0 0 0 0 <target#> */
+FLASH_BANK_COMMAND_HANDLER(dsp5680xx_flash_bank_command)
+{
+	bank->base = HFM_FLASH_BASE_ADDR;
+	bank->size = HFM_SIZE_BYTES; /* top 4k not accessible */
+	bank->num_sectors = HFM_SECTOR_COUNT;
+	dsp5680xx_build_sector_list(bank);
+
+	return ERROR_OK;
+}
+
+/**
+ * A memory mapped register (PROT) holds information regarding sector protection.
+ * Protection refers to undesired core access.
+ * The value in this register is loaded from flash upon reset.
+ *
+ * @param bank
+ *
+ * @return
+ */
+static int dsp5680xx_flash_protect_check(struct flash_bank *bank)
+{
+	int retval = ERROR_OK;
+
+	uint16_t protected = 0;
+
+	retval = dsp5680xx_f_protect_check(bank->target, &protected);
+	if (retval != ERROR_OK) {
+		for (int i = 0; i < HFM_SECTOR_COUNT; i++)
+			bank->sectors[i].is_protected = -1;
+		return ERROR_OK;
+	}
+	for (int i = 0; i < HFM_SECTOR_COUNT / 2; i++) {
+		if (protected & 1) {
+			bank->sectors[2 * i].is_protected = 1;
+			bank->sectors[2 * i + 1].is_protected = 1;
+		} else {
+			bank->sectors[2 * i].is_protected = 0;
+			bank->sectors[2 * i + 1].is_protected = 0;
+		}
+		protected = (protected >> 1);
+	}
+	return retval;
+}
+
+/**
+ * Protection funcionality is not implemented.
+ * The current implementation applies/removes security on the chip.
+ * The chip is effectively secured/unsecured after the first reset
+ * following the execution of this function.
+ *
+ * @param bank
+ * @param set Apply or remove security on the chip.
+ * @param first This parameter is ignored.
+ * @param last This parameter is ignored.
+ *
+ * @return
+ */
+static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first,
+				   int last)
+{
+/**
+ * This applies security to flash module after next reset, it does
+ * not actually apply protection (protection refers to undesired access from the core)
+ */
+	int retval;
+
+	if (set)
+		retval = dsp5680xx_f_lock(bank->target);
+	else {
+		retval = dsp5680xx_f_unlock(bank->target);
+		if (retval == ERROR_OK) {
+			/* mark all as erased */
+			for (int i = 0; i <= (HFM_SECTOR_COUNT - 1); i++)
+				/* FM does not recognize it as erased if erased via JTAG. */
+				bank->sectors[i].is_erased = 1;
+		}
+	}
+	return retval;
+}
+
+/**
+ * The dsp5680xx use word addressing. The "/2" that appear in the following code
+ * are a workaround for the fact that OpenOCD uses byte addressing.
+ *
+ * @param bank
+ * @param buffer Data to write to flash.
+ * @param offset
+ * @param count In bytes (2 bytes per address).
+ *
+ * @return
+ */
+static int dsp5680xx_flash_write(struct flash_bank *bank, const uint8_t* buffer,
+				 uint32_t offset, uint32_t count)
+{
+	int retval;
+
+	if ((offset + count / 2) > bank->size) {
+		LOG_ERROR("%s: Flash bank cannot fit data.", __func__);
+		return ERROR_FAIL;
+	}
+	if (offset % 2) {
+		/**
+		 * Writing to odd addresses not supported.
+		 * This chip uses word addressing, Openocd only supports byte addressing.
+		 * The workaround results in disabling writing to odd byte addresses
+		 */
+		LOG_ERROR("%s: Writing to odd addresses not supported for this target", __func__);
+		return ERROR_FAIL;
+	}
+	retval = dsp5680xx_f_wr(bank->target, buffer, bank->base + offset / 2, count, 0);
+	uint32_t addr_word;
+
+	for (addr_word = bank->base + offset / 2; addr_word < count / 2;
+			addr_word += (HFM_SECTOR_SIZE / 2)) {
+		if (retval == ERROR_OK)
+			bank->sectors[addr_word / (HFM_SECTOR_SIZE / 2)].is_erased = 0;
+		else
+			bank->sectors[addr_word / (HFM_SECTOR_SIZE / 2)].is_erased = -1;
+	}
+	return retval;
+}
+
+static int dsp5680xx_probe(struct flash_bank *bank)
+{
+	LOG_DEBUG("%s not implemented", __func__);
+	return ERROR_OK;
+}
+
+/**
+ * The flash module (FM) on the dsp5680xx supports both individual sector
+ * and mass erase of the flash memory.
+ * If this function is called with @first == @last == 0 or if @first is the
+ * first sector (#0) and @last is the last sector then the mass erase command
+ * is executed (much faster than erasing each sector individually).
+ *
+ * @param bank
+ * @param first
+ * @param last
+ *
+ * @return
+ */
+static int dsp5680xx_flash_erase(struct flash_bank *bank, int first, int last)
+{
+	int retval;
+
+	retval = dsp5680xx_f_erase(bank->target, (uint32_t) first, (uint32_t) last);
+	if ((!(first | last)) || ((first == 0) && (last == (HFM_SECTOR_COUNT - 1))))
+		last = HFM_SECTOR_COUNT - 1;
+	if (retval == ERROR_OK)
+		for (int i = first; i <= last; i++)
+			bank->sectors[i].is_erased = 1;
+	else
+		/**
+		 * If an error occurred unknown status
+		 *is set even though some sector could have been correctly erased.
+		 */
+		for (int i = first; i <= last; i++)
+			bank->sectors[i].is_erased = -1;
+	return retval;
+}
+
+/**
+ * The flash module (FM) on the dsp5680xx support a blank check function.
+ * This function executes the FM's blank check functionality on each and every sector.
+ *
+ * @param bank
+ *
+ * @return
+ */
+static int dsp5680xx_flash_erase_check(struct flash_bank *bank)
+{
+	int retval = ERROR_OK;
+
+	uint8_t erased = 0;
+
+	uint32_t i;
+
+	for (i = 0; i < HFM_SECTOR_COUNT; i++) {
+		if (bank->sectors[i].is_erased == -1) {
+			retval = dsp5680xx_f_erase_check(bank->target, &erased, i);
+			if (retval != ERROR_OK) {
+				bank->sectors[i].is_erased = -1;
+			} else {
+				if (erased)
+					bank->sectors[i].is_erased = 1;
+				else
+					bank->sectors[i].is_erased = 0;
+			}
+		}
+	}
+	return retval;
+}
+
+struct flash_driver dsp5680xx_flash = {
+	.name = "dsp5680xx_flash",
+	.flash_bank_command = dsp5680xx_flash_bank_command,
+	.erase = dsp5680xx_flash_erase,
+	.protect = dsp5680xx_flash_protect,
+	.write = dsp5680xx_flash_write,
+	/* .read = default_flash_read, */
+	.probe = dsp5680xx_probe,
+	.auto_probe = dsp5680xx_probe,
+	.erase_check = dsp5680xx_flash_erase_check,
+	.protect_check = dsp5680xx_flash_protect_check,
+};