请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
主题中讨论的其他器件:TM4C1294NCPDT随附的 TM4C1294NCPDT 示例创建了初始化段、其中包含孔洞、因为使用了放置在特定地址的段:
$ ~/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armofd --xml TM4C1294NCPDT_fixed_checksum.out | ~/ti/ti-processor-sdk-rtos-am335x-evm-05.01.00.11/cg_xml/bin/sectti
Reading from stdin ...
************************************************************
REPORT FOR FILE: TM4C1294NCPDT_fixed_checksum.out
************************************************************
Name : Size (dec) Size (hex) Type Load Addr Run Addr
-------------------- : ---------- ---------- ---- ---------- ----------
.intvecs : 520 0x00000208 DATA 0x00000000 0x00000000
.text : 68 0x00000044 CODE 0x00000208 0x00000208
.stack : 512 0x00000200 UDATA 0x20000000 0x20000000
.TI.bound:CHECKSUM : 2 0x00000002 DATA 0x000f0000 0x000f0000
------------------------------------------------------------
Totals by section type
------------------------------------------------------------
Uninitialized Data : 512 0x00000200
Initialized Data : 522 0x0000020a
Code : 68 0x00000044
由于存在漏洞、预期的二进制文件大小为0xF0002 = 983042。
随附的示例有两种生成二进制输出文件的方法:
- 使用 TI ARM v20.2.4编译器中的 armobjcopy 的编译后规则
- 来自 TI ARM v20.2.4编译器的 armhex、使用 CCS Build -> Arm Hex Utility 下的 CCS 工程属性进行配置。 唯一设置的选项是输出格式(设置为--binary)和输出文件名(--outfile)。
CCS 编译控制台的完整输出、包括创建二进制输出文件的两种方法:
**** Build of configuration Debug for project TM4C1294NCPDT_fixed_checksum **** /home/mr_halfword/ti/ccs1020/ccs/utils/bin/gmake -k -j 12 all -O Building file: "../main.c" Invoking: Arm Compiler "/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/home/mr_halfword/workspace_v10/TM4C1294NCPDT_fixed_checksum" --include_path="/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/include" --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --asm_listing --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c" Finished building: "../main.c" Building file: "../tm4c1294ncpdt_startup_ccs.c" Invoking: Arm Compiler "/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/home/mr_halfword/workspace_v10/TM4C1294NCPDT_fixed_checksum" --include_path="/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/include" --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --asm_listing --preproc_with_compile --preproc_dependency="tm4c1294ncpdt_startup_ccs.d_raw" "../tm4c1294ncpdt_startup_ccs.c" Finished building: "../tm4c1294ncpdt_startup_ccs.c" Building target: "TM4C1294NCPDT_fixed_checksum.out" Invoking: Arm Linker "/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --asm_listing -z -m"TM4C1294NCPDT_fixed_checksum.map" --heap_size=0 --stack_size=512 -i"/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/lib" -i"/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="TM4C1294NCPDT_fixed_checksum_linkInfo.xml" --rom_model -o "TM4C1294NCPDT_fixed_checksum.out" "./main.obj" "./tm4c1294ncpdt_startup_ccs.obj" "../tm4c1294ncpdt.cmd" -llibc.a <Linking> Finished building target: "TM4C1294NCPDT_fixed_checksum.out" Building files: "TM4C1294NCPDT_fixed_checksum.out" Invoking: Arm Hex Utility "/home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armhex" --diag_wrap=off --binary -o "TM4C1294NCPDT_fixed_checksum.armhex_bin" "TM4C1294NCPDT_fixed_checksum.out" Translating to Binary format... "TM4C1294NCPDT_fixed_checksum.out" .intvecs ==> .intvecs "TM4C1294NCPDT_fixed_checksum.out" .text ==> .text "TM4C1294NCPDT_fixed_checksum.out" .TI.bound:CHECKSUM ==> .TI.bound:CHECKSUM Finished building: "TM4C1294NCPDT_fixed_checksum.out" Create binary file /home/mr_halfword/ti/ccs1020/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS/bin/armobjcopy -O binary TM4C1294NCPDT_fixed_checksum.out TM4C1294NCPDT_fixed_checksum.objcopy_bin **** Build Finished ****
生成的二进制文件的大小为:
$ ls -l *bin* -rw-rw-r-- 1 mr_halfword mr_halfword 590 Apr 2 10:15 TM4C1294NCPDT_fixed_checksum.armhex_bin -rw-rw-r-- 1 mr_halfword mr_halfword 983042 Apr 2 10:15 TM4C1294NCPDT_fixed_checksum.objcopy_bin
由 armobjcopy 创建的二进制文件具有预期的大小。
但是、armhex 创建的二进制文件只是所有已初始化段的总大小。 即、不是有效的二进制文件、因为已排除 了已初始化段之间的空洞。 在 这种情况下、通过结合使用--binary 和--image 以及 ROMS 指令来查看 ARM 汇编语言工具 v20.2.0.LTS 用户指南、可以创建有效的二进制文件。
仅使用--binary 选项会导致输出文件不包含已初始化段之间的孔洞的 armhex 中是否存在错误?