Cubietruck, USB OTG g_hid, g_mass_storage
This section describes
Linux Kernel version: 4.4-rc1
Install Plop Linux
Plop Linux is for advanced Linux users. The install documentation does not describe every step with commands. When it's too difficult for people then I will update this page with more details.
Boot a Linux on a computer with a SD card reader.
• On the SD Card, create one partition for Plop Linux.
• Create an Ext3 file system on the 'mkfs.ext3 /dev/PARTITION1'. Minimum size is 3.1 GB.
• Mount the Partition to '/mnt'.
• Extract the ploplinux-desktop-4.3.2-arm.tar.gz archive to '/mnt'.
• Move the directories in '/mnt/ploplinux-desktop-4.3.2-arm/'. one directory up that they became the root directories on the Plop Linux partition.
• Remove the empty '/mnt/ploplinux-desktop-4.3.2-arm/' directory.
• Extract the cubietruck-boot.tar.gz archive to '/mnt'.
• Install the U-Boot boot loader. Change to '/mnt/boot' and run 'dd if=u-boot-sunxi-with-spl.bin of=/dev/SDCARD bs=1024 seek=8'
• A few important files (the default settings should be ok):
• Unmount '/mnt'.
Notes about Linux Kernel releases
The kernel that comes with Plop Linux does not support all Cubietruck features. The stable kernel 3.4. for Cubietruck should support the hardware features, but cannot be compiled with the latest GCC. The 3.4. kernel is not part of Plop Linux.
The latest kernel release 4.9. does not poweroff the Cubietruck.
Poweroff works with 4.4.rc-1 which comes with Plop Linux.
Compile the Linux Kernel
Either compile the Linux Kernel on your Cubietruck (slow) or you have to setup a cross compile environment (see here) on your computer.
• When you use the cross compile environment, then start the 'shell.sh' script.
• Download the Linux Kernel Source Code for the Cubietruck.
• Change to the Linux Kernel directory 'cd linux-sunxi' and setup base configuration
• To compile the kernel run 'make && make modules_install'.
Note: 'make modules_install' installs the kernel modules. When you compile on the Cubietruck then the modules will be installed to '/lib/modules'. When you compile in the cross compile environment then you find the modules in the 'kernel-modules/' directory where you started the 'shell.sh' script.
• You find the Linux Kernel file in the 'arch/arm/boot/' directory. The file name is 'zImage'.
• Copy the 'zImage' file to the '/boot' directory of your Cubietruck.
Note: When you compile in a cross compile environment, then an easy way to transfer the files
to your running Cubietruck is using sshfs.
Modify the file '/etc/boot.cmd' for your needs.
To create the 'boot.scr' file run 'mkimage -C none -A arm -T script -d boot.cmd boot.scr'.
The Cubietruck has 4 leds and you can set triggers for those leds. For example SD Card access, Bluetooth and much more. There is the blue, white, orange and green led.
Find the leds in '/sys/class/leds/'.
The green led is '/sys/class/leds/cubietruck:green:usr/'.
In this directory you find the file 'trigger' file. Run 'cat trigger' to list the possible values. The current setting is marked with square brackets.
Here is the Plop Linux setup from '/etc/rc.local'.
# Set green led to SD Card actvity echo mmc0 > /sys/class/leds/cubietruck:green:usr/trigger # Plop Linux has booted, set orange led on echo default-on > /sys/class/leds/cubietruck:orange:usr/trigger
USB OTG - HID, mass storage device
Use only an USB OTG cable to connect the OTG port with a computer!
• The Cubietruck as HID
You have to modify the g_hid kernel module source code to enable the HID function. Plop Linux has a working sample g_hid module installed. You find details about the g_hid driver in the kernel documentation file gadget_hid.txt
You have to edit the file 'drivers/usb/gadget/legacy/hid.c' and add
Download the modified hid.c
Note: When you use the unmodified hid.c, then you will get the error "ERROR: could not insert 'g_hid': No such device" on modprobe g_hid.
Using the g_hid module
Download the test program: hid_gadget_test.c
Compile the test program: gcc hid_gadget_test.c -o hid_gadget_test
Load the g_hid driver: modprobe g_hid
Start the test program: ./hid_gadget_test /dev/hidg0 keyboard
You are now in the prompt of hid_gadget_test and can enter values.
When the Cubietruck is connected to a computer with the USB OTG cable, then the Cubietruck act as a keyboard. Type 'a b c' and then enter on the hid_gadget_test prompt. On the computer should you see the typed text "abc". '--num-lock' toggles the numlock. See gadget_hid.txt for more details.
• The Cubietruck as mass storage device
This is an example with using a disk image file.
Create the disk image file:
Enable the USB mass storage:
Run 'modprobe g_mass_storage file=/var/disk.img'.
When the Cubietruck is connected to a computer with the USB OTG cable, then the Cubietruck act as a mass storage device. When you run on the computer 'dmesg' then you should see the entries of the new USB mass storage device. When you mount on the computer the USB device with example 'mount /dev/sdd /mnt', then you should see the created 'test.txt' in the /mnt directory.
© 2017 by Elmar Hanlhofer