@@ -272,6 +272,7 @@ impl FlashSettings {
272
272
freq : None ,
273
273
}
274
274
}
275
+
275
276
pub fn new (
276
277
mode : Option < FlashMode > ,
277
278
size : Option < FlashSize > ,
@@ -281,6 +282,93 @@ impl FlashSettings {
281
282
}
282
283
}
283
284
285
+ /// Builder interface to create [`FlashData`] objects.
286
+ pub struct FlashDataBuilder < ' a > {
287
+ bootloader_path : Option < & ' a Path > ,
288
+ partition_table_path : Option < & ' a Path > ,
289
+ partition_table_offset : Option < u32 > ,
290
+ image_format : Option < ImageFormatKind > ,
291
+ target_app_partition : Option < String > ,
292
+ flash_settings : FlashSettings ,
293
+ min_chip_rev : u16 ,
294
+ }
295
+
296
+ impl < ' a > Default for FlashDataBuilder < ' a > {
297
+ fn default ( ) -> Self {
298
+ Self {
299
+ bootloader_path : Default :: default ( ) ,
300
+ partition_table_path : Default :: default ( ) ,
301
+ partition_table_offset : Default :: default ( ) ,
302
+ image_format : Default :: default ( ) ,
303
+ target_app_partition : Default :: default ( ) ,
304
+ flash_settings : FlashSettings :: default ( ) ,
305
+ min_chip_rev : Default :: default ( ) ,
306
+ }
307
+ }
308
+ }
309
+
310
+ impl < ' a > FlashDataBuilder < ' a > {
311
+ /// Creates a new [`FlashDataBuilder`] object.
312
+ pub fn new ( ) -> Self {
313
+ Self :: default ( )
314
+ }
315
+
316
+ /// Sets the bootloader path.
317
+ pub fn with_bootloader ( mut self , bootloader_path : & ' a Path ) -> Self {
318
+ self . bootloader_path = Some ( bootloader_path) ;
319
+ self
320
+ }
321
+
322
+ /// Sets the partition table path.
323
+ pub fn with_partition_table ( mut self , partition_table_path : & ' a Path ) -> Self {
324
+ self . partition_table_path = Some ( partition_table_path) ;
325
+ self
326
+ }
327
+
328
+ /// Sets the partition table offset.
329
+ pub fn with_partition_table_offset ( mut self , partition_table_offset : u32 ) -> Self {
330
+ self . partition_table_offset = Some ( partition_table_offset) ;
331
+ self
332
+ }
333
+
334
+ /// Sets the image format.
335
+ pub fn with_image_format ( mut self , image_format : ImageFormatKind ) -> Self {
336
+ self . image_format = Some ( image_format) ;
337
+ self
338
+ }
339
+
340
+ /// Sets the label of the target app partition.
341
+ pub fn with_target_app_partition ( mut self , target_app_partition : String ) -> Self {
342
+ self . target_app_partition = Some ( target_app_partition) ;
343
+ self
344
+ }
345
+
346
+ /// Sets the flash settings.
347
+ pub fn with_flash_settings ( mut self , flash_settings : FlashSettings ) -> Self {
348
+ self . flash_settings = flash_settings;
349
+ self
350
+ }
351
+
352
+ /// Sets the minimum chip revision.
353
+ pub fn with_min_chip_rev ( mut self , min_chip_rev : u16 ) -> Self {
354
+ self . min_chip_rev = min_chip_rev;
355
+ self
356
+ }
357
+
358
+ /// Builds a [`FlashData`] object.
359
+ pub fn build ( self ) -> Result < FlashData > {
360
+ FlashData :: new (
361
+ self . bootloader_path ,
362
+ self . partition_table_path ,
363
+ self . partition_table_offset ,
364
+ self . image_format ,
365
+ self . target_app_partition ,
366
+ self . flash_settings ,
367
+ self . min_chip_rev ,
368
+ )
369
+ }
370
+ }
371
+
284
372
/// Flash data and configuration
285
373
#[ derive( Debug , Clone ) ]
286
374
#[ non_exhaustive]
@@ -308,7 +396,7 @@ impl FlashData {
308
396
// specified path.
309
397
let bootloader = if let Some ( path) = bootloader {
310
398
let path = fs:: canonicalize ( path) . into_diagnostic ( ) ?;
311
- let data = fs:: read ( path) . into_diagnostic ( ) ?;
399
+ let data: Vec < u8 > = fs:: read ( path) . into_diagnostic ( ) ?;
312
400
313
401
Some ( data)
314
402
} else {
0 commit comments