From 7151398cff16129764c79038a2701322f62da883 Mon Sep 17 00:00:00 2001 From: Alexandre Pereira da Silva Date: Fri, 24 Feb 2012 18:51:48 -0200 Subject: [PATCH] stlink: fix alignment build warning The {read,write}_mem32 interface functions was asking a 32 bits buffer but they don't need 32 bits alignment. This will change the interface to a 8 bits buffer to remove the alignment mismatch warning. This was causing build errors on platforms with strict aliasing rules. Change-Id: I338be8df5686f07a64ddb4f17c1bb494af583999 Signed-off-by: Alexandre Pereira da Silva Reviewed-on: http://openocd.zylin.com/483 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/jtag/drivers/stlink_usb.c | 8 ++++---- src/jtag/stlink/stlink_layout.h | 4 ++-- src/target/stm32_stlink.c | 14 ++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 98eeb090..33126424 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -926,7 +926,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, h_u16_to_le(h->cmdbuf+h->cmdidx, len); h->cmdidx += 2; - res = stlink_usb_xfer(handle, (uint8_t *) buffer, len); + res = stlink_usb_xfer(handle, buffer, len); if (res != ERROR_OK) return res; @@ -936,7 +936,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, /** */ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, - uint32_t *buffer) + uint8_t *buffer) { int res; struct stlink_usb_handle_s *h; @@ -968,7 +968,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, /** */ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, - const uint32_t *buffer) + const uint8_t *buffer) { int res; struct stlink_usb_handle_s *h; @@ -988,7 +988,7 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, h_u16_to_le(h->cmdbuf+h->cmdidx, len); h->cmdidx += 2; - res = stlink_usb_xfer(handle, (uint8_t *) buffer, len); + res = stlink_usb_xfer(handle, buffer, len); if (res != ERROR_OK) return res; diff --git a/src/jtag/stlink/stlink_layout.h b/src/jtag/stlink/stlink_layout.h index c0c89f57..59e6174c 100644 --- a/src/jtag/stlink/stlink_layout.h +++ b/src/jtag/stlink/stlink_layout.h @@ -56,10 +56,10 @@ struct stlink_layout_api_s { const uint8_t *buffer); /** */ int (*read_mem32) (void *handle, uint32_t addr, uint16_t len, - uint32_t *buffer); + uint8_t *buffer); /** */ int (*write_mem32) (void *handle, uint32_t addr, uint16_t len, - const uint32_t *buffer); + const uint8_t *buffer); /** */ int (*idcode) (void *fd, uint32_t *idcode); /** */ diff --git a/src/target/stm32_stlink.c b/src/target/stm32_stlink.c index d2f38e5a..7bec73f5 100644 --- a/src/target/stm32_stlink.c +++ b/src/target/stm32_stlink.c @@ -586,7 +586,6 @@ static int stm32_stlink_read_memory(struct target *target, uint32_t address, int res; uint32_t buffer_threshold = 128; uint32_t addr_increment = 4; - uint8_t *dst = buffer; uint32_t c; struct stlink_interface_s *stlink_if = target_to_stlink(target); @@ -612,16 +611,16 @@ static int stm32_stlink_read_memory(struct target *target, uint32_t address, if (size != 4) res = stlink_if->layout->api->read_mem8(stlink_if->fd, - address, c, dst); + address, c, buffer); else res = stlink_if->layout->api->read_mem32(stlink_if->fd, - address, c, (uint32_t *)dst); + address, c, buffer); if (res != ERROR_OK) return res; address += (c * addr_increment); - dst += (c * addr_increment); + buffer += (c * addr_increment); count -= c; } @@ -635,7 +634,6 @@ static int stm32_stlink_write_memory(struct target *target, uint32_t address, int res; uint32_t buffer_threshold = 128; uint32_t addr_increment = 4; - const uint8_t *dst = buffer; uint32_t c; struct stlink_interface_s *stlink_if = target_to_stlink(target); @@ -661,16 +659,16 @@ static int stm32_stlink_write_memory(struct target *target, uint32_t address, if (size != 4) res = stlink_if->layout->api->write_mem8(stlink_if->fd, - address, c, dst); + address, c, buffer); else res = stlink_if->layout->api->write_mem32(stlink_if->fd, - address, c, (uint32_t *)dst); + address, c, buffer); if (res != ERROR_OK) return res; address += (c * addr_increment); - dst += (c * addr_increment); + buffer += (c * addr_increment); count -= c; } -- 2.39.5