From ea3a12bd1fad8c8acf4d0cded746c7f6ffc69cb5 Mon Sep 17 00:00:00 2001
From: Tien Hock Loh <thloh@pg-thloh-lv1.altera.com>
Date: Mon, 23 Jun 2014 03:28:38 +0800
Subject: [PATCH] TSE example design yocto

---
 .../recipes-core/images/altera-tse-image.bb        |   20 +++++++
 meta-altera/recipes-kernel/linux/linux-altera.inc  |    2 +
 .../initscripts-altera-tse/files/tse_init.sh       |   57 ++++++++++++++++++++
 .../initscripts-altera-tse_1.0.bb                  |   21 +++++++
 .../iperf/iperf-2.0.5/iperf-2.0.5_ManPage.patch    |    8 +++
 meta-altera/recipes-tse/iperf/iperf_2.0.5.bb       |   18 ++++++
 meta-altera/scripts/altera-setup-builddir          |    1 +
 7 files changed, 127 insertions(+), 0 deletions(-)
 create mode 100755 meta-altera/recipes-core/images/altera-tse-image.bb
 create mode 100644 meta-altera/recipes-tse/initscripts-altera-tse/files/tse_init.sh
 create mode 100644 meta-altera/recipes-tse/initscripts-altera-tse/initscripts-altera-tse_1.0.bb
 create mode 100755 meta-altera/recipes-tse/iperf/iperf-2.0.5/iperf-2.0.5_ManPage.patch
 create mode 100755 meta-altera/recipes-tse/iperf/iperf_2.0.5.bb

