Skip to content

Commit

Permalink
Use regexp for Flashy S356523 workaround
Browse files Browse the repository at this point in the history
Summary:
When tested on an affected device with the built ephemeral fbpkg, the workaround in D47928352 did not catch the issue.

While the grep matches, it fails when used as a utils.runCommand
```
In [14]: await host.run_raw_cmd("grep mtd0:.*spi0.1 /proc/mtd")
Out[14]: CommandResult(exit_status=0, stderr='', stdout='mtd0: 08000000 00010000 "spi0.1"\n', exit_signal=None)

In [15]: await flashy.flashy_checks_and_remediations("flash1","grandteton","openbmc.image.grandteton:v2023.25.2",True)
Command '/run/flashy/checks_and_remediations/common/05_ensure_flash_writable --imagepath /run/upgrade/image --device mtd:flash1' exited with non-zero exit code: CommandResult(exit_status=53, std
err='2023/07/31 16:10:47 Starting: checks_and_remediations/common/05_ensure_flash_writable\n2023/07/31 16:10:47 Running command \'grep mtd0:.*spi0.1 /proc/mtd\' with 30s timeout\n2023/07/31 16:1
0:47 Command \'grep mtd0:.*spi0.1 /proc/mtd\' exited with code 1 after 6.668228ms\n2023/07/31 16:10:47 Running command \'fw_printenv bootargs\' with 30s timeout\n2023/07/31 16:10:47 stderr: Warn
ing: Bad CRC, using default environment\n2023/07/31 16:10:47 stdout: bootargs=console=ttyS0,57600n8 root=/dev/ram rw vmalloc=384M\n2023/07/31 16:10:47 Command \'fw_printenv bootargs\' exited wit
h code 0 after 17.899282ms\n2023/07/31 16:10:47 Running command \'fw_setenv _flashy_test 4d658221\' with 30s timeout\n2023/07/31 16:10:47 stderr: Warning: Bad CRC, using default environment\n202
3/07/31 16:10:47 Command \'fw_setenv _flashy_test 4d658221\' exited with code 0 after 30.450366ms\n2023/07/31 16:10:47 Running command \'fw_printenv _flashy_test\' with 30s timeout\n2023/07/31 1
6:10:47 stderr: Warning: Bad CRC, using default environment\n2023/07/31 16:10:47 stderr: ## Error: "_flashy_test" not defined\n2023/07/31 16:10:47 Command \'fw_printenv _flashy_test\' exited wit
h code 1 after 19.637594ms\n2023/07/31 16:10:47 U-Boot environment is READ ONLY\n2023/07/31 16:10:47 Running command \'fw_setenv _flashy_test\' with 30s timeout\n2023/07/31 16:10:47 stderr: Warn
ing: Bad CRC, using default environment\n2023/07/31 16:10:47 Command \'fw_setenv _flashy_test\' exited with code 0 after 30.213364ms\n2023/07/31 16:10:47 {Err:U-Boot environment is read only: fl
ash chips swapped? Error code: exit status 1, stderr: Warning: Bad CRC, using default environment\n## Error: "_flashy_test" not defined\n\ngithub.com/facebook/openbmc/tools/flashy/checks_and_rem
ediations/common.ensureFlashWritable\n\t/home/ciaranconcannon/local/openbmc/tools/flashy/checks_and_remediations/common/05_ensure_flash_writable.go:98\nmain.main\n\t/home/ciaranconcannon/local/o
penbmc/tools/flashy/flashy.go:139\nruntime.main\n\t/data/users/ciaranconcannon/gopaths/goroot/src/runtime/proc.go:250\nruntime.goexit\n\t/data/users/ciaranconcannon/gopaths/goroot/src/runtime/as
m_arm.s:824}\n{"message":"U-Boot environment is read only: flash chips swapped? Error code: exit status 1, stderr: Warning: Bad CRC, using default environment\\n## Error: \\"_flashy_test\\" not
defined\\n"}\n', stdout='', exit_signal=None)
FLASHY_ERROR_BAD_FLASH_CHIP: U-Boot environment is read only: flash chips swapped? Error code: exit status 1, stderr: Warning: Bad CRC, using default environment
## Error: "_flashy_test" not defined```

