About fromELF

fromELF是一款实用工具,用于将ELF格式文件转换为多种适用于ROM工具或直接内存加载的格式,如二进制、S记录等。此外,它还能显示关于ELF对象的各种信息,并生成包含这些信息的文本文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一、About fromELF

The fromELF utility translates Executable Linkable Format (ELF) image files produced by armlink into other formats suited to ROM tools and to loading directly into memory. You can also use it to display various information about an ELF object or to generate text files containing the information.

fromELF outputs the following image formats:

  • Plain binary format.

  • Motorola 32-bit S-record format.

  • Intel Hex-32 format.

  • Byte Oriented (Verilog Memory Model) Hex format.

  • ELF format. You can resave as ELF. For example, you can convert a -debug ELF image to a -nodebug ELF image).

fromELF can also display information about the input file, for example disassembly output or symbol listings, to either standard output or a text file.

Note

Do not link your images with the -nodebug linker option if you require a -fieldoffsets fromELF step. If your image is produced without debug information:

  • fromELF cannot translate the image into other file formats

  • fromELF cannot produce a meaningful disassembly listing.

二、fromELF command-line options

The fromELF command syntax is as follows:

fromelf [-help] [ -fieldoffsets [[-select select_options]]] [-nolinkview] [-nodebug] [-vsn] [[text_output_format] |  code_output_format] [-base n] [memory_config] [-output output_file] {input_file}

where:

-help

This option shows help and usage information. If this option is specified, other command-line options are ignored. Calling fromELF without any parameters produces the same help information.

-fieldoffsets

This option produces, to standard output, a list of assembly language EQU directives that equate C++ class or C structure field names to their offsets from the base of the class or structure. The input ELF file can be a relocatable object or an image.

Use -o to redirect the output to a file. Use the INCLUDE command from armasm to load the produced file and provide access to C++ classes and C structure members by name from assembly language. See the ADS Assembler Guide for more information on armasm.

Note

If the source file does not have debug information, this option is not available. You cannot use this option together with a code_output_format.

-fieldoffsets outputs all structure information. To output a subset of the structures, use -select select_options.

If you do not require a file that can be input to armasm, use the -text -a option to format the display addresses in a more readable form. The -a option only outputs address information for structures and static data in images because the addresses are not known in a relocatable object.

-select select_options

Use -select select_option together with either the -fieldoffsets or -text -a options to select only those fields that match the patterns in the option list.

Use special characters to select multiple fields:

  • Join options in the list together with a , as in: a*,b*,c*.

  • The wildcard character * can be used to match any name.

  • The wildcard character ? can be used to match any single letter.

  • Specify the fields to include by prefixing a + to the select_option string. This is the default.

  • Specify the fields to exclude by prefixing a ~ to the select_option string.

If you are using a special character on Unix, you must enclose the options in quotes to prevent the shell expanding the selection.

-nolinkview

Use -nolinkview to discard the section-level view (link-time view) from the ELF image and retain only the segment level view (load-time view). Discarding the link-view section level eliminates:

  • the section header table

  • the section header string table

  • the string table

  • the symbol table

  • all debug sections.

All that is left in the output is the program header table and the program segments. According to the ELF specification, these are all that a program loader can rely upon being present in an ELF file.

Caution

This option can have unexpected effects if -elf is not specified on the command line. See Example 7.2 for an example of correct usage.

-nodebug

This option does not put debug information in the output files. This is the default for binary images. If -nodebug is specified, it affects all output formats. It overrides the -text -g option.

Caution

This option can have unexpected effects if -elf is not specified on the command line. The options in Example 7.1 produce a text file because no output format has been specified.

Example 7.1. Text output


fromelf -nodebug image -o image_nodb.asf 

To get ELF format output use the options shown in Example 7.2

Example 7.2. ELF output


fromelf -elf -nodebug image.axf -o image_ndb.axf

-vsn

This option displays fromELF version information.

text_output_format

Use a text specification, for example -text -c, to display image information in text format. You can decode an ELF image or ELF object file using this option. This is the default. If no text or code output format is specified, -text is assumed.

If output_file is not specified with the -o option, the information is displayed on stdout.

