How To: Arch Linux ARM for A20-OLinuXino-[MICRO:LIME:LIME2]

arch-linux-logo

Borislav Lilov a.k.a. progmetalbg posted on our forum tutorial how to run Arch Linux on A20-OLinuXino.

https://www.olimex.com/forum/index.php?topic=4261.0

Arch Linux image for A20-OLinuXino

Image

progmetalbg posted on our forum that he successfully built Arch Linux image for A20-OLinuXino-MICRO and then blogged step by step instructions how he did it

iMX233-OLinuXino get started – making the ARCH Linux SD card

Image

In several articles we will make step-by-step guide how first to build ARCH Linux distribution with the necessary tools for development and how then you can write simple HELLO WORLD code and later how to interface our UEXT modules by iMX233-OLinuXino.

I.  First to Get started we need Linux SD card with ARCH Linux.

Why ARCH? Because thanks to Kiril Zyapkov this is the most complete Linux distribution for iMX233-OLinuXino for the moment. It have support for the TV console, I2C, UART, USB, web cameras and different WIFI adapters.

Note that from September 1st we ship ARCH Linux on the iMX233-OLinuXino-SD cards, so if you have one of these you can skip the instructions below, if you do not have you can easily build one, for this purpose you will need computer with running LINUX, we got several messages asking how to build the Linux SD card under Windows and the simple answer is – there is no way you can do this under Windows, if you have Windows the best solution is to download Ubuntu and to install it as second OS, Ubuntu will keep your Windows and you can boot your computer either with Linux either with Windows OS so you do not lose anything (just learn something new 😉 ).

So we assume you have computer running LINUX for the steps below. To write the SD card of course your computer should have also card reader/writer.

1. First you need to download some Linux images from our Gdrive. Put these files in some folder like /home/user/Archlinux for instance.

The files you need are:

