AylaAsia-Derek Zhu
AylaAsia-Derek Zhu

Reputation: 13

how can i read some struct param in attribute section "test"?

test.h

struct test_desc {
  const char *name;
}
#define PFM_TEST(a,name) struct test_desc a \
__attribute__((section("test"))) = {name}

test.c

PFM_TEST(name1,abc);
PFM_TEST(name2,dec);

main.c

#pragma section = "test"
void main(void)
{
  struct struct test_desc *start,*stop;
  start = (struct test_desc *)__section_begin("test");
  stop = (struct test_desc *)__section_end("test");
  printf("start->name = %s\n",start->name);
}

test.icf

define symbol __ICFEDIT_region_TEST_start__ = (0x10080000);
define symbol __ICFEDIT_region_TEST_end__ = (0x100DFFFF);
define region TEST_region = mem:[from __ICFEDIT_region_TEST_start__ to __ICFEDIT_region_TEST_end__];
keep { section test};
place at start of TEST_region {readwrite,section test};

actual result

hard fault patch...

expect result

start->name = abc

i can read the test section start address and stop address,i think i could cast them as test_desc type. but the actual result is error. i think maybe i can't put the section into the .data,how can i do that?

Upvotes: 0

Views: 73

Answers (2)

AylaAsia-Derek Zhu
AylaAsia-Derek Zhu

Reputation: 13

Finally, i set the section next to the .data section.like this

define block .ram_image2.data with fixed order{ section .data*,
                        section DATA,
                        section test*,
                        section .iar.init_table,
                        section __DLIB_PERTHREAD,
                                                block CPP_INIT,
                        };

expect result i can get,and the param is not the const type.

Upvotes: 1

AylaAsia-Derek Zhu
AylaAsia-Derek Zhu

Reputation: 13

modify before

#define PFM_TEST(a,name) struct test_desc a \
__attribute__((section("test"))) = {name}

later

#define PFM_TEST(a,name) const struct test_desc a \
__attribute__((section("test"))) = {name}

it could get my expect result,but i don't want the struct to be const. I think i should take the section into the right memory like .data.but i don't know how can i do that.

Upvotes: 0

Related Questions