diff --git a/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version.go b/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version.go deleted file mode 100644 index 60320eed4ff1..000000000000 --- a/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version.go +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright 2020-present Facebook. All Rights Reserved. - * - * This program file is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program in a file named COPYING; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -package remediations_grandteton - -import ( - "encoding/json" - "log" - "regexp" - "strconv" - "time" - - "github.com/facebook/openbmc/tools/flashy/lib/step" - "github.com/facebook/openbmc/tools/flashy/lib/utils" - "github.com/facebook/openbmc/tools/flashy/lib/validate" - "github.com/pkg/errors" -) - -func init() { - step.RegisterStep(ensureCompatibleMBCPLDVersion) -} - -type FWUtilVersionJson struct { - COMPONENT string - FRU string - PRETTY_COMPONENT string - VERSION string -} - -var versionRegex = regexp.MustCompile("^grandteton-(v[0-9]+[.][0-9]+[.][0-9]+)$") - -var GetOpenBMCVersionFromImageFile = validate.GetOpenBMCVersionFromImageFile - -// ensureCompatibleMBCPLDVersion checks whether the MB CPLD version is compatible with the image being -// flashed -func ensureCompatibleMBCPLDVersion(stepParams step.StepParams) step.StepExitError { - // Fetch current MB CPLD version from fw-util - mbCpldVersion, stepErr := fwutilGetMbCpldVersion() - if stepErr != nil { - return stepErr - } - - // Fetch BMC version from image file - imageFileVer, err := GetOpenBMCVersionFromImageFile(stepParams.ImageFilePath) - if err != nil { - return step.ExitSafeToReboot{ - Err: err, - } - } - - if !versionRegex.MatchString(imageFileVer) { - return step.ExitSafeToReboot{ - Err: errors.Errorf("Image version '%v' does not match expected format %v", imageFileVer, versionRegex), - } - } - - // S365492: Images newer than v2024.11.1 require MB CPLD version 20010 or greater, otherwise sensor data - // becomes unavailable (T175831581). Booting older images with the new CPLD version should be safe. - if imageFileVer >= "grandteton-v2024.11.1" && mbCpldVersion < 20010 { - return step.ExitSafeToReboot{ - Err: errors.Errorf("S365492: Image version ('%v') requires MB CPLD version 20010 or greater (current MB CPLD version is %d)", imageFileVer, mbCpldVersion), - } - } - - log.Printf("MB CPLD version %d is compatible with image version %v", mbCpldVersion, imageFileVer) - - return nil -} - -func fwutilGetMbCpldVersion() (int, step.StepExitError) { - // Run fw-util - fwutilCmd := []string{ - "fw-util", "mb", "--version-json", "mb_cpld", - } - exitCode, err, stdout, stderr := utils.RunCommand(fwutilCmd, 1800*time.Second) - - if err != nil { - return 0, step.ExitSafeToReboot{ - Err: errors.Errorf("`fw-util mb --version-json mb_cpld` failed with exit code %d, stderr: %v, stdout: %v", exitCode, stderr, stdout), - } - } - - var fwutilVersionJson []FWUtilVersionJson - if err := json.Unmarshal([]byte(stdout), &fwutilVersionJson); err != nil { - return 0, step.ExitSafeToReboot{ - Err: errors.Errorf("failed to parse `fw-util mb --version-json mb_cpld` output: %v", err), - } - } - - if len(fwutilVersionJson) != 1 { - return 0, step.ExitSafeToReboot{ - Err: errors.Errorf("`fw-util mb --version-json mb_cpld` returned %v entries", len(fwutilVersionJson)), - } - } - - mbCpldVersion, err := strconv.Atoi(fwutilVersionJson[0].VERSION) - if err != nil { - return 0, step.ExitSafeToReboot{ - Err: errors.Errorf("Cannot parse `fw-util mb --version-json mb_cpld` version as integer: %v", fwutilVersionJson), - } - } - - return mbCpldVersion, nil -} diff --git a/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version_test.go b/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version_test.go deleted file mode 100644 index 2595d7352fd2..000000000000 --- a/tools/flashy/checks_and_remediations/grandteton/00_ensure_compatible_mb_cpld_version_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package remediations_grandteton - -import ( - "strings" - "testing" - "time" - - "github.com/facebook/openbmc/tools/flashy/lib/step" - "github.com/facebook/openbmc/tools/flashy/lib/utils" - "github.com/pkg/errors" -) - -var fwUtilOutputOldCpldExample = ` -[ - { - "COMPONENT": "mb_cpld", - "FRU": "mb", - "PRETTY_COMPONENT": "MB_CPLD", - "VERSION": "00020008" - } -] -` - -var fwUtilOutputNewCpldExample = ` -[ - { - "COMPONENT": "mb_cpld", - "FRU": "mb", - "PRETTY_COMPONENT": "MB_CPLD", - "VERSION": "00020010" - } -] -` - -func TestEnsureCompatibleMBCPLDVersion(t *testing.T) { - // mock and defer restore RunCommand - runCommandOrig := utils.RunCommand - getOpenBMCVersionFromImageFileOrig := GetOpenBMCVersionFromImageFile - defer func() { - utils.RunCommand = runCommandOrig - GetOpenBMCVersionFromImageFile = getOpenBMCVersionFromImageFileOrig - }() - cases := []struct { - name string - bmcImageVersion string - runCmdStdout string - want step.StepExitError - }{ - { - name: "succeeded as image version == v2023.39.2 and CPLD is old", - bmcImageVersion: "grandteton-v2023.39.2", - runCmdStdout: fwUtilOutputOldCpldExample, - want: nil, - }, - { - name: "succeeded as image version == v2024.11.1 and CPLD is new", - bmcImageVersion: "grandteton-v2024.11.1", - runCmdStdout: fwUtilOutputNewCpldExample, - want: nil, - }, - { - name: "succeeded as image version > v2024.11.1 and CPLD is new", - bmcImageVersion: "grandteton-v2024.12.1", - runCmdStdout: fwUtilOutputNewCpldExample, - want: nil, - }, - { - name: "failed as image version == v2024.11.1 but CPLD is old", - bmcImageVersion: "grandteton-v2024.11.1", - runCmdStdout: fwUtilOutputOldCpldExample, - want: step.ExitSafeToReboot{ - Err: errors.Errorf("S365492: Image version ('grandteton-v2024.11.1') requires MB CPLD version 20010 or greater (current MB CPLD version is 20008)"), - }, - }, - { - name: "failed as image version > v2024.11.1 but CPLD is old", - bmcImageVersion: "grandteton-v2024.12.0", - runCmdStdout: fwUtilOutputOldCpldExample, - want: step.ExitSafeToReboot{ - Err: errors.Errorf("S365492: Image version ('grandteton-v2024.12.0') requires MB CPLD version 20010 or greater (current MB CPLD version is 20008)"), - }, - }, - { - name: "invalid image version", - bmcImageVersion: "fby3-v2024.12.0", - runCmdStdout: fwUtilOutputOldCpldExample, - want: step.ExitSafeToReboot{ - Err: errors.Errorf("Image version 'fby3-v2024.12.0' does not match expected format ^grandteton-(v[0-9]+[.][0-9]+[.][0-9]+)$"), - }, - }, - } - - wantCmd := "fw-util mb --version-json mb_cpld" - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - utils.RunCommand = func(cmdArr []string, timeout time.Duration) (int, error, string, string) { - gotCmd := strings.Join(cmdArr, " ") - if wantCmd != gotCmd { - t.Errorf("cmd: want '%v' got '%v'", wantCmd, gotCmd) - } - return 0, nil, tc.runCmdStdout, "" - } - GetOpenBMCVersionFromImageFile = func(imageFile string) (string, error) { - return tc.bmcImageVersion, nil - } - got := ensureCompatibleMBCPLDVersion(step.StepParams{}) - step.CompareTestExitErrors(tc.want, got, t) - }) - } -} diff --git a/tools/flashy/install/install.go b/tools/flashy/install/install.go index fa9a2eff0cea..ac7ede289d9d 100644 --- a/tools/flashy/install/install.go +++ b/tools/flashy/install/install.go @@ -34,7 +34,6 @@ import ( _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/galaxy100" _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/wedge100" _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/yamp" - _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/grandteton" _ "github.com/facebook/openbmc/tools/flashy/flash_procedure" _ "github.com/facebook/openbmc/tools/flashy/utilities" )