summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/buildtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/spdk/dpdk/buildtools')
-rw-r--r--src/spdk/dpdk/buildtools/Makefile9
-rwxr-xr-xsrc/spdk/dpdk/buildtools/auto-config-h.sh108
-rwxr-xr-xsrc/spdk/dpdk/buildtools/call-sphinx-build.py31
-rwxr-xr-xsrc/spdk/dpdk/buildtools/check-symbols.sh89
-rwxr-xr-xsrc/spdk/dpdk/buildtools/gen-build-mk.sh23
-rwxr-xr-xsrc/spdk/dpdk/buildtools/gen-config-h.sh15
-rwxr-xr-xsrc/spdk/dpdk/buildtools/gen-pmdinfo-cfile.sh14
-rwxr-xr-xsrc/spdk/dpdk/buildtools/list-dir-globs.py19
-rwxr-xr-xsrc/spdk/dpdk/buildtools/map-list-symbol.sh70
-rw-r--r--src/spdk/dpdk/buildtools/map_to_def.py40
-rw-r--r--src/spdk/dpdk/buildtools/meson.build23
-rwxr-xr-xsrc/spdk/dpdk/buildtools/options-ibverbs-static.sh21
-rw-r--r--src/spdk/dpdk/buildtools/pmdinfogen/Makefile20
-rw-r--r--src/spdk/dpdk/buildtools/pmdinfogen/meson.build14
-rw-r--r--src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.c456
-rw-r--r--src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.h119
-rwxr-xr-xsrc/spdk/dpdk/buildtools/relpath.sh76
-rw-r--r--src/spdk/dpdk/buildtools/symlink-drivers-solibs.sh13
18 files changed, 1160 insertions, 0 deletions
diff --git a/src/spdk/dpdk/buildtools/Makefile b/src/spdk/dpdk/buildtools/Makefile
new file mode 100644
index 000000000..7f76fd7d6
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2016 Neil Horman <nhorman@tuxdriver.com>
+# All rights reserved.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+DIRS-y += pmdinfogen
+
+include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/src/spdk/dpdk/buildtools/auto-config-h.sh b/src/spdk/dpdk/buildtools/auto-config-h.sh
new file mode 100755
index 000000000..5b613c35f
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/auto-config-h.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2014-2015 6WIND S.A.
+#
+# Crude script to detect whether particular types, macros and functions are
+# defined by trying to compile a file with a given header. Can be used to
+# perform cross-platform checks since the resulting object file is not
+# executed.
+#
+# Set VERBOSE=1 in the environment to display compiler output and errors.
+#
+# CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
+# environment.
+#
+# AUTO_CONFIG_CFLAGS may append additional CFLAGS without modifying the
+# above variables.
+
+file=${1:?output file name required (config.h)}
+macro=${2:?output macro name required (HAVE_*)}
+include=${3:?include name required (foo.h)}
+type=${4:?object type required (define, enum, type, field, func)}
+name=${5:?define/type/function name required}
+
+: ${CC:=cc}
+
+temp=$(mktemp -t dpdk.${0##*/}.c.XXXXXX)
+
+case $type in
+define)
+ code="\
+#ifndef $name
+#error $name not defined
+#endif
+"
+ ;;
+enum)
+ code="\
+long test____ = $name;
+"
+ ;;
+type)
+ code="\
+$name test____;
+"
+ ;;
+field)
+ code="\
+void test____(void)
+{
+ ${name%%.*} test_____;
+
+ (void)test_____.${name#*.};
+}
+"
+ ;;
+func)
+ code="\
+void (*test____)() = (void (*)())$name;
+"
+ ;;
+*)
+ unset error
+ : ${error:?unknown object type \"$type\"}
+ exit
+esac
+
+if [ "${VERBOSE}" = 1 ]
+then
+ err=2
+ out=1
+ eol='
+'
+else
+ exec 3> /dev/null ||
+ exit
+ err=3
+ out=3
+ eol=' '
+fi &&
+printf 'Looking for %s %s in %s.%s' \
+ "${name}" "${type}" "${include}" "${eol}" &&
+printf "\
+#include <%s>
+
+%s
+" "$include" "$code" > "${temp}" &&
+if ${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
+ ${AUTO_CONFIG_CFLAGS} \
+ -xc -c -o ${temp}.o "${temp}" 1>&${out} 2>&${err}
+then
+ rm -f "${temp}" "${temp}.o"
+ printf "\
+#ifndef %s
+#define %s 1
+#endif /* %s */
+
+" "${macro}" "${macro}" "${macro}" >> "${file}" &&
+ printf 'Defining %s.\n' "${macro}"
+else
+ rm -f "${temp}" "${temp}.o"
+ printf "\
+/* %s is not defined. */
+
+" "${macro}" >> "${file}" &&
+ printf 'Not defining %s.\n' "${macro}"
+fi
+
+exit
diff --git a/src/spdk/dpdk/buildtools/call-sphinx-build.py b/src/spdk/dpdk/buildtools/call-sphinx-build.py
new file mode 100755
index 000000000..b9a3994e1
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/call-sphinx-build.py
@@ -0,0 +1,31 @@
+#! /usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+#
+
+import sys
+import os
+from os.path import join
+from subprocess import run, PIPE
+from distutils.version import StrictVersion
+
+(sphinx, src, dst) = sys.argv[1:] # assign parameters to variables
+
+# for sphinx version >= 1.7 add parallelism using "-j auto"
+ver = run([sphinx, '--version'], stdout=PIPE).stdout.decode().split()[-1]
+sphinx_cmd = [sphinx]
+if StrictVersion(ver) >= StrictVersion('1.7'):
+ sphinx_cmd += ['-j', 'auto']
+
+# find all the files sphinx will process so we can write them as dependencies
+srcfiles = []
+for root, dirs, files in os.walk(src):
+ srcfiles.extend([join(root, f) for f in files])
+
+# run sphinx, putting the html output in a "html" directory
+process = run(sphinx_cmd + ['-b', 'html', src, join(dst, 'html')], check=True)
+print(str(process.args) + ' Done OK')
+
+# create a gcc format .d file giving all the dependencies of this doc build
+with open(join(dst, '.html.d'), 'w') as d:
+ d.write('html: ' + ' '.join(srcfiles) + '\n')
diff --git a/src/spdk/dpdk/buildtools/check-symbols.sh b/src/spdk/dpdk/buildtools/check-symbols.sh
new file mode 100755
index 000000000..e407553a3
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/check-symbols.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+# SPDX-License-Identifier: BSD-3-Clause
+
+MAPFILE=$1
+OBJFILE=$2
+
+LIST_SYMBOL=$(dirname $(readlink -f $0))/map-list-symbol.sh
+
+# added check for "make -C test/" usage
+if [ ! -e $MAPFILE ] || [ ! -f $OBJFILE ]
+then
+ exit 0
+fi
+
+if [ -d $MAPFILE ]
+then
+ exit 0
+fi
+
+DUMPFILE=$(mktemp -t dpdk.${0##*/}.XXX.objdump)
+trap 'rm -f "$DUMPFILE"' EXIT
+objdump -t $OBJFILE >$DUMPFILE
+
+ret=0
+for SYM in `$LIST_SYMBOL -S EXPERIMENTAL $MAPFILE |cut -d ' ' -f 3`
+do
+ if grep -q "\.text.*[[:space:]]$SYM$" $DUMPFILE &&
+ ! grep -q "\.text\.experimental.*[[:space:]]$SYM$" $DUMPFILE &&
+ $LIST_SYMBOL -s $SYM $MAPFILE | grep -q EXPERIMENTAL
+ then
+ cat >&2 <<- END_OF_MESSAGE
+ $SYM is not flagged as experimental
+ but is listed in version map
+ Please add __rte_experimental to the definition of $SYM
+ END_OF_MESSAGE
+ ret=1
+ fi
+done
+
+# Filter out symbols suffixed with a . for icc
+for SYM in `awk '{
+ if ($2 != "l" && $4 == ".text.experimental" && !($NF ~ /\.$/)) {
+ print $NF
+ }
+}' $DUMPFILE`
+do
+ $LIST_SYMBOL -S EXPERIMENTAL -s $SYM -q $MAPFILE || {
+ cat >&2 <<- END_OF_MESSAGE
+ $SYM is flagged as experimental
+ but is not listed in version map
+ Please add $SYM to the version map
+ END_OF_MESSAGE
+ ret=1
+ }
+done
+
+for SYM in `$LIST_SYMBOL -S INTERNAL $MAPFILE |cut -d ' ' -f 3`
+do
+ if grep -q "\.text.*[[:space:]]$SYM$" $DUMPFILE &&
+ ! grep -q "\.text\.internal.*[[:space:]]$SYM$" $DUMPFILE
+ then
+ cat >&2 <<- END_OF_MESSAGE
+ $SYM is not flagged as internal
+ but is listed in version map
+ Please add __rte_internal to the definition of $SYM
+ END_OF_MESSAGE
+ ret=1
+ fi
+done
+
+# Filter out symbols suffixed with a . for icc
+for SYM in `awk '{
+ if ($2 != "l" && $4 == ".text.internal" && !($NF ~ /\.$/)) {
+ print $NF
+ }
+}' $DUMPFILE`
+do
+ $LIST_SYMBOL -S INTERNAL -s $SYM -q $MAPFILE || {
+ cat >&2 <<- END_OF_MESSAGE
+ $SYM is flagged as internal
+ but is not listed in version map
+ Please add $SYM to the version map
+ END_OF_MESSAGE
+ ret=1
+ }
+done
+
+exit $ret
diff --git a/src/spdk/dpdk/buildtools/gen-build-mk.sh b/src/spdk/dpdk/buildtools/gen-build-mk.sh
new file mode 100755
index 000000000..636920b63
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/gen-build-mk.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2014 Intel Corporation
+
+# Auto-generate a Makefile in build directory
+# Args:
+# $1: path of project src root
+
+echo "# Automatically generated by gen-build-mk.sh"
+echo
+echo "ifdef O"
+echo "ifeq (\"\$(origin O)\", \"command line\")"
+echo "\$(error \"Cannot specify O= as you are already in a build directory\")"
+echo "endif"
+echo "endif"
+echo
+echo "MAKEFLAGS += --no-print-directory"
+echo
+echo "all:"
+echo " @\$(MAKE) -C $1 O=\$(CURDIR)"
+echo
+echo "%::"
+echo " @\$(MAKE) -C $1 O=\$(CURDIR) \$@"
diff --git a/src/spdk/dpdk/buildtools/gen-config-h.sh b/src/spdk/dpdk/buildtools/gen-config-h.sh
new file mode 100755
index 000000000..a8c200633
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/gen-config-h.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2014 Intel Corporation
+
+echo "#ifndef __RTE_CONFIG_H"
+echo "#define __RTE_CONFIG_H"
+grep CONFIG_ $1 |
+grep -v '^[ \t]*#' |
+sed 's,CONFIG_\(.*\)=y.*$,#undef \1\
+#define \1 1,' |
+sed 's,CONFIG_\(.*\)=n.*$,#undef \1,' |
+sed 's,CONFIG_\(.*\)=\(.*\)$,#undef \1\
+#define \1 \2,' |
+sed 's,\# CONFIG_\(.*\) is not set$,#undef \1,'
+echo "#endif /* __RTE_CONFIG_H */"
diff --git a/src/spdk/dpdk/buildtools/gen-pmdinfo-cfile.sh b/src/spdk/dpdk/buildtools/gen-pmdinfo-cfile.sh
new file mode 100755
index 000000000..43059cf36
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/gen-pmdinfo-cfile.sh
@@ -0,0 +1,14 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017 Intel Corporation
+
+arfile=$1
+output=$2
+pmdinfogen=$3
+
+# The generated file must not be empty if compiled in pedantic mode
+echo 'static __attribute__((unused)) const char *generator = "'$0'";' > $output
+for ofile in `ar t $arfile` ; do
+ ar p $arfile $ofile | $pmdinfogen - - >> $output 2> /dev/null
+done
+exit 0
diff --git a/src/spdk/dpdk/buildtools/list-dir-globs.py b/src/spdk/dpdk/buildtools/list-dir-globs.py
new file mode 100755
index 000000000..80b5e801f
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/list-dir-globs.py
@@ -0,0 +1,19 @@
+#! /usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import sys
+import os
+from glob import iglob
+
+if len(sys.argv) != 2:
+ print("Usage: {0} <path-glob>[,<path-glob>[,...]]".format(sys.argv[0]))
+ sys.exit(1)
+
+root = os.path.join(os.getenv('MESON_SOURCE_ROOT', '.'),
+ os.getenv('MESON_SUBDIR', '.'))
+
+for path in sys.argv[1].split(','):
+ for p in iglob(os.path.join(root, path)):
+ if os.path.isdir(p):
+ print(os.path.relpath(p))
diff --git a/src/spdk/dpdk/buildtools/map-list-symbol.sh b/src/spdk/dpdk/buildtools/map-list-symbol.sh
new file mode 100755
index 000000000..5509b4a7f
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/map-list-symbol.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 David Marchand <david.marchand@redhat.com>
+
+section=all
+symbol=all
+quiet=
+
+while getopts 'S:s:q' name; do
+ case $name in
+ S)
+ [ $section = 'all' ] || {
+ echo 'Cannot list in multiple sections'
+ exit 1
+ }
+ section=$OPTARG
+ ;;
+ s)
+ [ $symbol = 'all' ] || {
+ echo 'Cannot list multiple symbols'
+ exit 1
+ }
+ symbol=$OPTARG
+ ;;
+ q)
+ quiet='y'
+ ;;
+ ?)
+ echo 'usage: $0 [-S section] [-s symbol] [-q]'
+ exit 1
+ ;;
+ esac
+done
+
+shift $(($OPTIND - 1))
+
+for file in $@; do
+ cat "$file" |awk '
+ BEGIN {
+ current_section = "";
+ if ("'$section'" == "all" && "'$symbol'" == "all") {
+ ret = 0;
+ } else {
+ ret = 1;
+ }
+ }
+ /^.*{/ {
+ if ("'$section'" == "all" || $1 == "'$section'") {
+ current_section = $1;
+ }
+ }
+ /.*}/ { current_section = ""; }
+ /^[^}].*[^:*];/ {
+ if (current_section != "") {
+ gsub(";","");
+ if ("'$symbol'" == "all" || $1 == "'$symbol'") {
+ ret = 0;
+ if ("'$quiet'" == "") {
+ print "'$file' "current_section" "$1;
+ }
+ if ("'$symbol'" != "all") {
+ exit 0;
+ }
+ }
+ }
+ }
+ END {
+ exit ret;
+ }'
+done
diff --git a/src/spdk/dpdk/buildtools/map_to_def.py b/src/spdk/dpdk/buildtools/map_to_def.py
new file mode 100644
index 000000000..6775b54a9
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/map_to_def.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Intel Corporation
+
+from __future__ import print_function
+import sys
+from os.path import dirname, basename, join, exists
+
+
+def is_function_line(ln):
+ return ln.startswith('\t') and ln.endswith(';\n') and ":" not in ln
+
+
+def main(args):
+ if not args[1].endswith('version.map') or \
+ not args[2].endswith('exports.def'):
+ return 1
+
+# special case, allow override if an def file already exists alongside map file
+ override_file = join(dirname(args[1]), basename(args[2]))
+ if exists(override_file):
+ with open(override_file) as f_in:
+ functions = f_in.readlines()
+
+# generate def file from map file.
+# This works taking indented lines only which end with a ";" and which don't
+# have a colon in them, i.e. the lines defining functions only.
+ else:
+ with open(args[1]) as f_in:
+ functions = [ln[:-2] + '\n' for ln in sorted(f_in.readlines())
+ if is_function_line(ln)]
+ functions = ["EXPORTS\n"] + functions
+
+ with open(args[2], 'w') as f_out:
+ f_out.writelines(functions)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/src/spdk/dpdk/buildtools/meson.build b/src/spdk/dpdk/buildtools/meson.build
new file mode 100644
index 000000000..d5f8291be
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/meson.build
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017-2019 Intel Corporation
+
+subdir('pmdinfogen')
+
+pkgconf = find_program('pkg-config', 'pkgconf', required: false)
+pmdinfo = find_program('gen-pmdinfo-cfile.sh')
+list_dir_globs = find_program('list-dir-globs.py')
+check_symbols = find_program('check-symbols.sh')
+ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
+
+# set up map-to-def script using python, either built-in or external
+python3 = import('python').find_installation(required: false)
+if python3.found()
+ py3 = [python3]
+else
+ py3 = ['meson', 'runpython']
+endif
+map_to_def_cmd = py3 + files('map_to_def.py')
+sphinx_wrapper = py3 + files('call-sphinx-build.py')
+
+# stable ABI always starts with "DPDK_"
+is_stable_cmd = [find_program('grep', 'findstr'), '^DPDK_']
diff --git a/src/spdk/dpdk/buildtools/options-ibverbs-static.sh b/src/spdk/dpdk/buildtools/options-ibverbs-static.sh
new file mode 100755
index 000000000..0740a711f
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/options-ibverbs-static.sh
@@ -0,0 +1,21 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Print link options -l for static link of ibverbs.
+#
+# Static flavour of ibverbs and the providers libs are explicitly picked,
+# thanks to the syntax -l:libfoo.a
+# Other libs (pthread and nl) are unchanged, i.e. linked dynamically by default.
+#
+# PKG_CONFIG_PATH may be required to be set if libibverbs.pc is not installed.
+
+lib='libibverbs'
+deps='pthread|nl'
+
+pkg-config --libs --static $lib |
+ tr '[:space:]' '\n' |
+ sed -r "/^-l($deps)/! s,(^-l)(.*),\1:lib\2.a," | # explicit .a
+ sed -n '/^-[Ll]/p' | # extra link options may break with make
+ tac |
+ awk "/^-l:$lib.a/&&c++ {next} 1" | # drop first duplicates of main lib
+ tac
diff --git a/src/spdk/dpdk/buildtools/pmdinfogen/Makefile b/src/spdk/dpdk/buildtools/pmdinfogen/Makefile
new file mode 100644
index 000000000..a97a7648f
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/pmdinfogen/Makefile
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2016 Neil Horman <nhorman@tuxdriver.com>
+# All rights reserved.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+HOSTAPP = dpdk-pmdinfogen
+
+#
+# all sources are stored in SRCS-y
+#
+SRCS-y += pmdinfogen.c
+
+HOST_CFLAGS += $(HOST_WERROR_FLAGS) -g
+HOST_CFLAGS += -I$(RTE_OUTPUT)/include
+
+include $(RTE_SDK)/mk/rte.hostapp.mk
diff --git a/src/spdk/dpdk/buildtools/pmdinfogen/meson.build b/src/spdk/dpdk/buildtools/pmdinfogen/meson.build
new file mode 100644
index 000000000..7da415b3b
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/pmdinfogen/meson.build
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017 Intel Corporation
+
+if host_machine.system() == 'windows'
+ subdir_done()
+endif
+
+pmdinfogen_inc = [global_inc]
+pmdinfogen_inc += include_directories('../../lib/librte_eal/include')
+pmdinfogen_inc += include_directories('../../lib/librte_pci')
+pmdinfogen = executable('pmdinfogen',
+ 'pmdinfogen.c',
+ include_directories: pmdinfogen_inc,
+ native: true)
diff --git a/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.c b/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.c
new file mode 100644
index 000000000..a68d1ea99
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.c
@@ -0,0 +1,456 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Postprocess pmd object files to export hw support
+ *
+ * Copyright 2016 Neil Horman <nhorman@tuxdriver.com>
+ * Based in part on modpost.c from the linux kernel
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <libgen.h>
+
+#include <rte_common.h>
+#include "pmdinfogen.h"
+
+#ifdef RTE_ARCH_64
+#define ADDR_SIZE 64
+#else
+#define ADDR_SIZE 32
+#endif
+
+static int use_stdin, use_stdout;
+
+static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
+{
+ if (sym)
+ return elf->strtab + sym->st_name;
+ else
+ return "(unknown)";
+}
+
+static void *grab_file(const char *filename, unsigned long *size)
+{
+ struct stat st;
+ void *map = MAP_FAILED;
+ int fd = -1;
+
+ if (!use_stdin) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ } else {
+ /* from stdin, use a temporary file to mmap */
+ FILE *infile;
+ char buffer[1024];
+ int n;
+
+ infile = tmpfile();
+ if (infile == NULL) {
+ perror("tmpfile");
+ return NULL;
+ }
+ fd = dup(fileno(infile));
+ fclose(infile);
+ if (fd < 0)
+ return NULL;
+
+ n = read(STDIN_FILENO, buffer, sizeof(buffer));
+ while (n > 0) {
+ if (write(fd, buffer, n) != n)
+ goto failed;
+ n = read(STDIN_FILENO, buffer, sizeof(buffer));
+ }
+ }
+
+ if (fstat(fd, &st))
+ goto failed;
+
+ *size = st.st_size;
+ map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+
+failed:
+ close(fd);
+ if (map == MAP_FAILED)
+ return NULL;
+ return map;
+}
+
+/**
+ * Return a copy of the next line in a mmap'ed file.
+ * spaces in the beginning of the line is trimmed away.
+ * Return a pointer to a static buffer.
+ **/
+static void release_file(void *file, unsigned long size)
+{
+ munmap(file, size);
+}
+
+
+static void *get_sym_value(struct elf_info *info, const Elf_Sym *sym)
+{
+ return RTE_PTR_ADD(info->hdr,
+ info->sechdrs[sym->st_shndx].sh_offset + sym->st_value);
+}
+
+static Elf_Sym *find_sym_in_symtab(struct elf_info *info,
+ const char *name, Elf_Sym *last)
+{
+ Elf_Sym *idx;
+ if (last)
+ idx = last+1;
+ else
+ idx = info->symtab_start;
+
+ for (; idx < info->symtab_stop; idx++) {
+ const char *n = sym_name(info, idx);
+ if (!strncmp(n, name, strlen(name)))
+ return idx;
+ }
+ return NULL;
+}
+
+static int parse_elf(struct elf_info *info, const char *filename)
+{
+ unsigned int i;
+ Elf_Ehdr *hdr;
+ Elf_Shdr *sechdrs;
+ Elf_Sym *sym;
+ int endian;
+ unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U;
+
+ hdr = grab_file(filename, &info->size);
+ if (!hdr) {
+ perror(filename);
+ exit(1);
+ }
+ info->hdr = hdr;
+ if (info->size < sizeof(*hdr)) {
+ /* file too small, assume this is an empty .o file */
+ return 0;
+ }
+ /* Is this a valid ELF file? */
+ if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
+ (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
+ (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
+ (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
+ /* Not an ELF file - silently ignore it */
+ return 0;
+ }
+
+ if (!hdr->e_ident[EI_DATA]) {
+ /* Unknown endian */
+ return 0;
+ }
+
+ endian = hdr->e_ident[EI_DATA];
+
+ /* Fix endianness in ELF header */
+ hdr->e_type = TO_NATIVE(endian, 16, hdr->e_type);
+ hdr->e_machine = TO_NATIVE(endian, 16, hdr->e_machine);
+ hdr->e_version = TO_NATIVE(endian, 32, hdr->e_version);
+ hdr->e_entry = TO_NATIVE(endian, ADDR_SIZE, hdr->e_entry);
+ hdr->e_phoff = TO_NATIVE(endian, ADDR_SIZE, hdr->e_phoff);
+ hdr->e_shoff = TO_NATIVE(endian, ADDR_SIZE, hdr->e_shoff);
+ hdr->e_flags = TO_NATIVE(endian, 32, hdr->e_flags);
+ hdr->e_ehsize = TO_NATIVE(endian, 16, hdr->e_ehsize);
+ hdr->e_phentsize = TO_NATIVE(endian, 16, hdr->e_phentsize);
+ hdr->e_phnum = TO_NATIVE(endian, 16, hdr->e_phnum);
+ hdr->e_shentsize = TO_NATIVE(endian, 16, hdr->e_shentsize);
+ hdr->e_shnum = TO_NATIVE(endian, 16, hdr->e_shnum);
+ hdr->e_shstrndx = TO_NATIVE(endian, 16, hdr->e_shstrndx);
+
+ sechdrs = RTE_PTR_ADD(hdr, hdr->e_shoff);
+ info->sechdrs = sechdrs;
+
+ /* Check if file offset is correct */
+ if (hdr->e_shoff > info->size) {
+ fprintf(stderr, "section header offset=%lu in file '%s' "
+ "is bigger than filesize=%lu\n",
+ (unsigned long)hdr->e_shoff,
+ filename, info->size);
+ return 0;
+ }
+
+ if (hdr->e_shnum == SHN_UNDEF) {
+ /*
+ * There are more than 64k sections,
+ * read count from .sh_size.
+ */
+ info->num_sections =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[0].sh_size);
+ } else {
+ info->num_sections = hdr->e_shnum;
+ }
+ if (hdr->e_shstrndx == SHN_XINDEX)
+ info->secindex_strings =
+ TO_NATIVE(endian, 32, sechdrs[0].sh_link);
+ else
+ info->secindex_strings = hdr->e_shstrndx;
+
+ /* Fix endianness in section headers */
+ for (i = 0; i < info->num_sections; i++) {
+ sechdrs[i].sh_name =
+ TO_NATIVE(endian, 32, sechdrs[i].sh_name);
+ sechdrs[i].sh_type =
+ TO_NATIVE(endian, 32, sechdrs[i].sh_type);
+ sechdrs[i].sh_flags =
+ TO_NATIVE(endian, 32, sechdrs[i].sh_flags);
+ sechdrs[i].sh_addr =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_addr);
+ sechdrs[i].sh_offset =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_offset);
+ sechdrs[i].sh_size =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_size);
+ sechdrs[i].sh_link =
+ TO_NATIVE(endian, 32, sechdrs[i].sh_link);
+ sechdrs[i].sh_info =
+ TO_NATIVE(endian, 32, sechdrs[i].sh_info);
+ sechdrs[i].sh_addralign =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_addralign);
+ sechdrs[i].sh_entsize =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_entsize);
+ }
+ /* Find symbol table. */
+ for (i = 1; i < info->num_sections; i++) {
+ int nobits = sechdrs[i].sh_type == SHT_NOBITS;
+
+ if (!nobits && sechdrs[i].sh_offset > info->size) {
+ fprintf(stderr, "%s is truncated. "
+ "sechdrs[i].sh_offset=%lu > sizeof(*hrd)=%zu\n",
+ filename, (unsigned long)sechdrs[i].sh_offset,
+ sizeof(*hdr));
+ return 0;
+ }
+
+ if (sechdrs[i].sh_type == SHT_SYMTAB) {
+ unsigned int sh_link_idx;
+ symtab_idx = i;
+ info->symtab_start = RTE_PTR_ADD(hdr,
+ sechdrs[i].sh_offset);
+ info->symtab_stop = RTE_PTR_ADD(hdr,
+ sechdrs[i].sh_offset + sechdrs[i].sh_size);
+ sh_link_idx = sechdrs[i].sh_link;
+ info->strtab = RTE_PTR_ADD(hdr,
+ sechdrs[sh_link_idx].sh_offset);
+ }
+
+ /* 32bit section no. table? ("more than 64k sections") */
+ if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) {
+ symtab_shndx_idx = i;
+ info->symtab_shndx_start = RTE_PTR_ADD(hdr,
+ sechdrs[i].sh_offset);
+ info->symtab_shndx_stop = RTE_PTR_ADD(hdr,
+ sechdrs[i].sh_offset + sechdrs[i].sh_size);
+ }
+ }
+ if (!info->symtab_start)
+ fprintf(stderr, "%s has no symtab?\n", filename);
+ else {
+ /* Fix endianness in symbols */
+ for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
+ sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx);
+ sym->st_name = TO_NATIVE(endian, 32, sym->st_name);
+ sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value);
+ sym->st_size = TO_NATIVE(endian, ADDR_SIZE, sym->st_size);
+ }
+ }
+
+ if (symtab_shndx_idx != ~0U) {
+ Elf32_Word *p;
+ if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link)
+ fprintf(stderr,
+ "%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n",
+ filename, sechdrs[symtab_shndx_idx].sh_link,
+ symtab_idx);
+ /* Fix endianness */
+ for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
+ p++)
+ *p = TO_NATIVE(endian, 32, *p);
+ }
+
+ return 1;
+}
+
+static void parse_elf_finish(struct elf_info *info)
+{
+ struct pmd_driver *tmp, *idx = info->drivers;
+ release_file(info->hdr, info->size);
+ while (idx) {
+ tmp = idx->next;
+ free(idx);
+ idx = tmp;
+ }
+}
+
+struct opt_tag {
+ const char *suffix;
+ const char *json_id;
+};
+
+static const struct opt_tag opt_tags[] = {
+ {"_param_string_export", "params"},
+ {"_kmod_dep_export", "kmod"},
+};
+
+static int complete_pmd_entry(struct elf_info *info, struct pmd_driver *drv)
+{
+ const char *tname;
+ int i;
+ char tmpsymname[128];
+ Elf_Sym *tmpsym;
+
+ drv->name = get_sym_value(info, drv->name_sym);
+
+ for (i = 0; i < PMD_OPT_MAX; i++) {
+ memset(tmpsymname, 0, 128);
+ sprintf(tmpsymname, "__%s%s", drv->name, opt_tags[i].suffix);
+ tmpsym = find_sym_in_symtab(info, tmpsymname, NULL);
+ if (!tmpsym)
+ continue;
+ drv->opt_vals[i] = get_sym_value(info, tmpsym);
+ }
+
+ memset(tmpsymname, 0, 128);
+ sprintf(tmpsymname, "__%s_pci_tbl_export", drv->name);
+
+ tmpsym = find_sym_in_symtab(info, tmpsymname, NULL);
+
+
+ /*
+ * If this returns NULL, then this is a PMD_VDEV, because
+ * it has no pci table reference
+ */
+ if (!tmpsym) {
+ drv->pci_tbl = NULL;
+ return 0;
+ }
+
+ tname = get_sym_value(info, tmpsym);
+ tmpsym = find_sym_in_symtab(info, tname, NULL);
+ if (!tmpsym)
+ return -ENOENT;
+
+ drv->pci_tbl = (struct rte_pci_id *)get_sym_value(info, tmpsym);
+ if (!drv->pci_tbl)
+ return -ENOENT;
+
+ return 0;
+}
+
+static int locate_pmd_entries(struct elf_info *info)
+{
+ Elf_Sym *last = NULL;
+ struct pmd_driver *new;
+
+ info->drivers = NULL;
+
+ do {
+ new = calloc(sizeof(struct pmd_driver), 1);
+ if (new == NULL) {
+ fprintf(stderr, "Failed to calloc memory\n");
+ return -1;
+ }
+ new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last);
+ last = new->name_sym;
+ if (!new->name_sym)
+ free(new);
+ else {
+ if (complete_pmd_entry(info, new)) {
+ fprintf(stderr,
+ "Failed to complete pmd entry\n");
+ free(new);
+ } else {
+ new->next = info->drivers;
+ info->drivers = new;
+ }
+ }
+ } while (last);
+
+ return 0;
+}
+
+static void output_pmd_info_string(struct elf_info *info, char *outfile)
+{
+ FILE *ofd;
+ struct pmd_driver *drv;
+ struct rte_pci_id *pci_ids;
+ int idx = 0;
+
+ if (use_stdout)
+ ofd = stdout;
+ else {
+ ofd = fopen(outfile, "w+");
+ if (!ofd) {
+ fprintf(stderr, "Unable to open output file\n");
+ return;
+ }
+ }
+
+ drv = info->drivers;
+
+ while (drv) {
+ fprintf(ofd, "const char %s_pmd_info[] __attribute__((used)) = "
+ "\"PMD_INFO_STRING= {",
+ drv->name);
+ fprintf(ofd, "\\\"name\\\" : \\\"%s\\\", ", drv->name);
+
+ for (idx = 0; idx < PMD_OPT_MAX; idx++) {
+ if (drv->opt_vals[idx])
+ fprintf(ofd, "\\\"%s\\\" : \\\"%s\\\", ",
+ opt_tags[idx].json_id,
+ drv->opt_vals[idx]);
+ }
+
+ pci_ids = drv->pci_tbl;
+ fprintf(ofd, "\\\"pci_ids\\\" : [");
+
+ while (pci_ids && pci_ids->device_id) {
+ fprintf(ofd, "[%d, %d, %d, %d]",
+ pci_ids->vendor_id, pci_ids->device_id,
+ pci_ids->subsystem_vendor_id,
+ pci_ids->subsystem_device_id);
+ pci_ids++;
+ if (pci_ids->device_id)
+ fprintf(ofd, ",");
+ else
+ fprintf(ofd, " ");
+ }
+ fprintf(ofd, "]}\";\n");
+ drv = drv->next;
+ }
+
+ fclose(ofd);
+}
+
+int main(int argc, char **argv)
+{
+ struct elf_info info = {0};
+ int rc = 1;
+
+ if (argc < 3) {
+ fprintf(stderr,
+ "usage: %s <object file> <c output file>\n",
+ basename(argv[0]));
+ exit(127);
+ }
+ use_stdin = !strcmp(argv[1], "-");
+ use_stdout = !strcmp(argv[2], "-");
+ parse_elf(&info, argv[1]);
+
+ if (locate_pmd_entries(&info) < 0)
+ exit(1);
+
+ if (info.drivers) {
+ output_pmd_info_string(&info, argv[2]);
+ rc = 0;
+ } else {
+ fprintf(stderr, "No drivers registered\n");
+ }
+
+ parse_elf_finish(&info);
+ exit(rc);
+}
diff --git a/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.h b/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.h
new file mode 100644
index 000000000..93930e454
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/pmdinfogen/pmdinfogen.h
@@ -0,0 +1,119 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Postprocess pmd object files to export hw support
+ *
+ * Copyright 2016 Neil Horman <nhorman@tuxdriver.com>
+ * Based in part on modpost.c from the linux kernel
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#ifdef __linux__
+#include <endian.h>
+#else
+#include <sys/endian.h>
+#endif
+#include <fcntl.h>
+#include <unistd.h>
+#include <elf.h>
+#include <rte_pci.h>
+
+/* On BSD-alike OSes elf.h defines these according to host's word size */
+#undef ELF_ST_BIND
+#undef ELF_ST_TYPE
+#undef ELF_R_SYM
+#undef ELF_R_TYPE
+
+/*
+ * Define ELF64_* to ELF_*, the latter being defined in both 32 and 64 bit
+ * flavors in elf.h. This makes our code a bit more generic between arches
+ * and allows us to support 32 bit code in the future should we ever want to
+ */
+#ifdef RTE_ARCH_64
+#define Elf_Ehdr Elf64_Ehdr
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Addr Elf64_Addr
+#define Elf_Sword Elf64_Sxword
+#define Elf_Section Elf64_Half
+#define ELF_ST_BIND ELF64_ST_BIND
+#define ELF_ST_TYPE ELF64_ST_TYPE
+
+#define Elf_Rel Elf64_Rel
+#define Elf_Rela Elf64_Rela
+#define ELF_R_SYM ELF64_R_SYM
+#define ELF_R_TYPE ELF64_R_TYPE
+#else
+#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Addr Elf32_Addr
+#define Elf_Sword Elf32_Sxword
+#define Elf_Section Elf32_Half
+#define ELF_ST_BIND ELF32_ST_BIND
+#define ELF_ST_TYPE ELF32_ST_TYPE
+
+#define Elf_Rel Elf32_Rel
+#define Elf_Rela Elf32_Rela
+#define ELF_R_SYM ELF32_R_SYM
+#define ELF_R_TYPE ELF32_R_TYPE
+#endif
+
+
+/*
+ * Note, it seems odd that we have both a CONVERT_NATIVE and a TO_NATIVE macro
+ * below. We do this because the values passed to TO_NATIVE may themselves be
+ * macros and need both macros here to get expanded. Specifically its the width
+ * variable we are concerned with, because it needs to get expanded prior to
+ * string concatenation
+ */
+#define CONVERT_NATIVE(fend, width, x) ({ \
+typeof(x) ___x; \
+if ((fend) == ELFDATA2LSB) \
+ ___x = le##width##toh(x); \
+else \
+ ___x = be##width##toh(x); \
+ ___x; \
+})
+
+#define TO_NATIVE(fend, width, x) CONVERT_NATIVE(fend, width, x)
+
+enum opt_params {
+ PMD_PARAM_STRING = 0,
+ PMD_KMOD_DEP,
+ PMD_OPT_MAX
+};
+
+struct pmd_driver {
+ Elf_Sym *name_sym;
+ const char *name;
+ struct rte_pci_id *pci_tbl;
+ struct pmd_driver *next;
+
+ const char *opt_vals[PMD_OPT_MAX];
+};
+
+struct elf_info {
+ unsigned long size;
+ Elf_Ehdr *hdr;
+ Elf_Shdr *sechdrs;
+ Elf_Sym *symtab_start;
+ Elf_Sym *symtab_stop;
+ char *strtab;
+
+ /* support for 32bit section numbers */
+
+ unsigned int num_sections; /* max_secindex + 1 */
+ unsigned int secindex_strings;
+ /* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
+ * take shndx from symtab_shndx_start[N] instead
+ */
+ Elf32_Word *symtab_shndx_start;
+ Elf32_Word *symtab_shndx_stop;
+
+ struct pmd_driver *drivers;
+};
diff --git a/src/spdk/dpdk/buildtools/relpath.sh b/src/spdk/dpdk/buildtools/relpath.sh
new file mode 100755
index 000000000..02953837a
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/relpath.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2014 Intel Corporation
+
+#
+# print the relative path of $1 from $2 directory
+# $1 and $2 MUST be absolute paths
+#
+
+if [ $# -ne 2 ]; then
+ echo "Bad arguments"
+ echo "Usage:"
+ echo " $0 path1 path2"
+ exit 1
+fi
+
+# get the real absolute path, derefencing symlinks
+ABS1="$(dirname $(readlink -f $1))/$(basename $1)"
+ABS2=$(readlink -f $2)
+
+# remove leading slash
+REL1=${ABS1#/}
+REL2=${ABS2#/}
+
+left1=${REL1%%/*}
+right1=${REL1#*/}
+prev_right1=$REL1
+prev_left1=
+
+left2=${REL2%%/*}
+right2=${REL2#*/}
+prev_right2=$REL2
+prev_left2=
+
+prefix=
+
+while [ "${right1}" != "" -a "${right2}" != "" ]; do
+
+ if [ "$left1" != "$left2" ]; then
+ break
+ fi
+
+ prev_left1=$left1
+ left1=$left1/${right1%%/*}
+ prev_right1=$right1
+ right1=${prev_right1#*/}
+ if [ "$right1" = "$prev_right1" ]; then
+ right1=""
+ fi
+
+ prev_left2=$left2
+ left2=$left2/${right2%%/*}
+ prev_right2=$right2
+ right2=${prev_right2#*/}
+ if [ "$right2" = "$prev_right2" ]; then
+ right2=""
+ fi
+done
+
+if [ "${left1}" != "${left2}" ]; then
+ right2=${prev_right2}
+ right1=${prev_right1}
+fi
+
+while [ "${right2}" != "" ]; do
+ prefix=${prefix}../
+ prev_right2=$right2
+ right2=${right2#*/}
+ if [ "$right2" = "$prev_right2" ]; then
+ right2=""
+ fi
+done
+
+echo ${prefix}${right1}
+
+exit 0
diff --git a/src/spdk/dpdk/buildtools/symlink-drivers-solibs.sh b/src/spdk/dpdk/buildtools/symlink-drivers-solibs.sh
new file mode 100644
index 000000000..42985e855
--- /dev/null
+++ b/src/spdk/dpdk/buildtools/symlink-drivers-solibs.sh
@@ -0,0 +1,13 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017 Intel Corporation
+
+# post-install script for meson/ninja builds to symlink the PMDs stored in
+# $libdir/dpdk/drivers/ to $libdir. This is needed as some PMDs depend on
+# others, e.g. PCI device PMDs depending on the PCI bus driver.
+
+# parameters to script are paths relative to install prefix:
+# 1. directory for installed regular libs e.g. lib64
+# 2. subdirectory of libdir where the pmds are
+
+cd ${MESON_INSTALL_DESTDIR_PREFIX}/$1 && ln -sfv $2/librte_*.so* .