How to create bare minimum Debian Wheezy rootfs from scratch

debian-wheezy-download

In this post we will explain how you can create your own Debian rootfs with pre-installed packages of your choice, which to allow tiny Linux images to be created.

All steps below should work on any Debian host (Debian/Ubuntu etc) and are verified with Ubuntu 12.04LTS.

First of all you need to install the support packages on your pc

sudo apt-get install qemu-user-static debootstrap binfmt-support

 

Next you need to choose the version of Debian in this case we are building a wheezy image.

targetdir=rootfs
distro=wheezy

 

Now we will build first stage of Debian rootfs :

mkdir $targetdir
sudo debootstrap --arch=armhf --foreign $distro $targetdir

 

Next copy the qemu-arm-static binary into the right place for the binfmt packages to find it and copy in resolv.conf from the host.

sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin/
sudo cp /etc/resolv.conf $targetdir/etc

 

If everything is right we now have a minimal Debian Rootfs

sudo chroot $targetdir

 

Inside the chroot we need to set up the environment again

distro=wheezy
export LANG=C

 

Now we are setup the second stage of debootstrap needs to run install the packages downloaded earlier

/debootstrap/debootstrap --second-stage

 

Once the package installation has finished, setup some support files and apt configuration.

 

cat <<EOT > /etc/apt/sources.list
deb http://ftp.uk.debian.org/debian $distro main contrib non-free
deb-src http://ftp.uk.debian.org/debian $distro main contrib non-free
deb http://ftp.uk.debian.org/debian $distro-updates main contrib non-free
deb-src http://ftp.uk.debian.org/debian $distro-updates main contrib non-free
deb http://security.debian.org/debian-security $distro/updates main contrib non-free
deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
EOT
 

Update Debian package database:

apt-get update

 

set up locales dpkg scripts tend to complain otherwise, note in jessie you will also need to install the dialog package as well.

 

apt-get install locales dialog
dpkg-reconfigure locales

 

Install some useful packages inside the chroot

apt-get install openssh-server ntpdate

 

Set a root password so you can login

passwd

 

Build a basic network interface file so that the board will DHCP on eth0

echo <<EOT >> /etc/network/interfaces
allow-hotplug eth0
iface eth0 inet static
	address 192.168.1.254
	netmask 255.255.255.248
	gateway 192.168.1.1	
EOT

 

Note: Your board will be accessible over SSH on IP address defined above !

 

Set the hostname

echo nameme > /etc/hostname

 

Enable the serial console, Debian sysvinit way

echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> /etc/inittab

 

We are done inside the chroot, so quit the chroot shell

exit

 

Tidy up the support files

sudo rm $targetdir/etc/resolv.conf
sudo rm $targetdir/usr/bin/qemu-arm-static

 

Now you have your Debian rootfs. Next step is to build Kernel, Uboot and to make your SD-card as explained in our early posts and Build instructions but instead to use the rootfs in the posts you can use your own minimal rootfs which you created above. The rootfs image created above is approx 150MB, it could be made smaller if you remove more packages.

Special thanks to Dimitar Gamishev (aka HEHOPMAJIEH) for creating this tutorial.

A10-OLinuXino-LIME Debian Build with Kernel 3.4.90+

Image

 

A while ago we put on our Forum wishlist for the next Debian release, now in this Debian release we implemented most of the requests we read on the forum.

Here is Debian image for A10-OLinuXino-LIME with Kernel 3.4.90+

Here is Building description.

Here is List of installed packages.

Here is image description.

Building Debian Linux image for A10-OLinuXino-Lime with Kernel 3.4.67+

Image

If you do not want to bother with Linux Debian image generations here is image build following the instructions below, so you just write it to SD card and boot your LIME 🙂

1. Setup of the toolchain

You should make sure you have the tools for building the Linux Kernel and install them if you don’t have them. To install new software you should be with super user rights on your Linux machine, so do this type in a terminal.

$ sudo su

you will be asked for your password and then your prompt will change to # which means you are now the super user, all future commands should be run in this mode.

First update apt-get links by typing

# apt-get update

Install the toolchain by typing the following.

# apt-get install gcc-4.7-arm-linux-gnueabihf ncurses-dev uboot-mkimage build-essential git

This will install: GCC compiler used to compile the kernal, The kernel config menu
uboot make image which is required to allow the SD card to book into the linux image, Git which allows you to download from the github which holds source code for some of the system, Some other tools for building the kernel.

Note that if you use debian may be you will need to add

deb http://www.emdebian.org/debian squeeze main

in the file below:

/etc/apt/sources.list

after the installation you now have all tools to make your very own A10 kernel image!

2. Building Uboot

The Allwinner Linux-Sunxi community uboot is maintained by Henrik Nordstrom aka hno on Freenode irc. You can find him in #linux-sunxi or #olimex channels, if something with uboot is broken he is your man 🙂

