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