English / Deutsch | Print version Plop Linux  

<< Previous
Banana Pi

Table of Contents

Next >>
Odroid-XU4

Cubietruck, USB OTG g_hid, g_mass_storage


This section describes

  • How you install Plop Linux on the Cubietruck.
  • How you compile the Linux Kernel for the Cubietruck.
  • Building the boot.scr file.
  • Set the Cubietruck leds.
  • Using the USB OTG as HID or mass storage device.

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.

Download ploplinux-desktop-24.2-arm.tar.gz and cubietruck-boot.tar.gz.

• On the SD Card, create one partition for Plop Linux.

• Create an Ext3 file system on the 'mkfs.ext3 /dev/PARTITION1'. Minimum size is 7 GB (or 3 GB without /opt).

Note: /dev/PARTITION1 is only a placeholder. You have to set the device node of your partition. Example: /dev/sdd1

• Mount the Partition to '/mnt'.

• Extract the ploplinux-desktop-24.2-arm.tar.gz archive to '/mnt'.

• Move the directories in '/mnt/ploplinux-desktop-24.2-arm/'. one directory up that they became the root directories on the Plop Linux partition.

• Remove the empty '/mnt/ploplinux-desktop-24.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'

Note: /dev/SDCARD is only a placeholder. You have to set the device node of your SD Card. Example: /dev/sdd

Note: I am using the U-Boot binary of ARCH Linux.

• A few important files (the default settings should be ok):

Edit '/mnt/etc/fstab' to your system setup.

Edit the Cubietruck section in '/mnt/etc/rc.local'.

• Unmount '/mnt'.


Now boot your Cubietruck. Continue with the personalisation of your fresh system. See here for general Plop Linux Desktop configurations and here for ARM related configurations.


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.

The stable Kernel: git clone https://github.com/cubieboard/linux-sunxi.git

The next Kernel: git clone https://github.com/linux-sunxi/linux-sunxi.git -b sunxi-next

Or download and extract the Kernel Source Code (used by Plop Linux) linux-sunxi-next.tar.xz

• Change to the Linux Kernel directory 'cd linux-sunxi' and setup base configuration

Run 'make sunxi_defconfig'.

Or use the Plop Linux config file. Copy .config to the 'linux-sunxi' directory.

Note: To add additional configurations run 'make menuconfig'.

• 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.
Mount example (Cubietruck IP: 10.0.0.208): sshfs root@10.0.0.208:/ /mnt


Building boot.scr


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'.


Cubietruck leds


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

  • a hidg_func_descriptor structure
  • a platform_device structure
  • and "platform_device_unregister (&my_hid);" in the __exit hidg_cleanup(void) function

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:

  • Create a 100MB file: dd if=/dev/zero of=/var/disk.img bs=1M count=100
  • Create a file system on the disk image: mkfs.ext3 /var/disk.img
  • Mount the image file: mount -o loop /var/disk.img /mnt
  • Create a test file on the disk image: echo "Hello there" > /mnt/test.txt
  • Unmount the image file: umount /mnt

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.




© 2024 by Elmar Hanlhofer