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.

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:// it has now move to git://

mkdir kernel
cd kernel
git clone git:// 

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 */

Friday, 12 October 2012

Hackberry A10 - 3G Modem Support

One of the outstanding items on my long of list of 'things to do with the Hackberry' was to get my Huawei E173s 3G modem working under Debian.  This allows the Hackberry to used for remote deployments where LAN/WLAN is not possible. Furthermore there is the possibility of using the modem for reading and writing SMS messages. You can use these instructions as a template for other modems types and/or or other Linux variants.

First step is to enable ppp support in the kernel as below:

    [*] Network device support  --->     

       <M>   PPP (point-to-point protocol) support
       [*]     PPP filtering  
       <M>     PPP support for async serial ports  
       <M>     PPP support for sync tty ports      
       <M>     PPP Deflate compression 
       <M>     PPP BSD-Compress compression 
       <M>     PPP on L2TP Access Concentrator 
       <M>     PPP on PPTP Network Server            

Fortunately in my debian image the kernel is configured to include the ppp modules. Next step is to install the package usb_modeswitch which allows switching from usb storage mode to modem mode. Without this package plugging the modem into the usb port result in it being recognised as a usb storage device. At the same time we can retrieve the package usbutils and wvdial so that we run the command lsusb and configure the modem.

apt-get install usb_modeswitch
apt-get install usbutils
apt-get install wvdial

To switch modes we need to add a new rule for the modem (based on it's usb id), you can skip this step if your modem does not have usb storage support. For the E173s this means creating the file /etc/usb_modeswitch.d/12d1:1c0b with following contents:

# Huawei E173s
DefaultVendor= 0x12d1
DefaultProduct= 0x1c0b
TargetVendor= 0x12d1
TargetProduct= 0x1c05
MessageEndpoint= 0x0f
MessageContent= "55534243123456780000000000000011062000000100000000000000000000"

Next install the kernel modules for usb modem support and ppp.

insmod /lib/modules/3.0.36+/kernel/drivers/usb/serial/usbserial.ko
insmod /lib/modules/3.0.36+/kernel/drivers/usb/serial/usb_wwan.ko 
insmod /lib/modules/3.0.36+/kernel/drivers/usb/serial/option.ko 
insmod /lib/modules/3.0.36+/lib/crc-ccitt.ko
insmod /lib/modules/3.0.36+/kernel/drivers/net/slhc.ko
insmod /lib/modules/3.0.36+/kernel/drivers/net/ppp_generic.ko
insmod /lib/modules/3.0.36+/kernel/drivers/net/bsd_comp.ko 
insmod /lib/modules/3.0.36+/kernel/drivers/net/ppp_deflate.ko 
insmod /lib/modules/3.0.36+/kernel/drivers/net/ppp_async.ko 

Fingers crossed we can plug the modem into the top usb port of the hackberry. Dmesg should report some thing similar to this:

[ 2482.070000] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
[ 2482.100000] option 2-1.2:1.0: device disconnected
[ 2482.140000] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
[ 2482.170000] option 2-1.2:1.1: device disconnected
[ 2482.200000] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
[ 2482.250000] option 2-1.2:1.2: device disconnected
[ 2528.090000] usb 2-1.2: new high speed USB device number 5 using sw-ehci
[ 2528.590000] scsi4 : usb-storage 2-1.2:1.0
[ 2528.620000] scsi5 : usb-storage 2-1.2:1.1
[ 2530.960000] scsi 5:0:0:0: Direct-Access     HUAWEI   SD Storage       2.31 PQ: 0 ANSI: 2
[ 2530.990000] scsi 4:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[ 2531.050000] sd 5:0:0:0: [sda] Attached SCSI removable disk
[ 2531.090000] sr0: scsi-1 drive
[ 2531.150000] sr 4:0:0:0: Attached scsi CD-ROM sr0

And lsusb reports (note 'modem on', if 'modem off' then something is wrong):

root@(none):~# lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 002: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 002 Device 006: ID 12d1:1c05 Huawei Technologies Co., Ltd. E173s 3G broadband stick (modem on)

Last step is to configure wvdial , I found the default configuration in /etc/wvdial.conf doesn't work so here are my settings, thanks to koi-sama on the miniand forums for help with configuration. Replace tmobile section with your settings, Init2 is APN and the Username and Password are self explanatory.

[dialer defaults]
Modem = /dev/ttyUSB0
Baud = 460800
Dial Command = ATD
Init1 = ATE1
Phone = *99***1#
Stupid Mode = 1
New PPPD = 1
Dial Attempts = 10
Dial Timeout = 10

[Dialer tmobile]
Modem = /dev/ttyUSB0
Init2 = AT+CGDCONT=1,"IP",""
Phone = *99#
Stupid mode = yes
Username = ""
Password = ""
Dial Attempts = 0

Now we can attempt to connect

root@(none):~# wvdial tmobile
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: ATE1
--> Sending: AT+CGDCONT=1,"IP",""
--> Modem initialized.
--> Sending: ATD*99#
--> Waiting for carrier.
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Sat Jan  2 23:48:07 2010
--> Pid of pppd: 2099
--> Using interface ppp0
--> pppd: )
--> pppd: )
--> pppd: )
--> pppd: )
--> pppd: )
--> pppd: )
--> pppd: )
--> local  IP address
--> pppd: )
--> remote IP address
--> pppd: )
--> primary   DNS address
--> pppd: )
--> secondary DNS address
--> pppd: )

ifconfig reports

root@(none):~# ifconfig
ppp0      Link encap:Point-to-Point Protocol
          inet addr:  P-t-P:  Mask:
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:128 (128.0 B)  TX bytes:185 (185.0 B)

When I get time I will look into reading/writing sms messages from the modem.

Sunday, 7 October 2012

Hackberry A10 - Linaro 12.06 (Desktop)

I took Toby's Linaro build for the MK802 and patched it to work for the Hackberry. Thanks to Tobay for the work he put into creating the build.

You have two options for getting an image to SD card:

1. Use download my pre-built image

The image is for the 1GB board and contains my latest uboot and a 3.0.36+ kernel compiled to work with the uboot. Kernel is now compiled with hard float resulting in improved performance. It is for a 4GB SD card but the ext4 partition is only 3.5GB. Note: not all 4GB SD cards are 4GB, they may be 3.7,3.8 etc which may mean your dd may fails early. However since we only use 3.6GB hopefully it is ok. If it fails to boot try a 8GB card if you can or re-adjust the partitions on linux after creating the image. 

    gunzip linaro_hf_3.0.36_1gb.img.gz
    dd if=linaro_hf_3.0.36_1gb.img of=/dev/<device>
    sudo sync

2. Build from scratch as below:

Download Toby's last image from linaro-alip-armhf-t4.7z. Extract image from the zip to reveal linaro-alip-armhf-t4.img.

Download my uboot files sunxi-spl.bin and u-boot.bin from here.

Use the boards existing script.bin or download from here script.bin.

Copy image and uboot files to SD card:

    sudo dd if=linaro-alip-armhf-t4.img of=/dev/sdc
    sudo sync
    sudo dd if=sunxi-spl.bin of=/dev/sdc bs=1024 seek=8
    sudo dd if=u-boot.bin of=/dev/sdc bs=1024 seek=32
    sudo sync

I suggest building a kernel to ensure it works with uboot files and copy that across to the SD card.
Remove SD card and re-insert to mount drives.

Replace existing evb.bin on fat16 partition with your script.bin, eg on ubuntu do:

    cp script.bin /media/<drive label>/evb.bin

Now to test it boots:

Remove SD card and place in hackberry, connect hdmi cable to your TV/monitor and boot. Fingers crossed after a while the linaro desktop should appear. Plug in a usb mouse & keyboard and away you go.

Tuesday, 2 October 2012

Hackberry A10 - Debian Wheezy (Headless)

There seems to be demand for a minimal headless debian wheezy image for the Hackberry. So here is a pre-built image that I've created using this armhf rootfs and compiling a 3.0.36 kernel. This should easily fit on a 1GB SD card as its fairly light weight however the pre-built image is currently for a 4GB card. You can dd the image to a smaller SD card and subsequently mend the ext4 partition. Image works on the 1Gb model haven't got a 512Mb version to test with. To deploy the image to your SD card use the following commands, you  can find the <device> of your SD card by 'df -h'.

    gunzip debian_wheezy_3.0.36.img.gz
    dd if=debian_wheezy_3.0.36.img of=/dev/<device>
    sudo sync

Once the imaging is complete the SD card will contain a small fat16 partition for booting and the remaining space allocated to the rootfs (ext4).  You change the debian configuration as you like before booting. The default image is configured for eth0 (dhcp) and ssh enabled.  You can configure eth0 to a static ip address by editing /etc/network/interface. It is possible to enable wifi by editing /etc/modules to load 8192cu.ko, configuring  /etc/network/intefaces for wlan0.

Note: I have created a new uboot based on the lastest source, the two files sunxi-spl.bin and u-boot.bin can be download from here. Patch these to the SD card image:

    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

Now boot the Hackberry with the SD card if all is ok you will need to find the ip address of the Hackberry and ssh as root (password is password) eg:

    ssh root@<ip address>

You should now be presented with a shell

Linux (none) 3.0.36+ #39 PREEMPT Sun Sep 23 14:52:17 BST 2012 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Jan  1 00:00:50 2010 from mtx512-inspiron-620.lan

Free memory is currently showing at around 800K:

root@(none):~# free -m
             total       used       free     shared    buffers     cached
Mem:           814         30        784          0          2         12
-/+ buffers/cache:         15        799
Swap:            0          0          0

We can probably release more memory by removing unwanted kernel modules (eg mali) since this is a headless image.