Skip to content

Commit

Permalink
subsys/mgmt/mcumgr: Reduce unnecessary ROM usage
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
besmarsh committed Oct 24, 2023
1 parent b510073 commit fa47eeb
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions subsys/mgmt/mcumgr/transport/src/smp_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,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;

Expand Down Expand Up @@ -379,6 +366,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;
Expand All @@ -398,6 +388,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;
Expand Down

0 comments on commit fa47eeb

Please sign in to comment.