Linux-alarm-2.6.35-6-ARCH.img ( https://docs.google.com/open?id=0B-bAEPML8fwlZS0wcFNyLTFpX2M )– this is the kernel image patched with the latest version 2.6.35-6;

– ArchLinuxARM-olinuxino-latest-rootfs-clean.tar.gz ( https://docs.google.com/open?id=0B-bAEPML8fwlLXlxblQxWTVvZVU )– the root file system, only the basics, no extra packages; our recommendation is to get this only if you are familiar with ARCH and you want to add packages by your choice, if you are beginner do not use these but download next file:

– ArchLinuxARM-olinuxino-latest-rootfs.tar.bz2( https://docs.google.com/open?id=0B-bAEPML8fwlNDFUYkx0ZkNWV3c )– the root file system with installed packages and their corresponding dependencies:  mplayer – very powerful media tool to play audio and video; alsi-utils – a tool that can successfully manage the headphone output and line-in input; basedevel – a big and mighty package for every developer; fbset – simple frame buffer ;

2. Insert the card-reader into the Linux host machine.

IMPORTANT NOTE – this example is given with “sdb1” and “sdb2” devices but it could enumerate differently on your host (sdc, sdd, sde etc.), so confirm what it enumerates as before running fdisk!

TIP – Before inserting the card-reader type in the console without pressing Enter:

$ ls /dev/sd

and press the TAB key twice. This should display all of the available devices. Insert the card-reader and press TAB again. Now you should see a new device – the SD-card.

3. Unmount the card-reader:

$ sudo umount /dev/sdb1

NOTE – Some systems doesn’t auto-mount devices so this step may be unnecessary.

4. Format the SD-card using fdisk:

$ sudo fdisk /dev/sdb

5. With the help of the menu create two partitions. The steps are the following:

NOTE – We recommend fist to type “m” to see what does each one of the following operations.

5.1. Type “p” to view existing partitions on the SD-card
5.1. Type “o” to delete all partitions
5.2. Type “n” to create new one
5.3. Set “1” as partition number
5.4. Type “p” to select primary partition
5.5. Press Enter to select default beginning sector
5.6. Type “+32M” to create 32MB partition
5.7. Type “t” to change partition type
5.8. Type “53
5.9. Type “n” to create another partition
5.10. Set “2” as partition number
5.11. Type “p” to set partition as primary
5.12. Press Enter to set default size of the partition
5.13. Type “w” to write partitions to the SD-card

6. Format the second partition with ext3 file system:

$ sudo mkfs.ext3 /dev/sdb2

7. Mount the second partition:

$ sudo mount /dev/sdb2 /mnt/mmc

NOTE – If you don’t have mount-point you should create one. Just type:

$ sudo mkdir /mnt/<dir>

8. Log-in as root for the next operations:

$ sudo su

IMPORTANT NOTE: It is necessary to log-in as root, not as super-user!

9. Extract the downloaded tarball into the second partitions:

# cd /mnt/mmc
# tar -jxvf /home/User/Archlinux/ArchLinuxARM-olinuxino-latest-rootfs.tar.bz2

IMPORTANT NOTE: If you want the clean file system change the second command:

# tar -zxvf /home/User/Archlinux/ArchLinuxARM-olinuxino-latest-rootfs-clean.tar.gz

10. The next step is to to write the boot-loader and kernel image to the first partition.

# dd if=/Archlinux/Linux-alarm-2.6.35-6-ARCH.img of=/dev/sdb1

11. Unmount the SD-card, it should be ready for use.

# cd
# sync
# umount /dev/sdb2

IMPORTANT NOTE: The default log-in is : root, and the password is also: root.

II. Setup Internet

NOTE – This is working example, but you may read some additional information, if this doesn’t work for you.

With every reboot the device is assigned with different MAC address. To change this use these commands:

# ip link set dev usb0 down
# ip link set dev usb0 address aa:bb:cc:dd:ee:ff
# ip link set dev usb0 up

To set an IP address enter:
# ifconfig usb0 192.168.0.249

or whatever address you want.

After that add default gateway:
# route add default gw 192.168.0.1 usb0

Finally you should add DNS-server. You should modify /etc/resolv.conf with vi, or other program. For example:
# vi /etc/resolv.conf

Press d several times to remove all lines. Press I to enter insert mode. Type:
# nameserver 192.168.0.1

(Again this is example. You should add you DNS-server.)
After you finish entering this press Esc. This will set the program in command mode. In command mode press:
:wq

This should do the work. To check connection use ping. If it doesn’t, check your configuration again and router settings. You can use ifconfig to see OLinuXino settings.

III. Hello World!

Now we have all tools to make our first program for iMX233-OLinuXino:

using vi editor you can type this code:

#include <stdio.h>

int main (int argc, char *argv[]) {
if (argc > 1)
printf(“\r\n Hello %s.\r\n\r\n”, argv[1]);
else
printf(“\r\n Hello World.\r\n\r\n”);

return 0 ;
}

if you are lazy to do this in the /home/examples directory this example is already written 🙂

to compile the code use:

# gcc hello_world.c -o hello

then make hello executable with

# chmod +x hello

and you can test the code with

# ./hello <your name>

the code should display

Hello <your name>.

IV. Blinking LED

Now when we made our first C code for iMX233-OLinuXino is time to make our first shell script.

with vi editor again you can write this code :

echo out > /sys/class/gpio/gpio65/direction
while [ 1 -eq 1 ]
do
echo 1 > /sys/class/gpio/gpio65/value
sleep 1
echo 0 > /sys/class/gpio/gpio65/value
sleep 1
done

this is simple endless loop to blink the green LED next to the power connector, if we want it to be executed at every board boot we can add it to the rc.local

# vi /etc/rc.local

Add the path to the script file:

/home/examples/led_blink/led_blink &

The “&” means that the script will be running in background.

Now every time when the board boot will execute this script and the green LED will start blinking which proves the board works correctly.

I hope this is good start for beginners, tomorrow I will post how you can talk to I2C devices connected to UEXT connector like MOD-MAG 3 axis magnetometer for instance.

Building ARCH Linux distribution for iMX233-OLinuXino

Image

iMX233-OLinuXino ARCHLINUX distribution

Kiril Zyapkov is one of our early developers who received free iMX233-OLinuXino-Maxi, he uses ARCHLinux during his daily work and he made ArchLinux distribution for OLinuXino.

The distribution use OpenEmbedded Layer to generate the necessary packages. The project is at GitHub:

https://github.com/OLIMEX/archlinuxarm-olinuxino

If you browse the Github project you will notice PKGBUILD scripts, they are used by makepkg (which is part of pacman, the package manager for arch) to build the packages.

Kiril still work to create custom repo with the kernel, elftosb and imx-bootlets, now he is working on PKGBUILD for imx-bootlets, to may the install script for the kernelto add alone mmcblk0p1, and will be ready in the next days.

For these who want to test Archlinux without building the packages themself there is ready generated binary rootfs at https://docs.google.com/open?id=0B-bAEPML8fwlUnB6MTU4NVdqb1k

It works with the normal Open Embedded generated Kernel 2.6.35 which image you can download from: https://docs.google.com/open?id=0B-bAEPML8fwlWDRpMGl5TGVaNXM

Here are some documentation and useful links:

https://wiki.archlinux.org/index.php/Pacman
https://wiki.archlinux.org/index.php/Pacman_Tips
https://wiki.archlinux.org/index.php/Post_Installation_Tips

and here https://aur.archlinux.org/ is collection of many software which are not part of the repositories.
You can figure out how build system works by browsing their PKGBUILD files.
ArchlinuxARM uses the buildscripts of the original Arch, but with modifications of some packages, the repository is https://github.com/archlinuxarm/PKGBUILDs . There is scrip for rootfs generation https://github.com/archlinuxarm/PKGBUILDs/blob/master/scripts/distro-builder

Kiril is using the same script to generate rootfs-a for OLinuXino.

Short description about how to make bootable SD card with Linux file system for OLinuXino boards

(NOTE – this example is given with “sdb1 and sdb2” device but it could enumerate differently on your host, so confirm what it enumerates as before running fdisk!)

1. Insert the card reader to the Linux host.
2. Un-mount the card reader, i.e. ‘sudo umount /dev/sdb1’
3. run fdisk, ‘sudo fdisk /dev/sdb’
4. Press ‘p’ to show the partitions on the card
5. Press ‘d’ to delete a partition. Repeat to remove all partitions
6. Press ‘n’ to create a new partition
7. Press ‘p’ to select the primary partition
8. Press ‘1’ to create partition 1 on the card
9. Press Enter to start from first block
10. Type ’16MB’ to create the 16MB partitions
11. Press ‘t’ to change the newly created partition type
12. Enter ’53’ for the new partition type
13. Press ‘n’ to create a second partition, select ‘p'(primary), then ‘2’(number)
14. Press Enter to accept all default settings
15. Press ‘w’ to write the partitions to the card and exit the fdisk
16. Format the second partition on the SD card – run ‘sudo mkfs.ext2 /dev/sdb2’ command.
17. Mount the second partition on the card
18. If you do not have the mmc mounting point created yet, create one with ‘sudo mkdir /mnt/mmc’
19. Run ‘sudo mount /dev/sdb2 /mnt/mmc’ to mount the partition as the mmc card
20. Copy the supplied files – alarm-olinuxino-rootfs.tar.gz(the ARCHLINUX FS) and imx233-Olinuxino.zip(boot image) for example in your home/user directory, unzip imx233-Olinuxino.zip to imx233-Olinuxino.img
21. Enter the mounted sd card directory – cd /mnt/mmc
22. Untar the rootfs to the card ‘sudo tar -xzf /home/user/alarm-olinuxino-rootfs.tar.gz’ to put down the root filesystem.
for login use
user:
password:
23. Copy the boot image in sdb1 device using dd, i.e. type – ‘sudo dd if=/home/user/imx233-Olinuxino.img of=/dev/sdb1
24. Type ‘cd’, ‘sync’ and umount sd card – ‘sudo umount /dev/sdb2’

At this point the SD card should be ready for use.

EDIT 09/07/2012: Kiril has updated the GitHub project page with completely instructions and pre-build images: https://github.com/OLIMEX/archlinuxarm-olinuxino

Now you can download and use full functional ARCH Linux ARM distribution