Skip to content

Commit 61511a4

Browse files
Merge pull request #292 from Mellanox/bfb-update-fix
Add BlueField-4 support and tolerate missing BFB versions
2 parents ec9238f + 0e4f210 commit 61511a4

File tree

4 files changed

+130
-94
lines changed

4 files changed

+130
-94
lines changed

pkg/consts/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
BlueField3DeviceID = "a2dc"
2121
BlueField3LxDeviceID = "a2d9"
2222
BlueField2DeviceID = "a2d6"
23+
BlueField4DeviceID = "a2df"
2324

2425
Ethernet = "Ethernet"
2526
Infiniband = "Infiniband"

pkg/firmware/utils.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,32 +282,35 @@ func (u *utils) GetFWVersionsFromBFB(bfbPath string) (map[string]string, error)
282282

283283
versions := make(map[string]string)
284284

285-
log.Log.V(2).Info("Extracting versions from info-v0 file", "bfbPath", bfbPath)
286-
cmd = u.execInterface.Command("/bin/sh", "-c", `awk '/"Name": "BF3_NIC_FW"/ {getline; print $2}' `+infoFile+` | tr -d '",'`)
287-
bf3NicFwVersion, err := cmd.Output()
288-
if err != nil {
289-
log.Log.Error(err, "GetFWVersionsFromBFB(): Failed to extract BF3 NIC FW version")
290-
return nil, err
285+
bfVersions := []struct {
286+
name string
287+
deviceID string
288+
}{
289+
{name: "BF2_NIC_FW", deviceID: consts.BlueField2DeviceID},
290+
{name: "BF3_NIC_FW", deviceID: consts.BlueField3DeviceID},
291+
{name: "BF4_NIC_FW", deviceID: consts.BlueField4DeviceID},
291292
}
292293

293-
bf3Version := strings.TrimSpace(string(bf3NicFwVersion))
294-
if bf3Version == "" {
295-
return nil, fmt.Errorf("GetFWVersionsFromBFB(): BF3 NIC FW version is empty or not found in BFB file")
296-
}
297-
versions[consts.BlueField3DeviceID] = bf3Version
294+
log.Log.V(2).Info("Extracting versions from info-v0 file", "bfbPath", bfbPath)
295+
for _, bfv := range bfVersions {
296+
cmd = u.execInterface.Command("/bin/sh", "-c", `awk '/"Name": "`+bfv.name+`"/ {getline; print $2}' `+infoFile+` | tr -d '",'`)
297+
output, err := cmd.Output()
298+
if err != nil {
299+
log.Log.V(2).Info("GetFWVersionsFromBFB(): Failed to extract version, skipping", "name", bfv.name, "error", err)
300+
continue
301+
}
298302

299-
cmd = u.execInterface.Command("/bin/sh", "-c", `awk '/"Name": "BF2_NIC_FW"/ {getline; print $2}' `+infoFile+` | tr -d '",'`)
300-
bf2NicFwVersion, err := cmd.Output()
301-
if err != nil {
302-
log.Log.Error(err, "GetFWVersionsFromBFB(): Failed to extract BF2 NIC FW version")
303-
return nil, err
303+
version := strings.TrimSpace(string(output))
304+
if version == "" {
305+
log.Log.V(2).Info("GetFWVersionsFromBFB(): Version is empty or not found, skipping", "name", bfv.name)
306+
continue
307+
}
308+
versions[bfv.deviceID] = version
304309
}
305310

306-
bf2Version := strings.TrimSpace(string(bf2NicFwVersion))
307-
if bf2Version == "" {
308-
return nil, fmt.Errorf("GetFWVersionsFromBFB(): BF2 NIC FW version is empty or not found in BFB file")
311+
if len(versions) == 0 {
312+
return nil, fmt.Errorf("GetFWVersionsFromBFB(): no firmware versions found in BFB file")
309313
}
310-
versions[consts.BlueField2DeviceID] = bf2Version
311314

312315
return versions, nil
313316
}

0 commit comments

Comments
 (0)