Showing results for 
Search instead for 
Did you mean: 
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Uploading files using boa and cgihtml

Uploading files using boa and cgihtml

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".

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 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.

Example of HTML page

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.


<HEAD><TITLE>A test web page</TITLE></HEAD>


<H1>Test Page</H1>

<P>If you are seeing this 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">




CGI-Program example

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;


 if (read_cgi_input(&entries) <= 0 ||

     (value = cgi_val(entries, "swimage")) == 0)

   h1("<BR />Error: failed to read \"swimage\" CGI input...<BR />\n");



   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");




 h2("Back to the <A HREF=/>main menu</A>...\n");


 return 0;


Application's Makefile example

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...





       -O2 -g -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED \

       -fno-builtin -D__adjtimex=adjtimex

LDFLAGS= -Wl,-d -Wl,-elf2flt $(LIB_CGIHTML)/cgihtml.a

mycgipgm: mycgipgm.o

       $(CC) -o $@ $< $(LDFLAGS)

install:       mycgipgm

       cp mycgipgm $(UCLINUX_DIST)/vendors/Altera/nios2


       rm -f mycgipgm mycgipgm.o

To include all your changes into your zImage, you must follow these steps:

  • copy your HTML file(s) and your CGI-Program(s) into the dir vendors/Altera/nios2, and add the related lines in vendors/Altera/nios2/Makefile.

$(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

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.

You can obviously modify, but to get all my customizations located in the single vendors/Altera/nios2 directory, I have prefered to unselect this item.

  • because UPLOADDIR is defined to "/usr/tmp" in user/cgihtml/Makefile, the files you will upload will be stored there. You have thus to add usr/tmp to the ROMFS_DIR list, and the line

chmod 777 $(ROMFSINST)/usr/tmp

to 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.

Version history
Last update:
‎06-26-2019 02:20 AM
Updated by: