# Build digi realport drivers for Beaglebone/Angstrom

# Initially, had 3.2.18 kernel, but 3.2.42 kernel headers.
# Used opkg upgrade to update kernel to 3.2.42 
# (TODO: build 3.2.42 in OEBB)

# References
http://www.ing.iac.es/~docs/external/realport/rp-linux-frameset.html
http://elene.dahners.com/blog/2012/10/22/compiling-a-kernel-module-for-beaglebone/

# download the digi realport driver TGZ source
# digi > support > PortServer > TS1/2/4 > Drivers > Debian 6.0
http://ftp1.digi.com/support/driver/81000137_U.tgz

# unpack them to some build directory e.g. ~/build/
# [creates ~/build/dgrp-1.9]
cd ~//build
tar xzvf 81000137_U.tgz

# use opkg to install the following packages
# these are needed to build/install other
# (kernel?) packages
sudo opkg install 
update-rc.d
update-rc.d-dbg
update-modules
update-modules-dbg
module-init-tools-depmod
module-init-tools-depmod-dbg 
module-init-tools-depmod-dev

# update opkg repo lists
sudo opkg update

# Update all packages (includes kernel)
# A number of websites indicated that this may be 
# buggy, with reports of not being able to reboot, etc.
# Experienced a couple off problems (e.g. missing depmod, bad path dbus-1 postinstall)
sudo opkg --tmp-dir ~/build/tmp upgrade
fix  /var/lib/opkg/info/dbus-1.postinst : (path to rc-update.d: /usr/sbin (or PATH?))
sudo opkg --tmp-dir ~/build/tmp upgrade

# create sym links to the kernel directory in the 
# digi build directory
ln -s /usr/src/kernel ~/build/dgrp-1.9/linux-3.2.42

ln -s /usr/src/kernel /lib/modules//linux-3.2.42/build

sudo make scripts
sudo make modules

Fix broken driver includes
add
#include <linux/uaccess.h>
to dgrp source files:
  driver/build/dgrp_mon_ops.c 
  driver/build/dgrp_ports_ops.c 
  driver/build/dgrp_specproc.c 
  driver/build/dgrp_tty.c 

# missing depmod errors
/mnt/xfoce/tmp/opkg-fPELEI/opkg-intercept-HkPBLA/update-modules: line 1: update-modules: command not found
/mnt/xfoce/tmp/opkg-fPELEI/opkg-intercept-HkPBLA/depmod: line 1: depmod: command not found
/mnt/xfoce/tmp/opkg-fPELEI/opkg-intercept-HkPBLA/depmod: line 2: depmod: command not found
/mnt/xfoce/tmp/opkg-fPELEI/opkg-intercept-HkPBLA/depmod: line 3: depmod: command not found

# bad path in dbus-1 postinst errors
Collected errors:
 * pkg_run_script: package "dbus-1" postinst script returned status 127.
 * opkg_configure: dbus-1.postinst returned 127.