Zynq > BOOT.binの解析 > H. Boot.binに含まれる.elfファイルの情報

```txt:動作環境
PetaLinux 2014.4
Vivado v2014.4
MicroZed
```

2014年頃のメモより。

.elfファイルは以下の構造を持つ
- ELF header
- Program header table
- セクション1
- ...
- セクションN
- Section header table

### H-1. zynq-boot編

[zynq-boot](https://github.com/cambridgehackers/zynq-boot)で使用するzynq_fsbl.elfおよびそれを用いて作成したboot.binファイルを見ると、zynq_fsbl.elfのセクション1からセクションNをboot.binにコピーして、header情報はコピーしていないようだ。

Linux上でreadelf -S zynq_fsbl.elfにて表示されたセクション情報は以下の通り 

```c:zynq_fsbl.elfのセクション情報
[zynq-boot]$ readelf -S zynq_fsbl.elf | less
There are 34 section headers, starting at offset 0xc5864:
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .boot             PROGBITS        00000000 008000 000240 00  AX  0   0  4
  [ 2] .text             PROGBITS        00000240 008240 00a4c4 00  AX  0   0  4
  [ 3] .text.startup     PROGBITS        0000a704 012704 00001c 00  AX  0   0  4
  [ 4] .handoff          PROGBITS        0000ff40 017f40 00004c 00  AX  0   0  4
  [ 5] .mmu_tbl          PROGBITS        00010000 018000 004000 00   A  0   0  1
  [ 6] .init             PROGBITS        00014000 01c000 000018 00  AX  0   0  4
  [ 7] .fini             PROGBITS        00014018 01c018 000018 00  AX  0   0  4
  [ 8] .glue_7           PROGBITS        00014030 01c030 000000 00  AX  0   0  4
  [ 9] .glue_7t          PROGBITS        00014030 01c030 000000 00  AX  0   0  4
  [10] .rodata           PROGBITS        00014030 01c030 0001c0 00   A  0   0  4
  [11] .eh_frame         PROGBITS        000141f0 01c1f0 000004 00   A  0   0  4
  [12] .jcr              PROGBITS        000141f4 01c1f4 000004 00  WA  0   0  4
  [13] .init_array       INIT_ARRAY      000141f8 01c1f8 000004 00  WA  0   0  4
  [14] .comment          PROGBITS        000141fc 01d32c 000030 01  MS  0   0  1
  [15] .fini_array       FINI_ARRAY      000141fc 01c1fc 000004 00  WA  0   0  4
  [16] .ARM.attributes   ARM_ATTRIBUTES  00014200 01d35c 00003f 00      0   0  1
  [17] .data             PROGBITS        00014200 01c200 001128 00  WA  0   0  8
  [18] .init_array.00000 PROGBITS        00015328 01d328 000004 00  WA  0   0  4
  [19] .bss              NOBITS          00015340 01d32c 00acc0 00  WA  0   0 64
  [20] .heap             NOBITS          00020000 01d32c 001000 00  WA  0   0  1
  [21] .stack            NOBITS          ffff0000 020000 006000 00  WA  0   0  1
  [22] .debug_info       PROGBITS        00000000 01d39b 0068e0 00      0   0  1
  [23] .debug_abbrev     PROGBITS        00000000 023c7b 00198f 00      0   0  1
  [24] .debug_loc        PROGBITS        00000000 02560a 0019a8 00      0   0  1
  [25] .debug_aranges    PROGBITS        00000000 026fb8 000340 00      0   0  8
  [26] .debug_line       PROGBITS        00000000 0272f8 002f07 00      0   0  1
  [27] .debug_macinfo    PROGBITS        00000000 02a1ff 098919 00      0   0  1
  [28] .debug_str        PROGBITS        00000000 0c2b18 001999 01  MS  0   0  1
  [29] .debug_frame      PROGBITS        00000000 0c44b4 00124c 00      0   0  4
  [30] .debug_ranges     PROGBITS        00000000 0c5700 000018 00      0   0  1
  [31] .shstrtab         STRTAB          00000000 0c5718 00014b 00      0   0  1
  [32] .symtab           SYMTAB          00000000 0c5db4 001e00 10     33 307  4
  [33] .strtab           STRTAB          00000000 0c7bb4 000f76 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
```

上記においてOff:0x8000から(0x1c1fc+4)あたりまで[Name=.fini_array | TYPE=FINI_ARRAY]がboot.binのアドレス0xA80以降にコピーされていることをLinux上で確認済み。
 
### H-2. XSDKで作成したベアメタルアプリ編

H-1と同様に、XSDKでベアメタルアプリ作成時のZynqFSBL.elfおよびBOOT.binの関係

```c:ZynqFSBL.elfのセクション情報
There are 29 section headers, starting at offset 0x5a7c4:
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 008000 00ccb4 00  AX  0   0 64
  [ 2] .handoff          PROGBITS        0000ccb4 014cb4 00004c 00  AX  0   0  4
  [ 3] .init             PROGBITS        0000cd00 014d00 000018 00  AX  0   0  4
  [ 4] .fini             PROGBITS        0000cd18 014d18 000018 00  AX  0   0  4
  [ 5] .rodata           PROGBITS        0000cd30 014d30 00035c 00   A  0   0  4
  [ 6] .data             PROGBITS        0000d090 015090 003028 00  WA  0   0  8
  [ 7] .eh_frame         PROGBITS        000100b8 0180b8 000004 00   A  0   0  4
  [ 8] .mmu_tbl          PROGBITS        00014000 01c000 004000 00   A  0   0  1
  [ 9] .init_array       INIT_ARRAY      00018000 020000 000008 00  WA  0   0  4
  [10] .fini_array       FINI_ARRAY      00018008 020008 000004 00  WA  0   0  4
  [11] .rsa_ac           NOBITS          0001800c 02000c 001034 00  WA  0   0  1
  [12] .ARM.attributes   ARM_ATTRIBUTES  00019040 02000c 000033 00      0   0  1
  [13] .bss              NOBITS          00019040 02000c 001a80 00  WA  0   0 32
  [14] .heap             NOBITS          0001aac0 02000c 002000 00  WA  0   0  1
  [15] .stack            NOBITS          ffff0000 028000 00d400 00  WA  0   0  1
  [16] .debug_line       PROGBITS        00000000 02003f 00647d 00      0   0  1
  [17] .debug_info       PROGBITS        00000000 0264bc 00c5f8 00      0   0  1
  [18] .debug_abbrev     PROGBITS        00000000 032ab4 003167 00      0   0  1
  [19] .debug_aranges    PROGBITS        00000000 035c20 0004f8 00      0   0  8
  [20] .debug_macro      PROGBITS        00000000 036118 005539 00      0   0  1
  [21] .debug_str        PROGBITS        00000000 03b651 015524 01  MS  0   0  1
  [22] .comment          PROGBITS        00000000 050b75 000046 01  MS  0   0  1
  [23] .debug_frame      PROGBITS        00000000 050bbc 001c7c 00      0   0  4
  [24] .debug_loc        PROGBITS        00000000 052838 007a7e 00      0   0  1
  [25] .debug_ranges     PROGBITS        00000000 05a2b6 0003f8 00      0   0  1
  [26] .shstrtab         STRTAB          00000000 05a6ae 000115 00      0   0  1
  [27] .symtab           SYMTAB          00000000 05ac4c 002dc0 10     28 331  4
  [28] .strtab           STRTAB          00000000 05da0c 002151 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
```