First let’s make the directory where we will build the A10-OLinuXino-LIME linux:

# mkdir A10_kernel_3.4/
 # cd A10_kernel_3.4/

Then let’s download the uboot sources from GitHub repository, note there are lot of branches but you have to use sunxi branch.

Note that the A10-OLinuXino-LIME board u-boot is tested with the next branch:

# git rev-parse --verify HEAD
 4e491b03b53bd89af3065fc325a99106d0161998

Download u-boot sourses:

# git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git

After the download you should have a new directory

# cd u-boot-sunxi/

With the following command you can start the uboot build:

# make A10-OLinuXino-Lime CROSS_COMPILE=arm-linux-gnueabihf-

At the end of the process you can check if everything is OK by

# ls u-boot.bin u-boot-sunxi-with-spl.bin spl/sunxi-spl.bin
spl/sunxi-spl.bin u-boot.bin u-boot-sunxi-with-spl.bin

If you got these files everything is complete, well done so far

# cd ..

You should be in the following directory

/home/user/A10_kernel_3.4/#

3. Building kernel sources for A10-OLinuXino-LIME

For problems related to Linux Kernel  use  #linux-sunxi irc channel or Google groups Mailing List.

Kernel sources for A10 are available on GitHub. Note that the following building is made with the revision below:

# git rev-parse --verify HEAD
 a7350cb6a9ec1aae510e26cdc730f05f12e13f9f

You can download the kernel sources using the following command:

# git clone https://github.com/linux-sunxi/linux-sunxi

After the download go to the kernel directory

# cd linux-sunxi/

Here you need from A10 configuration file – a10lime_defconfig. The file contains all kernel module settings.

Download a10lime_defconfig then copy a10lime_defconfig file to configs directory:

# cp a10lime_defconfig linux-sunxi/arch/arm/configs/.

and make:

# make ARCH=arm a10lime_defconfig

The result should be:

configuration written to .config

If you wish to make your changes in the kernel configuration do:

# make ARCH=arm menuconfig

The menuconfig changes a .config text file, which you can view/edit even with a text editor like vi,nano.

With this command you can add or remove different modules for the different peripherials in the kernel. Be careful when use this as this may cause the kernel to not work properly.

Note that before compiling kernel you have to do a patch related with I2C speed. The patch changes i2c speed from 200kHz to 100kHz.
If you want to use some of olimex’s i2c modules on UEXT then you need from this patch.

Download the patch sunxi-i2c.patch and apply the patch:

# patch -p0 < sunxi-i2c.patch

The other patch is related with A10-OLinuXino-LIME sound.

Download the patch a10_sound.patch and apply the patch:

# patch -p0 < a10_sound.patch

Note that by default A10-OLinuXino-LIME board there is no audio connectors and if you do not need from audio then you no need from this patch.

Now you can continue with kernel image compiling.

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 uImage

when this finish’s you will have uImage ready and the result should be:

Image Name: Linux-3.4.67+
 Created: Mon Sep 16 13:39:04 2013
 Image Type: ARM Linux Kernel Image (uncompressed)
 Data Size: 5450904 Bytes = 5323.15 kB = 5.20 MB
 Load Address: 40008000
 Entry Point: 40008000
 Image arch/arm/boot/uImage is ready

Now you can build the kernel modules:

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 INSTALL_MOD_PATH=out modules
 # make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 INSTALL_MOD_PATH=out modules_install

DONE! At this point you have uboot and kernel modules.

The uImage file is located in linux-sunxi/arch/arm/boot/

The kernel modules are located in linux-sunxi/out/lib/modules/3.x.xx where 3.x.xx is kernel version in our case the directory with modules is:

linux-sunxi/out/lib/modules/3.4.67+

4. Format and setup the SD-card

We suggest 4GB class 10 micro sd-card but you can use any card between 2GB and 16GB.

First we have to make the correct card partitions, this is done with fdisk.

Plug SD card into your SD card reader and enter in the terminal

# ls /dev/sd

Then press two times <TAB> you will see a list of your sd devices like sda sdb sdc note that some of these devices may be your hard disk so make sure you know which one is your sd card before you proceed as you can damage your HDD if you choose the wrong sd-device. You can do this by unplugging your sd card reader and identify which “sd” devices remove from the list.

Once you know which device is your sdcard like sda use this text instead of the sdX name in the references below:

# fdisk /dev/sdX

then do these steps:

1. p

will list your partitions

if there are already partitions on your card do:

2. d enter 1

if you have more than one partitition press d while delete them all

3. create the first partition, starting from 2048
n enter p enter 1 enter enter +16M

4. create second partition
n enter p enter 2 enter enter enter

then list the created partitions:
p enter

if you did everything correctly on 4GB card you should see something like:

Disk /dev/sdg: 3980 MB, 3980394496 bytes
 123 heads, 62 sectors/track, 1019 cylinders, total 7774208 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
 /dev/sdg1 2048 34815 16384 83 Linux
 /dev/sdg2 34816 7774207 3869696 83 Linux

7. w

write changes to sd card

now we have to format the file system on the card:

the first partition should be vfat as this is FS which the Allwinner bootloader understands

# mkfs.vfat /dev/sdX1

the second should be normal Linux EXT3 FS

# mkfs.ext3 /dev/sdX2

5. Write the Uboot and sunxi-spl.bin

You should be in /home/user/A10_kernel_3.4/# directory

Note that you have to write u-boot-sunxi-with-spl.bin in /dev/sdX (not sdX1 or sdX2)

# dd if=u-boot-sunxi/u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

6. Write kernel uImage you build to the SD-card

You should be in the directory below

/home/user/A10_kernel_3.4/# directory
 # mount /dev/sdX1 /mnt/sd

copy the Kernel uImage to root directory in partition 1

# cp linux-sunxi/arch/arm/boot/uImage /mnt/sd

7. Write script.bin file

script.bin is a file with very important configuration parameters like port GPIO assignments, DDR memory parameters, Video resolution etc.

Download the script.bin

# cp script.bin /mnt/sd
# sync
# umount /dev/sdX1

8. Debian rootfs

The Linux Kernel and Uboot are ready, now we have need from Linux distribution rootfs.

Basically the only difference between the different Linux distributions is the rootfs, so if you put Debian rootfs you will have Debian, if you put Ubuntu rootfs it will be Ubuntu etc.

How to build one is a long topic, the good thing is that there are many already pre-built so we can just download one and use.

exit the kernel directory

# cd ..

You should be in the directory below

# /home/user/A10_kernel_3.4/

download debian rootfs – a10-olinuxino-lime.tgz

mount your sd card EXT3 FS partition:

# mkdir /mnt/sd
# mount /dev/sdX2 /mnt/sd

and unarchive the rootfs

# tar xzvf debian_34_67_fs.tgz -C /mnt/sd
# ls /mnt/sd

the right result should be:
bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var

Now you have to replace the new generated kernel modules from

/home/user/A10_kernel_3.4/linux-sunxi/out/lib/modules/ to the new debian file system

# rm -rf /mnt/sd/lib/modules/*
# cp -rfv linux-sunxi/out/lib/modules/3.x.xx+/ /mnt/sd/lib/modules/

where x.xx is the kernel version in our case:

# cp -rfv linux-sunxi/out/lib/modules/3.4.67+/ /mnt/sd/lib/modules/

replace /lib/firmware folder with the generated /linux-sunxi/out/firmware

# rm -rf /mnt/sd/lib/firmware/
# cp -rfv linux-sunxi/out/lib/firmware/ /mnt/sd/lib/
# sync
# umount /mnt/sdX2

at this point you have Debian on your SD card second partition and you have an SD card ready to boot debian on A10-OLinuXino-Micro

Connect USB-SERIAL-CABLE-F to UEXT Tx.Rx and GND, or connect a HDMI screen. Put the SD-card in A10-OLinuXino-Micro and apply 5V power, you should see Uboot and then Kernel messages on the console

default username/password is : root / olimex

Building the Ultimate Debian SD card for Linux with Kernel 3.4 for A20-OLinuxino-MICRO

Image

 

EDIT: there is newer image with hardware accelerated video: https://olimex.wordpress.com/2014/03/07/building-a20-olinuxino-micro-debian-image-with-hardware-accelerated-video/

 

This is step by step instruction how to Build Debian for A20-OLinuXino with Kernel 3.4

We call this image ULTIMATE as it supports all hardware features and fix all known bugs to the moment 🙂

The built image ready to write on SD card will be linked on our wiki in a hour, these steps below are just for Linux geeks who want to know how things happend and want to do Debian distribution by themself or to modify it.

1. Setup of the toolchain

You should make sure you have the tools for building the Linux Kernel and install them if you don’t have them. To install new software you should be with super user rights on your Linux machine, so do this type in a terminal.

$ sudo su

you will be asked for your password and then your prompt will change to # which means you are now the super user, all future commands should be run in this mode.

First update apt-get links by typing

# apt-get update

Install the toolchain by typing the following.

# apt-get install gcc-4.7-arm-linux-gnueabihf ncurses-dev uboot-mkimage build-essential git

This will install: GCC compiler used to compile the kernal, The kernel config menu
uboot make image which is required to allow the SD card to book into the linux image, Git which allows you to download from the github which holds source code for some of the system, Some other tools for building the kernel

Note that if you use debian may be you will need to add

deb http://www.emdebian.org/debian squeeze main

in the file below:

/etc/apt/sources.list

after the installation you now have all tools to make your very own A20 kernel image!

2. Building Uboot

