Tool/software:
Hello,
An error is reported when attempting to include pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h in a source file compiled for A72.
Here is the error:
[GCC] Compiling C99 vx_vpac_viss_host.c In file included from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/csl_dru.h:48, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/udma.h:91, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/vhwa/vhwa_abstraction_layer.h:82, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/vhwa/include/vhwa_common.h:62, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/imaging/kernels/uguzzi_node/include/uguzzi/uguzzi_isp_out.h:41, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/imaging/kernels/uguzzi_node/include/uguzzi/uguzzi_isp_settings.h:12, from /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/imaging/kernels/hwa/host/vx_vpac_viss_host.c:72: /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h: In function ‘CSL_druChSubmitTr’: /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h:533:5: error: converting a packed ‘CSL_UdmapTR’ {aka ‘const struct CSL_UdmapTR_t’} pointer (alignment 1) to a ‘uint32_t’ {aka ‘const unsigned int’} pointer (alignment 4) may result in an unaligned pointer value [-Werror=address-of-packed-member] 533 | const uint32_t *trWord32 = (const uint32_t *) tr; | ^~~~~ cc1: all warnings being treated as errors make[2]: *** [/home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/sdk_builder/concerto/finale.mak:316: /home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/imaging/out/J784S4/A72/LINUX/release/module/kernels.hwa.host/vx_vpac_viss_host.o] Error 1 make[2]: Leaving directory '/home/users/redacted/ti-processor-sdk-rtos-j784s4-evm-10_01_00_04/imaging'
As you can see the header is indirectly included to imaging/kernels/hwa/host/vx_vpac_viss_host.c by vhwa_common.h. However if you look at the implementation of CSL_druChSubmitTr you will notice that there are actually 2 pointer to pointer conversions and both are violating the "Strict aliasing rule" by performing type punning which is undefined behavior by the C standard. Here are the two type punnings:
const CSL_DRU_CHCORERegs_CHCORE_CORE *pCoreRegs = &pRegs->CHCORE[chId].CORE[coreId]; const uint32_t *trWord32 = (const uint32_t *) tr; volatile uint32_t *submitWord32 = (volatile uint32_t *) pCoreRegs;
Attached to this message you will find a patch file that fixes the error above and one of the type punning conversions. For the other I'm not sure how to fix it.
Board and PSDK version are included in the error log above.
Thank you for your time!
Best regards,
Hristo
diff --git a/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h b/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h index 6c90f49a..dcf7f2ad 100755 --- a/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h +++ b/pdk_j784s4_10_01_00_25/packages/ti/drv/udma/src/dru/V0/V0_2/csl_dru.h @@ -53,6 +53,7 @@ /* Include Files */ /* ========================================================================== */ +#include <string.h> #include <stdint.h> #include <ti/drv/udma/src/dru/cslr_dru.h> #include <ti/drv/udma/src/udmap/csl_udmap.h> @@ -530,18 +531,20 @@ static inline void CSL_druChSubmitTr(const CSL_DRU_t *pRegs, { const CSL_DRU_CHCORERegs_CHCORE_CORE *pCoreRegs = &pRegs->CHCORE[chId].CORE[coreId]; - const uint32_t *trWord32 = (const uint32_t *) tr; + const unsigned char *trWord32 = (const unsigned char *) tr; volatile uint32_t *submitWord32 = (volatile uint32_t *) pCoreRegs; - uint32_t numWords32, cnt; + uint32_t numWords32, cnt, trWord32_proper; /* Write all wrds expect first */ numWords32 = (sizeof(CSL_UdmapTR) / sizeof(uint32_t)); for(cnt = 1U; cnt < numWords32; cnt++) { - CSL_REG32_WR(submitWord32+cnt, trWord32[cnt]); + memcpy(&trWord32_proper, &trWord32[cnt*sizeof(uint32_t)], sizeof(uint32_t)); + CSL_REG32_WR(submitWord32+cnt, trWord32_proper); } + memcpy(&trWord32_proper, &trWord32[0], sizeof(uint32_t)); /* This triggers the actual TR submission */ - CSL_REG32_WR(submitWord32, trWord32[0]); + CSL_REG32_WR(submitWord32, trWord32_proper); return; }