build: cleanup src/flash/nor directory
Change-Id: Ic299de969ce566282c055ba4dd8b94892c4c4311 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/420 Tested-by: jenkins
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
@@ -25,9 +26,7 @@
|
||||
#include "ocl.h"
|
||||
#include <target/embeddedice.h>
|
||||
|
||||
|
||||
struct ocl_priv
|
||||
{
|
||||
struct ocl_priv {
|
||||
struct arm_jtag *jtag_info;
|
||||
unsigned int buflen;
|
||||
unsigned int bufalign;
|
||||
@@ -50,9 +49,7 @@ FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
|
||||
struct ocl_priv *ocl;
|
||||
|
||||
if (CMD_ARGC < 6)
|
||||
{
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
arm7_9 = target_to_arm7_9(bank->target);
|
||||
if (!is_arm7_9(arm7_9))
|
||||
@@ -76,39 +73,36 @@ static int ocl_erase(struct flash_bank *bank, int first, int last)
|
||||
if (bank->num_sectors == 0)
|
||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||
|
||||
if (bank->target->state != TARGET_RUNNING)
|
||||
{
|
||||
if (bank->target->state != TARGET_RUNNING) {
|
||||
LOG_ERROR("target has to be running to communicate with the loader");
|
||||
return ERROR_TARGET_NOT_RUNNING;
|
||||
}
|
||||
|
||||
if ((first == 0) && (last == bank->num_sectors - 1))
|
||||
{
|
||||
if ((first == 0) && (last == bank->num_sectors - 1)) {
|
||||
dcc_buffer[0] = OCL_ERASE_ALL;
|
||||
if ((retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dcc_buffer[0] = OCL_ERASE_BLOCK;
|
||||
dcc_buffer[1] = first;
|
||||
dcc_buffer[2] = last;
|
||||
if ((retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 3) != ERROR_OK))
|
||||
retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 3);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* wait for response, fixed timeout of 1 s */
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000) != ERROR_OK))
|
||||
{
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* receive response */
|
||||
if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer + 1, 1) != ERROR_OK))
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer + 1, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
|
||||
if (dcc_buffer[1] != OCL_CMD_DONE)
|
||||
{
|
||||
if (dcc_buffer[1] != OCL_CMD_DONE) {
|
||||
if (dcc_buffer[0] == OCL_ERASE_ALL)
|
||||
LOG_ERROR("loader response to OCL_ERASE_ALL 0x%08" PRIx32 "", dcc_buffer[1]);
|
||||
else
|
||||
@@ -140,8 +134,7 @@ static int ocl_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
|
||||
if (ocl->buflen == 0 || ocl->bufalign == 0)
|
||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||
|
||||
if (bank->target->state != TARGET_RUNNING)
|
||||
{
|
||||
if (bank->target->state != TARGET_RUNNING) {
|
||||
LOG_ERROR("target has to be running to communicate with the loader");
|
||||
return ERROR_TARGET_NOT_RUNNING;
|
||||
}
|
||||
@@ -149,8 +142,7 @@ static int ocl_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
|
||||
/* allocate buffer for max. ocl buffer + overhead */
|
||||
dcc_buffer = malloc(sizeof(uint32_t)*(ocl->buflen/4 + 3));
|
||||
|
||||
while (count)
|
||||
{
|
||||
while (count) {
|
||||
if (count + (offset % ocl->bufalign) > ocl->buflen)
|
||||
runlen = ocl->buflen - (offset % ocl->bufalign);
|
||||
else
|
||||
@@ -165,10 +157,8 @@ static int ocl_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
|
||||
chksum = OCL_CHKS_INIT;
|
||||
|
||||
/* copy data to DCC buffer in proper byte order and properly aligned */
|
||||
for (i = 0; i < runlen; i++)
|
||||
{
|
||||
switch (byteofs++)
|
||||
{
|
||||
for (i = 0; i < runlen; i++) {
|
||||
switch (byteofs++) {
|
||||
case 0:
|
||||
*dcc_bufptr &= *(buffer++) | 0xffffff00;
|
||||
break;
|
||||
@@ -194,28 +184,27 @@ static int ocl_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
|
||||
*(dcc_bufptr++) = chksum;
|
||||
|
||||
/* send the data */
|
||||
if ((retval = embeddedice_send(ocl->jtag_info, dcc_buffer, dcc_bufptr-dcc_buffer)) != ERROR_OK)
|
||||
{
|
||||
retval = embeddedice_send(ocl->jtag_info, dcc_buffer, dcc_bufptr-dcc_buffer);
|
||||
if (retval != ERROR_OK) {
|
||||
free(dcc_buffer);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* wait for response, fixed timeout of 1 s */
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000) != ERROR_OK))
|
||||
{
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000);
|
||||
if (retval != ERROR_OK) {
|
||||
free(dcc_buffer);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* receive response */
|
||||
if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
{
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK) {
|
||||
free(dcc_buffer);
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (dcc_buffer[0] != OCL_CMD_DONE)
|
||||
{
|
||||
if (dcc_buffer[0] != OCL_CMD_DONE) {
|
||||
LOG_ERROR("loader response to OCL_FLASH_BLOCK 0x%08" PRIx32 "", dcc_buffer[0]);
|
||||
free(dcc_buffer);
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
@@ -241,50 +230,61 @@ static int ocl_probe(struct flash_bank *bank)
|
||||
embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
|
||||
dcc_buffer[0] = OCL_PROBE;
|
||||
if ((retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_send(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
|
||||
/* wait for response, fixed timeout of 1 s */
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000) != ERROR_OK))
|
||||
{
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 1000);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* receive response */
|
||||
if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
|
||||
if (dcc_buffer[0] != OCL_CMD_DONE)
|
||||
{
|
||||
if (dcc_buffer[0] != OCL_CMD_DONE) {
|
||||
LOG_ERROR("loader response to OCL_PROBE 0x%08" PRIx32 "", dcc_buffer[0]);
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
/* receive and fill in parameters, detection of loader is important, receive it one by one */
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0) != ERROR_OK)
|
||||
|| (retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
bank->base = dcc_buffer[0];
|
||||
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0) != ERROR_OK)
|
||||
|| (retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
bank->size = dcc_buffer[0];
|
||||
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0) != ERROR_OK)
|
||||
|| (retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
bank->num_sectors = dcc_buffer[0];
|
||||
|
||||
if ((retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0) != ERROR_OK)
|
||||
|| (retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK))
|
||||
retval = embeddedice_handshake(ocl->jtag_info, EICE_COMM_CTRL_WBIT, 0);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
ocl->buflen = dcc_buffer[0] & 0xffff;
|
||||
ocl->bufalign = dcc_buffer[0] >> 16;
|
||||
|
||||
bank->sectors = realloc(bank->sectors, sizeof(struct flash_sector)*bank->num_sectors);
|
||||
if (bank->num_sectors == 0)
|
||||
{
|
||||
if (bank->num_sectors == 0) {
|
||||
LOG_ERROR("number of sectors shall be non zero value");
|
||||
return ERROR_FLASH_BANK_INVALID;
|
||||
}
|
||||
@@ -293,8 +293,7 @@ static int ocl_probe(struct flash_bank *bank)
|
||||
return ERROR_FLASH_BANK_INVALID;
|
||||
}
|
||||
sectsize = bank->size / bank->num_sectors;
|
||||
for (i = 0; i < bank->num_sectors; i++)
|
||||
{
|
||||
for (i = 0; i < bank->num_sectors; i++) {
|
||||
bank->sectors[i].offset = i * sectsize;
|
||||
bank->sectors[i].size = sectsize;
|
||||
bank->sectors[i].is_erased = -1;
|
||||
@@ -304,20 +303,17 @@ static int ocl_probe(struct flash_bank *bank)
|
||||
if (ocl->bufalign == 0)
|
||||
ocl->bufalign = 1;
|
||||
|
||||
if (ocl->buflen == 0)
|
||||
{
|
||||
if (ocl->buflen == 0) {
|
||||
LOG_ERROR("buflen shall be non zero value");
|
||||
return ERROR_FLASH_BANK_INVALID;
|
||||
}
|
||||
|
||||
if ((ocl->bufalign > ocl->buflen) || (ocl->buflen % ocl->bufalign))
|
||||
{
|
||||
if ((ocl->bufalign > ocl->buflen) || (ocl->buflen % ocl->bufalign)) {
|
||||
LOG_ERROR("buflen is not multiple of bufalign");
|
||||
return ERROR_FLASH_BANK_INVALID;
|
||||
}
|
||||
|
||||
if (ocl->buflen % 4)
|
||||
{
|
||||
if (ocl->buflen % 4) {
|
||||
LOG_ERROR("buflen shall be divisible by 4");
|
||||
return ERROR_FLASH_BANK_INVALID;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user