Uploading code from one Arduino to another

Hi there,
does there exists any example code for updating an Arduinoboard by a second one?
This is the background:
There are two Arduinoboards working together, one is the master, the other slave. Now i want to update the code in the slave (like a firmwareupdate) without using the development ide.
I do have a (windows) application which communicates with the master. Now i want to update the slaves code over the communication with the master. The master himself transfers the update to the slave.
This should simply be done by the RxTx lines of the slave, i assume. The code transfer from the ide should run the same way, right (via ftdi or similar usb-serial chip)?
I searched a lot but failed due to creating the right question in the search... :~

thanks a lot for your suggestions.

Slackman

Now i want to update the code in the slave (like a firmwareupdate) without using the development ide.

You must first compile and link the code to produce a hex file. Do you know how to do that?

The master himself transfers the update to the slave.

You are going to have to develop a new boot-loader, for the slave, for this to happen. Do you know how to do this?

This should simply be done by the RxTx lines of the slave, i assume.

That's the usual way.

The code transfer from the ide should run the same way, right (via ftdi or similar usb-serial chip)?

Yes, except that the IDE knows what to send, and what to expect in response, at what baud rate.

JC at Jeelabs.org has done something similar I think - a sketch that can capture a download and reprogram other Arduino compatibles later (if I understand correctly) - certainly its worth delving around on the site for inspiration: http://jeelabs.org/2010/05/05/a-capturing-isp-programmer/

Sorry, i think you all misunderstood:
This has nothing to do with flashing one Arduino with another. Samples to make an Ardiuno work like an isp-programmer will be found in the net. That's not what i'm looking for!
In my mind the Arduino get's control of the code himself. The bootloader inside handles the serial connection, done with the integrated usb-serial interface of the board. Without an Arduino board you have to programm the controller via special assigned pins (the isp - interface).
There are several similar projects which are based on the same technique: a bootloader stays in the controller the whole time and via a simple filetransfer the controller gets the new code and therefore new functionality. This is not isp-flshing!
So i'm looking for the transfer protocol which is used by the Arduino IDE to transfer the compiled code into the controller.

Slackman

Your problem is that you can only write to the main flash memory when you are running code in the area normally occupied by the boot loader. Therefore you will have to either make the master look like a PC and have it trip the reset on the slave or rewrite the boot loader.
That is why you haven't seen any examples of this.

I believe the ATmegas have instructions for writing to flash memory. I mean, the bootloader has to use them, so of course it does.

What it sounds like the OP wants to do is have their code use those instructions to replace the running program, bypassing the bootloader completely. There is documentation on how the standard boot loader works, and what it expects to see on the serial line when it initially boots. The usual technique is to have a piece of code at a fixed high address which contains =all= of the required functionality. When the "update firmware" command is seen, control is transferred to that high address and the data is written to the proper address for a normally running program. After the new firmware is flashed, control is transferred to the entry point of that new code and life goes on.

I believe the ATmegas have instructions for writing to flash memory.

Yes but it will only allow writing to the "other" bank of flash.

In this processor the flash is divided into two unequal size banks. If code is running in one bank it can't write to the flash in the same bank, it can only write to the flash in the bank where the code is not running from. This is of course fine when the boot loader is running as it writes in the main bank.
However, when anything else is running the only place it can write code to is the memory space (bank) occupied by the boot loader. That makes it difficult to do what the OP wanted.

You could use Bitlash, an interpreted text based "language" on the arduino and store the code in SD Flash cards, then update would be easy.

The Arduino bootloaders are open source, one go and have a look at the code to see how they work...