Forum Discussion
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
Honored Contributor
Thanks! No, it is a good explanation! i will give it a try and if cant, i will leave a msg here again.
- Altera_Forum
Honored 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
Honored 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
Honored 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
Then regions->block_size contains the size of the write blocks on the flash device. ::edited to include code tags.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, ®ions, &number_of_regions); if (retval) { alt_flash_close_dev(fd); return errno; } - Altera_Forum
Honored Contributor
my code is here: http://www.alteraforum.com/forum/showthread.php?t=28345
- Altera_Forum
Honored Contributor
Yes, i put that before but the return value for alt_write_flash is an error. cannot write.
- Altera_Forum
Honored Contributor
1048576, or 0x100000
- Altera_Forum
Honored Contributor
Hi, mmTsuchi. I am transferring 1MB (1 Mega Byte) of data into flash. I am using alt_write_flash. So, what should be the length in alt_write_flash. pls help. I have been debugging the whole day but still cannot understand. Thanks!
- Altera_Forum
Honored Contributor
--- Quote Start --- So, it means, if my data is 1Mb, so the length is 1Mb? --- Quote End --- Be careful about 1 Mb = 1 Mega bits 1 Mb = 1 mega Bytes (1 mega octet) = 8 megabits - Altera_Forum
Honored Contributor
Correct. You write however many bytes you would like to read out in that field. You can look at some of the memtest examples for their usage of it as well.
You do have to play nicely with the region size though if you are managing the file locations yourself. So, don't expect to write a partial block and not have the other contents of that block erased. But that is a whole other topic kinda.