Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

problem with usb driver

Altera_Forum
Honored Contributor II
2,049 Views

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!

0 Kudos
17 Replies
Altera_Forum
Honored Contributor II
1,318 Views

TO_BE_DONE

0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

TO_BE_DONE

0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

Hi,hippo. 

I have solved the usb problem by enable fdisk in busybox. 

Now,I want to programme my apps by using the device driver,how can i do? 

Which files should i include? 

Thahk you! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- Quote Start ---  

originally posted by zhengkaike@Jun 4 2006, 10:02 PM 

 

hi,hippo. 

i have solved the usb problem by enable fdisk in busybox. 

now,i want to programme my apps by using the device driver,how can i do? 

which files should i include? 

thahk you!  http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/smile.gif  

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15884) 

--- quote end ---  

 

--- Quote End ---  

 

You can access the mounted usb disk as normal file. 

So just include stdio.h and stdlib.h should work.
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

Hi,hippo. 

Could you tell me how to hang a usb disk on my board automatic not by execute  

the "mount" command in nios2-termimal?  

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- Quote Start ---  

originally posted by zhengkaike@Jun 5 2006, 03:12 PM 

hi,hippo. 

  could you tell me how to hang a usb disk on my board automatic not by execute  

the "mount" command in nios2-termimal?   

  thank you! 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15901) 

--- quote end ---  

 

--- Quote End ---  

 

You can add the mount command or other initialization into vendors/Altera/nios2nommu/rc . 

it will be installed to romfs/etc/rc .
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- Quote Start ---  

originally posted by hippo+jun 5 2006, 02:28 am--><div class='quotetop'>quote (hippo @ jun 5 2006, 02:28 am)</div> 

--- quote start ---  

<!--quotebegin-zhengkaike@Jun 5 2006, 03:12 PM 

hi,hippo. 

  could you tell me how to hang a usb disk on my board automatic not by execute  

the "mount" command in nios2-termimal?   

  thank you! 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15901) 

--- quote end ---  

 

--- Quote End ---  

 

You can add the mount command or other initialization into vendors/Altera/nios2nommu/rc . 

it will be installed to romfs/etc/rc . 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15902)</div> 

[/b] 

--- Quote End ---  

 

 

Hi,hippo. 

I have added the mount command(#mount -t vfat /dev/sda1 /mnt)into vendors/Altera/nios2nommu/rc ,but it need to execute mount manual all the same,and there is nothing under the path of /mnt . 

please help me! 

thak you!
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

did you rebuild the kernel with, 

make 

make romfs 

make linux image ? 

 

What is your boot message now? 

 

May be you have to add busybox sleep, and wait several seconds for usb disk to be detected before mount usb. 

 

sleep 15 

mount -t vfat /dev/sda1 /mnt
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- Quote Start ---  

originally posted by hippo@Jun 5 2006, 05:32 AM 

did you rebuild the kernel with, 

make 

make romfs 

make linux image ? 

 

what is your boot message now? 

 

may be you have to add busybox sleep, and wait several seconds for usb disk to be detected before mount usb. 

 

sleep 15 

mount -t vfat /dev/sda1 /mnt 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15911) 

--- quote end ---  

 

--- Quote End ---  

 

 

Sorry,hippo. 

I can&#39;t solve the problem.  

The mount command always be executed before the usb disk be detected. 

my step: 

 

1. add the mount command into vendors/Altera/nios2nommu/rc . 

2. make menuconfig 

busybox-->[*]sleep 

3. make  

4. make romfs 

5. make linux image 

 

Is there any problem? 

Thank you.
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

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?
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- 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?
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- 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&#39;t work. 

It show "Bad command or file name" for every command which your reply. 

Can anyone tell me where i take a mistake?
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

hi, 

Another question: 

How to run a shell script in my apps by execve() or other programmes? 

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

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 &
0 Kudos
Altera_Forum
Honored Contributor II
1,318 Views

 

--- 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&#39;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.
0 Kudos
Reply