This patch introduces a serious and sweeping regression that
a compiler warning caught:

cc1: warnings being treated as errors
src/target/target.c: In function ‘target_read_buffer’:
src/target/target.c:1490: error: control reaches end of non-void function


How's the attached updated patch?


(Otherwise the patch seems fine to me)

-- 
Øyvind Harboe

Can Zylin Consulting help on your project?

US toll free 1-866-980-3434 / International +47 51 63 25 00

http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
From d5a167f186dddc060c1a287c6a2f168975976789 Mon Sep 17 00:00:00 2001
From: Timo Juhani Lindfors <[email protected]>
Date: Sun, 28 Nov 2010 19:30:12 +0200
Subject: [PATCH] TARGET: Add "phys" flag to dump_image command

---
 doc/openocd.texi    |    9 ++++++---
 src/target/target.c |   37 +++++++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 70d789a..1b75f94 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -5731,9 +5731,12 @@ Otherwise, or if the optional @var{phys} flag is specified,
 @cindex image dumping
 
 @anchor{dump_image}
-...@deffn Command {dump_image} filename address size
-Dump @var{size} bytes of target memory starting at @var{address} to the
-binary file named @var{filename}.
+...@deffn Command {dump_image} [phys] filename address size
+Dump @var{size} bytes of target memory starting at @var{address} to
+the binary file named @var{filename}. When the current target has an
+MMU which is present and active, @var{addr} is interpreted as a
+virtual address.  Otherwise, or if the optional @var{phys} flag is
+specified, @var{addr} is interpreted as a physical address.
 @end deffn
 
 @deffn Command {fast_load}
diff --git a/src/target/target.c b/src/target/target.c
index 93efa76..01dfa6b 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -1393,12 +1393,22 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
  * mode respectively, otherwise data is handled as quickly as
  * possible
  */
-int target_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+static int target_read_buffer2(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer, bool physical)
 {
 	int retval;
 	LOG_DEBUG("reading buffer of %i byte at 0x%8.8x",
 			  (int)size, (unsigned)address);
 
+	int (*read_fn)(struct target *target,
+			uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+	if (physical)
+	{
+		read_fn=target_read_phys_memory;
+	} else
+	{
+		read_fn=target_read_memory;
+	}
+
 	if (!target_was_examined(target))
 	{
 		LOG_ERROR("Target not examined yet");
@@ -1420,7 +1430,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
 
 	if (((address % 2) == 0) && (size == 2))
 	{
-		return target_read_memory(target, address, 2, 1, buffer);
+		return read_fn(target, address, 2, 1, buffer);
 	}
 
 	/* handle unaligned head bytes */
@@ -1431,7 +1441,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
 		if (unaligned > size)
 			unaligned = size;
 
-		if ((retval = target_read_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
+		if ((retval = read_fn(target, address, 1, unaligned, buffer)) != ERROR_OK)
 			return retval;
 
 		buffer += unaligned;
@@ -1444,7 +1454,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
 	{
 		int aligned = size - (size % 4);
 
-		if ((retval = target_read_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
+		if ((retval = read_fn(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
 			return retval;
 
 		buffer += aligned;
@@ -1456,7 +1466,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
 	if(size	>=2)
 	{
 		int aligned = size - (size%2);
-		retval = target_read_memory(target, address, 2, aligned / 2, buffer);
+		retval = read_fn(target, address, 2, aligned / 2, buffer);
 		if (retval != ERROR_OK)
 			return retval;
 
@@ -1467,13 +1477,18 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
 	/* handle tail writes of less than 4 bytes */
 	if (size > 0)
 	{
-		if ((retval = target_read_memory(target, address, 1, size, buffer)) != ERROR_OK)
+		if ((retval = read_fn(target, address, 1, size, buffer)) != ERROR_OK)
 			return retval;
 	}
 
 	return ERROR_OK;
 }
 
+int target_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+{
+	return target_read_buffer2(target, address, size, buffer, false);
+}
+
 int target_checksum_memory(struct target *target, uint32_t address, uint32_t size, uint32_t* crc)
 {
 	uint8_t *buffer;
@@ -2605,6 +2620,12 @@ COMMAND_HANDLER(handle_dump_image_command)
 	struct duration bench;
 	struct target *target = get_current_target(CMD_CTX);
 
+	bool physical=strcmp(CMD_ARGV[0], "phys")==0;
+	if (physical)
+	{
+		CMD_ARGC--;
+		CMD_ARGV++;
+	}
 	if (CMD_ARGC != 3)
 		return ERROR_COMMAND_SYNTAX_ERROR;
 
@@ -2622,7 +2643,7 @@ COMMAND_HANDLER(handle_dump_image_command)
 	{
 		size_t size_written;
 		uint32_t this_run_size = (size > 560) ? 560 : size;
-		retval = target_read_buffer(target, address, this_run_size, buffer);
+		retval = target_read_buffer2(target, address, this_run_size, buffer, physical);
 		if (retval != ERROR_OK)
 		{
 			break;
@@ -5305,7 +5326,7 @@ static const struct command_registration target_exec_command_handlers[] = {
 		.name = "dump_image",
 		.handler = handle_dump_image_command,
 		.mode = COMMAND_EXEC,
-		.usage = "filename address size",
+		.usage = "['phys'] filename address size",
 	},
 	{
 		.name = "verify_image",
-- 
1.7.0.4

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to