Files
daedalus-v4l2/kernel/Makefile
T
marfrit 895f57c63a Phase 8.2: kernel ↔ daemon chardev bridge with round-trip test
Adds /dev/daedalus-v4l2 misc chardev to the kernel module. The
chardev is the IPC channel for the future userspace decoder
daemon: kernel enqueues REQ_* messages, daemon read()s them,
processes, write()s RESP_* back.

Wire protocol (pre-1.0, header in include/daedalus_v4l2_proto.h):
- struct daedalus_msg_hdr: magic (D04V) + version + type +
  cookie + payload_len + reserved
- Request/response separated by high bit of type field
- Max 64 KiB payload per message
- Cookie correlates request with matching response

Kernel implementation (kernel/daedalus_v4l2_chardev.{c,h}):
- Single-instance chardev (-EBUSY on second open)
- In-kernel FIFO bounded at 64 messages
- Blocking + non-blocking read; poll() with EPOLLIN on queued
- write() parses + validates header, logs response at pr_debug
- Bad magic → -EBADMSG, bad version → -EPROTO, oversize → -EMSGSIZE
- All error paths free resources

Phase 8.2 test trigger via debugfs:
- /sys/kernel/debug/daedalus_v4l2/test_ping — any byte
  enqueues a PING with a fixed 24-byte payload. Removed in
  Phase 8.4 when real REQ_DECODE from V4L2 path takes over.

Userspace verification tool (tools/test_chardev_pingpong.c):
- Real C program, proper error reporting via strerror
- Validates the 6-step round-trip: open → empty-queue EAGAIN →
  trigger ping → read PING → verify all fields → write PONG → close
- Builds with -Wall -Wextra clean

Verification on hertz (Pi 5, 6.12.75+rpt-rpi-2712):
  $ sudo insmod daedalus_v4l2.ko
  $ sudo tools/test_chardev_pingpong
  opening /dev/daedalus-v4l2...
    non-blocking read on empty queue: EAGAIN ✓
    injected PING via debugfs ✓
    read PING: magic ✓ version ✓ type=PING ✓ cookie=0x1234 ✓ payload=24 bytes
      payload: "DAEDALUS-V4L2-PING-PL"
    wrote PONG (cookie=0x1234) ✓
  ALL TESTS PASSED.
  $ sudo rmmod daedalus_v4l2      # clean

Per correctness-before-speed: full kerneldoc on structs, 8-tab
kernel style, SPDX headers, proper error paths, real test
program (not "I ran it once"), failure-mode coverage documented.

Phase 8.3 next: userspace daemon with dlopen'd FFmpeg parse path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 15:05:54 +00:00

48 lines
1.3 KiB
Makefile

# SPDX-License-Identifier: GPL-2.0-or-later
#
# daedalus-v4l2 — out-of-tree kbuild for the Linux kernel V4L2
# stateless decoder shim. Forwards bitstream + controls to the
# daedalus-v4l2 userspace daemon via a chardev bridge.
#
# Build against the running kernel:
# make
# Or against a specific kernel:
# make KERNELDIR=/path/to/kernel/source
# Install (requires root):
# sudo make install
# Clean:
# make clean
obj-m := daedalus_v4l2.o
daedalus_v4l2-objs := daedalus_v4l2_main.o daedalus_v4l2_chardev.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
# Be strict: warnings are errors, kernel coding style enforced.
# include/ is for the shared kernel↔daemon wire protocol header.
ccflags-y := -Wall -Wextra -Wno-unused-parameter -I$(src)/../include
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
install: all
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
depmod -a
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
# Run kernel checkpatch.pl against the source. Picks up the
# kernel-tree-installed checkpatch via the running kernel's
# build directory if present.
checkpatch:
@if [ -x $(KERNELDIR)/scripts/checkpatch.pl ]; then \
$(KERNELDIR)/scripts/checkpatch.pl --no-tree --strict -f *.c; \
else \
echo "checkpatch.pl not available at $(KERNELDIR)/scripts/"; \
exit 1; \
fi
.PHONY: all install clean checkpatch