diff options
author | Chris Severance | 2017-08-08 15:57:23 -0400 |
---|---|---|
committer | Chris Severance | 2017-08-08 15:57:23 -0400 |
commit | 74591c853279269137346fd9d7c1bec256053cde (patch) | |
tree | b366fbae6c531dd1ea55694671eb72d78f70f5ea | |
download | aur-74591c853279269137346fd9d7c1bec256053cde.tar.gz |
Initial Import
-rw-r--r-- | .SRCINFO | 29 | ||||
-rw-r--r-- | 0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch | 85 | ||||
-rw-r--r-- | PKGBUILD | 322 | ||||
-rw-r--r-- | moxa-uport16x0-install.sh | 78 |
4 files changed, 514 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..0f6f134552c2 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,29 @@ +# Generated by mksrcinfo v8 +# Tue Aug 8 19:57:11 UTC 2017 +pkgbase = moxa-uport16x0 + pkgdesc = kernel module driver for Moxa multi port USB serial 1250 1410 1450 1610 1650 RS-232 422 485 + pkgver = 1.2.9 + pkgrel = 1 + url = https://www.moxa.com/product/UPort_1610-8_1650-8.htm + install = moxa-uport16x0-install.sh + arch = i686 + arch = x86_64 + license = GPL + makedepends = gzip + makedepends = findutils + makedepends = sed + makedepends = diffutils + makedepends = patch + depends = setserial + depends = linux + depends = dkms + depends = linux-headers + options = !strip + backup = etc/moxa-uport16x0-settings.sh + source = http://ftp.gwdg.de/pub/opensuse/repositories/hardware/openSUSE_Tumbleweed/src/moxa-1.2.9_14103017-1.299.src.rpm + source = 0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch + sha256sums = 280ec934e6683b962e037faaa92b890608bc20701c4836954f5586c40d96f796 + sha256sums = 1243f168ed4876a5d821386b62104ae77ffddf66833cd76f21180f398d8b0608 + +pkgname = moxa-uport16x0 + diff --git a/0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch b/0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch new file mode 100644 index 000000000000..3ef8a05d5c95 --- /dev/null +++ b/0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch @@ -0,0 +1,85 @@ +--- driver/mxuport/mx-uport.c.orig 2014-10-30 03:05:36.000000000 -0400 ++++ driver/mxuport/mx-uport.c 2017-08-08 07:58:00.133293227 -0400 +@@ -2007,10 +2007,11 @@ static void mx_load_firmware(struct mxup + unsigned long txlen, fwsize, fwidx; + unsigned long dev_ver, local_ver; + unsigned char *fw_buf, *fw_tmp; + unsigned char ver_buf[4]; + ++ printk("Moxa: Upgrading firmware\n"); + #if 1 + /* + * Send vendor request - Get firmware version of SDRAM + */ + status = mx_recv_ctrl_urb(mxserial->serial->dev, +@@ -3260,20 +3261,24 @@ static int mx_recv_ctrl_urb (struct usb_ + __u16 index, + u8 *data, + int size) + { + int status; ++ u8 *pdatatmp=kmalloc(size,GFP_KERNEL); // we'll just assume this one works ++ memcpy(pdatatmp,data,size); + + status = usb_control_msg (dev, + usb_rcvctrlpipe(dev, 0), + request, + (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE), + value, + index, +- data, ++ pdatatmp, + size, + HZ * USB_CTRL_GET_TIMEOUT); ++ memcpy(data,pdatatmp,size); ++ kfree(pdatatmp); + + if (status < 0){ + dbg("%s - send usb_control_msg failed. (%d)", + __FUNCTION__, status); + return status; +@@ -3298,19 +3303,23 @@ static int mx_send_ctrl_urb (struct usb_ + __u16 index, + u8 *data, + int size) + { + int status; ++ u8 *pdatatmp=kmalloc(size,GFP_KERNEL); // we'll just assume this one works ++ memcpy(pdatatmp,data,size); + status = usb_control_msg (dev, + usb_sndctrlpipe(dev, 0), + request, + (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE), + value, + index, +- data, ++ pdatatmp, + size, + HZ * USB_CTRL_SET_TIMEOUT); ++ memcpy(data,pdatatmp,size); ++ kfree(pdatatmp); + if (status < 0){ + dbg("%s - send usb_control_msg failed. (%d)", + __FUNCTION__, status); + return status; + } +@@ -3439,14 +3448,18 @@ static int mx_write_bulkout_urb (struct + */ + static int mx_get_string (struct usb_device *dev, int Id, char *string) + { + struct usb_string_descriptor StringDesc; + struct usb_string_descriptor *pStringDesc; ++ struct usb_string_descriptor *rStringDesc = kmalloc (sizeof(*rStringDesc), GFP_KERNEL); + +- if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { ++ if (!usb_get_descriptor(dev, USB_DT_STRING, Id, rStringDesc, sizeof(*rStringDesc))) { ++ kfree(rStringDesc); + return 0; + } ++ memcpy(&StringDesc,rStringDesc,sizeof(*rStringDesc)); ++ kfree(rStringDesc); + + pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); + + if (!pStringDesc) { + return 0; diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..f7ae4958764e --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,322 @@ +# Maintainer: Chris Severance aur.severach aATt spamgourmet dott com + +# TODO: serserial port RS-422/485 setting does not stick after power loss or USB replug +# TODO: mxusbserial causes sysfs group 'power' not found for kobject 'ttyMXUSB7' + +# Installing the Moxa version lets you use setserial to change modes to RS-422 or 485 + +_opt_DKMS=1 # This can be toggled between installs + +# ls -l /dev/ttyMXUSB[0-9]* +# lsmod | grep mx +# setserial -g /dev/ttyMXUSB* + +# See /etc/moxa-uport16x0.sh to set port speed and mode to RS-422 or RS-485 + +#% dmesg | grep -iF $'mxusbserial|moxa|mx' +#1 chris@gq ~/build/moxa-uport16x0 % dmesg | grep -iF $'mxusbserial\nmoxa\nmx' +#[ 9.077859] usbcore: registered new interface driver mxusbserial +#[ 9.087250] USB Serial support registered for MOXA UPort 1200 series +#[ 9.087255] USB Serial support registered for MOXA UPort 1400 series +#[ 9.087259] USB Serial support registered for MOXA UPort 1600-8 series +#[ 9.087264] USB Serial support registered for MOXA UPort 1600-16 series +#[ 9.087275] mxuport 1-1.4:1.0: MOXA UPort 1600-8 series converter detected +#[ 9.087501] usb 1-1.4: MOXA UPort 1650-8 detected +#[ 9.087622] Moxa: Upgrading firmware +#[ 11.713663] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB0 +#[ 11.713717] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB1 +#[ 11.713770] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB2 +#[ 11.713821] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB3 +#[ 11.713870] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB4 +#[ 11.713920] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB5 +#[ 11.713970] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB6 +#[ 11.713996] usb 1-1.4: MOXA UPort 1600-8 series converter now attached to ttyMXUSB7 +#[ 11.714007] usbcore: registered new interface driver mxuport +#[ 11.714008] MOXA UPort series driver v1.2.9 + +_modulenames=('mxusbserial' 'mxuport') # mxusbserial must be listed first +#_modulenames=('mxusbserial' 'mxuport16x0') # mxusbserial must be listed first +_origmodname=('mxuport') + +set -u +pkgname='moxa-uport16x0' +_servicename="${pkgname}-settings" +pkgver='1.2.9'; _build='14103017' +#pkgver='1.2'; _build='12071314' +pkgrel='1' +pkgdesc='kernel module driver for Moxa multi port USB serial 1250 1410 1450 1610 1650 RS-232 422 485' +_servicedesc='Moxa UPort persistent settings' +arch=('i686' 'x86_64') +url='https://www.moxa.com/product/UPort_1610-8_1650-8.htm' +#url='https://github.com/uecasm/mxser' +#url='https://pkgs.org/download/moxa-kmp-default' +#url='https://www.moxa.ru/forum/index.php?/topic/25005-drajver-dlia-moxa-uport-1250-dlia-linux-iadro-316/' +license=('GPL') +depends=('setserial') +makedepends=('gzip' 'findutils' 'sed' 'diffutils' 'patch') +backup=("etc/${_servicename}.sh") +options=('!strip') +install="${pkgname}-install.sh" +_srcdir='mxuport' +source=( + #"https://www.moxa.com/drivers/UPort/U12_14_1600/Linux2.6/V1.2/driv_linux_uport_v${pkgver}_build_${_build}.tgz" + "http://ftp.gwdg.de/pub/opensuse/repositories/hardware/openSUSE_Tumbleweed/src/moxa-${pkgver}_${_build}-1.299.src.rpm" + '0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch' +) +sha256sums=('280ec934e6683b962e037faaa92b890608bc20701c4836954f5586c40d96f796' + '1243f168ed4876a5d821386b62104ae77ffddf66833cd76f21180f398d8b0608') + +if [ "${_opt_DKMS}" -ne 0 ]; then + depends+=('linux' 'dkms' 'linux-headers') +else + makedepends+=('linux-headers') +fi + +# Moxa https doesn't work with curl +for _dlagentk in "${!DLAGENTS[@]}"; do + case "${DLAGENTS[${_dlagentk}]}" in + 'https::/'*) DLAGENTS[${_dlagentk}]="${DLAGENTS[${_dlagentk}]//\/curl -/\/curl -k}";; + esac +done + +# We can't modify .install but we can stop and force the user to fix it. +_install_check() { + local _ckvar + local _ckline + local _pkgname="${pkgname}" + for _ckvar in _pkgname _modulenames _origmodname _servicename; do + _ckline="$(declare -p ${_ckvar} 2>/dev/null)" + _ckline="${_ckline#* }" + _ckline="${_ckline#* }" + _ckline="${_ckline//\[[0-9]\]=/}" # unenumerate arrays + _ckline="${_ckline//\"/\'}" + if ! grep -q "^${_ckline}"'$' "${startdir}/${install}"; then + set +u + msg "${install} must be fixed" + echo "${_ckline}" + false + fi + done +} + +# All the firmwares were changed which makes the patch too large to be useful +_make_patch() { + cd "${startdir}" + rm -rf 'makepatch' + mkdir 'makepatch' + cd 'makepatch' + bsdtar -xf '../driv_linux_uport_v1.2_build_12071314.tgz' + mv 'mxuport'{,-1.2} + bsdtar -xf '../driv_linux_uport_v1.2.9_build_14103017.tgz' + mv 'mxuport'{,-1.2.9} + sed -e 's:\r$::g' -i $(grep -rlFe $'\r') + diff -pNaru5 mxuport-{1.2,1.2.9} > '../0000-mxuport-1.2-1.2.9.patch' || : + cd .. + rm -r 'makepatch' + #patch -Nbup2 < '../0000-mxuport-1.2-1.2.9.patch' + set +u + false +} + +prepare() { + set -u + #_make_patch + _install_check + + bsdtar -xf "driv_linux_uport_v${pkgver}_build_${_build}.tgz" + + cd "${_srcdir}" + + rm 'driver/mxconf' + + sed -e 's:\s*\r$::g' -i $(grep -rlFe $'\r') + + # diff -pNau5 driver/mxuport/mx-uport.c{.orig,} > '0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch' + patch -Nbup0 < '../0001-kernel-4.9-no-dma-on-stack-transfer-buffer-not-dma-capable.patch' + + # Make package compatible + # cp -p driver/Makefile{,.Arch} + sed -e '# Remove pesky blank line. n messes up the positioning so we do it separately' \ + -e '/^modules:/ {n; d}' \ + -i 'driver/Makefile' + sed -e '# Fix path' \ + -e 's:/lib/:/usr/lib/:g' \ + -e '# Get rid of useless var' \ + -e 's:^REL_DATE:# &:g' \ + -e '# Get rid of useless var' \ + -e 's:^KDISVER:# &:g' \ + -e '# Disable Fedora hack' \ + -e '/Fedora/,/^endif/ s:^:#:g' \ + -e '# Remove leading @ to prevent silent execution' \ + -e 's:^\t@:\t:g' \ + -e '# Disable envchk' \ + -e '/^module/ s:envchk::g' \ + -e '# Remove build log helper that hides output' \ + -e '/^\t\$(MAKE)/ s:\s\+2>>.\+$::g' \ + -e '# Disable all make lines' \ + -e '/^modules:/,/^$/ s:^\t:#\t:g' \ + -e '# Reenable module targets' \ + -e '/^#modules:/ s:^#::g' \ + -e '# Reenable make line' \ + -e '/^#\t\$(MAKE/ s:^#\t:\t:g' \ + -e '# Fix install lines' \ + -e '# Dont remake modules on install' \ + -e '/^install/ s:modules::g' \ + -e '# Make package compatible' \ + -e '/^install/,/^$/ s:/usr/:"$(DESTDIR)"&:g' \ + -e '# Disable depmod' \ + -e 's:^\tdepmod:\ttrue depmod:g' \ + -i 'driver/Makefile' + sed -e '# Fix path' \ + -e 's:/lib/:/usr/lib/:g' \ + -e '# Get rid of KDIS' \ + -e 's:^KDISVER:# &:g' \ + -e '# Disable Fedora hack' \ + -e '/Fedora/,/^endif/ s:^:#:g' \ + -e '# Remove leading @ to prevent silent execution' \ + -e 's:^\t@:\t:g' \ + -e '# Fix install lines' \ + -e '# Dont remake modules on install' \ + -e 's@^\(install:\).*$@\1@g' \ + -e '# Make package compatible' \ + -e '/^install/,/^$/ s:/usr/:"$(DESTDIR)"&:g' \ + -e '# Disable depmod' \ + -e 's:^\tdepmod:\ttrue depmod:g' \ + -i driver/{mxusbserial,mxuport}/Makefile + sed -e '# Forgot to clean something' \ + -e 's/^clean:$/&\n\trm -f .mx*.o.d/g' \ + -e '# This make modules is never used so it contains a bug' \ + -e '/^\t\$(MAKE)/ {s: -EXTRA: EXTRA:g; s: C : -C :g}'\ + -i 'driver/mxusbserial/Makefile' + + # Change module name + if [ "${_modulenames[1]}" != "${_origmodname}" ]; then + sed -e "s:\"${_origmodname}\":\"${_modulenames[1]}\":g" -i 'driver/mxuport/mx-uport.c' + sed -e "/^TARGET/ s:${_origmodname}:${_modulenames[1]}:g" -i 'driver/mxuport/Makefile' + fi + set +u +} + +build() { + set -u + cd "${_srcdir}" + make -C 'driver' -j1 # too small for parallel make + set +u +} + +package() { + set -u + cd "${_srcdir}" + + make -C 'driver' -s -j1 install DESTDIR="${pkgdir}" + + local _driverfd='/updates' + if [ "${_modulenames[1]}" != "${_origmodname}" ]; then + # Don't install twice + rm -r "${pkgdir}/usr/lib/modules/$(uname -r)/misc" + # Blacklist exiting incomplete built in module + install -Dm644 <(cat << EOF +# Do not load built in module with only barebones support +blacklist ${_origmodname} +EOF + ) "${pkgdir}/etc/modprobe.d/${pkgname}.conf" + _driverfd='/kernel/drivers/usb/serial' + else + # Don't install twice + rm -r "${pkgdir}/usr/lib/modules/$(uname -r)/kernel" + # The new driver is the same name as the built in driver so put it in updates + mv "${pkgdir}/usr/lib/modules/$(uname -r)"/{misc,updates} + fi + + # Install persistent settings service + install -Dm644 <(cat << EOF +# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR +# https://aur.archlinux.org/ + +[Unit] +Description=${_servicedesc} +#After=sysinit.target +After=local-fs.target + +[Service] +Type=notify +ExecStart=/usr/bin/bash -c 'source /etc/${_servicename}.sh; systemd-notify --ready' +RemainAfterExit=yes + +[Install] +WantedBy=network.target +EOF + ) "${pkgdir}/usr/lib/systemd/system/${_servicename}.service" + + install -Dm644 <(cat << EOF +# From readme.txt + +#4. Setserial + +# Supported Setserial parameters are listed as below. + +# port use for change port interface +# 0x3 RS-485 4W +# 0x2 RS-422 +# 0x1 RS-485 2W +# 0x0 RS-232 + +# spd_hi Use 57.6kb when the application requests 38.4kb. +# spd_vhi Use 115.2kb when the application requests 38.4kb. +# spd_shi Use 230kb when the application requests 38.4kb. +# spd_warp Use 460kb when the application requests 38.4kb. +# spd_normal Use 38.4kb when the application requests 38.4kb. + +# [Example] + +# i) The following command sets interface of "/dev/ttyMXUSB0" to RS-422. + +# # setserial /dev/ttyMXUSB0 port 0x2 + +# ii) Lookup the serial settings of current port. + +# # setserial -g /dev/ttyMXUSB0 +EOF + ) "${pkgdir}/etc/${_servicename}.sh" + + # The module is in the same folder as DKMS. Compress to a different name to prevent conflict. + # When future versions of DKMS compress we'll stop doing this. + find "${pkgdir}/usr/lib/modules/" -type 'f' -name '*.ko' -exec 'gzip' '-9' '{}' ';' + + if [ "${_opt_DKMS}" -ne 0 ]; then + rm -r "${pkgdir}/usr/lib/modules/" + local _dkms="${pkgdir}/usr/src/${pkgname}-${pkgver}" + install -Dm644 <(cat << EOF +# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR +# https://aur.archlinux.org/ + +PACKAGE_NAME="${pkgname}" +PACKAGE_VERSION="${pkgver}" +AUTOINSTALL="yes" +# MAKE[0] is expected to make all modules with an umbrella makefile +MAKE[0]="make -C driver -j1" + +BUILT_MODULE_NAME[0]="${_modulenames[0]}" +BUILT_MODULE_LOCATION[0]="driver/${_modulenames[0]}" +# The install version is .ko.gz. The DKMS version is .ko. No conflicts. +DEST_MODULE_LOCATION[0]="${_driverfd}" + +BUILT_MODULE_NAME[1]="${_modulenames[1]}" +BUILT_MODULE_LOCATION[1]="driver/${_origmodname}" +# The install version is .ko.gz. The DKMS version is .ko. No conflicts. +DEST_MODULE_LOCATION[1]="${_driverfd}" +EOF + ) "${_dkms}/dkms.conf" + cp -pr 'driver/' "${_dkms}/" + sed -e 's:shell uname -r:KERNELRELEASE:g' \ + -e '# DKMS sets KERNELRELEASE which accidentally launches phase 2 of this Makefile' \ + -e '# Fix by changing the detection var.' \ + -e '# SUBDIRS makes more sense to me because I can see it in the Makefile!' \ + -e 's:^ifneq (\$(KERNELRELEASE),):ifneq (\$(SUBDIRS),):g' \ + -i "${_dkms}/driver/Makefile" + make -s -C "${_dkms}/driver/" clean_local KERNELRELEASE="$(uname -r)" + fi + set +u +} + +set +u diff --git a/moxa-uport16x0-install.sh b/moxa-uport16x0-install.sh new file mode 100644 index 000000000000..1ec6f61afc27 --- /dev/null +++ b/moxa-uport16x0-install.sh @@ -0,0 +1,78 @@ +_pkgname='moxa-uport16x0' +_modulenames=('mxusbserial' 'mxuport') +_origmodname=('mxuport') +_servicename='moxa-uport16x0-settings' +_modulenamesr=() +for (( _idx=${#_modulenames[@]}-1 ; _idx >= 0; _idx-- )); do + _modulenamesr+=("${_modulenames[${_idx}]}") +done +unset _idx + +pre_upgrade() { + set -u + systemctl disable "${_servicename}.service" + if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then + local _modulename + for _modulename in "${_modulenamesr[@]}"; do + rmmod "${_modulename}" + done + fi + set +u +} + +post_upgrade() { + set -u + if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then + depmod -a + rmmod "${_origmodname}" 2> /dev/null # blacklisted on boot + local _modulename + for _modulename in "${_modulenames[@]}"; do + if ! lsmod | cut -d' ' -f1 | grep -q "^${_modulename}"'$'; then + #echo 'Reboot or load now with:' + #echo " sudo modprobe '${_modulename}'" + modprobe "${_modulename}" + fi + done + else + echo 'Once installed the new driver can be loaded with' + echo " sudo rmmod ${_origmodname}$(printf '; sudo modprobe %s' "${_modulenames[@]}")" + fi + systemctl daemon-reload + systemctl enable "${_servicename}.service" + set +u +} + +post_install() { + set -u + post_upgrade + # Doesn't do any good to start it. After install there's nothing in it. + # systemctl start "${_servicename}.service" + set +u +} + +pre_remove() { + set -u + if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then + local _modulename + for _modulename in "${_modulenamesr[@]}"; do + rmmod "${_modulename}" + done + fi + systemctl disable "${_servicename}.service" + if [ -d "/usr/src/${_pkgname}"-*/ ]; then + # dkms remove runs before this so we could run these automatically but that might interrupt services + echo 'Once removed the old driver can be loaded with' + echo " $(printf 'sudo rmmod %s; ' "${_modulenamesr[@]}")sudo modprobe ${_origmodname}" + fi + set +u +} + +post_remove() { + set -u + systemctl daemon-reload + if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then + depmod -a + modprobe "${_origmodname}" + fi + set +u +} |