Skip to content

Commit 084bc88

Browse files
committed
Merge amlogic-adbd into this package
1 parent 22993a7 commit 084bc88

File tree

10 files changed

+152
-75
lines changed

10 files changed

+152
-75
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ all:
99
fpm -s dir -t deb -n $(NAME) -v $(VERSION) \
1010
-p $(NAME)_$(VERSION)_all.deb \
1111
--deb-priority optional --category utils \
12-
--before-remove prerm.sh \
12+
--depends android-tools-adbd \
1313
--force \
1414
--deb-field "Multi-Arch: foreign" \
1515
--deb-field "Replaces: $(NAME)" \

NAME

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
radxa-usbnet
1+
radxa-otgutils

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# radxa-usbnet
1+
# radxa-otgutils
22

3-
[![Build](https://github.com/radxa-pkg/radxa-usbnet/actions/workflows/build.yml/badge.svg)](https://github.com/radxa-pkg/radxa-usbnet/actions/workflows/build.yml) [![Release](https://github.com/radxa-pkg/radxa-usbnet/actions/workflows/release.yml/badge.svg)](https://github.com/radxa-pkg/radxa-usbnet/actions/workflows/release.yml)
3+
[![Build](https://github.com/radxa-pkg/radxa-otgutils/actions/workflows/build.yml/badge.svg)](https://github.com/radxa-pkg/radxa-otgutils/actions/workflows/build.yml) [![Release](https://github.com/radxa-pkg/radxa-otgutils/actions/workflows/release.yml/badge.svg)](https://github.com/radxa-pkg/radxa-otgutils/actions/workflows/release.yml)
44

5-
Enable USB ethernet gadget on selected Radxa single board computers
5+
Enable USB gadget on OTG port.
66

77
# Usage
8-
This service conflicts with `amlogic-adbd`. As such please run the following command to enable it:
9-
```
10-
sudo systemctl disable amlogic-adbd
11-
sudo systemctl enable radxa-usbnet
12-
```
13-
The device will be available after reboot.
8+
9+
The following gadgets are provided:
10+
* radxa-adbd
11+
* radxa-usbnet
12+
13+
They can be enabled with `sudo systemctl enable --now <gadget>`, and disabled with `sudo systemctl disable --now <gadget>`.
14+
15+
Please be aware than those gadgets are mutually exclusive. If one is already enabled you have to diable then reboot before you can enable anyther gadget.

prerm.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
radxa-otgutils.sh
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash -e
2+
3+
configfs_init()
4+
{
5+
modprobe libcomposite
6+
7+
case "$MODE" in
8+
adbd)
9+
local VENDOR="0x18d1"
10+
local PRODUCT="0x0001"
11+
;;
12+
usbnet)
13+
local VENDOR="0x1d6b"
14+
local PRODUCT="0x0104"
15+
;;
16+
esac
17+
18+
mkdir -p /sys/kernel/config/usb_gadget/radxa-$MODE -m 0770
19+
echo "$VENDOR" > /sys/kernel/config/usb_gadget/radxa-$MODE/idVendor
20+
echo "$PRODUCT" > /sys/kernel/config/usb_gadget/radxa-$MODE/idProduct
21+
mkdir -p /sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409 -m 0770
22+
echo "Radxa" > /sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/manufacturer
23+
echo "$MODE" > /sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/product
24+
mkdir -p /sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1 -m 0770
25+
26+
case "$MODE" in
27+
adbd)
28+
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/serialnumber
29+
mkdir -p /sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/strings/0x409 -m 0770
30+
echo "500" > /sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/MaxPower
31+
echo "adb" > /sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/strings/0x409/configuration
32+
;;
33+
esac
34+
}
35+
36+
function_init()
37+
{
38+
case "$MODE" in
39+
adbd)
40+
local GADGET="ffs.adb"
41+
;;
42+
usbnet)
43+
local GADGET="ecm.usb0"
44+
;;
45+
esac
46+
47+
if [ ! -e "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/$GADGET" ];
48+
then
49+
mkdir -p /sys/kernel/config/usb_gadget/radxa-$MODE/functions/$GADGET
50+
ln -s /sys/kernel/config/usb_gadget/radxa-$MODE/functions/$GADGET /sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1
51+
fi
52+
}
53+
54+
start()
55+
{
56+
configfs_init
57+
function_init
58+
59+
case "$MODE" in
60+
adbd)
61+
if [ ! -e "/dev/usb-ffs/adb" ] ;
62+
then
63+
mkdir -p /dev/usb-ffs/adb
64+
mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb
65+
fi
66+
export service_adb_tcp_port=5555
67+
start-stop-daemon --start --oknodo --pidfile /var/run/adbd.pid --startas /usr/bin/adbd --background
68+
sleep 1
69+
;;
70+
esac
71+
72+
local UDC=$(ls /sys/class/udc/ | head -1)
73+
echo $UDC > /sys/kernel/config/usb_gadget/radxa-$MODE/UDC
74+
)
75+
76+
stop()
77+
{
78+
echo "none" > /sys/kernel/config/usb_gadget/radxa-$MODE/UDC
79+
case "$MODE" in
80+
adbd)
81+
start-stop-daemon --stop --oknodo --pidfile /var/run/adbd.pid --retry 5
82+
;;
83+
esac
84+
}
85+
86+
MODE=
87+
case "$(basename $0)" in
88+
radxa-adbd.sh)
89+
MODE=adbd
90+
;;
91+
radxa-usbnet.sh)
92+
MODE=usbnet
93+
;;
94+
radxa-otgutils.sh)
95+
echo Please run this script from symbolic links.
96+
exit 1
97+
;;
98+
*)
99+
echo Unknown script name.
100+
exit 1
101+
;;
102+
esac
103+
104+
case "$1" in
105+
start)
106+
start
107+
;;
108+
stop)
109+
stop
110+
;;
111+
restart|reload)
112+
stop
113+
start
114+
;;
115+
*)
116+
echo "Usage: $0 {start|stop|restart}"
117+
exit 1
118+
esac
119+
120+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
radxa-otgutils.sh
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Enable adbd on selected Radxa single board computers
3+
Documentation=https://github.com/radxa-pkg/radxa-otgutils/
4+
After=network.target
5+
Conflicts=radxa-usbnet.service
6+
[Service]
7+
Type=forking
8+
ExecStart=/lib/radxa-otgutils/radxa-adbd.sh start
9+
ExecStop=/lib/radxa-otgutils/radxa-adbd.sh stop
10+
ExecReload=/lib/radxa-otgutils/radxa-adbd.sh reload
11+
[Install]
12+
WantedBy=multi-user.target
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[Unit]
22
Description=Enable USB ethernet gadget on selected Radxa single board computers
3-
Documentation=https://wiki.radxa.com/Template:Rockpi_apt
3+
Documentation=https://github.com/radxa-pkg/radxa-otgutils/
44
After=network.target
5-
Conflicts=amlogic-adbd.service
5+
Conflicts=radxa-adbd.service
66
[Service]
77
Type=forking
8-
ExecStart=/usr/sbin/radxa-usbnet.sh start
9-
ExecStop=/usr/sbin/radxa-usbnet.sh stop
10-
ExecReload=/usr/sbin/radxa-usbnet.sh reload
8+
ExecStart=/lib/radxa-otgutils/radxa-usbnet.sh start
9+
ExecStop=/lib/radxa-otgutils/radxa-usbnet.sh stop
10+
ExecReload=/lib/radxa-otgutils/radxa-usbnet.sh reload
1111
[Install]
1212
WantedBy=multi-user.target

root/usr/sbin/radxa-usbnet.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)