Refactor Static Inventory, MCTP Discovery and Rediscovery Flow

'''
why:
1. NsmDevice was created based on static inventory provided by EM config file and it was mapped to the MCTP EID in sensor polling loop.
   This was not an efficient and cleaner method to remap device and there was dependency on sensor manager to map EID from Static inventory.
2. The MCTP rediscovery flow was not efficient, leading to many incoming bugs in field. There was multiple in between operations involved in
   MCTP rediscovery signal and the corresponding nsmDevice going online and offline.
3. Due to issue 2, it was creating hindrance in making discovery flow atomic.

what:
1. Restructuring of static inventory object in EM config file, it will help in removing instance mapping file from platform configs.
2. MCTP discovery/Rediscovery flow and Static inventory mapping is restructured and made more modular.
'''

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Refactor Init, Mctp Rediscovery and Synchronize Post/Patch

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Fix for state maintenance during rediscovery and state management

'''
- Implement sequential processing of rediscovery signals
- Add queue management for MCTP info in device manager
- Update NsmDevice state based on queued MCTP info
- Ensure state consistency with last received signal
'''

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by <ayushkumart@nvidia.com>

Add Coroutine Semaphore for locking nsm device update

'''
Semaphore is required for synchronizing update nsm device during init if mctp discovery signal is also received.
'''

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Refactor: Extract capability sensor refresh into separate function

'''
Capability sensors must be refreshed after MCTP rediscovery events and driver reloads. Previously, this functionality was embedded within a monolithic function that also handled command code matrix refresh and FRU updates. This commit extracts the capability sensor refresh logic into a dedicated `refreshCapabilitySensor()` function to improve code modularity and maintainability.

The new function is called from:
- MCTP rediscovery event handlers
- Driver reload scenarios
- Device state transitions
'''

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Defer Rediscovery Event processing while MCTP rediscovery is in progress

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Rebase after upstream sync

Fixes Jira https://jirasw.nvidia.com/browse/DGXOPENBMC-17745
signed-off-by: <ayushkumart@nvidia.com>

Change-Id: I2d87efe8a0b49ce5d3ee324aea89e9a50fc53e58
1 file changed
tree: 2b048eb8e2bc095dc46351a535c3672b95af6ba4
  1. common/
  2. example/
  3. libnsm/
  4. mockupResponder/
  5. nsmd/
  6. nsmtool/
  7. requester/
  8. services/
  9. subprojects/
  10. tools/
  11. tracepoints/
  12. .beautysh-ignore
  13. .black-ignore
  14. .clang-format
  15. .eslintignore
  16. .flake8-ignore
  17. .gitignore
  18. .isort-ignore
  19. .markdownlint-ignore
  20. .prettierignore
  21. .shellcheck-ignore
  22. LICENSE
  23. meson.build
  24. meson_options.txt
  25. README.md
README.md

nsmd - Nvidia System Management Daemon

How to build

Install dependencies

sudo apt install build-essential gcc-13 g++-13 python3-dev nlohmann-json3-dev
pip install --user meson ninja

Install Boost

sudo apt install libboost1.83-all-dev # for Ubuntu 22.04

or

sudo apt install libboost1.84-all-dev # for Ubuntu 24.04

or if it not installed, download and install it from source.

wget https://downloads.sourceforge.net/project/boost/boost/1.84.0/boost_1_84_0.tar.gz
tar -xzf boost_1_84_0.tar.gz
cd boost_1_84_0
./bootstrap.sh --prefix=/usr/local
./b2 install

Copy libmctp header for local development

git archive --remote=ssh://git@gitlab-master.nvidia.com:12051/dgx/bmc/libmctp.git develop libmctp-externals.h | tar -x -C common/

Configure and build with Meson

