diff --git a/include/linker/common-ram.ld b/include/linker/common-ram.ld index cf6ce03836d..2a7bef67730 100644 --- a/include/linker/common-ram.ld +++ b/include/linker/common-ram.ld @@ -173,6 +173,16 @@ __net_if_end = .; } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#if defined(CONFIG_NET_SHELL) + SECTION_DATA_PROLOGUE(net_stack, (OPTIONAL),) + { + __net_stack_start = .; + *(".net_stack.*") + KEEP(*(SORT_BY_NAME(".net_stack*"))) + __net_stack_end = .; + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#endif /* CONFIG_NET_SHELL */ + SECTION_DATA_PROLOGUE(net_l2_data, (OPTIONAL),) { __net_l2_data_start = .; diff --git a/include/net/yaip/net_core.h b/include/net/yaip/net_core.h index 34d2cac4c24..afd2bfc3287 100644 --- a/include/net/yaip/net_core.h +++ b/include/net/yaip/net_core.h @@ -95,6 +95,47 @@ int net_recv_data(struct net_if *iface, struct net_buf *buf); */ int net_send_data(struct net_buf *buf); +struct net_stack_info { + unsigned char *stack; + const char *pretty_name; + const char *name; + size_t orig_size; + size_t size; +}; + +#if defined(CONFIG_NET_SHELL) +#define NET_STACK_GET_NAME(name, sfx) (__net_stack_##name##_##sfx) + +#define NET_STACK_INFO_ADDR(_pretty, _name, _orig, _size, _addr, sfx) \ + static struct net_stack_info \ + (NET_STACK_GET_NAME(_name, sfx)) __used \ + __attribute__((__section__(".net_stack.data"))) = { \ + .stack = _addr, \ + .size = _size, \ + .orig_size = _orig, \ + .name = #_name, \ + .pretty_name = _pretty, \ + } + +#define NET_STACK_INFO(_pretty_name, _name, _orig, _size) \ + NET_STACK_INFO_ADDR(_pretty_name, _name, _orig, _size, _name, 0) + +#define NET_STACK_DEFINE(pretty_name, name, orig, size) \ + static unsigned char __noinit __stack name[size]; \ + NET_STACK_INFO(pretty_name, name, orig, size) + +#else /* CONFIG_NET_SHELL */ + +#define NET_STACK_INFO(...) +#define NET_STACK_INFO_ADDR(...) + +#define NET_STACK_DEFINE(pretty_name, name, orig, size) \ + static unsigned char __noinit __stack name[size] + +#endif /* CONFIG_NET_SHELL */ + +#define NET_STACK_DEFINE_EMBEDDED(name, size) unsigned char name[size] + /** @cond ignore */ #if defined(CONFIG_INIT_STACKS) #include diff --git a/include/net/yaip/net_if.h b/include/net/yaip/net_if.h index 0dbd7a59beb..7624e5de6cd 100644 --- a/include/net/yaip/net_if.h +++ b/include/net/yaip/net_if.h @@ -186,7 +186,7 @@ struct net_if { #ifndef CONFIG_NET_TX_STACK_SIZE #define CONFIG_NET_TX_STACK_SIZE 1024 #endif - char tx_stack[CONFIG_NET_TX_STACK_SIZE]; + NET_STACK_DEFINE_EMBEDDED(tx_stack, CONFIG_NET_TX_STACK_SIZE); #if defined(CONFIG_NET_IPV6) #define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT @@ -1086,7 +1086,14 @@ struct net_if_api { .l2 = &(NET_L2_GET_NAME(_l2)), \ .l2_data = &(NET_L2_GET_DATA(dev_name, sfx)), \ .mtu = _mtu, \ - } + }; \ + NET_STACK_INFO_ADDR("TX", \ + dev_name, \ + CONFIG_NET_TX_STACK_SIZE, \ + CONFIG_NET_TX_STACK_SIZE, \ + NET_IF_GET(dev_name, sfx)->tx_stack, \ + sfx) + /* Network device initialization macros */ diff --git a/net/yaip/net_core.c b/net/yaip/net_core.c index c5a0d56dad5..da6c4d01121 100644 --- a/net/yaip/net_core.c +++ b/net/yaip/net_core.c @@ -62,7 +62,9 @@ #if !defined(CONFIG_NET_RX_STACK_SIZE) #define CONFIG_NET_RX_STACK_SIZE 1024 #endif -static char __noinit __stack rx_stack[CONFIG_NET_RX_STACK_SIZE]; +NET_STACK_DEFINE("RX", rx_stack, CONFIG_NET_RX_STACK_SIZE, + CONFIG_NET_RX_STACK_SIZE); + static struct k_fifo rx_queue; static k_tid_t rx_tid; diff --git a/scripts/sanitycheck b/scripts/sanitycheck index 78419e90a8c..b47c8cb001f 100755 --- a/scripts/sanitycheck +++ b/scripts/sanitycheck @@ -464,7 +464,7 @@ class SizeCalculator: "_k_sem_area", "_k_mutex_area", "_k_alert_area", "_k_fifo_area", "_k_lifo_area", "_k_stack_area", "_k_msgq_area", "_k_mbox_area", "_k_pipe_area", - "net_if", "net_l2_data"] + "net_if", "net_stack", "net_l2_data"] # These get copied into RAM only on non-XIP ro_sections = ["text", "ctors", "init_array", "reset", "rodata", "devconfig", "net_l2"]