@@ -18,6 +18,7 @@ package nvcdi
1818
1919import (
2020 "fmt"
21+ "os"
2122 "path/filepath"
2223 "strings"
2324
@@ -26,6 +27,7 @@ import (
2627 "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
2728 "github.com/sirupsen/logrus"
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 *logrus.Logger, driverRoot string, nvidia
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
@@ -100,18 +105,65 @@ func NewDriverLibraryDiscoverer(logger *logrus.Logger, driverRoot string, nvidia
100105 return d , nil
101106}
102107
108+ func getUTSRelease () (string , error ) {
109+ utsname := & unix.Utsname {}
110+ if err := unix .Uname (utsname ); err != nil {
111+ return "" , err
112+ }
113+ return unix .ByteSliceToString (utsname .Release [:]), nil
114+ }
115+
116+ func getFirmwareSearchPaths (logger * logrus.Logger ) ([]string , error ) {
117+
118+ var firmwarePaths []string
119+ if p := getCustomFirmwareClassPath (logger ); p != "" {
120+ logger .Debugf ("using custom firmware class path: %s" , p )
121+ firmwarePaths = append (firmwarePaths , p )
122+ }
123+
124+ utsRelease , err := getUTSRelease ()
125+ if err != nil {
126+ return nil , fmt .Errorf ("failed to get UTS_RELEASE: %v" , err )
127+ }
128+
129+ standardPaths := []string {
130+ filepath .Join ("/lib/firmware/updates/" , utsRelease ),
131+ filepath .Join ("/lib/firmware/updates/" ),
132+ filepath .Join ("/lib/firmware/" , utsRelease ),
133+ filepath .Join ("/lib/firmware/" ),
134+ }
135+
136+ return append (firmwarePaths , standardPaths ... ), nil
137+ }
138+
139+ // getCustomFirmwareClassPath returns the custom firmware class path if it exists.
140+ func getCustomFirmwareClassPath (logger * logrus.Logger ) string {
141+ customFirmwareClassPath , err := os .ReadFile ("/sys/module/firmware_class/parameters/path" )
142+ if err != nil {
143+ logger .Warningf ("failed to get custom firmware class path: %v" , err )
144+ return ""
145+ }
146+
147+ return strings .TrimSpace (string (customFirmwareClassPath ))
148+ }
149+
103150// NewDriverFirmwareDiscoverer creates a discoverer for GSP firmware associated with the specified driver version.
104- func NewDriverFirmwareDiscoverer (logger * logrus.Logger , driverRoot string , version string ) discover.Discover {
105- gspFirmwarePath := filepath .Join ("/lib/firmware/nvidia" , version , "gsp*.bin" )
151+ func NewDriverFirmwareDiscoverer (logger * logrus.Logger , driverRoot string , version string ) (discover.Discover , error ) {
152+ gspFirmwareSearchPaths , err := getFirmwareSearchPaths (logger )
153+ if err != nil {
154+ return nil , fmt .Errorf ("failed to get firmware search paths: %v" , err )
155+ }
156+ gspFirmwarePaths := filepath .Join ("nvidia" , version , "gsp*.bin" )
106157 return discover .NewMounts (
107158 logger ,
108159 lookup .NewFileLocator (
109160 lookup .WithLogger (logger ),
110161 lookup .WithRoot (driverRoot ),
162+ lookup .WithSearchPaths (gspFirmwareSearchPaths ... ),
111163 ),
112164 driverRoot ,
113- []string {gspFirmwarePath },
114- )
165+ []string {gspFirmwarePaths },
166+ ), nil
115167}
116168
117169// NewDriverBinariesDiscoverer creates a discoverer for GSP firmware associated with the GPU driver.
0 commit comments