Skip to content

Commit 02ca8d3

Browse files
committed
bluetooth support added
1 parent a615938 commit 02ca8d3

File tree

3 files changed

+85
-19
lines changed

3 files changed

+85
-19
lines changed

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
1414
RUN [ "cross-build-start" ]
1515

1616
#version
17-
ENV HILSCHERNETPI_RASPBIAN_VERSION 1.1.0
17+
ENV HILSCHERNETPI_RASPBIAN_VERSION 1.2.0
1818

1919
#labeling
2020
LABEL maintainer="netpi@hilscher.com" \
@@ -25,9 +25,6 @@ LABEL maintainer="netpi@hilscher.com" \
2525
ENV USER=pi
2626
ENV PASSWD=raspberry
2727

28-
#copy files
29-
COPY "./init.d/*" /etc/init.d/
30-
3128
RUN apt-get update \
3229
&& apt-get install wget \
3330
&& wget https://archive.raspbian.org/raspbian.public.key -O - | apt-key add - \
@@ -168,11 +165,17 @@ RUN apt-get update \
168165
libsigc++-1.2-dev \
169166
raspberrypi-kernel \
170167
raspi-copies-and-fills \
168+
&& mkdir /etc/firmware \
169+
&& curl -o /etc/firmware/BCM43430A1.hcd -L https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd \
170+
&& wget https://raw.githubusercontent.com/raspberrypi/firmware/1.20180417/opt/vc/bin/vcmailbox -O /opt/vc/bin/vcmailbox \
171171
&& apt-get remove git \
172172
&& apt-get autoremove \
173173
&& rm -rf /tmp/* \
174174
&& rm -rf /var/lib/apt/lists/*
175175

176+
#copy files
177+
COPY "./init.d/*" /etc/init.d/
178+
176179
#set the entrypoint
177180
ENTRYPOINT ["/etc/init.d/entrypoint.sh"]
178181

README.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,46 @@ netPI features a restricted Docker protecting the system software's integrity by
1717

1818
### Container features
1919

20-
The image provided hereunder deploys a container with Debian, SSH server, Raspberry Pi userland tool and created user pi.
20+
The image provided hereunder deploys a container with Debian, SSH server, pre-compiled software/packages typically found installed on Raspbian OS (inclusive userland tools) and default user pi.
2121

22-
Base of this image builds [debian](https://www.balena.io/docs/reference/base-images/base-images/) with enabled [SSH](https://en.wikipedia.org/wiki/Secure_Shell), created user 'pi' and preinstalled packages of a headless Raspbian lite.
22+
Base of this image builds [debian](https://www.balena.io/docs/reference/base-images/base-images/) with enabled [SSH](https://en.wikipedia.org/wiki/Secure_Shell), installed [userland](https://github.com/raspberrypi/userland) tools, created user 'pi' and preinstalled packages of a Raspbian lite operating system (headless).
2323

2424
### Container setup
2525

26-
#### Port mapping
26+
#### Network mode
2727

28-
For a SSH login to the container any unused netPI host port needs to be added to the container port `22` (SSH).
28+
The container supports bridged or host network mode. More details at [Container networking](https://docs.docker.com/v17.09/engine/userguide/networking/).
29+
30+
##### Bridged
31+
32+
Any unused netPI host port needs to be mapped to the container port `22` to expose the container SSH server to the host.
33+
34+
Remark: Container bluetooth communications are supported in host network mode only.
35+
36+
##### Host
37+
38+
Port mapping is unnecessary since all the used container ports (like 22) are exposed to the host automatically.
39+
40+
Remark: Host network mode is mandatory for container bluetooth communications.
2941

3042
#### Hostname (optional)
3143

32-
For an equal standard Raspberry Pi condition set the container hostname to `raspberrypi`.
44+
For an equal default Raspbian OS hostname set the container hostname to `raspberrypi`.
3345

3446
#### Privileged mode (optional)
3547

36-
The privileged mode option needs to be activated to lift the standard Docker enforced container limitations. With this setting the container and the applications inside are the getting (almost) all capabilities as if running on the Host directly.
48+
The privileged mode lifts the standard Docker enforced container limitations: applications inside a container are getting (almost) all capabilities as if running on the host directly.
49+
50+
Enabling the privileged mode is optional but mandatory for the following container functions:
51+
52+
* bluetooth communications
53+
* using userland tools
3754

38-
netPI's secure reference software architecture prohibits root access to the Host system always. Even if priviledged mode is activated the intrinsic security of the Host Linux Kernel can not be compromised.
55+
#### Host devices (optional)
3956

40-
#### Host device (optional)
57+
For bluetooth communications the `/dev/ttyAMA0` host device needs to be added to the container. In conjunction the `/dev/vcio` host device needs be added to the container too to allow proper bluetooth controller resets.
4158

42-
The container includes the [userland](https://github.com/raspberrypi/userland) tools installed with original Raspbian OS too. To grant access of tools like [vcmailbox](https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/vcmailbox/vcmailbox.c) the `/dev/vcio` and `/dev/vchiq` and `/dev/vc-mem` host devices need to be exposed to the container. (Prerequisite is running the container in privileged mode).
59+
For using userland tools like [vcmailbox](https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/vcmailbox/vcmailbox.c) the `/dev/vcio` and `/dev/vchiq` and `/dev/vc-mem` host devices need to be added to the container.
4360

4461
### Container deployment
4562

@@ -52,21 +69,23 @@ STEP 3. Enter the following parameters under *Containers > + Add Container*
5269
Parameter | Value | Remark
5370
:---------|:------ |:------
5471
*Image* | **hilschernetpi/netpi-raspbian**
72+
*Network > Network* | **bridge** or **host** | use alternatively
5573
*Network > Hostname* | **raspberrypi** | optional
56-
*Port mapping* | *host* **22** -> *container* **22** | *host*=any unused
74+
*Port mapping* | *host* **22** -> *container* **22** | *host*=any unused, bridged mode only
5775
*Restart policy* | **always**
58-
*Runtime > Devices > +add device* | *Host path* **/dev/vcio** -> *Container path* **/dev/vcio** | optional
59-
*Runtime > Devices > +add device* | *Host path* **/dev/vchiq** -> *Container path* **/dev/vchiq** | optional
60-
*Runtime > Devices > +add device* | *Host path* **/dev/vc-mem** -> *Container path* **/dev/vc-mem** | optional
61-
*Runtime > Privileged mode* | **On** | optional
76+
*Runtime > Devices > +add device* | *Host path* **/dev/ttyAMA0** -> *Container path* **/dev/ttyAMA0** | optional for bluetooth
77+
*Runtime > Devices > +add device* | *Host path* **/dev/vcio** -> *Container path* **/dev/vcio** | optional for bluetooth, userland tools
78+
*Runtime > Devices > +add device* | *Host path* **/dev/vchiq** -> *Container path* **/dev/vchiq** | optional for userland tools
79+
*Runtime > Devices > +add device* | *Host path* **/dev/vc-mem** -> *Container path* **/dev/vc-mem** | optional for userland tools
80+
*Runtime > Privileged mode* | **On** | optional for bluetooth, userland tools
6281

6382
STEP 4. Press the button *Actions > Start/Deploy container*
6483

6584
Pulling the image may take a while (5-10mins). Sometimes it may take too long and a time out is indicated. In this case repeat STEP 4.
6685

6786
### Container access
6887

69-
The container automatically starts the SSH server. For a SSH session use a SSH client such as [putty](http://www.putty.org/) with the netPI IP address (@mapped SSH host port number).
88+
The container automatically starts the SSH server. For a SSH terminal session use a SSH client such as [putty](http://www.putty.org/) with the netPI IP address (@mapped SSH host port number).
7089

7190
Use the credentials `pi` as user and `raspberry` as password when asked and you are logged in as non-root user `pi`.
7291

init.d/entrypoint.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
# SIGNAL-handler
55
term_handler() {
66

7+
echo "stopping bluetooth daemon ..."
8+
if [ $pidbt -ne 0 ]; then
9+
kill -SIGTERM "$pidbt"
10+
wait "$pidbt"
11+
echo "bring hci0 down ..."
12+
hciconfig hci0 down
13+
fi
14+
15+
echo "terminating dbus ..."
16+
/etc/init.d/dbus stop
17+
718
echo "terminating ssh ..."
819
sudo /etc/init.d/ssh stop
920

@@ -20,6 +31,39 @@ sudo /etc/init.d/ssh start
2031
echo "starting dbus ..."
2132
/etc/init.d/dbus start
2233

34+
pidbt=0
35+
36+
if [[ -n `grep "docker0" /proc/net/dev` ]]; then
37+
#container is running in host mode
38+
ip link add dummy0 type dummy >/dev/null 2>&1
39+
if [[ -n `grep "dummy0" /proc/net/dev` ]]; then
40+
ip link delete dummy0 >/dev/null 2>&1
41+
#container running in privileged mode
42+
if [[ -e "/dev/ttyAMA0" ]]; then
43+
#bluetooth can be supported
44+
45+
if [[ -e "/dev/vcio" ]]; then
46+
#reset BCM chip possible
47+
/opt/vc/bin/vcmailbox 0x38041 8 8 128 0 >/dev/null
48+
sleep 1
49+
/opt/vc/bin/vcmailbox 0x38041 8 8 128 1 >/dev/null
50+
sleep 1
51+
fi
52+
53+
#load firmware to BCM chip and attach to hci0
54+
hciattach /dev/ttyAMA0 bcm43xx 921600 noflow
55+
56+
#create hci0 device
57+
hciconfig hci0 up
58+
59+
#start bluetooth daemon
60+
bluetoothd -d &
61+
pidbt="$!"
62+
fi
63+
fi
64+
fi
65+
66+
2367
# wait forever not to exit the container
2468
while true
2569
do

0 commit comments

Comments
 (0)