# Configure Meson build with debug options and compiler flags (copied from openbmc-build-scripts repo)
meson setup --reconfigure -Db_sanitize=address,undefined -Db_lundef=true -Dwerror=true -Dwarning_level=3 -Db_colorout=never --buildtype=debug -Dcpp_args="-Wno-error=invalid-constexpr -Wno-invalid-constexpr -Werror=uninitialized -Werror=strict-aliasing" builddir
# Build all targets
ninja -C builddir

Build and run unit tests

# Run all unit tests
meson test -C builddir
# Run specific unit test
meson test -C builddir nsmChassis_test

Troubleshooting Build Issues

sdbusplus Version Mismatch

If you encounter sdbusplus build errors, verify that the revision in subprojects/sdbusplus.wrap matches the version specified in the openbmc-build-scripts repository. Version mismatches can cause build failures.

Updating Subproject Dependencies

For other subproject-related errors, you can update all subproject repositories to their latest commits using:

cd subprojects

find -L . -type d -name ".git" | while read gitdir; do
    repo=$(dirname "$gitdir")
    echo "Pulling updates in $repo"
    cd "$repo"
    git pull
    cd - > /dev/null
done

Unit Tests Debugging

Debugging with GDB in console

# Debug all tests
meson test -C builddir --gdb

# Debug specific test
meson test -C builddir nsmChassis_test --gdb

Debugging with GDB in VSCode/Cursor

  1. Configure launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug file with Meson",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/builddir/${relativeFileDirname}/${fileBasenameNoExtension}",
            "cwd": "${workspaceFolder}/builddir/${relativeFileDirname}",
            "preLaunchTask": "Compile meson test"
        }
    ]
}
  1. Configure tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile meson test",
            "type": "shell",
            "command": "meson compile -C builddir ${fileBasenameNoExtension}",
            "group": "build",
        }
    ]
}
  1. Open the unit test file you want to debug in VSCode/Cursor
  2. Set breakpoints in the code where needed
  3. Press F5 to start debugging the test

Installing clang-format-19 for CI Usage

To ensure code consistency and formatting standards in the CI pipeline, clang-format-19 needs to be installed. Follow the steps below to install clang-format-19 on your system:

# Update the package list
sudo apt update

# Install clang-format-19
sudo apt install clang-format-19

This will install clang-format-19 on your system, enabling it for use in the CI pipeline.

Using clang-format-19 for all changed files before commit

To automatically format your code before each commit, create a pre-commit hook with the following steps:

cat > .git/hooks/pre-commit << EOL
#!/bin/sh

# Get list of staged files that are C/C++ source files
files=$(git diff --cached --name-only --diff-filter=ACMR | grep ".*\.[ch]\(pp\)\?$")

if [ -n "$files" ]; then
    # Format the files
    clang-format-19 -i $files
    
    # Add the formatted files back to staging
    git add $files
    
    # Check if any files were modified after formatting
    if ! git diff --cached --quiet; then
        echo "Formatted C/C++ files were automatically fixed up"
    fi
fi

exit 0
EOL
chmod +x .git/hooks/pre-commit

Artifacts

Successful build should generate three binary artifacts.

  1. nsmd (NSM Daemon)
  2. nsmtool (NSM Requester utility)
  3. nsmMockupResponder (NSM Endpoint Mockup Responder)

nsmd

A Daemon that can discover NSM endpoint, gather telemetry data from the endpoints, and can publish them to D-Bus or similar IPC services, for consumer services like bmcweb.

nsmtool

nsmtool is a client tool that acts as a NSM requester which can be invoked from the BMC. nsmtool sends the request message and parse the response message & display it in readable format.

nsmMockupResponder

A mockup NSM responder that can be used for development purpose. Its primary usage is to test nsmd and nsmtool features on an emulator like QEMU. The mockup NSM responder includes modified MCTP control and demux daemon, user can create a emulated MCTP endpoint by providing a json file to modified MCTP control daemon to expose the emulated MCTP Endpoint to D-Bus.

The mockup NSM responder listens to demux unix socket for the request from nsmd/nsmtool and returns the respond through modified MCTP demux daemon.