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
s/^\(.\{45\}\).*$/\1/
# 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
s/^\(.\{9\}\).*$/\1/

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
s/#/F/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
:10000000F00000000000000000000000000000FF01
:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0
:1000400000F000000000000FF000000000000000C1
:10005000FF000000000000000F0000000000000092
:10006000FF000000000000000FF000000000000092
:10007000FF00000000000000FFF000000000000092
:10008000FFFF00000000000FFF0000000000000064
:100090000FFFFFFFFFFFFFFFF00000000000000068
:1000A000000FFFFFFFFFFFFF000000000000000047
:1000B0000000000000000000000000000000000040
:1000C00000000000000000000FF000000000000031
:1000D0000000FFFFFFFFFFFFFFF000000000000037
:1000E0000FFFFFFFFFFFFFFFFFF000000000000019
:1000F000FFFFFFFFFFFFFFFFFFF000000000000019
:10010000FFF0000000000000000000000000000000
:10011000FF000000000000000000000000000000E0
:100120000FF00000000000000000000000000000D0
:1001300000F00000000000000FF0000000000000D0
:10014000FFFFFFFFFFFFFFFFFFF0000000000000C8
:10015000FFFFFFFFFFFFFFFFFFF0000000000000B8
:10016000FFFFFFFFFFFFFFFFFFF0000000000000A8
:10017000F00000000000000000000000000000008F
:10018000F00000000000000000000000000000FF80
:10019000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F
:1001A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F
:1001B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4F
:1001C000F00000000000000000000000000000003F
:1001D000F00000000000000000000000000000FF30
:1001E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1F
:1001F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F
:10020000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
:10021000F0000000000000000000000000000000EE
:1002200000000000000000FFFFF0000000000000E0
:10023000FF000000000000FFFFF0000000000000D1
:10024000FFFFF000000000000FF0000000000000C1
:10025000FFFFFFFF000000000FF0000000000000A3
:10026000F0FFFFFFFF0000000FF0000000000000A3
:10027000F0000FFFFFFFF0000FF000000000000093
:10028000F0000000FFFFFFFF0FF000000000000083
:10029000F000000000FFFFFFFFF000000000000082
:1002A000F00000000000FFFFFFF000000000000071
:1002B000FF0000000000000FFFF000000000000041
:1002C000FFFF00000000000000F000000000000040
:00000001FF

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: