在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 "[email protected]" "#L"

或者

$K\ARM\ARMCC\bin\fromelf.exe  --bincombined [email protected] !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 Code Description
% 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)
~ 1 Line number of the current cursor position
^ 1 Column number of the current cursor position
File Code Description
$D Device name as selected from the Device Database.
E Editor 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.
H Application HEX file name (PROJECT1.H86).
$J Absolute 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.
K Absolute root folder of the development toolchain, regardless of the Key Code used.
L Linker output file. Typically the executable file used for debugging (PROJECT1).
$M CPU mask revision number.
P Current project file name.
X µVision executable program file (..\UV4\UV4.EXE). Works for For Key Code %, # @.
$X XTAL clock frequency in MHz as specified in Options for Target — Target — XTAL.
^X XTAL clock frequency in kHz as specified in Options for Target — Target — XTAL.

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章