Friday, September 23, 2005

First Running Code

After four days of wrestling with the bootloader and figuring out how it loads code. I got code to run through the Rockbox bootloader! Right now i just am using some assembly that loads the regular iriver firmware on boot. So if it works, the firmware loads. If it fails, it freezes and a paper clip is needed to reset it.

The bootloader loading mechanism is actually rather simple when you figure it out. I had to deal with linker scripts that wouldn't do what I want and frequent disassembling and hex editing to get it to work. I will describe it because it hasn't been documented anywhere else.

The general file structure of your code needs to look like this if you want it to run:
[4 bytes (chksum)][4 bytes(model name)][4 bytes("end of stack")][4 bytes(address of starting instruction)][many bytes(actual code)]
The chksum is computed by adding every byte from the "end of stack" byte onwards to a long.

This code is loaded into memory at 0x31000000 (first memory location of SDRAM), so all of your references to variables and symbols need to be setup so that is the base address instead of 0x00000000. This can be done with a linker script (an lds file).

I'm going to try to figure out if its possible to cut out the assembly altogether in the linking process -- whether it is necessary to have some assembly in order to start code with the bootloader or if it can be skipped. I hope to be able to clean it up a bit tonite and have a simple version up, but my sister is being a pain and not letting me use what is currently our only Windows box to copy code onto the player (for whatever reason Ubuntu Breezy won't let me put stuff on the player -- and Vista build 5219 isn't dual boot friendly)

The tool chain I'm using consists of binutils and gcc, compiled with --target=m68k-elf