This is a Rust program to run mcumgr commands, used for example for Zephyr, for uploading firmware updates from a PC to an embedded device. It is a faster alternative to the mcumgr Go program.
Released builds for x86-64 Windows, Linux, and MacOS are here.
Example download:
wget https://github.com/vouch-opensource/mcumgr-client/releases/latest/download/mcumgr-client-linux-x86.zip
wget -O - https://github.com/vouch-opensource/mcumgr-client/releases/latest/download/mcumgr-client-linux-x86.zip.sha256sum | sha256sum --check
unzip mcumgr-client-linux-x86.zip
Install Rust:
Recommended is with rustup, because then it is easy to keep it up to date.
Change to this directory and build it:
cargo build --release
Without --release, it builds in debug mode.
mcumgr-client supports two transport methods:
Use -d or --device to specify a serial port:
mcumgr-client -d /dev/ttyACM0 <command>If not specified and only one serial device exists, it will be used automatically.
Use --host to connect over UDP (SMP over UDP):
mcumgr-client --host 192.0.2.1 <command>The default UDP port is 1337. Use --port to specify a different port:
mcumgr-client --host 192.0.2.1 --port 1338 <command>List images:
mcumgr-client -d /dev/ttyACM0 list
mcumgr-client --host 192.0.2.1 listUpload firmware:
mcumgr-client -d /dev/ttyACM0 upload firmware-image.bin
mcumgr-client --host 192.0.2.1 upload firmware-image.bin
# Upload to a specific slot
mcumgr-client -d /dev/ttyACM0 upload firmware-image.bin --slot 1Test/confirm an image:
# Mark image for test boot
mcumgr-client -d /dev/ttyACM0 test <image-hash>
# Confirm the current image
mcumgr-client -d /dev/ttyACM0 test <image-hash> --confirm trueErase an image slot:
mcumgr-client -d /dev/ttyACM0 erase
mcumgr-client -d /dev/ttyACM0 erase --slot 1Reset the device:
mcumgr-client -d /dev/ttyACM0 reset
mcumgr-client --host 192.0.2.1 resetEcho test:
mcumgr-client --host 192.0.2.1 echo "hello world"Get task/thread statistics:
mcumgr-client --host 192.0.2.1 taskstatGet MCUmgr parameters:
mcumgr-client --host 192.0.2.1 mcumgr-paramsGet OS/application information:
mcumgr-client --host 192.0.2.1 os-info
mcumgr-client --host 192.0.2.1 os-info --format a # all info
mcumgr-client --host 192.0.2.1 os-info --format s # kernel name
mcumgr-client --host 192.0.2.1 os-info --format v # kernel versionFormat specifiers: s=kernel name, n=node name, r=release, v=version, b=build date, m=machine, p=processor, i=platform, o=OS, a=all
Get bootloader information:
mcumgr-client --host 192.0.2.1 bootloader-info
mcumgr-client --host 192.0.2.1 bootloader-info --query modeGet hardware ID:
mcumgr-client --host 192.0.2.1 hwidNote: Requires custom os-info hook on the device supporting format h.
Execute shell commands on the device (requires CONFIG_MCUMGR_GRP_SHELL=y):
mcumgr-client --host 192.0.2.1 shell "kernel uptime"
mcumgr-client --host 192.0.2.1 shell "kernel version"
mcumgr-client --host 192.0.2.1 shell "device list"
mcumgr-client --host 192.0.2.1 shell "sensor get bmi088@0"Requires CONFIG_MCUMGR_GRP_FS=y on the device.
Download a file from the device:
mcumgr-client --host 192.0.2.1 fs-download /lfs/config.txt ./config.txtUpload a file to the device:
mcumgr-client --host 192.0.2.1 fs-upload ./config.txt /lfs/config.txtGet file size:
mcumgr-client --host 192.0.2.1 fs-stat /lfs/config.txtCalculate file hash:
mcumgr-client --host 192.0.2.1 fs-hash /lfs/config.txt
mcumgr-client --host 192.0.2.1 fs-hash /lfs/config.txt --hash-type crc32Requires CONFIG_MCUMGR_GRP_STAT=y on the device.
List available statistics groups:
mcumgr-client --host 192.0.2.1 stat-listRead statistics from a group:
mcumgr-client --host 192.0.2.1 stat-read mygroupRequires CONFIG_MCUMGR_GRP_SETTINGS=y on the device.
Read a setting:
mcumgr-client --host 192.0.2.1 settings-read my/setting/key
mcumgr-client --host 192.0.2.1 settings-read my/setting/key --max-size 256Write a setting (hex value):
mcumgr-client --host 192.0.2.1 settings-write my/setting/key 48656c6c6fDelete a setting:
mcumgr-client --host 192.0.2.1 settings-delete my/setting/keyCommit/load/save settings:
mcumgr-client --host 192.0.2.1 settings-commit
mcumgr-client --host 192.0.2.1 settings-load
mcumgr-client --host 192.0.2.1 settings-save| Option | Description | Default |
|---|---|---|
-d, --device |
Serial port device | Auto-detect |
--host |
UDP host (use instead of serial) | - |
--port |
UDP port | 1337 |
-v, --verbose |
Enable debug logging | false |
-t, --initial_timeout |
Initial timeout in seconds | 60 |
-u, --subsequent_timeout |
Subsequent timeout in ms | 200 |
--nb_retry |
Number of retries per packet | 4 |
-l, --linelength |
Maximum line length (serial) | 128 |
-m, --mtu |
Maximum request size | 512 |
-b, --baudrate |
Serial baud rate | 115200 |
To enable MCUmgr features on your Zephyr device, add the relevant Kconfig options:
CONFIG_MCUMGR=y
CONFIG_MCUMGR_TRANSPORT_UDP=y # For UDP transport
CONFIG_MCUMGR_TRANSPORT_UDP_IPV4=y
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_OS_INFO=y
CONFIG_MCUMGR_GRP_OS_TASKSTAT=y
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y
CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO=y
CONFIG_MCUMGR_GRP_IMG=y
CONFIG_SHELL=y
CONFIG_SHELL_BACKEND_DUMMY=y
CONFIG_BASE64=y
CONFIG_MCUMGR_GRP_SHELL=y
CONFIG_STATS=y
CONFIG_STATS_NAMES=y
CONFIG_MCUMGR_GRP_STAT=y
CONFIG_FILE_SYSTEM=y
CONFIG_MCUMGR_GRP_FS=y
CONFIG_SETTINGS=y
CONFIG_MCUMGR_GRP_SETTINGS=y
Flash firmware over serial with optimized settings:
mcumgr-client -m 4096 -l 8192 -d /dev/ttyACM0 upload firmware-image.binMonitor device over UDP:
mcumgr-client --host 192.0.2.1 os-info
mcumgr-client --host 192.0.2.1 taskstat
mcumgr-client --host 192.0.2.1 shell "kernel uptime"Auto-detect serial device:
You can omit the -d parameter. If only one device exists, it will be used automatically. If the filename contains slot1 or slot3, it flashes to that slot:
mcumgr-client upload firmware-slot1.bin
mcumgr-client upload ext-flash-slot3.binThere is a bug in the Zephyr CDC ACM driver. When building mcuboot for it, it needs this patch:
--- a/subsys/usb/device/class/cdc_acm.c
+++ b/subsys/usb/device/class/cdc_acm.c
@@ -70,7 +70,7 @@ LOG_MODULE_REGISTER(usb_cdc_acm, CONFIG_USB_CDC_ACM_LOG_LEVEL);
#define CDC_ACM_DEFAULT_BAUDRATE {sys_cpu_to_le32(115200), 0, 0, 8}
/* Size of the internal buffer used for storing received data */
-#define CDC_ACM_BUFFER_SIZE (CONFIG_CDC_ACM_BULK_EP_MPS)
+#define CDC_ACM_BUFFER_SIZE 512
/* Serial state notification timeout */
#define CDC_CONTROL_SERIAL_STATE_TIMEOUT_US 100000
With the default settings for the line length and MTU, it needs about 3 minutes to flash 917,504 bytes (5 times faster than the original mcumgr program). With these settings for mcuboot:
CONFIG_BOOT_MAX_LINE_INPUT_LEN=8192
CONFIG_BOOT_SERIAL_MAX_RECEIVE_SIZE=4096
The line length and MTU size can be increased, like this for the example:
./target/release/mcumgr-client -m 4096 -l 8192 -d /dev/ttyACM0 upload firmware-image.bin
This needs 17 seconds for the same file (instead of 1:48 minutes with the default buffer sizes), which is more than 10 times faster than the original mcumgr Go program.
To make it easier to use the program from Python, there is a wrapper for it here.