User talk:H3ndrik/Mainline Debian HowTo

Jump to: navigation, search

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 [1]

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.



  • 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 [2]


What do we need (of hardware) to do the build prozess ? Which Hardware will be supported ?

Getting a cross toolchain

Refer to Toolchain.

In short (and if you're using Debian):

 apt-get install emdebian-archive-keyring
 echo "deb 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 -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#Compile 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 [3] 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


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 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

cat <<EOF > /mnt/etc/apt/sources.list

deb testing main non-free contrib
deb-src testing main non-free contrib

deb testing/updates main contrib non-free
deb-src testing/updates main contrib non-free

# testing-updates, previously known as 'volatile'
deb testing-updates main contrib non-free
deb-src testing-updates main contrib non-free
cat <<EOF > /mnt/etc/apt/sources.list.d/experimental.list
deb unstable main non-free contrib
deb-src unstable main non-free contrib

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

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

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

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/ >> /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

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

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:

   passwd root


 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


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,115200 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


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

External Links

Personal tools