Skip to content

Commit 0dee889

Browse files
Count the number of partitions to determine if it is a R0 image
1 parent 5953691 commit 0dee889

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

updater/artifacts/read.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" ?>
22
<data>
3-
<read SECTOR_SIZE_IN_BYTES="512" filename="dump.bin" physical_partition_number="0" num_partition_sectors="34" start_sector="0"/>
3+
<read SECTOR_SIZE_IN_BYTES="512" filename="dump.bin" physical_partition_number="0" num_partition_sectors="19" start_sector="1"/>
44
</data>

updater/flasher.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/hex"
2121
"fmt"
2222
"runtime"
23+
"strconv"
2324
"strings"
2425

2526
"github.com/arduino/go-paths-helper"
@@ -245,7 +246,25 @@ func checkBoardGPTTable(ctx context.Context, qdlPath, flashDir *paths.Path) erro
245246
}
246247
strDump := hex.Dump(dump)
247248

248-
if strings.Contains(strDump, "00000250 4c 00 00 00") {
249+
strDumpSlice := strings.Split(strDump, "\n")
250+
// the max number of partitions is stored at entry 0x50
251+
maxPartitions, err := strconv.ParseInt(strings.Split(strDumpSlice[5], " ")[2], 16, 16)
252+
if err != nil {
253+
return err
254+
}
255+
256+
numPartitions := 0
257+
// starting from entry 0x200, there is a new partition every 0x80 bytes
258+
// TODO: check if the size of each partition is 80h or just assume it?
259+
for i := 32; numPartitions < int(maxPartitions); i += 8 {
260+
// partitions are made of non-zero bytes, if all 0s then there are no more entries
261+
if strings.Contains(strDumpSlice[i], "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00") {
262+
break
263+
}
264+
numPartitions++
265+
}
266+
267+
if numPartitions == 73 && maxPartitions == 76 {
249268
return fmt.Errorf("the current Debian image (R0) does not support user partition preservation")
250269
}
251270

0 commit comments

Comments
 (0)