Forum Discussion
Altera_Forum
Honored Contributor
15 years agoHow to Save Data in uClinux
hi I am trying to save data in to Flash. I want to load previous execute data and system setting before I turn it off. Did anyone know how to do this. Please tell who or share me so...
Altera_Forum
Honored Contributor
15 years ago --- Quote Start --- Basically, if you want to use CFI-Flash, you may want to add MTD driver. I am using JFFS2. It is easy to use, but consume a bit area for the file system itself. You should be able to find the drive in the menuconfig selection. --- Quote End --- Hi nekojiru Thank you for your replying. I enable "Direct char device access to MTD Device" After that, I write a small program to test it. I try to open it --- Quote Start --- fd = open("/dev/mtd0",O_RDWR); if(fd<0){ printf("Cannot Open mtd0 Error Code = %d\n",fd); }else{ printf("Open mtd0 Success\n"); ret = read( fd, buffer, 4); if(ret > 0) printf("PreData 0x%02x 0x%02x 0x%02x 0x%02x\n",buffer[0],buffer[1],buffer[2],buffer[3]); else printf("Reading Fail %d\n",ret); buffer[0] = buffer[0] + 1; buffer[1] = buffer[1] + 2; buffer[2] = buffer[2] + 3; buffer[3] = 0x30; ret = write(fd,buffer, 4); if(ret > 0) printf("Write Success !!\n"); else printf("Write Fail %d\n",ret); ret = read( fd, buffer, 4); if(ret > 0) printf("Reading Data 0x%02x 0x%02x 0x%02x 0x%02x\n",buffer[0],buffer[1],buffer[2],buffer[3]); else printf("Reading Fail %d\n",ret); } close(fd); --- Quote End --- The Exec result is past below --- Quote Start --- Open mtd0 Success PreData 0xff 0x00 0x00 0x01 Write Success !! Reading Data 0xff 0xff 0xff 0xff --- Quote End --- It seems I still can't read write to correct location. I search Internet, and It seems I need to create the file systems mkfs.jffs2 **** However, do I need to create file system every time? If I need to do it every time when I booting up, my file saved inside will been clear. Then I still can't save it. I am using Cyclone III (#define CONFIG_ALTERA_CYCLONE_III) This is the booting up result when I added the MTD Support. http://i53.tinypic.com/zmts2.jpg Below is my setting for Flash MTD Support Setting http://i54.tinypic.com/20s6fpx.jpg File System Setting http://i52.tinypic.com/28vx8nk.png Flash Tool http://i52.tinypic.com/wlt92v.png