First OLPC Program

To check whether a program compiled using Plan9’s compiler works on OLPC I wrote following program. This program fills OLPC’s screen with Blue color.

void
_main(void)
{
    int i=0;
    unsigned short *fb = (unsigned short *) 0xfd000000;
    for(i=0; i<1200*900;i++)
    {
        *fb = 0x0015U
        fb++;
    }
}

Here linear frame buffer start address is 0xfd000000.
OLPC Screen Resolution is 1200x900.
Color Depth is 16 bits.
0x0015U is value for Blue color.

I compiled this program using following commands,

8c color.c
8l -H5 -T0x100000 color.8

I got 8.out which was in ELF format. I wanted OLPC’s open firmware to load this executable at 1MB so I gave -T0x100000 option to 8l.

To execute this program, copy it to USB disk. Attached this USB disk to OLPC and boot the laptop. You need to press ‘x’ key in game pad to interrupt the booting sequence. After this you need to press Esc key to enter to open firmware boot prompt. Once you are at open firmware boot prompt execute following command to check whether USB disk is detected properly and appropriate FS driver is loaded.

dir disk:\

This command should print out contents of USB disk’s root directory.

Now you need to tell open firmware (OFW) that you want to load 8.out from USB disk and execute it. Execute following command,

setenv boot-device disk:\8.out

OFW by default resets USB system just before handling over control to new kernel. If you need to turn off that behaviour then you should execute following command,

' noop to go-hook

Now we need to tell OFW to map linear frame buffer video memory to 0xfd000000 address. Execute following command,

h# 910 config-l@ dup 100.0000 -1 mmu-map

After this you can boot 8.out by executing command,

boot

Some other useful OFW commands,

reset-all = To reset all hardware and reboot
power-off = Shutdown
print-env = Prints all the Environment
dev / = Sets to root of device tree, after this you can use ls command to print the tree.
.properties = Prints properties of the selected node.