From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Date: Mon, 5 Sep 2016 18:56:46 +0200
Subject: [PATCH] AArch64: Add native build support

FIXME: OVS-NSH-DPDK is not yet supported on arm64, see [1].

[1] https://jira.opnfv.org/browse/ARMBAND-86

Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
---
 ovs_build/build-ovs-dpdk.sh                      | 19 ++++++++--
 ovs_build/build-ovs-nsh-dpdk.sh                  | 48 ++++++++++++++----------
 ovs_build/openvswitch-dpdk_2.5.90/debian/control |  2 +-
 3 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/ovs_build/build-ovs-dpdk.sh b/ovs_build/build-ovs-dpdk.sh
index a14f5fd..a0c50e3 100755
--- a/ovs_build/build-ovs-dpdk.sh
+++ b/ovs_build/build-ovs-dpdk.sh
@@ -10,6 +10,10 @@ BUILD_DEST=${BUILD_DEST:-/tmp/ovs-dpdk}
 
 export DEB_BUILD_OPTIONS='parallel=8 nocheck'
 
+# AArch64 specifics, repository base URL, debian build versions
+AARCH64_REPO=${AARCH64_REPO:-'https://linux.enea.com/mos-repos/ubuntu/9.0'}
+AARCH64_DPDK_DEBV=${AARCH64_DPDK_DEBV:-'0~u14.04+mos1+mos9.0+amos1'}
+
 # Keep track of native arch (BUILD_ARCH) and target arch(s) (UBUNTU_ARCH)
 # All archs should be represented in `dpkg --print-architecture` format
 # UBUNTU_ARCH holds a space-separated list of target arch(s)
@@ -24,10 +28,17 @@ for ARCH in ${UBUNTU_ARCH}; do
     # Native building for: DPDK, OVS-DPDK, OVS
     sudo apt-get -y --force-yes install devscripts dpkg-dev wget
 
-    wget -c http://fast.dpdk.org/rel/dpdk-16.07.tar.xz
-    xz -d dpdk-16.07.tar.xz; tar xvf dpdk-16.07.tar
-    cd dpdk-16.07
-    cp -r ${BUILD_SRC}/dpdk_16.07/debian .
+    if [ ${ARCH} = 'arm64' ]; then
+      # Armband: arm64 already has debian control archive for DPDK 16.07
+      dget -x -u ${AARCH64_REPO}/pool/main/d/dpdk/dpdk_16.07-${AARCH64_DPDK_DEBV}.dsc
+      cd dpdk-16.07
+    else
+      # Other archs will use the debian control archive in this repo
+      wget -c http://fast.dpdk.org/rel/dpdk-16.07.tar.xz
+      xz -d dpdk-16.07.tar.xz; tar xvf dpdk-16.07.tar
+      cd dpdk-16.07
+      cp -r ${BUILD_SRC}/dpdk_16.07/debian .
+    fi
 
     # DPDK build-dep install: copy from debian/control
     sudo apt-get install -y --force-yes debhelper \
diff --git a/ovs_build/build-ovs-nsh-dpdk.sh b/ovs_build/build-ovs-nsh-dpdk.sh
index a65a2bb..59d8a79 100755
--- a/ovs_build/build-ovs-nsh-dpdk.sh
+++ b/ovs_build/build-ovs-nsh-dpdk.sh
@@ -25,10 +25,12 @@ for ARCH in ${UBUNTU_ARCH}; do
     # Native building for: DPDK, OVS-DPDK, OVS
     sudo apt-get build-dep openvswitch -y --force-yes
     sudo apt-get -y --force-yes install devscripts dpkg-dev wget
-    dget -x -u https://launchpad.net/ubuntu/+archive/primary/+files/dpdk_2.2.0-0ubuntu8.dsc
 
+    # FIXME(armband): OVS-NSH-DPDK is not yet supported on arm64
     # DPDK build-dep install: copy from debian/control
-    sudo apt-get install -y --force-yes debhelper \
+    if [ ! ${ARCH} = 'arm64' ]; then
+      dget -x -u https://launchpad.net/ubuntu/+archive/primary/+files/dpdk_2.2.0-0ubuntu8.dsc
+      sudo apt-get install -y --force-yes debhelper \
                dh-python \
                dh-systemd \
                doxygen  \
@@ -43,19 +45,20 @@ for ARCH in ${UBUNTU_ARCH}; do
                texlive-fonts-recommended  \
                texlive-latex-extra
 
-    cd dpdk-2.2.0; rm -rf debian/patches/
-    cat << EOF > debian/changelog
+      cd dpdk-2.2.0; rm -rf debian/patches/
+      cat << EOF > debian/changelog
 dpdk (2.2.0-1) unstable; urgency=low
   * DPDK 2.2.0
  -- DPDK team <dev@dpdk.org>  $(date --rfc-2822)
 EOF
-    # DPDK build & install (required for following native build of OVS-NSH)
-    debian/rules build; fakeroot debian/rules binary
-    cd ${BUILD_HOME}; sudo dpkg -i *.deb
-    apt-get download libxenstore3.0
+      # DPDK build & install (required for following native build of OVS-NSH)
+      debian/rules build; fakeroot debian/rules binary
+      cd ${BUILD_HOME}; sudo dpkg -i *.deb
+      apt-get download libxenstore3.0
 
-    cd ${BUILD_HOME}
-    dget -x -u https://launchpad.net/ubuntu/+archive/primary/+files/openvswitch-dpdk_2.4.0-0ubuntu1.dsc
+      # OVS-NSH-DPDK build preparations: download sources, patch if needed
+      dget -x -u https://launchpad.net/ubuntu/+archive/primary/+files/openvswitch-dpdk_2.4.0-0ubuntu1.dsc
+    fi
 
     # OVS-NSH build-dep install: copy from debian/control
     sudo apt-get install -y --force-yes autoconf \
@@ -88,20 +91,27 @@ EOF
       patch -p1 < ${DIR}/patches/${patch}
     done
     cd ${BUILD_HOME}; tar czvf ovs.tar.gz ovs
-    rm -rf openvswitch-dpdk-${OVS_VER}*
-    cd openvswitch-dpdk-2.4.0; uupdate -v ${OVS_VER} ../ovs.tar.gz
-    cd ../openvswitch-dpdk-${OVS_VER}
-    sed -i "s/include\/rte_config.h/include\/dpdk\/rte_config.h/" acinclude.m4
-    sed -i 's/DPDK_INCLUDE=.*/DPDK_INCLUDE=$RTE_SDK\/include\/dpdk/'  acinclude.m4
-    autoreconf --install
-    rm -rf debian/patches/
-    cat << EOF > debian/changelog
+
+    # FIXME(armband): OVS-NSH-DPDK is not yet supported on arm64
+    if [ ! ${ARCH} = 'arm64' ]; then
+      rm -rf openvswitch-dpdk-${OVS_VER}{,.orig*}
+      cd openvswitch-dpdk-2.4.0
+      uupdate -v ${OVS_VER} ../ovs.tar.gz
+      cd ${BUILD_HOME}/openvswitch-dpdk-${OVS_VER}
+      sed -i "s/include\/rte_config.h/include\/dpdk\/rte_config.h/" acinclude.m4
+      sed -i 's/DPDK_INCLUDE=.*/DPDK_INCLUDE=$RTE_SDK\/include\/dpdk/'  acinclude.m4
+      rm -rf debian/patches/
+      autoreconf --install
+      # OVS-NSH-DPDK build
+      cat << EOF > debian/changelog
 openvswitch-dpdk (${OVS_VER}-1.nsh) unstable; urgency=low
   * Support NSH
  -- Open vSwitch team <dev@openvswitch.org>  $(date --rfc-2822)
 EOF
-    debian/rules build; fakeroot debian/rules binary
+      debian/rules build; fakeroot debian/rules binary
+    fi
 
+    # OVS-NSH build
     cd ${BUILD_HOME}/ovs
     cat << EOF > debian/changelog
 openvswitch (${OVS_VER}-1.nsh) unstable; urgency=low
diff --git a/ovs_build/openvswitch-dpdk_2.5.90/debian/control b/ovs_build/openvswitch-dpdk_2.5.90/debian/control
index e7171b9..e0c27c5 100644
--- a/ovs_build/openvswitch-dpdk_2.5.90/debian/control
+++ b/ovs_build/openvswitch-dpdk_2.5.90/debian/control
@@ -27,7 +27,7 @@ Homepage: http://openvswitch.org/
 XS-Testsuite: autopkgtest
 
 Package: openvswitch-switch-dpdk
-Architecture: i386 amd64
+Architecture: i386 amd64 arm64
 Depends: dpdk,
          openvswitch-switch (>= 2.4.0),
          ${misc:Depends},