-
-
Couldn't load subscription status.
- Fork 2.7k
config: boards: pocketbeagle2: Enable better USB Gadget #8382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,13 +10,55 @@ TIBOOT3_FILE="tiboot3-am62x-hs-fs-evm.bin" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_CONSOLE="serial" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| KERNEL_TARGET="edge" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| KERNEL_TEST_TARGET="edge" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SERIALCON="ttyS2,ttyGS0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SERIALCON="ttyS2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ATF_BOARD="lite" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SRC_EXTLINUX="yes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SRC_CMDLINE="root=/dev/mmcblk1p2 rootwait console=ttyS2,115200n8 console=ttyGS0,115200n8 modules-load=dwc2,g_cdc" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SRC_CMDLINE="root=/dev/mmcblk1p2 rootwait console=ttyS2,115200n8" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BOOT_FDT_FILE="ti/k3-am6232-pocketbeagle2.dtb" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OPTEE_PLATFORM="k3-am62x" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # USB Gadget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function post_family_tweaks_bsp__pocketbeagle2_firmware() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming, based on our discussion, that you won't do this here, but instead make this into a package? This just seems wrong. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Setup USB Gadget for ${BOARD}" "${RELEASE}" "warn" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # USB Gadget Network service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $destination/usr/local/bin/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any distro-installed software should be in /usr/local. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $destination/usr/lib/systemd/system/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $destination/etc/initramfs-tools/scripts/init-bottom/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The service expects the name setup-usbgadget-network.sh. Depending on the board vendor, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # usbgadget configuration they would like can be wildly different. However, the same service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # will work fine for almost all cases. So better to rename file rather than modifying the service. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/setup-usbgadget-network-multi.sh $destination/usr/local/bin/setup-usbgadget-network.sh || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget setup script" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/remove-usbgadget-network.sh $destination/usr/local/bin/ || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /usr/local is just wrong in a distro-installed component. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget remove script" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm744 $SRC/packages/bsp/usb-gadget-network/usbgadget-rndis.service $destination/usr/lib/systemd/system/ || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget service" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-hook $destination/etc/initramfs-tools/hooks/usb-gadget || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget initramfs hook" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-premount $destination/etc/initramfs-tools/scripts/init-premount/usb-gadget || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget initramfs premount script" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/dropbear $destination/etc/initramfs-tools/scripts/init-premount/ || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget initramfs premount dropbear" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 $SRC/packages/bsp/usb-gadget-network/kill-dropbear $destination/etc/initramfs-tools/scripts/init-bottom/ || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Failed to install USB gadget initramfs premount kill dropbear" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix unit file mode (0644) and quote paths to harden installs
Apply: - mkdir -p $destination/usr/local/bin/
- mkdir -p $destination/usr/lib/systemd/system/
- mkdir -p $destination/etc/initramfs-tools/scripts/init-bottom/
+ mkdir -p "$destination/usr/local/bin"
+ mkdir -p "$destination/usr/lib/systemd/system"
+ mkdir -p "$destination/etc/initramfs-tools/scripts/init-bottom"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/setup-usbgadget-network-multi.sh $destination/usr/local/bin/setup-usbgadget-network.sh ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/setup-usbgadget-network-multi.sh" "$destination/usr/local/bin/setup-usbgadget-network.sh" ||
exit_with_error "Failed to install USB gadget setup script"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/remove-usbgadget-network.sh $destination/usr/local/bin/ ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/remove-usbgadget-network.sh" "$destination/usr/local/bin/" ||
exit_with_error "Failed to install USB gadget remove script"
- install -Dm744 $SRC/packages/bsp/usb-gadget-network/usbgadget-rndis.service $destination/usr/lib/systemd/system/ ||
+ install -Dm644 "$SRC/packages/bsp/usb-gadget-network/usbgadget-rndis.service" "$destination/usr/lib/systemd/system/" ||
exit_with_error "Failed to install USB gadget service"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-hook $destination/etc/initramfs-tools/hooks/usb-gadget ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-hook" "$destination/etc/initramfs-tools/hooks/usb-gadget" ||
exit_with_error "Failed to install USB gadget initramfs hook"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-premount $destination/etc/initramfs-tools/scripts/init-premount/usb-gadget ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/usb-gadget-initramfs-premount" "$destination/etc/initramfs-tools/scripts/init-premount/usb-gadget" ||
exit_with_error "Failed to install USB gadget initramfs premount script"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/dropbear $destination/etc/initramfs-tools/scripts/init-premount/ ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/dropbear" "$destination/etc/initramfs-tools/scripts/init-premount/" ||
exit_with_error "Failed to install USB gadget initramfs premount dropbear"
- install -Dm755 $SRC/packages/bsp/usb-gadget-network/kill-dropbear $destination/etc/initramfs-tools/scripts/init-bottom/ ||
+ install -Dm755 "$SRC/packages/bsp/usb-gadget-network/kill-dropbear" "$destination/etc/initramfs-tools/scripts/init-bottom/" ||
exit_with_error "Failed to install USB gadget initramfs premount kill dropbear"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function post_family_tweaks__pocketbeagle2_enable_services() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Enable Services for ${BOARD}" "${RELEASE}" "warn" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # We need unudhcpd from armbian repo, so enable it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mv "${SDCARD}"/etc/apt/sources.list.d/armbian.sources.disabled "${SDCARD}"/etc/apt/sources.list.d/armbian.sources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels wrong. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do_with_retries 3 chroot_sdcard_apt_get_install unudhcpd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # disable armbian repo back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mv "${SDCARD}"/etc/apt/sources.list.d/armbian.sources "${SDCARD}"/etc/apt/sources.list.d/armbian.sources.disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Odd. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard systemctl enable usbgadget-rndis.service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like it should be in a package postinst. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # We want custom IPs. systemctl edit does not seem to work in chroot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${SDCARD}"/etc/systemd/system/usbgadget-rndis.service.d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo -e "[Service]\nEnvironment=\"unudhcpd_host_ip=192.168.7.2\"\nEnvironment=\"unudhcpd_client_ip=192.168.7.3\"" > "${SDCARD}"/etc/systemd/system/usbgadget-rndis.service.d/override.conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like it should be in a package install. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function current_beagle_kernel_uboot() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare -g KERNELSOURCE="https://github.com/beagleboard/linux" # BeagleBoard kernel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare -g KERNEL_MAJOR_MINOR="6.12" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to put this in a package outside the BSP. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deviceinfo_name="USB Gadget Network" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deviceinfo_manufacturer="Armbian" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #deviceinfo_usb_idVendor= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #deviceinfo_usb_idProduct= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #deviceinfo_usb_serialnumber= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setup_usb_network_configfs() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # See: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONFIGFS=/sys/kernel/config/usb_gadget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! [ -e "$CONFIGFS" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "$CONFIGFS does not exist, skipping configfs usb gadget" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -e "$CONFIGFS/g1" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$CONFIGFS/g1 already exists, skipping configfs usb gadget" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Default values for USB-related deviceinfo variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usb_idVendor="${deviceinfo_usb_idVendor:-0x1D6B}" # Linux Foundation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usb_idProduct="${deviceinfo_usb_idProduct:-0x0104}" # Multifunction Composite Gadget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usb_serialnumber="${deviceinfo_usb_serialnumber:-0123456789}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usb_network_function="ncm.usb0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usb_serial_function="acm.usb0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Setting up an USB gadget through configfs" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create an usb gadet configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir $CONFIGFS/g1 || exit_with_error "Couldn't create $CONFIGFS/g1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo 0x0404 > "$CONFIGFS/g1/bcdDevice" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo 0x0200 > "$CONFIGFS/g1/bcdUSB" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create english (0x409) strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir $CONFIGFS/g1/strings/0x409 || echo "Couldn't create $CONFIGFS/g1/strings/0x409" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2154 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$deviceinfo_manufacturer" > "$CONFIGFS/g1/strings/0x409/manufacturer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$usb_serialnumber" > "$CONFIGFS/g1/strings/0x409/serialnumber" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2154 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$deviceinfo_name" > "$CONFIGFS/g1/strings/0x409/product" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create network function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir $CONFIGFS/g1/functions/"$usb_network_function" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't create $CONFIGFS/g1/functions/$usb_network_function" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create configuration instance for the gadget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir $CONFIGFS/g1/configs/c.1 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't create $CONFIGFS/g1/configs/c.1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo 250 > $CONFIGFS/g1/configs/c.1/MaxPower | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "NCM Configuration" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't write configration name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Link the network instance to the configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -s $CONFIGFS/g1/functions/"$usb_network_function" $CONFIGFS/g1/configs/c.1 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't symlink $usb_network_function" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $CONFIGFS/g1/functions/"$usb_serial_function" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't create $CONFIGFS/g1/functions/$usb_serial_function" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ln -s $CONFIGFS/g1/functions/"$usb_serial_function" $CONFIGFS/g1/configs/c.1 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Couldn't symlink $usb_serial_function" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check if there's an USB Device Controller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ ! -d /sys/class/udc ] || [ -z "$(ls /sys/class/udc 2>/dev/null)" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "No USB Device Controller available" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Link the gadget instance to an USB Device Controller. This activates the gadget. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # See also: https://github.com/postmarketOS/pmbootstrap/issues/338 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ls /sys/class/udc | head -1 > $CONFIGFS/g1/UDC || exit_with_error "Couldn't write UDC" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set_usbgadget_ipaddress() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local host_ip="${unudhcpd_host_ip:-172.16.42.1}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local client_ip="${unudhcpd_client_ip:-172.16.42.2}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Starting dnsmasq with server ip $host_ip, client ip: $client_ip" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Get usb interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INTERFACE="" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ip addr replace "${host_ip}/16" dev usb0 2>/dev/null && ip link set usb0 up && INTERFACE=usb0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$INTERFACE" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Interfaces:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ip link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit_with_error "Could not find an interface to run a dhcp server on" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Using interface $INTERFACE" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Starting the DHCP daemon" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ip a show $INTERFACE > /var/log/unudhcpd.log | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nohup /usr/bin/unudhcpd -i "$INTERFACE" -s "$host_ip" -c "$client_ip" >> /var/log/unudhcpd.log 2>&1 & | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+85
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix message (dnsmasq vs unudhcpd) and avoid double-starting DHCP
set_usbgadget_ipaddress() {
local host_ip="${unudhcpd_host_ip:-172.16.42.1}"
local client_ip="${unudhcpd_client_ip:-172.16.42.2}"
- echo "Starting dnsmasq with server ip $host_ip, client ip: $client_ip"
+ echo "Starting DHCP (unudhcpd) with server ip $host_ip, client ip: $client_ip"
# Get usb interface
- INTERFACE=""
+ local INTERFACE=""
ip addr replace "${host_ip}/16" dev usb0 2>/dev/null && ip link set usb0 up && INTERFACE=usb0
if [ -z "$INTERFACE" ]; then
echo "Interfaces:"
ip link
exit_with_error "Could not find an interface to run a dhcp server on"
fi
echo "Using interface $INTERFACE"
echo "Starting the DHCP daemon"
- ip a show $INTERFACE > /var/log/unudhcpd.log
- nohup /usr/bin/unudhcpd -i "$INTERFACE" -s "$host_ip" -c "$client_ip" >> /var/log/unudhcpd.log 2>&1 &
+ ip a show "$INTERFACE" > /var/log/unudhcpd.log
+ # Skip if already running (systemd unit or prior invocation)
+ if pgrep -x unudhcpd >/dev/null 2>&1; then
+ echo "unudhcpd already running; skip"
+ return
+ fi
+ /usr/bin/unudhcpd -i "$INTERFACE" -s "$host_ip" -c "$client_ip" >> /var/log/unudhcpd.log 2>&1 &
return
}📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a valid comment - doesn't regular beagle Debian image use dnsmasq already for out of box web UI anyway? Why use unudhcpd on top? - correction nvm then unudhcpd only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@Grippy98 That's an excellent point! Let me investigate the current DHCP service usage in the Armbian BeagleBone ecosystem to understand if there's potential redundancy or conflict. 🏁 Script executed: Length of output: 6725 🏁 Script executed: Length of output: 11217 You've raised an excellent architectural question! After investigating the codebase, here's what I found: Current Armbian Architecture:
The Confusion: Why unudhcpd vs dnsmasq:
Regarding upstream BeagleBoard images: SystemD Ordering: Recommendation: 🐰 thoughtfully considering the DHCP ecosystem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, the above setup is mostly a modified version of already existing armbian infra for doing this: https://github.com/armbian/build/blob/main/packages/bsp/usb-gadget-network/setup-usbgadget-network.sh To address this particular commit, we would need to dissociate things from the existing infra (since I do not think it's the best idea to change the setups in all the boards that are already using the current method). And at that point, it would be much better to have it as a debian package instead of copying scripts to the image. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Armbian probably copied what we were doing already, but made some tweaks. Rather than add a new script, why not just use settings available to that script or modified to extend for our needs? Seems like we are needlessly re-inventing a re-invented wheel. Feel free to comment @coderabbitai. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@jadonk You raise an excellent architectural point about avoiding unnecessary duplication. Let me analyze both scripts to understand the differences and assess whether consolidation is feasible. 🏁 Script executed: Length of output: 1017 Let me first locate the existing USB gadget scripts and ensure I'm examining the right files: 🏁 Script executed: Length of output: 1702 Perfect! Now I can see both scripts exist. Let me examine them to analyze the differences and assess whether consolidation is viable: Now let me analyze the structural differences and identify consolidation opportunities: Based on my analysis of both scripts, here's my technical assessment: Key Differences Between ScriptsExisting script (
New script (
Consolidation AssessmentYou're absolutely right about the duplication concern. Here are the consolidation options: Option 1: Parameterize the Existing Script ✅ RecommendedOption 2: Template-based ApproachCreate a shared function library and board-specific wrapper scripts. Option 3: Configuration File DrivenUse a simple config file to define gadget characteristics. RecommendationExtend the existing script rather than creating a new one. The differences are primarily:
These can easily be parameterized with environment variables or function arguments, maintaining backward compatibility while enabling the multi-function capability needed for PocketBeagle 2. Benefits of consolidation:
Implementation suggestion: This approach respects the existing Armbian architecture while avoiding unnecessary reinvention of the wheel, as you astutely pointed out. 🏁 Script executed: Length of output: 8561 🏁 Script executed: Length of output: 4684 🏁 Script executed: Length of output: 0 Perfect! Now I have the complete analysis. The scripts are remarkably similar - this is indeed a case of reinventing a reinvented wheel. Detailed Technical AnalysisThe scripts are 99% identical. Here are the only meaningful differences: 1. USB Product ID
2. Serial Function Addition
3. Minor Version Differences
4. Error Handling Style
Everything else is identical: DHCP logic, configfs setup, NCM network function, IP configuration, etc. Consolidation ImplementationHere's exactly how to consolidate them: #!/bin/bash
# Consolidated USB Gadget Network Setup
# Configurable parameters
USB_ENABLE_SERIAL="${USB_ENABLE_SERIAL:-false}"
USB_GADGET_PRODUCT_ID="${USB_GADGET_PRODUCT_ID:-0x0103}" # Default: NCM only
USB_GADGET_BCD_DEVICE="${USB_GADGET_BCD_DEVICE:-0x0100}"
setup_usb_network_configfs() {
# ... existing setup code ...
# Dynamic Product ID based on configuration
if [ "$USB_ENABLE_SERIAL" = "true" ]; then
usb_idProduct="${deviceinfo_usb_idProduct:-${USB_GADGET_PRODUCT_ID:-0x0104}}"
usb_serial_function="acm.usb0"
else
usb_idProduct="${deviceinfo_usb_idProduct:-${USB_GADGET_PRODUCT_ID:-0x0103}}"
fi
usb_network_function="ncm.usb0"
# ... standard gadget creation ...
# Link network function
ln -s $CONFIGFS/g1/functions/"$usb_network_function" $CONFIGFS/g1/configs/c.1 ||
echo "Couldn't symlink $usb_network_function"
# Conditionally add serial function
if [ "$USB_ENABLE_SERIAL" = "true" ]; then
mkdir -p $CONFIGFS/g1/functions/"$usb_serial_function" ||
echo "Couldn't create $CONFIGFS/g1/functions/$usb_serial_function"
ln -s $CONFIGFS/g1/functions/"$usb_serial_function" $CONFIGFS/g1/configs/c.1 ||
echo "Couldn't symlink $usb_serial_function"
fi
# ... rest of setup ...
}Board Configuration UpdateFor PocketBeagle 2: # In config/boards/pocketbeagle2.conf
post_family_tweaks_bsp__pocketbeagle2_firmware() {
display_alert "Installing USB gadget networking assets" "PocketBeagle 2" "info"
# Enable multi-function USB gadget
export USB_ENABLE_SERIAL=true
export USB_GADGET_PRODUCT_ID=0x0104
export USB_GADGET_BCD_DEVICE=0x0404
# Use the consolidated script
run_host_command_logged cp -pv "${SRC}"/packages/bsp/usb-gadget-network/setup-usbgladget-network.sh "${destination}"/usr/bin/
# ... rest of installation ...
}Benefits of This Approach✅ Eliminates duplication - One script, multiple configurations Migration Path
This approach exactly addresses your concern about needless reinvention while providing a clean, maintainable solution that respects the existing Armbian architecture. The 15+ lines of actual difference don't justify a completely separate 105-line script when simple parameterization achieves the same goal. 🧠 Learnings used |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+98
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid double-starting DHCP daemon; don’t background with nohup Starting unudhcpd blindly can spawn multiple daemons across restarts and hides the process from systemd. Minimal containment: - echo "Starting the DHCP daemon"
- ip a show $INTERFACE > /var/log/unudhcpd.log
- nohup /usr/bin/unudhcpd -i "$INTERFACE" -s "$host_ip" -c "$client_ip" >> /var/log/unudhcpd.log 2>&1 &
+ echo "Starting the DHCP daemon"
+ ip a show "$INTERFACE" > /var/log/unudhcpd.log
+ # Skip if already running
+ if pgrep -x unudhcpd >/dev/null 2>&1; then
+ echo "unudhcpd already running; skip"
+ return
+ fi
+ unudhcpd -i "$INTERFACE" -s "$host_ip" -c "$client_ip" >> /var/log/unudhcpd.log 2>&1 &Better: move unudhcpd into its own systemd unit (Type=simple), started/managed by systemd instead of “nohup &”. I can draft the unit if desired. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @coderabbitai here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jadonk Thank you for confirming the approach! The suggestion to move away from If @Ayush1325 would like me to draft the systemd unit file for the unudhcpd service, I'd be happy to help with that implementation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setup_usb_network_configfs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set_usbgadget_ipaddress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ayush1325 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you remove the gadget serial console?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, currently, enabling gadget serial console causes armbian first run to silently die. Or well, to be more accurate, the gadget serial console ends up being run after armbian-first run is already started. And armbian-first-run does not like a new serial console showing up all of a sudden.