Linux Host & Hypervisor Bridges, USB Passthrough & udev Rules
Embedded Linux bring-up stalls before compilation ever starts when a hypervisor NAT layer drops inbound TFTP packets, a Wi-Fi bridge strips guest MAC frames, or USB re-enumeration resets serial console permissions to root-only defaults.
What you'll learn
- Configure a dual-NIC hypervisor topology separating NAT internet access from a wired Layer-2 bench bridge.
- Diagnose why Wi-Fi 802.11 client stations reject spoofed guest MAC frames and why NAT blocks unsolicited board TFTP requests.
- Author deterministic udev rules for CH340 USB-UART consoles (1a86:7523) and i.MX6ULL SDP Boot ROM recovery devices (15a2:0080).
Why Embedded Benches Break Inside Default Virtual Machine Settings
Desktop software engineers rarely notice whether their Linux virtual machine sits behind hypervisor Network Address Translation (NAT), because outbound TCP connections to Git servers originate from inside the guest. Embedded board bring-up reverses the connection direction. On power-on, U-Boot broadcasts an ARP request on the bench cable and sends an unsolicited UDP/69 TFTP read request toward the Linux workstation to fetch zImage and the Device Tree blob. Behind NAT, the guest owns a private address invisible to the physical Ethernet port, so every frame from the board vanishes at the host interface.
Switching the single virtual adapter to automatic Bridged mode creates a subtle trap on laptops. Hypervisors set to Auto-bridging frequently bind to the host Wi-Fi adapter, where standard 802.11 client frames carry only three MAC address fields and access points silently drop packets whose source MAC differs from the authenticated laptop radio. At the same time, plugging in a CH340 (1a86:7523) USB-serial cable or resetting an i.MX6ULL board into Serial Download Protocol (0x15a2:0x0080) creates a fresh /dev node owned by root:root (0600) or root:dialout (0660), breaking unprivileged tools whenever a engineer relies on manual sudo or temporary chmod workarounds.
Figure 1.1a. Hardware EPT paging plus isolated NAT (WAN) and wired L2 Bridge (bench) paths eliminate MAC drops and USB re-enumeration permission loss.
mental model: Think of a hypervisor network and USB layer like a laboratory building's mailroom and badge desk: NAT acts like an outbound corporate mailroom where staff can mail letters out, yet couriers arriving from the hardware lab bench with no employee extension number are turned away at the lobby. A dedicated wired Bridge opens a direct loading-dock bay straight into the bench subnet, while udev acts as permanent badge-provisioning rules keyed to a device's manufacturer serial (idVendor:idProduct) rather than a visitor sticker (chmod) that falls off every time the device walks out and re-enters.
Where it stops working: Unlike physical doors, 802.11 Wi-Fi station interfaces enforce strict MAC-address framing at the radio link layer, and Linux udev evaluates keys across a hierarchy of parent sysfs kobjects where mixing ATTR and ATTRS from two distinct parent levels fails to match.
definition (Extended Page Tables (EPT) and Netlink uevent): Extended Page Tables (EPT on Intel VT-x, Rapid Virtualization Indexing on AMD-V) add a second hardware MMU translation stage mapping guest-physical addresses (gPA) to host-physical RAM (hPA), allowing KVM or VMware guests to compile the Linux kernel without trapping on guest page-table updates. When a USB device enumerates inside the guest, the Linux kernel emits a AF_NETLINK (NETLINK_KOBJECT_UEVENT) message to user-space systemd-udevd, which evaluates /etc/udev/rules.d/*.rules in lexical order before exposing the /dev character node.
- Step 1. Verify hardware virtualization flags and assign two distinct virtual NICs: NAT for internet and a wired-only Bridge for the target board.
- Step 2. Query sysfs attributes on the enumerated serial or Boot ROM device to extract exact hexadecimal idVendor and idProduct strings.
- Step 3. Write /etc/udev/rules.d/99-embedded-bench.rules separating boolean match keys (==) from mode, group, and symlink mutations (= / +=).
- Step 4. Reload the systemd-udevd rule cache, replay kernel uevents, and confirm non-root group access without unplugging the cable.
Figure 1.1b. Separate NAT WAN from wired L2 bridges and bind USB permissions via udev == matchers.
Inside KVM/VMware L2 Bridging and udev Operator Semantics
At the CPU and memory boundary, a Type-1/2 hypervisor (KVM/QEMU or VMware Workstation) executes guest Ring-0 Linux kernel instructions and Ring-3 compiler processes directly on physical cores using VT-x non-root operation. Whenever a gcc worker faults a new heap page, the hardware page-table walker traverses the 4-level guest CR3 hierarchy and resolves each intermediate guest physical address through the host EPT root pointer (EPTP), keeping parallel make -j$(nproc) builds within a few percent of bare-metal throughput.
At the I/O boundary, udev rule syntax is unforgiving because C-like operators carry distinct state-machine meanings. == and != are pure predicates (SUBSYSTEM=="tty"), whereas = overwrites a property (MODE="0660"), += appends to a list (SYMLINK+="ttyBENCH0"), and := locks a value against later rules (99-*.rules). Writing a single = on ATTR{idVendor} attempts an invalid attribute write instead of filtering, causing the rule either to fail or to match unintended devices! Furthermore, users added via usermod -aG dialout,plugdev $USER must start a fresh login session because supplementary GID arrays are inherited at login setgroups(2) time, not re-read dynamically by running shells.
Figure 1.1b. Exact operator distinction (== predicate vs = / += assignment) prevents silent wildcard matches and world-writable 0666 hazards.
| VM Network Mode | Host WAN / apt | Board -> Host TFTP/NFS | Engineering Verdict |
|---|---|---|---|
Single NIC (NAT) | Works via host SNAT | Blocked (board cannot address private NAT subnet) | Unsuitable for U-Boot TFTP or NFS rootfs |
Single NIC (Auto-Bridge) | Depends on LAN DHCP | Fails silently when hypervisor binds host 802.11 Wi-Fi | Fragile on laptops; breaks offline bench work |
Host-Only (vmnet1) | No WAN route | Guest-to-Host only; never reaches physical RJ45 port | Good for QEMU virtual boards, useless for real silicon |
Dual NIC (NAT + Pinned Wired Bridge) | Always online via eth0 | Direct L2 ARP / UDP / TCP over dedicated USB-LAN | Production gold standard for embedded bring-up |
learner@ksa:~/gl-e00/m01-l01$ bat -H 3 -H 7 99-embedded-bench.rules File: 99-embedded-bench.rules # /etc/udev/rules.d/99-embedded-bench.rules # 1. USB-UART serial console (CH340 1a86:7523 & CP2102 10c4:ea60) -> /dev/ttyBENCH0 SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE="0660", GROUP="dialout", SYMLINK+="ttyBENCH0" SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE="0660", GROUP="dialout", SYMLINK+="ttyBENCH0" # 2. i.MX6ULL Boot ROM USB OTG Serial Download Protocol (SDP HID 15a2:0080) for UUU SUBSYSTEM=="usb", ATTR{idVendor}=="15a2", ATTR{idProduct}=="0080", MODE="0660", GROUP="plugdev", TAG+="uaccess"- Double-equals (==) predicates filter tty nodes strictly by parent USB VID:PID before = and += mutate node metadata.
- Boot ROM SDP recovery exposes raw USB interface 15a2:0080 (not a tty), so SUBSYSTEM=='usb' and GROUP='plugdev' govern UUU access.
udev(7) GL-E00 Quick Reference udev(7) NAME udev, udevadm - Linux kernel dynamic device management and rule verifier SYNOPSIS udevadm info -a -n /dev/ttyUSB0 sudo udevadm control --reload-rules && sudo udevadm trigger udevadm test $(udevadm info -q path -n /dev/ttyUSB0) OPERATORS == Compare key for equality (predicate; MUST be used on SUBSYSTEM/ATTR/ATTRS). != Compare key for inequality. = Assign value to key (MODE="0660", GROUP="dialout"), overwriting prior rules. += Append value to multi-string key (SYMLINK+="ttyBENCH0", TAG+="uaccess"). ERRORS & SECURITY Using = instead of == on idVendor turns a predicate into an attribute write fault. Avoid MODE="0666": world-writable USB/serial nodes let any local UID hijack U-Boot. Kernel Systems Academy Lesson 1.1 udev(7) GL-E00 quick reference · full manual page: man 7 udev Auditing VM Bridge Selection and udev Rules in Host C11
Before deploying workstation onboarding scripts across an engineering team, we can validate both hypervisor adapter bindings and /etc/udev/rules.d/ rule files deterministically in ISO C11. Our host verifier verify.c inspects candidate VM NIC topologies—confirming that a NAT WAN interface is paired with a wired 802.3 Ethernet bridge rather than an 802.11 Wi-Fi station—and parses raw udev clauses token by token.
Pay close attention to how audit_udev_line() distinguishes == match predicates from = assignments and parses the octal MODE string. It explicitly rejects single-= typos on SUBSYSTEM, ATTR, or ATTRS, requires 4-character hexadecimal idVendor/idProduct identifiers, and blocks world-writable (mode & 0002) permissions (0666). While this host program proves configuration invariants in user space, verifying physical xhci_hcd USB signal integrity and U-Boot serial framing still requires attaching the target board.
learner@ksa:~/gl-e00/m01-l01$ bat -H 37 -H 53 verify.c File: verify.c #define _POSIX_C_SOURCE 200809L #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { const char *name; int has_nat_wan; int has_wired_bridge; int bridges_wifi; } vm_net_cfg_t; static int verify_vm_topology(const vm_net_cfg_t *cfg) { if (!cfg->has_nat_wan) return -1; /* No outbound WAN for apt/git */ if (cfg->bridges_wifi) return -2; /* 802.11 station drops guest MAC */ if (!cfg->has_wired_bridge) return -3; /* Board L2 ARP/TFTP unreachable */ return 0; } static int is_hex4(const char *s) { if (strlen(s) != 4) return 0; for (int i = 0; i < 4; ++i) { if (!isxdigit((unsigned char)s[i])) return 0; } return 1; } static int audit_udev_line(const char *line, unsigned int *mode_out) { char buf[256]; snprintf(buf, sizeof(buf), "%s", line); int has_subsys = 0, has_vid = 0, has_pid = 0, has_grp = 0, has_mode = 0; *mode_out = 0; char *save = NULL; for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) { while (*tok == ' ' || *tok == '\t') tok++; int is_eq2 = (strstr(tok, "==") != NULL); if (strncmp(tok, "SUBSYSTEM", 9) == 0 || strncmp(tok, "ATTR", 4) == 0) { if (!is_eq2) return -10; /* Fatal: single '=' on match key */ } const char *q1 = strchr(tok, '"'); const char *q2 = q1 ? strchr(q1 + 1, '"') : NULL; if (!q1 || !q2 || (size_t)(q2 - q1 - 1) >= 32) return -11; char val[32]; memcpy(val, q1 + 1, (size_t)(q2 - q1 - 1)); val[q2 - q1 - 1] = '\0'; if (strncmp(tok, "SUBSYSTEM==", 11) == 0) has_subsys = 1; else if (strstr(tok, "{idVendor}==")) has_vid = is_hex4(val); else if (strstr(tok, "{idProduct}==")) has_pid = is_hex4(val); else if (strncmp(tok, "GROUP=", 6) == 0 && tok[6] == '"') has_grp = (val[0] != '\0'); else if (strncmp(tok, "MODE=", 5) == 0 && tok[5] == '"') { char *end = NULL; unsigned long m = strtoul(val, &end, 8); if (*end != '\0' || (m & 0002UL) != 0) return -12; /* Reject world-writable */ *mode_out = (unsigned int)m; has_mode = 1; } } return (has_subsys && has_vid && has_pid && has_grp && has_mode) ? 0 : -13; } int main(void) { vm_net_cfg_t bad_vm = {"auto-wifi-bridge", 0, 0, 1}; vm_net_cfg_t good_vm = {"nat+usb-eth-bridge", 1, 1, 0}; const char *good_uart = "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"1a86\", ATTRS{idProduct}==\"7523\", " "MODE=\"0660\", GROUP=\"dialout\", SYMLINK+=\"ttyBENCH0\""; const char *bad_op = "SUBSYSTEM==\"usb\", ATTR{idVendor}=\"15a2\", ATTR{idProduct}==\"0080\", " "MODE=\"0660\", GROUP=\"plugdev\""; const char *bad_mode = "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"1a86\", ATTRS{idProduct}==\"7523\", " "MODE=\"0666\", GROUP=\"dialout\""; unsigned int m_good = 0, m_bad1 = 0, m_bad2 = 0; int r_vm_bad = verify_vm_topology(&bad_vm); int r_vm_ok = verify_vm_topology(&good_vm); int r_u_ok = audit_udev_line(good_uart, &m_good); int r_u_op = audit_udev_line(bad_op, &m_bad1); int r_u_md = audit_udev_line(bad_mode, &m_bad2); printf("vm_check: auto_wifi=%d dual_nic_wired=%d\n", r_vm_bad, r_vm_ok); printf("udev_check: ch340_0660=%d (mode=0%03o) single_eq=%d mode_0666=%d\n", r_u_ok, m_good, r_u_op, r_u_md); return (r_vm_bad == -1 && r_vm_ok == 0 && r_u_ok == 0 && r_u_op == -10 && r_u_md == -12) ? 0 : 1; }- Rejects single '=' on SUBSYSTEM/ATTR/ATTRS keys before a silent assignment bug ever reaches /etc/udev/rules.d/.
- Parses MODE in base-8 and rejects any rule setting the world-writable o+w bit (0002, such as 0666).
Verifying Rule Diagnostics and System Call Output
Compile verify.c under strict -std=c11 -Wall -Wextra -Werror and inspect both stdout and the strace syscall stream. Notice how audit_udev_line() accepts the 1a86:7523 0660 dialout rule (rc = 0), immediately flags the single-= typo on ATTR{idVendor}="15a2" with -10, and blocks the world-writable MODE="0666" rule with -12. In strace, glibc buffers the two formatted diagnostic lines into a single write(1, ...) syscall when stdout is non-interactive, terminating cleanly with exit_group(0).
learner@ksa:~/gl-e00/m01-l01gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m01-l01./verifyvm_check: auto_wifi=-1 dual_nic_wired=0udev_check: ch340_0660=0 (mode=0660) single_eq=-10 mode_0666=-12learner@ksa:~/gl-e00/m01-l01learner@ksa:~/gl-e00/m01-l01strace -e trace=write,exit_group ./verifywrite(1, "vm_check: auto_wifi=-1 dual_nic_"..., 105) = 105exit_group(0) = ?+++ exited with 0 +++Common Virtualization & USB Hotplug Failure Modes
A reliable embedded Linux workstation separates network planes and eliminates manual root interventions on device nodes. Keep Adapter 1 on NAT so package updates work on any network, pin Adapter 2 strictly to the physical USB-Ethernet controller wired to your target board, and manage both serial consoles (1a86:7523) and Boot ROM SDP interfaces (15a2:0080) through version-controlled /etc/udev/rules.d/ files.
Mixing ATTRS Parent Walks Across Unrelated sysfs Ancestors:
- Symptom:
udevadm testreports zero matching rules even though bothATTRS{idVendor}and an interface-levelATTRS{bInterfaceNumber}exist inudevadm info -a. - Root Cause:
systemd-udevdrequires allATTRS{...}predicates within a single rule to match on the same parentsysfsdevice node rather than cherry-picking attributes from two different ancestor levels. - Fix: Match
SUBSYSTEM=="tty"at the leaf node and keepATTRS{idVendor}plusATTRS{idProduct}on the singleusb-serialorusb_deviceparent, or useENV{ID_VENDOR_ID}=="1a86"populated byusb_id.
Running Terminal Emulators or Flashing Tools Under sudo:
- Symptom: After running
sudo minicom -sorsudo uuu, subsequent non-root runs fail to save configuration files or build artifacts in$HOMEwithPermission denied. - Root Cause: Invoking interactive tools under
sudopreserves$HOMEon many distributions while running asUID 0, creating root-owned dotfiles (~/.minirc.dfl) and masking missingdialout/plugdevgroup membership. - Fix: Fix
/etc/udev/rules.d/permissions to0660withGROUP="dialout"orGROUP="plugdev", add your user viasudo usermod -aG dialout,plugdev $USER, re-login soid -Gnshows the new groups, and chown any root-owned$HOMEfiles back.
Guided Practice
Extend verify.c to parse an optional SYMLINK+="ttyBENCH0" token and reject rules that use SYMLINK="ttyBENCH0" (overwrite =) instead of SYMLINK+="ttyBENCH0" (append +=). Why does overwriting SYMLINK with = break systemd persistent paths such as /dev/serial/by-id/... created by earlier 60-serial.rules?
Independent Practice
Write a two-rule udev snippet and matching C11 unit test for a dual-channel FT2232H (0403:6010) JTAG + UART debug probe where interface 00 (ENV{ID_USB_INTERFACE_NUM}=="00") is bound to GROUP="plugdev" for OpenOCD JTAG and interface 01 creates SYMLINK+="ttyJTAG_UART" under GROUP="dialout", verifying zero world-writable bits.
Verification Checks
Key takeaways
- Hardware virtualization pairs VT-x or AMD-V guest execution modes with Extended Page Tables (EPT) so guest virtual-to-host-physical translations resolve in silicon without per-fault hypervisor traps.
- A dual-adapter VM layout uses Adapter 1 in NAT mode for outbound WAN package traffic and Adapter 2 bridged exclusively to a wired USB-Ethernet bench NIC for L2 ARP, TFTP, and NFS traffic.
- Declarative /etc/udev/rules.d/ rules match SUBSYSTEM and hexadecimal idVendor/idProduct attributes with == to assign 0660 dialout or plugdev group ownership across every USB hotplug cycle.
- USB Boot ROM recovery tools re-enumerate target silicon from SDP HID mode (15a2:0080) into Fastboot endpoints, requiring persistent udev rules and hypervisor vendor-ID filters instead of one-shot chmod 666 hacks.