From ff5ec942d80a34e20b5a3ca3328f7e6a55fb309b Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Sat, 5 Oct 2013 00:19:08 +0200 Subject: arm7_9: Avoid infinite loops in bulk write dispatching Add a mandatory field in struct arm7_9_common for regular, non-optimized memory writes. Together with the existing bulk_memory_write field, this allows variants to select any combination of implementations for regular and bulk writes, without risking infinite loops from accidentally using bulk writes for implementing bulk writes. ARM 7/9 targets may now select arm7_9_memory_write_opt as their target.write_memory implementation, which will dispatch to arm7_9_common.bulk_write_memory if possible, or fallback to arm7_9_common.write_memory otherwise. To avoid loops, bulk write implementations mustn't call any other functions than arm7_9_write_memory_no_opt() to write memory; it will unconditionally call arm7_9_common.write_memory. If they fail, they should simply return error to allow the caller to fallback to regular writes. Tested on a regular ARM7TDMI only. Change-Id: Iae42a6e093e2df68c4823c927d757ae8f42ef388 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/1685 Tested-by: jenkins Reviewed-by: Sergey A. Borshch Reviewed-by: Spencer Oliver --- src/target/arm7_9_common.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/target/arm7_9_common.h') diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 85e5ac04..5821e132 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -119,6 +119,13 @@ struct arm7_9_common { void (*pre_restore_context)(struct target *target); /**< Callback function called before restoring the processor context */ + /** + * Variant specific memory write function that does not dispatch to bulk_write_memory. + * Used as a fallback when bulk writes are unavailable, or for writing data needed to + * do the bulk writes. + */ + int (*write_memory)(struct target *target, uint32_t address, + uint32_t size, uint32_t count, const uint8_t *buffer); /** * Write target memory in multiples of 4 bytes, optimized for * writing large quantities of data. @@ -160,6 +167,8 @@ int arm7_9_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); int arm7_9_write_memory_opt(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); +int arm7_9_write_memory_no_opt(struct target *target, uint32_t address, + uint32_t size, uint32_t count, const uint8_t *buffer); int arm7_9_bulk_write_memory(struct target *target, uint32_t address, uint32_t count, const uint8_t *buffer); -- cgit v1.2.3-18-g5258