This series adds an httpd command which receives a file uploaded from a
web browser into memory. It is meant for recovering a device, typically
a router, without a serial console or a TFTP server on the host.
Downstream forks, such as the MediaTek SDK "failsafe" web UI and its
derivatives, implement this with their own TCP stack and HTTP server.

An httpd on top of the legacy stack was proposed in 2024 [1]. Its TCP
fixes were merged, the server was not; one reviewer suggested the httpd
bundled with lwIP if a server is needed at all [2]. This series builds
lib/lwip httpd.c; the command parses no HTTP itself and implements the
lwIP POST and custom file callbacks.

Patch 1 adds httpd_deinit() to the bundled lwIP, as was done with
httpc_abort() for wget: with the shared lwIP runtime a listener left
behind would accept connections while another client polls. The series
is based on next.

The command only stores the upload and sets $fileaddr, $filesize and
$httpd_target. What to do with a target is left to the environment:

  => setenv httpd_targets "initramfs bl2"
  => setenv httpd_do_initramfs 'bootm $fileaddr'
  => httpd && run httpd_do_$httpd_target

It follows the structure and test of tftpsrv. The size cost is about
11 KiB on qemu_arm64_lwip_defconfig.

Tested on qemu_arm64_lwip with curl and headless Chrome: uploads of 3
and 20 MiB with CRC check, unknown targets, multipart bodies, concurrent
uploads, uploads overlapping reserved memory, interrupted uploads,
repeated runs and Ctrl-C. After the command returns, port 80 refuses
connections while tftpsrv polls. test_net_httpd passes with a 5 MiB
file.

A revision before the move to the shared runtime was also tested on an
Airoha AN7583 board (Nokia XG-040G-MF), on v2026.07 with the OpenWrt
patches for that board and the lwIP chained pbuf transmit fix: 20 MiB
were uploaded in 1.4 s with a matching CRC, and an OpenWrt initramfs
uploaded from a browser was booted by httpd_do_initramfs. The command
adds 11 KiB to u-boot.bin there.

On QEMU's e1000, lwIP wget runs at about 3 KB/s and a 5 MiB httpd
upload does not finish within 60 s. The cause is in the e1000 driver; a
fix is posted separately [3].

[1] 
https://lore.kernel.org/u-boot/[email protected]/
[2] 
https://lore.kernel.org/u-boot/calede9ps9hua1+ahzdka+wtxg0phb_0e7j8rjja8ky5eqn2...@mail.gmail.com/
[3] 
https://lore.kernel.org/u-boot/[email protected]/

Vitaliy Sochnev (4):
  net: lwip: add an httpd stop operation
  net: lwip: add httpd command
  doc: usage: cmd: add httpd
  test: py: net: add httpd test

 cmd/Kconfig                                 |  11 +
 cmd/lwip/Makefile                           |   1 +
 cmd/lwip/httpd.c                            |  12 +
 configs/qemu_arm64_lwip_defconfig           |   1 +
 configs/sandbox64_lwip_defconfig            |   1 +
 doc/usage/cmd/httpd.rst                     |  92 +++++
 include/net-lwip.h                          |   1 +
 lib/lwip/Makefile                           |   9 +
 lib/lwip/lwip/src/apps/http/httpd.c         |  51 ++-
 lib/lwip/lwip/src/include/lwip/apps/httpd.h |   1 +
 lib/lwip/u-boot/fsdata_uboot.h              |   8 +
 lib/lwip/u-boot/lwipopts.h                  |  14 +
 net/lwip/Makefile                           |   1 +
 net/lwip/httpd.c                            | 373 ++++++++++++++++++++
 test/py/tests/test_net.py                   |  95 +++++
 15 files changed, 669 insertions(+), 2 deletions(-)
 create mode 100644 cmd/lwip/httpd.c
 create mode 100644 doc/usage/cmd/httpd.rst
 create mode 100644 lib/lwip/u-boot/fsdata_uboot.h
 create mode 100644 net/lwip/httpd.c


base-commit: 2b8902913c19eb581fb0d567201c09b8fa46ac74
-- 
2.55.0

Reply via email to