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++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

BOA CGI problem hasn't been fixed

Altera_Forum
Honored Contributor II
2,822 Views

This days i try to complete the CGI function in the uClinux BOA of my 1s10 board,but no results. 

And wanna achieve the ledcontrol (http://www.niosforum.com/forum/index.php?act=st&f=18&t=2185) via the cgi function on boa. 

I have tried different ways.  

>1:index.html //add to home/httpd folder.  

follow what KEN's method, change "POST" to "GET":  

<html> <head> <title>CGI script test</title> </head> <body> <form method="get" action="http://202.112.147.82/cgi-bin/test.cgi"> <input type="submit" value="ok"> </form> </body> </html> 

>2:creat test.cgi //add to home/httpd/cgi-bin folder. 

one way: 

## cgi-bin/test.cgi# # ! /bin/sh echo "Content-type: text/html\n\n" echo echo "The cgi script is working\n" 

another way://Compile to test.exe,then add test.exe to home/httpd/cgi-bin folder.  

#include <stdio.h> void main(void) { printf("content-type: text/html\n"); printf("\n"); printf("the cgi script is working\n); exit(0); } 

 

Unfortunately,error in IE browser: the page cannot be displayed,server inner error... 

Also i browsered the concerning topic, just like the TOPIC:"How to use boa?" by sunclever. 

No result to find,even i follow the same way, but no success. 

 

Any help would be greatly appreciated! 

Thank you very much! 

Best regards! 

Justin
0 Kudos
12 Replies
Altera_Forum
Honored Contributor II
1,310 Views

If you were trying to use the shell script that I posted, there may be an error in it. 

 

I inadvertently added some comments before the "#! /bin/sh" and I think that may affect whether or not Linux will run the script through the shell interpreter or treat it as a full blown executable. 

 

The correct script should be: 

 

#! /bin/sh # # cgi-bin/test.cgi# echo "Content-type: text/html\n\n" echo echo "The cgi script is working\n"
0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

Hi Ken: 

 

I have tried again,using the correct code below: 

#! /bin/sh # # cgi-bin/test.cgi# echo "Content-type: text/html\n\n" echo echo "The cgi script is working\n" 

However, when i click the "ok" button in the index.html,no page to find, 

the ie address is: http://202.112.147.82/cgi-bin/test.cgi (http://202.112.147.82/cgi-bin/test.cgi)? 

 

I really don&#39;t know where the problem is, and why not use this below code 

#include <stdio.h> void main(void) { printf("content-type: text/html\n"); printf("\n"); printf("the cgi script is working\n); exit(0); } 

 

BOA in the distribution doesn&#39;t support this? 

 

Thank you again~! 

Best Regards! 

Justin
0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

I&#39;m using scripts because it reduces my debug time if I do everything on Nios II Linux. So, I&#39;ve gone into the boa.conf file and I&#39;ve moved my document root from /home/httpd to /var/www and I use "busybox vi" to make a new index.html and test.cgi each time I try these tests. 

 

Things to watch out for: 

(1) Your CGI script must end with a .cgi suffix... i.e. test.cgi... or foo.cgi... or bar.cgi... 

(2) If you&#39;re compiling a C program to be your CGI script, then you should compile it to foo.cgi.exe... This will be renamed to foo.cgi and it will be given execute permissions when the filesystem is built. 

(3) Finally, the CGI script *must* have execute permissions... try executing your script from the commandline. If it doesn&#39;t *exactly* spit out: 

 

Content-type: text/htmlnn The cgi script is workingn 

 

Then there&#39;s something wrong with the script itself. 

 

I really have no idea why you&#39;re getting those server errors. I&#39;m assuming that ip address you&#39;ve listed in the IP address for your Nios II Linux Board. I tried the same thing except with my own IP address (10.1.1.125) and it found the test.cgi file without a problem. 

 

Can you show me what is exactly in your document root directory (recursively)?
0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

I&#39;m also having trouble getting CGI to work. 

 

I am using the Altera 1C20 board. I&#39;ve created a kernel and file system following the quickstart guide. 

 

I&#39;ve added my html files to the httpd directory. 

 

 

 

<html> 

<head> 

<title>CGI script test</title> 

</head> 

<body> 

<form method="get" action="http://202.112.147.82/cgi-bin/test.cgi"> 

<input type="submit" value="ok"> 

</form> 

</body> 

</html> 

 

Inserting my own IP address... 

 

 

Added a subdirectory /cgi-bin/ 

Added the "ScriptAlias /home/httpd/cgi-bin/ /cgi-bin/" to the boa.conf file. 

 

Then I created the script: 

# ! /bin/sh 

# # cgi-bin/test.cgi#  

 

echo "Content-type: text/html\n\n" 

echo 

 

echo "The cgi script is working\n" 

 

I saved the script as test.cgi.exe in my filesystem /home/httpd/cgi-bin 

Which when uploaded changed to test.cgi. 

 

I bring up the server, and get the page that has the "OK" button which should kick off the script. I press the button and get a "500 Server Error" back. 

 

Any clue as to what I&#39;m forgetting? 

 

Thanks, 

Scott
0 Kudos
Altera_Forum
Honored Contributor II
1,309 Views

I&#39;m wondering if the script might have been saved with dos linefeeds... That would prevent the script from starting properly which would in turn could cause a 500 error (if I remember my error codes correctly). 

 

Can you confirm that?
0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

I created the script using the NIOS II IDE, so I assume that it doesn&#39;t have DOS LF&#39;s inserted. I saved the file as "test.cgi.exe" 

 

Is there a quick way to verify that there are no special characters thrown in? 

 

Thanks, 

Scott
0 Kudos
Altera_Forum
Honored Contributor II
1,309 Views

> Is there a quick way to verify that there are no special characters thrown in? 

 

You can just run dos2unix ... it&#39;ll make sure everything is converted: 

 

$ dos2unix test.cgi.exe 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
1,309 Views

dumping the DOS LF&#39;s didn&#39;t help with the error. Any other thoughts?

0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

Are you able to run the script using from the commandline?

0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

nope. It can&#39;t recognize echo. Any idea why the script wouldn&#39;t work?

0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

Hi schaney, 

 

> nope. It can&#39;t recognize echo. Any idea why the script wouldn&#39;t work? 

 

This sounds weird ... I ran the following script without any problems:#!/bin/sh echo "Content-type:text/html\n\n" echo "The cgi script is working\n" Here are a few things to check: 

 

1. Try the following command: 

 

$ echo $PATH 

 

If this doesn&#39;t work ... you&#39;re probably missing &#39;echo&#39;. 

 

2. Check your PATH environment 

 

If the PATH env var doesn&#39;t include the directory where echo actually is, you&#39;ll either need to add the 

full path to your script, or setup PATH in your /etc/rc file. Or from the command line: 

 

$ export PATH=$PATH:<path to echo> 

 

Then try running the script again. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
1,310 Views

That would be the problem. I didn&#39;t have the sh utilities built into the filesystem. 

 

Thanks, 

Scott
0 Kudos
Reply