From 0814fc837f0f2b0c7b3c5aa968d1e31c279a200c Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 21 Jun 2021 12:03:26 +0200 Subject: [PATCH] add fsdata webdir --- Makefile | 2 +- README.md | 1 - firmware/.gitignore | 3 +- firmware/Makefile | 4 +- firmware/fsdata/fs/404.html | 22 +++++++ firmware/fsdata/makefsdata | 114 ++++++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 firmware/fsdata/fs/404.html create mode 100755 firmware/fsdata/makefsdata diff --git a/Makefile b/Makefile index 00690fc..2257790 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ all: firmware case pcb firmware: - +@make -C firmware all + +@make -C firmware html all clean: +@make -C firmware clean diff --git a/README.md b/README.md index e05b0ad..def2d29 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,3 @@ install `docker` on your platform and buil with ```bash make firmware_docker -j$(nproc) -``` diff --git a/firmware/.gitignore b/firmware/.gitignore index 9ac0926..a9bcf3d 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -142,4 +142,5 @@ dkms.conf *.remove firmware/ -compile_commands.json \ No newline at end of file +compile_commands.json +fsdata/fsdata.c diff --git a/firmware/Makefile b/firmware/Makefile index 8006a40..c2ff9b8 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -5,7 +5,7 @@ EXTRA_CFLAGS=-O3 #Enable debugging #EXTRA_CFLAGS+=-DLWIP_DEBUG=1 -DHTTPD_DEBUG=LWIP_DBG_ON -EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/mbedtls extras/sntp extras/cpp_support +EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/mbedtls extras/httpd extras/sntp extras/cpp_support LIBS = hal m @@ -24,3 +24,5 @@ unittest: systest: true + +.NOTPARALLEL: html all \ No newline at end of file diff --git a/firmware/fsdata/fs/404.html b/firmware/fsdata/fs/404.html new file mode 100644 index 0000000..da81a20 --- /dev/null +++ b/firmware/fsdata/fs/404.html @@ -0,0 +1,22 @@ + + + + + + + HTTP Server + + + + +
+

404 - Page not found

+
Sorry, the page you are requesting was not found on this server.
+
+ + + diff --git a/firmware/fsdata/makefsdata b/firmware/fsdata/makefsdata new file mode 100755 index 0000000..5361370 --- /dev/null +++ b/firmware/fsdata/makefsdata @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +$incHttpHeader = 1; + +open(OUTPUT, "> fsdata.c"); +print(OUTPUT "#include \"httpd/fsdata.h\"\n\n"); + +chdir("fs"); +open(FILES, "find . -type f |"); + +while($file = ) { + + # Do not include files in CVS directories nor backup files. + if($file =~ /(CVS|~)/) { + next; + } + + chop($file); + + if($incHttpHeader == 1) { + open(HEADER, "> /tmp/header") || die $!; + if($file =~ /404/) { + print(HEADER "HTTP/1.0 404 File not found\r\n"); + } else { + print(HEADER "HTTP/1.0 200 OK\r\n"); + } + print(HEADER "lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n"); + if($file =~ /\.html$/ || $file =~ /\.htm$/ || $file =~ /\.shtml$/ || $file =~ /\.shtm$/ || $file =~ /\.ssi$/) { + print(HEADER "Content-type: text/html\r\n"); + } elsif($file =~ /\.js$/) { + print(HEADER "Content-type: application/x-javascript\r\n\r\n"); + } elsif($file =~ /\.css$/) { + print(HEADER "Content-type: text/css\r\n\r\n"); + } elsif($file =~ /\.ico$/) { + print(HEADER "Content-type: image/x-icon\r\n\r\n"); + } elsif($file =~ /\.gif$/) { + print(HEADER "Content-type: image/gif\r\n"); + } elsif($file =~ /\.png$/) { + print(HEADER "Content-type: image/png\r\n"); + } elsif($file =~ /\.jpg$/) { + print(HEADER "Content-type: image/jpeg\r\n"); + } elsif($file =~ /\.bmp$/) { + print(HEADER "Content-type: image/bmp\r\n\r\n"); + } elsif($file =~ /\.class$/) { + print(HEADER "Content-type: application/octet-stream\r\n"); + } elsif($file =~ /\.ram$/) { + print(HEADER "Content-type: audio/x-pn-realaudio\r\n"); + } else { + print(HEADER "Content-type: text/plain\r\n"); + } + print(HEADER "\r\n"); + close(HEADER); + + unless($file =~ /\.plain$/ || $file =~ /cgi/) { + system("cat /tmp/header $file > /tmp/file"); + } else { + system("cp $file /tmp/file"); + } + } else { + system("cp $file /tmp/file"); + } + + open(FILE, "/tmp/file"); + unlink("/tmp/file"); + unlink("/tmp/header"); + + $file =~ s/\.//; + $fvar = $file; + $fvar =~ s-/-_-g; + $fvar =~ s-\.-_-g; + + print(OUTPUT "static const unsigned char data".$fvar."[] = {\n"); + print(OUTPUT "\t/* $file */\n\t"); + for($j = 0; $j < length($file); $j++) { + printf(OUTPUT "0x%02X, ", unpack("C", substr($file, $j, 1))); + } + printf(OUTPUT "0,\n"); + + + $i = 0; + while(read(FILE, $data, 1)) { + if($i == 0) { + print(OUTPUT "\t"); + } + printf(OUTPUT "0x%02X, ", unpack("C", $data)); + $i++; + if($i == 10) { + print(OUTPUT "\n"); + $i = 0; + } + } + print(OUTPUT "};\n\n"); + close(FILE); + push(@fvars, $fvar); + push(@files, $file); +} + +for($i = 0; $i < @fvars; $i++) { + $file = $files[$i]; + $fvar = $fvars[$i]; + + if($i == 0) { + $prevfile = "NULL"; + } else { + $prevfile = "file" . $fvars[$i - 1]; + } + print(OUTPUT "const struct fsdata_file file".$fvar."[] = {{\n$prevfile,\ndata$fvar, "); + print(OUTPUT "data$fvar + ". (length($file) + 1) .",\n"); + print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) .",\n"); + print(OUTPUT $incHttpHeader."\n}};\n\n"); +} + +print(OUTPUT "#define FS_ROOT file$fvars[$i - 1]\n\n"); +print(OUTPUT "#define FS_NUMFILES $i\n");