Forum Discussion
21 Replies
- Altera_Forum
Honored Contributor
Hi posix6973,
> This method is correct or not? > int fd; > fd = open ("/dev/mtd0", O_RDWR); > etc. Yes. The mtd-utils code has many examples. Take a look the erase utility for example. > Could you explain the -D, --devtable option and how to use? This is only for mkfs.jffs2 ... if you're not using jffs2, you won't need this. Regardless, when using mkfs.jffs2, a devtable file provides two advantages: 1. You don't have to su root. Without a devtable file, you would need to have root privileges on your development host to create device inodes in your jffs2 target tree -- which is a big hassle -- at least if you're concerned with security ;-) 2. The devtable file serves as a form of documentation that can be placed under version control just like any other source file. This is right out of an mtd-utils souce tree: <div class='quotetop'>QUOTE </div> --- Quote Start --- # This is a sample device table file for use with mkfs.jffs2. You can# do all sorts of interesting things with a device table file. For# example, if you want to adjust the permissions on a particular file# you can just add an entry like:# /sbin/foobar f 2755 0 0 - - - - -# and (assuming the file /sbin/foobar exists) it will be made setuid# root (regardless of what its permissions are on the host filesystem.# # Device table entries take the form of:# <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count># where name is the file name, type can be one of: # f A regular file# d Directory# c Character special device file# b Block special device file# p Fifo (named pipe)# uid is the user id for the target file, gid is the group id for the# target file. The rest of the entried apply only to device special# file. # When building a target filesystem, it is desirable to not have to# become root and then run 'mknod' a thousand times. Using a device # table you can create device nodes and directories "on the fly".# Furthermore, you can use a single table entry to create a many device# minors. For example, if I wanted to create /dev/hda and /dev/hda[0-15]# I could just use the following two table entries:# /dev/hda b 640 0 0 3 0 0 0 -# /dev/hda b 640 0 0 3 1 1 1 16# # Have fun# -Erik Andersen <andersen@codepoet.org># # <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count> # /dev d 755 0 0 - - - - - /dev/mem c 640 0 0 1 1 0 0 - /dev/kmem c 640 0 0 1 2 0 0 - /dev/null c 640 0 0 1 3 0 0 - /dev/zero c 640 0 0 1 5 0 0 - /dev/random c 640 0 0 1 8 0 0 - /dev/urandom c 640 0 0 1 9 0 0 - /dev/tty c 640 0 0 5 0 0 0 - /dev/tty c 640 0 0 4 0 0 1 6 /dev/console c 640 0 0 5 1 0 0 - /dev/ram b 640 0 0 1 1 0 0 - /dev/ram b 640 0 0 1 0 0 1 4 /dev/loop b 640 0 0 7 0 0 1 2 /dev/ttyS c 640 0 0 4 64 0 1 4 [/b] --- Quote End --- Regards, --Scott - Altera_Forum
Honored Contributor
Hi all,
1. create these dev files in ROOTFS project in IDE: @mtd3,c,90,3 @mtdblock,b,31,0 @mtdblock,b,31,1 @mtdblock,b,31,2 @mtdblock,b,31,4 build,upload ROOTFS 2. config MTD, MTD_CHAR build kernel 3. download netflash from uClinux-dist-2005...tar.bz2 compile it, copy to NFS share dir. 4. after uClinux boot up, I test netflash# netflash -bfkn -r /dev/mtd3 192.168.168.0 testfile error: open("/dev/mtd3") permission denied Any suggestion , please? BTY, flash is AM29LV128 (16MB). My Altera maps is: Creating 5 MTD partitions on "Altera NDK flash (AMD)": 0x00200000-0x00c00000 : "romfs/root" 0x00000000-0x00200000 : "loader/kernel" 0x00c00000-0x00e00000 : "RW zone/jffs2" 0x00e00000-0x00f00000 : "User configuration" 0x00f00000-0x01000000 : "safe configuration" I'd like to test ACCESS mtdblock3(mtd3?). - Altera_Forum
Honored Contributor
It worked!
I debuged mtdchar.c, and found open permission errror from:
and the minor = dev_minor >>1 , so should Dev's minor should 0, 2, 4, 8 ... to writable? why? however , I modify the mtd3,c,90,3->mtd3,c,90,4. And, It worked: <div class='quotetop'>QUOTE </div> --- Quote Start --- netflash: ftping file "Makefile" from 192.168.168.160 .. netflash: got "Makefile", length=9180 netflash: programming FLASH device /dev/mtd3 ................................[/b] --- Quote End --- but, i don't know which location(address) of flash did netflash programming?/* You can't open the RO devices RW */ if ((file->f_mode & 2) && (minor & 1)) return -EACCES; - Altera_Forum
Honored Contributor
I've several days work invested in this jffs2 thing, but I'm not quite there yet. Below is a summary of what I've got so far. I'm diving into the mtd-utils stuff now...
# cat /proc/partitions major minor # blocks name 31 0 4064 mtdblock0 31 1 2048 mtdblock1 31 2 512 mtdblock2 31 3 8192 mtdblock3# cat /proc/mtd dev: size erasesize name mtd0: 003f8000 00010000 "ROMfs" mtd1: 00200000 00010000 "kernel" mtd2: 00080000 00010000 "Flash FS" mtd3: 00800000 00010000 "FPGA Cores"# ls -la /dev/mtdblock2 brw------- 1 root root 31, 2 Jan 1 1970 /dev/mtdblock2 [note I created the /dev entry in my ROMfs project as "@mtdblock2,b,31,2"] # cat /proc/partitions major minor # blocks name 31 0 4064 mtdblock0 31 1 2048 mtdblock1 31 2 512 mtdblock2 31 3 8192 mtdblock3# cat /proc/mtd dev: size erasesize name mtd0: 003f8000 00010000 "ROMfs" mtd1: 00200000 00010000 "kernel" mtd2: 00080000 00010000 "Flash FS" mtd3: 00800000 00010000 "FPGA Cores"# ls -la /var/flash drwxrwxrwx 2 root root 1024 Nov 30 18:57 . drwxr-xr-x 4 root root 1024 Nov 30 18:57 ..# mount -t jffs2 /dev/mtdblock2 /var/flash can't create lock file /etc/mtab~41: Read-only file system (use -n flag to overr ide)# mount -t jffs2 /dev/mtdblock2 /mnt -n Eep. No valid nodes for ino# 1 [the system locks up at this point...] I've created a file system image on a different machine and tried to cp it into /dev/mtdblock2, but it locks the system up as well. I compiled the mtd-tools erase program, and it's having issues as well:# cat /proc/mtd dev: size erasesize name mtd0: 003f8000 00010000 "ROMfs" mtd1: 00200000 00010000 "kernel" mtd2: 00080000 00010000 "Flash FS" mtd3: 00800000 00010000 "FPGA Cores"# cat /proc/partitions major minor # blocks name 31 0 4064 mtdblock0 31 1 2048 mtdblock1 31 2 512 mtdblock2 31 3 8192 mtdblock3# ./erase.exe /dev/mtd2 MTD_open File open error Any suggestions would be appreciated. - Altera_Forum
Honored Contributor
In my own case, You have done it ! Try to mkdir in the /var/flash for testing.
And , please refe to another post (http://www.niosforum.com/forum/index.php?act=st&f=18&t=2484) - Altera_Forum
Honored Contributor
Hi mikewest,
># ./erase.exe /dev/mtd2 > MTD_open > File open error Does /dev/mtd2 exist ... as a character mode device? And did you enable the char mode mtd driver in you kernel? Regards, --Scott - Altera_Forum
Honored Contributor
/dev/mtd2 shows up. I added it via my file system project (i.e., @mtd2,c,90,2). The CFI probe seems to work, and reports the partitions correction:
ISI flash device: 1000000 at 1000000 Probing for chip type phys_mapped_flash: Found 1 x16 devices at 0x0 in 16-bit bank Amd/Fujitsu Extended Query Table at 0x0040 Using buffer write method phys_mapped_flash: 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. Using ISI specific partition definition Creating 4 MTD partitions on "phys_mapped_flash": 0x00200000-0x005f8000 : "ROMfs" mtd: Giving out device 0 to ROMfs 0x00000000-0x00200000 : "kernel" mtd: Giving out device 1 to kernel 0x00700000-0x00800000 : "Flash FS" mtd: Giving out device 2 to Flash FS 0x00800000-0x01000000 : "FPGA Cores" mtd: Giving out device 3 to FPGA Cores Is it sufficient that the devices show up as follows?# ls -la /dev/mt* crw------- 1 root root 90, 0 Jan 1 1970 /dev/mtd0 crw------- 1 root root 90, 1 Jan 1 1970 /dev/mtd1 crw------- 1 root root 90, 2 Jan 1 1970 /dev/mtd2 crw------- 1 root root 90, 3 Jan 1 1970 /dev/mtd3 brw------- 1 root root 31, 2 Jan 1 1970 /dev/mtdblock2 I enabled the block and char mtd drivers in the kerel config...I just can't seem to nip this one. Mike --- Quote Start --- originally posted by smcnutt@Oct 17 2005, 08:22 AM hi mikewest,># ./erase.exe /dev/mtd2
> mtd_open
> file open error
does /dev/mtd2 exist ... as a character mode device? and did you enable the char
mode mtd driver in you kernel?
regards,
--scott
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10405)
--- quote end ---
--- Quote End ---
- Altera_Forum
Honored Contributor
I've tracked it down a bit more...mtd_char.c thinks this mtd is not writable.
/* You can't open it RW if it's not a writeable device */ if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { printk("Device not writable %x/%x\n", file->f_mode & 2, mtd->flags & MTD_WRITEABLE); put_mtd_device(mtd); return -EACCES; } With that printk added, I see the following:# ./mtd_debug.exe info /dev/mtd2 MTD_open Device not writable 2/0 open(): Permission denied I have _not_ included MTD_WRITEABLE in my partition definition, so there must be some other logic that's deciding this is the case. Partitions.h says writable partition be aligned: Note: writeable partitions require their size and offset be * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK). I'm asking for a 0x1000000 chunk at location 0x1000000. Seems like that shouldn't have any alignment issues... - Altera_Forum
Honored Contributor
Hi Mike,
> I have _not_ included MTD_WRITEABLE in my partition definition, so there must > be some other logic that's deciding this is the case. I'm getting confused WRT the partition you are actually trying to access ... mtd partition 0: 0x00200000-0x005f8000 : "ROMfs" mtd partition 1: 0x00000000-0x00200000 : "kernel" mtd partition 2: 0x00700000-0x00800000 : "Flash FS" mtd partition 3: 0x00800000-0x01000000 : "FPGA Cores" Just to be sure ... you are try to access mtd partition 1 (the "kernel" partition, minor number 2), AND it does NOT have the MTD_WRITEABLE attribute set ... correct? Given a particular minor number for the char driver, the partition number is: minor >> 1. Basically: partition = minor >> 1 partition is read only = minor & 1 partition is read/write = ~(minor & 1) irrespective of your char mode device inode attributes. E.g.: crw------- 1 root root 90, 0 Jan 1 1970 /dev/mtd0 crw------- 1 root root 90, 1 Jan 1 1970 /dev/mtd0_ro crw------- 1 root root 90, 2 Jan 1 1970 /dev/mtd1 crw------- 1 root root 90, 3 Jan 1 1970 /dev/mtd1_ro crw------- 1 root root 90, 4 Jan 1 1970 /dev/mtd2 crw------- 1 root root 90, 5 Jan 1 1970 /dev/mtd2_ro crw------- 1 root root 90, 6 Jan 1 1970 /dev/mtd3 crw------- 1 root root 90, 7 Jan 1 1970 /dev/mtd3_ro Regards, --Scott - Altera_Forum
Honored Contributor
Bingo. I must have missed the class on partition<->minor device numbering... Based on other threads here and this (http://www.enseirb.fr/~kadionik/embedded/uclinux/mtd/howto_mtd.html)
I was under the distinct impression that partition N mapped directly to minor number N (aka mtdN/mtdblockN). I now see that when MTD says: 0x00700000-0x00800000 : "Flash FS" mtd: Giving out device 2 to Flash FS I should access the partition via /dev/mtd4 (rw) and /dev/mtd5 (ro). I've spent several days trying to access it as /dev/mtd2 (which refers to my MTD_WRITEABLE-flagged partition# 1). Now I can open the partition (via /dev/mtd4), but I can't do much with it:# mkdir /var/flash# mount -t jffs2 /dev/mtdblock4 /var/flash -n mount: wrong fs type, bad option, bad superblock on /dev/mtdblock4, or too many mounted file systems AND# cp jffs2.img /dev/mtd4 MTD_open MTD_write Badness in local_bh_enable at /cygdrive/c/altera/kits/nios2/bin/eclipse/plugins/ com.microtronix.nios2linux.kernel_1.4.0/linux-2.6.x/kernel/softirq.c:140 Stack from 00c53e54:<0> <0> 00166734<0> 0000ffc4<0> 000ec400<0> 00000000<0> 00000000<0> 00369e68... AND# erase /dev/mtd4 Trying to open /dev/mtd4 MTD_open Erase Total 1 Units MTD_ioctl MTD_ioctl Performing Flash Erase of length 65536 at offset 0x0MTD_ioctl (System hangs here...) Cheers! Mike --- Quote Start --- partition = minor >> 1 partition is read only = minor & 1 partition is read/write = ~(minor & 1) irrespective of your char mode device inode attributes. E.g.: crw------- 1 root root 90, 0 Jan 1 1970 /dev/mtd0 crw------- 1 root root 90, 1 Jan 1 1970 /dev/mtd0_ro crw------- 1 root root 90, 2 Jan 1 1970 /dev/mtd1 crw------- 1 root root 90, 3 Jan 1 1970 /dev/mtd1_ro crw------- 1 root root 90, 4 Jan 1 1970 /dev/mtd2 crw------- 1 root root 90, 5 Jan 1 1970 /dev/mtd2_ro crw------- 1 root root 90, 6 Jan 1 1970 /dev/mtd3 crw------- 1 root root 90, 7 Jan 1 1970 /dev/mtd3_ro Regards, --Scott <div align='right'><{post_snapback}> (index.php?act=findpost&pid=10416)</div> --- Quote End --- --- Quote End ---