0

I've been tasked with updating a driver on a Raspberry Pi 4 running Raspbian. I'm told I need to apply this patch https://lkml.org/lkml/2019/4/1/1050 in order to get my USB modem to work.

When I run uname -r I'm told I'm on kernel version 4.19.75-v7l+

I created the option.c file in the directory /lib/modules/4.19.75-v7l+/kernel/drivers/usb/serial but I can't figure out how to 'apply?/patch?/compile?/update?' these changes to the option.ko file in the directory?

Thank you for any help

  • You cannot patch a compiled binary object such as a .ko file with source code. The file (option.c) is referenced directly in the patch (for use with the patch tool). You then have to compile that to create a new .ko file and replace it in /lib/modules. I'll warn you your chance of failure here is pretty high. – goldilocks Nov 11 '19 at 14:42
  • 1
    That fix is already in the Raspberry Pi kernel source at github.com/raspberrypi/linux/blob/…. Try running sudo rpi-update && sudo reboot to get the very latest kernel. – Dougie Nov 11 '19 at 21:23
3

For such a small patch I wouldn't bother using a tool to apply it. Just add the lines starting with the + sign to option.c, not including the + sign itself. The first insertion will be at line 249, and another three lines should be inserted at line 1091 (or 1092 after you insert the first one).

Bigger patches must be saved into a file and applied using a compatible tool, usually patch or git apply.

  • 1
    I believe the file I need to patch is "option.ko" which I can't open with any text editor. – fullyjosh Nov 11 '19 at 14:36
  • 2
    @fullyjosh No, .ko files are compilation outputs. Patches are applied to source code. This patch mention its target: drivers/usb/serial/option.c – Dmitry Grigoryev Nov 11 '19 at 14:39
  • 1
    So after I create the option.c file (there was no existing file previously) there's nothing more I need to do? – fullyjosh Nov 11 '19 at 14:41
  • 1
    You need to get the kernel source code (which will create option.c), modify that file and then rebuild the kernel module (usbserial.ko?) or maybe build it into a custom kernel. – Dmitry Grigoryev Nov 11 '19 at 14:45
  • 1
    Don't bother. That patch is already in the kernel source: github.com/raspberrypi/linux/blob/rpi-4.19.y/drivers/usb/serial/… – goldilocks Nov 11 '19 at 14:57
2

I've been tasked with updating a driver on a Raspberry Pi 4 running Raspbian. I'm told I need to apply this patch https://lkml.org/lkml/2019/4/1/1050 in order to get my USB modem to work.

You are in luck in the sense that that patch has already been applied. Here is the relevant source file in what is approximately the current Pi kernel source:

https://github.com/raspberrypi/linux/blob/rpi-4.14.y/drivers/usb/serial/option.c

I also checked 4.14, since that LKML post appears to be dated 2019 and refers to 4.14. You can check your current kernel version with uname -r. If it is less than 4.14 you should upgrade.

If you already have a current kernel but the modem still does not work, this is probably not such great news (perhaps consider an XY problem here). To dispell any doubts, you can read up on how the patch utility works (see also man patch); in short the lines marked on the left with + in that patch file are to be added to the target. The rest is there for context.

What that amounts to is simply adding the USB ID for a particular make and model of device; there's no real functional code there. These are used by the kernel to associate USB devices (which provide an ID) with drivers. You can see these with lsusb (you may need to apt install usbutils). That modem will appear as 2c7c:0512. The first number is the QUECTEL_VENDOR_ID, the second the QUECTEL_PRODUCT_EM12 ID. Note lsusb will show it regardless of whether an appropriate driver is loaded or available (ie., this does not indicate it works).

I don't think these are strictly necessary in order to use the driver; you can manually load it (sudo modprobe option; you can see if it is loaded with lsmod | grep option). The ID, again, is so it can be automatically loaded when the device is plugged in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.