Mainline Debian HowTo

This page describes bootstrapping debian with it's default (mainline) linux kernel (>= 3.15 / 3.16) to create a SD-card with a clean (official) install. Based on the instructions on the official debian wiki

To summarize the process: Most work is the normal debian bootstrapping procedure. Apart from that we need to get the kernel package from the experimental repository and it is necessary to compile a patched version of u-boot. Tested on Cubietruck, should work on other boards, too.

Caveats

 * The kernel comes without display drivers, so you won't get any display-output with this guide! Use UART or ssh to login
 * We need at least Linux 3.16 for MMC (SD-Card) support (the debian folks also backported this patch to their version of 3.15)
 * We will use a recent version of u-boot and device tree. The Allwinner-specific script.bin isn't needed anymore.
 * linux-image-3.16-rc6-armmp-lpae is the current version at the time of writing. You'll have to modify these instructions if there is a new version

= Getting a cross toolchain = Refer to Toolchain.

In short (and if you're using Debian): apt-get install emdebian-archive-keyring echo "deb http://www.emdebian.org/debian/ unstable main" >> /etc/apt/sources.list.d/emdebian.list apt-get update apt-get install gcc-4.7-arm-linux-gnueabihf for i in /usr/bin/arm-linux-gnueabihf*-4.7 ; do ln -s $i ${i%%-4.7} ; done apt-get install build-essential git binfmt-support qemu-user-static debootstrap

= Building u-boot = Mainline u-boot seems yet to be missing a few sunxi-specific patches, so we have to use uboot-sunxi. Hans de Goede's version has working PCSI support for SMP (to enable all CPU cores). git clone https://github.com/jwrdegoede/u-boot-sunxi.git -b sunxi-next cd u-boot-sunxi make CROSS_COMPILE=arm-linux-gnueabihf Cubietruck_config make -j4 CROSS_COMPILE=arm-linux-gnueabihf-

(Also refer to U-Boot)

= Setting up the sd card = ${card} is the SD device (ie /dev/sdc). ${partition} is the partition number (ie. 1). Warning: This will delete the content. dd if=/dev/zero of=${card} bs=1M count=1 dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1024 seek=8 Create partition(s). ie one big partition beginning with sector 2048, type 83 (Linux) fdisk ${card}

mkfs.ext4 ${card}${partition} mount ${card}${partition} /mnt

This will first clean the card (at least the first 1M), install the u-boot bootloader you compiled in the step before, and then you can create -for example- one partition, format it, and mount it to /mnt/ for use in the next steps.

(Also refer to Bootable_SD_card)

= Bootstrapping Debian = This will bootstrap Debian testing (aka Jessie). debootstrap --foreign --arch=armhf testing /mnt/ cp /usr/bin/qemu-arm-static /mnt/usr/bin/ mount chproc /mnt/proc -t proc mount chsys /mnt/sys -t sysfs DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt /debootstrap/debootstrap --second-stage

I'm not sure if the mounts of proc and sys are necessary. If in doubt, have a look at the debian wiki or the official documentation.

(Furthermore, when linux >=3.15 migrates to testing, we can --include=linux-image-armmp-lpae it in the first debootstrap instead of doing it later)

= Configuring the system =

flash-kernel
We are going to use flash-kernel to generate the boot.src. Tell it which hardware we're aiming for. (Devices listed in: /usr/share/flash-kernel/db/all.db) mkdir /mnt/etc/flash-kernel/ echo "Cubietech Cubietruck" >> /mnt/etc/flash-kernel/machine

Kernel arguments: echo 'LINUX_KERNEL_CMDLINE="console=ttyS0,115200 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:1280x1024p60 root=/dev/mmcblk0p1 rootwait panic=10 ${extra}"' >> /mnt/etc/default/flash-kernel

Kernel modules
Write extra modules that should be loaded at boot time to /mnt/etc/modules. echo "rtc_sunxi" >> /etc/initramfs-tools/modules

Base configuration files
echo "/dev/mmcblk0p1 /           ext4    relatime,errors=remount-ro        0       1" > /mnt/etc/fstab echo "HOSTNAME" > /mnt/etc/hostname

Hint: Please consider using your favorite debian-mirror instead of ftp.debian.org. cat < /mnt/etc/apt/sources.list

deb http://ftp.debian.org/debian/ testing main non-free contrib deb-src http://ftp.debian.org/debian/ testing main non-free contrib

deb http://security.debian.org/ testing/updates main contrib non-free deb-src http://security.debian.org/ testing/updates main contrib non-free

deb http://ftp.debian.org/debian/ testing-updates main contrib non-free deb-src http://ftp.debian.org/debian/ testing-updates main contrib non-free EOF cat < /mnt/etc/apt/sources.list.d/experimental.list deb http://ftp.debian.org/debian/ unstable main non-free contrib deb-src http://ftp.debian.org/debian/ unstable main non-free contrib
 * 1) testing-updates, previously known as 'volatile'

deb http://ftp.debian.org/debian/ experimental main non-free contrib deb-src http://ftp.debian.org/debian/ experimental main non-free contrib EOF cat < /mnt/etc/apt/preferences.d/experimental Package: * Pin: release o=Debian,a=unstable Pin-Priority: 150

Package: * Pin: release a=experimental Pin-Priority: -10 EOF cat < /mnt/etc/network/interfaces
 * 1) This file describes the network interfaces available on your system
 * 2) and how to activate them. For more information, see interfaces(5).

auto lo iface lo inet loopback
 * 1) The loopback network interface

allow-hotplug eth0 iface eth0 inet dhcp EOF
 * 1) The primary network interface

Prepare Login
Remember: We won't have any display output, so we can eiter: spawn a login on the serial console: echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" >> /mnt/etc/inittab and/or use ssh. Since debian disabled root password-login in jessie, re-enable it or copy your key: sed -i "s/^PermitRootLogin without-password/PermitRootLogin yes/" umask 077; mkdir /mnt/root/.ssh/ cat ~/.ssh/id_rsa.pub >> /mnt/root/.ssh/authorized_keys

chroot and setup
Now chroot in to the new system, install kernel and set everything up. mount -t proc chproc /mnt/proc mount chsys /mnt/sys -t sysfs mount -t devtmpfs chdev /mnt/dev || mount --bind /dev /mnt/dev mount -t devpts chpts /mnt/dev/pts echo -e '#!/bin/sh\nexit 101' > /mnt/usr/sbin/policy-rc.d chmod 755 /mnt/usr/sbin/policy-rc.d  DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt dpkg --configure -a

LC_ALL=C LANGUAGE=C LANG=C chroot /mnt The next steps are executed inside the chroot: apt-get update apt-get install locales && dpkg-reconfigure locales dpkg-reconfigure tzdata Install the kernel and u-boot (u-boot from debian is not used, but it does no harm and i'll include it for future reference) apt-get -t experimental install linux-image-3.16-rc6-armmp-lpae u-boot u-boot-tools Install non-free firmware and add one currently missing file to the wifi-firmware: apt-get install firmware-linux firmware-brcm80211 sunxi-tools flash-kernel wget -O /lib/firmware/brcm/brcmfmac43362-sdio.txt http://dl.cubieboard.org/public/Cubieboard/benn/firmware/ap6210/nvram_ap6210.txt Install a few other things: apt-get install console-setup keyboard-configuration systemd systemd-sysv openssh-server ntp

At this point, debian should have generated a kernel image /boot/vmlinuz-??? and an initrd /boot/initrd.img-??? for you. Generate the /boot/boot.scr, set a password and after a little cleanup you're set: flash-kernel passwd root exit

= Cleanup = rm /mnt/usr/sbin/policy-rc.d rm /mnt/usr/bin/qemu-arm-static umount /mnt/dev/pts && umount /mnt/dev && umount /mnt/sys && umount /mnt/proc && umount /mnt sync

= Boot = Now you should be able to boot your brand new debian installation. Hopefully it'll boot, pull up networking and you're able to login via ssh.

Manual boot (serial console)
If it doesn't boot, you'll want an 3,3V USB UART module to debug. u-boot seems to be powerful and gives helpful error messages. If it says something like 'CRC error' 'loading default environment', that's okay, we want default. (Side note: use the filesize variable or give the size in hexadecimal)

setenv bootargs console=ttyS0,115200n8 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:1280x1024p60 root=/dev/mmcblk0p1 rootwait panic=10 ${extra} ext4load mmc 0:1 0x47000000 boot/dtb-3.16-rc6-armmp-lpae ext4load mmc 0:1 0x46000000 boot/vmlinuz-3.16-rc6-armmp-lpae ext4load mmc 0:1 0x48000000 boot/initrd.img-3.16-rc6-armmp-lpae bootz 0x46000000 0x48000000:${filesize} 0x47000000

= Conclusion = As of now it is possible to run Debian with a recent mainline kernel and only few changes to the system. We can throw away some of the crude, device-specific things like the modifications to the kernel, 'script.bin'... U-boot is on the right track and Debian-installer will be usable on various sunxi-based systems, once a recent kernel arrives in the installer builds.

What's left to be done is:
 * Optimizing the system
 * Getting some/any graphics support

= See also =
 * Mainline Kernel Howto

= External Links =
 * https://wiki.debian.org/InstallingDebianOn/Allwinner
 * https://github.com/igorpecovnik/Cubietruck-Debian/blob/master/build.sh