Skip to content

Commit 1bba489

Browse files
committed
Initial commit
0 parents  commit 1bba489

8 files changed

Lines changed: 384 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Copyright (c) 2020, Lukasz Duda.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# 1. Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# 2. Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# 3. Neither the name of the copyright holder nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
# POSSIBILITY OF SUCH DAMAGE.
27+
#
28+
29+
name: rpi-nrfutil
30+
31+
on: [push, pull_request]
32+
33+
jobs:
34+
35+
cancel-previous-runs:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: rokroskar/workflow-run-cleanup-action@master
39+
env:
40+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
41+
if: "github.ref != 'refs/heads/master'"
42+
43+
rpi-nrfutil-check:
44+
runs-on: ubuntu-latest
45+
env:
46+
IMAGE_URL: http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-06-24/2019-06-20-raspbian-buster-lite.zip
47+
NRFUTIL_URL: https://github.com/NordicSemiconductor/pc-nrfutil/archive/v6.1.zip
48+
steps:
49+
- uses: actions/checkout@v2
50+
with:
51+
submodules: true
52+
- name: Bootstrap
53+
run: script/bootstrap
54+
- name: Build
55+
run: script/build
56+
- name: Upload artifact
57+
uses: actions/upload-artifact@v2
58+
with:
59+
name: rpi-nrfutil
60+
path: output/nrfutil
61+
if-no-files-found: error

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*img
2+
output/*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/docker-rpi-emu"]
2+
path = third_party/docker-rpi-emu
3+
url = https://github.com/ryankurte/docker-rpi-emu.git

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# nRF Util for Raspberry Pi
2+
3+
[![rpi-nrfutil Actions Status](https://github.com/LuDuda/rpi-nrfutil/workflows/rpi-nrfutil/badge.svg)](https://github.com/LuDuda/rpi-nrfutil/actions)
4+
5+
## Overview
6+
7+
This repository contains a set of scripts presenting how to build [nRF Util](https://github.com/NordicSemiconductor/pc-nrfutil) executable for Raspberry Pi (armv7l architecture).
8+
9+
Project uses QEMU based emulated environment for the Raspberry Pi, and can be run on Linux system (tested on Ubuntu 18.04).
10+
11+
The resulted `nrfutil` was verified for:
12+
- generating firmware packages
13+
- flashing [nRF52840 Dongle (PCA10059)](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle) using serial DFU over USB
14+
- triggering bootloader mode using USB DFU trigger library
15+
16+
This is experimental project and other functionalities were not tested.
17+
18+
## Installing nRF Util from Raspberry Pi
19+
20+
The easiest way to fetch `nrfutil` is to download it from [GitHub release assets](https://github.com/LuDuda/rpi-nrfutil/releases/download/v6.1.0/nrfutil) or from the [GitHub actions](https://github.com/LuDuda/rpi-nrfutil/actions)
21+
22+
For example:
23+
24+
```bash
25+
wget https://github.com/LuDuda/rpi-nrfutil/releases/download/v6.1.0/nrfutil
26+
chmod +x nrfutil
27+
nrfutil --help
28+
```
29+
30+
## Building nRF Util on Linux
31+
32+
Run the following commands to prepare the build environment and start the building process.
33+
34+
```bash
35+
./script/bootstrap
36+
./script/build
37+
```
38+
39+
After a successful build, the `nrfutil` executable can be found in the `output` folder.
40+
41+
#### nRF Util version
42+
43+
This project supports `nrfutil` in version 6.1.0. To change it's version, adjust the content of `script/_nrfutil` script.
44+
45+
#### Building nRF Util on Raspberry Pi
46+
47+
Alternatively, you can also install/build the `nrfutil` directly on your Raspberry Pi by following the `script/_nrfutil` script.
48+
49+
For older versions of Rasbian such as Stretch, you would need also to build Python3.7 from sources with development support.
50+
51+
52+
```bash
53+
sudo apt-get update -y
54+
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
55+
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
56+
tar xf Python-3.7.4.tar.xz
57+
cd Python-3.7.4
58+
./configure --enable-shared
59+
make
60+
sudo make altinstall
61+
```
62+
63+
## Flashing nRF52840 Dongle from Raspberry Pi
64+
65+
The [nRF52840 Dongle (PCA10059)](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle) incorporates Nordic’s bootloader from Nordic’s nRF5 SDK.
66+
`nrfutil` supports generating and flashing firmware packages over USB.
67+
68+
To update the firmware, perform the following steps:
69+
70+
1. Enter the Bootloader mode on the board.
71+
72+
To do that, either push the reset button on the board or make use of DFU USB software trigger. The second option requires additional support in the existing application firmware.
73+
74+
2. Generate firmware package.
75+
76+
```bash
77+
nrfutil pkg generate --hw-version 52 --sd-req=0x00 \
78+
--application app.hex --application-version 1 app.zip
79+
```
80+
81+
3. Flash new firmware.
82+
83+
```bash
84+
nrfutil dfu usb-serial -pkg app.zip -p /dev/ttyACM0
85+
```

script/_nrfutil

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2020, Lukasz Duda.
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# 3. Neither the name of the copyright holder nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Building nrfutil executable on RaspPi.
30+
#
31+
32+
set -exo pipefail
33+
34+
install_packages()
35+
{
36+
echo 'Downloading package information from configured sources..'
37+
sudo apt-get update --allow-releaseinfo-change
38+
sudo apt update -y
39+
40+
echo 'Installing required dependency...'
41+
sudo apt-get install --no-install-recommends --allow-unauthenticated --fix-missing -y \
42+
python3-pip python3-dev
43+
44+
sudo python3.7 -m pip install pyinstaller
45+
}
46+
47+
build_nrfutil()
48+
{
49+
if [ -z $NRFUTIL_URL]
50+
then
51+
NRFUTIL_URL=https://github.com/NordicSemiconductor/pc-nrfutil/archive/v6.1.zip
52+
fi
53+
54+
echo 'Downloading nrfutil source code...'
55+
wget -O nrfutil.zip $NRFUTIL_URL
56+
unzip -o nrfutil.zip
57+
cd pc-nrfutil*
58+
59+
# pc-ble-driver-py in versions above 0.11.4 cannot be used for RaspPi building.
60+
sed -i 's/pc_ble_driver_py.*$/pc_ble_driver_py==0.11.4/g' requirements.txt
61+
62+
echo 'Preparing nrfutil executable...'
63+
python3.7 setup.py install
64+
nrfutil --help
65+
66+
sudo pyinstaller nrfutil.spec
67+
./dist/nrfutil --help
68+
69+
mkdir -p /home/pi/output
70+
cp -v ./dist/* /home/pi/output
71+
}
72+
73+
main()
74+
{
75+
install_packages
76+
build_nrfutil
77+
}
78+
79+
main

script/bootstrap

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2020, Lukasz Duda.
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# 3. Neither the name of the copyright holder nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Fulfilling dependencies of the project.
30+
#
31+
32+
set -exo pipefail
33+
34+
install_packages()
35+
{
36+
echo 'Downloading package information from configured sources...'
37+
sudo apt-get update
38+
39+
echo 'Installing required dependency...'
40+
sudo apt-get install --no-install-recommends --allow-unauthenticated -y \
41+
docker wget qemu qemu-user-static
42+
}
43+
44+
initialize_submodules()
45+
{
46+
echo 'Initializing git submodules...'
47+
git submodule update --init
48+
}
49+
50+
download_rpi_image()
51+
{
52+
mkdir -p images
53+
IMAGE_FILE=images/raspbian.img
54+
55+
if [ ! -f "$IMAGE_FILE" ]; then
56+
echo 'Downloading Raspbian image...'
57+
58+
if [ -z $IMAGE_URL]
59+
then
60+
IMAGE_URL=http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-06-24/2019-06-20-raspbian-buster-lite.zip
61+
fi
62+
63+
wget -O images/raspbian.zip $IMAGE_URL
64+
unzip -o images/raspbian.zip -d images
65+
mv images/*.img images/raspbian.img
66+
rm images/raspbian.zip
67+
fi
68+
}
69+
70+
main()
71+
{
72+
install_packages
73+
initialize_submodules
74+
download_rpi_image
75+
}
76+
77+
main

script/build

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2020, Lukasz Duda.
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# 3. Neither the name of the copyright holder nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Preparing RPi on QEMU.
30+
#
31+
32+
set -exo pipefail
33+
34+
IMAGE_FILE=images/raspbian.img
35+
WORK_DIR=tmp
36+
OUTPUT_DIR=output
37+
MEDIA_DIR=/media/rpi
38+
RPI_EMU_DIR=third_party/docker-rpi-emu/scripts
39+
40+
init()
41+
{
42+
[ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR"
43+
[ -d "$OUTPUT_DIR" ] || mkdir -p "$OUTPUT_DIR"
44+
45+
cp -v "$IMAGE_FILE" "$WORK_DIR"/raspbian.img
46+
47+
sudo mkdir -p "$MEDIA_DIR"
48+
49+
sudo ./"$RPI_EMU_DIR"/mount.sh "$WORK_DIR"/raspbian.img "$MEDIA_DIR" &&
50+
sudo cp -v script/_nrfutil "$MEDIA_DIR"/home/pi/build_nrfutil.sh &&
51+
sudo ./"$RPI_EMU_DIR"/qemu-setup.sh "$MEDIA_DIR" &&
52+
sudo chroot "$MEDIA_DIR" /bin/bash /home/pi/build_nrfutil.sh &&
53+
sudo cp -v "$MEDIA_DIR"/home/pi/output/* "$OUTPUT_DIR" || die
54+
}
55+
56+
deinit()
57+
{
58+
sudo ./"$RPI_EMU_DIR"/qemu-cleanup.sh "$MEDIA_DIR" || true
59+
sudo umount -lf "$MEDIA_DIR" || true
60+
sudo ./"$RPI_EMU_DIR"/unmount.sh "$MEDIA_DIR" || true
61+
sudo rm -rf "$MEDIA_DIR"
62+
}
63+
64+
die()
65+
{
66+
deinit
67+
exit 1
68+
}
69+
70+
main()
71+
{
72+
init
73+
deinit
74+
}
75+
76+
main

third_party/docker-rpi-emu

Submodule docker-rpi-emu added at 9c74eb4

0 commit comments

Comments
 (0)