First of all get information about your flash device.
After alt_flash_open_dev call, define
alt_flash_cfi_dev* flash = (alt_flash_cfi_dev*)fd;
Then you can read:
flash->dev.number_of_regions
For every flash region:
flash->dev.region_info
.offset
flash->dev.region_info.region_size
flash->dev.region_info
.number_of_blocks
flash->dev.region_info.block_size
Probably you have a single flash region, so you need read these only for i=0
If block_size is indeed 64kB then my supposition is probably correct and you must limit write size to 64kB (and align writes to block boundaries)
You can simply do something like this:
int addr = 0;
while (addr < size) {
//Write data into flash
ret_code = alt_write_flash(fd, addr, src_ptr+addr, 0x10000);
if(ret_code != 0)
{
printf("Error writing into flash: %d\n", ret_code);
exit(1);
}
addr += 0x10000; // next 64kb block
}