Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7776fa7

Browse files
Flasher: add support for flashing non-latest images
1 parent62cd2b9 commit7776fa7

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

‎updater/download_image.go‎

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ import (
77
"encoding/hex"
88
"fmt"
99
"io"
10-
"log/slog"
1110

1211
"github.com/arduino/go-paths-helper"
1312
"github.com/bcmi-labs/orchestrator/cmd/feedback"
13+
"github.com/bcmi-labs/orchestrator/cmd/i18n"
1414
"github.com/codeclysm/extract/v4"
1515
)
1616

17-
// TODO: add more fields to download other image versions
1817
typeManifeststruct {
19-
Lateststruct {
20-
Versionstring`json:"version"`
21-
Urlstring`json:"url"`
22-
Sha256string`json:"sha256"`
23-
}`json:"latest"`
18+
LatestRelease`json:"latest"`
19+
Releases []Release`json:"releases"`
20+
}
21+
22+
typeReleasestruct {
23+
Versionstring`json:"version"`
24+
Urlstring`json:"url"`
25+
Sha256string`json:"sha256"`
2426
}
2527

2628
// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
@@ -59,6 +61,11 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D
5961
returnnil,fmt.Errorf("error downloading the image: %v",err)
6062
}
6163

64+
// Download not confirmed
65+
iftmpZip==nil {
66+
returnnil,nil
67+
}
68+
6269
err=ExtractImage(tmpZip,tmpZip.Parent())
6370
iferr!=nil {
6471
returnnil,fmt.Errorf("error extracting the image: %v",err)
@@ -71,39 +78,43 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D
7178
funcDownloadImage(client*Client,targetVersionstring,upgradeConfirmCbDownloadConfirmCB,forceYesbool) (*paths.Path,string,error) {
7279
varerrerror
7380

74-
slog.Info("Checking for Debian image releases")
81+
feedback.Print(i18n.Tr("Checking for Debian image releases"))
7582
manifest,err:=client.GetInfoManifest()
7683
iferr!=nil {
7784
returnnil,"",err
7885
}
7986

80-
iftargetVersion=="latest" {
81-
targetVersion=manifest.Latest.Version
87+
varrel*Release
88+
iftargetVersion=="latest"||targetVersion==manifest.Latest.Version {
89+
rel=&manifest.Latest
90+
}else {
91+
for_,r:=rangemanifest.Releases {
92+
iftargetVersion==r.Version {
93+
rel=&r
94+
break
95+
}
96+
}
97+
}
98+
99+
ifrel==nil {
100+
returnnil,"",fmt.Errorf("could not find Debian image %s",targetVersion)
82101
}
83102

84103
if!forceYes {
85-
res,err:=upgradeConfirmCb(targetVersion)
104+
res,err:=upgradeConfirmCb(rel.Version)
86105
iferr!=nil {
87106
returnnil,"",err
88107
}
89108
if!res {
90-
slog.Info("Download not confirmed by user, exiting")
109+
feedback.Print(i18n.Tr("Download not confirmed by user, exiting"))
91110
returnnil,"",nil
92111
}
93112
}
94113

95-
// Download the Debian image
96-
vardownload io.ReadCloser
97-
varsizeint64
98-
iftargetVersion==manifest.Latest.Version {
99-
slog.Info("Downloading Debian image","version",manifest.Latest.Version)
100-
download,size,err=client.FetchZip(manifest.Latest.Url)
101-
iferr!=nil {
102-
returnnil,"",fmt.Errorf("could not fetch Debian image: %w",err)
103-
}
104-
}else {
105-
// TODO: check the json for the specific version and download it
106-
returnnil,"",nil
114+
feedback.Print(i18n.Tr("Downloading Debian image version %s",rel.Version))
115+
download,size,err:=client.FetchZip(rel.Url)
116+
iferr!=nil {
117+
returnnil,"",fmt.Errorf("could not fetch Debian image: %w",err)
107118
}
108119
deferdownload.Close()
109120

@@ -128,20 +139,20 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo
128139
}
129140

130141
// Check the hash
131-
ifsha256Byte,err:=hex.DecodeString(manifest.Latest.Sha256);err!=nil {
142+
ifsha256Byte,err:=hex.DecodeString(rel.Sha256);err!=nil {
132143
returnnil,"",fmt.Errorf("could not convert sha256 from hex to bytes: %w",err)
133144
}elseifs:=checksum.Sum(nil);!bytes.Equal(s,sha256Byte) {
134145
returnnil,"",fmt.Errorf("bad hash: %x (expected %x)",s,sha256Byte)
135146
}
136147

137-
slog.Info("Download of Debian image completed","path",temp)
148+
feedback.Print(i18n.Tr("Download of Debian image completed"))
138149

139-
returntmpZip,targetVersion,nil
150+
returntmpZip,rel.Version,nil
140151
}
141152

142153
funcExtractImage(archive,temp*paths.Path)error {
143154
// Unzip the Debian image
144-
slog.Info("Unzipping Debian image","tmpDir",temp)
155+
feedback.Print(i18n.Tr("Unzipping Debian image"))
145156
tmpZipFile,err:=archive.Open()
146157
iferr!=nil {
147158
returnfmt.Errorf("could not open archive: %w",err)

‎updater/flasher.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"context"
55
"fmt"
6-
"log/slog"
76
"net/url"
87
"runtime"
98
"strings"
@@ -12,6 +11,7 @@ import (
1211

1312
"github.com/arduino/go-paths-helper"
1413
"github.com/bcmi-labs/orchestrator/cmd/feedback"
14+
"github.com/bcmi-labs/orchestrator/cmd/i18n"
1515
)
1616

1717
//go:embed assets
@@ -45,6 +45,11 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
4545
returnfmt.Errorf("could not download and extract the image: %v",err)
4646
}
4747

48+
// Download not confirmed
49+
iftempImagePath==nil {
50+
returnnil
51+
}
52+
4853
defertempImagePath.Parent().RemoveAll()
4954

5055
imagePath=tempImagePath
@@ -113,7 +118,7 @@ func FlashBoard(ctx context.Context, downloadedImagePath string) error {
113118
returnerr
114119
}
115120
// TODO: add logic to preserve the user partition
116-
slog.Info("Flashing with qdl")
121+
feedback.Print(i18n.Tr("Flashing with qdl"))
117122
cmd,err:=paths.NewProcess(nil,qdlPath.String(),"--allow-missing","--storage","emmc","prog_firehose_ddr.elf","rawprogram0.xml","patch0.xml")
118123
iferr!=nil {
119124
returnerr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp