@@ -90,7 +90,15 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
90
90
var uploadToolName string
91
91
var uploadToolPlatform * cores.PlatformRelease
92
92
var programmer * cores.Programmer
93
- if programmerID := req .GetProgrammer (); programmerID != "" {
93
+
94
+ burnBootloader := req .GetBurnBootloader ()
95
+ if burnBootloader {
96
+ uploadToolName = boardProperties .Get ("bootloader.tool" )
97
+ uploadToolPlatform = boardPlatform
98
+ if uploadToolName == "" {
99
+ return nil , fmt .Errorf ("cannot get programmer tool: undefined 'bootloader.tool' in boards.txt" )
100
+ }
101
+ } else if programmerID := req .GetProgrammer (); programmerID != "" {
94
102
programmer = boardPlatform .Programmers [programmerID ]
95
103
if programmer == nil {
96
104
// Try to find the programmer in the referenced build platform
@@ -153,13 +161,25 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
153
161
if v , ok := uploadProperties .GetOk ("program.params.verbose" ); ok {
154
162
uploadProperties .Set ("program.verbose" , v )
155
163
}
164
+ if v , ok := uploadProperties .GetOk ("erase.params.verbose" ); ok {
165
+ uploadProperties .Set ("erase.verbose" , v )
166
+ }
167
+ if v , ok := uploadProperties .GetOk ("bootloader.params.verbose" ); ok {
168
+ uploadProperties .Set ("bootloader.verbose" , v )
169
+ }
156
170
} else {
157
171
if v , ok := uploadProperties .GetOk ("upload.params.quiet" ); ok {
158
172
uploadProperties .Set ("upload.verbose" , v )
159
173
}
160
174
if v , ok := uploadProperties .GetOk ("program.params.quiet" ); ok {
161
175
uploadProperties .Set ("program.verbose" , v )
162
176
}
177
+ if v , ok := uploadProperties .GetOk ("erase.params.quiet" ); ok {
178
+ uploadProperties .Set ("erase.verbose" , v )
179
+ }
180
+ if v , ok := uploadProperties .GetOk ("bootloader.params.quiet" ); ok {
181
+ uploadProperties .Set ("bootloader.verbose" , v )
182
+ }
163
183
}
164
184
165
185
// Set properties for verify
@@ -172,29 +192,31 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
172
192
}
173
193
174
194
var importPath * paths.Path
175
- if importDir := req .GetImportDir (); importDir != "" {
176
- importPath = paths .New (importDir )
177
- } else {
178
- // TODO: Create a function to obtain importPath from sketch
179
- importPath = sketch .FullPath
180
- // Add FQBN (without configs part) to export path
181
- fqbnSuffix := strings .Replace (fqbn .StringWithoutConfig (), ":" , "." , - 1 )
182
- importPath = importPath .Join ("build" ).Join (fqbnSuffix )
183
- }
195
+ if ! burnBootloader {
196
+ if importDir := req .GetImportDir (); importDir != "" {
197
+ importPath = paths .New (importDir )
198
+ } else {
199
+ // TODO: Create a function to obtain importPath from sketch
200
+ importPath = sketch .FullPath
201
+ // Add FQBN (without configs part) to export path
202
+ fqbnSuffix := strings .Replace (fqbn .StringWithoutConfig (), ":" , "." , - 1 )
203
+ importPath = importPath .Join ("build" ).Join (fqbnSuffix )
204
+ }
184
205
185
- if ! importPath .Exist () {
186
- return nil , fmt .Errorf ("compiled sketch not found in %s" , importPath )
187
- }
188
- if ! importPath .IsDir () {
189
- return nil , fmt .Errorf ("expected compiled sketch in directory %s, but is a file instead" , importPath )
206
+ if ! importPath .Exist () {
207
+ return nil , fmt .Errorf ("compiled sketch not found in %s" , importPath )
208
+ }
209
+ if ! importPath .IsDir () {
210
+ return nil , fmt .Errorf ("expected compiled sketch in directory %s, but is a file instead" , importPath )
211
+ }
212
+ uploadProperties .SetPath ("build.path" , importPath )
213
+ uploadProperties .Set ("build.project_name" , sketch .Name + ".ino" )
190
214
}
191
- uploadProperties .SetPath ("build.path" , importPath )
192
- uploadProperties .Set ("build.project_name" , sketch .Name + ".ino" )
193
215
194
216
// If not using programmer perform some action required
195
217
// to set the board in bootloader mode
196
218
actualPort := port
197
- if programmer == nil {
219
+ if programmer == nil && ! burnBootloader {
198
220
// Perform reset via 1200bps touch if requested
199
221
if uploadProperties .GetBoolean ("upload.use_1200bps_touch" ) {
200
222
ports , err := serial .GetPortsList ()
@@ -250,8 +272,14 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
250
272
}
251
273
252
274
// Build recipe for upload
253
- var recipe string
254
- if programmer != nil {
275
+ if burnBootloader {
276
+ if err := runTool ("erase.pattern" , uploadProperties , outStream , errStream , req .GetVerbose ()); err != nil {
277
+ return nil , fmt .Errorf ("chip erase error: %s" , err )
278
+ }
279
+ if err := runTool ("bootloader.pattern" , uploadProperties , outStream , errStream , req .GetVerbose ()); err != nil {
280
+ return nil , fmt .Errorf ("burn bootloader error: %s" , err )
281
+ }
282
+ } else if programmer != nil {
255
283
if err := runTool ("program.pattern" , uploadProperties , outStream , errStream , req .GetVerbose ()); err != nil {
256
284
return nil , fmt .Errorf ("programming error: %s" , err )
257
285
}
0 commit comments