Forum

v9.13 startup freeze on OpenWrt 10.03.1, custom crossbuild

Tomas Kolousek
21 May 2015, 13:18
Hiawatha version: 9.13
Operating System: Openwrt 10.03.1 on Asus WL-500w, custom crossbuild using the openwrt toolchain, 2.4 kernel for broadcom 47xx mips CPU.

Hello Hugo.
I'm lost in my tries for compiling and running the Hiawatha on my embedded system. Maybe you can point me a bit further what's wrong on my side.

I succesfully compiled the webserver using the toolchain using:

cmake -DCMAKE_TOOLCHAIN_FILE=../mipsel-openwrt-linux-uclibc.cmake -DENABLE_SSL=off -DENABLE_CACH
E=off -DENABLE_IPV6=off -DENABLE_RPROXY=off -DENABLE_XSLT=off -DCMAKE_INSTALL_PREFIX= -DENABLE_DEBUG=on -DWORK_DIR=/tmp ..

in my cmake config I have:

SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR mipsel)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER mipsel-openwrt-linux-uclibc-gcc)
SET(CMAKE_CXX_COMPILER mipsel-openwrt-linux-uclibx-g++)
SET(CMAKE_FIND_ROOT_PATH /tmp/openwrt-toolchain)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

But when I upload the binary to the box, I can start it, in detached mode I see "Press Ctrl+C to shutdown the server" and that's all - nothing is served at all.
The trace logs can be downloaded from http://web.spscv.cz/~kolousek/hiawatha/ - I noticed lot of old_mmap calls with invalid file descriptor, but didn't investigate it further.

Additionally in log.c gzip conditionals according to https://www.hiawatha-webserver.org/forum/topic/1660 was included, as originally I got exactly the same problem during linking in hiawatha, altough binary libz.so and header files zlib.h was present in toolchain.

I hope you'll have a tip for me, as I really want the up to date version of hiawatha on my system and currently running out of ideas what else can be checked.

Have a nice day

Tomas
Hugo Leisink
21 May 2015, 18:13
I have no experience with or knowledge about cross-platform compilation. So, I can't help you with this.
Tomas Kolousek
21 May 2015, 19:52
Okay, no problem. I'll try it again and in case of sucess I'll leave a note in form of small mini howto for others.
Tomas Kolousek
24 May 2015, 00:38
Hello Hugo.
I'm back again with good news and mini howto about crosscompile under openwrt toolchain:

1. D*ownload and extract toolchain for your target platform. This includes basic gcc, linker including minimal set of libraries (uclibc, crypt etc). I'll use OpenWrt Barrier Breaker 10.03.1 toolchain, extracted in /tmp/openwrt-toolchain, compiler used is mipsel-openwrt-linux-uclibc-gcc.
If you use this toolchain, please note that toolchain script usr/bin/mipsel-openwrt-linux-uclibc-wrapper.sh has a bug inside, GCC_SYSROOT_FLAGS content needs to start with "-Wl,", in toolchain -Wl is somewhere further in contente which prevents it from correct work.
2. Add toolchain binary directories (/bin, /usr/bin etc) to your build host PATH variable. Any standard Linux system can be used as build host. I used Tiny Core Linux with minimal packages, just for building. This includes gcc (not generally necessary), make, cmake etc.
3. Do*wnload and extract hiawatha sources - I used /tmp/hiawatha
4. Make build directory and cd to it (as build instructions of hiawatha says).
5. For building using cross compiler, create configuration file of cmake (my is mipsel-openwrt-linux-uclibc.cmake) with this content:
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR brcm47xx)
SET(CMAKE_SYSTEM_VERSION 1)
# compiler binary names
SET(CMAKE_C_COMPILER mipsel-openwrt-linux-uclibc-gcc)
SET(CMAKE_CXX_COMPILER mipsel-openwrt-linux-uclibx-g++)
# toolchain root directory
SET(CMAKE_FIND_ROOT_PATH /tmp/openwrt-toolchain)
# target location for compiled binaries install to prevent mixing with build host system
SET(CMAKE_STAGING_PREFIX /tmp/openwrt-toolchain)
# search for programs, libraries and includes in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

- for more details see cmake documentation
6. configure hiawatha using cmake:
cmake -DCMAKE_TOOLCHAIN_FILE=../mipsel-openwrt-linux-uclibc.cmake -DENABLE_CACHE=off -DENABLE_IPV6=off -DENABLE_RPROXY=off -DENABLE_XSLT=off -DCMAKE_INSTALL_PREFIX= .. 

options for hiawatha configuration according to needs, for example TLS can be ommited etc ...
7. You'll probably encounter problems with missing zlib.h header files and zlib.so library in toolchain library folder. You can fix it by downloading the header file and binary from the openwrt repository. The zlib.so binary can be aither downloaded from your server (it's necessary to have it there for running hiawatha binary later), or you can extract the coresponding zlib package and find the library there. The header should be put in toolchain directory under
usr/include
directory, the library in
usr/lib
under toolchain.
8. After sucesfull configuration, make the binary using
make
command
9. You can use either
make install
to include the compiled binaries in your toolchain and copy them from there, or you can manually take all the necesarry binaries (at least hiawatha binary) and copy them to your target system (using eg. scp) or make a openwrt package and install them using opkg tool

I encountered problem arounf 86% of build during hiawatha linking: [quite]Implicit definition of gzdopen() ... undefined reference to gzdopen, gzwrite ... [/quite]. It seems to me that zlib binary in default build is somewhow stripped down with some code ommited in favour of size. This can be fixed by custom build of zlib library by downloading its sources (at least in version according the one used in openwrt build):
1. Download the sources, extract them somewhere (/tmp/zlib) and cd to it
2. Run configure WITHOUT selecting toolchain compiler (some issue with shared library compilation):
./configure --shared

3. Now open generated makefile of zlib and replace all occurences of gcc compiler with the toolchain one (mipsel-openwrt-linux-uclibc-gcc)
4. Run make, check if toolchain compiler was used.
5. After compilation, zlib.so should be present in the zlib sources directory. Grab them and put it in
usr/lib
folder of your toolchain, ang header files zlib.h and zconf.h put in
usr/include
. Then run cmake (see above) again, everything should be fine then.

After fresh build of hiawatha I noticed that it simply doesn't woth and freezes, so in detached mode Ctrl+C doesn't work. The interface port was bought altough. I tracked this down to challenge module initialization. It seems that at least my router doesn't have anough entropy for
/dev/random
to generate the server secret. You can fix this by using /dev/urandom (yes, not recommended generally, but this is the only solution in that case I think) in
get_random()
function in source
challenge.c
.

I wish you good luck with your cross compilations and sorry in case that this post isn't perfectly formated

Tomas
This topic has been closed.