Skip to content

Commit

Permalink
Restore fw_printenv command
Browse files Browse the repository at this point in the history
Summary:
D60115096 introduced a potential bug whereby `fw_printenv` check is expecintg stdout from the previous command, which is now replaced by an `ls` command

Restore the previous command and clearly differentiate between the two errors

Test Plan:
Unit tests
```
$ ./tools/flashy/scripts/run_unit_tests.sh
...
...
...
142/142 unit tests passed
```

Reviewed By: kawmarco

Differential Revision: D60234128

fbshipit-source-id: 50ebd779d47082ca8487bbf53bb68d5db292c883
  • Loading branch information
cjcon90 authored and facebook-github-bot committed Jul 25, 2024
1 parent fa05ac3 commit f5510f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ func ensureFlashAvailable(stepParams step.StepParams) step.StepExitError {
_, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second)
if err != nil {
errMsg := errors.Errorf(
"Broken flash chip? U-Boot environment is inaccessible." +
"Broken flash chip? Cannot see MTD chips on device." +
" Error code: %v, stderr: %v", err, stderr)
return step.ExitMissingMtd{Err: errMsg}
}

// Override mtdparts on next boot.
cmd = []string{"fw_printenv", "bootargs"}
_, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second)
if err != nil {
errMsg := errors.Errorf(
"Broken flash chip? U-Boot environment is inaccessible." +
" Error code: %v, stderr: %v", err, stderr)
return step.ExitBadFlashChip{Err: errMsg}
}
bootargs := strings.Replace(strings.TrimSpace(stdout), "bootargs=", "", 1)
log.Printf("Current bootargs: [%v]", bootargs)
if !strings.Contains(stdout, bootargsAppend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ func TestEnsureFlashAvailable(t *testing.T) {
cases := []struct {
name string
vbootUtilExists bool
lfOpenBMC bool
lfOpenBMC bool
failGrep bool
failLs bool
failPrint bool
failSet bool
lsOutput string
printOutput string
grepOutput string
want step.StepExitError
Expand All @@ -63,8 +65,10 @@ func TestEnsureFlashAvailable(t *testing.T) {
vbootUtilExists: true,
lfOpenBMC: false,
failGrep: false,
failLs: false,
failPrint: false,
failSet: false,
lsOutput: "/dev/mtd1",
printOutput: "derp",
grepOutput: "foo",
want: nil,
Expand All @@ -74,8 +78,10 @@ func TestEnsureFlashAvailable(t *testing.T) {
vbootUtilExists: false,
lfOpenBMC: true,
failGrep: false,
failLs: false,
failPrint: false,
failSet: false,
lsOutput: "/dev/mtd1",
printOutput: "derp",
grepOutput: "foo",
want: nil,
Expand All @@ -85,8 +91,10 @@ func TestEnsureFlashAvailable(t *testing.T) {
vbootUtilExists: false,
lfOpenBMC: false,
failGrep: false,
failLs: false,
failPrint: false,
failSet: false,
lsOutput: "/dev/mtd1",
printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw",
grepOutput: "mtd4: 02000000 00010000 \"flash0\"",
want: nil,
Expand All @@ -96,8 +104,10 @@ func TestEnsureFlashAvailable(t *testing.T) {
vbootUtilExists: false,
lfOpenBMC: false,
failGrep: true,
failLs: false,
failPrint: false,
failSet: false,
lsOutput: "/dev/mtd1",
printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw",
grepOutput: "",
want: step.ExitMustReboot{Err: errors.Errorf("Forcing reboot for new bootargs to take effect")},
Expand All @@ -107,19 +117,36 @@ func TestEnsureFlashAvailable(t *testing.T) {
vbootUtilExists: false,
lfOpenBMC: false,
failGrep: false,
failLs: true,
failPrint: false,
failSet: false,
lsOutput: "Cannot access MTD device /dev/mtd1: No such file or directory",
printOutput: "",
grepOutput: "",
want: step.ExitMissingMtd{Err: errors.Errorf("Broken flash chip? Cannot see MTD chips on device. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")},
},
{
name: "fw_printenv broken",
vbootUtilExists: false,
lfOpenBMC: false,
failGrep: false,
failLs: false,
failPrint: true,
failSet: false,
lsOutput: "/dev/mtd1",
printOutput: "Cannot access MTD device /dev/mtd1: No such file or directory",
grepOutput: "",
want: step.ExitMissingMtd{Err: errors.Errorf("Broken flash chip? U-Boot environment is inaccessible. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")},
want: step.ExitBadFlashChip{Err: errors.Errorf("Broken flash chip? U-Boot environment is inaccessible. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")},
},
{
name: "fw_setenv broken",
vbootUtilExists: false,
lfOpenBMC: false,
failGrep: false,
failLs: false,
failPrint: false,
failSet: true,
lsOutput: "/dev/mtd1",
printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw",
grepOutput: "",
want: nil,
Expand All @@ -139,6 +166,12 @@ func TestEnsureFlashAvailable(t *testing.T) {
return 0, nil, tc.grepOutput, ""
}
} else if (cmdArr[0] == "ls") {
if (tc.failLs) {
return 1, errors.Errorf("err1"), "", tc.lsOutput
} else {
return 0, nil, "", tc.lsOutput
}
} else if (cmdArr[0] == "fw_printenv") {
if (tc.failPrint) {
return 1, errors.Errorf("err1"), "", tc.printOutput
} else {
Expand Down

0 comments on commit f5510f3

Please sign in to comment.