
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; base–devel – 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.
Recent Comments