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 {
279279 /// Label of target app partition
280280 #[ arg( long, value_name = "LABEL" ) ]
281281 pub target_app_partition : Option < String > ,
282+ /// Whether to apply padding for secure boot v2
283+ #[ arg( long) ]
284+ pub secure_pad_v2 : bool ,
282285}
283286
284287/// Arguments for connection and monitoring
@@ -1100,6 +1103,7 @@ pub fn make_flash_data(
11001103 config : & Config ,
11011104 chip : Chip ,
11021105 xtal_freq : XtalFrequency ,
1106+ secure_pad_v2 : bool ,
11031107) -> FlashData {
11041108 // Create flash settings with precedence
11051109 let mode = flash_config_args
@@ -1121,6 +1125,7 @@ pub fn make_flash_data(
11211125 image_args. mmu_page_size ,
11221126 chip,
11231127 xtal_freq,
1128+ secure_pad_v2,
11241129 )
11251130}
11261131
Original file line number Diff line number Diff line change @@ -488,6 +488,8 @@ pub struct FlashData {
488488 pub chip : Chip ,
489489 /// Crystal frequency.
490490 pub xtal_freq : XtalFrequency ,
491+ /// Whether to add secure boot V2 padding.
492+ pub secure_pad_v2 : bool ,
491493}
492494
493495impl FlashData {
@@ -498,13 +500,15 @@ impl FlashData {
498500 mmu_page_size : Option < u32 > ,
499501 chip : Chip ,
500502 xtal_freq : XtalFrequency ,
503+ secure_pad_v2 : bool ,
501504 ) -> Self {
502505 FlashData {
503506 flash_settings,
504507 min_chip_rev,
505508 mmu_page_size,
506509 chip,
507510 xtal_freq,
511+ secure_pad_v2,
508512 }
509513 }
510514}
Original file line number Diff line number Diff line change @@ -514,6 +514,18 @@ impl<'a> IdfBootloaderFormat<'a> {
514514 segment_count += 1 ;
515515 }
516516
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+
517529 let padding = 15 - ( data. len ( ) % 16 ) ;
518530 let padding = & [ 0u8 ; 16 ] [ 0 ..padding] ;
519531 data. write_all ( padding) ?;
You can’t perform that action at this time.
0 commit comments