subsys/mgmt/mcumgr: Reduce unnecessary ROM usage

mcumgr's SMP UDP transport was unnecessarily using a potentially large
amount of ROM space due to static initialising fields in a
config struct that also contains buffers/stacks.

This has been changed to instead initialise fields in the start
function, reducing ROM usage by ~5K in the default configuration
with IPv4 and IPv6 enabled.

Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
This commit is contained in:
Ben Marsh 2023-10-24 09:39:13 +01:00 committed by Fabio Baltieri
parent 385ceb7145
commit f9809a0a72

View file

@ -81,20 +81,7 @@ struct configs {
#endif
};
static struct configs configs = {
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
.ipv4 = {
.proto = PROTOCOL_IPV4,
.sock = -1,
},
#endif
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6
.ipv6 = {
.proto = PROTOCOL_IPV6,
.sock = -1,
},
#endif
};
static struct configs configs;
static struct net_mgmt_event_callback smp_udp_mgmt_cb;
@ -382,6 +369,9 @@ static void smp_udp_start(void)
int rc;
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
configs.ipv4.proto = PROTOCOL_IPV4;
configs.ipv4.sock = -1;
k_sem_init(&configs.ipv4.network_ready_sem, 0, 1);
configs.ipv4.smp_transport.functions.output = smp_udp4_tx;
configs.ipv4.smp_transport.functions.get_mtu = smp_udp_get_mtu;
@ -401,6 +391,9 @@ static void smp_udp_start(void)
#endif
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6
configs.ipv6.proto = PROTOCOL_IPV6;
configs.ipv6.sock = -1;
k_sem_init(&configs.ipv6.network_ready_sem, 0, 1);
configs.ipv6.smp_transport.functions.output = smp_udp6_tx;
configs.ipv6.smp_transport.functions.get_mtu = smp_udp_get_mtu;