please choosego to mobile | Continue to access the PC version
View: 28824|Reply: 9

Enable OTG gadget devices on Linux (OrangePI PC)

[Copy link]

1

threads

5

posts

29

credits

Novice

Rank: 1

credits
29
Published in 2015-12-16 20:35:16 | Show all floors |Read mode
Edited by EduardMe1 at 2015-12-16 20:39

Dear community,

Im trying to get an USB gadget via OTG running on Linux (OrangePI PC).
For example g_mass_storage or g_hid or g_serial is interesting.

What I want to achieve is, when I connect the OTG cable to OrangePI PC, it should be detected as a device on a PC. One of the above.
First challenge is to get it detected at all. Currently nothing happens, if I connect the cable.

I attempted the following:

I used loboris repo to re-build the kernel: https://github.com/loboris/OrangePI-Kernel
I changed the kernel config like this (described here):

  1. Device Drivers  --->
  2.              USB support  --->
  3.                    <*>    NOP USB Transceiver Driver
  4.                     [*]    SUNXI USB2.0 Dual Role Controller support --->
  5.                              [*]    Sunxi USB2.0 Manager
  6.                                   USB0 Controller support (otg support) --->
  7.                                         (*) otg support
Copy code


Additionally I activated as <M> the OTG gadget drivers for g_mass_storage, g_hid and g_serial.
After the compilation, I have copied the uImage and the lib/modules folder onto the SD Card. The SD Card has a Linux image installed. In this case the Ubuntu_vivid_mini.img from loboris.

After replacing the above, the board is booting normally, but Im not able to activate the gadget drivers.
Im using following commands as root:

  1. $ modprobe g_hid
Copy code
output is: insmod /lib/modules/3.4.39-02-lobo/kernel/drivers/usb/gadget/g_hid.komodrpobe: ERROR: could not insert g_hid: No such device

Although the module is there at the same location. I can modprobe the g_mass_storage, but still nothing shows up on the PC connected to OrangePI PC.

From my understanding, OrangePI PC should be detected as some device on a PC.
Any clues, tips or references how to setup OTG correctly?

Thanks!


1

threads

5

posts

29

credits

Novice

Rank: 1

credits
29
 Author| Published in 2015-12-16 23:02:40 | Show all floors
On Android I can activate the OTG (and adb) by following command:

  1. echo 2 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role
Copy code


Is there a similar file or other way for linux to activate the device otg role?

1

threads

5

posts

29

credits

Novice

Rank: 1

credits
29
 Author| Published in 2015-12-24 22:53:04 | Show all floors
The same file, otg_role, is also there on Linux, but its not working as expected. I have loaded the android driver as build-in driver. On Android this gadget driver is configured after setting otg_role and plugging in a cable. Additionally bus 5 of the usb ports is deregistered on setting otg_role. I guess this port is the OTG port, which is configured as device. On Linux it stays in lsusb.

1

threads

5

posts

29

credits

Novice

Rank: 1

credits
29
 Author| Published in 2015-12-26 09:32:16 | Show all floors
Its actually working, except on loboris minimal images. If anyone is interested, these are the commands to enable the android composite driver under linux:

  1. echo 1 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role
  2. echo 2 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role

  3. echo 0 > /sys/class/android_usb/android0/enable
  4. echo 1d6b > /sys/class/android_usb/android0/idVendor
  5. echo 0001 > /sys/class/android_usb/android0/idProduct
  6. echo mtp > /sys/class/android_usb/android0/functions
  7. echo 1 > /sys/class/android_usb/android0/enable
Copy code


Enables MTP for example. There is a list of other devices too.

2

threads

29

posts

112

credits

Registered member

Rank: 2

credits
112
Published in 2016-1-5 17:24:56 | Show all floors
Thanks for the report!

All USB host working or just otg? Maybe it's possible to make an ethenet device g_ether module.
https://learn.adafruit.com/turni ... get/ethernet-gadget

1

threads

5

posts

29

credits

Novice

Rank: 1

credits
29
 Author| Published in 2016-1-11 01:59:38 | Show all floors
Not sure if the several gadgets work on its own. I was using successfully the android composite gadget to enable other gadgets and multiple in combination. HID, Mass Storage, MTP, ACM/Serial were working well. I think it also has RNDIS, which is basically the g_ether gadget. But I didnt test this one.

2

threads

29

posts

112

credits

Registered member

Rank: 2

credits
112
Published in 2016-1-23 15:51:17 | Show all floors
Edited by boob at 2016-1-23 16:15

Thanks a lot for your work, my goal is to make it work orange pi as OTG connected to an Openwrt device, OP for CPUing and display and openwrt as gateway (WT3020H have wireless 2T2R and 2 Ethernet port)!
I will try to compile kernel like you suggest and hope it's will work for RNIS ethernet device.
If all is right let 's go to buy one orange pi ;)

Many thanks

2

threads

