First of all init the flash device and possibly get extra info about the flash device, like block size:
flash_region *regions;
int numRegions;
int error = 0;
pFlashDevice = alt_flash_open_dev(FLASH_CONTROLLER_NAME);
if (pFlashDevice <= 0)
error = -1;
if (!error)
error = alt_epcs_flash_get_info(pFlashDevice, ®ions, &numRegions);
if (!error) {
flash_block_size = regions->block_size;
flash_max_addr = regions->region_size;
This is for erasing a single block:
alt_epcs_flash_erase_block(pFlashDevice, block_address);
This is for writing any data to a previously erased area:
int buf = { 1, 2,3,4,5,6,7,8,9,10 };
rv = alt_epcs_flash_write_block(pFlashDevice, block_address,
data_offset_inside_block , buf, 10);
Then, read back data with:
alt_epcs_flash_read(pFlashDevice, addr, buf, len);