...your main source of everything AVR32 Linux

Navigation

NewbieLinuxDriver

Scope

This article explains how to compile and load very simple kernel module that can be used as a basic template for linux driver development for avr32 platform. Article also covers topics that regard preparing avr32 linux kernel and required tools on your host machine.

Requirements and environment

This tutorial applies to ATNGW100 development board. But after making some minor changes it can work with other avr32 linux boards.
  • Basic requirements for compiling and loading new kernel module are:
    • avr32 toolchain
    • U-Boot
    • avr32 Linux kernel sources
    • Linux distribution on your host machine (e.g. Ubuntu, Fedora)
  • Optional:
    • sd card and buildroot from Atmel

Important notes

Building and loading new kernel module to your board requires that your toolchain uses exactly the same kernel sources version as your on board linux. It is also important that you compile your module with exactly the same compiler version that was used for building your on board kernel. Linux kernel version on your host machine is not so important. Because of this before you start writing drivers for avr32 linux you will probably have to update your on board kernel. If you don`t do this, there exists high probability that you will receive some errors during module insertion.

avr32 toolchain

First of all, you will need avr32 toolchain that will allow you to compile programs for avr32 architecture on your host machine. You can find some information about setting up your toolchain here: http://www.avrfreaks.net/wiki/index.php/Documentation:AVR32_General/Tools_Installation. Keep in mind that kernel build process was designed to work under linux so it`s really better not to use Cygwin at this point but probably it is possible.

U-Boot

During kernel build process you will need mkimage utility that is shipped with u-boot. This utility will be used for building your new kernel uImage. So if you build your kernel and you can`t find uImage file in …/arch/avr32/boot/images/ it probably means that you don`t have mkimage utility. To fix this problem go to: UbootPatches download u-boot sources and follow instructions in this article: GettingStarted#Building_the_boot_loader

During this tutorial I have used U-Boot 1.2.0.atmel.1

avr32 Linux kernel sources

For building new kernel and compiling new kernel module you will need kernel sources which for avr32 linux can be downloaded from: LinuxPatches. After you download new kernel sources compile them with executing following command:
make ARCH=avr32 atngw100_defconfig && make ARCH=avr32 CROSS_COMPILE=avr32-linux-
During this tutorial I have used linux-2.6.23.atmel.4.tar.bz2

Updating on board kernel

If you want you can upload new uImage directly to your on board flash memory programmed with linux by Atmel (directory /boot/). In this tutorial I have decided to setup new linux on sd card and then change its kernel. This method will give you plenty of free space and for sure will not destroy your original linux stored in on board flash memory. For exact instruction how to boot from sd card go to: http://www.avrfreaks.net/wiki/index.php/Documentation:NGW/Newbie/boot_from_SD

Compiling simple driver

After completing above steps you can compile and load your first driver. Atmel provides simple gpio driver in application note: “AVR32408: AVR32 AP7 Linux GPIO driver”. To compile this driver you will need to change KDIR variable in Makefile. It should point to your kernel source directory on your host machine. You can also modify init and exit functions leaveing only only printk instructions e.g. printk(KERN_DEBUG”My init function\n”); Execute make and copy your driver file .ko to ATNGW100. To insert driver execute insmod DRIVER_NAME.ko (this will execute init function), to remove driver execute rmmod DRIVER_NAME (this will execute exit function). If everything goes ok you will not receive any error during inserting and removing module. You can find your KERN_DEBUG messages in /var/log/messages. If you receive error similar to this one:
gpio_example: version magic '2.6.18-at0 mod_unload AVR32v1gcc-4.2' should be '2.6.18-atngw mod_unload AVR32v1gcc-4.1' 
Segmentation fault
it means that your on board kernel version is different from version of kernel sources used during module build process.

r1 - 05 May 2008 - 19:41 - MichalMosdorf
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Atmel®, AVR® and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries.
All other trademarks are the property of their respective owners.
Powered by Wed, 08 Feb 2006 build 8740
Syndicate this site