The Allwinner Linux-Sunxi community uboot is maintained by Henrik Nordstrom aka hno on Freenode irc. You can find him in #linux-sunxi or #olimex channels, if something with uboot is broken he is your man 🙂

First let’s make the directory where we will build the A20-OLinuXino-Micro linux:

# mkdir a20_kernel_3.4/
# cd a20_kernel_3.4/

Then let’s download the uboot sources from GitHub repository, note there are lot of branches but you have to use sunxi branch.
Note that the OLinuXino-A20-Micro board u-boot is tested with the next branch:

# git rev-parse --verify HEAD
8a4621c488f33089d831168bfa5bae210a5684c8

Download u-boot sourses:

# git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git

After the download you should have a new directory

# cd u-boot-sunxi/

With the following command you can start the uboot build:

# make a20-olinuxino_micro CROSS_COMPILE=arm-linux-gnueabihf-

At the end of the process you can check if everything is OK by

# ls u-boot.bin u-boot-sunxi-with-spl.bin spl/sunxi-spl.bin
spl/sunxi-spl.bin u-boot.bin u-boot-sunxi-with-spl.bin

If you got these files everything is complete, well done so far

# cd ..

You should be in the following directory

/home/user/a20_kernel_3.4/#

3. Building kernel sources for Olinuxino-A20-Micro

The Allwinner Linux-Sunxi community Kernel developers can be reached on http://linux-sunxi.org/Mailing_list

Kernel sources for A20 are available on GitHub. Note that the following building is made with the revision below:

# git rev-parse --verify HEAD
a7350cb6a9ec1aae510e26cdc730f05f12e13f9f

You can download the kernel sources using the following command:

# git clone https://github.com/linux-sunxi/linux-sunxi

After the download go to the kernel directory

# cd linux-sunxi/

Here you need from a20 configuration file – a20_defconfig. The file contains all kernel module settings.

Download a20_defconfig then copy a20_defconfig file to configs directory:

# cp a20_defconfig linux-sunxi/arch/arm/configs/.

and make:

# make ARCH=arm a20_defconfig

The result should be:

configuration written to .config

If you wish to make your changes in the kernel configuration do:

# make ARCH=arm menuconfig

The menuconfig changes a .config text file, which you can view/edit even with a text editor like vi,nano.

With this command you can add or remove different modules for the different peripherials in the kernel. Be careful when use this as this may cause the kernel to not work properly.

Note that before compiling kernel you have to do a patch realted with I2C speed. The patch changes i2c speed from 200kHz to 100kHz.

If you want to use some of olimex’s i2c modules on UEXT then you need from this patch.

download the patch sunxi-i2c.patch and apply the patch:

# patch -p0 < sunxi-i2c.patch

Now you can continue with kernel image compiling

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 uImage

when this finish’s you will have uImage ready and the result should be:

Image Name: Linux-3.4.67+
Created: Mon Sep 16 13:39:04 2013
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 5450904 Bytes = 5323.15 kB = 5.20 MB
Load Address: 40008000
Entry Point: 40008000
Image arch/arm/boot/uImage is ready

Now you can build the kernel modules:

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 INSTALL_MOD_PATH=out modules
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 INSTALL_MOD_PATH=out modules_install

DONE! At this point you have uboot and kernel modules.

The uImage file is located in linux-sunxi/arch/arm/boot/

The kernel modules are located in

linux-sunxi/out/lib/modules/3.x.xx

where 3.x.xx is kernel version

in our case the directory with modules is:

linux-sunxi/out/lib/modules/3.4.67+

4. Format and setup the SD-card

We suggest 4GB class 10 micro sd-card but you can use any card between 2GB and 16GB.

First we have to make the correct card partitions, this is done with fdisk.

Plug SD card into your SD card reader and enter in the terminal

# ls /dev/sd

Then press two times <TAB> you will see a list of your sd devices like sda sdb sdc note that some of these devices may be your hard disk so make sure you know which one is your sd card before you proceed as you can damage your HDD if you choose the wrong sd-device. You can do this by unplugging your sd card reader and identify which “sd” devices remove from the list.

Once you know which device is your sdcard like sda use this text instead of the sdX name in the references below:

# fdisk /dev/sdX

then do these steps:

1. p

will list your partitions

if there are already partitions on your card do:

2. d enter 1

if you have more than one partitition press d while delete them all

3. create the first partition, starting from 2048

n enter p enter 1 enter enter +16M

4. create second partition

n enter p enter 2 enter enter enter

then list the created partitions:

p enter

if you did everything correctly on 4GB card you should see something like:

Disk /dev/sdg: 3980 MB, 3980394496 bytes
123 heads, 62 sectors/track, 1019 cylinders, total 7774208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdg1 2048 34815 16384 83 Linux
/dev/sdg2 34816 7774207 3869696 83 Linux

7. w

write changes to sd card
now we have to format the file system on the card:

the first partition should be vfat as this is FS which the Allwinner bootloader understands

