Let’s continue
In the first part we learnt how to interact with the Stellaris board using OpenOCD and GDB, we also performed a dump of the entire image of the flash memory.
Analyzing the memory
OK, now lets to analyze the memory content. A very important thing you should notice is that the empty memory is represented by 0xFF, using the GHex editor we look for the part of the memory where there is nothing more than only 0xFF, in this case I find that the address where the empty flash memory starts is 0x0002A748 so based on this we can determine that the size of the application into the flash memory is about 170 KB so we have 86 KB of free memory. Take a look at the picture below.
Let’s try some assembly code
The next step is to implement some tiny programs and load them in some point using the free memory.
The following code perfom some simple instructions to count even numbers in the range from 0 to 10.
Remember that at this point we have two consoles, in the first one we are running the openocd server and on the other one we are running the gdb client. We need a third console which will be used to assemble and link the tiny_program.s file.
OK, now lets see how to create the object and binary files.
The options -mcpu and -mthumb are used to define the instruction set we want to use. For a better understanding of these and other options I recommend to read the User Guide to the GNU Assembler as.
Loading the binary file to the Stellaris board
Now it is time to focus on the gdb client and load the tiny_program.bin file to the flash memory:
Notice that we are using the address 0x0002A810 in the write_image command to indicate that we want to write our program in this address. As we already know the flash memory is empty starting from the 0x0002A748 address, so we just have to choose any address higher to load our assembly program (in this case the address is 0x0002A810).
If you want to be sure the assembly program is actually located in the address 0x0002A810 you should try the same steps we tried when we dumped the entire board image for the first time, so the binary image should look like this:
Running the assembly program on board
The next step is to set the Program Counter (PC) to the address 0x0002A810 (which is where our assembly program is located) and start typing the GDB commands ‘ni’ and ‘i r’ which means next instruction and info registers respectively.
Put special attention to R0 and R1 registers, see that at some point R0 takes the value of 10 and then decrements to 8 and so on until reach the value of 0. R1 is used to hold the count of the even numbers (10,8,6,4, and 2). At the end R1 reach the value of 30.
At this point we have hacked the Stellaris board using OpenOCD, a low cost ARM USB JTAG and the GNU tool chain. A lot of things are open for learning, in the future I will take these posts as a base for explaining some interesting things I did not cover here.
Thanks a lot for reading this post and see you around!





