Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: cp somefile /dev/mtdX - doesn't work - SOLVED
PostPosted: Wed Apr 13, 2011 10:15 am 
Offline

Joined: Fri Mar 25, 2011 10:58 pm
Posts: 8
I have an AT91SAM9260 system with kernel 2.6.26.8 w/o config sources where I can do direct copy of files to the dataflash-backed mtd devices like:

cp my_file /dev/mtd3

Making a new one with latest kernel (using buildroot), I am unable to do the same.

I can do "flashcp file /dev/mtd3", and it works. But using simple cp immediately returns and writes nothing. Moreover, after that I have device file changed like this:

crw-r----- 1 root disk 90, 4 Dec 31 17:00 /dev/mtd2
crw-r----- 1 root disk 90, 5 Dec 31 17:00 /dev/mtd2ro
-rw------- 1 root root 2247944 Dec 31 17:03 /dev/mtd3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And after that even flashcp can do nothing with it.

I suspect that I don't have some option in the kernel to support such direct write. Maybe someone knows which kernel option should I set for this?

Thanks in advance!


Last edited by osnwt on Wed Apr 13, 2011 5:14 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: cp somefile /dev/mtdX (on data flash) - doesn't work
PostPosted: Wed Apr 13, 2011 4:28 pm 
Offline

Joined: Sun Jan 23, 2011 7:18 pm
Posts: 12
By doing cp my_file /dev/mtd3 you are copying 'my_file' to a file named 'mtd3' inside the '/dev' dir, effectively destroying the device node entry. Thats why flashcp doesn't work any more after that and the file size is now 2247944.

You need to understand how devices are used in linux, you should be able to do 'cat my_file > /dev/mtd3' which will pipe the contents of my_file into /dev/mtd3, but that is only useful if my_file contains a filesystem image.



[quote="osnwt"]I have an AT91SAM9260 system with kernel 2.6.26.8 w/o config sources where I can do direct copy of files to the dataflash-backed mtd devices like:

cp my_file /dev/mtd3

Making a new one with latest kernel (using buildroot), I am unable to do the same.

I can do "flashcp file /dev/mtd3", and it works. But using simple cp immediately returns and writes nothing. Moreover, after that I have device file changed like this:

crw-r----- 1 root disk 90, 4 Dec 31 17:00 /dev/mtd2
crw-r----- 1 root disk 90, 5 Dec 31 17:00 /dev/mtd2ro
-rw------- 1 root root 2247944 Dec 31 17:03 /dev/mtd3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And after that even flashcp can do nothing with it.

I suspect that I don't have some option in the kernel to support such direct write. Maybe someone knows which kernel option should I set for this?

Thanks in advance![/quote]


Top
 Profile  
 
 Post subject: cp somefile /dev/mtdX (on data flash) - doesn't work - SOLVE
PostPosted: Wed Apr 13, 2011 5:13 pm 
Offline

Joined: Fri Mar 25, 2011 10:58 pm
Posts: 8
>>>You need to understand how devices are used in linux, you should be able to do 'cat my_file > /dev/mtd3' which will pipe the contents of my_file into /dev/mtd3, but that is only useful if my_file contains a filesystem image.

Thank you for the help, it really works! But for the full clarification here is an additional info for others.

Latest busybox has the following library tuning option:

config FEATURE_NON_POSIX_CP
bool "Non-POSIX, but safer, copying to special nodes"
default y
help
With this option, "cp file symlink" will delete symlink and create a regular file. This does not conform to POSIX, but prevents a symlink attack. Similarly, "cp file device" will not send file's data to the device.

There was no such option in the legacy system's busybox, that's why this worked there. And as I can see from the help message, "cp file /dev/device" is a POSIX-compliant way which was turned off by default in the busybox.

So either cat should be used, or cp with this option turned off.

I just verified both ways. Both work as expected.


Top
 Profile  
 
 Post subject: Re: cp somefile /dev/mtdX - doesn't work - SOLVED
PostPosted: Wed Apr 13, 2011 5:47 pm 
Offline

Joined: Sun Jan 23, 2011 7:18 pm
Posts: 12
It's nice to know busybox has that option.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: