Debian on MK80

Forum to discuss the new OctaCore Rikomagic MK80 & MK80+ Mini PC

Moderators: KEgg, twjordo, tatubias

Debian on MK80

Postby shogunx » Sun Feb 15, 2015 3:44 am

Hi Everyone. I am looking at strategies to put Debian (jessie, most likely) onto my shiny new MK80. The other Allwinner based devices I have are development boards, and generally have a TTL serial console that provides access to the U-boot shell, and generally kernel boot messages and a tty thereafter. Most of the ARM hosts I have worked with also boot from a card slot. From my understanding, there is a popular procedure involving LiveSuite/PheonixSuite of flashing the firmware via USB OTG in recovery mode as well, but I have avoided this method as I have migrated my network to ARM hosts, and these applications support only x86 and x86-64.

So, first things first... are the current U-boot environment variables set to attempt boot from SD card if one is present? This would likely be the easiest route forward, BUT...
Early debugging with this method can be difficult if there is a problem with the display driver or configuration thereof. Firing blind would be a good analogy. Hence, the need for the serial console. When I look at the MK80 circuit board, I see no obvious tx/rx pair pins or holes. Ground we can take from anywhere, so this is no big deal. I do see several test pad locations that could potentially carry this data, but I thought that I should ask the forum before getting busy with an oscilloscope hunting for a 9600Hz signal.

Any hints on where to find ttyS0, or SD boot being enabled before I try to make an SD card image?

Thanks,
Scott
shogunx
 
Posts: 2
Joined: Thu Feb 12, 2015 5:11 am

Re: Debian on MK80

Postby shogunx » Sat Sep 19, 2015 8:33 am

Well, I see this has been a popular topic here on the forum! In any case, I have successfully completed a procedure for installing Debian Sid on the MK80/MK80+, thanks to the fine support at Cloudsto pointing out the appropriate pins on the board to access a tty. Having popped open the case and soldered in pins for ground, rx and tx, I was dismayed to find that the default u-boot gave us a bootdelay of 0. Sigh. This meant a bit more involved procedure to get to a u-boot shell, and change the bootloader settings. More on that later. What follows is a general strategy and installation instructions to get Debian sid (or jessie, or stretch, if you prefer) on your MK80. Note well that if you are not quite careful in following the instructions, or perhaps mistype a line or two, you can leave your machine in an unbootable state. You have been warned. If you are reading this, and are interested in Debian on this host, you are probably OK with recovering from such a snafu, should it occur. Also, you will need a USB to TTL serial adapter to interface with the board's serial port. I use this one: http://www.adafruit.com/products/954
You will also need another computer to use to access the serial console. Please read this article in its entirety before attempting to proceed with this procedure, lest you wind up with your pants in a revealing position.

You must start from a MK80 Linux Edition host, or flash the firmware onto your machine yourself with LiveSuit/PheonixSuit. There is ample documentation of that procedure already, and as such, is beyond the scope of this writing. First, boot your machine to the Linaro desktop, and get a root shell by opening a terminal and running
Code: Select all
sudo su
. In said root shell, you will need to
Code: Select all
 apt-get update && apt-get install u-boot-tools debootstrap
in order to get the necessary tools to proceed with the installation. At this point, I collected the factory supplied u-boot environment variables by running
Code: Select all
strings /dev/mmcblk0p5
, which extracts all of the alphanumeric strings from, in this case, the partition storing the u-boot configurations. I then copied this data to another host, to have handy for reference. You can omit the last two steps, if you wish, as I have listed the info needed out of it below for your convenience.

Next we will build our Debian root filesystem on what is normally unused space on the onboard storage. First, we need to format the existing, empty partition with
Code: Select all
mkfs.ext4 /dev/mmcblk0p1
. Make a place to mount the new ext4 partition with
Code: Select all
mkdir /mnt/1
and mount it with
Code: Select all
mount /dev/mmcblk0p1 /mnt/1
. To build our basic Debian sid bootstrap, we will
Code: Select all
debootstrap sid /mnt/1
. This will take a little while. Get some tea (<--this step is optional). When this is complete, we will need to make a home for the kernel modules, and populate that home with
Code: Select all
mkdir /mnt/1/lib/modules && cp -a /lib/modules/* /mnt/1/lib/modules/
. Now for a little tweaking of our new Debian partition, to prepare it for field duty... enter the new filesystem with
Code: Select all
chroot /mnt/1
. Use
Code: Select all
passwd
to set a root password. Run
Code: Select all
adduser
to add a normally privileged user account.
By running
Code: Select all
apt-get remove systemd
inside this chroot, we can ensure that our system does not become tainted by preventing this from ever running. Also, the memory manager is by default very aggressive in killing user processes, so we will ditch that problem beforehand by using
Code: Select all
echo "vm.mmap_min_addr = 0" >> /etc/sysctl.conf
.
At this point you will be have a very basic Debian installation. You will need to apt-get to taste once it is booted, but wait... there is yet another hurdle to overcome: configuring u-boot.

Finding no other way to get into the u-boot shell, I had to get down and dirty and glitch the system by writing to an incorrect address with u-boot-tools' fw_setenv. This causes u-boot to load a "failsafe" yet unbootable configuration, but one that we can interrupt from a serial console to get to a shell. We must first write the configuration file with
Code: Select all
echo "/dev/mmcblk0p5 0x8000 0x2000" > /etc/fw_env.config
. Then, we actually glitch it with
Code: Select all
fw_setenv bootdelay 3

You will get a "WARNING BAD CRC Using Default Environment" message. Cha-ching! Now
Code: Select all
umount /mnt/1 && halt
to power down the machine. Remove the power cable, and all other connections. We are going to have to operate on this one to breathe Debian life into the display.

Open the case by gently prying off the bottom cover with a blunted batleth, or similar non-scarring pry tool. You will find 3 small screws holding the board in place. Remove these, pop the board out (careful with the wifi antenna wire) and flip it over, so you can see the heatsink. https://plus.google.com/+shogunx/posts/FLnVkEwm5Nb <-- this image will show you how to connect your USB-TTL Serial cable. Ground is on the far left pin left of the header, and the tx/rx are on the rightmost pins, viewed from the closest edge of the board. Fire up your favorite terminal emulator... I like minicom myself, but others prefer screen. If you want to use putty, stop reading. You are out of your league. You will brick your box and mama will not buy you another one. You have been warned (twice). 115200 8N1 Hardware and Software flow control off, BTW.

Apply power to the board. Your serial console will show some spew, and begin counting down. Whack a key, and you will drop to a u-boot console. Hooray! You now need to change some environment variables and write them to the appropriate partition. Tell uboot how to find the kernel again with
Code: Select all
setenv boot_normal 'sunxi_flash read 40008000 boot;bootm 40008000'
. Next, we need to define the new root partition with
Code: Select all
setenv mmc_root /dev/mmcblk0p1
. Now we need to define the parameters that get passed to the kernel, in the process reclaiming some 821M of memory from the Android related Ion memory manager, which does squat for Debian, with
Code: Select all
setenv setargs_mmc 'setenv bootargs console=${console} earlyprintk=${console} root=${mmc_root} init=${init} vmalloc=384M loglevel=${loglevel} partitions=${partitions}'
. This leaves only saving this configuration with
Code: Select all
saveenv
before the system is ready to boot into a fresh, shiny, systemd free Debian Linux. Just type
Code: Select all
boot
or power cycle the system to boot Debian. For those who want a GUI, the following will get you started once you login as root to your new install:
Code: Select all
apt-get install xorg iceweasel e17 terminology locales openssh-server
. Enjoy!
shogunx
 
Posts: 2
Joined: Thu Feb 12, 2015 5:11 am


Return to Rikomagic MK80(+) OctaCore Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron