Friday, 15 February 2013

I.MX6 GK802/Hi802 - A working Kernel with Ubuntu

The Hi802/GK802 mini-pcs are interesting devices because of the vast reference documentation available for the IMX6Q processor. Freescale are also providing a HDMI TV Dongle reference design complete with source code, the Hi802/GK802 are partially based on this design. With this is mind and after spending many hours decoding the pcb layout coupled with bouts of head scratching, I finally got a kernel booting ubuntu. This is a work in progress but hopefully will kick start further development by community see here. Considering this is work in progress you definitely require serial console access if booting fails. Furthermore I'm testing on a GK802 with 1.2 CPU version therefore no guarantee on a 1.1 CPU which I think are GEN 1 or for Hi802 devices.



1. Kernel Boots from SD card.
2. USB port functions with USB hub (for me works with keyboard and mouse).
3. Serial console shell active.
4. HDMI output is set to 1280x720@60.
5. Ubuntu Desktop launches but freezes randomly :(. Not that use-able in its current state.
6. No wifi or bluetooth. Wifi shouldn't be too hard to add.

So if your keen or want to help out, instructions below, I assuming you know how to use git and have armel compiler (I use arm-linux-gnueabi-) :

1. Check out the Freescale imx6 kernel tree and checkout imx_3.0.35_1.1.0. I found 1.1.0 to be more stabe than the 2012-09-01 branch.

    cd linux-2.6-imx
    git checkout imx_3.0.35_1.1.0
          
2. Down this tar file containing patches and kernel config (thanks to miniand.com for provding hosting). Extract and apply patches

    git apply gk802_patch_1.patch
    git apply gk802_patch_2.patch

3. Make kernel config

    make ARCH=arm imx6_defconfig
    make ARCH=arm menuconfig
        
4. Copy the file kernel_config to .config 

    cp kernel_config .config

5. Build the kernel and modules

    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=output      modules     
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=output modules_install

6. Download the rootfs L3.0.35_1.1.0_UBUNTU_RFS from the freescale website. You may need to create an account to access to the files.

7. To create a bootable SD card, I took the bare ubuntu image from here (thanks ArmTvTech.com and   dylandn ) and dd'd this to the card. I then reformated the ext4 partition and untar'd the rootfs 
L3.0.35_1.1.0_UBUNTU_RFS to it.

8. Next step is to copy the new kernel and modules over:

    sudo dd if=arch/arm/boot/uImage of=/dev/<device> bs=1048576 seek=1 && sudo sync

    sudo cp -r output/lib/modules/3.0.35-05236-gc9dfae3-dirty /media/ubuntu/lib/modules


9. Now try to boot, fingers crossed you should see the kernel trace output appearing and finally a command shell in the serial console.

generic-usb 0003:413C:2107.0002: input,hidraw1: USB HID v1.10 Keyboard [Dell Dell USB Entry Keyboard] on usb-fsl-ehci.0-1.4/input0
EXT4-fs (mmcblk0p1): couldn't mount as ext3 due to feature incompatibilities
EXT4-fs (mmcblk0p1): couldn't mount as ext2 due to feature incompatibilities
EXT4-fs (mmcblk0p1): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device 179:1.
Freeing init memory: 184K
 * Starting mDNS/DNS-SD daemon[ OK ]
 * Starting load fallback graphics devices[ OK ]
 * Starting Userspace bootsplash[ OK ]
 * Stopping load fallback graphics devices[ OK ]
 * Starting configure network device security[ OK ]
 * Starting Mount network filesystems[ OK ]
 * Starting Upstart job to start rpcbind on boot only[ OK ]
 * Stopping Upstart job to start rpcbind on boot only[ OK ]
 * Starting network connection manager[ OK ]
 * Stopping Mount network filesystems[ OK ]
 * Starting Failsafe Boot Delay[ OK ]
 * Stopping Failsafe Boot Delay[ OK ]
 * Starting System V initialisation compatibility[ OK ]
 * Starting configure network device[ OK ]
 * Starting Bridge socket events into upstart[ OK ]
 * Starting RPC portmapper replacement[ OK ]
 * Starting Start this job to wait until rpcbind is started or fails to start[ OK ]
 * Stopping rpcsec_gss daemon[ OK ]
 * Stopping Start this job to wait until rpcbind is started or fails to start[ OK ]

[ OK ]rting Advanced Power Management daemon...        
Last login: Thu Jan  1 00:00:41 UTC 1970 on tty1
speech-dispatcher disabled; edit /etc/default/speech-dispatcher
Checking for running unattended-upgrades: 
[ OK ]rting bluetooth        
 * PulseAudio configured for per-user sessions
saned disabled; edit /etc/default/saned
 1 Jan 01:36:59 ntpdate[5241]: no servers can be used, exiting
Welcome to Linaro 11.10 (development branch) (GNU/Linux 3.0.35-02666-gc27cb38-dirty armv7l)

 * Documentation:  https://wiki.linaro.org/

301 packages can be updated.
53 updates are security updates.

New release '12.04 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

root@linaro-ubuntu-desktop:~# 


10. Your HDMI display should show a Ubuntu desktop after a while. If the desktop appears then try launching a terminal window which should appear without it freezing. Once the deskop freezes it can be recovered in the serial console shell by:

    service lightdm stop
    service lightdm start

Xorg is reporting the following error when frozen:

[    71.433] (II) XKB: reuse xkmfile /var/lib/xkb/server-A77BBE312A49C9FE89948D38B2A8CB84C3CBB410.xkm
[   101.398] (II) XKB: reuse xkmfile /var/lib/xkb/server-A77BBE312A49C9FE89948D38B2A8CB84C3CBB410.xkm
[   181.556] [mi] EQ overflowing. The server is probably stuck in an infinite loop.

Monday, 31 December 2012

Hackberry A10 : Ubuntu 12.10 with Razor-qt

Having heard about Razor-qt, I thought I would give it a go on the Hackberry. Razor-qt is a light-weight desktop built for simplicity and speed. It is also intended to target 'weak machines' therefore I was hoping it would perform well on the Hackberry giving that we still lack full hardware acceleration.



To start with I reused my XBMC image which is basically a Ubuntu 12.10 install complemented with a 3.0.42+ kernel. You can remove the xbmc install by removing the /allwinner (ie rm -rf /allwinner).

I couldn't find a pre-compiled armhf package of raxor-qt therefore I built from scratch (using root user) following the build instructions here as a guide. Fortunately the xbmc image already includes most of the build tools for compilation.

Download the latest release and untar to a directory (eg src/razor) :

    mkdir src; cd src; mkdir razor;
    wget https://github.com/downloads/Razor-qt/razor-qt/razorqt-0.5.1.tar.bz2
    tar xvf razorqt-0.5.1.tar.bz2 razorqt-0.5.1
    cd ..
    mkdir build
    
Before building get some additional packages for building:    

    apt-get install qt4-dev-tools qt4-designer
    apt-get install libmagic-dev

Now build (this takes a bit of time) and install

    cd build
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local ../razorqt-0.5.1
    make
    make install

Once built successfully we need to replace the existing window manager fluxbox with openbox the default for razor-qt.

    apt-get remove fluxbox
    apt-get clean
    apt-get install openbox

Now we create a simple startup script to invoke razor-qt.

    echo 'exec razor-session -w openbox' > /root/.xinitrc_razor

I suggest setting the CPU governor profile to performance:

     cpufreq-set -g performance

To start razor-qt from the command line:

    cd /root
    xinit ~/.xinitrc_razor -- :1

The basic desktop has minimal applications because the XBMC image has no defaults application installed (eg browser, file manager, text editor, etc ..) however these is can be easily installed. You would also need to customise the image to your requirements ie wifi/ethernet etc. Also further work is require to auto-start razort-qt and use for non-root users.

Although the desktop experience is primitive I found it to be more responsive than the Linaro image although my main use has been for code development/compilation on the Hackberry, requiring multiple open command shells.

I also compiled the mesa-demo library to stress the windowing system/cpu along with 'openssl speed' to see how responsive the GUI would remain under load. Below is a another badly made video to demonstrate how it performs.


Saturday, 22 December 2012

Hackberry A10 - Booting Android from an SD Card

Having spent many hours attempting to get a custom kernel booting for the factory Android image, I found that is was easier to first create an factory Android image that would boot from an SD card. The main advantage is that it removes the arduous steps of packaging a complete image and then re-flashing to Nand for each small change.  It also opens up the possibility of booting other Android distributions from an SD card.

To start with I created a mirror image of the nand paritition on an SD card, to do this requires a linux installation. The nand partitions range from A-K as are covered in more detail here. I used gparted to create the partitions with the correct sizes as below, it is important that you leave 16MB free at the start of the SD card for uboot (shown by 'unallocated' partition) .  You need to create an extended partition (shown by /dev/sdc4) in order to create more than 4 partitions.



You need to create an additional partition on the SD card to represent the extrernal sd card /mnt/extsd, I created a FAT32 partition which becomes /dev/sdc13 (mmcblk0p13).

Next step is to copy across all the nand partitions from the hackberry. This can be done by booting the hackberry with a linux distro and using the linux dd command to copy the partitions to files. I copied the partitions on to a usb stick (needs to be at least 4GB) as below:

   dd if =/dev/block/nanda of=nanda
   dd if =/dev/block/nandb of=nandb
   dd if=/dev/block/nandc  of=nandc
   ...
   ...
   dd if=/dev/block/nandk  of=nandk

Once all the nand files are created we can 'dd' the files to the SD card. The boot partition file nandc is not copied because we need to extract the rootfs from it and create a ext4 partition. The bootloader  file nanda is also not copied as we create our uboot on FAT16 partition (/dev/sdc1). Assuming the SD card shows up as /dev/sdc I executed the following (amend /dev/sdc with correct device name for your SD card).

   
   sudo dd if=nandb of=/dev/sdc2
   sudo dd if=nandd of=/dev/sdc5 bs=1M
   sudo dd if=nande of=/dev/sdc6
   sudo dd if=nandf of=/dev/sdc7
   sudo dd if=nandg of=/dev/sdc8
   sudo dd if=nandh of=/dev/sdc9
   sudo dd if=nandi of=/dev/sdc10
   sudo dd if=nandj of=/dev/sdc11
   sudo dd if=nandk of=/dev/sdc12 bs=1M
   sudo sync

Next I extracted the ramdisk rootfs from the nandc file, fortunately I have done this for you. Download the file android_sd.tar.gz, it contains  all the additional files required to create a bootable sd card. If your interested how I extract the kernel and rootfs I used the split_bootimg.pl utility, further info here.  I also fixed the files init.sun4i.rc and ueventd.sun4i.rc so that they refer to the sdcard paritions /dev/ /dev/mmcblk0pX instead of /dev/nandX.

The mapping between nand and mmcblk0p are shown below

   nanda -> mmcblk0p1  
   nandb -> mmcblk0p2
   nandc -> mmcblk0p3       
            mmcblk0p4              
   nandd -> mmcblk0p5       
   nande -> mmcblk0p6       
   nandf -> mmcblk0p7       
   nandg -> mmcblk0p8       
   nandh -> mmcblk0p9       
   nandi -> mmcblk0p10      
   nandj -> mmcblk0p11      
   nandk -> mmcblk0p12    

Take the nandc file from the zip file and dd it to the correct SD card parition, in my example it is /dev/sdc eg:

   sudo dd if=nandc of=/dev/sdc3


I then changed all references in the script files on the system partition (/dev/sdc5 in my example) from /dev/nandX to /dev/mmcblk0pX.  The files to amend are:

   ./etc/vold.fstab
   ./bin/preinstall.sh
   ./bin/sop.sh

You need to edit ./etc/vold.fstab and replace the /mnt/extsd  with the following:

dev_mount extsd   /mnt/extsd   auto  /devices/virtual/block/mmcblk0p13

Next I converted the extracted kernel from the nandc file to be uboot compatible, again in the download zip there is a pre-built file (uImage). If your interested, I used the following command to convert the kernel:

    mkimage -A ARM -C none -T kernel -O linux  -a 40008000 -e 40008000 -d nandc-kernel uImage

Copy the uImage file to first partition on the SD card (this is bootloader FAT16 partition which is empty ). Also copy the uboot config files uEnv.txt and boot.scr to the first partition.

Finally I copied the Hackberry uboot files sunxi-spl.bin and u-boot.bin to the SD card to make it bootable. This is the reason for the leaving 16MB free at the start of the SD card.

    sudo dd if=sunxi-spl.bin of=/dev/[drive] bs=1024 seek=8
    sudo dd if=u-boot.bin of=/dev/[drive] bs=1024 seek=32
    sudo sync

I suggest you delete everything of the data partition (eg /dev/sdc6), this will ensure the correct device partitions are found and recorded on the first boot. It would be prudent to hook up a serial console to the Hackberry to monitor boot progress in case of failures. Insert the SD card into the Hackberry and power up.

Once you have Android booting, turn off media scanning for the SD card. This option is in Setting->Storage>"Enable media scanning on SD".

If want to try deploy another kernel (assuming the kernel and modules are compatible with the Android image) then:

  1. Copy the newly built uImage file to the first partition of the SD card.
  2. Copy the modules to the /vendor/modules on the system partition of the SD card.

Sunday, 11 November 2012

Hackberry A10 - XBMC

I spent some time creating a working XBMC image for the Hackberry because of the increased interest generated on the xbmc forum. Firstly a big thanks to numerous contributors (empatzero,rellla,shivansps,gimli) on the xbmc forum for getting the cedar libaries integrated and getting a build-able xbmc for the A10 soc.

The latest compiled version of xbmc is towards the end of this post if just want to download it works on hackberry and should work on any distro with fb support (for non hackberry deployment).

Standard disclaimer at this point, its an unsupported release as there are many untested/non-working features but hopefully gives you a taste of progress or starting point for further improvements. Furthermore there's nothing stopping you getting this running on other A10 devices, at minimum you will need to replace script.bin, uboot and if no ethernet remove this from /etc/network/interfaces otherwise there will be a long delay before you see a command prompt on the screen. Lastly you may also need to replace the kernel.

To start with I took guillaume ubuntu 12.10 (armhf) build and reworked it so that it boots for the Hackberry from an SD card using a 3.0.42+ kernel (revision cbf3d41b7ed513a743854fde1ca0b5c4d0f11610 + my wemac patch). Again thanks to guillaume for such a useful headless build. One of the highlights of this build is that it presents an on screen command console, meaning there is no longer a reliance on ssh for a command shell. The main issue with the build seems to be graphical tearing while editing at the command line, something I can live for now. The build still starts an ssh daemon if you need access through Ethernet (host name is hackberry, try ssh root@hackberry). There's nothing stopping you using the image without xbmc, although it currently it assumes a default resolution of 1280 x 720 which is required by xbmc.

I created an armhf build of xbmc which was compiled on the Hackberry (taking numerous hour to complete, something to leave overnight). I mainly followed the instructions here.

Download the image (its quite large 722Mb) and dd (or equivalent in Windows) to an SD card, the image expands to 4GB but only takes around 2GB and should easily fit on a 4GB card. Repartition the ext3/ext4 partition to make use of the remaining space on your SD card. Instructions to dd the image:

    gunzip
    dd if=xbmc_hackberry.img of=/dev/<device> bs=1M
    sudo sync

You should alter script.bin (on the FAT partition) to contain a different mac address if you intend to use ethernet, more instruction here.

Boot the Hackberry with the newly created SD card and hopefully the command console should appear on your display:

    Ubuntu 12.10 hackberry tty1

    hackberry login :

To logon user/password is root and to start xbmc

    cd /allwinner/xbmc-pvr-binhf/lib 
    xbmc/xbmc.bin

Fingers crossed the xbmc log should appear followed by the main screen. Plug-in a keyboard/mouse to navigate.



Short video to demonstrate how well it runs (unfortunately no sound as I was using a hdmi to vga adapter).



I tried a 1080p video (.mov) which it played without any problems.

To enable audio,  go to setting and cycle through audio adapters and until sound is heard. For me thiss worked for hdmi and also through the hackberry AV port (the socket nearest to the usb ports).

I couldn't exit xmbc using the menu options, 'Power off System' occasionally worked but dropped to the command line. In the end I resorted to ssh'ing and powering down (shutdown -Ph now).

I compiled a new xbmc version based on commits as of  01-12-2012 from empatzero's repo. Main change as per commit log is:

FIXED MPEG4 CODECS: FLV1, WMV2, DIVX4, DIVX4, DIVX5, XVID.

Download xbmc_01_12_2012.tar.gz, which  contains the contents of the allwinner directory and replace with the existing one on the image. Beware the allwinner directory is owned by root on the image. Copy the downloaded tar file to the hackberry and then untar, example below.

    cd /
    tar xvf xbmc_01_12_2012.tar,gz

For those looking to make modifications or build from source, the repository I used is git://github.com/empatzero/xbmca10 along with following the instructions here to a greater extent.

Saturday, 27 October 2012

Hackberry A10 - Extra USB Ports

As discovered by Adrian on the miniand forums, the Hackberry has an on-board USB Hub (Genesys Logic GL850G) resulting in the board providing up to 6 usb ports. 1 port is used by the wifi module, another are 2 exposed by the double connector next to the HDMI port. Out of the remaining 3, 2 are available through solder pads on the pcb. 

One is located on the rear of the board as shown below.
This one seems better suited to a on board module such a bluetooth or another wifi. The difficultly arises from sources a module that matches the dimensions of the 4 pin layout. 







The second port is located on the front side of the board near to the SD card and is easily recognised by the tracing lines for a Type A USB connector.You could try to populate this one with a Type A connector although because the solder pads aren't holed there nothing to keep the connector in place apart from soldering the connector housing to their solder pads.




After some deliberation I decided to see if it was possible to solder a 0.1" 4 way pcb header to the four usb pads. This solution allows for a plug-n-play style usb port connector, use it when you want! The problem of using a stand vertical pcb header like this is that there is little support for it once solder due to the lack of through holes for mounting. To overcome this I used a right angled version of the connector which first was soldered the wrong way (ie the pin without the plastic support the soldered) and after successful soldering I prised off the plastic supports from the vertical pins.





The next stage was to create a pluggable usb connector, this required a 4 way 0.1" right angle header, a Type A usb connector and a small strip of vero board. I soldered the 4 way header and Type A connector onto the vero board. 










Once done I could plug the pluggable usb connector onto the pins on the hackberry using a jump cable made from two 4 way 0.1" female connectors. 







Last step was to test it worked, for this I plugged in a usb stick. 

When I don't require the usb port I can easily remove the jump cable.











Hackberry A10 - Java benchmarks

Having not seen any benchmarks for running Java on a A10 device, I thought I would performed some benchmarks using dacapo bench suite. Currently the Oracle JDK for ARM is only available for armel, armhf is reportedly faster therefore I conducted these tests with OpenJDK 7 (IcedTea7 2.1.2) using my debian wheezy image with a hard-float compiled kernel.

OpenJDK 7 includes support for 3 JVM's - JamVM, Cacao and Zero/Shark. Unfortunately Cacao failed to run with dacapo therefore there it is excluded from our tests. OpenJDK7 is currently classed as 'testing' in the Debian repository which may explain the Cacao failure.

Below are the results for JamVM and Zero, times are in milliseconds.

Dacapo
Test
JamVM Zero/Shark
avrora 278216 196867
eclipse 1173809 837472
fop 46093 35759
jython 553172 373691
luindex 56140 52659
lusearch 243673 202925
pmd 88551 97203
sunflow 1283857 729727
tomcat 131739 FAILED
xalan 305040 255660


Overall Zero performs better than JamVM apart from the failure in the tomcat test. There is another JVM available for OpenJDK that is  Avain it's a small lightweight and fast JVM. There is a Arm port available in the Debian repository unfortunately it is classed as 'unstable' and I couldn't get it to execute with dacapo. It is possible to compile Avain from source unfortunately I didn't have time to do so. 

If we compare these results to similar benchmarks for the Raspberry PI, then OpenJDK 7 does seem to redeem itself on the A10 platform. Although we are not comparing apples with apples (cortex A8 v ARM1176) it is encouraging to see that the figures compete with Oracle JDK 7 (amel) albeit on the PI. Oracle JDK 7 is know to perform better than OpenJDK and it is a shame we still don't have an armhf version to benchmark against. Hopefully Oracle will release something soon!  

Sunday, 14 October 2012

Hackberry A10 - Compiling a kernel (armhfs)

I've had quite a few requests to include or create kernel modules for the debian image. So here are instruction to compile a kernel. There's plenty of information on the web for compiling kernels for the A10 and its not that difficult. All you require is a machine with Linux. Its best to do some background reading on using 'git' if you are not familiar with it. These instructions are for Ubuntu.

I've updated these instructions so that they use hard float instead of soft float which should give an increase in performance. 'arm-linux-gnueabi' is replaced with 'arm-linux-gnueabihf'

First retrieve the build and cross compiler tools:

sudo apt-get install gcc-arm-linux-gnueabihf build-essential git uboot-mkimage libncurses5-dev

Next create a directory where you want build the kernel and retrieve the kernel source from git. This will take some time. Note the old repository was git://github.com/amery/linux-allwinner.git it has now move to git://github.com/linux-sunxi/linux-sunxi.

mkdir kernel
cd kernel
git clone git://github.com/linux-sunxi/linux-sunxi 

Now switch to branch you are interested in, the current stable is linux-sunxi.  For debian I'm currently using revision 23e5456879db0175f571dec43095c49e181e0b10 (3.0.36+). Note kernels version beyond 3.0.36+ ethernet (eth0) on the hackberry fails to initialise correctly, see my patch at the end of the blog for a temporary fix.

cd linux-sunxi
git checkout 23e5456879db0175f571dec43095c49e181e0b10

next step is to create a default kernel config, this creates a .config file.

make ARCH=arm sun4i_defconfig

now to add additional modules or change kernel settings do

make ARCH=arm menuconfig

Now can compile the kernel and modules

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j3 uImage
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j3 INSTALL_MOD_PATH=output modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j3 INSTALL_MOD_PATH=output modules_install

Last step is to copy the kernel (uImage) to the boot fat partition and the kernel modules to the ext4 partition. Note keep track of the kernel version that is in .config as this will determine which modules directory has to be copied across. Here is the example for the debian image and git revision 23e5456879db0175f571dec43095c49e181e0b10.

cp arch/arm/boot/uImage /media/BOOT/
cp -rp output/lib/modules/3.0.36+/kernel /media/debian/lib/modules/3.0.36+



---------------------------------------------------------------------------------
Patch for ethernet initialisation failure:

--- a/drivers/net/sun4i/sun4i_wemac.c

+++ b/drivers/net/sun4i/sun4i_wemac.c
@@ -53,7 +53,7 @@
 #define DRV_VERSION    "1.01"
 #define DMA_CPU_TRRESHOLD 2000
 #define TOLOWER(x) ((x) | 0x20)
-#define PHY_POWER 0
+#define PHY_POWER 1
 /*
  * Transmit timeout, default 5 seconds.
  */
@@ -1563,7 +1563,8 @@ static int wemac_phy_read(struct net_device *dev, int phyaddr_unused, int reg)
        writel(0x1, db->emac_vbase + EMAC_MAC_MCMD_REG);
        spin_unlock_irqrestore(&db->lock, flags);

-       wemac_msleep(db, 1); /* Wait read complete */
+       //      wemac_msleep(db, 1); /* Wait read complete */
+        udelay(150); /* 100 */

        /* push down the phy io line and read data */
        spin_lock_irqsave(&db->lock, flags);
@@ -1596,7 +1597,8 @@ static void wemac_phy_write(struct net_device *dev,
        writel(0x1, db->emac_vbase + EMAC_MAC_MCMD_REG);
        spin_unlock_irqrestore(&db->lock, flags);

-       wemac_msleep(db, 1);            /* Wait write complete */
+//     wemac_msleep(db, 1);            /* Wait write complete */
+        udelay(150); /* 100 */

        spin_lock_irqsave(&db->lock, flags);
        /* push down the phy io line */