diff --git a/meta-altera/recipes-core/images/altera-tse-image.bb b/meta-altera/recipes-core/images/altera-tse-image.bb
new file mode 100755
index 0000000..5f878db
--- /dev/null
+++ b/meta-altera/recipes-core/images/altera-tse-image.bb
@@ -0,0 +1,20 @@
+
+DESCRIPTION = "The set of packages for development and testing provided by Altera"
+
+LICENSE = "BSD-3-Clause"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9"
+
+ALTERA_IMAGE_INSTALL ?= "util-linux initramfs-altera kernel-modules netbase	\
+	busybox base-passwd base-files tinylogin sysvinit initscripts e2fsprogs	\
+	mtd-utils gdb gdbserver bash strace openssh openssl elfutils sysfsutils	\
+	usbutils dtc gawk ethtool grep lighttpd iputils make pciutils portmap	\
+	sed setserial wget autoconf diffutils perl minicom valgrind i2c-tools	\
+	iptables oprofile gator openssh-sftp-server memtool nfs-utils-client	\
+	net-tools iperf initscripts-altera-tse"
+IMAGE_INSTALL ?= "${ALTERA_IMAGE_INSTALL}"
+
+inherit core-image
+
+# altera-image.inc must be included after inherit core-image to override functionality
+
+include altera-image.inc
diff --git a/meta-altera/recipes-kernel/linux/linux-altera.inc b/meta-altera/recipes-kernel/linux/linux-altera.inc
index 7625f83..c925220 100755
--- a/meta-altera/recipes-kernel/linux/linux-altera.inc
+++ b/meta-altera/recipes-kernel/linux/linux-altera.inc
@@ -30,6 +30,8 @@ do_configure() {
 	
 	cp .config .config.ori
 
+	# We assume that the TSE driver is not set in any way in your .config
+	grep CONFIG_ALTERA_TSE\= .config || echo "CONFIG_ALTERA_TSE=m" >> .config
 	grep CONFIG_BLK_DEV_INITRD .config || echo "CONFIG_BLK_DEV_INITRD=y" >> .config
 	grep CONFIG_INITRAMFS_SOURCE .config || echo "CONFIG_INITRAMFS_SOURCE=\"\"" >> .config
 	grep CONFIG_INITRAMFS_ROOT_UID .config || echo "CONFIG_INITRAMFS_ROOT_UID=0" >> .config
diff --git a/meta-altera/recipes-tse/initscripts-altera-tse/files/tse_init.sh b/meta-altera/recipes-tse/initscripts-altera-tse/files/tse_init.sh
new file mode 100644
index 0000000..9c0dde4
--- /dev/null
+++ b/meta-altera/recipes-tse/initscripts-altera-tse/files/tse_init.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# Copyright 2014 Altera Corporation. All Rights Reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO
+# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# OF SUCH DAMAGE.
+
+
+case "$1" in
+  start)
+	if [ "`cat /sys/class/fpga/fpga0/status`" == "user mode" ]; then
+		modprobe altera_tse
+		if [ $? -ne 0 ]; then
+			echo "Error: Failed to load module altera_tse"
+		else
+			for interface in eth1 eth2
+			do
+				ifconfig $interface up
+				if [ $? -eq 0 ]; then
+					# Retries 2 times, timeout 2 seconds and
+					# run in background if lease is not obtained
+					udhcpc -i $interface -t 2 -T 2 -b
+				fi
+			done
+		fi
+	else
+		echo "Error: FPGA not in user mode. Unable to load altera_tse driver"
+	fi
+	;;
+  stop)
+	rmmod altera_tse
+	if [ $? -ne 0 ]; then
+		echo "Error: Failed to load module altera_tse"
+	fi
+	;;
+esac
diff --git a/meta-altera/recipes-tse/initscripts-altera-tse/initscripts-altera-tse_1.0.bb b/meta-altera/recipes-tse/initscripts-altera-tse/initscripts-altera-tse_1.0.bb
new file mode 100644
index 0000000..c03a808
--- /dev/null
+++ b/meta-altera/recipes-tse/initscripts-altera-tse/initscripts-altera-tse_1.0.bb
@@ -0,0 +1,21 @@
+DESCRIPTION = "Altera TSE example design init script"
+SECTION = "ed"
+LICENSE = "BSD-3-Clause"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9"
+PR = "r0"
+inherit update-rc.d
+SRC_URI = "file://tse_init.sh"
+FILES_${PN} += "${sysconfdir}"
+CONFFILES_${PN} = "${sysconfdir}/tse_init.sh"
+INITSCRIPT_NAME = "tse_init.sh"
+INITSCRIPT_PARAMS = "defaults 90"
+
+S = "${WORKDIR}"
+
+do_configure() {
+}
+
+do_install() {
+	install -d ${D}${sysconfdir}/init.d
+	install -m 0755 ${WORKDIR}/tse_init.sh ${D}${sysconfdir}/init.d
+}
diff --git a/meta-altera/recipes-tse/iperf/iperf-2.0.5/iperf-2.0.5_ManPage.patch b/meta-altera/recipes-tse/iperf/iperf-2.0.5/iperf-2.0.5_ManPage.patch
new file mode 100755
index 0000000..12e8f46
--- /dev/null
+++ b/meta-altera/recipes-tse/iperf/iperf-2.0.5/iperf-2.0.5_ManPage.patch
@@ -0,0 +1,8 @@
+diff --git iperf-2.0.5/man/Makefile.am iperf-2.0.5/man/Makefile.am
+ index ed97bc6..728873f 100644
+--- iperf-2.0.5/man/Makefile.am
++++ iperf-2.0.5/man/Makefile.am
+@@ -1,2 +1 @@
+-man_MANS = iperf.1
+-dist_man_MANS = $(man_MANS)
++dist_man_MANS = iperf.1
diff --git a/meta-altera/recipes-tse/iperf/iperf_2.0.5.bb b/meta-altera/recipes-tse/iperf/iperf_2.0.5.bb
new file mode 100755
index 0000000..a207716
--- /dev/null
+++ b/meta-altera/recipes-tse/iperf/iperf_2.0.5.bb
@@ -0,0 +1,18 @@
+DESCRIPTION = "Iperf is a tool to measure maximum TCP bandwidth, allowing the tuning of various parameters and UDP characteristics"
+HOMEPAGE = "http://dast.nlanr.net/Projects/Iperf/"
+SECTION = "console/network"
+LICENSE = "BSD-2-Clause"
+LIC_FILES_CHKSUM = "file://COPYING;md5=e8478eae9f479e39bc34975193360298"
+
+SRC_URI = " ${SOURCEFORGE_MIRROR}/iperf/${PN}-${PV}.tar.gz \
+            file://iperf-2.0.5_ManPage.patch \
+          "
+
+SRC_URI[md5sum] = "44b5536b67719f4250faed632a3cd016"
+SRC_URI[sha256sum] = "636b4eff0431cea80667ea85a67ce4c68698760a9837e1e9d13096d20362265b"
+
+S = "${WORKDIR}/${PN}-${PV}"
+
+inherit autotools pkgconfig
+
+EXTRA_OECONF = "--exec-prefix=${STAGING_DIR_HOST}${layout_exec_prefix}"
diff --git a/meta-altera/scripts/altera-setup-builddir b/meta-altera/scripts/altera-setup-builddir
index 28aa4f0..7e96f01 100755
--- a/meta-altera/scripts/altera-setup-builddir
+++ b/meta-altera/scripts/altera-setup-builddir
@@ -197,4 +197,5 @@ Common targets are:
 	bitbake virtual/bootloader
 	bitbake altera-gsrd-image
 	bitbake altera-image
+	bitbake altera-tse-image
 EOM
-- 
1.7.1

