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.