Skip to content

Commit 5074d45

Browse files
doranandfacebook-github-bot
authored andcommitted
sleep briefly while flashing
Summary: Go idle periodically when flashing the image, to allow other work on the system to happen, for example SPI I/O. For a 32MB flash image, this would result in an extra 8s of idle time during wipe plus 8s during flashing. For S434121. Test Plan: ``` 0 ~/local/openbmc/tools/flashy $ ./build.sh && ./build_dev.sh && go test ./... ? github.com/facebook/openbmc/tools/flashy/flash_procedure [no test files] ? github.com/facebook/openbmc/tools/flashy/lib/logger [no test files] ? github.com/facebook/openbmc/tools/flashy/tests [no test files] ? github.com/facebook/openbmc/tools/flashy/utilities [no test files] ok github.com/facebook/openbmc/tools/flashy 2.024s ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/bletchley (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/grandteton (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) ok github.com/facebook/openbmc/tools/flashy/install 0.007s ok github.com/facebook/openbmc/tools/flashy/lib/fileutils (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash 0.007s ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashcp 0.508s ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils/devices (cached) 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) 0 ~/local/openbmc/tools/flashy $ ``` Build ephemeral fbpkg and flash a wedge100 using it: ``` Host Workflow ID Progress Status Result ---------------------------------- ------------------------------------ ---------- ----------------------- ---------------------- fboss8382003-oob.snc1.facebook.com b4600065-e674-4696-9378-5c313ae45819 finished WorkflowStatus.FINISHED FinishStatus.SUCCEEDED ``` -> https://fburl.com/scuba/openbmc_upgrades/yksvon8b Reviewed By: kawmarco Differential Revision: D59927810 fbshipit-source-id: 7db5bb534575d360816a2ec27bea361936fe16dd
1 parent 1486cae commit 5074d45

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tools/flashy/lib/flash/flashcp/flashcp.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"os"
4242
"regexp"
4343
"syscall"
44+
"time"
4445
"unsafe"
4546

4647
"github.com/facebook/openbmc/tools/flashy/lib/fileutils"
@@ -83,6 +84,7 @@ type mtd_info_user struct {
8384

8485
const sizeof_mtd_info_user = 32
8586
const sizeof_erase_user_info = 8
87+
const chunkSize = uint32(1048576)
8688

8789
// linux/include/uapi/mtd/mtd-abi.h
8890
var MEMGETINFO = ioctl.IOR('M', 1, sizeof_mtd_info_user)
@@ -254,6 +256,8 @@ var eraseFlashDevice = func(
254256
imFile imageFile,
255257
roOffset uint32,
256258
) error {
259+
sleepTodo := int32(chunkSize)
260+
257261
log.Printf("Erasing flash device '%v'...", deviceFile.Name())
258262

259263
if m.erasesize == 0 {
@@ -293,6 +297,18 @@ var eraseFlashDevice = func(
293297
log.Print(errMsg)
294298
return errors.Errorf("%v", errMsg)
295299
}
300+
301+
// For every chunkSize bytes of work done, sleep for 1/4s to
302+
// allow for other work on the system (especially I/O to the
303+
// SPI) to complete.
304+
//
305+
// In practice erasesize will be smaller than chunkSize but
306+
// in any case this will still trigger every so often.
307+
sleepTodo = sleepTodo - int32(m.erasesize);
308+
if sleepTodo <= 0 {
309+
sleepTodo = int32(chunkSize);
310+
utils.Sleep(time.Millisecond * 250);
311+
}
296312
}
297313

298314
log.Printf("Finished erasing flash device '%v'", deviceFile.Name())
@@ -306,7 +322,6 @@ var flashImage = func(
306322
imFile imageFile,
307323
roOffset uint32,
308324
) error {
309-
const chunkSize = uint32(1048576)
310325
fileSize := uint32(len(imFile.data))
311326

312327
log.Printf("Flashing image '%v' on to flash device '%v'", imFile.name, deviceFile.Name())
@@ -336,6 +351,11 @@ var flashImage = func(
336351
imFile.name, deviceFile.Name(), n, err,
337352
)
338353
}
354+
355+
// For every chunkSize bytes of work done, sleep for 1/4s to
356+
// allow for other work on the system (especially I/O to the
357+
// SPI) to complete.
358+
utils.Sleep(time.Millisecond * 250);
339359
}
340360

341361
log.Printf("Finished flashing image '%v' on to flash device '%v'",

tools/flashy/lib/flash/flashcp/flashcp_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"bytes"
2424
"math"
2525
"testing"
26+
"time"
2627
"unsafe"
2728

2829
"github.com/facebook/openbmc/tools/flashy/lib/fileutils"
@@ -59,6 +60,7 @@ func TestFlashCp(t *testing.T) {
5960
runFlashProcessOrig := runFlashProcess
6061
closeFileOrig := closeFlashDeviceFile
6162
PetWatchdogOrig := utils.PetWatchdog
63+
sleepOrig := utils.Sleep
6264
defer func() {
6365
openFlashDeviceFile = openFileOrig
6466
getMtdInfoUser = getMtdInfoUserOrig
@@ -67,6 +69,7 @@ func TestFlashCp(t *testing.T) {
6769
runFlashProcess = runFlashProcessOrig
6870
closeFlashDeviceFile = closeFileOrig
6971
utils.PetWatchdog = PetWatchdogOrig
72+
utils.Sleep = sleepOrig
7073
}()
7174

7275
cases := []struct {
@@ -168,6 +171,7 @@ func TestFlashCp(t *testing.T) {
168171
}
169172
utils.PetWatchdog = func() {
170173
}
174+
utils.Sleep = func(t time.Duration) {}
171175

172176
for _, tc := range cases {
173177
t.Run(tc.name, func(t *testing.T) {
@@ -227,6 +231,7 @@ func TestRunFlashProcess(t *testing.T) {
227231
flashImageOrig := flashImage
228232
verifyFlashOrig := verifyFlash
229233
PetWatchdogOrig := utils.PetWatchdog
234+
sleepOrig := utils.Sleep
230235
defer func() {
231236
openFlashDeviceFile = openFlashDeviceFileOrig
232237
closeFlashDeviceFile = closeFlashDeviceFileOrig
@@ -235,6 +240,7 @@ func TestRunFlashProcess(t *testing.T) {
235240
flashImage = flashImageOrig
236241
verifyFlash = verifyFlashOrig
237242
utils.PetWatchdog = PetWatchdogOrig
243+
utils.Sleep = sleepOrig
238244
}()
239245

240246
cases := []struct {
@@ -298,6 +304,7 @@ func TestRunFlashProcess(t *testing.T) {
298304
}
299305
utils.PetWatchdog = func() {
300306
}
307+
utils.Sleep = func(t time.Duration) {}
301308

302309
for _, tc := range cases {
303310
t.Run(tc.name, func(t *testing.T) {
@@ -441,8 +448,10 @@ func TestHealthCheck(t *testing.T) {
441448

442449
func TestEraseFlashDevice(t *testing.T) {
443450
IOCTLOrig := IOCTL
451+
sleepOrig := utils.Sleep
444452
defer func() {
445453
IOCTL = IOCTLOrig
454+
utils.Sleep = sleepOrig
446455
}()
447456

448457
imData := []byte("foobar")
@@ -529,6 +538,7 @@ func TestEraseFlashDevice(t *testing.T) {
529538
fileutils.Munmap = func(data []byte) error {
530539
return nil
531540
}
541+
utils.Sleep = func(t time.Duration) {}
532542

533543
for _, tc := range cases {
534544
t.Run(tc.name, func(t *testing.T) {
@@ -566,8 +576,10 @@ func TestEraseFlashDevice(t *testing.T) {
566576

567577
func TestFlashImage(t *testing.T) {
568578
pwriteOrig := fileutils.Pwrite
579+
sleepOrig := utils.Sleep
569580
defer func() {
570581
fileutils.Pwrite = pwriteOrig
582+
utils.Sleep = sleepOrig
571583
}()
572584

573585
imData := []byte("foobar")
@@ -610,6 +622,9 @@ func TestFlashImage(t *testing.T) {
610622
want: errors.Errorf("roOffset (100) >= file size (6)"),
611623
},
612624
}
625+
626+
utils.Sleep = func(t time.Duration) {}
627+
613628
for _, tc := range cases {
614629
t.Run(tc.name, func(t *testing.T) {
615630
fileutils.Pwrite = func(fd int, p []byte, roOffset int64) (n int, err error) {
@@ -642,13 +657,16 @@ func TestFlashImage(t *testing.T) {
642657
func TestVerifyFlash(t *testing.T) {
643658
mmapFileRangeOrig := fileutils.MmapFileRange
644659
munmapOrig := fileutils.Munmap
660+
sleepOrig := utils.Sleep
645661
defer func() {
646662
fileutils.MmapFileRange = mmapFileRangeOrig
647663
fileutils.Munmap = munmapOrig
664+
utils.Sleep = sleepOrig
648665
}()
649666
fileutils.Munmap = func(b []byte) error {
650667
return nil
651668
}
669+
utils.Sleep = func(t time.Duration) {}
652670

653671
imData := []byte("foobar")
654672
imFile := imageFile{

0 commit comments

Comments
 (0)