Revamp image to build dependencies as part of stages (#83)

Fixes #17.

Stage 2 is fairly minimal, stage 3 builds/installs OpenCV and WPILib et al, and stage 4
builds/installs the FRCVision webdash and adds the vision examples.

Other changes:
- OpenCV compiled with ffmpeg, OpenBLAS, and libgtk (fixes #79, fixes #80)
- OpenBLAS added to image (fixes #65)
- C++ Makefile is more easily extensible (fixes #71)
- Sources for everything are bundled into image into /usr/src
- README updated (fixes #16)
- pkg-config files for wpilibc et al are now installed and C++ Makefile uses them (if compiled local to Pi)
- Both dynamic and static libs are included in image

The only downside of all these changes (particularly the ffmpeg, OpenBLAS, and libgtk inclusion)
is the image size is now over 3GB (800MB compressed). The previous image didn't quite fit on a
2GB card however.
This commit is contained in:
Peter Johnson
2019-02-02 23:37:18 -08:00
committed by GitHub
parent 02d5c468a2
commit c85fd9f33c
75 changed files with 775 additions and 721 deletions
+19 -113
View File
@@ -11,25 +11,34 @@ install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/"
install -m 755 files/rc.local "${ROOTFS_DIR}/etc/"
# enable pi camera
install -m 644 files/picamera.conf "${ROOTFS_DIR}/etc/modules-load.d/"
#
# Install OpenJDK
#
pushd "${STAGE_WORK_DIR}"
wget -nc -nv \
https://github.com/wpilibsuite/raspbian-openjdk/releases/download/v2019-11.0.1-1/jdk_11.0.1-strip.tar.gz
popd
# disable wireless
install -m 644 files/raspi-blacklist.conf "${ROOTFS_DIR}/etc/modprobe.d/"
install -m 644 files/frc.json "${ROOTFS_DIR}/boot/"
install -m 755 extfiles/setuidgids "${ROOTFS_DIR}/usr/local/bin/"
cat extfiles/jdk_11.0.1-strip.tar.gz | sh -c "mkdir -p ${ROOTFS_DIR}/usr/lib/jvm && cd ${ROOTFS_DIR}/usr/lib/jvm/ && tar xzf - --exclude=\*.diz --exclude=src.zip --transform=s/^jdk/jdk-11.0.1/"
mkdir -p "${ROOTFS_DIR}/usr/lib/jvm"
pushd "${ROOTFS_DIR}/usr/lib/jvm"
tar xzf "${STAGE_WORK_DIR}/jdk_11.0.1-strip.tar.gz" \
--exclude=\*.diz \
--exclude=src.zip \
--transform=s/^jdk/jdk-11.0.1/
popd
cp files/jdk-11.0.1.jinfo "${ROOTFS_DIR}/usr/lib/jvm/.jdk-11.0.1.jinfo"
install -m 644 files/ld.so.conf.d/*.conf "${ROOTFS_DIR}/etc/ld.so.conf.d/"
on_chroot << EOF
cd /usr/lib/jvm
grep /usr/lib/jvm .jdk-11.0.1.jinfo | awk '{ print "update-alternatives --install /usr/bin/" \$2 " " \$2 " " \$3 " 2"; }' | bash
update-java-alternatives -s jdk-11.0.1
ldconfig
EOF
#
# Set up for read-only file system
#
on_chroot << EOF
rm -rf /var/lib/dhcp/ /var/run /var/spool /var/lock
ln -s /tmp /var/lib/dhcp
@@ -83,107 +92,4 @@ on_chroot << EOF
usermod --pass='*' root
EOF
install -m 644 files/ld.so.conf.d/*.conf "${ROOTFS_DIR}/etc/ld.so.conf.d/"
install -v -d "${ROOTFS_DIR}/usr/local/frc/bin"
install -m 755 extfiles/multiCameraServer "${ROOTFS_DIR}/usr/local/frc/bin/"
install -m 644 extfiles/multiCameraServer.debug "${ROOTFS_DIR}/usr/local/frc/bin/"
cat extfiles/wpilib-bin.tar.gz | sh -c 'cd ${ROOTFS_DIR}/usr/local/frc/bin/ && tar xzf -'
install -v -d "${ROOTFS_DIR}/usr/local/frc/lib"
cat extfiles/libopencv-debug.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/lib/ && tar xzf -"
cat extfiles/libopencv.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/lib/ && tar xzf -"
install -m 755 extfiles/cv2.*.so "${ROOTFS_DIR}/usr/local/lib/python3.5/dist-packages/"
cat extfiles/pynetworktables.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/lib/python3.5/dist-packages/ && tar xzf -"
cat extfiles/robotpy-cscore.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/lib/python3.5/dist-packages/ && tar xzf -"
install -m 755 extfiles/_cscore.*.so "${ROOTFS_DIR}/usr/local/lib/python3.5/dist-packages/cscore/"
cat extfiles/wpilib-debug.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/lib/ && tar xzf -"
cat extfiles/wpilib.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/lib/ && tar xzf -"
install -v -d "${ROOTFS_DIR}/usr/local/frc/include"
cat extfiles/wpiutil-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/cscore-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/ntcore-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/cameraserver-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/hal-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/hal-gen-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/wpilibc-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
cat extfiles/opencv-include.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/include/ && tar xzf -"
install -v -d "${ROOTFS_DIR}/usr/local/frc/share/OpenCV"
cat extfiles/opencv-cmake-debug.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/share/OpenCV/ && tar xzf -"
cat extfiles/opencv-cmake.tar.gz | sh -c "cd ${ROOTFS_DIR}/usr/local/frc/share/OpenCV/ && tar xzf -"
install -v -d "${ROOTFS_DIR}/usr/local/frc/java"
install -m 644 -o 1000 -g 1000 extfiles/*.jar "${ROOTFS_DIR}/usr/local/frc/java/"
install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/pi/examples/"
install -v -o 1000 -g 1000 extfiles/*-multiCameraServer.zip "${ROOTFS_DIR}/home/pi/examples/"
on_chroot << EOF
cd /home/pi/examples/
unzip java-multiCameraServer.zip
unzip cpp-multiCameraServer.zip
unzip python-multiCameraServer.zip
mkdir ../zips
mv *.zip ../zips/
chown -R 1000:1000 .
EOF
# add jar dependencies to java-multiCameraServer.zip
rm -rf /tmp/java-multiCameraServer
mkdir -p /tmp/java-multiCameraServer
sh -c "cd ${ROOTFS_DIR}/usr/local/frc/java && tar cf - *.jar" | sh -c "cd /tmp/java-multiCameraServer && tar xf -"
sh -c "cd /tmp && zip -r ${ROOTFS_DIR}/home/pi/zips/java-multiCameraServer.zip java-multiCameraServer"
rm -rf /tmp/java-multiCameraServer
# add header and library dependencies (excluding .debug files) to
# cpp-multiCameraServer.zip
# also update Makefile to use cross-compiler and point to local dependencies
rm -rf /tmp/cpp-multiCameraServer
mkdir -p /tmp/cpp-multiCameraServer
echo "CXX=arm-raspbian9-linux-gnueabihf-g++" > /tmp/cpp-multiCameraServer/Makefile
sed -e 's/\/usr\/local\/frc\///g' ${ROOTFS_DIR}/home/pi/examples/cpp-multiCameraServer/Makefile >> /tmp/cpp-multiCameraServer/Makefile
sh -c "cd ${ROOTFS_DIR}/usr/local/frc && tar cf - lib include" | sh -c "cd /tmp/cpp-multiCameraServer && tar xf -"
sh -c "cd /tmp && zip -r ${ROOTFS_DIR}/home/pi/zips/cpp-multiCameraServer.zip cpp-multiCameraServer --exclude \*.so.\*"
rm -rf /tmp/cpp-multiCameraServer
on_chroot << EOF
chown -R 1000:1000 /home/pi/zips
ldconfig
EOF
install -v -d "${ROOTFS_DIR}/service/configServer"
install -m 755 files/configServer_run "${ROOTFS_DIR}/service/configServer/run"
install -m 755 extfiles/rpiConfigServer "${ROOTFS_DIR}/usr/local/sbin/configServer"
install -m 644 extfiles/rpiConfigServer.debug "${ROOTFS_DIR}/usr/local/sbin/"
install -v -d "${ROOTFS_DIR}/service/camera"
install -v -d "${ROOTFS_DIR}/service/camera/log"
install -m 755 files/camera_run "${ROOTFS_DIR}/service/camera/run"
install -m 755 files/camera_log_run "${ROOTFS_DIR}/service/camera/log/run"
on_chroot << EOF
cd /service/camera && rm -f supervise && ln -s /tmp/camera-supervise supervise
cd /service/camera/log && rm -f supervise && ln -s /tmp/camera-log-supervise supervise
cd /service/configServer && rm -f supervise && ln -s /tmp/configServer-supervise supervise
cd /etc/service && rm -f camera && ln -s /service/camera .
cd /etc/service && rm -f configServer && ln -s /service/configServer .
EOF
install -m 755 -o 1000 -g 1000 files/runCamera "${ROOTFS_DIR}/home/pi/"
install -m 755 -o 1000 -g 1000 files/runInteractive "${ROOTFS_DIR}/home/pi/"
install -m 755 -o 1000 -g 1000 files/runService "${ROOTFS_DIR}/home/pi/"
rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key*
@@ -1,2 +0,0 @@
#!/bin/sh
exec /usr/local/frc/bin/netconsoleTee -u
-4
View File
@@ -1,4 +0,0 @@
#!/bin/sh
cd /home/pi
exec 2>&1
exec pgrphack /usr/local/bin/setuidgids pi ./runCamera
@@ -1,2 +0,0 @@
#!/bin/sh
exec /usr/local/sbin/configServer
-13
View File
@@ -1,13 +0,0 @@
{
"team": 294,
"cameras": [
{
"name": "rPi Camera 0",
"path": "/dev/video0",
"pixel format": "mjpeg",
"width": 160,
"height": 120,
"fps": 30
}
]
}
@@ -1,2 +0,0 @@
/usr/local/frc/lib
/usr/local/frc/third-party/lib
-1
View File
@@ -1 +0,0 @@
bcm2835_v4l2
@@ -1,6 +0,0 @@
#wifi
blacklist brcmfmac
blacklist brcmutil
#bt
blacklist btbcm
blacklist hci_uart
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
### TYPE: builtin
echo "Waiting 5 seconds..."
sleep 5
exec /usr/local/frc/bin/multiCameraServer
@@ -1,4 +0,0 @@
#!/bin/bash
sudo svc -d /service/camera
sleep 1
exec ./runCamera
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
sudo svc -u /service/camera
-4
View File
@@ -1,4 +0,0 @@
wpasupplicant wireless-tools firmware-atheros firmware-brcm80211 firmware-libertas firmware-misc-nonfree firmware-realtek
raspberrypi-net-mods
dhcpcd5
net-tools
-29
View File
@@ -1,29 +0,0 @@
#!/bin/bash -e
install -v -d "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d"
install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/"
install -v -d "${ROOTFS_DIR}/etc/wpa_supplicant"
install -v -m 600 files/wpa_supplicant.conf "${ROOTFS_DIR}/etc/wpa_supplicant/"
on_chroot << EOF
rm -f /etc/resolv.conf
touch /tmp/dhcpcd.resolv.conf
ln -s /tmp/dhcpcd.resolve.conf /etc/resolv.conf
sed -i -e 's/\/run\//\/var\/run\//' /etc/systemd/system/dhcpcd5.service
mv /etc/dhcpcd.conf /boot/
chown root:root /boot/dhcpcd.conf
ln -s /boot/dhcpcd.conf /etc/dhcpcd.conf
EOF
if [ -v WPA_COUNTRY ]
then
echo "country=${WPA_COUNTRY}" >> "${ROOTFS_DIR}/etc/wpa_supplicant/wpa_supplicant.conf"
fi
if [ -v WPA_ESSID -a -v WPA_PASSWORD ]
then
on_chroot <<EOF
wpa_passphrase ${WPA_ESSID} ${WPA_PASSWORD} >> "/etc/wpa_supplicant/wpa_supplicant.conf"
EOF
fi
-3
View File
@@ -1,3 +0,0 @@
[Service]
ExecStart=
ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -w
@@ -1,2 +0,0 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
-4
View File
@@ -1,4 +0,0 @@
IMG_SUFFIX="-lite"
if [ "${USE_QEMU}" = "1" ]; then
export IMG_SUFFIX="${IMG_SUFFIX}-qemu"
fi