# mkfs.vfat /dev/sdX1

the second should be normal Linux EXT3 FS

# mkfs.ext3 /dev/sdX2

5. Write the Uboot and sunxi-spl.bin

You should be in /home/user/a20_kernel_3.4/# directory
Note that you have to write u-boot-sunxi-with-spl.bin in /dev/sdX (not sdX1 or sdX2)

# dd if=u-boot-sunxi/u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

6. Write kernel uImage you build to the SD-card

You should be in the directory below

/home/user/a20_kernel_3.4/# directory 
# mount /dev/sdX1 /mnt/sd

copy the Kernel uImage to root directory in partition 1

# cp linux-sunxi/arch/arm/boot/uImage /mnt/sd

7. Write script.bin file

script.bin is a file with very important configuration parameters like port GPIO assignments, DDR memory parameters, Video resolution etc,

download the script.bin file

# cp script.bin /mnt/sd
# sync
# umount /dev/sdX1

8. Debian rootfs

The Linux Kernel and Uboot are ready, now we have need from Linux distribution rootfs.

Basically the only difference between the different Linux distributions is the rootfs, so if you put Debian rootfs you will have Debian, if you put Ubuntu rootfs it will be Ubuntu etc.

How to build one is a long topic, the good thing is that there are many already pre-built so we can just download one and use.

exit the kernel directory

# cd ..

You should be in the directory below

# /home/user/a20_kernel_3.4/

download debian rootfs – debian_34_67_fs.tgz

mount your sd card EXT3 FS partition:

# mkdir /mnt/sd
# mount /dev/sdX2 /mnt/sd

and unarchive the rootfs

# tar xzvf debian_34_67_fs.tgz -C /mnt/sd
# ls /mnt/sd

the right result should be:

bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var

Now you have to replace the new generated kernel modules from

/home/user/a20_kernel_3.4/linux-sunxi/out/lib/modules/ to the new debian file system

# rm -rf /mnt/sd/lib/modules/*
# cp -rfv linux-sunxi/out/lib/modules/3.x.xx+/ /mnt/sd/lib/modules/

where x.xx is the kernel version

in our case:

# cp -rfv linux-sunxi/out/lib/modules/3.4.67+/ /mnt/sd/lib/modules/

replace /lib/firmware folder with the generated /linux-sunxi/out/firmware

#rm -rf /mnt/sd/lib/firmware/
#cp -rfv linux-sunxi/out/lib/firmware/ /mnt/sd/lib/
# sync
# umount /mnt/sdX2

at this point you have Debian on your SD card second partition and
you have an SD card ready to boot debian on A20-OLinuXino-Micro

Connect USB-SERIAL-CABLE-F to UEXT Tx.Rx and GND, or connect a HDMI screen. Put the SD-card in A20-OLinuXino-Micro and apply 6-16V power, you should see Uboot and then Kernel messages on the console

default username/password is : root / olimex

Building Linux for A10S from Scratch

Image

In this post we will explain step by step what you have to do to build the A10S-Debian Linux image and all tools and steps so you can duplicate our image or modify and generate new images which to add support for modules which we didn’t included in our image.

Note that we use Linux-Sunxi github repository to generate the Uboot and Linux kernel. Linux-Sunxi is work in progress  and Linux-Sunxi community is very active, this means every day tens of changes are commited to the repository, unfortunately some of them are not well tested so sometimes things go broken, if you follow the steps below and you get error at some point, just report it to #linux-sunxi irc channel, thing usually get fixed very quickly in matter of hours 🙂

I’ve spoken with hno how to make SNAPSHOT of the current GitHub repository so when git checkout to be sure we use this exactly snapshot which we use to build, but I’m not so good with GitHub and didn’t understood how to use tags, any help is welcome. Anyway latest Linux-Sunxi should be always better and improved (unless something is broken unintentionally 😉 )

1. Setup of the toolchain

You should make sure you have the tools for building the Linux Kernel and install them if you don’t have them. To install new software you should be with super user rights on your Linux machine, so do this type in a terminal.

$ sudo su

you will be asked for your password and then your prompt will change to # which means you are now the super user, all future commands should be run in this mode.

First update apt-get links by typing

# apt-get update

Install the toolchain by typing the following.

# apt-get install gcc-4.6-arm-linux-gnueabi ncurses-dev uboot-mkimage build-essential git

This will install: GCC compiler used to compile the kernal, The kernel config menu
uboot make image which is required to allow the SD card to book into the linux image, Git which allows you to download from the github which holds source code for some of the system, Some other tools for building the kernel

Note that if you use debian may be you will need to add

deb http://www.emdebian.org/debian squeeze main

in the file below:

/etc/apt/sources.list

after the installation you now have all tools to make your very own A10s kernel image!

2. Building Uboot

