@@ -17,15 +17,45 @@ package flasherapi
1717
1818import (
1919 "context"
20+ "log/slog"
21+ "strings"
2022
2123 "github.com/arduino/arduino-app-cli/pkg/board/remote"
2224)
2325
2426// GetOSImageVersion returns the version of the OS image used in the board.
2527// It is used by the AppLab to enforce image version compatibility.
26- func GetOSImageVersion (ctx context.Context , conn remote.RemoteConn ) string {
27- // if no version is set, return a default value
28- return "20251123-159"
28+ func GetOSImageVersion (ctx context.Context , conn remote.RemoteConn ) (string , error ) {
29+ const defaultVersion = "20250807-136"
30+
31+ output , err := conn .GetCmd ("cat /etc/buildinfo" ).Output (ctx )
32+ if err != nil {
33+ return defaultVersion , err
34+ }
35+
36+ if version , ok := ParseOSImageVersion (string (output )); ok {
37+ slog .Info ("find OS Image version" , "version" , version )
38+ return version , nil
39+ }
40+ slog .Info ("Unable to find OS Image version" , "using default version" , defaultVersion )
41+ return defaultVersion , nil
42+ }
43+
44+ func ParseOSImageVersion (buildInfo string ) (string , bool ) {
45+ for _ , line := range strings .Split (buildInfo , "\n " ) {
46+ line = strings .TrimSpace (line )
47+
48+ key , value , ok := strings .Cut (line , "=" )
49+ if ! ok || key != "BUILD_ID" {
50+ continue
51+ }
52+
53+ version := strings .Trim (value , "\" ' " )
54+ if version != "" {
55+ return version , true
56+ }
57+ }
58+ return "" , false
2959}
3060
3161type OSImageRelease struct {
@@ -50,9 +80,12 @@ const R0_IMAGE_VERSION_ID = "20250807-136"
5080// according to the current and target OS image versions.
5181//
5282// Preservation is supported if both versions are not the R0 image.
53- func IsUserPartitionPreservationSupported (ctx context.Context , conn remote.RemoteConn , targetImageVersion OSImageRelease ) bool {
54- currentImageVersion := GetOSImageVersion (ctx , conn )
55- return ! (targetImageVersion .ID == R0_IMAGE_VERSION_ID || currentImageVersion == R0_IMAGE_VERSION_ID )
83+ func IsUserPartitionPreservationSupported (ctx context.Context , conn remote.RemoteConn , targetImageVersion OSImageRelease ) (bool , error ) {
84+ currentImageVersion , err := GetOSImageVersion (ctx , conn )
85+ if err != nil {
86+ return false , err
87+ }
88+ return ! (targetImageVersion .ID == R0_IMAGE_VERSION_ID || currentImageVersion == R0_IMAGE_VERSION_ID ), err
5689}
5790
5891type FlashStep string
0 commit comments