Sunday, June 24, 2012

Building WM8650 netbook kernel

So you bought a WM8650 netbook, followed my previous posts and got Arch Linux working, but... the WiFi dongle inside your netbook is not a RT8188 one, or you need ipv6 support, or you want NFS support, or maybe you want to mess with the kernel code to fix some issues. Then you need to build a new kernel.

To build the kernel, I followed this great tutorial by John Williams. All the credit for finding the kernel sources and investigating how to patch them is due to him. I only did some small modifications to support WM8650 netbooks (his tutorial covers WM8650 tablets) and to avoid changing kernel variables that could break compatibility with Android Kernel. The kernel I'll show you how to build, lacks the WiFi driver. If the USB dongle inside your netbook is supported by the drivers included in the kernel, you can enable it and it will be built. If it's not supported (as happened with mine), you'll need to search for a suitable driver, and merge it in the kernel sources. I'll explain how to do it when I get some time to write a new tutorial.

The infamous menuconfig screen

You will need a compiler. You can install gcc and binutils in your WM8650 netbook and do all the process inside it. Building the kernel in the netbook takes about 15 minutes. You can also build it in your PC using a cross compiler for armv5te architecture. This will take a lot less time, but getting the compiler working can be a bit tricky. I'll not explain how to build/install a cross compiler, since there are a lot of good tutorials covering it, all over the net.

Once you have your compiler set up, we can start working. The first step is downloading the sources. Unfortunately the sources for the kernel that come with the Android distro aren't easy to find. There are some sources from Wondermedia available, but they lack the code for some drivers, and also include some binary blobs. An older version of the kernel sources included some of the missing drivers, and can still be found on the Internet. The first thing we must do is to download sources for both the older and the newer kernel, then unpack the older kernel and then unpack the newer kernel overwriting the older one. This way we get the drivers missing in the newer kernel, but with all the bugfixes and improvements of the newer kernel. Then we must clean the kernel tree:

wget http://ftp.gpl-devices.org/pub/vendors/Wondermedia/WM8650/KERNEL-DS_ANDROID_2.6.32_WM8650.111209.1514.tgz
wget http://projectgus.com/files/wm8650/KERNEL-DS_ANDROID_2.6.32_WM8650.110408.1903.tgz
tar -xzf KERNEL-DS_ANDROID_2.6.32_WM8650.110408.1903.tgz
tar -xzf KERNEL-DS_ANDROID_2.6.32_WM8650.111209.1514.tgz
cd ANDROID_2.6.32-DS/ANDROID_2.6.32
make distclean

Now we must set the kernel configuration and patch the kernel with the code to fix battery readings, ethernet, etc. Download this patch to the working directory and type in the console:

tar -xjf wm8650_netbook.patch.tar.bz2
patch -p1 < wm8650_netbook.patch
wget http://pastebin.com/download.php?i=UBZW78BW -O .config

If you want to change the kernel configuration, launch the menu based configurator:

make menuconfig

Once you finish, exit (saving changes if you want). We are ready to start building the kernel:

make uImage

This will take some time. Hopefully, there should be no errors, and when it finishes, you should have your new kernel under arch/arm/boot/uImage. Just rename it to uzImage.bin and copy it to the boot partition of your SD card. Next, we will build the kernel modules:

make modules

And finally, we have to install the modules. If you have built them in your WM8650 netbook, run, with root privileges:

make modules_install

If you have built them in your PC using a cross compiler, mount the system partition of the SD card and run (also with root privileges):

INSTALL_MOD_PATH=/run/media/doragasu/ARCH_SYS make modules_install

As always, remember to change "/run/media/doragasu/ARCH_SYS" with the directory where the system partition of your SD card is mounted. And that's all, reboot your netbook, and the new kernel and modules should run fine. If you have included new features in your kernel, they should be working from now on!

When I get some more time, I'll write a tutorial detailing how to include the driver for the RT8188/8192 wireless dongles into the kernel tree. Stay tuned!

