@@ -90,7 +90,15 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
9090 var uploadToolName string
9191 var uploadToolPlatform * cores.PlatformRelease
9292 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 != "" {
94102 programmer = boardPlatform .Programmers [programmerID ]
95103 if programmer == nil {
96104 // 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
153161 if v , ok := uploadProperties .GetOk ("program.params.verbose" ); ok {
154162 uploadProperties .Set ("program.verbose" , v )
155163 }
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+ }
156170 } else {
157171 if v , ok := uploadProperties .GetOk ("upload.params.quiet" ); ok {
158172 uploadProperties .Set ("upload.verbose" , v )
159173 }
160174 if v , ok := uploadProperties .GetOk ("program.params.quiet" ); ok {
161175 uploadProperties .Set ("program.verbose" , v )
162176 }
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+ }
163183 }
164184
165185 // Set properties for verify
@@ -172,29 +192,31 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
172192 }
173193
174194 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+ }
184205
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" )
190214 }
191- uploadProperties .SetPath ("build.path" , importPath )
192- uploadProperties .Set ("build.project_name" , sketch .Name + ".ino" )
193215
194216 // If not using programmer perform some action required
195217 // to set the board in bootloader mode
196218 actualPort := port
197- if programmer == nil {
219+ if programmer == nil && ! burnBootloader {
198220 // Perform reset via 1200bps touch if requested
199221 if uploadProperties .GetBoolean ("upload.use_1200bps_touch" ) {
200222 ports , err := serial .GetPortsList ()
@@ -250,8 +272,14 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
250272 }
251273
252274 // 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 {
255283 if err := runTool ("program.pattern" , uploadProperties , outStream , errStream , req .GetVerbose ()); err != nil {
256284 return nil , fmt .Errorf ("programming error: %s" , err )
257285 }
0 commit comments