machine: remove bytes package dependency in flash code

This also moves flash padding code to a single place, since it was
copied 5 times.

This change is necessary in Go 1.24 to avoid an import cycle.
This commit is contained in:
Ayke van Laethem
2025-02-16 15:11:39 +01:00
committed by Ron Evans
parent ea53ace270
commit 52b9fcd57f
7 changed files with 17 additions and 65 deletions
+11
View File
@@ -64,3 +64,14 @@ type BlockDevice interface {
// EraseBlockSize to map addresses to blocks.
EraseBlocks(start, len int64) error
}
// pad data if needed so it is long enough for correct byte alignment on writes.
func flashPad(p []byte, writeBlockSize int) []byte {
overflow := len(p) % writeBlockSize
if overflow != 0 {
for i := 0; i < writeBlockSize-overflow; i++ {
p = append(p, 0xff)
}
}
return p
}