Skip to content

Commit

Permalink
detect missing/broken flash chips on non-vboot
Browse files Browse the repository at this point in the history
Summary:
If the U-Boot environment (env MTD partition) is inaccessible and flash0 is
missing too, it's a good indication that something serious is amiss with the
SPI chips.  Return a  broken flash chip error code in this case, instead of
an unsafe to reboot error.

(For example an A-SPEED/Linux driver bug may hide the env partition on the
primary chip invisible if the secondary chip is inaccessible.)

Test Plan:
Build & unit test:

```
0 ~/local/openbmc/tools/flashy $ ./build.sh && ./build_dev.sh && go test ./...
ok      github.com/facebook/openbmc/tools/flashy        (cached)
ok      github.com/facebook/openbmc/tools/flashy/checks_and_remediations/common (cached)
ok      github.com/facebook/openbmc/tools/flashy/checks_and_remediations/galaxy100      (cached)
ok      github.com/facebook/openbmc/tools/flashy/checks_and_remediations/wedge100       (cached)
ok      github.com/facebook/openbmc/tools/flashy/checks_and_remediations/yamp   (cached)
?       github.com/facebook/openbmc/tools/flashy/flash_procedure        [no test files]
ok      github.com/facebook/openbmc/tools/flashy/install        (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/fileutils  (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/flash      (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/flash/flashcp      (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils   (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils/devices   (cached)
?       github.com/facebook/openbmc/tools/flashy/lib/logger     [no test files]
ok      github.com/facebook/openbmc/tools/flashy/lib/step       (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/utils      (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/validate   (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/validate/image     (cached)
ok      github.com/facebook/openbmc/tools/flashy/lib/validate/partition (cached)
?       github.com/facebook/openbmc/tools/flashy/tests  [no test files]
?       github.com/facebook/openbmc/tools/flashy/utilities      [no test files]
0 ~/local/openbmc/tools/flashy $ echo $?
0
```

Reviewed By: kawmarco

fbshipit-source-id: 355a7d01ce55f4994ca76693b360592206651b6a
  • Loading branch information
doranand authored and facebook-github-bot committed Jul 6, 2022
1 parent 5ca3791 commit 95a150a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func ensureFlashAvailable(stepParams step.StepParams) step.StepExitError {
cmd = []string{"fw_printenv", "bootargs"}
_, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second)
if err != nil {
if strings.Contains(stderr, "Cannot access MTD device") {
errMsg := errors.Errorf(
"U-Boot environment is inaccessible: broken flash chip?" +
" Error code: %v, stderr: %v", err, stderr)
return step.ExitBadFlashChip{Err: errMsg}
}
log.Printf("fw_printenv doesn't work: %v, stderr: %v", err, stderr)
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,25 @@ func TestEnsureFlashAvailable(t *testing.T) {
want: step.ExitMustReboot{Err: errors.Errorf("Forcing reboot for new bootargs to take effect")},
},
{
name: "fw_printenv broken",
name: "fw_printenv broken because reasons",
vbootUtilExists: false,
failGrep: false,
failPrint: true,
failSet: false,
printOutput: "lol",
grepOutput: "mtd4: 02000000 00010000 \"flash0\"",
printOutput: "",
grepOutput: "",
want: nil,
},
{
name: "fw_printenv broken because missing flash",
vbootUtilExists: false,
failGrep: false,
failPrint: true,
failSet: false,
printOutput: "Cannot access MTD device /dev/mtd1: No such file or directory",
grepOutput: "",
want: step.ExitBadFlashChip{Err: errors.Errorf("U-Boot environment is inaccessible: broken flash chip? Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")},
},
{
name: "fw_setenv broken",
vbootUtilExists: false,
Expand All @@ -121,9 +131,9 @@ func TestEnsureFlashAvailable(t *testing.T) {
}
} else if (cmdArr[0] == "fw_printenv") {
if (tc.failPrint) {
return 0, errors.Errorf("err1"), "", "err1"
return 1, errors.Errorf("err1"), "", tc.printOutput
} else {
return 0, nil, tc.printOutput, ""
return 0, nil, "", tc.printOutput
}
} else if (cmdArr[0] == "fw_setenv") {
if (tc.failSet) {
Expand Down

0 comments on commit 95a150a

Please sign in to comment.