You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Tanushree Baindur <ta...@gmail.com> on 2021/06/06 06:01:37 UTC

Problem with running thttpd-nxflat in qemu - port forwarding from qemu to thttpd app running in it does not work.

Hi,

I am trying to run the thttpd web server example built using nxflat in
qemu.  Using the qemu-system-arm command I am able to run the generated
nuttx.bin. When I ran the curl command in another terminal, I noticed that
qemu does listen on the port but is not forwarding the port to nuttx.bin

I have attached the .config file (config.txt) that I am using.

These are the steps I used:

1. Modification to buildroot :
- Replaced toolchain/nxflat/ldnxflat.c with the patch provided in
https://github.com/apache/incubator-nuttx/issues/3737#issuecomment-846685364
- I then copied the configuration: configs/cortexm3-eabi-defconfig-7.4.0 to
.config and then built buildroot.

2. Modification in nuttx:
Added the mpic-data-is-text-relative flag to lm3s6965-ek/scripts/Make.defs.
To do this I replaced /nuttx/boards/arm/tiva/lm3s6965-ek/scripts/Make.defs
with the file in this link:
https://github.com/apache/incubator-nuttx/blob/fd80638f2c5b7673640fe11c9f86aafae64cdb1a/boards/arm/tiva/lm3s6965-ek/scripts/Make.defs

3. Build nuttx.bin
make
CROSSDEV=/home/tanushreebaindur/nuttx-code/buildroot/build_arm_nofpu/staging_dir/bin/arm-nuttx-eabi-
MKNXFLAT=/home/tanushreebaindur/nuttx-code/buildroot/build_arm_nofpu/staging_dir/bin/mknxflat
LDNXFLAT=/home/tanushreebaindur/nuttx-code/buildroot/build_arm_nofpu/staging_dir/bin/ldnxflat

4. Run in qemu:
qemu-system-arm -semihosting -M lm3s6965evb -netdev user,id=user0 -nic
user,id=user0 -serial mon:stdio -net user,hostfwd=tcp:127.0.0.1:9080-
10.0.0.2:80 -kernel nuttx.bin


Output when I run nuttx.bin in qemu:
tanushreebaindur@pop-os:~/nuttx-code/nuttx$qemu-system-arm -semihosting -M
lm3s6965evb -netdev user,id=user0 -nic user,id=user0 -serial mon:stdio -net
user,hostfwd=tcp:127.0.0.1:9080-10.0.0.2:80 -kernel nuttx.bin
qemu-system-arm: warning: hub 0 with no nics
ABCDF
Assigning MAC
netdev_ifr_ioctl: cmd: 1813
tcp_callback: flags: 0040
Setup network addresses
netdev_ifr_ioctl: cmd: 1794
tcp_callback: flags: 0040
netdev_ifr_ioctl: cmd: 1796
tcp_callback: flags: 0040
netdev_ifr_ioctl: cmd: 1800
tcp_callback: flags: 0040
netdev_ifr_ioctl: cmd: 1818
tiva_ifup: Bringing up: 10.0.0.2
tiva_ethreset: RCGC2: 50000021
tiva_ethreset: SRCR2: 00000000
tiva_ifup: MDV:   00000002
tiva_ifup: TCTL:  0000001e
tiva_ifup: RCTL:  00000010
tcp_callback: flags: 0040
Registering romdisk
Mounting ROMFS filesystem at target=/mnt/www with source=/dev/ram0
Starting THTTPD
thttpd_main: THTTPD started
fdwatch_dump: Initial state:
fdwatch_dump: nwatched: 0 nfds: 16
fdwatch_dump: nactive: 0 next: 0
thttpd_main: Calling httpd_initialize()
httpd_initialize: hostname: 10.0.0.2
initialize_listen_socket: Create listen socket
psock_vfcntl: sockfd=0x20006f30 cmd=2
psock_vfcntl: sockfd=0x20006f30 cmd=9
tcp_backlogcreate: conn=0x20002aec nblg=8
tcp_backlogdestroy: conn=0x20002aec
httpd_initialize: thttpd/2.25b 29dec2003-NuttX starting on port 80
fdwatch_add_fd: fd: 3 client_data: 0
fdwatch_dump: Before adding:
fdwatch_dump: nwatched: 0 nfds: 16
fdwatch_dump: nactive: 0 next: 0
fdwatch_dump: After adding:
fdwatch_dump: nwatched: 1 nfds: 16
fdwatch_dump:  1.pollfds: {fd: 3 events: 01 revents: 37} client: 0
fdwatch_dump: nactive: 0 next: 0
thttpd_main: Entering the main loop
fdwatch_dump: Before waiting:
fdwatch_dump: nwatched: 1 nfds: 16
fdwatch_dump:  1.pollfds: {fd: 3 events: 01 revents: 37} client: 0
fdwatch_dump: nactive: 0 next: 0
fdwatch: Waiting... (timeout 5000)
fdwatch: Awakened: 0
fdwatch: nactive: 0
fdwatch_dump: After wakeup:
fdwatch_dump: nwatched: 1 nfds: 16
fdwatch_dump:  1.pollfds: {fd: 3 events: 01 revents: 00} client: 0
fdwatch_dump: nactive: 0 next: 0
fdwatch_dump: Before waiting:
fdwatch_dump: nwatched: 1 nfds: 16
fdwatch_dump:  1.pollfds: {fd: 3 events: 01 revents: 00} client: 0
fdwatch_dump: nactive: 0 next: 0
fdwatch: Waiting... (timeout 4990)
<The last 11 lines from 'fdwatch: Awakened: 0' to 'fdwatch: Waiting...
(timeout 4990)' keep repeating>

With qemu still running, enter the following curl command in a new
terminal. The curl command fails:
tanushreebaindur@pop-os:~$ curl http://127.0.0.1:9080/index.html -v
*   Trying 127.0.0.1:9080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 9080 (#0)
> GET /index.html HTTP/1.1
> Host: 127.0.0.1:9080
> User-Agent: curl/7.68.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
tanushreebaindur@pop-os:~$


Before the curl command fails, running netstat shows that qemu is listening
on port 9080, but does not seem to be forwarding the port to nuttx.bin:
tanushreebaindur@pop-os:~$ netstat -a|grep 80
tcp        0      0 localhost:9080          0.0.0.0:*               LISTEN

tcp       88      0 localhost:9080          localhost:53168
ESTABLISHED
tcp        0      0 localhost:53168         localhost:9080
 ESTABLISHED

On looking through the code I saw that the poll function (line 281 in
apps/netutils/thttpd/fdwatch.c) times while waiting for the file descriptor
to become ready.

Can you let me know what I am doing wrong?

Thank you,
Tanushree