在KEIL中生成bin文件的方法

生成hex文件

KEIL中默认生成的是axf文件。

如果想要生成hex文件,则只需要简单地勾一下:

 

生成bin文件

要生成bin文件,则需要用到fromelf。

Keil自带了一个小工具,可以通过执行指令来将AXF文件转换为BIN文件这就需要调用一个外部程序fromelf.exe来将AXF文件转换为BIN格式文件。

fromelf.exe文件的位置在安装目录 Keil_v5\ARM\ARMCC\bin 或者 Keil_v5\ARM\ARMCLANG\bin 目录下。

在Options -> User -> After Build/Rebuild -> Run#1中输入:

C:\Keil_v5\ARM\ARMCLANG\bin\fromelf.exe --bin -o  ./Objects/Demo.bin ./Objects/Demo.axf

其中-o后面的要输出目标bin文件的路径和文件名;最后面的是生成的axf文件的路径及文件名。

这个方法网上有很多例子可以参考。

 

fromelf详解

首先参考KEIL官网的手册:

fromelf Command-line Options

http://www.keil.com/support/man/docs/armutil/armutil_pge1362128884798.htm

 

主要内容如下:

ARM 映像转换工具
fromelf [options] input_file
选项:
--help 显示帮助信息
--vsn 显示版本信息
--output file 输出文件名. (默认输出 -text 格式)
--nodebug 不要输出调试信息到映像文件中
--nolinkview 不要输出段信息到映像文件中

二进制输出格式:
--bin 普通二进制
--m32 摩托罗拉32位Hex码
--i32 英特尔32位Hex码
--vhx 定向字节的 Hex 格式
--base addr 为 m32,i32设置基地址(可选的)

输出格式要求的调试信息
--fieldoffsets Structures/Classes的汇编描述
--expandarrays Arrays inside and outside structures are expanded

其他输出格式:
--elf ELF格式
--text 文本信息
文本信息的标志
-v 详细信息
-a 打印数据的地址信息 (得到的.axf映像文件)
-c 汇编码
-d 打印数据的段内容
-e 打印例表
-g 打印调试表
-r 打印重定位信息
-s 打印符号表
-t 打印字符表
-y 打印段内容分析
-z 打印代码与数据的大小信息

 

可移植的方法

上述方法有一个不好的问题,就是在一个项目组里面多人同时开发一个项目时,如果大家安装KEIL开发环境时的路径不一样,则无法共享同一个配置。另外,当完成一个项目的开发后,再开始一个新的项目时,生成的axf文件的文件名也需要重新配置。为了解决这个问题,可以使用以下的命令行:

fromelf --bin -o "$L@L.bin" "#L"

或者

$K\ARM\ARMCC\bin\fromelf.exe  --bincombined --output=@L.bin !L

自动生成跟工程名称相同的bin文件。

 

说明:

符号代号(Key Code)
$扩展为 指定文件的路径名
@表示 Output -> Name of Exectable:定义的工程名,比如test1
build工程后,最终生成的bin文件名称将是test1.bin

当前目录下的扩展路径

!L 编译(Build)后,就是 .\obj\xx.axf文件

文件代号(File Code)
K keil develop chaintool 工具链(fromelf.exe)
L

Linker output file

L.bin 编译后,生成的就是最终的xx.bin文件

参考:

Key Sequence for Tool Parameters
http://www.keil.com/support/man/docs/uv4/uv4_ut_keysequence.htm

Use Key Sequences to pass arguments from µVision to external user programs. Key Sequences are combinations of a Key Code and a File Code. Key sequences can be used, for example, in the dialogsToolsSVCSOptions for Target — User, or from the command line. The following rules apply:

  • Certain Key Codes have to be duplicated when used from the command line.
    To use the symbols $, #, %, @, ~, ^
    escape them with $$, ##, %%, @@, ~~, ^^.
  • Enclose Key Sequences within quotes (" ") when using folder names that might contain special characters (space~, or #).

Key Codes and File Codes are listed in the tables below:

Key CodeDescription
%File name with extension (PROJECT1.UVPROJ)
#File name with extension and complete path specification (C:\MYPROJECT\PROJECT1.UVPROJ)
@File name without extension or path specification (PROJECT1)
$Path name of a file. Path names get extended with a backslash. For example, $P could generate C:\MYPROJECT\.
!File name with extension and relative path specification to the current folder (.\SRC\TEST.C)
~ 1Line number of the current cursor position
^ 1Column number of the current cursor position
File CodeDescription
$DDevice name as selected from the Device Database.
EEditor file name currently in focus.
F

Depending on the context, this File Code returns:

  • The file selected in the window Project.
  • The currently active editor file.
  • The file that is currently translated by a build process.
HApplication HEX file name (PROJECT1.H86).
$JAbsolute compiler system include folder. Compiler base folders are listed in the fieldProject — Manage — Project Items — Folder/Extensions - ARMCC Folder. The include path depends on the compiler selected in Options for Target - Code Generation - ARM Compiler.
KAbsolute root folder of the development toolchain, regardless of the Key Code used.
LLinker output file. Typically the executable file used for debugging (PROJECT1).
$MCPU mask revision number.
PCurrent project file name.
XµVision executable program file (..\UV4\UV4.EXE). Works for For Key Code %, # @.
$XXTAL clock frequency in MHz as specified in Options for Target — Target — XTAL.
^XXTAL clock frequency in kHz as specified in Options for Target — Target — XTAL.

 

 

 

 

 

 

  • 9
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值