Debian 7 on MK802II device

Forum to discuss the Rikomagic MK802 II Mini PC

Moderators: KEgg, twjordo, tatubias

Debian 7 on MK802II device

Postby ljones » Mon Sep 15, 2014 2:27 pm

Hello all :-)

Well hopefully someone will find all of this useful. A while back I was trying to get somone else's debian image to work on my MK802 device. However it did not work at all and could not find out the reason why. Also my device turned out to be a MK802II and not a plain MK802II!

So I decided to try to set out using the sunxi instructions a base debian 7 install from scratch (or as near as I could get). After getting it to work once I then wiped everything, started again wrote down each step that I took and re-did the whole thing. This worked again so I'm now posting here what I did to install debian 7. This all comes from notes that I've witten out so I apologise for the roughness of what I'm posting here.

BTW You can see some pictures of my device here - 1,2,3,4. The SD card is just there for a sense of scale, btw.

Also here's a picture of debian 7 afer it has booted up.

First of all some notes though.

- Always remember to use the sync command!
- The boot (.bin) files that are written to the start of the microsd card are *very* easily corruped. Always use sync. Also after dd'ing them wait around 10-20 seconds!
- Use dmesg to get the true name of your micro SD card. (Sidenote: I used a 2GB micro sd card to practise on).

I used the instructions btw from the sunxi wiki. It seems that it is the case that there's lots of little bits and pieces to make as you go along and it's just a case of bringing it all together and trying to put everything in the correct place. BTW in the text below I'm going to assume that the downloaded/compiled files live in $HOME btw.

To do all of this I was just originally going to use my normal x86_64 debian box but it seems that debian's cross-compliation programs aren't quite ready yet. So instead I used a normal x86 computer which wasn't being used, and installed ubuntu on it (14.04). I downloaded xubuntu from here. The PC I chose was an old Asus EEPC 904HD netbook (note that in this case, HD stands for hard drive, not high definiation....); it did the job ok but it was pretty slow going!

To start off with I had to get xubuntu started. I used this command to write the ISO file to a USB stick on my main x86_64 debian machine;

Code: Select all
$ dd < xubuntu-14.04-desktop-i386.iso > /dev/sdf


Let it write to the usb stick and once it has finished disconnect, insert into 904HD and power on. On my 904HD btw I had to press ESC to get up a bios boot menu so I could choose to boot off SD card. Then it was just a case of installing xubuntu.....

