# Build Digi RealPort (dgrp) drivers for Beaglebone/Angstrom

# Using Angstrom 3.2.18 kernel, customized oebb cloud9 image
# Building dgrp driver (kernel module) requires kernel headers and other packages
# In 3.2.X Angstrom distro, an extra header file must be included in some 
# of the digi sources.

# Basic process outline:
# - install required packages
# - upgrade packages (see notes-angstrom-bbone-opkg-upgrade-v0.rtf)
# - generate kernel scripts
# - download the dgrp driver sources
# - make required symlinks
# - patch the dgrp source files (add missing header - not needed in 3.8.x kernel)
# - make and install the dgrp driver and utils

# The procedure below for building dgrp drivers seems to work for 3.2.18 and the more # recent 3.8.13 kernels

# References
http://www.ing.iac.es/~docs/external/realport/rp-linux-frameset.html
http://www.digi.com/support/kbase/kbaseresultdetl?id=170

# update (not upgrade) package list
sudo opkg update

# install packages needed to build kernel modules
sudo opkg install coreutils
sudo opkg install kernel-headers
sudo opkg install kernel-dev
sudo opkg install module-init-tools-depmod
sudo opkg install update-rc.d 
sudo opkg install update-modules update-modules-dev

# if those aren't enough, may also need these
update-rc.d-dev update-rc.d-dbg
update-modules-dbg

cd /usr/src/kernel/
sudo make scripts

# using a build directory.../home/user/build
cd /home/user/build/

# get the digi driver sources and
# unpack them
wget http://ftp1.digi.com/support/driver/81000137_U.tgz
tar xzvf 81000137_U.tgz

cd dgrp-1.9/

# make symlinks
ln -s /usr/src/kernel/ /home/user/build/dgrp-1.9/linux-3.2.18
sudo ln -s /usr/src/kernel /lib/modules/3.2.18/build

# For 3.2.18 [not required in 3.8.x]
# add this header include:

    #include <linux/uaccess.h>

# to these dgrp source files:
dgrp-1.9/driver/build/dgrp_mon_ops.c 
dgrp-1.9/driver/build/dgrp_ports_ops.c 
dgrp-1.9/driver/build/dgrp_specproc.c 
dgrp-1.9/driver/build/dgrp_tty.c 

# build the driver
./configure
make

# install the driver
sudo make install

# among other things, should install
/usr/bin/dgrp_udev
/usr/bin/dgrp/config/dgrp_gui
/usr/bin/dgrp/config/dgrp_cfg_node
/usr/bin/dgrp/daemon/drpd
/lib/modules/3.2.18/misc/dgrp.ko

# to create /dev filesystem symlinks with correct permissions, create (as root) a
# udev rules file
      /etc/udev/rules.d/10-dgrp.rules 
# containing
KERNEL=="tty_dgrp*", PROGRAM="/usr/bin/dgrp_udev %k", SYMLINK+="%c", TAG="systemd"
KERNEL=="cu_dgrp*", PROGRAM="/usr/bin/dgrp_udev %k", SYMLINK+="%c", TAG="systemd"
KERNEL=="pr_dgrp*", PROGRAM="/usr/bin/dgrp_udev %k", SYMLINK+="%c", TAG="systemd"

# reboot the system
sudo /sbin/reboot

# initialize a digi real port 
# example: a digi TS-4 with hostname mydigi.mynet.org
# ownerID: 500 (id)
# groupID 20 (dialout)
# portID XF (for /dev/ttyXFnn)

sudo /usr/bin/dgrp/dgrp_cfg_node -v -e never -m 664 -o 500 -g 20 init XF mydigi.mynet.org 4

# creates device nodes
/dev/dgrp_tty_XF_0
/dev/dgrp_tty_XF_1
/dev/dgrp_tty_XF_2
/dev/dgrp_tty_XF_3

# pointed to by symlinks 
/dev/ttyXF00
/dev/ttyXF01
/dev/ttyXF02
/dev/ttyXF03

##############
##############
This note appears in the dgrp release notes.
Not tested, but maybe this is all that is needed to make from source
and would resolve build issues on 3.2.18, though the procedure above seems
to work

 o If you are running a prebuilt kernel from a packaged distribution,
       this typically involves loading the kernel sources from your
       distribution CD to your system, then using the following commands
       to do the following:

       1. cd /usr/src/linux-<your_version_of_the_kernel>
       2. make mrproper           Clean up any old version files.
       3. make oldconfig          Make a configuration file to match
                                  your running kernel.
       4. make dep                Create the dependency and version files.

       Now you can load and build the dgrp driver package.