-#define CHIPID 0xE0000000 /* Chip ID */
-#define FEAT0 0xE0000100 /* Chip feature 0 */
-#define FEAT1 0xE0000104 /* Chip feature 1 */
-#define FEAT2 0xE0000108 /* Chip feature 2 (contains flash size indicator) */
-#define FEAT3 0xE000010C /* Chip feature 3 */
+#define CHIPID 0xE0000000 /* Chip ID */
+#define FEAT0 0xE0000100 /* Chip feature 0 */
+#define FEAT1 0xE0000104 /* Chip feature 1 */
+#define FEAT2 0xE0000108 /* Chip feature 2 (contains flash size indicator) */
+#define FEAT3 0xE000010C /* Chip feature 3 */
-#define FCTR 0x20200000 /* Flash control */
-#define FPTR 0x20200008 /* Flash program-time */
-#define FTCTR 0x2020000C /* Flash test control */
-#define FBWST 0x20200010 /* Flash bridge wait-state */
-#define FCRA 0x2020001C /* Flash clock divider */
-#define FMSSTART 0x20200020 /* Flash Built-In Selft Test start address */
-#define FMSSTOP 0x20200024 /* Flash Built-In Selft Test stop address */
-#define FMS16 0x20200028 /* Flash 16-bit signature */
-#define FMSW0 0x2020002C /* Flash 128-bit signature Word 0 */
-#define FMSW1 0x20200030 /* Flash 128-bit signature Word 1 */
-#define FMSW2 0x20200034 /* Flash 128-bit signature Word 2 */
-#define FMSW3 0x20200038 /* Flash 128-bit signature Word 3 */
-
-#define EECMD 0x20200080 /* EEPROM command */
-#define EEADDR 0x20200084 /* EEPROM address */
-#define EEWDATA 0x20200088 /* EEPROM write data */
-#define EERDATA 0x2020008C /* EEPROM read data */
-#define EEWSTATE 0x20200090 /* EEPROM wait state */
-#define EECLKDIV 0x20200094 /* EEPROM clock divider */
-#define EEPWRDWN 0x20200098 /* EEPROM power-down/start */
-#define EEMSSTART 0x2020009C /* EEPROM BIST start address */
-#define EEMSSTOP 0x202000A0 /* EEPROM BIST stop address */
-#define EEMSSIG 0x202000A4 /* EEPROM 24-bit BIST signature */
-
-#define INT_CLR_ENABLE 0x20200FD8 /* Flash/EEPROM interrupt clear enable */
-#define INT_SET_ENABLE 0x20200FDC /* Flash/EEPROM interrupt set enable */
-#define INT_STATUS 0x20200FE0 /* Flash/EEPROM interrupt status */
-#define INT_ENABLE 0x20200FE4 /* Flash/EEPROM interrupt enable */
-#define INT_CLR_STATUS 0x20200FE8 /* Flash/EEPROM interrupt clear status */
-#define INT_SET_STATUS 0x20200FEC /* Flash/EEPROM interrupt set status */
+#define FCTR 0x20200000 /* Flash control */
+#define FPTR 0x20200008 /* Flash program-time */
+#define FTCTR 0x2020000C /* Flash test control */
+#define FBWST 0x20200010 /* Flash bridge wait-state */
+#define FCRA 0x2020001C /* Flash clock divider */
+#define FMSSTART 0x20200020 /* Flash Built-In Selft Test start address */
+#define FMSSTOP 0x20200024 /* Flash Built-In Selft Test stop address */
+#define FMS16 0x20200028 /* Flash 16-bit signature */
+#define FMSW0 0x2020002C /* Flash 128-bit signature Word 0 */
+#define FMSW1 0x20200030 /* Flash 128-bit signature Word 1 */
+#define FMSW2 0x20200034 /* Flash 128-bit signature Word 2 */
+#define FMSW3 0x20200038 /* Flash 128-bit signature Word 3 */
+
+#define EECMD 0x20200080 /* EEPROM command */
+#define EEADDR 0x20200084 /* EEPROM address */
+#define EEWDATA 0x20200088 /* EEPROM write data */
+#define EERDATA 0x2020008C /* EEPROM read data */
+#define EEWSTATE 0x20200090 /* EEPROM wait state */
+#define EECLKDIV 0x20200094 /* EEPROM clock divider */
+#define EEPWRDWN 0x20200098 /* EEPROM power-down/start */
+#define EEMSSTART 0x2020009C /* EEPROM BIST start address */
+#define EEMSSTOP 0x202000A0 /* EEPROM BIST stop address */
+#define EEMSSIG 0x202000A4 /* EEPROM 24-bit BIST signature */
+
+#define INT_CLR_ENABLE 0x20200FD8 /* Flash/EEPROM interrupt clear enable */
+#define INT_SET_ENABLE 0x20200FDC /* Flash/EEPROM interrupt set enable */
+#define INT_STATUS 0x20200FE0 /* Flash/EEPROM interrupt status */
+#define INT_ENABLE 0x20200FE4 /* Flash/EEPROM interrupt enable */
+#define INT_CLR_STATUS 0x20200FE8 /* Flash/EEPROM interrupt clear status */
+#define INT_SET_STATUS 0x20200FEC /* Flash/EEPROM interrupt set status */
static uint32_t lpc2900_wait_status(struct flash_bank *bank, uint32_t mask, int timeout);
static void lpc2900_setup(struct flash_bank *bank);
static uint32_t lpc2900_is_ready(struct flash_bank *bank);
static uint32_t lpc2900_read_security_status(struct flash_bank *bank);
static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
static uint32_t lpc2900_wait_status(struct flash_bank *bank, uint32_t mask, int timeout);
static void lpc2900_setup(struct flash_bank *bank);
static uint32_t lpc2900_is_ready(struct flash_bank *bank);
static uint32_t lpc2900_read_security_status(struct flash_bank *bank);
static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
LOG_ERROR("Refuse to burn index sector page %d", pagenum);
return ERROR_COMMAND_ARGUMENT_INVALID;
}
/* Get target, and check if it's halted */
struct target *target = bank->target;
LOG_ERROR("Refuse to burn index sector page %d", pagenum);
return ERROR_COMMAND_ARGUMENT_INVALID;
}
/* Get target, and check if it's halted */
struct target *target = bank->target;
- target_write_u32( target, bank->base, 0 );
- target_write_u32( target, FCTR,
- FCTR_FS_LOADREQ | FCTR_FS_WPB | FCTR_FS_ISS |
- FCTR_FS_WEB | FCTR_FS_WRE | FCTR_FS_CS );
+ target_write_u32(target, bank->base, 0);
+ target_write_u32(target, FCTR,
+ FCTR_FS_LOADREQ | FCTR_FS_WPB | FCTR_FS_ISS |
+ FCTR_FS_WEB | FCTR_FS_WRE | FCTR_FS_CS);
- if( target_write_memory( target,
- bank->base + pagenum * FLASH_PAGE_SIZE,
- 4, FLASH_PAGE_SIZE / 4, (uint8_t *)page) != ERROR_OK )
- {
+ if (target_write_memory(target,
+ bank->base + pagenum * FLASH_PAGE_SIZE,
+ 4, FLASH_PAGE_SIZE / 4, page) != ERROR_OK) {
- target_read_memory( target, bank->base+ISS_CUSTOMER_START1, 4,
- ISS_CUSTOMER_NWORDS1,
- (uint8_t *)&customer[0] );
- target_read_memory( target, bank->base+ISS_CUSTOMER_START2, 4,
- ISS_CUSTOMER_NWORDS2,
- (uint8_t *)&customer[ISS_CUSTOMER_NWORDS1] );
+ target_read_memory(target, bank->base+ISS_CUSTOMER_START1, 4,
+ ISS_CUSTOMER_NWORDS1,
+ &customer[0]);
+ target_read_memory(target, bank->base+ISS_CUSTOMER_START2, 4,
+ ISS_CUSTOMER_NWORDS2,
+ &customer[4 * ISS_CUSTOMER_NWORDS1]);
- ret = fileio_write( &fileio, sizeof(customer),
- (const uint8_t *)customer, &nwritten );
- if( ret != ERROR_OK )
- {
- LOG_ERROR( "Write operation to file %s failed", filename );
- fileio_close( &fileio );
+ ret = fileio_write(&fileio, sizeof(customer), customer, &nwritten);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Write operation to file %s failed", filename);
+ fileio_close(&fileio);
- retval = image_read_section( &image, 0, 0,
- ISS_CUSTOMER_SIZE1, &page[offset], &size_read);
- if( retval != ERROR_OK )
- {
+ retval = image_read_section(&image, 0, 0,
+ ISS_CUSTOMER_SIZE1, &page[offset], &size_read);
+ if (retval != ERROR_OK) {
- memset( page, 0xff, FLASH_PAGE_SIZE );
- retval = image_read_section( &image, 0, ISS_CUSTOMER_SIZE1,
- ISS_CUSTOMER_SIZE2, &page[offset], &size_read);
- if( retval != ERROR_OK )
- {
+ memset(page, 0xff, FLASH_PAGE_SIZE);
+ retval = image_read_section(&image, 0, ISS_CUSTOMER_SIZE1,
+ ISS_CUSTOMER_SIZE2, &page[offset], &size_read);
+ if (retval != ERROR_OK) {
- if( (first <= 4) || (last >= 8) )
- {
- memset( &page, 0xff, FLASH_PAGE_SIZE );
- for( sector = first; sector <= last; sector++ )
- {
- if( sector <= 4 )
- {
- memset( &page[0xB0 + 16*sector], 0, 16 );
- }
- else if( sector >= 8 )
- {
- memset( &page[0x00 + 16*(sector - 8)], 0, 16 );
- }
+ if ((first <= 4) || (last >= 8)) {
+ memset(&page, 0xff, FLASH_PAGE_SIZE);
+ for (sector = first; sector <= last; sector++) {
+ if (sector <= 4)
+ memset(&page[0xB0 + 16*sector], 0, 16);
+ else if (sector >= 8)
+ memset(&page[0x00 + 16*(sector - 8)], 0, 16);
- if( (first <= 7) && (last >= 5) )
- {
- memset( &page, 0xff, FLASH_PAGE_SIZE );
- for( sector = first; sector <= last; sector++ )
- {
- if( (sector >= 5) && (sector <= 7) )
- {
- memset( &page[0x00 + 16*(sector - 5)], 0, 16 );
- }
+ if ((first <= 7) && (last >= 5)) {
+ memset(&page, 0xff, FLASH_PAGE_SIZE);
+ for (sector = first; sector <= last; sector++) {
+ if ((sector >= 5) && (sector <= 7))
+ memset(&page[0x00 + 16*(sector - 5)], 0, 16);
/* Unprotect the sector */
target_write_u32(target, bank->sectors[sector].offset, 0);
target_write_u32(target, FCTR,
/* Unprotect the sector */
target_write_u32(target, bank->sectors[sector].offset, 0);
target_write_u32(target, FCTR,
- * "Protection" in LPC2900 terms is handled transparently. Sectors will
- * automatically be unprotected as needed.
- * Instead we use the concept of sector security. A secured sector is shown
- * as "protected" in OpenOCD. Sector security is a permanent feature, and
- * cannot be disabled once activated.
- */
+ * "Protection" in LPC2900 terms is handled transparently. Sectors will
+ * automatically be unprotected as needed.
+ * Instead we use the concept of sector security. A secured sector is shown
+ * as "protected" in OpenOCD. Sector security is a permanent feature, and
+ * cannot be disabled once activated.
+ */
- 0xe3a06020, /* mov r6,#(512/16) */
- 0xe8b00f00, /* next ldmia r0!,{r8-r11} */
- 0xe8a10f00, /* stmia r1!,{r8-r11} */
- 0xe2566001, /* subs r6,#1 */
- 0x1afffffb, /* bne next */
+ 0xe3a06020, /* mov r6,#(512/16) */
+ 0xe8b00f00, /* next ldmia r0!,{r8-r11} */
+ 0xe8a10f00, /* stmia r1!,{r8-r11} */
+ 0xe2566001, /* subs r6,#1 */
+ 0x1afffffb, /* bne next */
- FCTR = CS | WRE | WPB | PROGREQ */
- 0xe3a0a083, /* mov r10,#0x83 */
- 0xe38aaa01, /* orr r10,#0x1000 */
- 0xe583a000, /* str r10,[r3,#0] */
+ * FCTR = CS | WRE | WPB | PROGREQ */
+ 0xe3a0a083, /* mov r10,#0x83 */
+ 0xe38aaa01, /* orr r10,#0x1000 */
+ 0xe583a000, /* str r10,[r3,#0] */
- 0xe593afe0, /* wait ldr r10,[r3,#0xfe0] */
- 0xe21aa002, /* ands r10,#(1 << 1) */
- 0x0afffffc, /* beq wait */
+ 0xe593afe0, /* wait ldr r10,[r3,#0xfe0] */
+ 0xe21aa002, /* ands r10,#(1 << 1) */
+ 0x0afffffc, /* beq wait */
- for (sector = 0; sector < bank->num_sectors; sector++)
- {
- /* Start address in or before this sector? */
- /* End address in or behind this sector? */
- if ( ((bank->base + offset) <
- (bank->sectors[sector].offset + bank->sectors[sector].size)) &&
- ((bank->base + (offset + count - 1)) >= bank->sectors[sector].offset) )
- {
+ for (sector = 0; sector < bank->num_sectors; sector++) {
+ /* Start address in or before this sector?
+ * End address in or behind this sector? */
+ if (((bank->base + offset) <
+ (bank->sectors[sector].offset + bank->sectors[sector].size)) &&
+ ((bank->base + (offset + count - 1)) >= bank->sectors[sector].offset)) {
- retval = target_write_buffer( target,
- (warea->address)+buffer_size,
- target_code_size,
- (uint8_t *)write_target_code);
- if (retval != ERROR_OK)
- {
+ uint8_t code[sizeof(write_target_code)];
+ target_buffer_set_u32_array(target, code, ARRAY_SIZE(write_target_code),
+ write_target_code);
+ retval = target_write_buffer(target, (warea->address) + buffer_size, sizeof(code), code);
+ if (retval != ERROR_OK) {
- Burn first partial page separately. */
- memset( &page, 0xff, sizeof(page) );
- memcpy( &page[offset % FLASH_PAGE_SIZE],
- buffer,
- FLASH_PAGE_SIZE - (offset % FLASH_PAGE_SIZE) );
+ * Burn first partial page separately. */
+ memset(&page, 0xff, sizeof(page));
+ memcpy(&page[offset % FLASH_PAGE_SIZE],
+ buffer,
+ FLASH_PAGE_SIZE - (offset % FLASH_PAGE_SIZE));
- if (target_write_memory(
- target,
- bank->base + (offset - (offset % FLASH_PAGE_SIZE)),
- 4, FLASH_PAGE_SIZE / 4, page) != ERROR_OK)
- {
+ if (target_write_memory(target,
+ bank->base + (offset - (offset % FLASH_PAGE_SIZE)),
+ 4, FLASH_PAGE_SIZE / 4, page) != ERROR_OK) {
- if ( (status = lpc2900_run_bist128( bank,
- bank->sectors[sector].offset,
- bank->sectors[sector].offset +
- (bank->sectors[sector].size - 1),
- &signature)) != ERROR_OK )
- {
+ status = lpc2900_run_bist128(bank, bank->sectors[sector].offset,
+ bank->sectors[sector].offset + (bank->sectors[sector].size - 1), signature);
+ if (status != ERROR_OK)
-
-/**
- * Print info about the driver (not the device).
- *
- * @param bank Pointer to the flash bank descriptor
- * @param buf Buffer to take the string
- * @param buf_size Maximum number of characters that the buffer can take
- */
-static int lpc2900_info(struct flash_bank *bank, char *buf, int buf_size)
-{
- snprintf(buf, buf_size, "lpc2900 flash driver");
-
- return ERROR_OK;
-}
-
-
-struct flash_driver lpc2900_flash =
-{
- .name = "lpc2900",
- .commands = lpc2900_command_handlers,
+struct flash_driver lpc2900_flash = {
+ .name = "lpc2900",
+ .commands = lpc2900_command_handlers,
- .erase = lpc2900_erase,
- .protect = lpc2900_protect,
- .write = lpc2900_write,
- .probe = lpc2900_probe,
- .auto_probe = lpc2900_probe,
- .erase_check = lpc2900_erase_check,
- .protect_check = lpc2900_protect_check,
- .info = lpc2900_info
+ .erase = lpc2900_erase,
+ .protect = lpc2900_protect,
+ .write = lpc2900_write,
+ .read = default_flash_read,
+ .probe = lpc2900_probe,
+ .auto_probe = lpc2900_probe,
+ .erase_check = lpc2900_erase_check,
+ .protect_check = lpc2900_protect_check,