The Allwinner Linux-Sunxi community uboot is maintained by Henrik Nordstrom aka hno on Freenode irc. You can find him in #linux-sunxi or #olimex channels, if something with uboot is broken he is your man 🙂

First let’s make the directory where we will build the A10S-OLinuXino Linux:

# mkdir a10s_olinuxino 
# cd a10s_olinuxino

Then let’s download the uboot sources from GitHub repository, note there are lot of branches but you have to use sunxi branch.

# git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git

After the download you should have a new directory

# cd u-boot-sunxi/

With the following command you can start the uboot build:

# make A10s-OLinuXino-M CROSS_COMPILE=arm-linux-gnueabi-

At the end of the process you can check if everything is OK by

# ls u-boot.bin spl/sunxi-spl.bin

If you got these two files everything is complete, well done so far

# cd ..

You should be in the following directory

/home/user/a10s_olinuxino#

3. Building kernel sources for Olinuxino A10S

The Allwinner Linux-Sunxi community Kernel is maintained by Alejandro Mery aka mnemoc on Freenode irc. You can find him in #linux-sunxi or #olimex channel, if something is broken with the Linux Kernel you can contact him or use http://linux-sunxi.org/Mailing_list

Kernel sources for A10s are available on GitHub. You can download them using the following command:

# git clone https://github.com/linux-sunxi/linux-sunxi.git

After the download go to the kernel directory

# cd linux-sunxi/

Here you need from a10s configuration file – a10s_olinuxino_defconfig. The file contains all kernel module settings.

Download a10s_olinuxino_deconfig from https://docs.google.com/file/d/0B-bAEPML8fwldzdkQjJrdW5EU00/edit?usp=sharing

then copy a10s_olinuxino_defconfig file to configs directory:

# cp a10s_olinuxino_defconfig linux-sunxi/arch/arm/configs/.

and make:

# make ARCH=arm a10s_olinuxino_defconfig

update .config file

the above step will generate Linux Kernel with all modules we selected and tested, if you wish to make your changes in the kernel configuration do:

# make ARCH=arm menuconfig

The menuconfig changes a .config text file, which you can view/edit even with a text editor like vi,nano.

With this command you can add or remove different modules for the different peripherials in the kernel. Be careful when use this as this may cause the kernel to not work properly.

You have to patch i2c speed sourses in order to use some of olimex i2c modules on UEXT with software implemented i2C.

The pach change i2c1 and i2c2 speed from 200kHz to 100kHz.

For this purpose use A10S_100kHz_I2C.patch file

Download A10S_100kHz_I2C.patch from https://docs.google.com/file/d/0B-bAEPML8fwlRVRjWE1wdlhxeTQ/edit?usp=sharing

the file has to be copied to and started from arch/arm/plat-sunxi/include/plat/ directory

# cp A10S_100kHz_I2C.patch arch/arm/plat-sunxi/include/plat/
# cd arch/arm/plat-sunxi/include/plat/
# patch -p0 < A10S_100kHz_I2C.patch

the result should be:

patching file i2c.h

Go to linux-sunxi folder

# cd /home/user/a10s_olinuxino/linux-sunxi

Now you can contiue a10s_configuration compiling:

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage

when this finish’s you will have uImage ready and you can build the kernel modules:

# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=out modules
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=out modules_install

DONE! At this point you have uboot and kernel modules.

The uImage file is located in /a10s_olinuxino/linux-sunxi/arch/arm/boot/

The kernel modules are located in

/a10s_olinuxino/linux-sunxi/out/lib/modules/3.x.xx

where 3.x.xx is kernel version

in our case the directory with modules is:

/a10s_olinuxino/linux-sunxi/out/lib/modules/3.0.76+

4. Format and setup the SD-card

We suggest 4GB class 10 micro sd-card but you can use any card between 2GB and 16GB.

First we have to make the correct card partitions, this is done with fdisk.

Plug SD card into your SD card reader and enter in the terminal

# ls /dev/sd

Then press two times <TAB> you will see a list of your sd devices like sda sdb sdc note that some of these devices may be your hard disk so make sure you know which one is your sd card before you proceed as you can damage your HDD if you choose the wrong sd-device. You can do this by unplugging your sd card reader and identify which “sd” devices remove from the list.

Once you know which device is your sdcard like sda use this text instead of the sdX name in the references below:

# fdisk -u=sectors /dev/sdX

then do these steps:

1. p

will list your partitions

if there are already partitions on your card do:

2. d 1

if you have more than one partitition press d while delete them all

3. n p 1

create the first partition, starting from 2048 and ending to 34815

4. beginning 2048 end 34815

create second partition

5. n p 2 enter enter

then list the created partitions:

6. p

if you did everything correctly on 4GB card you should see something like:

Disk /dev/sdX: 3980 MB, 3980394496 bytes
123 heads, 62 sectors/track, 1019 cylinders, total 7774208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdg1 2048 34815 16384 83 Linux
/dev/sdg2 34816 7774207 3869696 83 Linux

