+
+ /**
+ * Registers driver-specific commands. When called (during the
+ * "flash bank" command), the driver may register addition
+ * commands to support new flash chip functions.
+ *
+ * @returns ERROR_OK if successful; otherwise, an error code.
+ */
+ int (*register_commands)(struct command_context *cmd_ctx);
+
+ /**
+ * 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 args are: @par
+ * @code
+ * args[0] = bank
+ * args[1] = drivername {name above}
+ * args[2] = baseaddress
+ * args[3] = lengthbytes
+ * args[4] = chip_width_in bytes
+ * args[5] = bus_width_bytes
+ * args[6] = driver-specific parameters
+ * @endcode
+ *
+ * For example, args[4] = 16 bit flash, args[5] = 32bit bus.
+ *
+ * If extra arguments are provided (@a argc > 6), they will
+ * start in @a args[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 disable 'flash write' bits (or
+ * enable 'erase protection' bits) for the given @a bank and @a
+ * sectors.
+ *
+ * @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,
+ 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 seee 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)
+
+/**
+ * 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