Cookbook

This page includes cookbook recipes, i.e, detailed guidelines on how to do something. This could be instructions that ease the development in general or perhaps something that solves a specific problem.

Application memory usage script

The nifty vmstatus.sh script extracts application memory usage from the /proc filesystem. It could be handy when trying to detect a memory leak. Generally the first field is the most useful when trying to find out which application that eats all the memory. If the number in the first field constantly increases you probably found the misbehaving application.

How to run a login shell on a serial port

First you will have a program like getty. Getty performs the following functions:

  1. Open tty lines and set their modes
  2. Print the login prompt and get the user's name
  3. Begin a login process for the user

Fortunately, busybox includes a port of getty which is included by default in the 2.01 release of the SDK. So if you are running the 2.01 release you do not have to re-configure busybox and rebuild your images.

To enable a shell on ttyS2, add the following line to the /etc/inittab file on the target system:

ttyS2:3:respawn:/sbin/getty 115200 /dev/ttyS2 vt100

Do not try to use a login shell on the debug port/console. If you would like to disable the debug port and run a login shell instead do the following:

  • Disable the debug port in the kernel configuration file. The suggested method is to use ‘make –C packages/os/linux-<version> menuconfig’. Observe that the there is a bug in the 2.6 kernel that prevents the system to boot if no debug port is selected, to solve this look here.
  • Disable the shell on the debug port by removing (or comment out) the ‘sh:3:respawn:/bin/sh’ line in /etc/inittab.

How to create a fimage with custom serial number/MAC address

Usage: This can be very handy in a production system when you would like to flash boards with different MAC addresses.

For each board:

  1. Copy the original fimage.
  2. Add the serial number variable using bootblocktool built for the host by running: 'bootblocktool -d path/to/copied/fimage -w SERNO=<MAC ADDRESS>'
  3. Flash the board with the path/to/copied/fimage file

Synchronous serial driver for Linux 2.6

This is a port of the synchronous serial driver found in Linux 2.4 Since this port haven’t been fully tested so far feedback is appreciated. To discuss the driver, join and post your thoughts to the dev-etrax mailing list.

The sync_serial.tar.gz file includes three files which should be placed in the “os/linux-2.6/arch/cris/arch-v10/drivers/” directory.

How to use RS485 port(s) on ETRAX 100 LX

The rs485 page explains how to use the RS485 ports on ETRAX 100LX.

How to decode a kernel oops

The oops page explains how to decode a kernel oops

How to map memory to an userspace program

The mmap page explains how to map memory to an userspace program using mmap().

How to mount a USB "pen drive"

1) Connect the USB dongle. If your system log resembles the txt below precede to “2”, if not go to “3”.

hub.c: new USB device ETRAX 100LX-2, assigned address 3
scsi0 : SCSI emulation for USB Mass Storage devices
  Vendor: SanDisk   Model: Cruzer Mini       Rev: 0.2 
  Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
SCSI device sda: 250879 512-byte hdwr sectors (128 MB)
sda: Write Protect is off
Partition check:
 sda: sda1

2) The system log output above tells us that we can access the USB pen drive using the /dev/sda1 device. Now we can try to mount this device but first we have to create the mount point. We can only create new directories in the writeable /mnt/flash area, hence that is where our mount point will reside:

mkdir /mnt/flash/usb_storage

Now we can try to mount the device to the mountpoint we created. In this example we assume that the pen drive use the vfat file system.

mount -t vfat /dev/sda1 /mnt/flash/usb_storage

If everything went well you should now be able to access the pen drive. If you couldn't mount the pen drive one possible reason could be that the SCSI device nodes are missing. In the /dev directory the following nodes should exist sda, sdaX, sdb, sdbX, sdc, sdcX, and so on where X is a number between 1 and 4. If these nodes are missing go to “4”. Another reason for not being able to mount the pen drive could be that the file system on the pen drive isn’t supported by your kernel, go to “3”.

3) So you encountered a problem? Make sure that your kernel has the appropriate support built in. Aside for the obvious ETRAX USB support the following options should be enabled in your kernel:

  • USB
    • USB mass storage
  • SCSI
    • SCSI disk support
      • Maximum number of SCSI disks = 40
  • File systems
    • dos fat fs
      • ms dos fs
      • vfat
  • Partition types
    • Advanced partition
      • pc bios (ms dos partition tables)

The default kernel configurations for all AXIS developer boards with USB ports have these options enabled from SDK release 2.01 and onwards.

4) The USB mass storage driver require that SCSI device nodes exist in /dev. Since the root file system is read only these devices nodes have to be created when the firmware image is created. In the R2.01 SDK release you can add the needed device nodes to the firmware image by selecting “Create SCSI device nodes” in the Axis Product Configuration tool (top-level make menuconfig).

Framebuffer support for Etrax

Introduction

This HOWTO explains how to enable FrameBuffer support in the Etrax kernel. It is based on Linux kernel 2.4.26 and Developer Board 82 Software version 1.92 but probably applies to any 2.4 Kernel. Note that the 2.6 kernel probably needs slightly different patches. The HOWTO is mainly based on the excellent master thesis by Magnus Kling and Jerker Buud available here. Some kernel files need to be patched and some configuration parameters have to be added but the patches should be non-destructive and can be disabled via menuconfig.

menuconfig patches

To allow usage of “make menuconfig” the file os/linux/arch/cris/config.in is patched so that some additional configuration parameters are added to the kernel configuration. At the end of that file add:

mainmenu_option next_comment
comment 'FrameBuffer for Etrax patches'

bool 'Dummy keyboard' CONFIG_DUMMY_KEYB
bool 'PC Keymap' CONFIG_PC_KEYMAP
bool 'Enable dummy console' CONFIG_DUMMY_CONSOLE
bool 'Enable kernel patches required for compiling' CONFIG_X_FB_PATCHES

source drivers/video/Config.in

endmenu

This adds a new menu item “FrameBuffer for Etrax patches” to your menuconfig. I choosed to place everything into one menu to separate it from the normal config.

  • Start make menuconfig in os/linux,
  • enter “Character devices”, activate “Virtual terminal” and “Support for console on virtual terminal”
  • enter “FrameBuffer for Etrax patches”, activate all four boolean switches, then
  • enter “Framebuffer support”, activate “Support for frame buffer devices (EXPERIMENTAL)”, then
  • select “Select compiled-in fonts” (you need some fonts otherwise the kernel won't compile).
  • Exit menuconfig.

Note: Just disable those switches and the kernel will compile without FrameBuffer support. All patches should be disabled that way.

source code patches

Create a dummy “keyboard.h” file in “linux/include/asm-cris/keyboard.h”. While in …/os/linux, type:

touch include/asm-cris/keyboard.h

Then open “linux/arch/cris/kernel/process.c” and at the very end of it add:

#ifdef CONFIG_X_FB_PATCHES
void show_regs(struct pt_regs * regs)
{
    printk("The function show_regs is not implemented for this architecture\n");
}
#endif

Since “linux_logo.h” is missing, copy it from another architecture:

cp linux/include/asm-i386/linux_logo.h linux/include/asm-cris/linux_logo.h

Now open “linux/include/asm-cris/pgtable.h” and near the end (before the last endif, which wraps around the whole file) add:

#ifdef CONFIG_X_FB_PATCHES
#define io_remap_page_range remap_page_range
#endif

Finally, open “linux/arch/cris/kernel/setup.c” and the following code in the includes part:

#ifdef CONFIG_X_FB_PATCHES
#include <linux/console.h>
#endif

Near the end of the “setup_arch” function (as a new instruction of it) add:

#ifdef CONFIG_X_FB_PATCHES
#ifdef CONFIG_DUMMY_CONSOLE
        conswitchp = &dummy_con;
#endif
#endif

That's (nearly) it!

Now you should be able to compile the kernel with FrameBuffer support built in. Note instead of using the non-standard “CONFIG_X_FB_PATCHES” switch you could remove it from the menuconfig and remove all references in the patched files, so that the patches are enabled all the time. That should not be a problem because they only add functions that are missing in cris. However, I like to undo kernel patches in a easy way…

Note that you still have to create the device for the framebuffer and activate the correct framebuffer driver! This howto only covers the patches needed to make compile succeed on the cris platform…

Getting other Busybox components

Simply cd to packages/apps/busybox/devboard and do a make menuconfig This will create a .config file in that directory with the options you specify. This is necessary, for example, if you want to get the udhcpd server and not just the client. There are other options that can be used to change the default behaviour of busybox in the menuconfig system. Do a make from your top level directory afterwards and it should install the required busybox subpackages.

Shared Libaries

This is a quick description how to generate a shared library for an CRIS-cpu, tested with gcc version 3.2.1 Axis release R64/1.64.

makefile

The makefile below will generate a library call libshared.so (acutaly a link to libshared.so.1.0.0) and the text programm mytest. Please be aware that clipping the makefile below will most likely convert the tabs “\t” into spaces. You will need to fix that before you can use it !

CC=cris-gcc -mlinux

SL_NAME:=libshared.so
SL_VERSION:=1.0.0
SL_PATH:=.

LOADLIBES=-L${SL_PATH} -lshared

all: libshared.so  mytest

%.lo: %.c 
        $(CC) -c -fPIC $(CFLAGS) $(CPPFLAGS) $< -o $@

%.so% : %.lo
        $(LINK.c) $^ -Wl,-soname,$@.$(SL_VERSION) -o $@.$(SL_VERSION)


libshared.so: shared.lo
        $(LINK.c) $^ -shared -Wl,-soname,$@.$(SL_VERSION) -o $@.$(SL_VERSION) 
        ln -s ${SL_PATH}/${SL_NAME}.${SL_VERSION} ${SL_PATH}/${SL_NAME} 

clean:
        $(RM) *.o *.lo libshared*.so*  mytest

shared.c

We provide two example functions add() and sub().

int add(int a, int b) {
  return a+b;
}

int sub(int a, int b) {
  return a-b;
}

shared.h

We provide declarations for add() and sub().

#ifndef __shared_h__
#define __shared_h__ 1
extern int add(int a, int b) ;
extern int sub(int a, int b) ;
#endif

mytest.c

This is a simple test code.

#include <stdio.h>
#include "shared.h"

int main(void ) {
  
  printf(" 1 + 2 = %d\n",add(1,2));
  printf(" 1 - 2 = %d\n",sub(1,2));
  return 0;
}

Compiling and testing

The output of make (GNU Make 3.80) should look like this

cris-gcc -mlinux -c -fPIC   shared.c -o shared.lo
cris-gcc -mlinux     shared.lo -shared -Wl,-soname,libshared.so.1.0.0 -o libshared.so.1.0.0 
ln -s ./libshared.so.1.0.0 ./libshared.so 
cris-gcc -mlinux     mytest.c -L. -lshared  -o mytest

this will not install the library propperly

to test the library you use the following command:

LD_PRELOAD="./libshared.so" ./mytest

(see man ld.so for a description of LD_PRELOAD).

the output should look like this:

 1 + 2 = 3
 1 - 2 = -1
 
cookbook.txt · Last modified: 2011/11/24 08:31 by admin
 
All text is available under the terms of the GNU Free Documentation License (see Copyrights for details).