If a specific text category is not specified, the default is to output header information.

If specified, the text category consists of one or more of the following:

a

Prints the global and static data addresses (including addresses for structure and union contents). This option can only be used on files containing debug information. Use the -select option to output a subset of the data addresses.

c

Disassembles code

d

Prints contents of the data sections

g

Prints debug information

r

Prints relocation information

s

Prints the symbol table

t

Prints the string table(s)

v

Prints detailed information on each segment and section header of the image

z

Prints the code and data sizes.

The category selectors can be specified as one of:

  • individual options, -text -c -d

  • a single concatenated string, -text -cd

  • category selectors only, -c -d

  • multiple characters following a slash character, -text/cd.

If an output format is not specified, the default output format of -text is used and the individual category selectors are recognized. If another output format is specified, the selectors are ignored.

code_output_format

This option selects the binary or ELF output file options. code_output_format can be one of:

-bin

Plain binary. You can split output from this option into multiple files with the memory_config option.

-ihf

Extended Intellec Hex format. You can specify the base address of the output with the -base option. (This option is deprecated and will be removed from future versions of the product.)

-m32

Motorola 32-bit format (32-bit S-records). You can specify the base address of the output with the -base option.

-i32

Intel Hex-32 format. You can specify the base address of the output with the -base option.

-vhx

Byte Oriented (Verilog Memory Model) Hex format. This format is suitable for loading into the memory models of HDL simulators. You can split output from this option into multiple files with the memory_config option.

-elf

ELF format (resaves as ELF). This can be used to convert a debug ELF image into a no-debug ELF image.

If you use fromELF to convert an ELF image containing multiple load regions to a binary format using any of the -bin, -ihf, -m32, -i32, or -vhx options, fromELF creates an output directory named output_file and generates one binary output file for each load region in the input image. fromELF places the output files in the output_file directory.

ELF images contain multiple load regions if, for example, they are built with a scatter-load description file that defines more than one load region.

-base n

This option specifies the base address of the output for Motorola S-record, Intel Hex, and Extended Intellec Hex file formats. This option is available only if -m32, -i32, or -ihf is specified as the output format.

You can specify the base address as either:

  • a decimal value, for example -base 0

  • as a hexadecimal value, for example -base 0x8000.

All addresses encoded in the output file start at the base address n. If you do not specify a -base option, the base address is taken from the load region address.

Note

If multiple load regions are present, the -base value is used for each output file. That is, it overrides all load region addresses.

memory_config

This option outputs multiple files for multiple memory banks. This option is available only if -vhx or -bin is specified as the output format.

The format of memory_config is -widthxbanks where:

width

is the width of memory in the target memory system (8-bit, 16-bit, 32-bit, or 64-bit).

banks

specifies the number of memory banks in the target memory system.

Valid configurations are:


-8x1
-8x2
-8x4
-16x1
-16x2
-32x1
-32x2
-64x1

fromELF uses the last specified configuration if more than one configuration is specified. If this option is selected for any format other than -bin or -vhx it is ignored.

If the image has one load region, fromELF generates bank files with the following naming conventions:

  • If there is one memory bank (banks is 1) the output file is named by the -o output_file argument.

  • If there are multiple memory banks (bank>1), fromELF generates banks number of files starting with output_file0 and finishing with output_file bank-1. For example:


    fromelf -vhx -8x2 test.axf -o test

    generates two files named test0 and test1.

If the image has multiple load regions, fromELF creates a directory named output_file and generates bank files for each load region named load region0 to load region banks-1.

The memory width specified by width controls the size of the chunk of information read from the image and written to a file. The first chunk read is allocated to the first file (output_file0), the next chunk is allocated to the next file. After a chunk is allocated to the last file, allocation begins again with the first file (that is, the allocation is modulo based on the number of files). For example:

For a memory_config of -8x4


byte0 -> file0
byte1 -> file1
byte2 -> file2 
byte3 -> file3 
byte4 -> file0 
...

For a memory_config of -16x2


halfword0 -> file0 
halfword1 -> file1 
halfword3 -> file0 
...

-output output_file

This option specifies the name of the output file, or the name of the output directory if multiple output files are created (see the description of text_output_format and code_output_format for more information). Specifying the output file is optional with the -text output option and mandatory with all other outputs.

input_file

This option specifies the ELF file to be translated.

fromELF accepts only ARM-executable ELF files and ARM object ELF files (.o). If input_file is a scatter-loaded image that contains more than one load region and the output format is either -bin, -ihf, -m32, -i32, or -vhx, fromELF creates a separate file for each load region.

 

<think>嗯,用户的问题是想下载fromelf工具。用户可能是一位嵌入式开发者或者学生,正在使用Keil MDK进行ARM开发,需要生成bin文件或其他格式的转换工具。从用户引用的大量资料来看,用户已经查阅过fromelf的使用方法,但找不到独立下载途径,显得有些着急。 用户引用的5个资料都指向同一个关键信息:fromelf是Keil MDK内置工具。引用1和2详细说明了如何通过命令行或Keil界面生成bin文件,引用3到5则补充了语法和高级用法。这说明用户真正需要的不是独立工具,而是正确调用现有环境中的工具。 考虑到用户可能刚接触Keil,我决定分三步回答:首先明确工具位置(避免用户盲目搜索下载),其次给出两种调用方式(满足不同使用习惯),最后补充常见问题(预防后续操作障碍)。要特别注意提醒用户检查环境变量,因为这是新手最容易卡住的地方——很多人会忘记安装Keil时勾选"Add PATH"选项。 用户引用的资料里提到工程名(@P)和链接文件名(#L)的区别特别重要(引用2),这点必须强调,否则用户可能复制命令后生成文件失败。另外从引用4看出用户似乎需要生成lst文件,虽然当前没提,但可以预判性补充相关参数。 最后生成的问题列表要覆盖用户可能遇到的延伸需求:环境配置问题对应常见安装错误,交叉编译场景则是为Linux开发者准备的,而查看版本参数能帮助用户确认工具链兼容性——毕竟ARMv5/v6/v7的工具链命令存在差异(引用3提到v5.02的语法)。</think>根据引用资料,**fromelf工具无需单独下载**,它是Keil MDK开发环境的内置工具。以下是使用说明: ### 一、工具位置 1. **默认路径**: `C:\Keil_v5\ARM\ARMCC\bin\fromelf.exe` (具体路径取决于Keil安装位置和编译器版本,`ARMCC`可能为`ARMCLANG`) ### 二、使用方法 #### 方法1:命令行生成(推荐) 1. 打开命令提示符(CMD) 2. 输入命令格式: ```bash fromelf.exe --bin --output 输出文件路径\目标文件名.bin 工程路径\工程名.axf ``` **示例**(引用[^1][^2]): ```bash fromelf.exe --bin --output .\usart.bin .\USART.axf ``` #### 方法2:Keil工程自动生成 1. 在Keil中右击工程名 → `Options for Target` → `User`选项卡 2. 勾选 `Run #1`,输入命令: ```bash fromelf --bin --output "输出路径\@P.bin" "#L" ``` - `@P`:自动替换为工程名 - `#L`:自动指向链接生成的`.axf`文件 (引用[^2][^4]) --- ### 三、其他功能(引用[^3][^4][^5]) ```bash # 生成反汇编文件(.lst) fromelf --text -c 工程名.axf > 输出文件.lst # 生成Hex文件 fromelf --i32 工程名.axf --output 输出文件.hex # 查看结构体/类内存布局 fromelf --fieldoffsets 工程名.axf ``` ### 四、常见问题 1. **找不到fromelf**: - 检查Keil安装目录的`ARM\bin`文件夹 - 将`ARM\bin`路径添加到系统环境变量`PATH` 2. **生成失败**: - 确保工程已成功编译生成`.axf`文件 - 检查命令中的文件路径是否正确 --- ### 相关问题 1. **如何配置Keil环境变量以全局调用fromelf?** 2. **fromelf生成.bin文件时出现内存区域错误如何解决?** 3. **是否支持在Linux环境下使用fromelf进行交叉编译?** 4. **如何通过fromelf查看固件的版本信息?**
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值