raw-gadget icon indicating copy to clipboard operation
raw-gadget copied to clipboard

Fail to compile raw-gadget after execute update.sh

Open AristoChen opened this issue 1 year ago • 1 comments

Hi,

the following error message will appear if trying to compile raw-gadget kernel module after update.sh is executed

$ make
make -C /lib/modules/5.10.60/build M=/root/raw-gadget/raw_gadget SUBDIRS=/root/raw-gadget/raw_gadget modules
make[1]: Entering directory '/usr/src/linux-source'
  CC [M]  /root/raw-gadget/raw_gadget/raw_gadget.o
/root/raw-gadget/raw_gadget/raw_gadget.c: In function ‘raw_ioctl_run’:
/root/raw-gadget/raw_gadget/raw_gadget.c:546:8: error: implicit declaration of function ‘usb_gadget_register_driver’; did you mean ‘usb_gadget_unregister_driver’? [-Werror=implicit-function-declaration]
  546 |  ret = usb_gadget_register_driver(&dev->driver);
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |        usb_gadget_unregister_driver
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:280: /root/raw-gadget/raw_gadget/raw_gadget.o] Error 1
make[1]: *** [Makefile:1824: /root/raw-gadget/raw_gadget] Error 2
make[1]: Leaving directory '/usr/src/linux-source'
make: *** [Makefile:7: default] Error 2

looks like this patch is causing the issue, usb_gadget_probe_driver() was renamed to usb_gadget_register_driver(), the following patch works fine with my SBC with 5.10.60 kernel version.

diff --git a/raw_gadget/update.sh b/raw_gadget/update.sh
index 6ffcb66..c363e12 100755
--- a/raw_gadget/update.sh
+++ b/raw_gadget/update.sh
@@ -9,4 +9,12 @@ BRANCH=usb-next
 wget $REPO/drivers/usb/gadget/legacy/raw_gadget.c?h=$BRANCH -O raw_gadget.c
 wget $REPO/include/uapi/linux/usb/raw_gadget.h?h=$BRANCH -O raw_gadget.h

+
+HEADER_FILE=/lib/modules/"$(uname -r)"/build/include/linux/usb/gadget.h
+if [[ $(grep -c "usb_gadget_probe_driver(" < "$HEADER_FILE") -ne 0 ]]
+then
+    echo "Replacing from usb_gadget_register_driver() to usb_gadget_probe_driver()"
+    sed -i 's/usb_gadget_register_driver/usb_gadget_probe_driver/g' raw_gadget.c
+fi
+
 git apply ./include.patch

AristoChen avatar Jul 24 '22 14:07 AristoChen

Hi,

Yeah, this is expected. There is no stable API for kernel modules. I think, for simplicity, we should keep the code in this repository compatible with the latest R Pi Zero kernel. And add a note what to do in case the modules do not compile.

I'll take a closer look into doing this when I get a chance. Let's keep this bug open for now.

Thanks!

xairy avatar Jul 27 '22 21:07 xairy

Fixed by https://github.com/xairy/raw-gadget/commit/8274ee02badc8804e63cca41ed24fbc223ff69f9.

xairy avatar Dec 08 '22 22:12 xairy

I am on kernel version 6.1.21 (Raspbian/RPi Zero) and I am seeing the same issue. usb_gadget_probe_driver doesn't seem to exist. I pulled the kernel headers via raspberrypi-kernel-headers. Is there anything I am missing here?

pr8x avatar Aug 01 '23 21:08 pr8x

You need to comment out this part and reupdate the module.

xairy avatar Aug 01 '23 22:08 xairy

Ah, got it. Thanks.

pr8x avatar Aug 01 '23 22:08 pr8x