Skip to content

Commit 7451e6e

Browse files
author
Evan Lezar
committed
Merge branch 'custom-firmware-paths' into 'main'
Add firmware search paths when generating CDI specifications See merge request nvidia/container-toolkit/container-toolkit!439
2 parents 4f89b60 + 81908c8 commit 7451e6e

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Add option to create device nodes when creating `/dev/char` symlinks
1616
* Create ouput folders if required when running `nvidia-ctk runtime configure`
1717
* Generate default config as post-install step.
18+
* Added support for detecting GSP firmware at custom paths when generating CDI specifications.
1819

1920
* [libnvidia-container] Support OpenSSL 3 with the Encrypt/Decrypt library
2021

pkg/nvcdi/driver-nvml.go

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package nvcdi
1818

1919
import (
2020
"fmt"
21+
"os"
2122
"path/filepath"
2223
"strings"
2324

@@ -26,6 +27,7 @@ import (
2627
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
2728
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
2829
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
30+
"golang.org/x/sys/unix"
2931
)
3032

3133
// NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
@@ -55,7 +57,10 @@ func newDriverVersionDiscoverer(logger logger.Interface, driverRoot string, nvid
5557
return nil, fmt.Errorf("failed to create discoverer for IPC sockets: %v", err)
5658
}
5759

58-
firmwares := NewDriverFirmwareDiscoverer(logger, driverRoot, version)
60+
firmwares, err := NewDriverFirmwareDiscoverer(logger, driverRoot, version)
61+
if err != nil {
62+
return nil, fmt.Errorf("failed to create discoverer for GSP firmware: %v", err)
63+
}
5964

6065
binaries := NewDriverBinariesDiscoverer(logger, driverRoot)
6166

@@ -96,18 +101,65 @@ func NewDriverLibraryDiscoverer(logger logger.Interface, driverRoot string, nvid
96101
return d, nil
97102
}
98103

104+
func getUTSRelease() (string, error) {
105+
utsname := &unix.Utsname{}
106+
if err := unix.Uname(utsname); err != nil {
107+
return "", err
108+
}
109+
return unix.ByteSliceToString(utsname.Release[:]), nil
110+
}
111+
112+
func getFirmwareSearchPaths(logger logger.Interface) ([]string, error) {
113+
114+
var firmwarePaths []string
115+
if p := getCustomFirmwareClassPath(logger); p != "" {
116+
logger.Debugf("using custom firmware class path: %s", p)
117+
firmwarePaths = append(firmwarePaths, p)
118+
}
119+
120+
utsRelease, err := getUTSRelease()
121+
if err != nil {
122+
return nil, fmt.Errorf("failed to get UTS_RELEASE: %v", err)
123+
}
124+
125+
standardPaths := []string{
126+
filepath.Join("/lib/firmware/updates/", utsRelease),
127+
filepath.Join("/lib/firmware/updates/"),
128+
filepath.Join("/lib/firmware/", utsRelease),
129+
filepath.Join("/lib/firmware/"),
130+
}
131+
132+
return append(firmwarePaths, standardPaths...), nil
133+
}
134+
135+
// getCustomFirmwareClassPath returns the custom firmware class path if it exists.
136+
func getCustomFirmwareClassPath(logger logger.Interface) string {
137+
customFirmwareClassPath, err := os.ReadFile("/sys/module/firmware_class/parameters/path")
138+
if err != nil {
139+
logger.Warningf("failed to get custom firmware class path: %v", err)
140+
return ""
141+
}
142+
143+
return strings.TrimSpace(string(customFirmwareClassPath))
144+
}
145+
99146
// NewDriverFirmwareDiscoverer creates a discoverer for GSP firmware associated with the specified driver version.
100-
func NewDriverFirmwareDiscoverer(logger logger.Interface, driverRoot string, version string) discover.Discover {
101-
gspFirmwarePath := filepath.Join("/lib/firmware/nvidia", version, "gsp*.bin")
147+
func NewDriverFirmwareDiscoverer(logger logger.Interface, driverRoot string, version string) (discover.Discover, error) {
148+
gspFirmwareSearchPaths, err := getFirmwareSearchPaths(logger)
149+
if err != nil {
150+
return nil, fmt.Errorf("failed to get firmware search paths: %v", err)
151+
}
152+
gspFirmwarePaths := filepath.Join("nvidia", version, "gsp*.bin")
102153
return discover.NewMounts(
103154
logger,
104155
lookup.NewFileLocator(
105156
lookup.WithLogger(logger),
106157
lookup.WithRoot(driverRoot),
158+
lookup.WithSearchPaths(gspFirmwareSearchPaths...),
107159
),
108160
driverRoot,
109-
[]string{gspFirmwarePath},
110-
)
161+
[]string{gspFirmwarePaths},
162+
), nil
111163
}
112164

113165
// NewDriverBinariesDiscoverer creates a discoverer for GSP firmware associated with the GPU driver.

0 commit comments

Comments
 (0)