Tuesday, June 19, 2012

Arch Linux on a WM8650 netbook (II)

UPDATE 20th November 2012: Due to recent changes in the Arch Linux boot process, this tutorial is no longer valid. You can still download an old pre-built image and install it, as I explain below. But with this old image, updating the distro (with pacman -Syu) will most likely throw some errors and maybe even break the system. Also installing applications without updating the distro (with pacman -S application_name) will likely fail because of the not updated dependencies.

In my previous post, we learned about these cheap ARM netbooks, and how to install a base Arch Linux system in one of them. If you are interested in this topic, and haven't read it, be sure to give it a look.

In this post, I'll show you how to install and configure LXDE desktop environment and the network manager daemon. If you're too impatient, too busy or too lazy, just grab the full system image (319 MiB) here or here. Then follow the first two steps I wrote in my previous post, and untar the downloaded file, by running (as root):

tar -xjf alarm-wm8650-2012.06.19.tar.bz2 -C /run/media/doragasu/ARCH_SYS/

Make sure you replace "/run/media/doragasu/ARCH_SYS/" with the directory where the Arch Linux system partition is mounted. Insert the SD card in your netbook and power it on. Arch Linux should boot as shown in this video:


You can login as the root user (login: root, password: root), and you can also login as a non privileged (but included in the sudoers) user (login: user, password: user). Remember to edit rc.conf to at least set the timezone, or you'll get the wrong time.

If you want to do it the long way, and you are an Arch Linux newbie, just follow me (or search in the essential Arch Linux Wiki). If you are an Arch Linux hardcore user, just skip this post, what I'm going to tell you is 100% standard Arch Linux, you don't need to do weird tricks or hacks like we did while installing the base system.

Desktop Environment Installation

Click to watch LXDE in all its glory
  1. Let's start installing the X-Window system. Start your netbook and login as root. If you have configured the network, I recommend loging in through SSH, to be able to easily copy and paste the commands from this post. It's also recommended to update the entire system before starting (pacman -Syu). Once you are logged in and the system is updated, start installing packages:
pacman -S xorg-server xorg-xinit xorg-utils xorg-server-utils xf86-video-fbdev
  1. If you did not add dbus to the daemons list, do it now. Edit /etc/rc.conf and add it. The daemons list should look like this:
DAEMONS=(hwclock syslog-ng network crond sshd dbus)
  1. Install the desktop environment. Here you have to choose among all the available. The most used are Gnome, KDE, XFCE and LXDE. I will detail how to install LXDE. I chose LXDE because it has a great advantage over KDE and Gnome: it may not look as eye candy as them, but requires a lot less resources. XFCE is also a good choice for machines low on resources, but I'll not detail how to install it. If you want to give XFCE a try, read its wiki page. Let's continue installing LXDE:
pacman -S lxde gamin
  1. Configure the desktop environment for the current user. You'll have to repeat this step for every user you want to be able to start a LXDE session:
mkdir -p ~/.config/openbox
cp /etc/xdg/openbox/menu.xml /etc/xdg/openbox/rc.xml /etc/xdg/openbox/autostart ~/.config/openbox
  1. Configure the session start for each user. Create a .xinitrc file in the home of each user, with the following contents:
#!/bin/sh
exec startlxde
  1. make sure .xinitrc is executable:
chmod +x .xinitrc
  1. Manually start the X session:
startx
  1. So far, the desktop environment should be working. You should see the XFCE desktop with its bottom panel. Everything should work, but... text rendering looks like crap, right? No problem, you can solve it by typing two commands:
pacman -S ttf-bitstream-vera ttf-dejavu ttf-droid ttf-freefont
fc-cache -vf
  1. You can install some commonly used programs:
pacman -S leafpad epdfview galculator abiword
PCManFM and AbiWord
  1. If you want to use a graphical login manager, you can install for example SLiM:
pacman -S slim
  1. To make slim start each boot, edit /etc/rc.conf and add slim to the daemons list, after dbus. This list should look like:
