Files
SteamFrame-FPV-Control-Center/scripts/setup_radxa_usb_gadget.sh

125 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOTFS="${1:-/run/media/${USER:-bleack}/rootfs}"
if [ ! -d "${ROOTFS}/etc" ]; then
echo "Erreur : La partition rootfs n'est pas montée dans ${ROOTFS}"
echo "Usage : $0 [/chemin/vers/rootfs]"
exit 1
fi
echo "=== Configuration du mode USB Gadget (RNDIS / CDC) sur la Radxa Zero 3W (${ROOTFS}) ==="
# 1. Activer l'overlay device-tree rk3568-dwc3-peripheral
echo "[1/5] Activation de l'overlay DWC3 Peripheral mode..."
if [ -f "${ROOTFS}/boot/dtbo/rk3568-dwc3-peripheral.dtbo.disabled" ]; then
cp "${ROOTFS}/boot/dtbo/rk3568-dwc3-peripheral.dtbo.disabled" "${ROOTFS}/boot/dtbo/rk3568-dwc3-peripheral.dtbo"
fi
EXTLINUX="${ROOTFS}/boot/extlinux/extlinux.conf"
if [ -f "${EXTLINUX}" ] && ! 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 (1280x720@60e cohérent avec Ruby)
# et persister dans /etc/default/u-boot pour survivre à u-boot-update
echo "[1b/5] Forçage de la sortie HDMI virtuelle (headless 1280x720@60e)..."
HDMI_PARAMS="drm.edid_firmware=HDMI-A-1:edid/edid.bin video=HDMI-A-1:1280x720@60e"
if [ -f "${EXTLINUX}" ]; then
if ! grep -q "video=HDMI-A-1" "${EXTLINUX}"; then
sed -i "/append/ s|\$| ${HDMI_PARAMS}|" "${EXTLINUX}"
else
sed -i "s|video=HDMI-A-1:[^ ]*|video=HDMI-A-1:1280x720@60e|g" "${EXTLINUX}"
fi
fi
UBOOT_DEFAULT="${ROOTFS}/etc/default/u-boot"
if [ -f "${UBOOT_DEFAULT}" ]; then
if ! grep -q "video=HDMI-A-1" "${UBOOT_DEFAULT}"; then
sed -i "s|^U_BOOT_PARAMETERS=\"\\(.*\\)\"|U_BOOT_PARAMETERS=\"\\1 ${HDMI_PARAMS}\"|" "${UBOOT_DEFAULT}"
else
sed -i "s|video=HDMI-A-1:[^ \"]*|video=HDMI-A-1:1280x720@60e|g" "${UBOOT_DEFAULT}"
fi
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"
# 3b. Préparer la configuration DHCP légère sur usb0 (plug-and-play Android Tab S8 Ultra & SteamOS)
echo "[3b/5] Préparation de la config DHCP usb0 (sans passerelle ni DNS)..."
mkdir -p "${ROOTFS}/etc/dnsmasq.d"
cat << 'EOF' > "${ROOTFS}/etc/dnsmasq.d/steamframe-usb0.conf"
port=0
interface=usb0
bind-dynamic
dhcp-range=192.168.1.10,192.168.1.20,255.255.255.0,12h
dhcp-option=3
dhcp-option=6
dhcp-authoritative
dhcp-leasefile=/tmp/dnsmasq-usb0.leases
EOF
cat << 'EOF' > "${ROOTFS}/etc/systemd/system/steamframe-usb0-dhcp.service"
[Unit]
Description=SteamFrame FPV DHCP Server on usb0 (Android & SteamOS Plug-and-Play)
After=usb0-setup.service network.target
Wants=usb0-setup.service
[Service]
Type=simple
ExecStart=/usr/sbin/dnsmasq --keep-in-foreground --no-daemon --conf-file=/etc/dnsmasq.d/steamframe-usb0.conf
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
if [ -x "${ROOTFS}/usr/sbin/dnsmasq" ]; then
ln -sf /etc/systemd/system/steamframe-usb0-dhcp.service "${ROOTFS}/etc/systemd/system/multi-user.target.wants/steamframe-usb0-dhcp.service"
else
echo " -> Info : dnsmasq non présent sur l'image SD, lancez ./scripts/setup_radxa_dhcp_usb0.sh après le premier boot."
fi
# 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 !"