Skip to content

Commit 5c4d184

Browse files
galakcarlescufi
authored andcommitted
emul: Use STRUCT_SECTION macros for emul devices
Clean up emulator code to utilize macros for handling sections. Signed-off-by: Kumar Gala <kumar.gala@intel.com>
1 parent f659740 commit 5c4d184

File tree

4 files changed

+4
-19
lines changed

4 files changed

+4
-19
lines changed

cmake/linker_script/common/common-rom.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ endif()
153153
zephyr_iterable_section(NAME k_p4wq_initparam KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
154154

155155
if(CONFIG_EMUL)
156-
zephyr_linker_section(NAME emulators_section GROUP RODATA_REGION ${XIP_ALIGN_WITH_INPUT})
157-
zephyr_linker_section_configure(SECTION emulators_section INPUT ".emulators" KEEP SORT NAME)
156+
zephyr_iterable_section(NAME emul KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
158157
endif()
159158

160159
if(CONFIG_DNS_SD)

include/zephyr/drivers/emul.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ struct emul {
8585
const void *backend_api;
8686
};
8787

88-
/**
89-
* Emulators are aggregated into an array at link time, from which emulating
90-
* devices can find the emulators that they are to use.
91-
*/
92-
extern const struct emul __emul_list_start[];
93-
extern const struct emul __emul_list_end[];
94-
9588
/**
9689
* @brief Use the devicetree node identifier as a unique name.
9790
*
@@ -130,7 +123,7 @@ extern const struct emul __emul_list_end[];
130123
.api = bus_api, \
131124
.Z_EMUL_BUS(node_id, addr, chipsel, chipsel) = DT_REG_ADDR(node_id), \
132125
}; \
133-
const struct emul EMUL_DT_NAME_GET(node_id) __attribute__((__section__(".emulators"))) \
126+
const STRUCT_SECTION_ITERABLE(emul, EMUL_DT_NAME_GET(node_id)) \
134127
__used = { \
135128
.init = (init_fn), \
136129
.dev = DEVICE_DT_GET(node_id), \

include/zephyr/linker/common-rom/common-rom-misc.ld

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
#endif
2222

2323
#if defined(CONFIG_EMUL)
24-
SECTION_DATA_PROLOGUE(emulators_section,,)
25-
{
26-
__emul_list_start = .;
27-
KEEP(*(SORT_BY_NAME(".emulators")));
28-
__emul_list_end = .;
29-
} GROUP_LINK_IN(ROMABLE_REGION)
24+
ITERABLE_SECTION_ROM(emul, 4)
3025
#endif /* CONFIG_EMUL */
3126

3227
SECTION_DATA_PROLOGUE(symbol_to_keep,,)

subsys/emul/emul.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ LOG_MODULE_REGISTER(emul);
1515

1616
const struct emul *emul_get_binding(const char *name)
1717
{
18-
const struct emul *emul_it;
19-
20-
for (emul_it = __emul_list_start; emul_it < __emul_list_end; emul_it++) {
18+
STRUCT_SECTION_FOREACH(emul, emul_it) {
2119
if (strcmp(emul_it->dev->name, name) == 0) {
2220
return emul_it;
2321
}

0 commit comments

Comments
 (0)