@@ -335,6 +335,28 @@ impl ImagesBuilder {
335335 }
336336 }
337337
338+ pub fn make_oversized_bootstrap_image ( self ) -> Images {
339+ let mut flash = self . flash ;
340+ let ram = self . ram . clone ( ) ; // TODO: Avoid this clone.
341+ let images = self . slots . into_iter ( ) . enumerate ( ) . map ( |( image_num, slots) | {
342+ let dep = BoringDep :: new ( image_num, & NO_DEPS ) ;
343+ let primaries = install_no_image ( ) ;
344+ let upgrades = install_image ( & mut flash, & slots[ 1 ] ,
345+ ImageSize :: Oversized , & ram, & dep, false ) ;
346+ OneImage {
347+ slots,
348+ primaries,
349+ upgrades,
350+ } } ) . collect ( ) ;
351+ Images {
352+ flash,
353+ areadesc : self . areadesc ,
354+ images,
355+ total_count : None ,
356+ ram : self . ram ,
357+ }
358+ }
359+
338360 /// Build the Flash and area descriptor for a given device.
339361 pub fn make_device ( device : DeviceName , align : usize , erased_val : u8 ) -> ( SimMultiFlash , AreaDesc , & ' static [ Caps ] ) {
340362 match device {
@@ -512,6 +534,39 @@ impl Images {
512534 fails > 0
513535 }
514536
537+ pub fn run_oversized_bootstrap ( & self ) -> bool {
538+ let mut flash = self . flash . clone ( ) ;
539+ let mut fails = 0 ;
540+
541+ if Caps :: Bootstrap . present ( ) {
542+ info ! ( "Try bootstraping image in the primary" ) ;
543+
544+ let boot_result = c:: boot_go ( & mut flash, & self . areadesc , None , None , false ) . interrupted ( ) ;
545+
546+ if boot_result {
547+ warn ! ( "Failed first boot" ) ;
548+ fails += 1 ;
549+ }
550+
551+ if self . verify_images ( & flash, 0 , 1 ) {
552+ warn ! ( "Image in the first slot was not bootstrapped" ) ;
553+ fails += 1 ;
554+ }
555+
556+ if self . verify_trailers ( & flash, 0 , BOOT_MAGIC_GOOD ,
557+ BOOT_FLAG_SET , BOOT_FLAG_SET ) {
558+ warn ! ( "Mismatched trailer for the primary slot" ) ;
559+ fails += 1 ;
560+ }
561+ }
562+
563+ if fails > 0 {
564+ error ! ( "Expected trailer on secondary slot to be erased" ) ;
565+ }
566+
567+ fails > 0
568+ }
569+
515570
516571 /// Test a simple upgrade, with dependencies given, and verify that the
517572 /// image does as is described in the test.
@@ -1485,11 +1540,12 @@ enum ImageSize {
14851540 Given ( usize ) ,
14861541 /// Make the image as large as it can be for the partition/device.
14871542 Largest ,
1543+ /// Make the image quite larger than it can be for the partition/device/
1544+ Oversized ,
14881545}
14891546
14901547#[ cfg( not( feature = "max-align-32" ) ) ]
14911548fn tralier_estimation ( dev : & dyn Flash ) -> usize {
1492-
14931549 c:: boot_trailer_sz ( dev. align ( ) as u32 ) as usize
14941550}
14951551
@@ -1501,6 +1557,25 @@ fn tralier_estimation(dev: &dyn Flash) -> usize {
15011557 align_up ( c:: boot_trailer_sz ( dev. align ( ) as u32 ) , sector_size) as usize
15021558}
15031559
1560+ fn image_largest_trailer ( dev : & dyn Flash ) -> usize {
1561+ // Using the header size we know, the trailer size, and the slot size, we can compute
1562+ // the largest image possible.
1563+ let trailer = if Caps :: OverwriteUpgrade . present ( ) {
1564+ // This computation is incorrect, and we need to figure out the correct size.
1565+ // c::boot_status_sz(dev.align() as u32) as usize
1566+ 16 + 4 * dev. align ( )
1567+ } else if Caps :: SwapUsingMove . present ( ) {
1568+ let sector_size = dev. sector_iter ( ) . next ( ) . unwrap ( ) . size as u32 ;
1569+ align_up ( c:: boot_trailer_sz ( dev. align ( ) as u32 ) , sector_size) as usize
1570+ } else if Caps :: SwapUsingScratch . present ( ) {
1571+ tralier_estimation ( dev)
1572+ } else {
1573+ panic ! ( "The maximum image size can't be calculated." )
1574+ } ;
1575+
1576+ trailer
1577+ }
1578+
15041579/// Install a "program" into the given image. This fakes the image header, or at least all of the
15051580/// fields used by the given code. Returns a copy of the image that was written.
15061581fn install_image ( flash : & mut SimMultiFlash , slot : & SlotInfo , len : ImageSize ,
@@ -1530,26 +1605,22 @@ fn install_image(flash: &mut SimMultiFlash, slot: &SlotInfo, len: ImageSize,
15301605 let len = match len {
15311606 ImageSize :: Given ( size) => size,
15321607 ImageSize :: Largest => {
1533- // Using the header size we know, the trailer size, and the slot size, we can compute
1534- // the largest image possible.
1535- let trailer = if Caps :: OverwriteUpgrade . present ( ) {
1536- // This computation is incorrect, and we need to figure out the correct size.
1537- // c::boot_status_sz(dev.align() as u32) as usize
1538- 16 + 4 * dev. align ( )
1539- } else if Caps :: SwapUsingMove . present ( ) {
1540- let sector_size = dev. sector_iter ( ) . next ( ) . unwrap ( ) . size as u32 ;
1541- align_up ( c:: boot_trailer_sz ( dev. align ( ) as u32 ) , sector_size) as usize
1542- } else if Caps :: SwapUsingScratch . present ( ) {
1543- tralier_estimation ( dev)
1544- } else {
1545- panic ! ( "The maximum image size can't be calculated." )
1546- } ;
1608+ let trailer = image_largest_trailer ( dev) ;
15471609 let tlv_len = tlv. estimate_size ( ) ;
15481610 info ! ( "slot: 0x{:x}, HDR: 0x{:x}, trailer: 0x{:x}" ,
15491611 slot_len, HDR_SIZE , trailer) ;
15501612 slot_len - HDR_SIZE - trailer - tlv_len
1551-
1613+ } ,
1614+ ImageSize :: Oversized => {
1615+ let trailer = image_largest_trailer ( dev) ;
1616+ let tlv_len = tlv. estimate_size ( ) ;
1617+ info ! ( "slot: 0x{:x}, HDR: 0x{:x}, trailer: 0x{:x}" ,
1618+ slot_len, HDR_SIZE , trailer) ;
1619+ // the overflow size is rougly estimated to work for all
1620+ // configurations. It might be precise if tlv_len will be maked precise.
1621+ slot_len - HDR_SIZE - trailer - tlv_len + dev. align ( ) * 4
15521622 }
1623+
15531624 } ;
15541625
15551626 // Generate a boot header. Note that the size doesn't include the header.
0 commit comments