1

I'm working on OS development on the Raspberry Pi.

in the makefile I found this command :

kernel.img: kernel.elf
    $(ARMGNU)-objcopy kernel.elf -O binary kernel.img

witch copy the kernel.elf object file and generate the file kernel.img

what's the difference between the two file??

I noticed that the output of kernel.img is a part of kernel.elf. so what's omitted (elf headers, sections???) and what's kept.

hexdump kernel.img :
0000000 d902 e3a0 4030 e59f 9030 e59f 5000 e3a0
0000010 6000 e3a0 7000 e3a0 8000 e3a0 0000 ea00
0000020 01e0 e8a4 0009 e154 fffc 3aff 3010 e59f
0000030 ff33 e12f f002 e320 fffd eaff 9000 0000
0000040 9000 0000 8048 0000 b004 e52d b000 e28d
0000050 d014 e24d 0008 e50b 100c e50b 2010 e50b
0000060 d000 e28b 0800 e8bd ff1e e12f          
000006c

hexdump kernel.elf
0000000 457f 464c 0101 0001 0000 0000 0000 0000
0000010 0002 0028 0001 0000 8000 0000 0034 0000
0000020 80f4 0000 0002 0500 0034 0020 0001 0028
0000030 0007 0004 0001 0000 8000 0000 8000 0000
0000040 8000 0000 006c 0000 006c 0000 0005 0000
0000050 8000 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
*
0008000 d902 e3a0 4030 e59f 9030 e59f 5000 e3a0
0008010 6000 e3a0 7000 e3a0 8000 e3a0 0000 ea00
0008020 01e0 e8a4 0009 e154 fffc 3aff 3010 e59f
0008030 ff33 e12f f002 e320 fffd eaff 9000 0000
0008040 9000 0000 8048 0000 b004 e52d b000 e28d
0008050 d014 e24d 0008 e50b 100c e50b 2010 e50b
0008060 d000 e28b 0800 e8bd ff1e e12f 2141 0000
0008070 6100 6165 6962 0100 0017 0000 0906 0108
0008080 0412 0114 0115 0317 0118 0119 011a 4700
0008090 4343 203a 5328 756f 6372 7265 2079 2b47
00080a0 202b 694c 6574 3220 3030 7138 2d33 3636
00080b0 2029 2e34 2e33 0032 2e00 7973 746d 6261
00080c0 2e00 7473 7472 6261 2e00 6873 7473 7472
00080d0 6261 2e00 6574 7478 2e00 5241 2e4d 7461
00080e0 7274 6269 7475 7365 2e00 6f63 6d6d 6e65
  • See stackoverflow.com/questions/2427011/…. Basically, objcopy strips off headers and comments generally used for debugging, such as identifying what architecture the executable is, etc. Just about any additional information that isn't required for proper execution gets removed to decrease size of the executable. Also, try running hexdump -C on the files as it also shows ASCII characters which may be helpful in visualizing. – ritiek Dec 30 '19 at 14:42
2

google://"linux objcopy"

objcopy can be used to generate a raw binary file by using an output target of binary (e.g., use -O binary). When objcopy generates a raw binary file, it will essentially produce a memory dump of the contents of the input object file. All symbols and relocation information will be discarded. The memory dump will start at the load address of the lowest section copied into the output file.

| improve this answer | |
  • what I understand here and by searching in the net is that the objcopy will produce memory dump of certain sections??? headers and some other sections are discared?? Im I right??? witch sections are copied and witch are discared?? – mikmik Jun 1 '14 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.