Forum Discussion
21 Replies
- Altera_Forum
Honored Contributor
Hi posix6973,
> Does anyone know how to read erase and program the AMD flash memory in > ucLinux using C programs? Normally this is done with mtd-utils: http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/....old/mtd-utils/ (http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/userland.old/mtd-utils/) In your own applications if you use a JFFS2 filesystem, you can simply access the files with read, write, etc. system calls. If you don't use a filesystem, then you can directly access the device via the mtd device inodes (but your application is responsible for reading/writing the appropriate offsets in the flash). You can also just access the flash directly through a pointer since there's no MMU. But this is probably not good practice unless you have some compelling reasons not to use mtd. Regards, --Scott - Altera_Forum
Honored Contributor
Hi Scott,
I have re-built the kernel with JFFS2 filesystem selected and the system boot as below: uClinux/Nios II Altera Nios II support © 2004 Microtronix Datacom Ltd. Built 1 zonelists Kernel command line: root=/dev/mtdblock0 ro PID hash table entries: 256 (order: 8, 4096 bytes) Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) Memory available: 30528k/32768k RAM, 0k/0k ROM (1567k kernel code, 302k data) Mount-cache hash table entries: 512 (order: 0, 4096 bytes) NET: Registered protocol family 16 JFFS2 version 2.2. © 2001-2003 Red Hat, Inc. JFFS2: default compression mode: priority NIOS serial driver version 0.0 ttyS0 (irq = 4) is a builtin NIOS UART io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize smc_probe: 85000 Khz Nios SMSC LAN91C111 Driver (v2.1), (Linux Kernel 2.6) eth0: SMC91C11xFD(rev:1) at 0x82210300 IRQ:6 MEMSIZE:8192b NOWAIT:0 ADDR: 00:07:ed:0f:63:08 smc_probe: 85000 Khz Nios Altera NDK flash (AMD): Found 1 x16 devices at 0x0 in 8-bit bank Amd/Fujitsu Extended Query Table at 0x0040 Altera NDK flash (AMD): CFI does not contain boot bank location. Assuming top. number of CFI chips: 1 cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness. cmdlinepart partition parsing not available RedBoot partition parsing not available Using Altera NDK partition definition Creating 4 MTD partitions on "Altera NDK flash (AMD)": 0x00200000-0x00600000 : "romfs/jffs2" 0x00000000-0x00200000 : "loader/kernel" 0x00600000-0x00700000 : "User configuration" 0x00700000-0x00800000 : "safe configuration" microtronix[mtd]: RAM probe address=0x200000 size=0x3f8000 Creating 1 MTD partitions on "RAM": 0x00000000-0x003f8000 : "ROMfs" microtronix[mtd]: set ROMfs to be root filesystem NET: Registered protocol family 2 IP: routing cache hash table of 512 buckets, 4Kbytes TCP established hash table entries: 2048 (order: 2, 16384 bytes) TCP bind hash table entries: 2048 (order: 1, 8192 bytes) TCP: Hash tables configured (established 2048 bind 2048) NET: Registered protocol family 1 NET: Registered protocol family 17 VFS: Mounted root (romfs filesystem) readonly. Freeing unused kernel memory: 64k freed (0x41b2000 - 0x41c1000) expand: from=/ramfs.img to=/dev/ram0 expand: from=/ramfs.img to=/dev/ram1 eth0:PHY 100BaseT eth0:PHY Full Duplex /etc/issue www.microtronix.com June 2005 Welcome to Linux on the Nios II Nios2 login: root Password: # cat /proc/mtd dev: size erasesize name mtd0: 00400000 00010000 "romfs/jffs2" mtd1: 00200000 00010000 "loader/kernel" mtd2: 00100000 00010000 "User configuration" mtd3: 00100000 00010000 "safe configuration" mtd4: 003f8000 00001000 "ROMfs"# I have two questions: 1. I didn’t see any mtd device file create in /dev. Did I missing some procedures? 2. Need I create the mtd-utils with kernel? 3. What difference between ROMfs and romfs/jffs2 in boot report? Thanks in advance. Best regards, - Altera_Forum
Honored Contributor
Hi posix6973,
> 1. I didn’t see any mtd device file create in /dev. Did I missing some procedures? You need to do this when you create the file system. You have two choices: (1) Create the device inodes by hand using mknod, then run mkfs.jffs2 (2) Create a device table file and use the -D, --devtable option to mkfs.jffs2 The second option is very convenient since you don't need to be root, and you basically have built-in documentation for /dev ;-) > 2. Need I create the mtd-utils with kernel? No. Just download and build the applications like any other linux apps. > 3. What difference between ROMfs and romfs/jffs2 in boot report? It looks like you are using two different mtd mapping drivers. Take a look at: drivers/mtd/maps/altera.c. drivers/mtd/maps/nios_romfs.c Regards, --Scott - Altera_Forum
Honored Contributor
Hi Scott,
As you mentioned: >(2) Create a device table file and use the -D, --devtable option to mkfs.jffs2 >The second option is very convenient since you don't need to be root, and you basically >have built-in documentation for /dev ;-) 1. I take the mkfs.jffs.c form mtd-util and compiler it as application project but it report too many error (incompatible types in assignment and crc32.h: No such file or directory) even I change the include file to <linux/crc32.h>. make -k all no emulation specific options. nios2-elf-gcc -nostdinc -D__linux__ -O2 -I"c:/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0"/include -I/cygdrive/c/altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1//include -fno-optimize-sibling-calls -mhw-mul -mhw-mulx -O0 -g -I"c:/altera/workspace/ep2c35Linux/build/include" -Wall -c -o mkfs.jffs2.o mkfs.jffs2.c mkfs.jffs2.c:45:19: crc32.h: No such file or directory mkfs.jffs2.c: In function `write_dirent': mkfs.jffs2.c:509: error: incompatible types in assignment mkfs.jffs2.c:510: error: incompatible types in assignment mkfs.jffs2.c:511: error: incompatible types in assignment 2. The /dev…. is read only filesystem how can I create the mtd device on it? Please give me some hints or show me how to do. Thanks again. Best regards, - Altera_Forum
Honored Contributor
Hi, scott
<div class='quotetop'>QUOTE </div> --- Quote Start --- If you don't use a filesystem, then you can directly access the device via the mtd device inodes (but your application is responsible for reading/writing the appropriate offsets in the flash).[/b] --- Quote End --- Can Flash(mtdblock1;kernel) be accessed directly by "open, read,write" routines If I want to update the kernel in runtime, then reboot. - Altera_Forum
Honored Contributor
Hi ,
> Can Flash(mtdblock1;kernel) be accessed directly by "open, read,write" routines If I want to > update the kernel in runtime, then reboot. Yes, but use the character mode device (major 90 I think) -- which needs to be enabled in your kernel configuration. Then you can open, read, write, ioctl. To erase, use the MEMERASE ioctl. See the following: include/mtd/mtd-abi.h drivers/mtd/mtdchar.c You might want to review the mtd-utils code as well. Regards, --Scott - Altera_Forum
Honored Contributor
Hi posix6973,
> I take the mkfs.jffs.c form mtd-util and compiler it as application project but it report > too many error It's not quite ready for cygwin ;-) You can get mkfs.jffs2 sources that build under cygwin at: http://www.psyent.com/download (http://www.psyent.com/download) > 2. The /dev…. is read only filesystem how can I create the mtd device on it? The mtd "partition" can be read-only or read-write ... this is controlled by your mapping driver. You can set the device "inode" attributes when you create the inode. If you want erase/write capability, both the partition and the inode attributes should be writeable. Regards, --Scott - Altera_Forum
Honored Contributor
Hi Scoot,
>The mtd "partition" can be read-only or read-write ....... Sorry, still don’t understand could you explain in detail or show me how to configure the system? If use directly access the AMD Flash memory which function be taken and how to specify the inode or name parameters? mtd_open(struct inode *inode, struct file *file) or. open(char *name, int flags, int perms) Thanks for help. Best regards, - Altera_Forum
Honored Contributor
Hi posix6973,
> Sorry, still don’t understand could you explain in detail or show me how to > configure the system? You already did configure the system:<div class='quotetop'>QUOTE </div> --- Quote Start --- Creating 4 MTD partitions on "Altera NDK flash (AMD)": 0x00200000-0x00600000 : "romfs/jffs2" 0x00000000-0x00200000 : "loader/kernel" 0x00600000-0x00700000 : "User configuration" 0x00700000-0x00800000 : "safe configuration"[/b] --- Quote End --- And ... <div class='quotetop'>QUOTE </div> --- Quote Start --- It looks like you are using two different mtd mapping drivers. Take a look at: drivers/mtd/maps/altera.c. drivers/mtd/maps/nios_romfs.c[/b] --- Quote End --- Review the source code. Look at the partition maps with attention to the mask_flags field of the mtd_partition structures. This field should _not_ include MTD_WRITEABLE if you want the partition to be writeable. Make sure your map matches your actual hardware. Enable the character mode device driver (CONFIG_MTD_CHAR) in the kernel and create an inode for the character mode driver (major: 90, minor: partition number).<div class='quotetop'>QUOTE </div> --- Quote Start --- You have two choices: (1) Create the device inodes by hand using mknod, then run mkfs.jffs2 (2) Create a device table file and use the -D, --devtable option to mkfs.jffs2[/b] --- Quote End --- Then for example:
If you need details, examples, info: <div class='quotetop'>QUOTE </div> --- Quote Start --- See the following: include/mtd/mtd-abi.h drivers/mtd/mtdchar.c You might want to review the mtd-utils code as well.[/b] --- Quote End --- Regards, --Scottint fd; fd = open ("/dev/mtd0", O_RDWR); etc. - Altera_Forum
Honored Contributor
Hi Scott,
I fixed my NiosII uClinux and the MTD partitions boot as below: uClinux/Nios II Altera Nios II support © 2004 Microtronix Datacom Ltd. Built 1 zonelists Kernel command line: root=/dev/mtdblock0 ro PID hash table entries: 256 (order: 8, 4096 bytes) Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) Memory available: 30720k/32768k RAM, 0k/0k ROM (1416k kernel code, 298k data) Mount-cache hash table entries: 512 (order: 0, 4096 bytes) NET: Registered protocol family 16 NIOS serial driver version 0.0 ttyS0 (irq = 4) is a builtin NIOS UART io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize smc_probe: 85000 Khz Nios SMSC LAN91C111 Driver (v2.1), (Linux Kernel 2.6) eth0: SMC91C11xFD(rev:1) at 0x82210300 IRQ:6 MEMSIZE:8192b NOWAIT:0 ADDR: 00:07:ed:0f:63:08 smc_probe: 85000 Khz Nios Altera NDK flash (AMD): Found 1 x16 devices at 0x0 in 8-bit bank Amd/Fujitsu Extended Query Table at 0x0040 Altera NDK flash (AMD): CFI does not contain boot bank location. Assuming top. number of CFI chips: 1 cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness. cmdlinepart partition parsing not available RedBoot partition parsing not available Using Altera NDK partition definition Creating 4 MTD partitions on "Altera NDK flash (AMD)": 0x00200000-0x00600000 : "romfs/jffs2" 0x00000000-0x00200000 : "loader/kernel" 0x00600000-0x00700000 : "User configuration" 0x00700000-0x00800000 : "safe configuration" NET: Registered protocol family 2 IP: routing cache hash table of 512 buckets, 4Kbytes TCP established hash table entries: 2048 (order: 2, 16384 bytes) TCP bind hash table entries: 2048 (order: 1, 8192 bytes) TCP: Hash tables configured (established 2048 bind 2048) NET: Registered protocol family 1 NET: Registered protocol family 17 VFS: Mounted root (romfs filesystem) readonly. Freeing unused kernel memory: 60k freed (0x418c000 - 0x419a000) expand: from=/ramfs.img to=/dev/ram0 expand: from=/ramfs.img to=/dev/ram1 eth0:PHY 100BaseT eth0:PHY Half Duplex /etc/issue www.microtronix.com June 2005 Welcome to Linux on the Nios II Nios2 login: root Password: # cat /proc/devices Character devices: 1 mem 2 pty 3 ttyp 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 10 misc 90 mtd 128 ptm 136 pts Block devices: 1 ramdisk 31 mtdblock# cat /proc/mtd dev: size erasesize name mtd0: 00400000 00010000 "romfs/jffs2" mtd1: 00200000 00010000 "loader/kernel" mtd2: 00100000 00010000 "User configuration" mtd3: 00100000 00010000 "safe configuration"# mknod /var/mtd0 c 90 0# mknod /var/mtd1 c 90 1# mknod /var/mtd2 c 90 2# mknod /var/mtd3 c 90 3# ls -la /var drwxr-xr-x 3 root root 1024 Nov 30 00:03 . drwxr-xr-x 1 root root 32 Jan 1 1970 .. drwxr-xr-x 2 root root 12288 Oct 8 1998 lost+found crw-r--r-- 1 root root 90, 0 Nov 30 00:02 mtd0 crw-r--r-- 1 root root 90, 1 Nov 30 00:02 mtd1 crw-r--r-- 1 root root 90, 2 Nov 30 00:03 mtd2 crw-r--r-- 1 root root 90, 3 Nov 30 00:03 mtd3 1. I make 4 MTD character devices on /var for character mode direct access FLASH using open, ioctl, read. This method is correct or not? int fd; fd = open ("/dev/mtd0", O_RDWR); etc. 2. >(2) Create a device table file and use the -D, --devtable option to mkfs.jffs2 Could you explain the -D, --devtable option and how to use? Thanks, Best Regards,