#!/usr/bin/env bash set -euo pipefail ROOTFS="/run/media/bleack/rootfs" if [ ! -d "${ROOTFS}/etc" ]; then echo "Erreur : La partition rootfs n'est pas montée dans ${ROOTFS}" exit 1 fi echo "=== Configuration du mode USB Gadget (RNDIS / CDC) sur la Radxa Zero 3W ===" # 1. Activer l'overlay device-tree rk3568-dwc3-peripheral echo "[1/4] Activation de l'overlay DWC3 Peripheral mode..." cp "${ROOTFS}/boot/dtbo/rk3568-dwc3-peripheral.dtbo.disabled" "${ROOTFS}/boot/dtbo/rk3568-dwc3-peripheral.dtbo" EXTLINUX="${ROOTFS}/boot/extlinux/extlinux.conf" if ! grep -q "rk3568-dwc3-peripheral.dtbo" "${EXTLINUX}"; then sed -i '/fdtdir/a \ fdtoverlays /boot/dtbo/rk3568-dwc3-peripheral.dtbo' "${EXTLINUX}" fi # 1b. Forcer l'activation de la sortie HDMI en mode headless (sans écran physique) echo "[1b/5] Forçage de la sortie HDMI virtuelle (headless) dans extlinux.conf..." if ! grep -q "video=HDMI-A-1" "${EXTLINUX}"; then sed -i '/append/ s/$/ video=HDMI-A-1:1920x1080@60e/' "${EXTLINUX}" fi # 2. Charger le module g_cdc au boot echo "[2/5] Ajout du module g_cdc dans /etc/modules..." if ! grep -q "g_cdc" "${ROOTFS}/etc/modules"; then echo "g_cdc" >> "${ROOTFS}/etc/modules" fi # 3. Configurer l'IP statique 192.168.1.1 sur usb0 echo "[3/5] Configuration réseau de usb0 (192.168.1.1/24)..." cat << 'EOF' > "${ROOTFS}/etc/network/interfaces.d/usb0" auto usb0 allow-hotplug usb0 iface usb0 inet static address 192.168.1.1 netmask 255.255.255.0 EOF cat << 'EOF' > "${ROOTFS}/etc/systemd/system/usb0-setup.service" [Unit] Description=SteamFrame FPV USB0 IP Setup After=network.target [Service] Type=oneshot ExecStart=/bin/sh -c 'sleep 2; ip link set usb0 up && ip addr add 192.168.1.1/24 dev usb0 || true' RemainAfterExit=yes [Install] WantedBy=multi-user.target EOF mkdir -p "${ROOTFS}/etc/systemd/system/multi-user.target.wants" ln -sf /etc/systemd/system/usb0-setup.service "${ROOTFS}/etc/systemd/system/multi-user.target.wants/usb0-setup.service" # 4. Ajuster le port vidéo dans controller_settings.cfg vers 5600 echo "[4/5] Configuration du port vidéo Ruby vers 5600..." if [ -f "${ROOTFS}/home/radxa/ruby/config/controller_settings.cfg" ]; then sed -i 's/video_usb: 1 [0-9]\+ 1024/video_usb: 1 5600 1024/g' "${ROOTFS}/home/radxa/ruby/config/controller_settings.cfg" fi echo "[5/5] Synchronisation des fichiers..." sync echo "[+] Configuration terminée avec succès !"