Skip to content

makefiles: FIX boards generating a binary '.hex' file#8840

Merged
kaspar030 merged 2 commits intoRIOT-OS:masterfrom
cladmi:pr/make/variables_cleanup
Mar 28, 2018
Merged

makefiles: FIX boards generating a binary '.hex' file#8840
kaspar030 merged 2 commits intoRIOT-OS:masterfrom
cladmi:pr/make/variables_cleanup

Conversation

@cladmi
Copy link
Contributor

@cladmi cladmi commented Mar 27, 2018

Contribution description

Some boards generate a '.hex' file that is a created with '-Obinary' which is wrong and is problematic to create rules by extension used in #8838

I also include some cleanup for HEXFILE/ELFFILE/BINFILE variables in the boards Makefile. To use them and remove unused BINFILE.

Issues/PRs references

Used in #8838

cladmi added 2 commits March 27, 2018 16:02
* Use the existing variable when possible
* Remove duplicate definition
* Remove unused BINFILE variable
@cladmi cladmi added Area: build system Area: Build system Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 27, 2018
@cladmi cladmi requested a review from aabadie March 27, 2018 14:21
export RESET = # dfu-util has no support for resetting the device

export OFLAGS = -O binary
HEXFILE = $(ELFFILE:.elf=.bin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the improvement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I see hello-world.elf, I expect it to be an elf executable.
When I see hello-world.hex, I expect it to bean ihex file, not a binary file.
Without this, for the boards I changed, you get a binary file called hello-world.hex.

The fix makes it generate a file named with .bin instead of .hex.

In master:

$ make  BOARD=bluepill PROGRAMMER=dfu-util
$ file bin/bluepill/hello-world.hex 
bin/bluepill/hello-world.hex: data

# which is different from an `ihex` file.
$ file bin/iotlab-m3/hello-world.hex
bin/iotlab-m3/hello-world.hex: ASCII text, with CRLF line terminators

Also, having the wrong format for the output is problematic for me, because in #8838 I plan to add the following rules which would break if you do the opposite.

%.hex: %elf
    $(Q)$(OBJCOPY) $(OFLAGS) -Oihex $< $@
 %.bin: %.elf
    $(Q)$(OBJCOPY) $(OFLAGS) -Obinary $< $@

For fixing it, I used what is done in other files in RIOT

git grep  'ELFFILE:.elf=.bin'
boards/cc2538dk/Makefile.include:export HEXFILE = $(ELFFILE:.elf=.bin)
boards/common/remote/Makefile.include:export HEXFILE = $(ELFFILE:.elf=.bin)
boards/mbed_lpc1768/Makefile.include:export HEXFILE = $(ELFFILE:.elf=.bin)
boards/nrf6310/Makefile.include:export HEXFILE = $(ELFFILE:.elf=.bin)
boards/opencm904/Makefile.include:export HEXFILE = $(ELFFILE:.elf=.bin)
boards/openmote-cc2538/Makefile.include:  export HEXFILE = $(ELFFILE:.elf=.bin)
makefiles/tools/bossa.inc.mk:export HEXFILE = $(ELFFILE:.elf=.bin)
makefiles/tools/edbg.inc.mk:HEXFILE = $(ELFFILE:.elf=.bin)
makefiles/tools/jlink.inc.mk:export HEXFILE = $(ELFFILE:.elf=.bin)

Using HEXFILE variable for the output of objcopy is bad if it is not an ihex file but its what is currently done in RIOT. Changing this is addressed in the global PR by introducing FLASHFILE and this line will be replaced by FLASHFILE = $(BINFILE).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks!

@kaspar030
Copy link
Contributor

Do we need to test flashing for all affected boards?

@kaspar030
Copy link
Contributor

Do we need to test flashing for all affected boards?

No.

@kaspar030 kaspar030 merged commit 1406050 into RIOT-OS:master Mar 28, 2018
@cladmi cladmi deleted the pr/make/variables_cleanup branch March 28, 2018 12:40
@cladmi cladmi added this to the Release 2018.04 milestone Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants