For applications that need a user configuration file in order to execute, this file update may involve a complex procedure (ftp, telnet, Unix commands, ...) that is not accessible to a "simple user", ... or a customer.
Those lines decribe what I did to answer the question of target files update, using boa and the library "cgihtml".
The version of cgihtml that is available in the uClinux-dist at this time is outdated. I have submitted the patch to upgrade it: please, check if your distribution resume writers is up to date. If not, I recommend you apply the patch below.
To summarize, if the version number that can be found in user/cgihtml/CHANGES is greater or equal to 1.69, all is ok.
Otherwise, do the following:
git apply --verbose 0001-user-cgithml-update-1.66-1.69.patch
Then, the library can be compiled with:
make user/cgihtml_only
This will produce the file user/cgihtml/cgihtml.a to be linked with your application.
This simple HTML page example shows how a single FORM permits to upload a file, and then to call the CGI-Program which will proceed the file.
<HTML> <HEAD><TITLE>A test web page</TITLE></HEAD> <BODY> <H1>Test Page</H1> <P>If you are seeing this custom writing page, then your web server is working, and now you need to create some nice pages to replace this one :-).<P><H1>SW Upload</H1> <FORM ACTION="/cgi-bin/mycgipgm" METHOD=POST ENCTYPE="multipart/form-data"> <INPUT TYPE=file name="swimage" /> <BR /> <INPUT TYPE=submit VALUE="Submit"> <INPUT TYPE=reset VALUE="Reset"> </FORM></BODY> </HTML>
This CGI-Program example is very minimal, because it just displays the upload result.
Note that after its execution, the uploaded file remains in UPLOADDIR (see the "romfs update" section below). It is up to the program to remove the file after processing (stored in flash for e.g.).
#include <stdio.h> #include <cgi-lib.h> #include <html-lib.h>int main() { llist entries; char *value;html_header(); if (read_cgi_input(&entries) <= 0 || (value = cgi_val(entries, "swimage")) == 0) h1("<BR />Error: failed to read \"swimage\" CGI input...<BR />\n"); else { printf("<BR><H1>File \"%s\" successfully uploaded!</H1>\n", value); if (strcmp(value, "zImage") == 0) { h1("OK, that is a zImage: need to store it in flash...<BR />\n"); } } list_clear(&entries);h2("Back to the <A HREF=/>main menu</A>...\n"); html_end();return 0; }
Here is the application's Makefile I'm using.
I think that explanations on how to add an application to the distribution can be found somewhere in the Wikis, but this works as a standalone project...
UCLINUX_DIST=/local/nios2-linux/uClinux-dist-ndk LIB_CGIHTML=$(UCLINUX_DIST)/user/cgihtmlCC=nios2-linux-uclibc-gcc CFLAGS= -I$(SRC_DIR) -I. -I$(LIB_CGIHTML) \ -O2 -g -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED \ -fno-builtin -D__adjtimex=adjtimex LDFLAGS= -Wl,-d -Wl,-elf2flt $(LIB_CGIHTML)/cgihtml.amycgipgm: mycgipgm.o $(CC) -o $@ $< $(LDFLAGS)install: mycgipgm cp mycgipgm $(UCLINUX_DIST)/vendors/Altera/nios2clean: rm -f mycgipgm mycgipgm.o
To include all your changes into your zImage, you must follow these steps:
Warning: if "generic cgi" is selected in make menuconfig / Customize Appl/Lib Settings / Miscellanous Configuration, the files index.html and boa.conf will be overrided by the files in vendors/Generic/httpd.$(ROMFSINST) /home/httpd/cgi-bin/mycgipgm # for your CGI-Programs $(ROMFSINST) /home/httpd/index.html # for your HTML pages $(ROMFSINST) /home/httpd/boa.conf # for boa configuration
chmod 777 $(ROMFSINST)/usr/tmpto the file vendors/Altera/nios2/Makefile.
OK, time for you to play with HTML and CGI-Programs: have fun!
PS: thanks to Endre who gave me the initial pointers...
| File | Size | Date | Attached by | |||
|---|---|---|---|---|---|---|
| 0001-user-cgihtml-update-1.66-1.69.patch No description | 21.2 kB | 01:50, 8 Dec 2008 | Admin | Actions | ||