* 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. *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/***************************************************************************
return ERROR_OK;
}
+/* TODO: Revisit! Is it impossible to read protection status? */
static int lpc288x_protect_check(struct flash_bank *bank)
{
return ERROR_OK;
return ERROR_OK;
}
-static int lpc288x_erase_check(struct flash_bank *bank)
-{
- uint32_t status = lpc288x_system_ready(bank); /* probed? halted? */
- if (status != ERROR_OK) {
- LOG_INFO("Processor not halted/not probed");
- return status;
- }
-
- return ERROR_OK;
-}
-
-static int lpc288x_erase(struct flash_bank *bank, int first, int last)
+static int lpc288x_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
uint32_t status;
- int sector;
struct target *target = bank->target;
status = lpc288x_system_ready(bank); /* probed? halted? */
if (status != ERROR_OK)
return status;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+ if ((last < first) || (last >= bank->num_sectors)) {
LOG_INFO("Bad sector range");
return ERROR_FLASH_SECTOR_INVALID;
}
/* Configure the flash controller timing */
lpc288x_set_flash_clk(bank);
- for (sector = first; sector <= last; sector++) {
+ for (unsigned int sector = first; sector <= last; sector++) {
if (lpc288x_wait_status_busy(bank, 1000) != ERROR_OK)
return ERROR_FLASH_OPERATION_FAILED;
return ERROR_OK;
}
-static int lpc288x_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int lpc288x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
{
uint8_t page_buffer[FLASH_PAGE_SIZE];
uint32_t status, source_offset, dest_offset;
struct target *target = bank->target;
uint32_t bytes_remaining = count;
uint32_t first_sector, last_sector, sector, page;
- int i;
/* probed? halted? */
status = lpc288x_system_ready(bank);
first_sector = last_sector = 0xffffffff;
/* validate the write range... */
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if ((offset >= bank->sectors[i].offset) &&
(offset < (bank->sectors[i].offset + bank->sectors[i].size)) &&
(first_sector == 0xffffffff)) {
target_write_u32(target, F_CTRL, FC_CS | FC_SET_DATA | FC_WEN | FC_FUNC);
target_write_u32(target, F_CTRL, FC_CS | FC_WEN | FC_FUNC);
- /*would be better to use the clean target_write_buffer() interface but
- * it seems not to be a LOT slower....
- * bulk_write_memory() is no quicker :(*/
-#if 1
- if (target_write_memory(target, offset + dest_offset, 4, 128,
- page_buffer) != ERROR_OK) {
- LOG_ERROR("Write failed s %" PRIx32 " p %" PRIx32 "", sector, page);
- return ERROR_FLASH_OPERATION_FAILED;
- }
-#else
+
if (target_write_buffer(target, offset + dest_offset, FLASH_PAGE_SIZE,
page_buffer) != ERROR_OK) {
LOG_INFO("Write to flash buffer failed");
return ERROR_FLASH_OPERATION_FAILED;
}
-#endif
+
dest_offset += FLASH_PAGE_SIZE;
source_offset += count;
bytes_remaining -= count;
return ERROR_OK;
}
-static int lpc288x_info(struct flash_bank *bank, char *buf, int buf_size)
-{
- snprintf(buf, buf_size, "lpc288x flash driver");
- return ERROR_OK;
-}
-
-static int lpc288x_protect(struct flash_bank *bank, int set, int first, int last)
+static int lpc288x_protect(struct flash_bank *bank, int set, unsigned int first,
+ unsigned int last)
{
- int lockregion, status;
+ int status;
uint32_t value;
struct target *target = bank->target;
if (status != ERROR_OK)
return status;
- if ((first < 0) || (last < first) || (last >= bank->num_sectors))
+ if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID;
/* Configure the flash controller timing */
lpc288x_set_flash_clk(bank);
- for (lockregion = first; lockregion <= last; lockregion++) {
+ for (unsigned int lockregion = first; lockregion <= last; lockregion++) {
if (set) {
- /* write an odd value to base addy to protect... */
+ /* write an odd value to base address to protect... */
value = 0x01;
} else {
- /* write an even value to base addy to unprotect... */
+ /* write an even value to base address to unprotect... */
value = 0x00;
}
target_write_u32(target, bank->sectors[lockregion].offset, value);
return ERROR_OK;
}
-struct flash_driver lpc288x_flash = {
+const struct flash_driver lpc288x_flash = {
.name = "lpc288x",
.flash_bank_command = lpc288x_flash_bank_command,
.erase = lpc288x_erase,
.read = default_flash_read,
.probe = lpc288x_probe,
.auto_probe = lpc288x_probe,
- .erase_check = lpc288x_erase_check,
+ .erase_check = default_flash_blank_check,
.protect_check = lpc288x_protect_check,
- .info = lpc288x_info,
+ .free_driver_priv = default_flash_free_driver_priv,
};