1

In my assembly startup code for ARM9 i have some lines that i don't understand and are like this:

    .word   0x41676d69
    .word   0,0,0,0,0
image_type:
    .word   0x0000000A
sizeOfPermanentCode:    
    .word   (__image_size)
    .word   0,0
bootparameter:  
    .word   0
    .word   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

I ve heard that number 0x41676d69 is some sort of an image magic number, but i dont know why it is used for. What about other .word elements? What are they? What do they do?

With kind regards Žiga Lausegger

71GA
  • 1,132
  • 6
  • 36
  • 69
  • 4
    `0x41676d69` translates to `Agmi` when interpreted as big-endian and converted to ASCII. `imgA` when interpreted as little-endian. Just an observation – cHao Mar 01 '12 at 13:37
  • So `0x41676d69` carries an information about format type which is `imgA`. I assume this is probabbly needed by boot ISROM at startup. But what would `.word 0 , 0 , 0 , 0 , 0` do? Is it possible this are some kind of parameters boot ISROM needs? – 71GA Mar 01 '12 at 19:43
  • 1
    Total semi-educated guess here, but it looks like padding to me. The loader probably expects to find `image_type` at exactly offset `0x18` in the image. If those 0 words specify boot params, they'd almost certainly be defaults. (Disclaimer: I've never touched an ARM system aside from a PDA i messed with 5 years ago. You'll want to look around on the internet and make sure what i'm saying makes sense...cause i haven't done much of that yet. :) ) – cHao Mar 01 '12 at 20:31
  • Why offset `0x18`? Hoe did you get to this number? And it is true what you say. – 71GA Mar 01 '12 at 22:54
  • 1
    The magic number plus those `0`s ends up being 6 words. At 4 bytes each, that's 24 bytes. 24 == `0x18`. – cHao Mar 02 '12 at 00:39
  • Actually, according to some stuff i'm seeing, there should be a 4-byte instruction (a jump) before this stuff, that jumps past the header. – cHao Mar 02 '12 at 17:12

1 Answers1

3

From what i'm seeing, a boot image should look something like this at the beginning...

+--------------------------+
|      (asm) B Start       | 0x00
+--------------------------+ 
|    Magic (0x41676d69)    | 0x04
+--------------------------+
| code CRC (if type=0x0b)  | 0x08
+--------------------------+
|                          | 0x0c
+--                      --+
|                          |
+--       Reserved       --+
|        (set to 0)        |
+--                      --+
|                          |
+--------------------------+
| image type(0x0a or 0x0b) | 0x1c
+--------------------------+
| image size (incl header) | 0x20
+--------------------------+
| image version (ignored)  | 0x24
+--------------------------+
|   build time (ignored)   | 0x28
+--------------------------+
|  "boot parameter" (..?)  | 0x2c
+--------------------------+
:                          : 0x30
.                          .
  it gets fuzzy from here. 
  Looks like this is yours 
  to do what you want with 
.                          .
:                          :
+--------------------------+
| header CRC(if type=0x0a) | 0x6c
+--------------------------+ 
|                          | 0x70
+--                      --+
|                          |
+--       Reserved       --+
|        (set to 0)        |
+--                      --+
|                          |
+==========================+
|  boot code starts here   | 0x80

The B Start is a jump instruction to the entry point in the boot code. Where that entry point is is mostly up to you.

The 0x41676d69 tells the boot loader that this is a bootable image. The CRCs are basically checksums (but don't ask me how they're calculated); fortunately, if the image_type is set to 10 (0x0a), they're ignored and can be set to 0.

Far as i'm seeing, the image version and build time are ignored by the boot loader as well. They're just there for tools or whatever to make it easier to figure out versions and stuff.

The "boot parameter", i'm not too sure about. I'm seeing stuff that says "just set it to 0" -- which apparently works. :) But what it means if it's not 0, i couldn't tell you.

cHao
  • 84,970
  • 20
  • 145
  • 172
  • This is all i needed! Thank you! Just one more question for clarification:"Is this an EBN image header?" – 71GA Mar 05 '12 at 14:46
  • 1
    @71GA: Dunno. I've never even heard of EBN, it doesn't seem to be in Google, and what i could tell you is limited to what i can google. :P Looks like this is a standard header for ARM boot images; that's all the info i have. – cHao Mar 05 '12 at 14:51
  • Something about EBN headers is mentioned [here](http://ics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc314x.pdf) check site 93, point 5-7. – 71GA Mar 05 '12 at 17:45
  • Hi @chao I am disassembling the vmlinux and i see .word in the function definitions. What does .word means in the assembly code? Could you please answer. A line of disassembly is as follows - "c0131524: c0e29ce0 .word 0xc0e29ce0" – Sandeep Oct 01 '13 at 08:08
  • 1
    @Manty: `.word` appears to be the directive to directly specify data. The disassembler thinks the 4 bytes at address 0xc0131524 are raw data; either they don't form a recognized instruction, or there's nothing jumping to that spot in the program, and/or they're in a section marked as data. – cHao Oct 01 '13 at 12:47
  • Thanks @Chao I got it. So what could be the equivalent C source code? I feel one such case where it can be used is for constant variables. Is it so? – Sandeep Oct 02 '13 at 02:03
  • @Manty: `static int x = 0xc0e29ce0;` could do it. But that's outside the scope of this question. – cHao Oct 02 '13 at 09:16