Archive

Tag Archives: kernel

We have one working and simple filesystem working. It is time to take a look on the /dev directory, and see which options do we have.

File devices are a special kind of files, usually found under /dev. If you want to write  to your serial port, open /dev/ttyS0, if you want to access the first framebuffer, go to /dev/fb0, etc. You can also setup permissions, for example, to protect the serial port to be abused from users, or to make a device readonly. And we can create symlinks, so we know that /dev/logitech will point to the correct webcam device.

How we create all this stuff?

The first option  is to use mknod for each device. This is very odd and hard to maintain, but if you are looking for some quick config, or a very fast boot, or a small kernel, you can choose this. With mknod, you specify a pair of magic numbers (driver specific) to create the device. So, you must know all thre devices that are present or that will be present in the future, and the magic numbers. That is quite a mess.

Busybox has a file with all the devices that you want to create when you make the final image. Check  system / device_table.txt . It has the device name, major/minor numbers, and permissions. For example, you can create the serial port and give it permissions to everybody. You can create more things like symlinks, dirs, etc, not only devices…

Tee most sophisticated way, and the usual one that you will find in your distro, is udev. This is not ‘unix traditional’, but it is the standard now in Linux. It works in userspace (safer) and for example, it will trigger actions when you plug devices (and you can create symlinks, etc). But if you have an embedded device, maybe this one is too much.

Nowadays, the kernel uses devtmpfs to handle device files. It will populate  /dev with the default devices and with default permissions (root 0600). It will mount it very early, so, you can do things like init=/bin/sh, and you can create even smaller images.

There were something similar before called devfs, but it had many issues and it is now obsolete. The new version (about 2009) is like ‘devfs done right’.

Busybox has a project called mdev. It is like a micro udev. It will handle things like load kernel modules when you plug an usb camera, etc.

You dont need devtmpfs to run mdev. Calling mdev -s will check /sys and will create the correct devices (slow). If you dont use devtmpfs, you need to call mdev -s in your /bin/init script to populate /dev

So, when the kernel detects a new device, it calls  /proc/sys/kernel/hotplug. To enable mdev :

echo /sbin/mdev > /proc/sys/kernel/hotplug

with some time, I will write a simple mdev.conf with same permissions, and some scripts to automount usb devices under /media

 

I am playing with my a13 olinuxino micro. It is running and I really love it! It is time to connect it to the LAN. The idea of this howto is to have a, more or less, clear idea of all the steps that you need to connect your wifi card, step by step.

This device hasnt any network card (it cost 35 euros), but fortunately I got an old usb wifi card, an Ovislink evo-w300usb, that internally comes with a chip from ralink, the 2870.  The current driver is the rt2800usb. So, if you compile the kernel by yourself, enable the driver here:

Device Drivers  --->
[*] Network device support  --->
[*]   Wireless LAN  ---> 
  <M> Ralink driver support  --->
   <M> Ralink rt2500 (USB) support
    <M> Ralink rt2501/rt73 (USB) support
    <M> Ralink rt27xx/rt28xx/rt30xx (USB) support
    [*] rt2800usb - Include support for rt33xx devices
    [ ] rt2800usb - Include support for unknown (USB) devices
    [*] Ralink debug output

Also, remember to enable all the obvious things, like network support, tcp support, etc.

The next step is to bring the interface up. This device has a proprietary firmware that must be uploaded when you setup the interface. The system will upload the firmware to the device automatically. But with our small system, this is not so easy, because the kernel must have some access to the filesystem.

For an embedded device there are some ways to do it. Busybox has a system called mdev to dinamically update the list of devices. Before you can tell to the kernel that you will use mdev as your device manager, you must mount the sysfs, and setup the kernel ‘hotplugger’ :

# mount -t proc proc /proc
# mount -t sysfs sysfs /sys
# sysctl -w kernel.hotplug=/sbin/mdev
# mdev -s

ok, now, copy the latest firmware to /lib/firmware, and setup the interface

to enable the driver, type

# modprobe rt2800usb

tocheck that your device exists:

# iw list

to bring the device up

# ip link set wlan0 up

if your hotplugger is not correctly configured, the system will hang up for a while… check that /dev is correctly populated and your filesystem is mounted, etc.

ok, now you have a working wireless network card. You can see more info with:

# iw phy phy0 info

to list the available networks, type:

# iw dev wlan0 scan

to check if we are connected to the access point (we are not) :

# iw dev wlan0 link

Now it is time to associate our wireless card to the access point. I assume your router is using WPA2 for encryption. We need the package wpa_supplicant that will stay resident while our interface is connected. We will configure a /etc/wpa_suppliant.conf with all the networks and passwords that we use.

# cat /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant

network={
ssid="MYSSDI"
psk=9f85448469740f8194ccd055cab3109251774aba3f1a788d50ed93a403afd1d5
scan_ssid=1
proto=WPA RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
}

wpa_passphrase is a simple command that will generate the key for authentication.this will genreate something like:

# wpa_passphrase test_ssid supersecret
network={
ssid="test_ssid"
#psk="supersecret"
psk=9574610e6e0032abd916be445cca3b5ab932ec450be3f8066ddfc372229ce238
}

we copy and paste the psk key to our configuration.

At this point, we have a link between our wifi card and the access point. You can see it like that you plugged the cable on the switch. The next step is to include the ip address, etc, and tell the system to use wpa_supplicant when we need it.

# cat /etc/network/interfaces
iface wlan0 inet static
address 192.168.1.15
netmask 255.255.255.0
wireless-essid MYSSID
gateway 192.168.1.5
pre-up wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
post-down killall -q wpa_supplicant

To setup the interface, type:

# iface wlan0 up

and try the network sending a ping to the gateway:

# ping 192.168.1.5

Please, if you think that I missed something, drop a comment here 🙂