Running Linux on a tablet with the Allwinner A10 SoC on board

Background


I bought a tablet for the Sowin Allwinner A10 ( sun4i is the code name for the AllWinner A10 ARMv7-A processor of the Cortex architecture of the A8 core family ). At first I played with it on Android 2.x and then on 4.x, but over time it became not enough for me. Moreover, minicomputers based on this SoC with Linux on board began to produce. I thought: “Hmm, what’s worse than my tablet?” And got down to business. As it turned out, everything had already been done for me, and there was no need to do things :
  1. The kernel has been optimized for this platform.
  2. Bootloader optimized for this platform
  3. New debian armhf port released .

It remains only this whole thing is configured and assembled.

Wednesday


System - ArchLinux x86-64. I won’t describe where to find and how to install the environment for the assembly, on the Internet this information is enough. Yes, and most of this is not why, I will make everything necessary collected.
My "kitchen" is this:
  • qemu-user-static - in order to be able to chroot in rootfs, there were no reps, I had to get and collect my package from the debian repository. This whole thing is necessary to run arm elf executable files on a machine with a different architecture, in this case, mine.
  • gcc version 4.6.1 ( Sourcery CodeBench Lite 2011.09-70) - GCC ARM cross-compiler. Maybe the old one, but it doesn’t let me down yet. I advise you to put a fresh cross-compiler from linaro.

SoC boot process


  • brom (looking for a bootloader in mmc, nand, usb called boot0 (the SPL - Second Program Loader: sun4i-spl.bin).
  • boot0 (the SPL - Second Program Loader: sun4i-spl.bin) initializes devices
  • SPL (boot0) boots u-boot (boot1)
  • u-boot (boot1) initializes the remaining devices and creates abstractions for working with hardware
  • Loads the hardware configuration file (script.bin. Evb.bin, mele.bin sys_config.bin) next to u-boot like initrd.
  • u-boot loads the kernel.

Those. Download starts with an SD card, if there is no bootloader there, it continues with NAND Flash.
According to the documentation for the allwinner-uboot bootloader, the structure of the SD card should look like this:
Startthe sizedescription
08KBUnused, available for partition table etc.
824KBInitial SPL loader
32512KBu-boot
544128KBenvironment
672352KB reserved
1024Free for partitions

U-boot assembly

It is not necessary to collect, sun4i-spl.bin u-boot.bin can be downloaded here .
Build uboot-allwinner:

git clone git://github.com/hno/uboot-allwinner
cd uboot-allwinner
make sun4i CROSS_COMPILE=arm-none-linux-gnueabi-
cd ..

Bootloader entry



Caution, be careful not to confuse the SD card device with other media. If you do not understand what you are doing, then do not do it better.
$ {SD} - device variable, can be replaced manually, you can register before execution:
export SD=/dev/sdb 

#Копируем SPL (boot0)  первичный загрузчик на SD
dd if=uboot-allwinner/spl/sun4i-spl.bin of=${SD} bs=1024 seek=8 conv=notrunc
#Записываем вторичный (boot1) u-boot загрузчик на SD
dd if=uboot-allwinner/u-boot.bin of=${SD} bs=1024 seek=32 conv=notrunc


We break the microSD drive



Attention, as a result of the operation, data on MicroSD drives will be lost, save everything you need in a safe place.
  • We need to create two sections necessarily.
  • The first section is the section with the iron configuration file (evb.bin) and the kernel (uImage). It should start from sector 2048, be 32MB-100MB in size and have the FAT file system (partition type FAT) or ext2 / 3 (partition type 83).
  • The second partition is the rootfs partition, the whole system itself, it is desirable to make the partition size within 1GB-4GB, the file system is strictly ext4, the partition type is 83.
  • You can make another swap section, if desired.
  • Use the remaining space for yourself. I created a section for my data, you can mount in / home /

Here is how I broke my 16GB card:
fdisk -l /dev/sdb
Disk /dev/sdb: 15.9 GB, 15935209472 bytes
64 heads, 32 sectors/track, 15197 cylinders, всего 31123456 секторов
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000728ca
Устр-во Загр     Начало       Конец       Блоки   Id  Система
/dev/sdb1            2048       34815       16384   83  Linux
/dev/sdb2           34816     6326271     3145728   83  Linux
/dev/sdb3         6326272    31123455    12398592   83  Linux

According to the points described above, we break the microSD drive.
I hope those who use linux can use fdisk.
fdisk ${SD} 



Formatting:

mkfs.vfat ${SD}1 -n sun4i-boot
mkfs.ext4 ${SD}2 -L sun4i-rootfs

Mount in the right place:
mkdir /mnt/sun4i-boot
mkdir /mnt/sun4i-rootfs
mount ${SD}1 /mnt/sun4i-boot
mount ${SD}2 /mnt/sun4i-rootfs

Kernel assembly



You can’t compile the kernel, I attached the finished kernel with modules from below.
#Клонируем репозиторий
git clone git://github.com/amery/linux-allwinner.git
#Сборка ядра
cd linux-allwinner
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- sun4i_defconfig
#Конфигуриуем ядро
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-  gconfig 

Instead of gconfig, you can use the taste of xconfig (qt interface) or menuconfig (console interface). Do not forget to include the necessary drivers in the kernel as well as the features you need. Read the tips for the options.
I advise you not to forget about the touchscreen modules and fs (fat, ntfs).
#Компилируем
make ARCH=arm CFLAGS="march=armv7-a -mfloat-abi=hard -mfpu=neon -ftree-vectorize -mvectorize-with-neon-quad -mcpu=cortex-a8 -mtune=cortex-a8 -mthumb -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -ffast-math"  CROSS_COMPILE=arm-none-linux-gnueabi- -j3 uImage modules
#Устанавливаем модули
make ARCH=arm CFLAGS="march=armv7-a -mfloat-abi=hard -mfpu=neon -ftree-vectorize -mvectorize-with-neon-quad -mcpu=cortex-a8 -mtune=cortex-a8 -mthumb -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -ffast-math" CROSS_COMPILE=arm-none-linux-gnueabi- -j3 INSTALL_MOD_PATH=/mnt/sun4i-rootfs
#Ядро копируем в boot раздел
cp arch/arm/boot/uImage /mnt/sun4i-boot

The -j argument specifies the number of simultaneous compilation threads. It has been experimentally established that there should be one more thread than the cores in the processor.
Optimization flags are taken from ValdikSS article . Honestly, the kernel compiled with them. But I have not yet installed it on an SD flash card.

Install rootfs


I won’t describe how to load initial rootfs using debootstrap , since this is worthy of another article. I’d better put a ready-made rootfs Debian Wheezy ARMHF, and you use it.
Rootfs must be unpacked with the attributes stored on the second SD partition, since u-boot is configured in this way by default (you can read about the configuration here .
Download Debian Wheezy Rootfs and unpack:
tar -xpf debian-wheezy-armhf-rootfs.img.tar.bz2 -C /mnt/sun4i-boot

By the way, there are also modules to the kernel 3.0.36+. Also there is lxde, slim with autoload of the user user, network-manager, nm-applet starts at the start of the session. The touchscreen works in touchpad mode.
It is likely that udev will load all the necessary modules, but for certainty they can be written in / mnt / sun4i-rootfs / etc / modules. A list of required modules can be obtained in AndroidOS via TerminalEmulator:
TerminalEmulator: $ lsmod
lsmod

either through ADB:
adb shell lsmod

Linux boot setup

Download the archive with the contents of the first boot partition.
And extract the evb.bin configuration file in / mnt / sun4i-boot from the archive.
tar -xf debian-wheezy-armhf-boot.tar.bz2 evb.bin -C /mnt/sun4i-boot

If you did not build the kernel, then the assembled kernel 3.0.36+ can also be extracted:
tar -xf debian-wheezy-armhf-boot.tar.bz2 uImage -C /mnt/sun4i-boot

Launch

Everything, perhaps, is ready. We installed the system on an SD drive. We insert the microSD card into the card reader of the tablet and turn it on. 5 seconds after switching on, the backlight should light up, the screen will remain black. After a few minutes, the entire system should boot.
Remember, the default password for root is root, for user is user. I advise you to change them.
If you do not have a usb keyboard, then a virtual keyboard is preinstalled in rootfs.
We connect to a wifi network, or use a USB Ethernet adapter and using nm-applet we connect to the network. You can immediately connect via ssh.
We start lxterminal and we deliver the necessary software.
sudo -i
apt-get update
apt-get install vlc geany 

Possible problems


  1. If you can’t see anything after turning on, maybe the download is still in progress, wait about 5 minutes. But if there’s not even a highlight, then you will need to replace evb.bin with your configuration file from the android firmware located on nanda.
    On an Android device via Terminal Emaulator or through adb:
    adb shell
    su
    mkdir /local/data/tmp/nanda
    mount /dev/block/nanda /local/data/tmp/nanda
    

    We extract script.bin by any means, I did this:
    $ adb pull /local/data/tmp/nanda/script.bin evb.bin
    cp evb.bin /mnt/sun4i-boot/
    

  2. If there is still a backlight, but the system has not booted, you can view the system logs by removing the MicroSD card from the tablet and mounting it in / mnt / sun4i-rootfs
    cat /mnt/sun4i-rootfs/var/log/dmesg
    cat /mnt/sun4i-rootfs/var/log/Xorg.0.log
    

  3. If the touch does not work, then you need to find out in Android which module is responsible for your touch:
    Method via ADB:
    adb shell 'lsmod | grep ts'
    

    Method through TerminalEmulator
    lsmod |  grep ts


    and write it / mnt / sun4i-rootfs / etc / modules.

Conclusion

So I launched linux on my MOMO9 tablet. The system has not yet been fully configured, it would not hurt to configure the same laptop-mode and deliver the necessary packages. Time was spent quite a bit. But then, having assembled the system “almost” from scratch, you immediately begin to understand how this OS works. The vocabulary of special English vocabulary is also replenished, which is also not bad.
Debian Wheezy on MOMO9 screenshots
Here is a screenshot taken on the device itself using the import utility from the MagickImage package.
image
real
I shot the phone on the camera, there was no other at hand, so I'm sorry.

And of course, I do not bear any responsibility for what you do on your PC, for damage to equipment. Do everything with understanding. Do not confuse the SD card reader with a hard drive or other device.

UPD:


  1. SoC boot process. Description on the forum.
  2. Процесс загрузки SoC.
  3. .config файл можно достать из уже скомпилированного ядра с помощью скрипта, который находится в папке с исходниками ядра linux-allwinner/scripts/extract-ikconfig. Я это к тому, что вы можите не конфигурировать новое ядро сами с нуля, а использовать файл конфигурации со старого ядра, только при компиляции у вас запросит скрипт сборки, что с новыми возможностями и модулями ядра делать (включать в ядро либо не включать в образ ядра ).
  4. RZK333 добавил источники: канал Rhombus-Tech #arm-netbook@freenode, откуда собственно все авторы того что ты описываешь (патчи для ядра, патчи для u-boot, разбор SPL, загрузка с SD) и linux-sunxi.org куда все было сложено. На канале не был, а вот на вики информация интересная.
  5. Много черпнул из данного топика. Linux на AllWinner A10, Принцип работы, обсуждение и сборка ядер
  6. Added some screenshots.
  7. I do not pretend to be the most correct way to install, maybe I don’t understand some things, since I just started to study this area. Therefore, I ask you, if you notice some inaccuracies, do not be “shy” to correct me. I will only be grateful to you.

Also popular now: