! @brief Add a chunk of data to be programmed.
        
        The data may cross flash memory region boundaries, as long as the regions are contiguous.
        
        @param self
        @param address Integer address for where the first byte of _data_ should be written.
        @param data A list of byte values to be programmed at the given address.
        
        @return The FlashLoader instance is returned, to allow chaining further add_data()
            calls or a call to commit().
        
        @exception ValueError Raised when the address is not within a flash memory region.
        @exception RuntimeError Raised if the flash memory region does not have a valid Flash
            instance associated with it, which indicates that the target connect sequence did
            not run successfully.

def add_data(self, address, data):
        """! @brief Add a chunk of data to be programmed.
        
        The data may cross flash memory region boundaries, as long as the regions are contiguous.
        
        @param self
        @param address Integer address for where the first byte of _data_ should be written.
        @param data A list of byte values to be programmed at the given address.
        
        @return The FlashLoader instance is returned, to allow chaining further add_data()
            calls or a call to commit().
        
        @exception ValueError Raised when the address is not within a flash memory region.
        @exception RuntimeError Raised if the flash memory region does not have a valid Flash
            instance associated with it, which indicates that the target connect sequence did
            not run successfully.
        """
        while len(data):
            # Look up flash region.
            region = self._map.get_region_for_address(address)
            if region is None:
                raise ValueError("no memory region defined for address 0x%08x" % address)
            if not region.is_flash:
                raise ValueError("memory region at address 0x%08x is not flash" % address)
        
            # Get our builder instance.
            if region in self._builders:
                builder = self._builders[region]
            else:
                if region.flash is None:
                    raise RuntimeError("flash memory region at address 0x%08x has no flash instance" % address)
                builder = region.flash.get_flash_builder()
                builder.log_performance = False
                self._builders[region] = builder
        
            # Add as much data to the builder as is contained by this region.
            programLength = min(len(data), region.end - address + 1)
            assert programLength != 0
            builder.add_data(address, data[:programLength])
            
            # Advance.
            data = data[programLength:]
            address += programLength
            self._total_data_size += programLength
        
        return self