README.md
1# smp_svr
2
3This sample application implements a simple SMP server with the following
4transports:
5 * Shell
6 * Bluetooth
7
8`smp_svr` enables support for the following command groups:
9 * fs_mgmt
10 * img_mgmt
11 * log_mgmt (Mynewt only)
12 * os_mgmt
13 * stat_mgmt
14
15## Mynewt
16
17The Mynewt port of `smp_svr` is a regular Mynewt app. The below example uses the nRF52dk as the BSP, so you may need to adjust accordingly if you are using different hardware.
18
190. Create a Mynewt project and upload the Apache mynewt boot loader to your
20board as described here: http://mynewt.apache.org/latest/os/tutorials/nRF52/
21
221. Add the mcumgr repo to your `project.yml` file:
23
24```
25repository.mynewt-mcumgr:
26 type: git
27 vers: 0-latest
28 url: 'git@github.com:apache/mynewt-mcumgr.git'
29```
30
312. Create a target that ties the `smp_svr` app to your BSP of choice (nRF52dk in this example):
32
33```
34$ newt target create smp_svr-nrf52dk
35$ newt target set smp_svr-nrf52dk app=@mynewt-mcumgr/samples/smp_svr/apache \
36 bsp=@apache-mynewt-core/hw/bsp/nrf52dk \
37 build_profile=debug
38```
39
403. Build, upload, and run the application on your board:
41
42```
43$ newt run smp_svr-nrf52dk
44```
45
46## Zephyr
47
48The Zephyr port of `smp_svr` is configured to run on an nRF52 MCU. The
49application should build and run for other platforms without modification, but
50the file system management commands will not work. To enable file system
51management for a different platform, adjust the `CONFIG_FS_NFFS_FLASH_DEV_NAME`
52setting in `prj.conf` accordingly.
53
54In addition, the MCUboot boot loader (https://github.com/runtimeco/mcuboot) is
55required for img_mgmt to function properly.
56
57### Building
58
59The below steps describe how to build and run the `smp_svr` sample app in
60Zephyr. Where examples are given, they assume the following setup:
61
62* BSP: Nordic nRF52dk
63* MCU: PCA10040
64
65If you would like to use a more constrained platform, such as the nRF51, you
66should use the `prj.conf.tiny` configuration file rather than the default
67`prj.conf`.
68
69#### Step 1: Configure environment
70
71Define the `BOARD`, `ZEPHYR_TOOLCHAIN_VARIANT`, and any other environment
72variables required by your setup. For our example, we use the following:
73
74```
75export ZEPHYR_TOOLCHAIN_VARIANT=gccarmemb
76export BOARD=nrf52_pca10040
77export GCCARMEMB_TOOLCHAIN_PATH=/usr/local/Caskroom/gcc-arm-embedded/6-2017-q2-update/gcc-arm-none-eabi-6-2017-q2-update
78```
79
80#### Step 2: Build MCUboot
81
82Build MCUboot by following the instructions in its `docs/readme-zephyr.md`
83file.
84
85#### Step 3: Upload MCUboot
86
87Upload the resulting `zephyr.bin` file to address 0 of your board. This can be
88done in gdb as follows:
89
90```
91restore <path-to-mcuboot-zephyr.bin> binary 0
92```
93
94#### Step 4: Build smp_svr
95
96The Zephyr port of `smp_svr` can be built using the usual procedure:
97
98```
99$ cd samples/smp_svr/zephyr
100$ mkdir build && cd build
101$ cmake ..
102$ make
103```
104
105#### Step 5: Create an MCUboot-compatible image
106
107Using MCUboot's `imgtool.py` script, convert the `zephyr.bin` file from step 4
108into an image file. In the below example, the MCUboot repo is located at `~/repos/mcuboot`.
109
110```
111~/repos/mcuboot/scripts/imgtool.py sign \
112 --header-size 0x200 \
113 --align 8 \
114 --version 1.0 \
115 --included-header \
116 --key ~/repos/mcuboot/root-rsa-2048.pem \
117 <path-to-smp_svr-zephyr.bin> signed.img
118```
119
120The above command creates an image file called `signed.img` in the current
121directory.
122
123#### Step 6: Upload the smp_svr image
124
125Upload the `signed.img` file from step 5 to image slot 0 of your board. The location of image slot 0 varies by BSP. For the nRF52dk, slot 0 is located at address 0xc000.
126
127The following gdb command uploads the image to 0xc000:
128```
129restore <path-to-signed.img> binary 0xc000
130```
131
132#### Step 7: Run it!
133
134The `smp_svr` app is ready to run. Just reset your board and test the app with the mcumgr CLI tool:
135
136```
137$ mcumgr --conntype ble --connstring peer_name=Zephyr echo hello
138hello
139```
140