pru: Update installation and flash scripts
Update the scripts used to install and "flash" the pru micro-controller code. Also, add a "flash" script for the linux micro-controller code. This makes it easier to install Klipper on a Beaglebone board that uses a Replicape. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
16d2ec3a90
commit
5a85c1667a
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# This script installs the Linux MCU code to /usr/local/bin/
|
||||||
|
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "This script must be run as root"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Install new micro-controller code
|
||||||
|
echo "Installing mirco-controller code to /usr/local/bin/"
|
||||||
|
rm -f /usr/local/bin/klipper_mcu
|
||||||
|
cp out/klipper.elf /usr/local/bin/klipper_mcu
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Restart (if system install script present)
|
||||||
|
if [ -f /etc/init.d/klipper_pru ]; then
|
||||||
|
echo "Attempting host MCU restart..."
|
||||||
|
service klipper_pru restart
|
||||||
|
fi
|
|
@ -13,18 +13,8 @@ cp out/pru0.elf /lib/firmware/am335x-pru0-fw
|
||||||
cp out/pru1.elf /lib/firmware/am335x-pru1-fw
|
cp out/pru1.elf /lib/firmware/am335x-pru1-fw
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# Shutdown existing Klipper instance (if applicable). The goal is to
|
# Restart (if system install script present)
|
||||||
# put the GPIO pins in a safe state.
|
if [ -f /etc/init.d/klipper_pru ]; then
|
||||||
if [ -c /dev/rpmsg_pru30 ]; then
|
echo "Attempting PRU restart..."
|
||||||
echo "Attempting to shutdown existing firmware..."
|
service klipper_pru restart
|
||||||
( echo "FORCE_SHUTDOWN" > /dev/rpmsg_pru30 ) 2> /dev/null || ( echo "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
|
||||||
sleep 1
|
|
||||||
( echo "FORCE_SHUTDOWN" > /dev/rpmsg_pru30 ) 2> /dev/null || ( echo "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
|
||||||
sleep 1
|
|
||||||
fi
|
fi
|
||||||
set +e
|
|
||||||
|
|
||||||
# Restart the PRU
|
|
||||||
echo "Restarting pru_rproc module"
|
|
||||||
rmmod -f pru_rproc
|
|
||||||
modprobe pru_rproc
|
|
||||||
|
|
|
@ -33,10 +33,17 @@ install_udev()
|
||||||
{
|
{
|
||||||
report_status "Installing pru udev rule..."
|
report_status "Installing pru udev rule..."
|
||||||
sudo /bin/sh -c "cat > /etc/udev/rules.d/pru.rules" <<EOF
|
sudo /bin/sh -c "cat > /etc/udev/rules.d/pru.rules" <<EOF
|
||||||
KERNEL=="rpmsg_pru30", MODE="0666"
|
KERNEL=="rpmsg_pru30", GROUP="tty", MODE="0660"
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Step 5: Add user to tty group
|
||||||
|
install_groups()
|
||||||
|
{
|
||||||
|
report_status "Adding $USER to tty group..."
|
||||||
|
sudo adduser $USER tty
|
||||||
|
}
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
report_status()
|
report_status()
|
||||||
{
|
{
|
||||||
|
@ -63,3 +70,4 @@ install_main
|
||||||
install_packages
|
install_packages
|
||||||
install_script
|
install_script
|
||||||
install_udev
|
install_udev
|
||||||
|
install_groups
|
||||||
|
|
|
@ -14,23 +14,98 @@
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
DESC="klipper_pru startup"
|
DESC="klipper_pru startup"
|
||||||
NAME="klipper_pru"
|
NAME="klipper_pru"
|
||||||
|
KLIPPER_HOST_MCU=/usr/local/bin/klipper_mcu
|
||||||
|
KLIPPER_HOST_ARGS="-w -r"
|
||||||
|
PIDFILE=/var/run/klipper_mcu.pid
|
||||||
|
|
||||||
. /lib/lsb/init-functions
|
. /lib/lsb/init-functions
|
||||||
|
|
||||||
|
pru_stop()
|
||||||
|
{
|
||||||
|
# Shutdown existing Klipper instance (if applicable). The goal is to
|
||||||
|
# put the GPIO pins in a safe state.
|
||||||
|
if [ -c /dev/rpmsg_pru30 ]; then
|
||||||
|
log_daemon_msg "Attempting to shutdown PRU..."
|
||||||
|
set -e
|
||||||
|
( echo "FORCE_SHUTDOWN" > /dev/rpmsg_pru30 ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
||||||
|
sleep 1
|
||||||
|
( echo "FORCE_SHUTDOWN" > /dev/rpmsg_pru30 ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
||||||
|
sleep 1
|
||||||
|
set +e
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_daemon_msg "Stopping pru"
|
||||||
|
echo 4a334000.pru0 > /sys/bus/platform/drivers/pru-rproc/unbind
|
||||||
|
echo 4a338000.pru1 > /sys/bus/platform/drivers/pru-rproc/unbind
|
||||||
|
}
|
||||||
|
|
||||||
|
pru_start()
|
||||||
|
{
|
||||||
|
if [ -c /dev/rpmsg_pru30 ]; then
|
||||||
|
pru_stop
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_daemon_msg "Starting pru"
|
||||||
|
echo 4a334000.pru0 > /sys/bus/platform/drivers/pru-rproc/bind
|
||||||
|
echo 4a338000.pru1 > /sys/bus/platform/drivers/pru-rproc/bind
|
||||||
|
}
|
||||||
|
|
||||||
|
mcu_host_stop()
|
||||||
|
{
|
||||||
|
# Shutdown existing Klipper instance (if applicable). The goal is to
|
||||||
|
# put the GPIO pins in a safe state.
|
||||||
|
if [ -c /tmp/klipper_host_mcu ]; then
|
||||||
|
log_daemon_msg "Attempting to shutdown host mcu..."
|
||||||
|
set -e
|
||||||
|
( echo "FORCE_SHUTDOWN" > /tmp/klipper_host_mcu ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
||||||
|
sleep 1
|
||||||
|
( echo "FORCE_SHUTDOWN" > /tmp/klipper_host_mcu ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
|
||||||
|
sleep 1
|
||||||
|
set +e
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_daemon_msg "Stopping klipper host mcu" $NAME
|
||||||
|
killproc -p $PIDFILE $KLIPPER_HOST_MCU
|
||||||
|
}
|
||||||
|
|
||||||
|
mcu_host_start()
|
||||||
|
{
|
||||||
|
[ -x $KLIPPER_HOST_MCU ] || return
|
||||||
|
|
||||||
|
if [ -c /tmp/klipper_host_mcu ]; then
|
||||||
|
mcu_host_stop
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_daemon_msg "Starting klipper MCU" $NAME
|
||||||
|
start-stop-daemon --start --quiet --exec $KLIPPER_HOST_MCU \
|
||||||
|
--background --pidfile $PIDFILE --make-pidfile \
|
||||||
|
-- $KLIPPER_HOST_ARGS
|
||||||
|
log_end_msg $?
|
||||||
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start) log_daemon_msg "Starting klipper_pru" $NAME
|
start)
|
||||||
# Enable ADC module
|
pru_start
|
||||||
echo 'BB-ADC' > /sys/devices/platform/bone_capemgr/slots
|
mcu_host_start
|
||||||
# Start PRU firmware
|
;;
|
||||||
if [ ! -c /dev/rpmsg_pru30 ]; then
|
stop)
|
||||||
rmmod -f pru_rproc
|
pru_stop
|
||||||
modprobe pru_rproc
|
mcu_host_stop
|
||||||
fi
|
;;
|
||||||
;;
|
restart)
|
||||||
stop|restart|reload|force-reload|status)
|
$0 stop
|
||||||
;;
|
$0 start
|
||||||
*) log_action_msg "Usage: /etc/init.d/klipper_pru {start|stop|status|restart|reload|force-reload}"
|
;;
|
||||||
exit 2
|
reload|force-reload)
|
||||||
;;
|
log_daemon_msg "Reloading configuration not supported" $NAME
|
||||||
|
log_end_msg 1
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
status_of_proc -p $PIDFILE $KLIPPER_HOST_MCU $NAME && exit 0 || exit $?
|
||||||
|
;;
|
||||||
|
*) log_action_msg "Usage: /etc/init.d/klipper {start|stop|status|restart|reload|force-reload}"
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -7,3 +7,7 @@ src-y += linux/pca9685.c linux/spidev.c linux/analog.c
|
||||||
src-y += generic/crc16_ccitt.c generic/alloc.c
|
src-y += generic/crc16_ccitt.c generic/alloc.c
|
||||||
|
|
||||||
CFLAGS_klipper.elf += -lutil
|
CFLAGS_klipper.elf += -lutil
|
||||||
|
|
||||||
|
flash: $(OUT)klipper.elf
|
||||||
|
@echo " Flashing"
|
||||||
|
$(Q)sudo ./scripts/flash-linux.sh
|
||||||
|
|
Loading…
Reference in New Issue