File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,9 @@ pub struct IdfFormatArgs {
279
279
/// Label of target app partition
280
280
#[ arg( long, value_name = "LABEL" ) ]
281
281
pub target_app_partition : Option < String > ,
282
+ /// Whether to apply padding for secure boot v2
283
+ #[ arg( long) ]
284
+ pub secure_pad_v2 : bool ,
282
285
}
283
286
284
287
/// Arguments for connection and monitoring
@@ -1100,6 +1103,7 @@ pub fn make_flash_data(
1100
1103
config : & Config ,
1101
1104
chip : Chip ,
1102
1105
xtal_freq : XtalFrequency ,
1106
+ secure_pad_v2 : bool ,
1103
1107
) -> FlashData {
1104
1108
// Create flash settings with precedence
1105
1109
let mode = flash_config_args
@@ -1121,6 +1125,7 @@ pub fn make_flash_data(
1121
1125
image_args. mmu_page_size ,
1122
1126
chip,
1123
1127
xtal_freq,
1128
+ secure_pad_v2,
1124
1129
)
1125
1130
}
1126
1131
Original file line number Diff line number Diff line change @@ -488,6 +488,8 @@ pub struct FlashData {
488
488
pub chip : Chip ,
489
489
/// Crystal frequency.
490
490
pub xtal_freq : XtalFrequency ,
491
+ /// Whether to add secure boot V2 padding.
492
+ pub secure_pad_v2 : bool ,
491
493
}
492
494
493
495
impl FlashData {
@@ -498,13 +500,15 @@ impl FlashData {
498
500
mmu_page_size : Option < u32 > ,
499
501
chip : Chip ,
500
502
xtal_freq : XtalFrequency ,
503
+ secure_pad_v2 : bool ,
501
504
) -> Self {
502
505
FlashData {
503
506
flash_settings,
504
507
min_chip_rev,
505
508
mmu_page_size,
506
509
chip,
507
510
xtal_freq,
511
+ secure_pad_v2,
508
512
}
509
513
}
510
514
}
Original file line number Diff line number Diff line change @@ -514,6 +514,18 @@ impl<'a> IdfBootloaderFormat<'a> {
514
514
segment_count += 1 ;
515
515
}
516
516
517
+ if flash_data. secure_pad_v2 {
518
+ let current_size = data. len ( ) ;
519
+ let padding_size = ( 65536 - ( ( current_size + 56 ) % 65536 ) ) % 65536 ;
520
+ let padding_bytes = vec ! [ 0 ; padding_size] ;
521
+ let segment = Segment {
522
+ addr : 0 ,
523
+ data : Cow :: Owned ( padding_bytes) ,
524
+ } ;
525
+ checksum = save_segment ( & mut data, & segment, checksum) ?;
526
+ segment_count += 1 ;
527
+ }
528
+
517
529
let padding = 15 - ( data. len ( ) % 16 ) ;
518
530
let padding = & [ 0u8 ; 16 ] [ 0 ..padding] ;
519
531
data. write_all ( padding) ?;
You can’t perform that action at this time.
0 commit comments