DAEMONS=(hwclock syslog-ng network crond sshd dbus slim)

Reboot and you should be greeted by the login screen! Remember you have to repeat steps 4, 5 and 6 for each user you want to be able to use LXDE.

Network Manager daemon

Network manager applet in action
If you are going to use a desktop environment, it's highly recommended to replace the network daemon with networkmanager one. This will ease a lot network configuration.
  1. Install networkmanager, the applet for the desktop panel, and gnome-keyring to store passwords for the wireless networks:
pacman -S networkmanager network-manager-applet xfce4-notifyd hicolor-icon-theme gnome-icon-theme gnome-keyring
  1. Replace network daemon with networkmanager. Make sure networkmanager is placed after dbus. The daemons list should look like this:
DAEMONS=(hwclock syslog-ng crond sshd dbus networkmanager slim)
Now if you reboot and enable WiFi (gpio 1:6:d8110040:d8110080:d81100c0), you should be able to select a wireless network and connect to it using the network manager applet, to the right of the bottom panel.
  1. You want to surf the net, right? Unfortunately, this netbook is extremely low on RAM (256 MiB). Most commonly used browsers (Firefox and Chromium) eat lots of RAM, so it's recommended to use lighter browsers, like Midori and Links. Links is very fast and has a very low memory footprint. Unfortunately, it's extremely non Acid3 test friendly: it doesn't support javascript and will not render properly most web pages (though most of them will be usable). Midori is a full featured browser, slower than Links, but can display most webpages failing in Links. To install these browsers, type:
pacman -S links midori

Links browser. Ugly but functional
Midori browser running fullscreen
Of course you can install a lot more network related stuff. Do you want to connect to the IRC? install irssi. Do you want to chat using gtalk, MSN, AIM, etc? install pidgin. Do you want to connect to a remote VNC desktop? install tightvnc, etc.
This concludes today's post. I hope you enjoyed Arch Linux the same as I do. It's a great distro and can make these cheap and tiny netbooks useful for lots of interesting projects!

Monday, June 18, 2012

Arch Linux on a WM8650 netbook

UPDATE 20th November 2012: Due to recent changes in the Arch Linux boot process, this tutorial is no longer valid. You can still download an old pre-built image and install it, as I explained here. But with this old image, updating the distro (with pacman -Syu) will most likely throw some errors and maybe even break the system. Also installing applications without updating the distro (with pacman -S application_name) will likely fail because of the not updated dependencies.

If you have searched the net for a very cheap tablet, maybe you have seen a lot of  7" chinese ones featuring the WM8650 SoC. This SoC has an ARM9 CPU running at 800 MHz, a DSP, a 2D graphics accelerator and a lot of peripherals.


I don't like tablets at all, but I found some cheap chinese netbooks containing pretty much the same hardware, removing the touchscreen and replacing it with a keyboard + touchpad. I couldn't resist and bought one of these netbooks in Aliexpress. It costed me around 50€, shipping costs included. The specs of this machine are:
  • Wondermedia WM8650 SoC at 800 MHz.
  • 256 MiB DDR RAM (I think it runs @ 800 MHz, but I'm not sure).
  • 2 GB internal NAND Flash.
  • 7" 800x480 pixels TFT screen.
  • 3 USB Host ports.
  • 1 Ethernet port.
  • WiFi.
  • Headphones and microphone ports.
  • Internal 7,4V 1800mAh LiPo battery.
  • 9V 1,5A power adapter.
  • Android 2.2.

The Android distro that comes pre-installed is pretty usable even without a touchscreen. As the specs of this machine are really far from being impressive, it doesn't run butter smooth, but works very well.

Android is OK, but as an Arch Linux fan I am, I wanted to make this netbook run it, so I started searching the net to see if anybody had already made it. The only thing I found was a Debian port for these netbooks, using the kernel from a preinstalled Android distro. This Debian port works, but isn't very well optimized, and for example, boot time takes almost 2 long minutes.



The closest thing I found is an Arch Linux port for a WM8650 based tablet. This tutorial is really great and very well detailed, and my work getting the kernel built is almost entirely based on it. John has made a really good job getting the Linux kernel built for these tablets.

In this post, I will detail the process I have followed to get a base Arch Linux system running in this netbook, but I will skip the kernel build process (maybe I'll detail it in a later blog post).

OK, let's get our hands dirty. You will need a SD card. The minimum required size of the SD card is 2 GB, but I recommend using at least a 4GB card, unless you don't need a desktop environment. The steps to get Arch Linux running are:

  1. Partition and format the card. To do it, I have used gparted application. First create a very small FAT32 partition, and name it BOOT. The smallest partition gparted allowed me to create was 33 MiB, more than enough (we need less than 4 MiB). Then create a ext3 partition using the remaining space, and label it ARCH_SYS.
Partitions created in the SD card
  1. Copy the boot script (wmt_scriptcmd) and kernel (uzImage.bin) to the BOOT partition. Download them here. Then run:
tar -xjf alarm-wm8650-boot.tar.bz2 -C /run/media/doragasu/BOOT/
Make sure to replace "/run/media/doragasu/BOOT/" with the directory where the BOOT partition of the SD card is mounted.
  1. Download the root filesystem and untar it in the ARCH_SYS partition:
wget http://archlinuxarm.org/os/ArchLinuxARM-armv5te-latest.tar.gz
tar -xzf ArchLinuxARM-armv5te-latest.tar.gz -C /run/media/doragasu/ARCH_SYS/
Make sure you replace "/run/media/doragasu/ARCH_SYS/" with the directory where the Arch Linux system partition is mounted, here and from now on. Also make sure to run it as root (write sudo before the tar command if you are not root).
  1. Copy the kernel modules to the ARCH_SYS partition. Download them here, and run (as root):
tar -xjf alarm-wm8650-modules.tar.bz2 -C /run/media/doragasu/ARCH_SYS/
  1. We are ready for the first boot. Unmount the SD card, insert it in the netbook and power it on. You should see the Android robot, and then the messages Loading Kernel... and Starting Linux... should appear. In a few seconds, you should be able to see the boot messages, and finally get the login prompt. The first boot will take a lot of time because udev has some problems and eats almost all the CPU. We will fix these proplems in the next step. Default password for the root user is root.
  2. Udev needs the accept4() OS call, that is not supplied by the Android kernel I have built. To fix this, you have to install libaccept4. Download this package and put it inside the SD card (for example in /root). Then start Linux, login as root and in the console change to the directory containing the downloaded package and type:
pacman -U libaccept4-570-1-arm.pkg.tar.xz
echo /usr/local/lib/libaccept4.so >> /etc/ld.so.preload
Accept the installation of the library, and reboot. Udev should be working fine from now on, and boot time will be a lot shorter.
  1. To extend battery life, power to the internal WiFi dongle is off by default. To enable it, you need to toggle the GPIO pin controlling its power. Download this package, copy it to the SD and install it with the following command:
pacman -U wmt-gpio-1.0-1-arm.pkg.tar.xz
Upon installing this package, to enable the WiFi chip, you have to input the command:
gpio 1:6:d8110040:d8110080:d81100c0

And to disable the WiFi chip:

gpio 0:6:d8110040:d8110080:d81100c0
You can create two scripts with these commands, or if you always use WiFi, you can add the first one to /etc/rc.local, to enable WiFi each time the system boots.
  1. To read the battery charge level, use the following command:
cat /sys/class/power_supply/wmt-battery/capacity
  1. To change the screen brightness, you have to write a number between 0 and 255 (the greater, the brighter) to /sys/class/leds/lcd-backlight/brightness. For example:
echo 200 > /sys/class/power_supply/wmt-battery/capacity
You can also add this line to rc.local to set the screen brightness to your favorite level each time the system boots.

Now you have a fully functional base Arch Linux install. It's highly recommended to update your system (pacman -Syu). Then you can start installing your favorite utilities, window manager, etc., by following the instructions documented in the awesome Arch Linux Wiki.

I'll give you some hints for Arch Linux newbies. Skip them all if you are experienced with this distro. You can start by editing /etc/rc.conf. This file contains some basic configuration parameters, like for example the timezone (TIMEZONE), the hostname (HOSTNAME) and some basic network configuration parameters (that default to DHCP on the Ethernet port). Very important in this file is the last line, detailing the services started when the system boots, and the order in which they are started. I usually remove netfs from the list, replace network with networkmanager (you'll have to install it first) and add dbus (you'll need it for the window manager and some more programs). If you use networkmanager instead of network daemon, make sure you put it after dbus.

To set the locale (in case you don't want the default en_US.UTF8), you have to follow these steps:
  1. Edit /etc/locale.gen. This file details the locales generated by the system. You can replace/add the desired locales to this file. For example, to generate locales for spanish language, add:
es_ES.UTF-8 UTF-8  
es_ES ISO-8859-1  
es_ES@euro ISO-8859-15  
  1. Generate the new locales by running (with root privileges):
locale-gen
  1. Edit /etc/rc.conf and change the default locale to the desired one. Of course, the locale must be one of the included in /etc/rocale.gen. For example, for spanish:
LOCALE=es_ES.UTF-8

To change the root password, use the command passwd. To create a new user, use the command adduser. Leave the default parameters, but when asked for additional groups, enter the following:
audio,lp,storage,video,wheel,games,power,scanner

It's highly recommended to install sudo and add the user to the sudoers. Just follow these steps:
  1. Install sudo:
pacman -S sudo
  1. Allow all the users in the wheel group to use sudo. Run the visudo command, and uncomment  (remove the '#') the following line:
# %wheel ALL=(ALL) ALL
If you don't know how to use the vi editor, press the [I] key to [I]nsert text, when you finish, press [ESC] to enter command mode and write :wq to write the file and quit the editor. If you mess something up, just press [ESC] to switch to command mode, and write :!q to quit without saving changes. Then try again the visudo command.
And that's all for today. If you followed this tutorial to the end, congratulations! You should be able to launch GNU/Linux in your shiny WM8650 laptop, with the locale, timezone and (hopefully) Ethernet network properly configured. You should be also able to login as a non privileged user, and use sudo to run tasks as root. If you have questions, feel free to ask them.

What? You don't like the console? Don't worry. In the next chapter, we will learn how to install a graphical desktop environment. Stay tuned!

TROUBLESHOOTING:

I have patched the kernel to make it compatible with the environment of the Android distro that comes pre-installed in some netbooks. You should be able to boot Android (without the SD card inserted) and GNU/Linux (with the SD card inserted). It works on my netbook, but it looks like there are different hardware revisions of these netbooks, and some of them, may require to change some variables in the environment stored inside the internal Flash memory. Typical problems that may arise are for example not being able to use the Ethernet port, or losing the ability to read the internal battery level. If you experience these problems, I can provide you with a modified wmt_scriptcmd that changes some variables of the environment stored in Flash, to make the broken things work. But I'll not post it here unless someone asks for it, because if you overwrite some variables, you may break things in the Android kernel (i.e. you can loose the battery level information in Android). And if you didn't back up that variables first, you might not be able to fix these problems.

Other problem that may arise, is that WiFi may not work. WiFi in these netbooks is implemented using an internal USB WiFi dongle. The one used in my unit has a Realtek RT8188CU chipset. I had to search the net for a compatible driver (rtl8192cu) and merge it into the kernel drivers. If your netbook uses a dongle with a different chipset, WiFi may not work. Enable WiFi with the gpio command, run lsusb and show me its output. I'll try to help you to get the dongle working.

Of course you may find a lot more problems. Feel free to ask for help! You can also read the follow-up to this post: Arch Linux on a WM8650 netbook (II).