Skip to content

Commit 24bb6b9

Browse files
committed
libc: Add shell support
This is useful as a placeholder for all commands common to applications. For now we start with malloc stats, useful in debugging HEAP issues. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 72190c0 commit 24bb6b9

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

doc/releases/release-notes-3.5.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,58 @@ Devicetree
232232
Libraries / Subsystems
233233
**********************
234234

235+
* Management
236+
237+
* Introduced MCUmgr client support with handlers for img_mgmt and os_mgmt.
238+
239+
* Added response checking to MCUmgr's :c:enumerator:`MGMT_EVT_OP_CMD_RECV`
240+
notification callback to allow applications to reject MCUmgr commands.
241+
242+
* MCUmgr SMP version 2 error translation (to legacy MCUmgr error code) is now
243+
supported in function handlers by setting ``mg_translate_error`` of
244+
:c:struct:`mgmt_group` when registering a transport. See
245+
:c:type:`smp_translate_error_fn` for function details.
246+
* shell
247+
248+
* Added an application shell module with helpers common to all applications.
249+
250+
* Fixed an issue with MCUmgr img_mgmt group whereby the size of the upload in
251+
the initial packet was not checked.
252+
253+
* Fixed an issue with MCUmgr fs_mgmt group whereby some status codes were not
254+
checked properly, this meant that the error returned might not be the
255+
correct error, but would only occur in situations where an error was
256+
already present.
257+
258+
* Fixed an issue whereby the SMP response function did not check to see if
259+
the initial zcbor map was created successfully.
260+
261+
* Fixes an issue with MCUmgr shell_mgmt group whereby the length of a
262+
received command was not properly checked.
263+
264+
* Added optional mutex locking support to MCUmgr img_mgmt group, which can
265+
be enabled with :kconfig:option:`CONFIG_MCUMGR_GRP_IMG_MUTEX`.
266+
267+
* Added MCUmgr settings management group, which allows for manipulation of
268+
zephyr settings from a remote device, see :ref:`mcumgr_smp_group_3` for
269+
details.
270+
271+
* Added :kconfig:option:`CONFIG_MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY`
272+
and :kconfig:option:`CONFIG_MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_ANY`
273+
that allow to control whether MCUmgr client will be allowed to confirm
274+
non-active images.
275+
276+
* Added :kconfig:option:`CONFIG_MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING` that allows
277+
to erase slots pending for next boot, that are not revert slots.
278+
279+
* File systems
280+
281+
* Added support for ext2 file system.
282+
* Added support of mounting littlefs on the block device from the shell/fs.
283+
* Added alignment parameter to FS_LITTLEFS_DECLARE_CUSTOM_CONFIG macro, it can speed up read/write
284+
operation for SDMMC devices in case when we align buffers on CONFIG_SDHC_BUFFER_ALIGNMENT,
285+
because we can avoid extra copy of data from card bffer to read/prog buffer.
286+
235287
HALs
236288
****
237289

subsys/shell/modules/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ zephyr_sources_ifdef(
1616
CONFIG_DEVMEM_SHELL
1717
devmem_service.c
1818
)
19+
zephyr_sources_ifdef(
20+
CONFIG_APP_SHELL
21+
app_service.c
22+
)

subsys/shell/modules/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ config DEVMEM_SHELL
4545
select GETOPT
4646
help
4747
This shell command provides read/write access to physical memory.
48+
49+
config APP_SHELL
50+
bool "application shell (common to all applications)"
51+
default y if !SHELL_MINIMAL
52+
help
53+
This shell module provides access to common helpers.

subsys/shell/modules/app_service.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/sys/printk.h>
8+
#include <zephyr/shell/shell.h>
9+
#include <zephyr/init.h>
10+
#include <zephyr/kernel.h>
11+
#include <kernel_internal.h>
12+
#if defined(CONFIG_LOG_RUNTIME_FILTERING)
13+
#include <zephyr/logging/log_ctrl.h>
14+
#endif
15+
16+
#include <malloc.h>
17+
18+
static int cmd_app_heap(const struct shell *sh, size_t argc, char **argv)
19+
{
20+
#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 33)
21+
/* mallinfo() was deprecated in glibc 2.33 and removed in 2.34. */
22+
struct mallinfo mi = mallinfo();
23+
#else
24+
struct mallinfo2 mi = mallinfo2();
25+
#endif /* __GLIBC__ < 2 && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 33) */
26+
27+
ARG_UNUSED(argc);
28+
ARG_UNUSED(argv);
29+
30+
shell_print(sh, "Heap size: %d bytes", mi.arena);
31+
shell_print(sh, " used: %d bytes", mi.uordblks);
32+
shell_print(sh, " free: %d bytes", mi.fordblks);
33+
shell_print(sh, " max used: %d bytes", mi.usmblks);
34+
shell_print(sh, " free fastbin: %d bytes", mi.fsmblks);
35+
36+
return 0;
37+
}
38+
39+
SHELL_STATIC_SUBCMD_SET_CREATE(sub_app,
40+
SHELL_CMD(heap, NULL, "app heap", cmd_app_heap),
41+
SHELL_SUBCMD_SET_END /* Array terminated. */
42+
);
43+
44+
SHELL_CMD_REGISTER(app, &sub_app, "application commands", NULL);

0 commit comments

Comments
 (0)