diff --git a/include/device.h b/include/device.h index 9d862caac28..3a4b1699faa 100644 --- a/include/device.h +++ b/include/device.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -835,7 +836,8 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts"); * is associated with the device */ #define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \ - static struct device_state Z_DEVICE_STATE_NAME(dev_name) = { \ + static struct device_state Z_DEVICE_STATE_NAME(dev_name) \ + __attribute__((__section__(".z_devstate"))) = { \ .pm = { \ .flags = ATOMIC_INIT(COND_CODE_1( \ DT_NODE_EXISTS(node_id), \ @@ -851,6 +853,7 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts"); .pm = &Z_DEVICE_STATE_NAME(dev_name).pm, #else #define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \ + __pinned_bss \ static struct device_state Z_DEVICE_STATE_NAME(dev_name); #define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) #endif diff --git a/include/linker/common-ram.ld b/include/linker/common-ram.ld index 6148f518d76..4cec4cecca4 100644 --- a/include/linker/common-ram.ld +++ b/include/linker/common-ram.ld @@ -23,6 +23,15 @@ } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) #endif + SECTION_DATA_PROLOGUE(device_states,,) + { + /* Device states used by the device objects. */ + __device_states_start = .; + KEEP(*(".z_devstate")); + KEEP(*(".z_devstate.*")); + __device_states_end = .; + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + #if CONFIG_PM_DEVICE SECTION_DATA_PROLOGUE(pm_device_slots, (NOLOAD),) {