88#include <zephyr/sys/printk.h>
99#include <zephyr/ztest.h>
1010
11- uint32_t var_sram2_data = 10U ;
12- uint32_t var_sram2_bss ;
11+ /*
12+ * These values will typically be placed in the appropriate sections, but may be moved around
13+ * by the compiler; for instance var_sram2_data might end up in .rodata if the compiler can prove
14+ * that it's never modified. To prevent that, we explicitly specify sections.
15+ */
16+ __in_section (data , sram2 , var ) uint32_t var_sram2_data = 10U ;
17+ __in_section (bss , sram2 , var ) uint32_t var_sram2_bss ;
1318K_SEM_DEFINE (test , 0 , 1 );
14- const uint32_t var_sram2_rodata = 100U ;
19+ __in_section ( rodata , sram2 , var ) const uint32_t var_sram2_rodata = 100U ;
1520
1621__in_section (custom_section , static , var ) uint32_t var_custom_data = 1U ;
1722
1823extern void function_in_sram (int32_t value );
1924void function_in_custom_section (void );
2025
26+ #define HAS_SRAM2_DATA_SECTION (CONFIG_ARM)
27+
2128ZTEST (code_relocation , test_function_in_sram2 )
2229{
23- extern uint32_t __sram2_text_start ;
24- extern uint32_t __sram2_text_end ;
25- extern uint32_t __sram2_data_start ;
26- extern uint32_t __sram2_data_end ;
27- extern uint32_t __sram2_bss_start ;
28- extern uint32_t __sram2_bss_end ;
29- extern uint32_t __sram2_rodata_start ;
30- extern uint32_t __sram2_rodata_end ;
31- extern uint32_t __custom_section_start ;
32- extern uint32_t __custom_section_end ;
30+ extern uintptr_t __sram2_text_start ;
31+ extern uintptr_t __sram2_text_end ;
32+ extern uintptr_t __sram2_data_start ;
33+ extern uintptr_t __sram2_data_end ;
34+ extern uintptr_t __sram2_bss_start ;
35+ extern uintptr_t __sram2_bss_end ;
36+ extern uintptr_t __sram2_rodata_start ;
37+ extern uintptr_t __sram2_rodata_end ;
38+ extern uintptr_t __custom_section_start ;
39+ extern uintptr_t __custom_section_end ;
3340
3441 /* Print values from sram2 */
3542 printk ("Address of var_sram2_data %p\n" , & var_sram2_data );
3643 printk ("Address of k_sem_give %p\n" , & k_sem_give );
3744 printk ("Address of var_sram2_rodata %p\n" , & var_sram2_rodata );
3845 printk ("Address of var_sram2_bss %p\n\n" , & var_sram2_bss );
3946
40- zassert_between_inclusive ((uint32_t )& var_sram2_data ,
41- (uint32_t )& __sram2_data_start ,
42- (uint32_t )& __sram2_data_end ,
47+ zassert_between_inclusive ((uintptr_t )& var_sram2_data ,
48+ (uintptr_t )& __sram2_data_start ,
49+ (uintptr_t )& __sram2_data_end ,
4350 "var_sram2_data not in sram2 region" );
44- zassert_between_inclusive ((uint32_t )& k_sem_give ,
45- (uint32_t )& __sram2_text_start ,
46- (uint32_t )& __sram2_text_end ,
51+ zassert_between_inclusive ((uintptr_t )& k_sem_give ,
52+ (uintptr_t )& __sram2_text_start ,
53+ (uintptr_t )& __sram2_text_end ,
4754 "k_sem_give not in sram_text region" );
48- zassert_between_inclusive ((uint32_t )& var_sram2_rodata ,
49- (uint32_t )& __sram2_rodata_start ,
50- (uint32_t )& __sram2_rodata_end ,
55+ zassert_between_inclusive ((uintptr_t )& var_sram2_rodata ,
56+ (uintptr_t )& __sram2_rodata_start ,
57+ (uintptr_t )& __sram2_rodata_end ,
5158 "var_sram2_rodata not in sram2_rodata region" );
52- zassert_between_inclusive ((uint32_t )& var_sram2_bss ,
53- (uint32_t )& __sram2_bss_start ,
54- (uint32_t )& __sram2_bss_end ,
59+ zassert_between_inclusive ((uintptr_t )& var_sram2_bss ,
60+ (uintptr_t )& __sram2_bss_start ,
61+ (uintptr_t )& __sram2_bss_end ,
5562 "var_sram2_bss not in sram2_bss region" );
5663
5764 /* Print values from sram */
@@ -62,13 +69,13 @@ ZTEST(code_relocation, test_function_in_sram2)
6269 & function_in_custom_section );
6370 printk ("Address of custom_section data placed using attributes %p\n\n" ,
6471 & var_custom_data );
65- zassert_between_inclusive ((uint32_t )& function_in_custom_section ,
66- (uint32_t )& __custom_section_start ,
67- (uint32_t )& __custom_section_end ,
72+ zassert_between_inclusive ((uintptr_t )& function_in_custom_section ,
73+ (uintptr_t )& __custom_section_start ,
74+ (uintptr_t )& __custom_section_end ,
6875 "function_in_custom_section not in custom_section region" );
69- zassert_between_inclusive ((uint32_t )& var_custom_data ,
70- (uint32_t )& __custom_section_start ,
71- (uint32_t )& __custom_section_end ,
76+ zassert_between_inclusive ((uintptr_t )& var_custom_data ,
77+ (uintptr_t )& __custom_section_start ,
78+ (uintptr_t )& __custom_section_end ,
7279 "var_custom_data not in custom_section region" );
7380
7481 k_sem_give (& test );
0 commit comments