@@ -492,6 +492,35 @@ find_last_sector_idx(const struct boot_loader_state *state, uint32_t copy_size)
492
492
return last_sector_idx ;
493
493
}
494
494
495
+ /**
496
+ * Finds the number of swap operations that have to be performed to swap the two images.
497
+ *
498
+ * @param state Current bootloader's state.
499
+ * @param copy_size Total number of bytes to swap.
500
+ *
501
+ * @return The number of swap operations that have to be performed.
502
+ */
503
+ static uint32_t
504
+ find_swap_count (const struct boot_loader_state * state , uint32_t copy_size )
505
+ {
506
+ int first_sector_idx ;
507
+ int last_sector_idx ;
508
+ uint32_t swap_count ;
509
+
510
+ last_sector_idx = find_last_sector_idx (state , copy_size );
511
+
512
+ swap_count = 0 ;
513
+
514
+ while (last_sector_idx >= 0 ) {
515
+ boot_copy_sz (state , last_sector_idx , & first_sector_idx );
516
+
517
+ last_sector_idx = first_sector_idx - 1 ;
518
+ swap_count ++ ;
519
+ }
520
+
521
+ return swap_count ;
522
+ }
523
+
495
524
/**
496
525
* Swaps the contents of two flash regions within the two image slots.
497
526
*
@@ -732,37 +761,6 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
732
761
}
733
762
#endif /* !MCUBOOT_OVERWRITE_ONLY */
734
763
735
- #ifdef MCUBOOT_SWAP_USING_SCRATCH
736
- /**
737
- * Finds the number of swap operations that have to be performed to swap the two images.
738
- *
739
- * @param state Current bootloader's state.
740
- * @param copy_size Total number of bytes to swap.
741
- *
742
- * @return The number of swap operations that have to be performed.
743
- */
744
- static uint32_t
745
- find_swap_count (const struct boot_loader_state * state , uint32_t copy_size )
746
- {
747
- int first_sector_idx ;
748
- int last_sector_idx ;
749
- uint32_t swap_count ;
750
-
751
- last_sector_idx = find_last_sector_idx (state , copy_size );
752
-
753
- swap_count = 0 ;
754
-
755
- while (last_sector_idx >= 0 ) {
756
- boot_copy_sz (state , last_sector_idx , & first_sector_idx );
757
-
758
- last_sector_idx = first_sector_idx - 1 ;
759
- swap_count ++ ;
760
- }
761
-
762
- return swap_count ;
763
- }
764
- #endif /* MCUBOOT_SWAP_USING_SCRATCH */
765
-
766
764
int app_max_size (struct boot_loader_state * state )
767
765
{
768
766
size_t num_sectors_primary ;
0 commit comments