Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Embedded Linux Hello World Application (&TCP/IP &PIO
PostPosted: Mon Aug 06, 2007 3:35 pm 
Offline

Joined: Mon Aug 06, 2007 2:21 pm
Posts: 9
Hi,

First, please forgive me but I am yet to find a tutorial for developing and transferring a helloworld c program onto an AT91SAMxxxx board and running that c program under an embedded linux OS.

I am a complete beginner to ALL embedded systems. I am computer science student with some C/C++ experience on linux and windows. I have been given an AT91SAM9260-EK board, a PC running windows, a USB cable and an RS232 cable.

So far I have managed to build simple binaries (such as Atmel's Getting Started LED application) using YAGARTO toolchain and have written those binaries to various on-board memories using the SAM-BA utility via USB. I have also managed to write the linux_demo binary to DataFlash memory and have played with it a little through a HyperTerminal via an RS232 DBGU connection.

My aim is to write a program which reads data from the PIOC connector, does some processing and sends/recieves data packets over an ethernet connection using the TCP/IP stack provided by an embedded linux OS.

My problem is that I don't understand how I should be developing and deploying c programs to run under the embedded linux OS on the board. How should I write/transfer the c program onto the memory and point linux OS to it such that it runs that program on startup?

Question:

How do I install an embedded linux distribution THEN write, build, transfer and run a hello world c program on that linux OS on the board?

Next question:

How do I extend this so that I am implementing TCP/IP stack through linux (i.e. will #include "socket.h" work now?) ?
How do I read from PIOC? (i.e. Memory map? )

Sorry for the long question(s).

Thanks a lot in advance!

Tom ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 10:55 pm 
Offline

Joined: Thu Apr 19, 2007 10:15 pm
Posts: 204
Location: USA
Hi there

Have you read a very similar thread below "New to Linux..."?

Quote:
How do I install an embedded linux distribution THEN write, build, transfer and run a hello world c program on that linux OS on the board?


You already wrote that you "also managed to write the linux_demo binary to DataFlash memory". Then means you installed Linux on the board.

TFTP (trivial file transfer protocol) is typically used move files between host and target.

Quote:
How do I extend this so that I am implementing TCP/IP stack through linux (i.e. will #include "socket.h" work now?) ?

The Linux you installed on the target board is just as capable as the OS on your desktop PC. The biggest difference is the amount of memory and hard disk storage. All system and library calls are available, including sockets. That does assume you link your application correctly.

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 11:14 am 
Offline

Joined: Mon Aug 06, 2007 2:21 pm
Posts: 9
Hi blue_z,

Thanks for the reply.

I am having some difficulty explaining myself so apologies if I seem to be writing a little over-detailed.

Quote:
TFTP (trivial file transfer protocol) is typically used move files between host and target.


So I install linux by transferring the binary onto the AT91x DataFlash using SAM-BA. Then, on my Windows PC, I build a hello world c program targetted for AT91SAM9260 to create an object file.

Then I need to transfer that object file onto some memory on the AT91x: I need to create some kind of a file system(?) And then use TFTP to transfer the file onto that file system(?)

I should then be able to run that program under the linux by opening a hyperterminal, logging into embedded linux via RS232 DBGU and executing that program from the command line..

Is that right?

Kind regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 3:49 pm 
Offline

Joined: Thu Aug 09, 2007 10:48 am
Posts: 106
Location: Artec Design LLC, Tallinn, Estonia
Typical architecture of AT91SAM product running linux is

1) AT91SAM internal Boot ROM. This initializes the CPU and looks a small boot image from Dataflash, copies it to internal SRAM(that is quite small) and starts it.
2) DataflashBoot. A very tiny bootloader, that can access the whole DataFlash. This initializes SDRAM and loads next stage loader to SDRAM
3) U-BOOT. This is a full-featured bootloader, that is capable of writing flash, downloading images from TFTP servers etc. U-Boot loads kernel image from somewhere (DataFlash, NAND flash, network server etc) to SDRAM and boots kernel
4) Linux kernel
5) Linux filesystem
6) Application