Once it is installed, you need these extra bits and pieces (also plenty of space and a half decent 'net connection!);

Code: Select all
$ apt-get install gcc-arm-linux-gnueabihf
$ apt-get install git
$ apt-get install libncurses5-dev
$ apt-get install u-boot-tools
$ apt-get install debootstrap
$ apt-get install qemu
$ apt-get install qemu-user-static
$ apt-get install libusb-1.0-0-dev


Once all those are installed, clone (git) the linux-sunxi kernel source files from https://github.com/linux-sunxi/linux-sunxi.git (on the machine you're going to use to do all of this, not the mk802II!). Xubuntu should have most of the tools needed to build all of this already installed, if not;

Code: Select all
$ apt-get install build-essential


Get the linux-sunxi source files from git;

Code: Select all
$ git clone -b sunxi-3.4 https://github.com/linux-sunxi/linux-sunxi.git


Note that this will take quite a fair amount of time to download. Once it is finished cd into linux-sunxi and set up the default configuration and start up the kernel menuconfig program;

Code: Select all
$ cd linux-sunxi
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun4i_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig


At this point in the menuconfig (kernel configuration) I found I had to enable a couple of options/drivers in the kernel. One was the wifi chipset driver (in my case I found it was a realtek 8188E), and also one other driver for the USB ethernet adapter I was using (DM9601 based). I'm not sure about other devices/chipsets btw, more on that later;

Code: Select all
** enable wifi (realtek 8188E)
Device drivers
- network device support
 - wiresss LAN
  - Realtek 8188E usb wifi

**note for DM9601 only
Device drivers
- network device support
 - USB network adapters
  - Multipurpose USB Networking framework
   - Davicom DM9601 based USB 1.1 10/100 ethernet devices


Exit the kernel configuration program (menuconfig) and let it save its .config file. Then proceed to compile the kernel and modules.

Code: Select all
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules


Note that should be uImage there, and not just uimage (all in lower case). This can take quite some time btw (and my old asus machine has only the one core!). But once it is done then;

Code: Select all
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install


That should be it for compiling the kernel (less tarring the modules, though we'll do that later). The next step is to make the boot files and for that you need both sunxi-tools.git and sunxi-boards.git;

Code: Select all
$ git clone git://github.com/linux-sunxi/sunxi-tools.git
$ git clone git://github.com/linux-sunxi/sunxi-boards.git


Since xubuntu btw dosen't come with a program btw called "fex2bin" (needed to make a script.bin for this device) you need to compile that as well. To do this;

Code: Select all
cd sunxi-tools
make fex2bin
cp fex2bin /usr/bin


btw I just copied across the "fex2bin" program there into /usr/bin so I don't have to hunt around or try to remember the exact path for it (and my memory is lousy). You'll also need one other file btw in this case a file called "mk802ii.fex";

[/code]
$ cd sunxi-boards/sys_config/a10
$ cp mk802ii.fex test.fex
[/code]

According to the instructions on sunxi apparently it is also a good idea (preumably if like me you're using a USB ethernet device) to set a MAC address. Use a text editor (e.g. jed, nano, etc) to edit this file and look for the part in the file that contains;

Code: Select all
[dynamic]
MAC = "000000000000"


Just change the zeros there to your MAC address. If you're not sure of what your MAC address for your usb ethernet device plug your usb ethernet stick into a linux box and use the command - as root);

Code: Select all
$ ifconfig ethX


And look at the output. The mac address is the line which says "HWAddr" followed by 6 hex numbers. Replace the "X" with the number of your device (so if you already have a ethernet device in your PC X might be one, so eth1, i.e. ifconfig eth1), etc.

Once this is done generate the script.bin by doing;

Code: Select all
$ fex2bin test.fex script.bin


Also to make things a bit easier I also moved the files created earlier into $HOME. e.g.

Code: Select all
$ cp linux-sunxi/arch/arm/boot/uImage $HOME
$ cp sunxi-boards/sys_config/a10/script.bin $HOME


Next tar the module files built earlier along with the kernel (again finally moving them into $HOME to make them easier to find later);

Code: Select all
$ cd linux-sunxi/output/lib
$ tar -cvf modules.tar *
$ mv modules.tar $HOME


The next step is to start writing data to a micro sd card. Also two partitons will be needed. First of all though you need a couple of .bin files for this device. Download the file "mk802ii_hwpack.tar.xz" from linux-sunxi as follows;

Code: Select all
$ cd $HOME
$ wget http://dl.linux-sunxi.org/users/amery/sunxi-3.0/latest/mk802ii_hwpack.tar.xz


Then decompress so that we have the two files -- sunxi-spl.bin and u-boot.bin;

Code: Select all
$ cd $HOME
$ xz -d mk802ii_hwpack.tar.xz
$ tar -xvf mk802ii_hwpack.tar


Next wipe off the sd card so it has no partitons (if your micro sd card has any data you want to keep -- make sure you've backed it up!). Also remember to use dmesg to get the exact device name for your micro sd card (e.g. if your micro sd card shows up as sdc replace the X with a c).

Code: Select all
$ dd if=/dev/zero of=/dev/sdX bs=1M count=1


And write the files to a micro SD card. Remember to wait after writing each file -- give it about 10 or 20 seconds. I found if I did this step too rapidly the result was that the micro SD card would not boot in my MK802II device or just boot android.

Code: Select all
$ cd bootloader
$ dd if=sunxi-spl.bin of=/dev/sdX bs=1024 seek=8
**wait for about 10-20 seconds
$ sync
$ dd if=u-boot.bin of=/dev/sdX bs=1024 seek=32
**wait again for about 10-20 seconds
$ sync


Then create partitons on the micro sd card with fdisk. The first partition however must start at location 2048 and be 16MB in size. The second partiiton is the rest of the micro sd card. So;

Partiton 1 - vfat formatted. Start at location 2048, and be 16MB in size.
Partiton 2 = rest of micro sd card.

To do this with fdisk (press the return key where you see <return>!);

Code: Select all
$ fdisk /dev/sdX
n <return>
p <return>
1 <return>
First sector (2048-) <---- press return here
Last sector -- type +16M and press return
n <return>
p <return>
2 <return>
Press return twice more (partition 2 first/last sector)
w <return> <---- writes the partition
$ sync


Then format the two partitions;

Code: Select all
$ mkfs.vfat /dev/sdX1
$ mkfs.ext4 /dev/sdX2


Depending on how large the second partition is and the speed of your micro sd card this might take a little while to do. Once that is done, copy across the uImage and script.bin files to the micro sd card. Don't forget to unmount and sync too!;

Code: Select all
$ mkdir /tmp/0
$ mount /dev/sdX /tmp/0
$ cp $HOME/uImage /tmp/0
$ cp $HOME/script.bin /tmp/0
$ sync
$ umount /tmp/0
$ sync


The last part is to get a base install of debian 7 (wheezy) and all of its files by using a program called "debootstrap". Again remember that X = the device name/letter of your micro sd card (e.g. sdc). To do this type;

Code: Select all
$ distro=wheezy (yep, actually type that!)
$ mount /dev/sdX2 /tmp/0
$ debootstrap --arch=armhf --foreign $distro /tmp/0


Once this part completes the debootstrap process needs to be continued but in a chroot. First of all though copy the file "qemu-arm-static" to the micro sd card;

Code: Select all
$ cp /usr/bin/qemu-arm-static /tmp/0/usr/bin


And then let the debootstrap process continue inside the chroot;

Code: Select all
$ chroot /tmp/0
$ /debootstrap/debootstrap --second-stage


Remember to type

Code: Select all
$ sync


once all of this is done. **WARNING! The parts using debootstrap took a very long time on my old asus 902HD netbook -- literally hours. Next adjust some of the files on the micro sd card, namely "sources.list","fstab" and "71-no-recommends". Easiest way to do this I found was just to simply cut and paste into each file. Remember to stay in the chroot!;

/etc/apt/sources.list
Code: Select all
deb http://http.debian.net/debian wheezy main contrib non-free



/etc/fstab
Code: Select all
/dev/sdX1      /boot      vfat      defaults    0     0


(Remember to change that X one more time, e.g. c, i.e.sdc1). Next temporarily leave the chroot to copy across your /etc/resolv.conf file from the computer you're working on onto the micro sd card);

Code: Select all
cp /etc/resolv.conf /tmp/0/etc


Then move back into the chroot and update the debian apt-get list on the micro sd card;

Code: Select all
$ chroot /tmp/0
$ export LANG=C
$ apt-get update


The next step is to modify the file /etc/apt/apt.conf.d/71-no-recommends by placing these two lines into the file;

Code: Select all
APT::Install-Recommends "0";
APT::Install-Suggests "0";


Then finally update/install the locales;

Code: Select all
$ apt-get install locales
$ dpkg-reconfigure locales


You may at this point be asked to choose a locale, just choose the correct one for your country. For example I am from the UK(GB) so I chose "en_GB-UTF-8"). Note that generating the locales can take a long time to do!

Then use the passwd command to set the root password;

Code: Select all
$ passwd


Then finally leave the chroot by typing exit, and use sync to make sure once again that no data is left unwritten;

Code: Select all
$ exit
$ sync


Give your device (the mk802ii) a hostname (e.g. "mylinuxbox")

Code: Select all
$ echo mylinuxbox > /tmp/0/etc/hostname


And add this line to inttab;

Code: Select all
$ echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> /tmp/0/etc/inittab


Then sync again, and untar the modules that were made earlier;

Code: Select all
$ sync
$ tar -xvf $HOME/modules.tar -C /tmp/0/lib/


Then finally unmount the micro sd card,sync, wait and try the card out in your mk802ii device.

Code: Select all
$ umount /tmp/0
$ sync


That should then be a case of "job done". :-) . Note that for other devices, e.g. A20 based devices you'll need a different kernel and the kernel config/compilation instructions may differ. These instructions just apply to the device I have btw.

Problems
I did come across one large problem however while doing all of this. One thing I noted about my MK802II device is that the built-in wifi was pretty slow. It's apparently a B/G device (though not a N!) but even so it was pretty slow going. I had hoped to use my MK802II device as a small server and AP device though internet speeds were always about 1/10th what they should be(!). However not so slow as to be unusuable (ok for general web browing, for downloading large files (e.g ISO files) pretty slow).

One answer I thought of was to just try an external USB wifi device. However unfortunatly it dosen't seem to be that easy. I was hoping to use a TP-LINKTl-WN722N here (150Mbps), N, Wifi. This appears to use the atheros chipset (in linux the ath9k driver). However in the sunxi kernel there is no ath9k driver at all(!). In fact there dosen't seem to be much support for many different usb wifi/ethernet devices in the sunxi kernel at all :-( .

A soultion might be to try to use the backported drivers however I'm honestly not sure how to do that. And for the kernel version I was using there are no backport drivers at all! The only other solution I can think of is to use the normal (and latest) main line linux kernel however that won't have any video display output. So it's a choice of either having limitied choice on wifi/ethernet or no display. x.x :-( !

Anyway I hope this all helps someone. I understand this is all quite brief and only roughly laid out. It took me about a week of work to finally get all of this to work.

ljones
ljones
 
Posts: 3
Joined: Sun Sep 07, 2014 6:32 pm

Re: Debian 7 on MK802II device

Postby Milos » Wed Dec 10, 2014 12:29 am

Many thanks. Fantastic piece of how-to. I have problems with WiFi but device is booted and working. Many thanks again for this fantastic tutorial.

Milos
Milos
 
Posts: 1
Joined: Wed Dec 10, 2014 12:26 am


Return to Rikomagic MK802 II Forum

Who is online

Users browsing this forum: Google [Bot] and 2 guests