7. w

write changes to sd card

now we have to format the file system on the card:

the first partition should be vfat as this is FS which the Allwinner bootloader understands

# mkfs.vfat /dev/sdX1

the second should be normal Linux EXT3 FS

# mkfs.ext3 /dev/sdX2

5. Debian rootfs

The Linux Kernel and Uboot are ready, now we have need from Linux distribution rootfs.

Basically the only difference between the different Linux distributions is the rootfs, so if you put Debian rootfs you will have Debian, if you put Ubuntu rootfs it will be Ubuntu etc.

How to build one is a long topic, the good thing is that there are many already pre-built so we can just download one and use.

exit the kernel directory

# cd ..

You should be in the directory below

# /home/user/a10s_olinuxino/

download debian rootfs – debian_fs_olimex.tar.gz from https://docs.google.com/file/d/0B-bAEPML8fwlZU9RSmZCdGtwZkk/edit?usp=sharing

mount your sd card EXT3 FS partition:

# mount /dev/sdX2 /mnt
# cd /mnt/

and unarchive the rootfs

# tar -xzvf /home/user/a10s_olinuxino/debian_fs_olimex.tar.gz
# ls

the right result should be:

bin boot dev etc home lib lost+found media mnt opt proc root run sbin selinux srv sys tmp usr var
# cd ..

copy the last generated kernel modules in the new debian file system

cp -rf linux-sunxi/out/lib/modules/3.x.xx+/ /mnt/lib/modules/.

where x.xx is the kernel version
in our case the directory with moduls is:

/a10s_olinuxino/linux-sunxi/out/lib/modules/3.0.76+
# sync
# umount /mnt

at this point you have Debian on your SD card second partition.

6. Write kernel uImage you build to the SD-card

You should be in the directory below

/home/user/a10s_olinuxino#
# mount /dev/sdX1 /mnt/

copy the Kernel uImage to root directory in partition 1

# cp linux-sunxi/arch/arm/boot/uImage /mnt/.

download the a10s_script files from:

https://docs.google.com/file/d/0B-bAEPML8fwlZ0VVWWZjYVZWajQ/edit?usp=sharing

then untar it in /mnt directory

# tar -xzvf a10s_scripts.tar.gz -C /mnt

the a10s_scripts archive contains:

script.bin
script_a10s_linux_LCD_1024x600
script_a10s_linux_LCD_800x480
script_a10s_linux_LCD_480x272
script_a10s_linux_HDMI
back_up

script.bin is a text file with very important configuration parameters like port GPIO assignments, DDR memory parameters, Video resolution etc, by changing these parameters in the script.bin you can configure your Linux without need to re-compile your kernel again and again this is smart way Allwinner provide for tweaking A10s Linux Kernel. The default A10s-olinuxino configuration is made for HDMI output. If you want to switch between HDMI and LCD_1024x600, LCD800x480 or LCD_480x272 mode then you have to replace the existing script.bin file from the first SD card partitition (note that this partitition is FAT – so you can replace the file under Windows or Linux) with the script.bin file from script_a10s_linux_LCD_1024x600, script_a10s_linux_LCD_800x480 or script_a10s_linux_LCD_480x272 directory

write the Uboot and sunxi-spl.bin

Note that you have to write u-boot.bin and sunxi-spl.bin in /dev/sdX (not sdX1 or sdX2)

# dd if=u-boot-sunxi/spl/sunxi-spl.bin of=/dev/sdX bs=1024 seek=8
# dd if=u-boot-sunxi/u-boot.bin of=/dev/sdX bs=1024 seek=32
# sync
# umount /mnt

Now you have an SD card ready to boot debian on A10s-OLinuXino.

Connect USB-SERIAL-CABLE-F to UEXT Tx.Rx and GND, or connect a HDMI screen. Put the SD-card in A10s-OLinuXino and apply +5V power, you should see Uboot and then Kernel messages on the console

default username/password is : root / olimex

7. Simple test of a10s-olinuxino LED1

You can write and read around 25 GPIO on a10s using the file system

root@A10s:~# ls /sys/class/gpio/export

gpio15_pc3/ gpio20_pe2/ gpio26_pe8/ gpio4_pb11/ gpiochip1/gpio10_pb6/ gpio16_pc7/ gpio21_pe3/ gpio27_pe9/ gpio5_pg9/ unexportgpio11_pb7/ gpio17_pc16/ gpio22_pe4/ gpio28_pe10/ gpio6_pg10/gpio12_pb8/ gpio18_pc17/ gpio23_pe5/ gpio29_pe11/ gpio7_pb15/gpio13_pb3/ gpio19_pe1/ gpio24_pe6/ gpio2_pb13/ gpio8_pb16/gpio14_pb4/ gpio1_pb14/ gpio25_pe7/ gpio3_pb12/ gpio9_pb5/

