Tag Archive: hex


At first, U-boot may seem like just a way to load a root file system on your Zipit Z2 but it is capable of so much more.  If you type “help” at your U-boot prompt, you will get a HUGE list of commands.  Some are self explanatory but others are coupled with vague descriptions.  To delve deeper into some of these commands, I did a bit of poking around online.  Before you proceed, please realize that attempting to fuzz memory locations like this could potential result in a brick or hardware damage. That being said, here is a short list of commands I’ve put together that I’ve found useful for exploring the Zipit at the bit level:

MD (Memory Display) – You can use this command with a couple of suffixes.  For example md.b, md.w & md.l all change the way that the output is displayed.  Experiment with those and see which one works best for your purpose.

md 0x40E00000

By default, md will show you several lines of memory starting at the address you type in.  To see the exact contents 4 bytes of memory, you would type in something like:

md 0x40E00000 1

The “1” is an offset value that tells the command to display one 4-byte block.  You can change that to see however many locations you would like.  After you use a value here, it will persist until you use a different value.  In other words, next time you type “md 0x40E00000”  without the “1”, it will show you 4-bytes until you run the command again with a different offset.

MTEST (Memory Test) – Memory test will perform test passes on a specified range of memory using a specified pattern.  For instance, if you want to see some interesting bits get flipped, type in:

mtest 40E0000C 40E0000D FFFFFFFF

This will fuzz the range of memory from 40E0000C-40E0000D with the specified test pattern.  I believe the LCD or power saving features may live in this range because this command makes the screen flicker.  I’m not entirely sure how the pattern value (“FFFFFFFF”) works but a bit of experimentation and you should be able to figure it out.

NM (Memory Modify) – This command allows you to selectively flip bits of any byte in memory.  For instance, if you run:

nm 40E0000C

You will see something similar to:

40E0000C: 0000032a ?

That is a prompt that is showing you the existing contents of the 4-bytes.  If you type in “FFFFFFFF”, that will set ALL of the 32-bits(4-bytes) to the “on” position.  In this case, it makes the screen dimmer.  The line will increment and ask you again what you would like to change to.  This time, if you type “00000000”, it will turn ALL 32-bits off and the screen will go to full brightness.  If it’s not already obvious, ALL of those bits and bytes don’t control the screen brightness.  You can start to narrow it down by flipping the nibbles(half-bytes).  Starting with “F0000000”, “0F000000”, “00F00000” and so on will narrow down which byte the brightness lives in.

It appears to be in the “00000F00” nibble.  So now it’s time to start flipping the bits.  The individual bits are at 1, 2, 4 & 8.  So something like “00000100”, “00000200”, “00000400” etc will track down the specific bit.  Turns out that it’s the most significant bit of that specific nibble.  So in binary, it looks like “1000”.  That translates to 8 in hex.  To sum it up, changing between “00000800” and “00000000” with toggle the LCD backlight between bright and dim.

If any of this is confusing, you should read my post on binary to hex number conversion.  Many people seem to think that computers somehow don’t operate on binary logic anymore but an exercise such as this proves quite the opposite to be true.

On the Zipit Z2, you probably don’t NEED to probe around like this since you can download a manual for the CPU and find most of the memory locations in there but if you just want to experiment or if you have another similar undocumented device that you want to reverse engineer, then this is a good way to go.

decimal to binary

I’ve been reading a book on the CCNA certification.  Part of the exam has to do with being able to manually convert numbers between binary, decimal and hex.  I’ve struggled with that concept of being able to do it on paper an easy way but in this particular book, the author spelled out a very simple way to do this that just clicked and will now stick with me for life.  Binary numbers are counted in powers of 2 relative to decimal numbers.  That is the most confusing thing that I want to say about the subject.  It should get easier from here on.

Typically binary numbers are represented in 8-bits or 1-byte.  This just means there are 8 digits.  These 8-bits can represent any decimal number between 0 and 255.  That’s it, any higher numbers and you have to add more bits to represent it.  Now for the fun part.  Draw a chart on a piece of paper like this:

128 64 32 16 8 4 2 1

If you look at the chart, you’ll notice a relation to the numbers.  Starting with 2, each number is double the number to the right of it.  If you can remember this chart, you are over half way there.  So now pretend you have a decimal number like 190 that you need to convert to binary.  To convert it, you need to find the numbers in the chart, starting from the left, that will add up to 190.  For starters, we know that 128 will fit in to 190 so let’s mark that one off with a one.

128 64 32 16 8 4 2 1
1

The next number, 64 won’t fit.  That would add up to 192 so we’ll mark that one with a zero.

128 64 32 16 8 4 2 1
1 0

Think of it like playing blackjack.  You want to get to 21 but you never want to go over.  So keep adding numbers left to right until you reach the correct number, if you go over, skip that number.  Adding 32 brings us to 160, add 16 and that gives us 176.  We’re still not over so keep going.

128 64 32 16 8 4 2 1
1 0 1 1

Adding 8 brings us to 184, 4 more gives us 188.  2 more gives us 190 and we’re done so zero out the last bit.

128 64 32 16 8 4 2 1
1 0 1 1 1 1 1 0

So there you have it.  190 in decimal works out to 10111110 in binary.  With a little practice, you can easily do these in your head.  As you can see from the chart, it’s even easier to go backwards.  Just add up the numbers that are set to one and skip the ones that are set to zero.  Now for the bonus round!

binary to hexadecimal

Hex is something that a lot of people find confusing.  I still find it confusing to convert decimal to hex and vice versa but I have found that it’s VERY easy to convert from binary to hex and back.  Let’s take the same number we were just working with.  190 or 10111110.  To do hex, we have to split the one byte into two nibbles.  This is easier than it sounds.  We just split the chart into two halves but write the binary number straight across as if nothing has changed.  This is because each hex number can only represent “0” through “15” or more accurately “0” through “F”.  The chart looks like this now:

8 4 2 1 8 4 2 1
1 0 1 1 1 1 1 0

So now all you do is add up each nibble separately.  The first one on the left gives us 11 or “B”.  The second nibble adds up to 14 or “E”.  So 190 in decimal equals 10111110 in binary which equals “BE” in hexadecimal.  Personally I find it easier to convert decimal to binary before trying to convert it to hex but your mind may work differently.

Powered by WordPress. Theme: Motion by 85ideas.