Test Plan:
Confirmed that flashy checks and remediations runs without issue with ephemeral built fbpkg openmbc.utils.flashy:414c5ac
```
In [2]: from openbmc.lib.openbmc_host import OpenBMCHost
In [3]: from openbmc.lib.helpers.flashy import Flashy
In [4]: host = OpenBMCHost("provisioninghold73583-oob.pci2")
In [5]: flashy = Flashy(host)
In [6]: await flashy.flashy_fetch("openbmc.image.grandteton:v2023.25.2")
In [7]: await flashy.flashy_install()
In [8]: await flashy.flashy_checks_and_remediations("flash1","grandteton","openbmc.image.grandteton:v2023.25.2",True)
In [9]:
```
 ---
Unit tests
```
$ go test .
ok      github.com/facebook/openbmc/tools/flashy/checks_and_remediations/common
```

Reviewed By: mchugh19

Differential Revision: D47945711

fbshipit-source-id: 3d3c05c77b3d6cf85b687784f1357fd1c54204f1
  • Loading branch information
cjcon90 authored and facebook-github-bot committed Aug 1, 2023
1 parent d5b7671 commit c7f86a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"log"
"math/rand"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -63,15 +64,22 @@ func ensureFlashWritable(stepParams step.StepParams) step.StepExitError {
// grandteton v2023.25.2 introduced an error whereby mtd0 was set as spi0.1
// this breaks checks and remediations as it thinks flash1 is read-only
// let's put in a workaround so we can upgrade all the affected hosts
cmd := []string{"grep", "mtd0:.*spi0.1 /proc/mtd"}
_, _, stdout, _ := utils.RunCommand(cmd, 30*time.Second)
if strings.Contains(stdout, "mtd0") {
buf, err := fileutils.ReadFile("/proc/mtd")
if err != nil {
return step.ExitBadFlashChip{Err: err}

}
mtdStr := string(buf)
mtdRegex := regexp.MustCompile(`mtd0:\s+\d+\s+\d+\s+"spi0\.1"`)
mtdMatch := mtdRegex.FindStringSubmatch(mtdStr)
if len(mtdMatch) > 0 {
log.Printf("Skipping ensure_flash_writable check for this device due to S356523")
return nil
return nil
}


// First up check that fw_printenv works okay and produces output.
cmd = []string{"fw_printenv", "bootargs"}
cmd := []string{"fw_printenv", "bootargs"}
_, err, stdout, stderr := utils.RunCommand(cmd, 30*time.Second)
if err != nil || !strings.Contains(stdout, "bootargs") {
log.Printf("fw_printenv doesn't work: %v, stderr: %v", err, stderr)
Expand Down
Expand Up @@ -36,11 +36,13 @@ func TestEnsureFlashWritable(t *testing.T) {
// save log output into buf for testing
var buf bytes.Buffer
log.SetOutput(&buf)
readFileOrig := fileutils.ReadFile
fileExistsOrig := fileutils.FileExists
runCommandOrig := utils.RunCommand

defer func() {
log.SetOutput(os.Stderr)
fileutils.ReadFile = readFileOrig
fileutils.FileExists = fileExistsOrig
utils.RunCommand = runCommandOrig
}()
Expand Down Expand Up @@ -78,7 +80,8 @@ func TestEnsureFlashWritable(t *testing.T) {
{
name: "s356523 case",
vbootUtilExists: true,
s356523: "mtd0: 08000000 00010000 \"spi0.1\"",
s356523: `mtd0: 08000000 00010000 "spi0.1"
mtd1: 00040000 00010000 "romx"`,
failPrint: false,
failSet: false,
failCheck: false,
Expand Down Expand Up @@ -136,6 +139,9 @@ func TestEnsureFlashWritable(t *testing.T) {
fileutils.FileExists = func(filename string) bool {
return tc.vbootUtilExists
}
fileutils.ReadFile = func(filename string) ([]byte, error) {
return []byte(tc.s356523), nil
}
utils.RunCommand = func(cmdArr []string, timeout time.Duration) (int, error, string, string) {
if (cmdArr[0] == "fw_printenv") {
if (cmdArr[1] == "bootargs") {
Expand All @@ -158,10 +164,6 @@ func TestEnsureFlashWritable(t *testing.T) {
} else {
return 0, nil, "bootargs=foo", ""
}
} else if (cmdArr[0] == "grep") {
if (cmdArr[1] == "mtd0:.*spi0.1 /proc/mtd") {
return 0, nil, tc.s356523, ""
}
} else{
if (tc.failSet) {
return 0, errors.Errorf("err2"), "", "err2"
Expand Down

0 comments on commit c7f86a5

Please sign in to comment.