summaryrefslogtreecommitdiffstats
path: root/staslib/nbft.py
blob: c643c9cc286d38d82f556e52f26a1a5ebce30068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (c) 2023, Dell Inc. or its subsidiaries.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See the LICENSE file for details.
#
# This file is part of NVMe STorage Appliance Services (nvme-stas).
#
# Authors: Martin Belanger <Martin.Belanger@dell.com>
#
'''Code used to access the NVMe Boot Firmware Tables'''

import os
import glob
import logging
from libnvme import nvme
from staslib import defs


def get_nbft_files(root_dir=defs.NBFT_SYSFS_PATH):
    """Return a dictionary containing the NBFT data for all the NBFT binary files located in @root_dir"""
    if not defs.HAS_NBFT_SUPPORT:
        logging.warning(
            "libnvme-%s does not have NBFT support. Please upgrade libnvme.",
            defs.LIBNVME_VERSION,
        )
        return {}

    pathname = os.path.join(root_dir, defs.NBFT_SYSFS_FILENAME)
    return {fname: nvme.nbft_get(fname) or {} for fname in glob.iglob(pathname=pathname)}  # pylint: disable=no-member