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.

(cherry picked from commit f9809a0)

Original-Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
GitOrigin-RevId: f9809a0
Change-Id: I34e9b2cdd378a94b9c79a400d17e19fc205c04b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4995672
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
besmarsh authored and Chromeos LUCI committed Nov 2, 2023
1 parent b8bddf1 commit 5f88cf2
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 @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5f88cf2

Please sign in to comment.