Emdebian on APF

From ArmadeusWiki
Revision as of 04:11, 11 December 2012 by Jorasse (Talk | contribs) (Kernel)

Jump to: navigation, search

Requirements

  • An APF28 with its docking board.
  • A PC running a Debian stable distribution (it can be in a chroot).
  • A microSD card.

Preamble

This page describes how to install an Emdebian stable distribution on APF28. Emdebian is mainly a Debian without documentation (manpages,etc...), so it can fit on smaller storage devices but providing the same functionalities. One of the goals in this procedure is to use the Armadeus tools as less as possible. So you won't need to change anything in u-boot configuration and buildroot will only be used to fetch and patch the kernel. The latter could have been avoided but doing this way facilitates the choice of the kernel (2.6.35.3 or a 3.x one) and ensures all the patches are applied.

Emdebian is a work in progress and the cross-toolchains in unstable are often broken so we'll stay here in the stable branches (both Emdebian and Debian).

This procedure has been written for an APF28 but should be easily adapted for another board.

Preparation

  • To avoid possible ownership issues in the generated files without sudoing (I'm a bit lazy, I agree, but I doubt God keeps an eye on me...):
$ sudo su
  • Add emdebian tools repository to your sources.list. We'll need it to install the cross-toolchain for kernel compilation:
# echo 'deb http://www.emdebian.org/debian/ stable main' >> /etc/apt/sources.list
  • Install needed packages:
# apt-get update
# apt-get install multistrap uboot-mkimage g++-4.4-arm-linux-gnueabi
multistrap will fetch the packages and build the rootfs.
uboot-mkimage will be needed to build the final uImage.
g++-4.4-arm-linux-gnueabi dependencies will install the whole cross-toolchain. Thanks apt :)
  • Create an ext2 partition on the SD card:
# mkfs.ext2 /dev/sdc1

Building the rootfs

  • Let's create a directory:
# mkdir apf
# cd apf

Kernel

  • Get an Armadeus working tree and apply configuration:
apf/# git clone git://git.code.sf.net/p/armadeus/code armadeus
apf/# cd armadeus
armadeus/# make apf28_defconfig
Customise things you want to.
  • Apply Armadeus patches:
armadeus/# export KDIR=$PWD/buildroot/output/build/linux-2.6.35.3
armadeus/# make $KDIR/.stamp_downloaded $KDIR/.stamp_extracted $KDIR/.stamp_patched
Adjust KDIR depending on the kernel you chose at the preceding step.
  • Copy default configuration:
armadeus/# cp buildroot/target/device/armadeus/apf28/apf28-linux-2.6.35.3.config $KDIR/.config
  • Configure and compile the kernel:
armadeus/# cd $KDIR
linux-2.6.35.3/# mkdir modout
linux-2.6.35.3/# make INSTALL_MOD_PATH=$KDIR/modout ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig uImage modules modules_install
menuconfig can be omitted if you're happy with the default kernel configuration.

Now we have a kernel at $KDIR/arch/arm/boot/uImage and the modules under $KDIR/modout. Let's build the rootfs.

Multistrap

Multistrap does basically quite the same things than 'debootstrap --foreign', fetching packages from an emdebian repository, building a root tree and leaving packages unconfigured.

  • Get back to the base directory:
linux-2.6.35.3/# cd ../../../../
apf28/#
  • Create a config file for multistrap:
apf28/# cat > stable.config << EOF
[General]
arch=armel
directory=rootfs
cleanup=true
noauth=false
unpack=true
debootstrap=Grip
aptsources=Grip 

[Grip]
packages=
keyring=emdebian-archive-keyring
source=http://www.emdebian.org/grip
suite=stable
EOF
'packages=' is a space separated list of additional packages.
If you have issues with the archive keyring you can either set 'noauth=true' or download this backport:
apf28/# wget http://backports.debian.org/debian-backports/pool/main/m/multistrap/multistrap_2.1.15~bpo60+1_all.deb
apf28/# dpkg -i multistrap_2.1.15~bpo60+1_all.deb
  • Build:
apf28/# multistrap -f stable.config
  • Copy the kernel and the modules:
apf28/# cp $KDIR/arch/arm/boot/uImage rootfs/boot/apf28-linux.bin
apf28/# cp -r $KDIR/modout/lib rootfs/
uImage is renamed to apf28-linux.bin so that u-boot can find it.

Finalisation

We're near the end.

  • Set hostname:
apf28/# echo 'apf28' >> rootfs/etc/hostname
  • Avoid some warnings:
apf28/# touch rootfs/etc/fstab
  • Network configuration (address,netmask,etc...) will be inherited from u-boot, but we'll need these:
apf28/# echo '127.0.0.1 localhost' >> rootfs/etc/hosts
apf28/# echo 'nameserver 192.168.0.1' >> rootfs/etc/resolv.conf
  • Add emdebian repository:
apf28/# echo 'deb http://www.emdebian.org/grip/ stable main' >> rootfs/etc/apt/sources.list
  • The very last step will occur onboard. Create a shell script to be executed at first boot:
apf28/# cat > rootfs/first_boot.sh << EOF
#! /bin/sh

set -e

export PATH=/usr/sbin:/usr/bin:/sbin:/bin
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C
export LANGUAGE=C
export LANG=C

mount proc -t proc /proc

# Workaround configuration of dash and bash failures
# See http://lists.debian.org/debian-embedded/2011/11/msg00037.html
mkdir -p /usr/share/man/man1
/var/lib/dpkg/info/dash.preinst

# Configure packages
dpkg --configure -a

# Reset root password
sed -i -e 's/root:\*:/root::/' /etc/shadow

# Enable login through debug console
echo 'T0:23:respawn:/sbin/getty -L ttyAM0 115200 vt100' >> /etc/inittab

# Self delete
rm $0
sync
echo 'Done! You can reset the board.'
while true;
do
echo '.\c'
sleep 1
done
EOF
  • Make it executable:
apf28/# chmod +x rootfs/first_boot.sh
  • Copy the rootfs on the SD:
apf28/# mkdir /mnt/sd
apf28/# mount /dev/sdc1 /mnt/sd
apf28/# cp -rp rootfs/* /mnt/sd
apf28/# umount /mnt/sd
  • Put the SD card into its placeholder, poweron the base board and interrupt the automatic boot. We need to tell the kernel it must launch first_boot.sh:
BIOS> setenv extrabootargs init=/first_boot.sh
BIOS> run mmcboot
update-alternative will complain about missing manpages. It can be ignored.

This should end-up with something like that:

Done! You can reset the board.
......

So...reset the board. To boot on emdebian, just get u-boot prompt and type:

BIOS> run mmcboot

To have it permanent:

BIOS> setenv bootcmd run mmcboot
BIOS> saveenv

Issues, tips, misc...

  • Sometimes u-boot fails to load the kernel
BIOS> run mmcboot
mmc0 is current device
Loading file "/boot/apf28-linux.bin" from mmc device 0:1 (xxa1)
MMC0: Data timeout with command 18 (status 0xe03c2020)!
 ** ext2fs_devread read error - block
** Unable to read "/boot/apf28-linux.bin" from mmc 0:1 **
## Booting kernel from Legacy Image at 40000000 ...
   Image Name:   Linux-2.6.35.3
   Created:      2012-07-02  14:05:13 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2714300 Bytes = 2.6 MiB
   Load Address: 40008000
   Entry Point:  40008000
   Verifying Checksum ... Bad Data CRC
ERROR: can't get kernel image!

Powering off/on (not just reset) solves the problem. I'm unable to say what is faulty, u-boot, hardware, other...?

  • you can also boot embdebian through your network NFS shared connection:

Copy the rootfs on your share NFS folder:

apf28/# mkdir -p /tftpboot/apf28-root
apf28/# cp -rp rootfs/* /tftpboot/apf28-root


For the first boot use

BIOS> setenv extrabootargs  init=/first_boot.sh
BIOS> run nfsboot

then after having succesfully deployed the embedebian distro:

BIOS> run nfsboot

Links