Skip to content

Commit 0c876a0

Browse files
committed
initial flasher import
1 parent fa54e74 commit 0c876a0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

pkg/flasherapi/flasherapi.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package flasherapi
2+
3+
import (
4+
"context"
5+
6+
"github.com/arduino/arduino-app-cli/pkg/board/remote"
7+
)
8+
9+
// GetOSImageVersion returns the version of the OS image used in the board.
10+
// It is used by the AppLab to enforce image version compatibility.
11+
func GetOSImageVersion(conn remote.RemoteConn) string {
12+
// if no version is set, return a default value
13+
return "20251123-159"
14+
}
15+
16+
type OSImageRelease struct {
17+
VersionLabel string
18+
ID string
19+
Latest bool
20+
}
21+
22+
func ListAvailableOSImages() []OSImageRelease {
23+
return []OSImageRelease{
24+
{
25+
ID: "20251123-159",
26+
VersionLabel: "r159 (2025-11-23)",
27+
Latest: true,
28+
},
29+
}
30+
}
31+
32+
func IsUserPartitionPreservationSupported(conn remote.RemoteConn, targetImageVersion OSImageRelease) bool {
33+
// targetImageVersion is the version of the image to be flashed
34+
// some older versions do not support user partition preservation
35+
// so this has to be considered here
36+
return true
37+
}
38+
39+
type FlashStep string
40+
41+
const (
42+
FlashStepPrecheck FlashStep = "precheck"
43+
FlashStepDetection FlashStep = "detection"
44+
FlashStepDownloading FlashStep = "downloading"
45+
FlashStepExtracting FlashStep = "extracting"
46+
FlashStepFlashing FlashStep = "flashing"
47+
)
48+
49+
type FlashEvent struct {
50+
Step FlashStep
51+
OverallProgress int // percentage 0-100
52+
Message string // log message to show on the UI
53+
}
54+
55+
func Flash(
56+
ctx context.Context, // context to cancel to interrupt the flashing process
57+
// conn remote.RemoteConn, // is this required for the flash process?
58+
imageVersion OSImageRelease, // OS image version to flash
59+
preserveUserPartition bool, // whether to preserve the user partition or not
60+
eventCB func(event FlashEvent), // Callback, sends progress events to the caller
61+
) error {
62+
// The disk space check is done before starting the flashing process.
63+
return InsufficientDiskSpaceError{
64+
RequiredSpaceMB: 2048,
65+
AvailableSpaceMB: 1024,
66+
}
67+
}
68+
69+
// Errors returned by the Flash function above.
70+
// Assertions can be done on the caller side to show better error messages.
71+
72+
type QDLFlashError struct {
73+
Details string
74+
Cause error
75+
}
76+
77+
type DownloadError struct {
78+
Details string
79+
}
80+
81+
type InsufficientDiskSpaceError struct {
82+
RequiredSpaceMB int64
83+
AvailableSpaceMB int64
84+
}
85+
86+
func (e InsufficientDiskSpaceError) Error() string {
87+
return "insufficient disk space"
88+
}

0 commit comments

Comments
 (0)