arm_jtag.h: In function `arm7flip32':
arm_jtag.h:64: warning: cast increases required alignment of target type
arm_jtag.h: In function `arm_le_to_h_u32':
arm_jtag.h:70: warning: cast increases required alignment of target type
...
I made 3 patch files, all warnings are same, but way of fixing are different.
patch1: Cast from "uint32_t *" to "uint8_t *".
patch2: use union
patch3: "uint8_t *" => "ulong" => "uint32_t *"
tested with gcc 3.4.5 and 4.4.0.
--------
Hiroshi Ito
Media Lab. Inc.,
URL http://www.mlb.co.jp ( Sorry, Japanese only. )
TEL +81-3-5294-7255 FAX +81-3-5294-7256
Index: src/pld/virtex2.c
===================================================================
--- src/pld/virtex2.c (revision 2589)
+++ src/pld/virtex2.c (working copy)
@@ -90,8 +90,8 @@
static __inline__ void virtexflip32(jtag_callback_data_t arg)
{
- uint8_t *in = (uint8_t *)arg;
- *((uint32_t *)in) = flip_u32(le_to_h_u32(in), 32);
+ uint32_t *in = (uint32_t *)arg;
+ *in = flip_u32(le_to_h_u32((uint8_t *)in), 32);
}
static int virtex2_receive_32(struct pld_device_s *pld_device,
Index: src/target/etb.c
===================================================================
--- src/target/etb.c (revision 2589)
+++ src/target/etb.c (working copy)
@@ -160,8 +160,8 @@
static void etb_getbuf(jtag_callback_data_t arg)
{
- uint8_t *in = (uint8_t *)arg;
- *((uint32_t *)in) = buf_get_u32(in, 0, 32);
+ uint32_t *in = (uint32_t *)arg;
+ *in = buf_get_u32((uint8_t *)in, 0, 32);
}
Index: src/target/xscale.c
===================================================================
--- src/target/xscale.c (revision 2589)
+++ src/target/xscale.c (working copy)
@@ -295,8 +295,8 @@
static void xscale_getbuf(jtag_callback_data_t arg)
{
- uint8_t *in = (uint8_t *)arg;
- *((uint32_t *)in) = buf_get_u32(in, 0, 32);
+ uint32_t *in = (uint32_t *)arg;
+ *in = buf_get_u32((uint8_t *)in, 0, 32);
}
int xscale_receive(target_t *target, uint32_t *buffer, int num_words)
Index: src/target/arm_jtag.h
===================================================================
--- src/target/arm_jtag.h (revision 2589)
+++ src/target/arm_jtag.h (working copy)
@@ -60,14 +60,14 @@
/* use this as a static so we can inline it in -O3 and refer to it via a
pointer */
static __inline__ void arm7flip32(jtag_callback_data_t arg)
{
- uint8_t *in = (uint8_t *)arg;
- *((uint32_t *)in) = flip_u32(le_to_h_u32(in), 32);
+ uint32_t *in = (uint32_t *)arg;
+ *in = flip_u32(le_to_h_u32((uint8_t *)in), 32);
}
static __inline__ void arm_le_to_h_u32(jtag_callback_data_t arg)
{
- uint8_t *in = (uint8_t *)arg;
- *((uint32_t *)in) = le_to_h_u32(in);
+ uint32_t *in = (uint32_t *)arg;
+ *in = le_to_h_u32((uint8_t *)in);
}
Index: src/target/arm11.c
===================================================================
--- src/target/arm11.c (revision 2589)
+++ src/target/arm11.c (working copy)
@@ -1092,7 +1092,14 @@
*/
int arm11_read_memory(struct target_s *target, uint32_t address, uint32_t
size, uint32_t count, uint8_t *buffer)
{
- /** \todo TODO: check if buffer cast to uint32_t* and uint16_t* might
cause alignment problems */
+
+ /* gcc says, warning: cast increases required alignment of target type
*/
+ /* just make gcc happy */
+ union {
+ uint8_t *bytes;
+ uint32_t *words;
+ } buf;
+ buf.bytes = buffer;
FNC_INFO;
@@ -1128,7 +1135,7 @@
/* MCR p14,0,R1,c0,c5,0 */
arm11_run_instr_data_from_core(arm11, 0xEE001E15, &res,
1);
- *buffer++ = res;
+ *buf.bytes++ = res;
}
break;
@@ -1149,7 +1156,7 @@
arm11_run_instr_data_from_core(arm11,
0xEE001E15, &res, 1);
uint16_t svalue = res;
- memcpy(buffer + i * sizeof(uint16_t), &svalue,
sizeof(uint16_t));
+ memcpy(buf.bytes + i * sizeof(uint16_t),
&svalue, sizeof(uint16_t));
}
break;
@@ -1158,12 +1165,10 @@
case 4:
{
uint32_t instr = !arm11_config_memrw_no_increment ? 0xecb05e01
: 0xed905e00;
- /** \todo TODO: buffer cast to uint32_t* causes alignment
warnings */
- uint32_t *words = (uint32_t *)buffer;
/* LDC p14,c5,[R0],#4 */
/* LDC p14,c5,[R0] */
- arm11_run_instr_data_from_core(arm11, instr, words, count);
+ arm11_run_instr_data_from_core(arm11, instr, buf.words, count);
break;
}
}
@@ -1176,6 +1181,13 @@
int arm11_write_memory(struct target_s *target, uint32_t address, uint32_t
size, uint32_t count, uint8_t *buffer)
{
FNC_INFO;
+ /* gcc says, warning: cast increases required alignment of target type
*/
+ /* just make gcc happy */
+ union {
+ uint8_t *bytes;
+ uint32_t *words;
+ } buf;
+ buf.bytes = buffer;
if (target->state != TARGET_HALTED)
{
@@ -1201,7 +1213,7 @@
for (size_t i = 0; i < count; i++)
{
/* MRC p14,0,r1,c0,c5,0 */
- arm11_run_instr_data_to_core1(arm11,
0xee101e15, *buffer++);
+ arm11_run_instr_data_to_core1(arm11,
0xee101e15, *buf.bytes++);
/* strb r1, [r0], #1 */
/* strb r1, [r0] */
@@ -1219,7 +1231,7 @@
for (size_t i = 0; i < count; i++)
{
uint16_t value;
- memcpy(&value, buffer + i * sizeof(uint16_t),
sizeof(uint16_t));
+ memcpy(&value, buf.bytes + i *
sizeof(uint16_t), sizeof(uint16_t));
/* MRC p14,0,r1,c0,c5,0 */
arm11_run_instr_data_to_core1(arm11,
0xee101e15, value);
@@ -1236,20 +1248,17 @@
case 4: {
uint32_t instr = !arm11_config_memrw_no_increment ? 0xeca05e01
: 0xed805e00;
- /** \todo TODO: buffer cast to uint32_t* causes alignment
warnings */
- uint32_t *words = (uint32_t*)buffer;
-
if (!arm11_config_memwrite_burst)
{
/* STC p14,c5,[R0],#4 */
/* STC p14,c5,[R0]*/
- arm11_run_instr_data_to_core(arm11, instr, words,
count);
+ arm11_run_instr_data_to_core(arm11, instr, buf.words,
count);
}
else
{
/* STC p14,c5,[R0],#4 */
/* STC p14,c5,[R0]*/
- arm11_run_instr_data_to_core_noack(arm11, instr, words,
count);
+ arm11_run_instr_data_to_core_noack(arm11, instr,
buf.words, count);
}
break;
Index: src/flash/at91sam3.c
===================================================================
--- src/flash/at91sam3.c (revision 2589)
+++ src/flash/at91sam3.c (working copy)
@@ -1423,7 +1423,7 @@
// By using prototypes - we can detect what would
// be casting errors.
- return ((uint32_t *)(((char *)(pCfg)) + pList->struct_offset));
+ return ((uint32_t *)(((ulong)(pCfg)) + pList->struct_offset));
}
@@ -1477,7 +1477,7 @@
// calculate where this one go..
// it is "possibly" this register.
- pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) +
pReg->struct_offset));
+ pPossible = ((uint32_t *)(((ulong)(&(pChip->cfg))) +
pReg->struct_offset));
// well? Is it this register
if (pPossible == goes_here) {
Index: src/flash/mflash.c
===================================================================
--- src/flash/mflash.c (revision 2589)
+++ src/flash/mflash.c (working copy)
@@ -1124,7 +1124,7 @@
!= ERROR_OK)
return ret;
- mg_gen_ataid((mg_io_type_drv_info *)buff);
+ mg_gen_ataid((mg_io_type_drv_info *)(ulong)buff);
if ((ret = mg_mflash_do_write_sects(buff, 0, 1,
mg_vcmd_update_stgdrvinfo))
!= ERROR_OK)
@@ -1152,7 +1152,7 @@
buff[0] = mg_op_mode_snd; /* operation mode */
buff[1] = MG_UNLOCK_OTP_AREA;
buff[2] = 4; /* boot size */
- *((uint32_t *)(buff + 4)) = 0; /* XIP size */
+ *((uint32_t *)(ulong)(buff + 4)) = 0; /* XIP size */
if ((ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_update_xipinfo))
!= ERROR_OK)
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development