HalfHour / libnxt

Automatically exported from code.google.com/p/libnxt
GNU General Public License v2.0
0 stars 0 forks source link

flashing fails on recent Linux versions #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. install linux kernel version >=2.6.32.5
2. try to flash
3. observe, that it fails because cdc_acm driver has claimed device

What is the expected output? What do you see instead?
flashing works

What version of the product are you using? On what operating system?
latest

Please provide any additional information below.
SAM-BA bootloader claims to be a cdc_acm device, but doesn't advertise any 
cdc-protocol (like AT commands). Since recently, the cdc_acm driver claims such 
devices too:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=
5b239f0aebd4dd6f85b13decf5e18e86e35d57f0

I suggest a call to libusb's usb_detach_kernel_driver_np.

Original issue reported on code.google.com by sven.koe...@gmail.com on 31 Oct 2010 at 4:53

GoogleCodeExporter commented 8 years ago
Sorry, the kernel version should be >=2.6.35.5.

Original comment by sven.koe...@gmail.com on 31 Oct 2010 at 5:05

GoogleCodeExporter commented 8 years ago
Indeed, the suggestion is good. Use of usb_detach_kernel _driver_np solve this 
issue with my linux kernel > 2.6.32.

This is my quick patch:

--- libnxt-0.3/lowlevel.c   2007-04-22 05:24:17.000000000 +0200
+++ libnxt-0.3.1/lowlevel.c 2010-11-15 00:46:00.000000000 +0100
@@ -93,9 +93,18 @@
 {
   char buf[2];
   int ret;
+  char bound_driver_name[20];

   nxt->hdl = usb_open(nxt->dev);

+//detach possible kernel driver bound to interface
+ if 
(usb_get_driver_np(nxt->hdl,1,bound_driver_name,sizeof(bound_driver_name))==0)
+   {
+  if (usb_detach_kernel_driver_np(nxt->hdl, 1)<0)
+   fprintf(stderr,"Failed to detach the driver %s (or cdc-acm) bound to the USB 
interface",bound_driver_name);
+   //Let usb_set_configuration() below return an error and handle it
+   }   
+
   ret = usb_set_configuration(nxt->hdl, 1);
   if (ret < 0)
     {

Original comment by l.cuvil...@gmail.com on 14 Nov 2010 at 11:57

GoogleCodeExporter commented 8 years ago
I wonder, is there a race here? What if usb_get_driver_np returns a driver, but 
it's detached by another process before you call usb_detach_kernel_driver_np. 
Does usb_detach_kernel_driver_np return success, if no driver is actually 
attached at the moment? Unfortunatly, the libusb docs don't answer any of these 
quesions.

Original comment by sven.koe...@gmail.com on 15 Nov 2010 at 1:12