objcopy概括:
gnu objcopy实用程序将一个对象文件的内容复制到另一个文件。objcopy使用gnu bfd库来读取和写入对象文件。它可以以与源对象文件不同的格式写入目标对象文件。objcopy的确切行为是由命令行选项控制的
BFD Library概括:
中文名称: 二进制文件描述库(Binary File Descriptor library)
BFD是GNU项目用于对各种格式的对象文件进行可移植操作的主要机制。它支持大约50种文件格式,适用于大约25种指令集架构(2003年)。
列出可用的BFD target
$ objdump -i
objcopy说明 | |
参数 | 说明 |
-j <section name> | 只将由sectionname指定的section拷贝到输出文件 |
-B <architecture> | 如 -B arm 或者 -B aarch64 |
-O <output-target bfdname> | 指定输出目标(主要为以下几种情况) |
-O srec | 16进制ascii 文本格式 摩托罗拉开发, 后缀.srec (S-record) |
-O ihex | 16进制ascii 文本格式 用于intel 处理器,后缀.hex |
-O binary | 生成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. |
-O elf32-littlearm | |
-S | remove sections containing debugging information |
-R | remove sections which contain information that is not needed by the binary file. |
--pad-to <addr> | Pad the output file up to the load address address. This is done by increasing the size of the last section. The extra space is filled in with the value specified by --gap-fill |
-gap-fill <val> | 填充值 默认为0 |
objcopy实例1: 生成u-boot.srec |
arm-linux-gnueabihf-objcopy \ -j .text -j .secure_text -j .secure_data -j .rodata -j .hash -j .data -j .got \ -j .got.plt -j .u_boot_list -j .rel.dyn -j .binman_sym_table -j .text_rest \ -j .dtb.init.rodata -j .efi_runtime -j .efi_runtime_rel \ --gap-fill=0xff \ -O srec \ u-boot u-boot.srec |
objcopy实例2: 制作u-boot.elf |
step0:变量设置 ifdef CONFIG_ARM64 PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64 else PLATFORM_ELFFLAGS += -B arm -O elf32-littlearm endif #define CONFIG_SYS_TEXT_BASE 0x00400000 step1:u-boot.bin 转换为u-boot.o objcopy -I binary $(PLATFORM_ELFFLAGS) u-boot.bin u-boot-elf.o step2:u-boot.o 转换为u-boot.elf ld u-boot-elf.o -o u-boot.elf\ --defsym=$(PLATFORM_ELFENTRY)=$(CONFIG_SYS_TEXT_BASE) \ -Ttext=$(CONFIG_SYS_TEXT_BASE) |