@@ -492,6 +492,35 @@ find_last_sector_idx(const struct boot_loader_state *state, uint32_t copy_size)
492492 return last_sector_idx ;
493493}
494494
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+
495524/**
496525 * Swaps the contents of two flash regions within the two image slots.
497526 *
@@ -732,37 +761,6 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
732761}
733762#endif /* !MCUBOOT_OVERWRITE_ONLY */
734763
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-
766764int app_max_size (struct boot_loader_state * state )
767765{
768766 size_t num_sectors_primary ;
0 commit comments