29

posts

112

credits

Registered member

Rank: 2

credits
112
Published in 2016-1-23 16:12:48 | Show all floors
I see "Ethernet Gadget (with CDC Ethernet support)" let 's go try compile

2

threads

29

posts

112

credits

Registered member

Rank: 2

credits
112
Published in 2016-1-23 19:41:51 | Show all floors
Edited by boob at 2016-1-23 19:46

It 's seem to be broken build on my 32bit linux machine :
  1. arch/arm/mach-sunxi/power/brom/gen_check_code: 1: arch/arm/mach-sunxi/power/brom/gen_check_code: Syntax error: end of file unexpected (expecting ")")
Copy code


I try this  (http://www.orangepi.org/orangepi ... =viewthread&tid=436) but error on "usage" of gen_check_code.

I will try the kernel build of Jef Moine (http://moinejf.free.fr/opi2/index.html), with Orange PI PC support, but 1GB to download for lichee zip is long wait

Maybe an minimal mainline kernel support (HDMI, USB, ethernet) too.

2

threads

29

posts

112

credits

Registered member

Rank: 2

credits
112
Published in 2016-1-24 07:05:11 | Show all floors
Here an ugly hack to compile with 32bit linux without gen_check_code problem :

edit the Makefile in OrangePI-Kernel-master/linux-3.4/arch/arm/mach-sunxi/power/brom for applying patch from JefMoine (http://moinejf.free.fr/opi2/kernel-3.4.patch).

New Makefile edited :

  1. #makefile for resume.bin

  2. always  := resumes.code
  3. targets := resumes.elf

  4. hostprogs-y        := mksunxichecksum
  5. #always                += $(hostprogs-y)

  6. #use "-Os" flags.
  7. #Don't use "-O2" flags.
  8. KBUILD_CFLAGS := -g -c -nostdlib -march=armv7-a -marm \
  9.         -fno-unwind-tables -fno-asynchronous-unwind-tables -mlittle-endian -Os
  10. #        --min_array_alignment=4 --no_unaligned_acces

  11. KBUILD_CPPFLAGS += -I.

  12. LD_FLAGS = -static
  13. LIBS =

  14. INCLUDE   = -I. \
  15.        -I$(KDIR)/include \
  16.        -I$(KDIR)/arch/arm/mach-sunxi/include

  17. resumes-y :=   resumes.o        \
  18.                resume_head.o

  19. resumes-y := $(addprefix $(obj)/,$(resumes-y))

  20. $(obj)/resumes.code: $(obj)/resumes.bin $(obj)/mksunxichecksum
  21.         $(obj)/mksunxichecksum $(obj)/resumes.bin $(obj)/resumes.code
  22. #        $(Q)$(obj)/gen_check_code $(obj)/resumes.bin $(obj)/resumes.code
  23. $(obj)/resumes.bin: $(obj)/resumes.elf FORCE
  24.         $(Q)$(CROSS_COMPILE)objcopy -O binary $(obj)/resumes.elf $(obj)/resumes.bin

  25. ifneq ($(strip $(CONFIG_ARCH_SUN9I)),)
  26. $(obj)/resumes.elf: $(srctree)/$(src)/sun9i_brom_scatter.scat $(resumes-y)
  27.         $(Q)$(CROSS_COMPILE)ld -T $(srctree)/$(src)/sun9i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
  28.         $(Q)$(CROSS_COMPILE)objdump -D $(obj)/resumes.elf > $(obj)/resumes.lst
  29. endif

  30. ifneq ($(strip $(CONFIG_ARCH_SUN8I)),)
  31. $(obj)/resumes.elf: $(srctree)/$(src)/sun8i_brom_scatter.scat $(resumes-y)
  32.         $(Q)$(CROSS_COMPILE)ld -T $(srctree)/$(src)/sun8i_brom_scatter.scat -EL $(resumes-y) -o $(obj)/resumes.elf -Map $(obj)/resumes.map
  33.         $(Q)$(CROSS_COMPILE)objdump -D $(obj)/resumes.elf > $(obj)/resumes.lst
  34. endif

  35. clean-files += resumes.code resumes.elf
Copy code


add mksunxichecksum.c from https://gist.github.com/hno/dae626bc7765dcad2dae and change this line :
  1. if (argc != 4) {
  2.                 printf("Usage: %s file.bin file.code\n"
  3.                        "calculates BROM checksum in boot header of given .bin file and writes to .code file\n"
  4.                        "", argv[0]);
  5.                 exit(1);
  6.         }
Copy code

by :
  1. if (argc != 3) {
  2.                 printf("Usage: %s file.bin file.code\n"
  3.                        "calculates BROM checksum in boot header of given .bin file and writes to .code file\n"
  4.                        "", argv[0]);
  5.                 exit(1);
  6.         }
Copy code


It's compile now on 32bit linux system (I haven't board OP PC to test for now).
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list