def _sector_erase_program_double_buffer(self, progress_cb=_stub_progress):
        """! @brief Double-buffered program by performing sector erases."""
        actual_sector_erase_count = 0
        actual_sector_erase_weight = 0
        progress = 0

        progress_cb(0.0)

        # Fill in same flag for all pages. This is done up front so we're not trying
        # to read from flash while simultaneously programming it.
        progress = self._scan_pages_for_same(progress_cb)

        # Erase all sectors up front.
        self.flash.init(self.flash.Operation.ERASE)
        for sector in self.sector_list:
            if sector.are_any_pages_not_same():
                # Erase the sector
                self.flash.erase_sector(sector.addr)
                
                # Update progress
                progress += sector.erase_weight
                if self.sector_erase_weight > 0:
                    progress_cb(float(progress) / float(self.sector_erase_weight))
        self.flash.uninit()

        # Set up page and buffer info.
        current_buf = 0
        next_buf = 1
        page, i = self._next_nonsame_page(0)

        # Make sure there are actually pages to program differently from current flash contents.
        if page is not None:
            self.flash.init(self.flash.Operation.PROGRAM)

            # Load first page buffer
            self.flash.load_page_buffer(current_buf, page.addr, page.data)

            while page is not None:
                assert page.same is not None

                # Kick off this page program.
                current_addr = page.addr
                current_weight = page.get_program_weight()

                self.flash.start_program_page_with_buffer(current_buf, current_addr)
                
                actual_sector_erase_count += 1
                actual_sector_erase_weight += page.get_program_weight()

                # Get next page and load it.
                page, i = self._next_nonsame_page(i)
                if page is not None:
                    self.flash.load_page_buffer(next_buf, page.addr, page.data)

                # Wait for the program to complete.
                result = self.flash.wait_for_completion()
                if result != 0:
                    raise FlashProgramFailure('program_page(0x%x) error: %i'
                            % (current_addr, result), current_addr, result)
                
                # Swap buffers.
                current_buf, next_buf = next_buf, current_buf

                # Update progress
                progress += current_weight
                if self.sector_erase_weight > 0:
                    progress_cb(float(progress) / float(self.sector_erase_weight))

            self.flash.uninit()

        progress_cb(1.0)

        LOG.debug("Estimated sector erase programmed page count: %i", self.sector_erase_count)
        LOG.debug("Actual sector erase programmed page count: %i", actual_sector_erase_count)

        return FlashBuilder.FLASH_SECTOR_ERASE
! @brief Double-buffered program by performing sector erases.