Monday, May 4, 2009

code your name ...

recently I read about ester eggs in Linux and it was fun playing with them.
And here is my attempt to create a one.
"how to codify you name and burn it in a microcontroller"
Two years of my learning, struggle and frustration in Embedded Systems and Sensor Networks Lab finally led me to do things like this (Thanks to PR ;)).
I created an easter egg, which nothing but my name in code format, and burned it in to a microcontroller.

First you generate you name pattern using banner.
(A line starting with "$" is a command and a line starting with a "#" is a comment).
$ banner "your name" > easter-egg.hex
$ banner -w 46 bullz > banner.hex
size will be a bit big, so reduce the size to fit a "Record" (line) in a 32 hex char field(32 : data length of a intel hex format field).
As you might have noticed, the length of each line is not uniform.
Lets take care of this using a simple sed script "uniform.sed"
$ sed -f uniform.sed banner.hex > uniform.hex

$ cat uniform.sed
s/$/ /
s/ *$/&&&&&&&&/
# keep 1st 43 chars
# delete first 11 spaces
s/^ //

Now as you can see, all the fields are fixed to contain same length.
But to burn into microcontroller, we need to have separate addresses for each field.
So lets strip addresses (first 9 chars of any rom.hex file) from some arbitrary rom.hex file. Trim the size of the output file so that it contains same number of lines as of uniform.hex
$ sed -f genadd.sed rom.hex > addfile.hex
$ cat genadd.sed
# keep 1st 9 chars

now lets join address file (genadd.hex) and name file (uniform.hex) into a tmp file and then fix the tab spacing to generate fixadd.hex file.
$ paste addfile.hex uniform.hex > tmp.hex
$ sed 's/\t//' tmp.hex > fixadd.hex
Now lets "hexify" the file to contain only "0" and "F".
$ sed -f hexify.sed fixadd.hex > hexify.hex
$ cat hexify.sed
s/ /0/g

Lets add EOF Record, in order to indicate the microcontroler programmer to indicate EOF.
$ echo ":00000001FF" >> hexify.hex
Almost there, but if we try to burn this code, the programmer will come back and say "Checksum error".
So lets fox the Checksums using "fixchksum" utility.
$ fixchksum hexify.hex
And we finally made it the easter-egg.
$ mv hexify-fixed.hex easter-egg.hex
And here is the final result.

$ cat easter-egg.hex

Can you see my name (bullz) in thr?

Lets hide it, so that someone else can find it ;)
$ flash easter-egg.hex (replace "flash" with you favorite way of flashing your micro)

And for those who want to try this out for fun, gimme a mail and I will post the makefiles and other sed files.

No comments: