@@ -291,6 +291,29 @@ impl ImagesBuilder {
291291 }
292292 }
293293
294+ pub fn make_oversized_secondary_slot_image ( self ) -> Images {
295+ let mut bad_flash = self . flash ;
296+ let ram = self . ram . clone ( ) ; // TODO: Avoid this clone.
297+ let images = self . slots . into_iter ( ) . enumerate ( ) . map ( |( image_num, slots) | {
298+ let dep = BoringDep :: new ( image_num, & NO_DEPS ) ;
299+ let primaries = install_image ( & mut bad_flash, & slots[ 0 ] ,
300+ maximal ( 32784 ) , & ram, & dep, false ) ;
301+ let upgrades = install_image ( & mut bad_flash, & slots[ 1 ] ,
302+ ImageSize :: Oversized , & ram, & dep, false ) ;
303+ OneImage {
304+ slots,
305+ primaries,
306+ upgrades,
307+ } } ) . collect ( ) ;
308+ Images {
309+ flash : bad_flash,
310+ areadesc : self . areadesc ,
311+ images,
312+ total_count : None ,
313+ ram : self . ram ,
314+ }
315+ }
316+
294317 pub fn make_erased_secondary_image ( self ) -> Images {
295318 let mut flash = self . flash ;
296319 let ram = self . ram . clone ( ) ; // TODO: Avoid this clone.
@@ -779,6 +802,53 @@ impl Images {
779802 fails > 0
780803 }
781804
805+ // Test taht too big upgrade image will be rejected
806+ pub fn run_oversizefail_upgrade ( & self ) -> bool {
807+ let mut flash = self . flash . clone ( ) ;
808+ let mut fails = 0 ;
809+
810+ info ! ( "Try upgrade image with to big size" ) ;
811+
812+ // Only perform this test if an upgrade is expected to happen.
813+ if !Caps :: modifies_flash ( ) {
814+ info ! ( "Skipping upgrade image with bad signature" ) ;
815+ return false ;
816+ }
817+
818+ self . mark_upgrades ( & mut flash, 0 ) ;
819+ self . mark_permanent_upgrades ( & mut flash, 0 ) ;
820+ self . mark_upgrades ( & mut flash, 1 ) ;
821+
822+ if !self . verify_trailers ( & flash, 0 , BOOT_MAGIC_GOOD ,
823+ BOOT_FLAG_SET , BOOT_FLAG_UNSET ) {
824+ warn ! ( "1. Mismatched trailer for the primary slot" ) ;
825+ fails += 1 ;
826+ }
827+
828+ // Run the bootloader...
829+ if !c:: boot_go ( & mut flash, & self . areadesc , None , None , false ) . success ( ) {
830+ warn ! ( "Failed first boot" ) ;
831+ fails += 1 ;
832+ }
833+
834+ // State should not have changed
835+ if !self . verify_images ( & flash, 0 , 0 ) {
836+ warn ! ( "Failed image verification" ) ;
837+ fails += 1 ;
838+ }
839+ if !self . verify_trailers ( & flash, 0 , BOOT_MAGIC_GOOD ,
840+ BOOT_FLAG_SET , BOOT_FLAG_UNSET ) {
841+ warn ! ( "2. Mismatched trailer for the primary slot" ) ;
842+ fails += 1 ;
843+ }
844+
845+ if fails > 0 {
846+ error ! ( "Expected an upgrade failure when image has to big size" ) ;
847+ }
848+
849+ fails > 0
850+ }
851+
782852 // Test that an upgrade is rejected. Assumes that the image was build
783853 // such that the upgrade is instead a downgrade.
784854 pub fn run_nodowngrade ( & self ) -> bool {
0 commit comments