Added gplan Python module ARM build and package install
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 19 Dec 2017 22:52:43 +0000 (14:52 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 19 Dec 2017 22:52:43 +0000 (14:52 -0800)
.gitignore
MANIFEST.in
Makefile
package.json
scripts/gplan-build.sh [new file with mode: 0755]
scripts/gplan-init-build.sh [new file with mode: 0755]
scripts/gplan-init-dev-img.sh [new file with mode: 0755]
scripts/rpi-chroot.sh [new file with mode: 0755]
setup.py
src/py/camotics/.gitignore [new file with mode: 0644]

index 745bae7e0486c8eb1c426c55baf0226ddd30a308..36cd8779c0a4e18468f081f463d82963faac4288 100644 (file)
@@ -11,3 +11,8 @@ node_modules
 __pycache__
 *.egg-info
 /upload
+/*.img
+*.so
+*.deb
+*.zip
+/rpi-share
index 16bff19d6672079d93ad157e8809a7bde4349e33..2c0a49c4945ccaa122e8a4ee3f27bb6b62624b92 100644 (file)
@@ -2,3 +2,5 @@ recursive-include src/py/bbctrl/http *
 include package.json README.md scripts/install.sh
 include src/avr/bbctrl-avr-firmware.hex
 include scripts/avr109-flash.py
+recursive-include src/py/camotics *
+global-exclude .gitignore
index a0f21e2a7faec1b1bda368f2dde67049c9e0419d..aaaf44bd92f1070464e9177267172e88e7baaddb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,9 @@ STATIC     := $(patsubst src/resources/%,$(TARGET)/%,$(STATIC))
 TEMPLS     := $(wildcard src/jade/templates/*.jade)
 
 AVR_FIRMWARE := src/avr/bbctrl-avr-firmware.hex
+GPLAN_MOD := rpi-share/camotics/gplan.so
+GPLAN_TARGET := src/py/camotics/gplan.so
+GPLAN_IMG := gplan-dev.img
 
 RSYNC_EXCLUDE := \*.pyc __pycache__ \*.egg-info \\\#* \*~ .\\\#\*
 RSYNC_EXCLUDE := $(patsubst %,--exclude %,$(RSYNC_EXCLUDE))
@@ -51,6 +54,21 @@ copy: pkg
 pkg: all $(AVR_FIRMWARE)
        ./setup.py sdist
 
+gplan: $(GPLAN_TARGET)
+
+$(GPLAN_TARGET): $(GPLAN_MOD)
+       cp $< $@
+
+$(GPLAN_MOD): $(GPLAN_IMG)
+       ./scripts/gplan-init-build.sh
+       git -C rpi-share/cbang pull
+       git -C rpi-share/camotics pull
+       cp ./scripts/gplan-build.sh rpi-share/
+       sudo ./scripts/rpi-chroot.sh $(GPLAN_IMG) /mnt/host/gplan-build.sh
+
+$(GPLAN_IMG):
+       ./scripts/gplan-init-build.sh
+
 .PHONY: $(AVR_FIRMWARE)
 $(AVR_FIRMWARE):
        $(MAKE) -C src/avr $(shell basename $@)
@@ -141,3 +159,4 @@ dist-clean: clean
        rm -rf node_modules
 
 .PHONY: all install html css static templates clean tidy copy mount umount pkg
+.PHONY: gplan
index d8713556787a4b1b9fe48c5c4912e9534f2a9870..df9cce498ff90e0050c0f8d16443b765de1eace8 100644 (file)
@@ -1,7 +1,7 @@
 {
   "name": "bbctrl",
   "version": "0.2.2",
-  "homepage": "https://github.com/buildbotics/rpi-firmware",
+  "homepage": "https://github.com/buildbotics/bbctrl-firmware",
   "license": "GPL 3+",
 
   "dependencies": {
diff --git a/scripts/gplan-build.sh b/scripts/gplan-build.sh
new file mode 100755 (executable)
index 0000000..a21237d
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash -ex
+
+cd /mnt/host
+scons -C cbang disable_local="re2 libevent"
+export CBANG_HOME="/mnt/host/cbang"
+scons -C camotics gplan.so with_gui=0 with_tpl=0
diff --git a/scripts/gplan-init-build.sh b/scripts/gplan-init-build.sh
new file mode 100755 (executable)
index 0000000..a4cbde3
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash -ex
+
+IMG_DATE=2017-11-29
+IMG_BASE=${IMG_DATE}-raspbian-stretch-lite
+BASE_URL=https://downloads.raspberrypi.org/raspbian_lite/images
+IMG_URL=$BASE_URL/raspbian_lite-2017-12-01/$IMG_BASE.zip
+GPLAN_IMG=gplan-dev.img
+
+# Create dev image
+if [ ! -e $GPLAN_IMG ]; then
+
+    # Get base image
+    if [ ! -e $IMG_BASE.img ]; then
+        if [ ! -e $IMG_BASE.zip ]; then
+            wget $IMG_URL
+        fi
+
+        unzip $IMG_BASE.zip
+    fi
+
+    # Copy base image
+    cp $IMG_BASE.img $GPLAN_IMG.tmp
+
+    # Init image
+    mkdir -p rpi-share
+    cp ./scripts/gplan-init-dev-img.sh rpi-share
+    sudo ./scripts/rpi-chroot.sh $GPLAN_IMG.tmp /mnt/host/gplan-init-dev-img.sh
+
+    # Move image
+    mv $GPLAN_IMG.tmp $GPLAN_IMG
+fi
+
+# Get repos
+mkdir -p rpi-share || true
+
+if [ ! -e rpi-share/cbang ]; then
+    if [ "$CBANG_HOME" != "" ]; then
+        git clone $CBANG_HOME rpi-share/cbang
+    else
+        git clone https://github.com/CauldronDevelopmentLLC/cbang \
+            rpi-share/cbang
+    fi
+fi
+
+if [ ! -e rpi-share/camotics ]; then
+    if [ "$CAMOTICS_HOME" != "" ]; then
+        git clone $CAMOTICS_HOME rpi-share/camotics
+    else
+        git clone https://github.com/CauldronDevelopmentLLC/camotics \
+            rpi-share/camotics
+    fi
+fi
diff --git a/scripts/gplan-init-dev-img.sh b/scripts/gplan-init-dev-img.sh
new file mode 100755 (executable)
index 0000000..7f0888f
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+export LC_ALL=C
+cd /mnt/host
+
+# Update the system
+apt-get update
+apt-get dist-upgrade -y
+
+# Install packages
+apt-get install -y scons build-essential libssl-dev python3-dev
diff --git a/scripts/rpi-chroot.sh b/scripts/rpi-chroot.sh
new file mode 100755 (executable)
index 0000000..a72d8d8
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash -ex
+
+ROOT="$PWD/rpi-root"
+LOOP=5
+
+if [ $# -lt 1 ]; then
+    echo "Usage: $0 <image> <exec>"
+    exit 1
+fi
+
+IMAGE="$1"
+LOOP_DEV=/dev/loop${LOOP}
+EXEC=
+
+if [ $# -gt 1 ]; then
+    shift
+    EXEC="$@"
+fi
+
+# install dependecies
+if [ ! -e /usr/bin/qemu-arm-static ]; then
+    apt-get update
+    apt-get install -y qemu qemu-user-static binfmt-support
+fi
+
+# Clean up on EXIT
+function cleanup {
+    umount "$ROOT"/{dev/pts,dev,sys,proc,boot,mnt/host,} 2>/dev/null || true
+    losetup -d $LOOP_DEV 2>/dev/null || true
+    rmdir "$ROOT" 2>/dev/null || true
+}
+trap cleanup EXIT
+
+# set up image as loop device
+losetup $LOOP_DEV "$IMAGE"
+if [ ! -e ${LOOP_DEV}p1 ]; then
+    partprobe $LOOP_DEV
+fi
+
+# check and fix filesystems
+fsck -f ${LOOP_DEV}p1
+fsck -f ${LOOP_DEV}p2
+
+# make dir
+mkdir -p "$ROOT"
+
+# mount partition
+mount -o rw ${LOOP_DEV}p2 -t ext4 "$ROOT"
+mount -o rw ${LOOP_DEV}p1 "$ROOT/boot"
+
+# mount binds
+mount --bind /dev "$ROOT/dev/"
+mount --bind /sys "$ROOT/sys/"
+mount --bind /proc "$ROOT/proc/"
+mount --bind /dev/pts "$ROOT/dev/pts"
+if [ -e ./rpi-share ]; then
+    mkdir -p "$ROOT/mnt/host"
+    mount --bind ./rpi-share "$ROOT/mnt/host"
+fi
+
+# copy qemu binary
+cp /usr/bin/qemu-arm-static "$ROOT/usr/bin/"
+
+# chroot to raspbian
+chroot "$ROOT" $EXEC
index 97a104e925ddecc0a444bb7d48fbcca07168970b..fa0e3aeafaa8b6330b3c14c074d7170fa5e3b397 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ setup(
     license = pkg['license'],
     url = pkg['homepage'],
     package_dir = {'': 'src/py'},
-    packages = ['bbctrl', 'inevent', 'lcd'],
+    packages = ['bbctrl', 'inevent', 'lcd', 'camotics'],
     include_package_data = True,
     entry_points = {
         'console_scripts': [
diff --git a/src/py/camotics/.gitignore b/src/py/camotics/.gitignore
new file mode 100644 (file)
index 0000000..e69de29