Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

alt_read_flash()

Hello,

What is the meaning of 5000 in alt_read_flash(fd, 0, dest, 5000)? I cannot understand the arguments inside alt_read_flash. I read a few articles and notes but still cannot get its meaning. pls help. thanks!

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    What is the error code? Have you tried writing a smaller value? is there a boundry that it appears to not write on? In all my use of it i write only block_size chunks at a time. Don't know if you have to do that or not, but all my code does. So, you would have to read the regions data structure, which

    
    alt_flash_fd* fd;
    int number_of_regions;
    flash_region *regions;
        fd = alt_flash_open_dev(flashName);
        if (!fd)
            return -EACCES;
        retval = alt_get_flash_info(fd, &regions, &number_of_regions);
        if (retval) {
            alt_flash_close_dev(fd);
            return errno;
        }
    

    Then regions->block_size contains the size of the write blocks on the flash device.

    ::edited to include code tags.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    yes, i tried for smaller value n it works fine. i dont quite understand regarding writing in block. please help. sorry, i am new. thanks!

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Flash is structured not as one large memory but as 1-N regions and each region has 1-N blocks of a paticular size. You can not usually erase just a single byte of flash, so you have to erase the whole block, and then make any changes you need. I know, poor explanation, but google may have a better one, or altera. Either way, you have to take that into account when making a change as you may inadvertently corrupt part of a block if you try and do a partial write. But, per your other thread, if you are just doing a single write then reading back and it is failing that should not be a corruption problem. But, try only writing a block at a time, and looping until you have written all of your data. The code to get the block size is above.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks! No, it is a good explanation! i will give it a try and if cant, i will leave a msg here again.