root@A10s:~# ls /sys/class/gpio/

this check available GPIO

the LED1 is connected to PE3(gpio21_pe3).

root@A10s:~# echo out > /sys/class/gpio/gpio21_pe3/direction

make PE3 output

root@A10s:~# echo 1 > /sys/class/gpio/gpio21_pe3/value

write logical 1 in PE3 – turn on LED1

root@A10s:~# echo 0 > /sys/class/gpio/gpio21_pe3/value

write logical 0 in PE3 – turn off LED1

————————————–

EDIT: After some discussion with Henrik on irc channel he made git TAGs on uboot and kernel which snapshot the GitHub repositories to match what I wrote above, this means even there are new changes to the GitHub repositories, if you follow the steps above and something is broken you can do after the # git clone …

for u-boot

# git checkout v2013.07-rc1-sunxi

for kernel

# git checkout sunxi-v3.0.76-r0

these commands will point GitHub to same snapshot we used in the posting to build uboot and kernel

Building Debian Linux distribution for iMX233-OLinuXino

Image

iMX233-OLinuXino Debian rootfs generation

If you want to skip the procedures below, the good news is that we have already pre-build Debian rootfs and you can just download it from here: https://docs.google.com/open?id=0B-bAEPML8fwlOHJkX2ZNanVfR2s

and then just read how to make your bootable SD-card as described here: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/DEBIAN/README.TXT

Otherwise if you want to go through the learning path follow these instructions:

1. Prepare empty file system – it’s good to be > 500MB, in this example we make it 1GB

$ dd if=/dev/zero of=my.img bs=1024 count=1MB

2. Format the image with the desired root fs, in this example -ext3

$ sudo mkfs.ext3 -F my.img

3. Mount the image

$ mkdir rootfs
$ sudo mount -o loop my.img rootfs/

4. Install Debian toor file system phase 1

$ sudo debootstrap –verbose –arch armel –variant=minbase –foreign squeeze rootfs/http://ftp.debian.org/debian

5. Install the packages necessary for emulation of armel with x86.
Note: If you make installation of ‘Debian squeeze’ you must install newer version of ‘qemu-user-static’ (otherwise you will see error qemu: Unsupported syscall: 341 when you generate the image in phase 2)

Only for ‘Debian squeeze’

Add these lines in /etc/apt/preferences

Package: *
Pin: release a=stable
Pin-Priority: 900
Package: *
Pin: release o=Debian
Pin-Priority: -10

add in /etc/apt/apt.conf.d/70debconf

APT::Default-Release “stable”;

add in /etc/apt/sources.list

deb http://ftp.debian.org/debian/ testing main contrib

update the list of the packages

$ sudo apt-get update

install qemu-user-static

$ sudo apt-get install -t testing qemu-user-static

install binfmt-support

$ sudo apt-get install binfmt-support

6. Start of phase 2 (this is executed on virtual armel machine). Do these commands:

$ sudo modprobe binfmt_misc
$ sudo cp /usr/bin/qemu-arm-static rootfs/usr/bin
$ sudo mkdir rootfs/dev/pts
$ sudo mount -t devpts devpts rootfs/dev/pts
$ sudo mount -t proc proc rootfs/proc
$ sudo chroot rootfs/

(this is executed on virtual armel machine)
$ /debootstrap/debootstrap –second-stage

7. To add the apt repositories, you must append these lines in /etc/apt/sources.list

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

8. Update the list of the packages

$ apt-get update

9. Config your language

$ export LANG=C
$ apt-get install apt-utils dialog locales

$ dpkg-reconfigure locales
$ export LANG=en_US.UTF-8

10. Installation of some important packages

$ apt-get install dhcp3-client udev netbase ifupdown iproute openssh-server iputils-ping wget net-tools ntpdate nano less

11. Config your network adapter usb11 and dhcp. Add in /etc/network/interfaces these lines

# Wireless interfaces
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf

auto usb0
iface usb0 inet dhcp

12. To config the file system add in /etc/fstab these lines:

/dev/root /dev/sda2 ext3 noatime,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults 0 0

13. To config the console

$ echo ‘T0:2345:respawn:/sbin/getty -L ttyAM0 115200 linux’ >> /etc/inittab
$ sed -i ‘s/^\([1-6]:.* tty[1-6]\)/#\1/’ /etc/inittab

13. To config the host name:

$ hostname <name>

14. To add root password

$ passwd

15. Exit from the armel virtual machine

$ exit

16. TO install the modules of Linux Kernel

$ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=<path_to>/rootfs modules_install

17. and unfortunately this is only the beginning 🙂

in this image we still didn’t manage to enable the TV-console, so we will try to do it later

Stanimir Bonev, Olimex Ltd

EDIT 09/7/2012: there is improvement on how to install the peripherial modules on the Debian distro: http://tech.groups.yahoo.com/group/olinuxino/message/889