From 63611899df466a9d45c7129424fbbf0f6e86dc1b Mon Sep 17 00:00:00 2001
From: cdsteinkuehler <charles@steinkuehler.net>
Date: Sun, 20 Nov 2016 09:50:46 -0600
Subject: [PATCH] Add dtc compatible with 3.8.13 kernel (#93)

Use RCN's script to fetch and build a dtc compiler compatible with
the 3.8.13 kernel used by the Machinekit image.

General cleanup of the machinekit/scripts directory

Signed-off-by: Charles Steinkuehler <charles@steinkuehler.net>
---
 configs/machinekit-debian-jessie.conf         |  4 +-
 machinekit/chroot_hook.sh                     |  9 ++-
 machinekit/pkg_list.sh                        | 33 -----------
 machinekit/scripts/000.build_dtc.shu          | 10 ++++
 machinekit/scripts/000.copy.sh                | 10 ----
 machinekit/scripts/001.build_dtc.shr          |  6 ++
 machinekit/scripts/001.download.shu           |  8 ---
 machinekit/scripts/002.download.shr           |  4 --
 machinekit/scripts/003.make-xenomai.shu       | 17 ------
 machinekit/scripts/004.make-xenomai.shr       | 16 ------
 machinekit/scripts/005.make-linuxcnc.shu      | 22 --------
 machinekit/scripts/006.make-linuxcnc.shr      | 11 ----
 machinekit/scripts/007.make-dtc.shu           | 16 ------
 machinekit/scripts/008.make-dtc.shr           | 12 ----
 machinekit/scripts/100.init.shr               | 56 -------------------
 machinekit/scripts/110.etc.shr                | 33 -----------
 machinekit/scripts/120.desktop.shr            | 13 -----
 machinekit/scripts/130.testbranch.shr         | 16 ------
 machinekit/scripts/900.homedir.shu            | 16 ------
 machinekit/scripts/999.cleanup.shr            | 13 -----
 .../scripts/x020.download.patch-bbio.shu      | 26 ---------
 machinekit/scripts/x021.make-bbio.shr         |  6 --
 target/chroot/machinekit-jessie.sh            | 13 +++++
 23 files changed, 38 insertions(+), 332 deletions(-)
 delete mode 100755 machinekit/pkg_list.sh
 create mode 100755 machinekit/scripts/000.build_dtc.shu
 delete mode 100755 machinekit/scripts/000.copy.sh
 create mode 100755 machinekit/scripts/001.build_dtc.shr
 delete mode 100755 machinekit/scripts/001.download.shu
 delete mode 100755 machinekit/scripts/002.download.shr
 delete mode 100755 machinekit/scripts/003.make-xenomai.shu
 delete mode 100755 machinekit/scripts/004.make-xenomai.shr
 delete mode 100755 machinekit/scripts/005.make-linuxcnc.shu
 delete mode 100755 machinekit/scripts/006.make-linuxcnc.shr
 delete mode 100755 machinekit/scripts/007.make-dtc.shu
 delete mode 100755 machinekit/scripts/008.make-dtc.shr
 delete mode 100755 machinekit/scripts/100.init.shr
 delete mode 100755 machinekit/scripts/110.etc.shr
 delete mode 100755 machinekit/scripts/120.desktop.shr
 delete mode 100755 machinekit/scripts/130.testbranch.shr
 delete mode 100755 machinekit/scripts/900.homedir.shu
 delete mode 100755 machinekit/scripts/999.cleanup.shr
 delete mode 100755 machinekit/scripts/x020.download.patch-bbio.shu
 delete mode 100755 machinekit/scripts/x021.make-bbio.shr

diff --git a/configs/machinekit-debian-jessie.conf b/configs/machinekit-debian-jessie.conf
index e9c853ea0..e2330ca15 100644
--- a/configs/machinekit-debian-jessie.conf
+++ b/configs/machinekit-debian-jessie.conf
@@ -181,7 +181,9 @@ repo_external_pkg_list="	\
 #
 chroot_COPY_SETUP_SDCARD="enable"
 chroot_before_hook=""
-chroot_after_hook=""
+chroot_after_hook="machinekit/chroot_hook.sh"
 chroot_script="machinekit-jessie.sh"
 chroot_post_uenv_txt="post_machinekit.txt"
 chroot_tarball="enable"
+
+
diff --git a/machinekit/chroot_hook.sh b/machinekit/chroot_hook.sh
index b7ad99038..a5d35efeb 100755
--- a/machinekit/chroot_hook.sh
+++ b/machinekit/chroot_hook.sh
@@ -4,19 +4,22 @@ echo "chroot: ${tempdir}"
 
 echo "userid: ${rfs_username}:${rfs_password}"
 
-#xenomai_gid="$(sed -n '/xenomai/{s/^[^:]*:[^:]*:\([^:]*\):.*/\1/;p;}' /etc/group)"
-#echo "xenomai gid: ${xenomai_gid}"
-
 sudo rsync -va ${DIR}/machinekit/scripts/* ${tempdir}/tmp/
 
 for SCRIPT in ${tempdir}/tmp/[0-9][0-9][0-9]* ; do
 	case "$SCRIPT" in
+	# Run script as root on the new image
 	*.shr)	time sudo chroot ${tempdir} /bin/sh  ${SCRIPT#$tempdir} ${rfs_username}
 		;;
+
+	# Run script as user on the new image
 	*.shu)	time sudo chroot ${tempdir} /bin/su  ${rfs_username} -c ${SCRIPT#$tempdir}
 		;;
+
+	# Run script on the build host, which can see both filesystems
 	*.sh)	. ${SCRIPT}
 		;;
+
 	*)	echo "Log: Unknown script format: ${SCRIPT}"
 		;;
 	esac
diff --git a/machinekit/pkg_list.sh b/machinekit/pkg_list.sh
deleted file mode 100755
index d6a0ea6f4..000000000
--- a/machinekit/pkg_list.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh -e
-
-#Note: These will be auto installed by chroot.sh script:
-#initramfs-tools sudo wget
-
-base_pkgs=""
-
-#Base
-base_pkgs="${base_pkgs} ca-certificates nano pastebinit"
-
-#Tools
-base_pkgs="${base_pkgs} bsdmainutils i2c-tools fbset hexedit hdparm memtester read-edid u-boot-tools"
-
-#OS
-base_pkgs="${base_pkgs} acpid dosfstools btrfs-tools cpufrequtils ntpdate watchdog"
-
-#USB Dongles
-base_pkgs="${base_pkgs} ppp usb-modeswitch usbutils"
-
-#Server
-base_pkgs="${base_pkgs} apache2 openssh-server udhcpd avahi-daemon"
-
-#Wireless
-base_pkgs="${base_pkgs} wireless-tools wpasupplicant lowpan-tools wvdial lshw hostapd"
-
-#Flasher
-base_pkgs="${base_pkgs} rsync"
-
-#shellinabox (breaks ssh over eth/usb)
-#base_pkgs="${base_pkgs} shellinabox"
-
-#Gateone:
-#base_pkgs="${base_pkgs} python-tornado python-pyopenssl"
diff --git a/machinekit/scripts/000.build_dtc.shu b/machinekit/scripts/000.build_dtc.shu
new file mode 100755
index 000000000..5897bb88f
--- /dev/null
+++ b/machinekit/scripts/000.build_dtc.shu
@@ -0,0 +1,10 @@
+#!/bin/sh -e
+
+# Don't try to sudo, it will fail
+sudo () {
+	echo sudo $@
+}
+
+# Build a dtc compiler that works with the 3.8.13 kernel
+. /opt/source/tools/pkgs/dtc.sh
+
diff --git a/machinekit/scripts/000.copy.sh b/machinekit/scripts/000.copy.sh
deleted file mode 100755
index fd6c7ffe6..000000000
--- a/machinekit/scripts/000.copy.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# If we have a 'kickstart' image, copy the pre-compiled source tree as a tarball
-for SOURCE in machinekit xenomai-2.6 dtc ; do
-
-	if [ -d ~/beaglebone.kickstart/home/machinekit/${SOURCE} ] ; then
-		sudo tar cf ${tempdir}/home/machinekit/kickstart.${SOURCE}.tar -C ~/beaglebone.kickstart/home/machinekit ${SOURCE}
-	fi
-done
-
diff --git a/machinekit/scripts/001.build_dtc.shr b/machinekit/scripts/001.build_dtc.shr
new file mode 100755
index 000000000..6b6e9e408
--- /dev/null
+++ b/machinekit/scripts/001.build_dtc.shr
@@ -0,0 +1,6 @@
+#!/bin/sh -e
+
+# Install a dtc compiler that works with the 3.8.13 kernel
+cd /home/machinekit/git/dtc
+make PREFIX=/usr/local/ install
+
diff --git a/machinekit/scripts/001.download.shu b/machinekit/scripts/001.download.shu
deleted file mode 100755
index c452ab76d..000000000
--- a/machinekit/scripts/001.download.shu
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-cd ~
-
-#wget http://static.mah.priv.at/public/beaglebone/starterkit/deploy/3.8.13xenomai-bone20.config
-#wget http://static.mah.priv.at/public/beaglebone/starterkit/deploy/3.8.13xenomai-bone23.config
-#wget http://www.machinekit.net/deb/wheezy-armhf/v3.8.13xenomai-bone26/3.8.13xenomai-bone26.config
-
diff --git a/machinekit/scripts/002.download.shr b/machinekit/scripts/002.download.shr
deleted file mode 100755
index 109d3c086..000000000
--- a/machinekit/scripts/002.download.shr
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-eval mv ~$1/*.config /boot/ || true
-
diff --git a/machinekit/scripts/003.make-xenomai.shu b/machinekit/scripts/003.make-xenomai.shu
deleted file mode 100755
index 10036e2ab..000000000
--- a/machinekit/scripts/003.make-xenomai.shu
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-SOURCE=xenomai-2.6
-
-cd ~
-
-# Unpack the kickstart file, if it exists, then remove it
-if [ -f kickstart.${SOURCE}.tar ] ; then
-	tar xf kickstart.${SOURCE}.tar
-else
-	git clone --depth 1 git://git.xenomai.org/xenomai-2.6.git xenomai-2.6
-	cd ~/xenomai-2.6/
-	git checkout -b Machinekit v2.6.3
-	./configure
-	make
-fi
-
diff --git a/machinekit/scripts/004.make-xenomai.shr b/machinekit/scripts/004.make-xenomai.shr
deleted file mode 100755
index 79d459e8f..000000000
--- a/machinekit/scripts/004.make-xenomai.shr
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-eval cd ~$1/xenomai-2.6
-make install
-groupadd --system xenomai
-
-# Add xenomai libraries to ld config
-cat << EOF >/etc/ld.so.conf.d/xenomai.conf
-# Xenomai user libraries
-/usr/xenomai/lib
-EOF
-
-ldconfig
-
-usermod -aG xenomai machinekit
-
diff --git a/machinekit/scripts/005.make-linuxcnc.shu b/machinekit/scripts/005.make-linuxcnc.shu
deleted file mode 100755
index bada5b8d1..000000000
--- a/machinekit/scripts/005.make-linuxcnc.shu
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-SOURCE=machinekit
-
-cd ~
-
-# Unpack the kickstart file, if it exists, then remove it
-if [ -f kickstart.${SOURCE}.tar ] ; then
-	tar xf kickstart.${SOURCE}.tar
-else
-	#git clone -b MachineKit-ubc git://git.mah.priv.at/emc2-dev.git machinekit-dev
-	#git clone -b MachineKit-ubc https://github.com/cdsteinkuehler/MachineKit.git machinekit-dev
-	git clone -b master https://github.com/machinekit/machinekit.git machinekit-dev
-	cd ~/machinekit-dev/
-	#git remote add linuxcnc git://git.linuxcnc.org/git/linuxcnc.git
-	#git remote add machinekit https://github.com/machinekit/machinekit.git
-	cd ~/machinekit-dev/src
-	./autogen.sh
-	./configure --with-xenomai --with-platform=beaglebone --enable-emcweb --with-posix --with-rt-preempt
-	make
-fi
-
diff --git a/machinekit/scripts/006.make-linuxcnc.shr b/machinekit/scripts/006.make-linuxcnc.shr
deleted file mode 100755
index e98be95d2..000000000
--- a/machinekit/scripts/006.make-linuxcnc.shr
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-eval cd ~$1/machinekit-dev/src
-make setuid
-
-usermod -aG kmem machinekit
-
-touch /var/log/linuxcnc.log
-[ -r rtapi/rsyslogd-linuxcnc.conf ] && cp rtapi/rsyslogd-linuxcnc.conf /etc/rsyslog.d/linuxcnc.conf || :
-[ -r rtapi/shmdrv/limits.d-linuxcnc.conf ] && cp rtapi/shmdrv/limits.d-linuxcnc.conf /etc/security/limits.d/linuxcnc.conf || :
-
diff --git a/machinekit/scripts/007.make-dtc.shu b/machinekit/scripts/007.make-dtc.shu
deleted file mode 100755
index 181ee1aa2..000000000
--- a/machinekit/scripts/007.make-dtc.shu
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-SOURCE=dtc
-
-cd ~
-
-# Unpack the kickstart file, if it exists, then remove it
-if [ -f kickstart.${SOURCE}.tar ] ; then
-	tar xf kickstart.${SOURCE}.tar
-else
-	git clone -b dtc-fixup-fdc7387 https://github.com/RobertCNelson/dtc.git dtc
-	cd ~/dtc
-	make clean
-	make PREFIX=/usr/local/ CROSS_COMPILE= all
-fi
-
diff --git a/machinekit/scripts/008.make-dtc.shr b/machinekit/scripts/008.make-dtc.shr
deleted file mode 100755
index 2b4b0537c..000000000
--- a/machinekit/scripts/008.make-dtc.shr
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-eval cd ~$1/dtc
-make PREFIX=/usr/local/ install
-
-for FILE in $( eval find ~$1/machinekit-dev/configs -name dtc.sh ) ; do
-
-    cd $( dirname $FILE )
-    ./dtc.sh
-
-done
-
diff --git a/machinekit/scripts/100.init.shr b/machinekit/scripts/100.init.shr
deleted file mode 100755
index 08d7afc24..000000000
--- a/machinekit/scripts/100.init.shr
+++ /dev/null
@@ -1,56 +0,0 @@
-########################################
-# Delete ssh host keys and setup to generate a new set on first boot
-########################################
-
-rm -f /etc/ssh/ssh_host_*
-
-cat << EOF > /etc/init.d/ssh_gen_host_keys
-#!/bin/sh
-### BEGIN INIT INFO
-# Provides:          Generates new ssh host keys on first boot
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:
-# Short-Description: Generates new ssh host keys on first boot
-# Description:       Generates new ssh host keys on first boot
-### END INIT INFO
-dpkg-reconfigure openssh-server
-insserv -r /etc/init.d/ssh_gen_host_keys
-rm -f \$0
-EOF
-
-chmod a+x /etc/init.d/ssh_gen_host_keys
-insserv /etc/init.d/ssh_gen_host_keys
-
-
-########################################
-# Generate rc.local
-########################################
-
-XENOGID=$(sed -n '/xenomai/{s/^[^:]*:[^:]*:\([^:]*\):[^:]*$/\1/;p;}' /etc/group)
-
-cat << EOF > /etc/rc.local
-#!/bin/sh -e
-#
-# rc.local
-#
-# This script is executed at the end of each multiuser runlevel.
-# Make sure that the script will "exit 0" on success or any other
-# value on error.
-#
-# In order to enable or disable this script just change the execution
-# bits.
-#
-# By default this script does nothing.
-
-# Configure xenomai group
-echo $XENOGID > /sys/module/xeno_nucleus/parameters/xenomai_gid
-
-# Make /dev/mem group writable
-chmod 664 /dev/mem
-
-exit 0
-
-EOF
-
diff --git a/machinekit/scripts/110.etc.shr b/machinekit/scripts/110.etc.shr
deleted file mode 100755
index bcd807ae0..000000000
--- a/machinekit/scripts/110.etc.shr
+++ /dev/null
@@ -1,33 +0,0 @@
-########################################
-# Configure sudo askpass 
-########################################
-
-# Setup askpass for all users
-cat << EOF > /etc/sudo.conf
-# Path to askpass helper program
-Path askpass /usr/bin/ssh-askpass
-
-EOF
-
-# Setup machinekit to not need an sudo password
-cat << EOF > /etc/sudoers.d/90-machinekit
-# No sudo password for machinekit user
-machinekit ALL=(ALL) NOPASSWD: ALL
-
-EOF
-
-# Remove machinekit from the admin group, to prevent the last line of
-# /etc/sudoers from over-riding the above NOPASSWD: setting
-
-gpasswd -d machinekit admin
-
-# Enable all users to read hidraw devices
-cat << EOF > /etc/udev/rules.d/99-hdiraw.rules
-SUBSYSTEM=="hidraw", MODE="0644"
-EOF
-
-# Enable PAM for ssh links
-# Fixes an issue where users cannot change ulimits when logged in via
-# ssh, which causes some Machinekit functions to fail
-sed -i 's/^UsePAM.*$/UsePam yes/' /etc/ssh/sshd_config
-
diff --git a/machinekit/scripts/120.desktop.shr b/machinekit/scripts/120.desktop.shr
deleted file mode 100755
index 9353f982a..000000000
--- a/machinekit/scripts/120.desktop.shr
+++ /dev/null
@@ -1,13 +0,0 @@
-########################################
-# Configure desktop
-########################################
-
-# Download additional desktop background images
-cd /opt/
-wget http://www.machinekit.net/deb/images/beagle-wallpaper_1920x1080.svg
-wget http://www.machinekit.net/deb/images/beaglebg-blue.png
-
-# Set default background image
-eval cd ~$1
-sed -i 's:^wallpaper=.*:wallpaper=/opt/beagle-wallpaper_1920x1080.svg:' .config/pcmanfm/LXDE/pcmanfm.conf
-
diff --git a/machinekit/scripts/130.testbranch.shr b/machinekit/scripts/130.testbranch.shr
deleted file mode 100755
index 8e79dced0..000000000
--- a/machinekit/scripts/130.testbranch.shr
+++ /dev/null
@@ -1,16 +0,0 @@
-# Install script to build latest Machinekit from source
-
-git_repo="https://github.com/mhaberler/scripts"
-git_target_dir="/opt/source/testbranch"
-
-mkdir -p ${git_target_dir} || true
-git clone ${git_repo} ${git_target_dir} --depth 1 || true
-sync
-echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
-
-if [ -f ${git_target_dir}/.git/config ] ; then
-	if [ -f ${git_target_dir}/testbranch.sh ] ; then
-		ln -s ${git_target_dir}/testbranch.sh /usr/local/bin/
-	fi
-fi
-
diff --git a/machinekit/scripts/900.homedir.shu b/machinekit/scripts/900.homedir.shu
deleted file mode 100755
index c87ab5b68..000000000
--- a/machinekit/scripts/900.homedir.shu
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-cd ~
-
-mkdir -p ~/.local/share
-
-cat << _EOF_ >>.bashrc
-if [ -f ~/machinekit-dev/scripts/rip-environment ]; then
-    . ~/machinekit-dev/scripts/rip-environment
-    echo "Environment set up for running Machinekit and LinuxCNC"
-fi
-
-# Set DISPLAY to point to an open X server if necessary
-#export DISPLAY=192.168.1.2:0.0
-
-_EOF_
diff --git a/machinekit/scripts/999.cleanup.shr b/machinekit/scripts/999.cleanup.shr
deleted file mode 100755
index 7cbee54db..000000000
--- a/machinekit/scripts/999.cleanup.shr
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-eval cd ~$1
-
-# Remove any kickstart tarballs
-rm kickstart.*.tar
-
-# Remove .git directory from xenomai user tools to save space
-rm -rf xenomai-2.6/.git
-
-# Remove /tmp files
-rm -rf /tmp/*
-
diff --git a/machinekit/scripts/x020.download.patch-bbio.shu b/machinekit/scripts/x020.download.patch-bbio.shu
deleted file mode 100755
index 189848a1e..000000000
--- a/machinekit/scripts/x020.download.patch-bbio.shu
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash
-
-cd ~
-
-git clone https://github.com/alexanderhiam/PyBBIO.git
-
-cd PyBBIO
-
-patch -p 1 << _EOF_
-diff --git a/bbio/config.py b/bbio/config.py
-index c399bf4..bbd61f7 100644
---- a/bbio/config.py
-+++ b/bbio/config.py
-@@ -393,8 +393,8 @@ PWM_CTRL_DIR = "/sys/class/pwm/"
- #  [mux_file, mux_mode, pwm_ctrl_dir]
-
- PWM_PINS = {
--  'PWM1A' : [ 'gpmc_a2', 0x06, 'ehrpwm.1:0/'],
--  'PWM1B' : [ 'gpmc_a3', 0x06, 'ehrpwm.1:1/']
-+#  'PWM1A' : [ 'gpmc_a2', 0x06, 'ehrpwm.1:0/'],
-+#  'PWM1B' : [ 'gpmc_a3', 0x06, 'ehrpwm.1:1/']
- }
- PWM1A = 'PWM1A'
- PWM1B = 'PWM1B'
-_EOF_
-
diff --git a/machinekit/scripts/x021.make-bbio.shr b/machinekit/scripts/x021.make-bbio.shr
deleted file mode 100755
index a2ce1bbc5..000000000
--- a/machinekit/scripts/x021.make-bbio.shr
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-eval cd ~$1/PyBBIO
-
-python setup.py install
-
diff --git a/target/chroot/machinekit-jessie.sh b/target/chroot/machinekit-jessie.sh
index b84dfa3de..74db4ba5b 100755
--- a/target/chroot/machinekit-jessie.sh
+++ b/target/chroot/machinekit-jessie.sh
@@ -337,6 +337,19 @@ install_git_repos () {
 	git_repo="https://github.com/StrawsonDesign/Robotics_Cape_Installer"
 	git_target_dir="/opt/source/Robotics_Cape_Installer"
 	git_clone
+
+	# Device tree compiler compatible with 3.8 kernels
+	git_repo="https://github.com/RobertCNelson/tools.git"
+	git_target_dir="/opt/source/tools"
+	git_clone
+# Don't try to run the build script, sudo will fail
+# Instead, run as two parts using the machinekit chroot-hook script
+#	if [ -f ${git_target_dir}/.git/config ] ; then
+#		cd ${git_target_dir}/
+#		if [ -f ${git_target_dir}/pkgs/dtc.sh ] ; then
+#			${git_target_dir}/pkgs/dtc.sh
+#		fi
+#	fi
 }
 
 install_build_pkgs () {
-- 
GitLab