gerrit
2017-05-01 19:54:08 UTC
This is an automated email from Gerrit.
Steven Stallion (***@gmail.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/4114
-- gerrit
commit 30c234cb9624f0b1a22de80d75cef117a075845e
Author: Steven Stallion <***@squareup.com>
Date: Mon May 1 14:50:42 2017 -0500
target: provide default checksum_memory function
This patch adds a default implementation for checksum_memory. There are
fewer targets that support hardware-assisted checksumming than not;
because of this it doesn't make much sense for this to be a required
part of the target type interface.
Change-Id: I1568a4bd1481777f2fb04fc09468665a33687463
Signed-off-by: Steven Stallion <***@squareup.com>
diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c
index a50f2cd..78bc563 100644
--- a/src/target/dsp5680xx.c
+++ b/src/target/dsp5680xx.c
@@ -1494,24 +1494,6 @@ static int dsp5680xx_read_buffer(struct target *t, target_addr_t a, uint32_t siz
}
/**
- * This function is not implemented.
- * It returns an error in order to get OpenOCD to do read out the data
- * and calculate the CRC, or try a binary comparison.
- *
- * @param target
- * @param address Start address of the image.
- * @param size In bytes.
- * @param checksum
- *
- * @return
- */
-static int dsp5680xx_checksum_memory(struct target *t, target_addr_t a, uint32_t s,
- uint32_t *checksum)
-{
- return ERROR_FAIL;
-}
-
-/**
* Calculates a signature over @word_count words in the data from @buff16.
* The algorithm used is the same the FM uses, so the @return may be used to compare
* with the one generated by the FM module, and check if flashing was successful.
@@ -2290,8 +2272,6 @@ struct target_type dsp5680xx_target = {
.read_memory = dsp5680xx_read,
.write_memory = dsp5680xx_write,
- .checksum_memory = dsp5680xx_checksum_memory,
-
.target_create = dsp5680xx_target_create,
.init_target = dsp5680xx_init_target,
};
diff --git a/src/target/nds32_v2.c b/src/target/nds32_v2.c
index 29489a0..f20ec7d 100644
--- a/src/target/nds32_v2.c
+++ b/src/target/nds32_v2.c
@@ -404,14 +404,6 @@ static int nds32_v2_deassert_reset(struct target *target)
return ERROR_OK;
}
-static int nds32_v2_checksum_memory(struct target *target,
- target_addr_t address, uint32_t count, uint32_t *checksum)
-{
- LOG_WARNING("Not implemented: %s", __func__);
-
- return ERROR_FAIL;
-}
-
static int nds32_v2_add_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
@@ -761,8 +753,6 @@ struct target_type nds32_v2_target = {
.read_memory = nds32_v2_read_memory,
.write_memory = nds32_v2_write_memory,
- .checksum_memory = nds32_v2_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v2_add_breakpoint,
.remove_breakpoint = nds32_v2_remove_breakpoint,
diff --git a/src/target/nds32_v3.c b/src/target/nds32_v3.c
index e5d146b..ebd3780 100644
--- a/src/target/nds32_v3.c
+++ b/src/target/nds32_v3.c
@@ -492,8 +492,6 @@ struct target_type nds32_v3_target = {
.read_memory = nds32_v3_read_memory,
.write_memory = nds32_v3_write_memory,
- .checksum_memory = nds32_v3_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v3_add_breakpoint,
.remove_breakpoint = nds32_v3_remove_breakpoint,
diff --git a/src/target/nds32_v3_common.c b/src/target/nds32_v3_common.c
index 271ffdd..d91f3e2 100644
--- a/src/target/nds32_v3_common.c
+++ b/src/target/nds32_v3_common.c
@@ -367,14 +367,6 @@ int nds32_v3_target_request_data(struct target *target,
return ERROR_OK;
}
-int nds32_v3_checksum_memory(struct target *target,
- target_addr_t address, uint32_t count, uint32_t *checksum)
-{
- LOG_WARNING("Not implemented: %s", __func__);
-
- return ERROR_FAIL;
-}
-
/**
* find out which watchpoint hits
* get exception address and compare the address to watchpoints
diff --git a/src/target/nds32_v3m.c b/src/target/nds32_v3m.c
index 86903a5..d87b369 100644
--- a/src/target/nds32_v3m.c
+++ b/src/target/nds32_v3m.c
@@ -479,8 +479,6 @@ struct target_type nds32_v3m_target = {
.read_memory = nds32_v3_read_memory,
.write_memory = nds32_v3_write_memory,
- .checksum_memory = nds32_v3_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v3m_add_breakpoint,
.remove_breakpoint = nds32_v3m_remove_breakpoint,
diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c
index 3895ddf..7730b52 100644
--- a/src/target/openrisc/or1k.c
+++ b/src/target/openrisc/or1k.c
@@ -1206,12 +1206,6 @@ int or1k_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *file
return ERROR_FAIL;
}
-static int or1k_checksum_memory(struct target *target, target_addr_t address,
- uint32_t count, uint32_t *checksum) {
-
- return ERROR_FAIL;
-}
-
static int or1k_profiling(struct target *target, uint32_t *samples,
uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
{
@@ -1447,7 +1441,6 @@ struct target_type or1k_target = {
.read_memory = or1k_read_memory,
.write_memory = or1k_write_memory,
- .checksum_memory = or1k_checksum_memory,
.commands = or1k_command_handlers,
.add_breakpoint = or1k_add_breakpoint,
diff --git a/src/target/target.c b/src/target/target.c
index e04ecc4..867def3 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -58,6 +58,8 @@
/* default halt wait timeout (ms) */
#define DEFAULT_HALT_TIMEOUT 5000
+static int target_checksum_memory_default(struct target *target, uint32_t address,
+ uint32_t size, uint32_t* checksum);
static int target_read_buffer_default(struct target *target, target_addr_t address,
uint32_t count, uint8_t *buffer);
static int target_write_buffer_default(struct target *target, target_addr_t address,
@@ -1256,6 +1258,9 @@ static int target_init_one(struct command_context *cmd_ctx,
type->virt2phys = identity_virt2phys;
}
+ if (target->type->checksum_memory == NULL)
+ target->type->checksum_memory = target_checksum_memory_default;
+
if (target->type->read_buffer == NULL)
target->type->read_buffer = target_read_buffer_default;
@@ -2164,42 +2169,50 @@ static int target_read_buffer_default(struct target *target, target_addr_t addre
return ERROR_OK;
}
-int target_checksum_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t* crc)
+int target_checksum_memory(struct target *target, uint32_t address, uint32_t size, uint32_t* crc)
{
- uint8_t *buffer;
- int retval;
- uint32_t i;
uint32_t checksum = 0;
+
if (!target_was_examined(target)) {
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
}
- retval = target->type->checksum_memory(target, address, size, &checksum);
- if (retval != ERROR_OK) {
- buffer = malloc(size);
- if (buffer == NULL) {
- LOG_ERROR("error allocating buffer for section (%" PRId32 " bytes)", size);
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
- retval = target_read_buffer(target, address, size, buffer);
- if (retval != ERROR_OK) {
- free(buffer);
- return retval;
- }
+ int retval = target->type->checksum_memory(target, address, size, &checksum);
+ if (retval != ERROR_OK)
+ return retval;
- /* convert to target endianness */
- for (i = 0; i < (size/sizeof(uint32_t)); i++) {
- uint32_t target_data;
- target_data = target_buffer_get_u32(target, &buffer[i*sizeof(uint32_t)]);
- target_buffer_set_u32(target, &buffer[i*sizeof(uint32_t)], target_data);
- }
+ *crc = checksum;
- retval = image_calculate_checksum(buffer, size, &checksum);
+ return retval;
+}
+
+static int target_checksum_memory_default(struct target *target, uint32_t address, uint32_t size, uint32_t* checksum)
+{
+ uint8_t *buffer;
+ int retval;
+ uint32_t i;
+
+ buffer = malloc(size);
+ if (buffer == NULL) {
+ LOG_ERROR("error allocating buffer for section (%" PRId32 " bytes)", size);
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ retval = target_read_buffer(target, address, size, buffer);
+ if (retval != ERROR_OK) {
free(buffer);
+ return retval;
}
- *crc = checksum;
+ /* convert to target endianness */
+ for (i = 0; i < (size/sizeof(uint32_t)); i++) {
+ uint32_t target_data;
+ target_data = target_buffer_get_u32(target, &buffer[i*sizeof(uint32_t)]);
+ target_buffer_set_u32(target, &buffer[i*sizeof(uint32_t)], target_data);
+ }
+
+ retval = image_calculate_checksum(buffer, size, checksum);
+ free(buffer);
return retval;
}
--
Steven Stallion (***@gmail.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/4114
-- gerrit
commit 30c234cb9624f0b1a22de80d75cef117a075845e
Author: Steven Stallion <***@squareup.com>
Date: Mon May 1 14:50:42 2017 -0500
target: provide default checksum_memory function
This patch adds a default implementation for checksum_memory. There are
fewer targets that support hardware-assisted checksumming than not;
because of this it doesn't make much sense for this to be a required
part of the target type interface.
Change-Id: I1568a4bd1481777f2fb04fc09468665a33687463
Signed-off-by: Steven Stallion <***@squareup.com>
diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c
index a50f2cd..78bc563 100644
--- a/src/target/dsp5680xx.c
+++ b/src/target/dsp5680xx.c
@@ -1494,24 +1494,6 @@ static int dsp5680xx_read_buffer(struct target *t, target_addr_t a, uint32_t siz
}
/**
- * This function is not implemented.
- * It returns an error in order to get OpenOCD to do read out the data
- * and calculate the CRC, or try a binary comparison.
- *
- * @param target
- * @param address Start address of the image.
- * @param size In bytes.
- * @param checksum
- *
- * @return
- */
-static int dsp5680xx_checksum_memory(struct target *t, target_addr_t a, uint32_t s,
- uint32_t *checksum)
-{
- return ERROR_FAIL;
-}
-
-/**
* Calculates a signature over @word_count words in the data from @buff16.
* The algorithm used is the same the FM uses, so the @return may be used to compare
* with the one generated by the FM module, and check if flashing was successful.
@@ -2290,8 +2272,6 @@ struct target_type dsp5680xx_target = {
.read_memory = dsp5680xx_read,
.write_memory = dsp5680xx_write,
- .checksum_memory = dsp5680xx_checksum_memory,
-
.target_create = dsp5680xx_target_create,
.init_target = dsp5680xx_init_target,
};
diff --git a/src/target/nds32_v2.c b/src/target/nds32_v2.c
index 29489a0..f20ec7d 100644
--- a/src/target/nds32_v2.c
+++ b/src/target/nds32_v2.c
@@ -404,14 +404,6 @@ static int nds32_v2_deassert_reset(struct target *target)
return ERROR_OK;
}
-static int nds32_v2_checksum_memory(struct target *target,
- target_addr_t address, uint32_t count, uint32_t *checksum)
-{
- LOG_WARNING("Not implemented: %s", __func__);
-
- return ERROR_FAIL;
-}
-
static int nds32_v2_add_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
@@ -761,8 +753,6 @@ struct target_type nds32_v2_target = {
.read_memory = nds32_v2_read_memory,
.write_memory = nds32_v2_write_memory,
- .checksum_memory = nds32_v2_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v2_add_breakpoint,
.remove_breakpoint = nds32_v2_remove_breakpoint,
diff --git a/src/target/nds32_v3.c b/src/target/nds32_v3.c
index e5d146b..ebd3780 100644
--- a/src/target/nds32_v3.c
+++ b/src/target/nds32_v3.c
@@ -492,8 +492,6 @@ struct target_type nds32_v3_target = {
.read_memory = nds32_v3_read_memory,
.write_memory = nds32_v3_write_memory,
- .checksum_memory = nds32_v3_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v3_add_breakpoint,
.remove_breakpoint = nds32_v3_remove_breakpoint,
diff --git a/src/target/nds32_v3_common.c b/src/target/nds32_v3_common.c
index 271ffdd..d91f3e2 100644
--- a/src/target/nds32_v3_common.c
+++ b/src/target/nds32_v3_common.c
@@ -367,14 +367,6 @@ int nds32_v3_target_request_data(struct target *target,
return ERROR_OK;
}
-int nds32_v3_checksum_memory(struct target *target,
- target_addr_t address, uint32_t count, uint32_t *checksum)
-{
- LOG_WARNING("Not implemented: %s", __func__);
-
- return ERROR_FAIL;
-}
-
/**
* find out which watchpoint hits
* get exception address and compare the address to watchpoints
diff --git a/src/target/nds32_v3m.c b/src/target/nds32_v3m.c
index 86903a5..d87b369 100644
--- a/src/target/nds32_v3m.c
+++ b/src/target/nds32_v3m.c
@@ -479,8 +479,6 @@ struct target_type nds32_v3m_target = {
.read_memory = nds32_v3_read_memory,
.write_memory = nds32_v3_write_memory,
- .checksum_memory = nds32_v3_checksum_memory,
-
/* breakpoint/watchpoint */
.add_breakpoint = nds32_v3m_add_breakpoint,
.remove_breakpoint = nds32_v3m_remove_breakpoint,
diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c
index 3895ddf..7730b52 100644
--- a/src/target/openrisc/or1k.c
+++ b/src/target/openrisc/or1k.c
@@ -1206,12 +1206,6 @@ int or1k_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *file
return ERROR_FAIL;
}
-static int or1k_checksum_memory(struct target *target, target_addr_t address,
- uint32_t count, uint32_t *checksum) {
-
- return ERROR_FAIL;
-}
-
static int or1k_profiling(struct target *target, uint32_t *samples,
uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
{
@@ -1447,7 +1441,6 @@ struct target_type or1k_target = {
.read_memory = or1k_read_memory,
.write_memory = or1k_write_memory,
- .checksum_memory = or1k_checksum_memory,
.commands = or1k_command_handlers,
.add_breakpoint = or1k_add_breakpoint,
diff --git a/src/target/target.c b/src/target/target.c
index e04ecc4..867def3 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -58,6 +58,8 @@
/* default halt wait timeout (ms) */
#define DEFAULT_HALT_TIMEOUT 5000
+static int target_checksum_memory_default(struct target *target, uint32_t address,
+ uint32_t size, uint32_t* checksum);
static int target_read_buffer_default(struct target *target, target_addr_t address,
uint32_t count, uint8_t *buffer);
static int target_write_buffer_default(struct target *target, target_addr_t address,
@@ -1256,6 +1258,9 @@ static int target_init_one(struct command_context *cmd_ctx,
type->virt2phys = identity_virt2phys;
}
+ if (target->type->checksum_memory == NULL)
+ target->type->checksum_memory = target_checksum_memory_default;
+
if (target->type->read_buffer == NULL)
target->type->read_buffer = target_read_buffer_default;
@@ -2164,42 +2169,50 @@ static int target_read_buffer_default(struct target *target, target_addr_t addre
return ERROR_OK;
}
-int target_checksum_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t* crc)
+int target_checksum_memory(struct target *target, uint32_t address, uint32_t size, uint32_t* crc)
{
- uint8_t *buffer;
- int retval;
- uint32_t i;
uint32_t checksum = 0;
+
if (!target_was_examined(target)) {
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
}
- retval = target->type->checksum_memory(target, address, size, &checksum);
- if (retval != ERROR_OK) {
- buffer = malloc(size);
- if (buffer == NULL) {
- LOG_ERROR("error allocating buffer for section (%" PRId32 " bytes)", size);
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
- retval = target_read_buffer(target, address, size, buffer);
- if (retval != ERROR_OK) {
- free(buffer);
- return retval;
- }
+ int retval = target->type->checksum_memory(target, address, size, &checksum);
+ if (retval != ERROR_OK)
+ return retval;
- /* convert to target endianness */
- for (i = 0; i < (size/sizeof(uint32_t)); i++) {
- uint32_t target_data;
- target_data = target_buffer_get_u32(target, &buffer[i*sizeof(uint32_t)]);
- target_buffer_set_u32(target, &buffer[i*sizeof(uint32_t)], target_data);
- }
+ *crc = checksum;
- retval = image_calculate_checksum(buffer, size, &checksum);
+ return retval;
+}
+
+static int target_checksum_memory_default(struct target *target, uint32_t address, uint32_t size, uint32_t* checksum)
+{
+ uint8_t *buffer;
+ int retval;
+ uint32_t i;
+
+ buffer = malloc(size);
+ if (buffer == NULL) {
+ LOG_ERROR("error allocating buffer for section (%" PRId32 " bytes)", size);
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ retval = target_read_buffer(target, address, size, buffer);
+ if (retval != ERROR_OK) {
free(buffer);
+ return retval;
}
- *crc = checksum;
+ /* convert to target endianness */
+ for (i = 0; i < (size/sizeof(uint32_t)); i++) {
+ uint32_t target_data;
+ target_data = target_buffer_get_u32(target, &buffer[i*sizeof(uint32_t)]);
+ target_buffer_set_u32(target, &buffer[i*sizeof(uint32_t)], target_data);
+ }
+
+ retval = image_calculate_checksum(buffer, size, checksum);
+ free(buffer);
return retval;
}
--