2020-09-30 11:40:14 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-04-09 08:58:36 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright(c) 2016 Neil Horman <nhorman@tuxdriver.com>
|
2016-12-21 15:03:48 +00:00
|
|
|
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Utility to dump PMD_INFO_STRING support from an object file
|
|
|
|
#
|
|
|
|
# -------------------------------------------------------------------------
|
2016-12-21 15:03:47 +00:00
|
|
|
import json
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
import os
|
2016-12-21 15:03:47 +00:00
|
|
|
import platform
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
import sys
|
2020-11-04 06:48:41 +00:00
|
|
|
import argparse
|
2016-12-21 15:03:47 +00:00
|
|
|
from elftools.common.exceptions import ELFError
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
from elftools.common.py3compat import byte2int
|
2016-12-21 15:03:47 +00:00
|
|
|
from elftools.elf.elffile import ELFFile
|
2020-11-04 06:48:41 +00:00
|
|
|
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
# For running from development directory. It should take precedence over the
|
|
|
|
# installed pyelftools.
|
|
|
|
sys.path.insert(0, '.')
|
|
|
|
|
|
|
|
raw_output = False
|
|
|
|
pcidb = None
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
class Vendor:
|
|
|
|
"""
|
|
|
|
Class for vendors. This is the top level class
|
|
|
|
for the devices belong to a specific vendor.
|
|
|
|
self.devices is the device dictionary
|
|
|
|
subdevices are in each device.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, vendorStr):
|
|
|
|
"""
|
|
|
|
Class initializes with the raw line from pci.ids
|
|
|
|
Parsing takes place inside __init__
|
|
|
|
"""
|
|
|
|
self.ID = vendorStr.split()[0]
|
|
|
|
self.name = vendorStr.replace("%s " % self.ID, "").rstrip()
|
|
|
|
self.devices = {}
|
|
|
|
|
|
|
|
def addDevice(self, deviceStr):
|
|
|
|
"""
|
|
|
|
Adds a device to self.devices
|
|
|
|
takes the raw line from pci.ids
|
|
|
|
"""
|
|
|
|
s = deviceStr.strip()
|
|
|
|
devID = s.split()[0]
|
|
|
|
if devID in self.devices:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.devices[devID] = Device(deviceStr)
|
|
|
|
|
|
|
|
def report(self):
|
2016-12-21 15:03:48 +00:00
|
|
|
print(self.ID, self.name)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
for id, dev in self.devices.items():
|
|
|
|
dev.report()
|
|
|
|
|
|
|
|
def find_device(self, devid):
|
|
|
|
# convert to a hex string and remove 0x
|
|
|
|
devid = hex(devid)[2:]
|
|
|
|
try:
|
|
|
|
return self.devices[devid]
|
|
|
|
except:
|
|
|
|
return Device("%s Unknown Device" % devid)
|
|
|
|
|
|
|
|
|
|
|
|
class Device:
|
|
|
|
|
|
|
|
def __init__(self, deviceStr):
|
|
|
|
"""
|
|
|
|
Class for each device.
|
|
|
|
Each vendor has its own devices dictionary.
|
|
|
|
"""
|
|
|
|
s = deviceStr.strip()
|
|
|
|
self.ID = s.split()[0]
|
|
|
|
self.name = s.replace("%s " % self.ID, "")
|
|
|
|
self.subdevices = {}
|
|
|
|
|
|
|
|
def report(self):
|
2016-12-21 15:03:48 +00:00
|
|
|
print("\t%s\t%s" % (self.ID, self.name))
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
for subID, subdev in self.subdevices.items():
|
|
|
|
subdev.report()
|
|
|
|
|
|
|
|
def addSubDevice(self, subDeviceStr):
|
|
|
|
"""
|
|
|
|
Adds a subvendor, subdevice to device.
|
|
|
|
Uses raw line from pci.ids
|
|
|
|
"""
|
|
|
|
s = subDeviceStr.strip()
|
|
|
|
spl = s.split()
|
|
|
|
subVendorID = spl[0]
|
|
|
|
subDeviceID = spl[1]
|
|
|
|
subDeviceName = s.split(" ")[-1]
|
|
|
|
devID = "%s:%s" % (subVendorID, subDeviceID)
|
|
|
|
self.subdevices[devID] = SubDevice(
|
|
|
|
subVendorID, subDeviceID, subDeviceName)
|
|
|
|
|
|
|
|
def find_subid(self, subven, subdev):
|
|
|
|
subven = hex(subven)[2:]
|
|
|
|
subdev = hex(subdev)[2:]
|
|
|
|
devid = "%s:%s" % (subven, subdev)
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self.subdevices[devid]
|
|
|
|
except:
|
|
|
|
if (subven == "ffff" and subdev == "ffff"):
|
|
|
|
return SubDevice("ffff", "ffff", "(All Subdevices)")
|
2020-11-04 06:48:38 +00:00
|
|
|
return SubDevice(subven, subdev, "(Unknown Subdevice)")
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SubDevice:
|
|
|
|
"""
|
|
|
|
Class for subdevices.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, vendor, device, name):
|
|
|
|
"""
|
|
|
|
Class initializes with vendorid, deviceid and name
|
|
|
|
"""
|
|
|
|
self.vendorID = vendor
|
|
|
|
self.deviceID = device
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def report(self):
|
2016-12-21 15:03:48 +00:00
|
|
|
print("\t\t%s\t%s\t%s" % (self.vendorID, self.deviceID, self.name))
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PCIIds:
|
|
|
|
"""
|
|
|
|
Top class for all pci.ids entries.
|
|
|
|
All queries will be asked to this class.
|
|
|
|
PCIIds.vendors["0e11"].devices["0046"].\
|
|
|
|
subdevices["0e11:4091"].name = "Smart Array 6i"
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, filename):
|
|
|
|
"""
|
|
|
|
Prepares the directories.
|
|
|
|
Checks local data file.
|
|
|
|
Tries to load from local, if not found, downloads from web
|
|
|
|
"""
|
|
|
|
self.version = ""
|
|
|
|
self.date = ""
|
|
|
|
self.vendors = {}
|
|
|
|
self.contents = None
|
|
|
|
self.readLocal(filename)
|
|
|
|
self.parse()
|
|
|
|
|
|
|
|
def reportVendors(self):
|
|
|
|
"""Reports the vendors
|
|
|
|
"""
|
|
|
|
for vid, v in self.vendors.items():
|
2016-12-21 15:03:48 +00:00
|
|
|
print(v.ID, v.name)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
def report(self, vendor=None):
|
|
|
|
"""
|
|
|
|
Reports everything for all vendors or a specific vendor
|
|
|
|
PCIIds.report() reports everything
|
|
|
|
PCIIDs.report("0e11") reports only "Compaq Computer Corporation"
|
|
|
|
"""
|
|
|
|
if vendor is not None:
|
|
|
|
self.vendors[vendor].report()
|
|
|
|
else:
|
|
|
|
for vID, v in self.vendors.items():
|
|
|
|
v.report()
|
|
|
|
|
|
|
|
def find_vendor(self, vid):
|
|
|
|
# convert vid to a hex string and remove the 0x
|
|
|
|
vid = hex(vid)[2:]
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self.vendors[vid]
|
|
|
|
except:
|
|
|
|
return Vendor("%s Unknown Vendor" % (vid))
|
|
|
|
|
|
|
|
def findDate(self, content):
|
|
|
|
for l in content:
|
|
|
|
if l.find("Date:") > -1:
|
|
|
|
return l.split()[-2].replace("-", "")
|
|
|
|
return None
|
|
|
|
|
|
|
|
def parse(self):
|
2020-11-04 06:48:42 +00:00
|
|
|
if not self.contents:
|
2016-12-21 15:03:48 +00:00
|
|
|
print("data/%s-pci.ids not found" % self.date)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
else:
|
|
|
|
vendorID = ""
|
|
|
|
deviceID = ""
|
|
|
|
for l in self.contents:
|
|
|
|
if l[0] == "#":
|
|
|
|
continue
|
2020-11-04 06:48:42 +00:00
|
|
|
elif not l.strip():
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if l.find("\t\t") == 0:
|
|
|
|
self.vendors[vendorID].devices[
|
|
|
|
deviceID].addSubDevice(l)
|
|
|
|
elif l.find("\t") == 0:
|
|
|
|
deviceID = l.strip().split()[0]
|
|
|
|
self.vendors[vendorID].addDevice(l)
|
|
|
|
else:
|
|
|
|
vendorID = l.split()[0]
|
|
|
|
self.vendors[vendorID] = Vendor(l)
|
|
|
|
|
|
|
|
def readLocal(self, filename):
|
|
|
|
"""
|
|
|
|
Reads the local file
|
|
|
|
"""
|
2020-11-04 06:48:37 +00:00
|
|
|
with open(filename, 'r', encoding='utf-8') as f:
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
self.contents = f.readlines()
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
self.date = self.findDate(self.contents)
|
|
|
|
|
|
|
|
def loadLocal(self):
|
|
|
|
"""
|
|
|
|
Loads database from local. If there is no file,
|
|
|
|
it creates a new one from web
|
|
|
|
"""
|
|
|
|
self.date = idsfile[0].split("/")[1].split("-")[0]
|
|
|
|
self.readLocal()
|
|
|
|
|
|
|
|
|
|
|
|
# =======================================
|
|
|
|
|
|
|
|
def search_file(filename, search_path):
|
|
|
|
""" Given a search path, find file with requested name """
|
2020-11-04 06:48:36 +00:00
|
|
|
for path in search_path.split(':'):
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
candidate = os.path.join(path, filename)
|
|
|
|
if os.path.exists(candidate):
|
|
|
|
return os.path.abspath(candidate)
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
class ReadElf(object):
|
|
|
|
""" display_* methods are used to emit output into the output stream
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, file, output):
|
|
|
|
""" file:
|
|
|
|
stream object with the ELF file to read
|
|
|
|
|
|
|
|
output:
|
|
|
|
output stream to write to
|
|
|
|
"""
|
|
|
|
self.elffile = ELFFile(file)
|
|
|
|
self.output = output
|
|
|
|
|
|
|
|
# Lazily initialized if a debug dump is requested
|
|
|
|
self._dwarfinfo = None
|
|
|
|
|
|
|
|
self._versioninfo = None
|
|
|
|
|
|
|
|
def _section_from_spec(self, spec):
|
|
|
|
""" Retrieve a section given a "spec" (either number or name).
|
|
|
|
Return None if no such section exists in the file.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
num = int(spec)
|
|
|
|
if num < self.elffile.num_sections():
|
|
|
|
return self.elffile.get_section(num)
|
2020-11-04 06:48:38 +00:00
|
|
|
return None
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
except ValueError:
|
|
|
|
# Not a number. Must be a name then
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
section = self.elffile.get_section_by_name(force_unicode(spec))
|
|
|
|
if section is None:
|
|
|
|
# No match with a unicode name.
|
|
|
|
# Some versions of pyelftools (<= 0.23) store internal strings
|
|
|
|
# as bytes. Try again with the name encoded as bytes.
|
|
|
|
section = self.elffile.get_section_by_name(force_bytes(spec))
|
|
|
|
return section
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
def pretty_print_pmdinfo(self, pmdinfo):
|
|
|
|
global pcidb
|
|
|
|
|
|
|
|
for i in pmdinfo["pci_ids"]:
|
|
|
|
vendor = pcidb.find_vendor(i[0])
|
|
|
|
device = vendor.find_device(i[1])
|
|
|
|
subdev = device.find_subid(i[2], i[3])
|
|
|
|
print("%s (%s) : %s (%s) %s" %
|
|
|
|
(vendor.name, vendor.ID, device.name,
|
|
|
|
device.ID, subdev.name))
|
|
|
|
|
|
|
|
def parse_pmd_info_string(self, mystring):
|
|
|
|
global raw_output
|
|
|
|
global pcidb
|
|
|
|
|
2016-12-15 13:46:39 +00:00
|
|
|
optional_pmd_info = [
|
|
|
|
{'id': 'params', 'tag': 'PMD PARAMETERS'},
|
|
|
|
{'id': 'kmod', 'tag': 'PMD KMOD DEPENDENCIES'}
|
|
|
|
]
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
i = mystring.index("=")
|
|
|
|
mystring = mystring[i + 2:]
|
|
|
|
pmdinfo = json.loads(mystring)
|
|
|
|
|
|
|
|
if raw_output:
|
tools: fix json output of pmdinfo
Using dpdk-pmdinfo with the '-r' flag does not produce a json output as
documented. Instead, the python representation of the json object is
shown, which is nearly the same, but cannot be properly parsed by a json
parser.
python repr (before):
{u'pci_ids': [[5549, 1968, 65535, 65535]], u'name': u'vmxnet3'}
json (after):
{"pci_ids": [[5549, 1968, 65535, 65535]], "name": "vmxnet3"}
Fixes: c67c9a5c646a ("tools: query binaries for HW and other support information")
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
2016-08-26 13:15:32 +00:00
|
|
|
print(json.dumps(pmdinfo))
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
print("PMD NAME: " + pmdinfo["name"])
|
|
|
|
for i in optional_pmd_info:
|
|
|
|
try:
|
|
|
|
print("%s: %s" % (i['tag'], pmdinfo[i['id']]))
|
2016-12-21 15:03:47 +00:00
|
|
|
except KeyError:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
continue
|
|
|
|
|
2020-11-04 06:48:42 +00:00
|
|
|
if pmdinfo["pci_ids"]:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("PMD HW SUPPORT:")
|
|
|
|
if pcidb is not None:
|
|
|
|
self.pretty_print_pmdinfo(pmdinfo)
|
|
|
|
else:
|
|
|
|
print("VENDOR\t DEVICE\t SUBVENDOR\t SUBDEVICE")
|
|
|
|
for i in pmdinfo["pci_ids"]:
|
|
|
|
print("0x%04x\t 0x%04x\t 0x%04x\t\t 0x%04x" %
|
|
|
|
(i[0], i[1], i[2], i[3]))
|
|
|
|
|
|
|
|
print("")
|
|
|
|
|
|
|
|
def display_pmd_info_strings(self, section_spec):
|
|
|
|
""" Display a strings dump of a section. section_spec is either a
|
|
|
|
section number or a name.
|
|
|
|
"""
|
|
|
|
section = self._section_from_spec(section_spec)
|
|
|
|
if section is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
data = section.data()
|
|
|
|
dataptr = 0
|
|
|
|
|
|
|
|
while dataptr < len(data):
|
|
|
|
while (dataptr < len(data) and
|
2020-11-04 06:48:40 +00:00
|
|
|
not 32 <= byte2int(data[dataptr]) <= 127):
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
dataptr += 1
|
|
|
|
|
|
|
|
if dataptr >= len(data):
|
|
|
|
break
|
|
|
|
|
|
|
|
endptr = dataptr
|
|
|
|
while endptr < len(data) and byte2int(data[endptr]) != 0:
|
|
|
|
endptr += 1
|
|
|
|
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# pyelftools may return byte-strings, force decode them
|
|
|
|
mystring = force_unicode(data[dataptr:endptr])
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
rc = mystring.find("PMD_INFO_STRING")
|
2020-11-04 06:48:38 +00:00
|
|
|
if rc != -1:
|
2020-11-19 09:44:01 +00:00
|
|
|
self.parse_pmd_info_string(mystring[rc:])
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
|
|
|
dataptr = endptr
|
|
|
|
|
|
|
|
def find_librte_eal(self, section):
|
|
|
|
for tag in section.iter_tags():
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# pyelftools may return byte-strings, force decode them
|
|
|
|
if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
|
|
|
|
if "librte_eal" in force_unicode(tag.needed):
|
|
|
|
return force_unicode(tag.needed)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def search_for_autoload_path(self):
|
|
|
|
scanelf = self
|
|
|
|
scanfile = None
|
|
|
|
library = None
|
|
|
|
|
|
|
|
section = self._section_from_spec(".dynamic")
|
|
|
|
try:
|
|
|
|
eallib = self.find_librte_eal(section)
|
|
|
|
if eallib is not None:
|
|
|
|
ldlibpath = os.environ.get('LD_LIBRARY_PATH')
|
|
|
|
if ldlibpath is None:
|
|
|
|
ldlibpath = ""
|
|
|
|
dtr = self.get_dt_runpath(section)
|
|
|
|
library = search_file(eallib,
|
|
|
|
dtr + ":" + ldlibpath +
|
|
|
|
":/usr/lib64:/lib64:/usr/lib:/lib")
|
|
|
|
if library is None:
|
|
|
|
return (None, None)
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("Scanning for autoload path in %s" % library)
|
2020-11-04 06:48:37 +00:00
|
|
|
scanfile = open(library, 'rb')
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
scanelf = ReadElf(scanfile, sys.stdout)
|
|
|
|
except AttributeError:
|
|
|
|
# Not a dynamic binary
|
|
|
|
pass
|
|
|
|
except ELFError:
|
|
|
|
scanfile.close()
|
|
|
|
return (None, None)
|
|
|
|
|
|
|
|
section = scanelf._section_from_spec(".rodata")
|
|
|
|
if section is None:
|
|
|
|
if scanfile is not None:
|
|
|
|
scanfile.close()
|
|
|
|
return (None, None)
|
|
|
|
|
|
|
|
data = section.data()
|
|
|
|
dataptr = 0
|
|
|
|
|
|
|
|
while dataptr < len(data):
|
|
|
|
while (dataptr < len(data) and
|
2020-11-04 06:48:40 +00:00
|
|
|
not 32 <= byte2int(data[dataptr]) <= 127):
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
dataptr += 1
|
|
|
|
|
|
|
|
if dataptr >= len(data):
|
|
|
|
break
|
|
|
|
|
|
|
|
endptr = dataptr
|
|
|
|
while endptr < len(data) and byte2int(data[endptr]) != 0:
|
|
|
|
endptr += 1
|
|
|
|
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# pyelftools may return byte-strings, force decode them
|
|
|
|
mystring = force_unicode(data[dataptr:endptr])
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
rc = mystring.find("DPDK_PLUGIN_PATH")
|
2020-11-04 06:48:38 +00:00
|
|
|
if rc != -1:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
rc = mystring.find("=")
|
|
|
|
return (mystring[rc + 1:], library)
|
|
|
|
|
|
|
|
dataptr = endptr
|
|
|
|
if scanfile is not None:
|
|
|
|
scanfile.close()
|
|
|
|
return (None, None)
|
|
|
|
|
|
|
|
def get_dt_runpath(self, dynsec):
|
|
|
|
for tag in dynsec.iter_tags():
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# pyelftools may return byte-strings, force decode them
|
|
|
|
if force_unicode(tag.entry.d_tag) == 'DT_RUNPATH':
|
|
|
|
return force_unicode(tag.runpath)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def process_dt_needed_entries(self):
|
|
|
|
""" Look to see if there are any DT_NEEDED entries in the binary
|
|
|
|
And process those if there are
|
|
|
|
"""
|
|
|
|
runpath = ""
|
|
|
|
ldlibpath = os.environ.get('LD_LIBRARY_PATH')
|
|
|
|
if ldlibpath is None:
|
|
|
|
ldlibpath = ""
|
|
|
|
|
|
|
|
dynsec = self._section_from_spec(".dynamic")
|
|
|
|
try:
|
|
|
|
runpath = self.get_dt_runpath(dynsec)
|
|
|
|
except AttributeError:
|
|
|
|
# dynsec is None, just return
|
|
|
|
return
|
|
|
|
|
|
|
|
for tag in dynsec.iter_tags():
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# pyelftools may return byte-strings, force decode them
|
|
|
|
if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
|
2020-11-04 15:57:21 +00:00
|
|
|
if 'librte_' in force_unicode(tag.needed):
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
library = search_file(force_unicode(tag.needed),
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
runpath + ":" + ldlibpath +
|
|
|
|
":/usr/lib64:/lib64:/usr/lib:/lib")
|
|
|
|
if library is not None:
|
2020-11-04 06:48:37 +00:00
|
|
|
with open(library, 'rb') as file:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
try:
|
|
|
|
libelf = ReadElf(file, sys.stdout)
|
2016-12-21 15:03:47 +00:00
|
|
|
except ELFError:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("%s is no an ELF file" % library)
|
|
|
|
continue
|
|
|
|
libelf.process_dt_needed_entries()
|
|
|
|
libelf.display_pmd_info_strings(".rodata")
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
usertools: fix pmdinfo with python 3 and pyelftools>=0.24
Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:
~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
~$ echo $?
0
While with python 2, it works:
~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
{"pci_ids": [], "name": "dpio"}
{"pci_ids": [], "name": "dpbp"}
{"pci_ids": [], "name": "dpaa2_qdma"}
.....
On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:
- Symbol/section names are strings internally now, not bytestrings
(this may affect API usage in Python 3) (#76).
We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.
To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".
Add 2 utility functions to force a string into bytes or bytes into an
unicode string.
Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).
If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.
Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.
Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
2019-10-15 12:39:17 +00:00
|
|
|
# compat: remove force_unicode & force_bytes when pyelftools<=0.23 support is
|
|
|
|
# dropped.
|
|
|
|
def force_unicode(s):
|
|
|
|
if hasattr(s, 'decode') and callable(s.decode):
|
|
|
|
s = s.decode('latin-1') # same encoding used in pyelftools py3compat
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
def force_bytes(s):
|
|
|
|
if hasattr(s, 'encode') and callable(s.encode):
|
|
|
|
s = s.encode('latin-1') # same encoding used in pyelftools py3compat
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
def scan_autoload_path(autoload_path):
|
|
|
|
global raw_output
|
|
|
|
|
2020-11-04 06:48:39 +00:00
|
|
|
if not os.path.exists(autoload_path):
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
dirs = os.listdir(autoload_path)
|
2016-12-21 15:03:47 +00:00
|
|
|
except OSError:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
# Couldn't read the directory, give up
|
|
|
|
return
|
|
|
|
|
|
|
|
for d in dirs:
|
|
|
|
dpath = os.path.join(autoload_path, d)
|
|
|
|
if os.path.isdir(dpath):
|
|
|
|
scan_autoload_path(dpath)
|
|
|
|
if os.path.isfile(dpath):
|
|
|
|
try:
|
2020-11-04 06:48:37 +00:00
|
|
|
file = open(dpath, 'rb')
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
readelf = ReadElf(file, sys.stdout)
|
2016-12-21 15:03:47 +00:00
|
|
|
except ELFError:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
# this is likely not an elf file, skip it
|
|
|
|
continue
|
2016-12-21 15:03:47 +00:00
|
|
|
except IOError:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
# No permission to read the file, skip it
|
|
|
|
continue
|
|
|
|
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("Hw Support for library %s" % d)
|
|
|
|
readelf.display_pmd_info_strings(".rodata")
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def scan_for_autoload_pmds(dpdk_path):
|
|
|
|
"""
|
|
|
|
search the specified application or path for a pmd autoload path
|
|
|
|
then scan said path for pmds and report hw support
|
|
|
|
"""
|
|
|
|
global raw_output
|
|
|
|
|
2020-11-04 06:48:39 +00:00
|
|
|
if not os.path.isfile(dpdk_path):
|
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("Must specify a file name")
|
|
|
|
return
|
|
|
|
|
2020-11-04 06:48:37 +00:00
|
|
|
file = open(dpdk_path, 'rb')
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
try:
|
|
|
|
readelf = ReadElf(file, sys.stdout)
|
2016-12-21 15:03:47 +00:00
|
|
|
except ElfError:
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("Unable to parse %s" % file)
|
|
|
|
return
|
|
|
|
|
|
|
|
(autoload_path, scannedfile) = readelf.search_for_autoload_path()
|
2020-02-12 12:31:56 +00:00
|
|
|
if not autoload_path:
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("No autoload path configured in %s" % dpdk_path)
|
|
|
|
return
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
2020-11-04 06:48:38 +00:00
|
|
|
if scannedfile is None:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
scannedfile = dpdk_path
|
|
|
|
print("Found autoload path %s in %s" % (autoload_path, scannedfile))
|
|
|
|
|
|
|
|
file.close()
|
2020-11-04 06:48:39 +00:00
|
|
|
if not raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("Discovered Autoload HW Support:")
|
|
|
|
scan_autoload_path(autoload_path)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def main(stream=None):
|
|
|
|
global raw_output
|
|
|
|
global pcidb
|
|
|
|
|
2016-12-21 15:03:47 +00:00
|
|
|
pcifile_default = "./pci.ids" # For unknown OS's assume local file
|
2016-07-08 20:37:05 +00:00
|
|
|
if platform.system() == 'Linux':
|
2020-03-12 16:30:27 +00:00
|
|
|
# hwdata is the legacy location, misc is supported going forward
|
|
|
|
pcifile_default = "/usr/share/misc/pci.ids"
|
|
|
|
if not os.path.exists(pcifile_default):
|
|
|
|
pcifile_default = "/usr/share/hwdata/pci.ids"
|
2016-07-08 20:37:05 +00:00
|
|
|
elif platform.system() == 'FreeBSD':
|
|
|
|
pcifile_default = "/usr/local/share/pciids/pci.ids"
|
|
|
|
if not os.path.exists(pcifile_default):
|
|
|
|
pcifile_default = "/usr/share/misc/pci_vendors"
|
|
|
|
|
2020-11-04 06:48:41 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
usage='usage: %(prog)s [-hrtp] [-d <pci id file>] elf_file',
|
|
|
|
description="Dump pmd hardware support info")
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
group.add_argument('-r', '--raw',
|
|
|
|
action='store_true', dest='raw_output',
|
|
|
|
help='dump raw json strings')
|
|
|
|
group.add_argument("-t", "--table", dest="tblout",
|
|
|
|
help="output information on hw support as a hex table",
|
|
|
|
action='store_true')
|
|
|
|
parser.add_argument("-d", "--pcidb", dest="pcifile",
|
|
|
|
help="specify a pci database to get vendor names from",
|
|
|
|
default=pcifile_default, metavar="FILE")
|
|
|
|
parser.add_argument("-p", "--plugindir", dest="pdir",
|
|
|
|
help="scan dpdk for autoload plugins",
|
|
|
|
action='store_true')
|
|
|
|
parser.add_argument("elf_file", help="driver shared object file")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.raw_output:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
raw_output = True
|
|
|
|
|
2020-11-04 06:48:41 +00:00
|
|
|
if args.tblout:
|
|
|
|
args.pcifile = None
|
|
|
|
|
|
|
|
if args.pcifile:
|
|
|
|
pcidb = PCIIds(args.pcifile)
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
if pcidb is None:
|
|
|
|
print("Pci DB file not found")
|
|
|
|
exit(1)
|
|
|
|
|
2020-11-04 06:48:41 +00:00
|
|
|
if args.pdir:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
exit(scan_for_autoload_pmds(args[0]))
|
|
|
|
|
|
|
|
ldlibpath = os.environ.get('LD_LIBRARY_PATH')
|
2020-11-04 06:48:38 +00:00
|
|
|
if ldlibpath is None:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
ldlibpath = ""
|
|
|
|
|
2020-11-04 06:48:41 +00:00
|
|
|
if os.path.exists(args.elf_file):
|
|
|
|
myelffile = args.elf_file
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
else:
|
2020-11-04 06:48:41 +00:00
|
|
|
myelffile = search_file(args.elf_file,
|
|
|
|
ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib")
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
|
2020-11-04 06:48:38 +00:00
|
|
|
if myelffile is None:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
print("File not found")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-11-04 06:48:37 +00:00
|
|
|
with open(myelffile, 'rb') as file:
|
tools: query binaries for HW and other support information
This tool searches for the primer sting PMD_DRIVER_INFO= in any ELF binary,
and, if found parses the remainder of the string as a json encoded string,
outputting the results in either a human readable or raw, script parseable
format
Note that, in the case of dynamically linked applications, pmdinfo.py will
scan for implicitly linked PMDs by searching the specified binaries
.dynamic section for DT_NEEDED entries that contain the substring
librte_pmd. The DT_RUNPATH, LD_LIBRARY_PATH, /usr/lib and /lib are
searched for these libraries, in that order
If a file is specified with no path, it is assumed to be a PMD DSO, and the
LD_LIBRARY_PATH, /usr/lib[64]/ and /lib[64] is searched for it
Currently the tool can output data in 3 formats:
a) raw, suitable for scripting, where the raw JSON strings are dumped out
b) table format (default) where hex pci ids are dumped in a table format
c) pretty, where a user supplied pci.ids file is used to print out vendor
and device strings
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-06-17 18:46:24 +00:00
|
|
|
try:
|
|
|
|
readelf = ReadElf(file, sys.stdout)
|
|
|
|
readelf.process_dt_needed_entries()
|
|
|
|
readelf.display_pmd_info_strings(".rodata")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
except ELFError as ex:
|
|
|
|
sys.stderr.write('ELF error: %s\n' % ex)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|