The linux is a full operating system, that is built from the same kernel tree, that your desktop linux is. You just carefully select only those features, that you really need (ie you don't need probably all filesystem support (EXT2, EXT3, FAT, NTFS, ...), just one or two; you don't need all networking features supported and definitely not all drivers supported). The kernel is a separate piece, that initializes devices, loads root filesystem image and excecutes a program called "init" from it. This program loads shells, programs etc.

If your kernel has network support compiled in and the network chip's driver is loaded, you can simply use the network like programming to a regular linux PC. You can even compile (or just use an precompiled binaries from ARM distribution like Debian) regular linux utilities like dhclient, ping, tracert etc for your board. You probably don't want to use a regular X server, but develop your app to direct framebuffer interface etc.

Using PIO from userspace is not that simple. You either use /dev/mem and map your IO memory through there (and then excecute the application as root user... this may be a problem if you want privilege separation in your device)... Or you write a device driver for your GPIO access and do it through that.

Building an embedded linux system is not an easy task if you are doing it for the first time. You should first get used to regular linux and be comfortable with developing software for linux.


Top
 Profile  
 
 Post subject: Examples
PostPosted: Thu Aug 16, 2007 10:54 am 
Offline

Joined: Mon Aug 06, 2007 2:21 pm
Posts: 9
Hi,

Thanks for the succinct response!

Do you know where I could get some example code of these bootloader modules FOR LINUX on the AT91SAM9260-EK (or similar)?

I have been looking at the sample code from Atmel and was trying to modify the bootloader provided with the Getting Started app. But I am not sure what I should be modifying and indeed how I actually boot a kernel and create a filesystem. I would use the linux_demo sample but unfortunately Atmel have not provided the source code for that project.

Any help is much appreciated!

Cheers

BTW I am thinking of making a wiki with a step-by-step tutorial for what I am doing(/try to do!) so that it is easier to see where I am stuck and also for others in this total beginner situation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 1:35 pm 
Offline

Joined: Thu Apr 19, 2007 10:15 pm
Posts: 204
Location: USA
Hi there

So I install linux by transferring the binary onto the AT91x DataFlash using SAM-BA. Then, on my Windows PC, I build a hello world c program targetted for AT91SAM9260 to create an object file.

Also known as cross compiling. The other thread had some discussion on build environment/platforms. I'm partial to a Linux devolment box. Others like Windows.


Then I need to transfer that object file onto some memory on the AT91x: I need to create some kind of a file system(?) And then use TFTP to transfer the file onto that file system(?)

If you install the Atmel Linux demo, then you already have a filesystem. Linux requires a filesystem in order to boot. The issue is that the Linux demo uses a RAM disk or ramFS, which means that all changes to the filesystem are lost when the board shutsdown/reboots. The embedded design problem is to either replace or to augment the original FS by implementing another filesystem on a non-volatile device (e.g. flash) and/or use the network (e.g.NFS). But the volatile FS that comes with the demo should be sufficient for a lot of experimentation. Transferring files using TFTP can be very fast at 100Mbs.


I should then be able to run that program under the linux by opening a hyperterminal, logging into embedded linux via RS232 DBGU and executing that program from the command line..

You need a console to interface with the Linux shell program. By default the console is the Debug port on these Atmel boards. Use a terminal emulator (such as Hyperterm) on your PC to access the console. The shell is the Linux command line interpreter. There is a wealth of Linux commands and programs to learn about, although only a handful (of shell commands) will actually be available on the embedded system. But the kernel is still full featured, and applications you write can use that capability.


I have been looking at the sample code from Atmel and was trying to modify the bootloader provided with the Getting Started app. But I am not sure what I should be modifying ...

If you're not sure what you want to do then forget about modifying the boot code. There's a lot to learn about the Linux kernel. Like, have you done multi-threaded programming? Or written a device driver? You should get your feet wet in the user code first, before you try boot code.

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 12:48 pm 
Offline

Joined: Mon Aug 06, 2007 2:21 pm
Posts: 9
Thanks a lot for the reply.

Ive gone back to looking at just using the basic linux demo and expanding on that.

Currently having difficulty mounting usb. Ive started another thread because I couldnt find any with a similar topic.

thread title: usb mounting troubles on AT91SAM9260-EK
href: "http://www.at91.com/phpbb/viewtopic.php?t=3638&start=0&postdays=0&postorder=asc&highlight="

Cheers again,
T


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: