Skip to content

Commit 5508df7

Browse files
authored
Merge pull request #494 from tock/dev/lwip-ethernet-tap-example
Add LwIP Ethernet example using tap network driver
2 parents 04ce654 + 9f0fc3c commit 5508df7

File tree

10 files changed

+631
-0
lines changed

10 files changed

+631
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
[submodule "RadioLib/RadioLib"]
1111
path = RadioLib/RadioLib
1212
url = https://github.com/jgromes/RadioLib.git
13+
[submodule "lwip/lwip"]
14+
path = lwip/lwip
15+
# Using GitHub mirror, as git.savannah.gnu.org seems to cause
16+
# problems with `git submodule sync`
17+
#url = https://git.savannah.gnu.org/git/lwip.git
18+
url = https://github.com/lwip-tcpip/lwip.git
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Makefile for LwIP TAP network example application
2+
3+
# The default application stack and heap size allocations are not
4+
# nearly sufficient for LwIP. While smaller limits may well work,
5+
# these have been tested to work *shrug*.
6+
STACK_SIZE=32768
7+
APP_HEAP_SIZE=32768
8+
9+
# Specify this directory relative to the current application.
10+
TOCK_USERLAND_BASE_DIR = ../..
11+
12+
# Which files to compile.
13+
C_SRCS := $(wildcard *.c)
14+
15+
# External libraries used
16+
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/lwip
17+
18+
# Include userland master makefile. Contains rules and flags for actually
19+
# building the application.
20+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# LwIP Tap Ethernet Example
2+
3+
This example demonstrates running a webserver using LwIP, using an Ethernet MAC
4+
exposed through the [`ethernet_tap`][ethernet-tap-capsule] kernel capsule
5+
driver.
6+
7+
## Running with the QEMU RISC-V 32 bit board
8+
9+
You can run this app with the QEMU RISC-V 32 bit `virt` board. This board has
10+
support for QEMU's VirtIO network device, and can use a userspace network stack
11+
to forward a local host-port to the LwIP network stack running in this
12+
application.
13+
14+
First, build this application:
15+
16+
```
17+
libtock-c/examples/lwip_ethernet_tap $ make
18+
CC main.c
19+
LD build/rv32imac/rv32imac.0x80100080.0x80210000.elf
20+
E2T build/lwip_ethernet_tap.tab
21+
Application size report for arch family rv32i:
22+
text data bss dec hex filename
23+
71256 104 48976 120336 1d610 build/rv32imac/rv32imac.0x80100080.0x80210000.elf
24+
```
25+
26+
Then, in the kernel run the QEMU board with this application:
27+
```
28+
tock/boards/qemu_rv32_virt $ make run-app \
29+
APP=$LIBTOCK_C/examples/lwip_ethernet_tap/build/rv32imac/rv32imac.0x80100080.0x80210000.tbf \
30+
NETDEV=SLIRP NETDEV_SLIRP_ARGS='hostfwd=tcp::8081-192.168.1.50:80'
31+
Finished `release` profile [optimized + debuginfo] target(s) in 0.10s
32+
text data bss dec hex filename
33+
89088 48 41908 131044 1ffe4 $TOCK/target/riscv32imac-unknown-none-elf/release/qemu_rv32_virt
34+
35+
Running QEMU emulator version 9.1.3 (tested: 7.2.0) with
36+
- kernel $TOCK/kernel/target/riscv32imac-unknown-none-elf/release/qemu_rv32_virt.elf
37+
- app $LIBTOCK_C/examples/lwip_ethernet_tap/build/rv32imac/rv32imac.0x80100080.0x80210000.tbf
38+
To exit type C-a x
39+
40+
qemu-system-riscv32 \
41+
-machine virt \
42+
-semihosting \
43+
-global driver=riscv-cpu,property=smepmp,value=true \
44+
-global virtio-mmio.force-legacy=false \
45+
-device virtio-rng-device \
46+
-netdev user,id=n0,net=192.168.1.0/24,dhcpstart=192.168.1.255,hostfwd=tcp::8081-192.168.1.50:80 \
47+
-device virtio-net-device,netdev=n0 \
48+
-nographic \
49+
-bios $TOCK/target/riscv32imac-unknown-none-elf/release/qemu_rv32_virt.elf \
50+
-device loader,file=$LIBTOCK_C/examples/lwip_ethernet_tap/build/rv32imac/rv32imac.0x80100080.0x80210000.tbf,addr=0x80100000
51+
QEMU RISC-V 32-bit "virt" machine, initialization complete.
52+
- Found VirtIO EntropySource device, enabling RngDriver
53+
- Found VirtIO NetworkCard device, enabling EthernetTapDriver
54+
Entering main loop.
55+
-> userspace tap network app
56+
-> tapif_init: success
57+
-> tapif_status: 192.168.1.50
58+
-> tap interface t0 added
59+
tock$
60+
```
61+
62+
Following this, you should be able to navigate to `http://127.0.0.1:8081` and
63+
see LwIP's default web page.
64+
65+
[ethernet-tap-capsule]: https://github.com/tock/tock/blob/master/capsules/extra/src/ethernet_tap.rs
66+
[qemu-rv32-board]: https://github.com/tock/tock/tree/master/boards/qemu_rv32_virt

0 commit comments

Comments
 (0)