Forum Discussion
Altera_Forum
Honored Contributor
20 years agoproblem with usb driver
hi,
I have boot uclinux kernel successful,then i plug a usb disk on my board,that's ok.But it show errors when i run the follow code:
[/CODE]fdisk -l /dev/sda
fdisk:Bad command or file name
[CODE]mount -t vfat /dev/sda1 /mnt
FAT:Code page cp437 not found
mount failed:Invalid argument[/B]
please help me,thank you!
17 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by hippo@Jun 5 2006, 08:41 PM add "make -c user/busybox clean" after step2.boot uclinux,
run "busybox", to see what you have built in busybox.
what is your rc now?
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15934)
--- quote end ---
--- Quote End --- Hi,hippo. It can mount usb disk automatic,but show another erro: <div class='quotetop'>QUOTE </div> --- Quote Start --- Command: mount -t vfat /dev/sda1 /mnt Kernel panic - not syncing: Attempted to kill init! Execution Finished,Exiting[/b] --- Quote End --- My rc: <div class='quotetop'>QUOTE </div> --- Quote Start --- hostname uClinux mount -t proc proc /proc mount -t sysfs sysfs /sys mount -t usbfs none /proc/bus/usb mkdir /var/tmp mkdir /var/log mkdir /var/run mkdir /var/lock mkdir /var/empty ifconfig lo 127.0.0.1 route add -net 127.0.0.0 netmask 255.0.0.0 lo# dhcpcd -p -a eth0 & cat /etc/motd sleep 15 mount -t vfat /dev/sda1 /mnt[/b] --- Quote End --- Now,i hope that it mount usb automatic when usb disk be detected,how can i do?
- Altera_Forum
Honored Contributor
Check,
http://www.tldp.org/howto/flash-memory-howto/ (http://www.tldp.org/howto/flash-memory-howto/) but I didn't try it yet. - Altera_Forum
Honored Contributor
I wrote a little shell script to mount the USB stick, but I dont know if this is the best solution. I wanted to port autofs first but it was to heavyweight.
For the shell script I use /proc/partitions and /proc/mounts to automount. # !/bin/sh while true do grep sda /proc/partitions > /dev/zero if test $? -eq 0; then grep sda /proc/mounts > /dev/zero if test $? -eq 1; then echo "*** mount usbdisk ***" mount -n -t vfat /dev/sda /mnt/usb fi else grep sda /proc/mounts > /dev/zero if test $? -eq 0; then echo "*** unmount usbdisk ***" umount -n /mnt/usb fi fi sleep 1 done - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by nacide@Jun 8 2006, 03:03 AM i wrote a little shell script to mount the usb stick, but i dont know if this is the best solution. i wanted to port autofs first but it was to heavyweight.for the shell script i use /proc/partitions and /proc/mounts to automount.
# !/bin/sh
while true
do
grep sda /proc/partitions > /dev/zero
if test $? -eq 0; then
grep sda /proc/mounts > /dev/zero
if test $? -eq 1; then
echo "*** mount usbdisk ***"
mount -n -t vfat /dev/sda /mnt/usb
fi
else
grep sda /proc/mounts > /dev/zero
if test $? -eq 0; then
echo "*** unmount usbdisk ***"
umount -n /mnt/usb
fi
fi
sleep 1
done
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16023)
--- quote end ---
--- Quote End --- hi, Thank your reply. I did follow your reply,but it can't work. It show "Bad command or file name" for every command which your reply. Can anyone tell me where i take a mistake?
- Altera_Forum
Honored Contributor
hi,
Another question: How to run a shell script in my apps by execve() or other programmes? Thank you! - Altera_Forum
Honored Contributor
zhengkaike,
You need to have the commands that are called like mount, umount, grep, test, echo and sleep in your rootfs. Maybe it will also work with the busybox versions but I did not test this. I call the shellscript from the rc script in /etc for example automount.sh & - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by nacide@Jun 13 2006, 04:05 AM zhengkaike,you need to have the commands that are called like mount, umount, grep, test, echo and sleep in your rootfs.
maybe it will also work with the busybox versions but i did not test this.
i call the shellscript from the rc script in /etc
for example
automount.sh &
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16150)
--- quote end ---
--- Quote End --- Hi,nacide, Thank you! May be my busybox has some bugs,there are many errors when compiled. I have resolved the problem by using mount() and umount(), it can work successful although it's not a best method. The code: <div class='quotetop'>QUOTE </div> --- Quote Start --- char spe_file[20]="/dev/sda1"; char cur_dir[]="/mnt/usb"; char um_dir[]="/mnt"; char subum_dir[]="usb/"; int main(void) { if(mkdir(cur_dir,O_RDWR)==-1) { //"/mnt/usb"exsit if(umount(cur_dir)==-1) { printf("erro : umount usb!\n"); exit(1); } chdir(um_dir); if(rmdir(subum_dir)==-1) { printf("error rmdir %s \n",subum_dir); exit(1); } printf("umount usb ok!\n"); return 0; } if(mount(spe_file,cur_dir,"vfat",2,(char *)NULL)==-1) { printf("error :mount"); exit(1); } printf("mount usb ok!\n"); return 0; }[/b] --- Quote End --- Thank you for your reply again.