From 14481a293995ad3d353fcbd220f5f923d9fd64dd Mon Sep 17 00:00:00 2001 From: Gabriel Lima Date: Sat, 4 Apr 2026 01:01:44 -0300 Subject: [PATCH] rtl8821cu mdev rule for automatic usb modeswitch --- board/raspberrypi/device_table.txt | 7 ++++++- .../{post_build.sh => post-build.sh} | 17 +++-------------- .../lib/mdev/rtl8821cu_usb_modeswitch.sh | 3 +++ configs/raspberrypi_common_defconfig | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) rename board/raspberrypi/{post_build.sh => post-build.sh} (62%) create mode 100644 board/raspberrypi/rootfs-overlay/lib/mdev/rtl8821cu_usb_modeswitch.sh diff --git a/board/raspberrypi/device_table.txt b/board/raspberrypi/device_table.txt index b3872be..348d4b6 100644 --- a/board/raspberrypi/device_table.txt +++ b/board/raspberrypi/device_table.txt @@ -1,4 +1,9 @@ # + +# ssh keys /etc/ssh/ssh_host_ecdsa_key f 600 0 0 - - - - - /etc/ssh/ssh_host_ed25519_key f 600 0 0 - - - - - -/etc/ssh/ssh_host_rsa_key f 600 0 0 - - - - - \ No newline at end of file +/etc/ssh/ssh_host_rsa_key f 600 0 0 - - - - - + +#rtl8821cu usb modeswitch script +/lib/mdev/rtl8821cu_usb_modeswitch.sh f 755 0 0 - - - - - \ No newline at end of file diff --git a/board/raspberrypi/post_build.sh b/board/raspberrypi/post-build.sh similarity index 62% rename from board/raspberrypi/post_build.sh rename to board/raspberrypi/post-build.sh index 50f5f23..a8eb8e6 100755 --- a/board/raspberrypi/post_build.sh +++ b/board/raspberrypi/post-build.sh @@ -18,17 +18,6 @@ # - Installing packages (use rootfs overlay or a package .mk instead) # - Modifying files outside $1 -set -e - -TARGET_DIR="$1" - -# Example: ensure /etc/hostname exists with a default value -if [ ! -f "${TARGET_DIR}/etc/hostname" ]; then - echo "rpi-common" > "${TARGET_DIR}/etc/hostname" -fi - -# Example: remove unnecessary documentation to save space -rm -rf "${TARGET_DIR}/usr/share/man" -rm -rf "${TARGET_DIR}/usr/share/doc" - -echo ">>> Common post-build script completed" +# Add usb_modeswitch mdev rule +grep -q "usb_modeswitch" "$TARGET_DIR/etc/mdev.conf" || \ + echo '$PRODUCT=bda/1a2b.* root:root 0660 */lib/mdev/rtl8821cu_usb_modeswitch.sh' >> "$TARGET_DIR/etc/mdev.conf" diff --git a/board/raspberrypi/rootfs-overlay/lib/mdev/rtl8821cu_usb_modeswitch.sh b/board/raspberrypi/rootfs-overlay/lib/mdev/rtl8821cu_usb_modeswitch.sh new file mode 100644 index 0000000..50932bd --- /dev/null +++ b/board/raspberrypi/rootfs-overlay/lib/mdev/rtl8821cu_usb_modeswitch.sh @@ -0,0 +1,3 @@ +#!/bin/sh +[ "$ACTION" = "add" ] || exit 0 +usb_modeswitch -v 0bda -p 1a2b -c /usr/share/usb_modeswitch/0bda:1a2b & \ No newline at end of file diff --git a/configs/raspberrypi_common_defconfig b/configs/raspberrypi_common_defconfig index 2bcdc0e..f4497b7 100644 --- a/configs/raspberrypi_common_defconfig +++ b/configs/raspberrypi_common_defconfig @@ -11,7 +11,7 @@ BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y BR2_ROOTFS_DEVICE_TABLE="system/device_table.txt $(BR2_EXTERNAL_RPI_COMMON_PATH)/board/raspberrypi/device_table.txt" BR2_SYSTEM_DHCP="eth0" BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_RPI_COMMON_PATH)/board/raspberrypi/rootfs-overlay" -BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi/post-build.sh" +BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi/post-build.sh $(BR2_EXTERNAL_RPI_COMMON_PATH)/board/raspberrypi/post-build.sh" BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_RPI_COMMON_PATH)/board/raspberrypi/post-image.sh" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y