2016-07-08 20:37:05 +00:00
|
|
|
#!/usr/bin/env python
|
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:48 +00:00
|
|
|
from __future__ import print_function
|
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 __future__ import unicode_literals
|
2016-12-21 15:03:47 +00:00
|
|
|
import json
|
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
|
|
|
import io
|
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
|
|
|
|
import string
|
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
|
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
|
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
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
# 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)")
|
|
|
|
else:
|
|
|
|
return SubDevice(subven, subdev, "(Unknown Subdevice)")
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
if len(self.contents) < 1:
|
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
|
|
|
|
elif len(l.strip()) == 0:
|
|
|
|
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
|
|
|
|
"""
|
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
|
|
|
with io.open(filename, 'r', encoding='utf-8') as f:
|
|
|
|
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 """
|
|
|
|
for path in string.split(search_path, ":"):
|
|
|
|
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)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
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
|
|
|
|
|
|
|
|
if (len(pmdinfo["pci_ids"]) != 0):
|
|
|
|
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
|
|
|
|
not (32 <= byte2int(data[dataptr]) <= 127)):
|
|
|
|
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")
|
|
|
|
if (rc != -1):
|
|
|
|
self.parse_pmd_info_string(mystring)
|
|
|
|
|
|
|
|
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)
|
|
|
|
if raw_output is False:
|
|
|
|
print("Scanning for autoload path in %s" % library)
|
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
|
|
|
scanfile = io.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
|
|
|
|
not (32 <= byte2int(data[dataptr]) <= 127)):
|
|
|
|
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")
|
|
|
|
if (rc != -1):
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
global raw_output
|
|
|
|
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':
|
|
|
|
if 'librte_pmd' in force_unicode(tag.needed):
|
|
|
|
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:
|
|
|
|
if raw_output is False:
|
|
|
|
print("Scanning %s for pmd information" % library)
|
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
|
|
|
with io.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
|
|
|
|
|
|
|
|
if os.path.exists(autoload_path) is False:
|
|
|
|
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:
|
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
|
|
|
file = io.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
|
|
|
|
|
|
|
|
if raw_output is False:
|
|
|
|
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
|
|
|
|
|
|
|
|
if (os.path.isfile(dpdk_path) is False):
|
|
|
|
if raw_output is False:
|
|
|
|
print("Must specify a file name")
|
|
|
|
return
|
|
|
|
|
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
|
|
|
file = io.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:
|
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 raw_output is False:
|
|
|
|
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:
|
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 (raw_output is False):
|
|
|
|
print("No autoload path configured in %s" % dpdk_path)
|
|
|
|
return
|
|
|
|
if (raw_output is False):
|
|
|
|
if (scannedfile is None):
|
|
|
|
scannedfile = dpdk_path
|
|
|
|
print("Found autoload path %s in %s" % (autoload_path, scannedfile))
|
|
|
|
|
|
|
|
file.close()
|
|
|
|
if (raw_output is False):
|
|
|
|
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"
|
|
|
|
|
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
|
|
|
optparser = OptionParser(
|
|
|
|
usage='usage: %prog [-hrtp] [-d <pci id file] <elf-file>',
|
|
|
|
description="Dump pmd hardware support info",
|
2016-07-20 13:38:54 +00:00
|
|
|
add_help_option=True)
|
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
|
|
|
optparser.add_option('-r', '--raw',
|
|
|
|
action='store_true', dest='raw_output',
|
|
|
|
help='Dump raw json strings')
|
|
|
|
optparser.add_option("-d", "--pcidb", dest="pcifile",
|
|
|
|
help="specify a pci database "
|
|
|
|
"to get vendor names from",
|
2016-07-08 20:37:05 +00:00
|
|
|
default=pcifile_default, metavar="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
|
|
|
optparser.add_option("-t", "--table", dest="tblout",
|
2016-12-21 15:03:47 +00:00
|
|
|
help="output information on hw support as a "
|
|
|
|
"hex table",
|
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
|
|
|
action='store_true')
|
|
|
|
optparser.add_option("-p", "--plugindir", dest="pdir",
|
|
|
|
help="scan dpdk for autoload plugins",
|
|
|
|
action='store_true')
|
|
|
|
|
|
|
|
options, args = optparser.parse_args()
|
|
|
|
|
|
|
|
if options.raw_output:
|
|
|
|
raw_output = True
|
|
|
|
|
|
|
|
if options.pcifile:
|
|
|
|
pcidb = PCIIds(options.pcifile)
|
|
|
|
if pcidb is None:
|
|
|
|
print("Pci DB file not found")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if options.tblout:
|
|
|
|
options.pcifile = None
|
|
|
|
pcidb = None
|
|
|
|
|
|
|
|
if (len(args) == 0):
|
|
|
|
optparser.print_usage()
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if options.pdir is True:
|
|
|
|
exit(scan_for_autoload_pmds(args[0]))
|
|
|
|
|
|
|
|
ldlibpath = os.environ.get('LD_LIBRARY_PATH')
|
|
|
|
if (ldlibpath is None):
|
|
|
|
ldlibpath = ""
|
|
|
|
|
|
|
|
if (os.path.exists(args[0]) is True):
|
|
|
|
myelffile = args[0]
|
|
|
|
else:
|
|
|
|
myelffile = search_file(
|
|
|
|
args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib")
|
|
|
|
|
|
|
|
if (myelffile is None):
|
|
|
|
print("File not found")
|
|
|
|
sys.exit(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
|
|
|
with io.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()
|