-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openocd.sh: allow flashing binary files without configuration #9787
Conversation
dist/tools/openocd/openocd.sh
Outdated
# This allows flashing normal binary files without env configuration | ||
if _is_binfile ${IMAGE_FILE}; then | ||
# hardwritten to use the first bank | ||
FLASH_ADDR=$(_flash_address 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you call bank here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the term from openocd documentation: http://www.openocd.org/doc/html/Flash-Commands.html and here http://repo.or.cz/openocd.git/blob_plain/HEAD:/tcl/target/stm32f1x.cfg (flash bank
).
From what I understood, it is a contiguous area of ROM.
By setting a 1
here, I assume that, if the board has multiple memory banks, the first one is used.
I reviewed the code and it makes sense to me. However I want to test it... Would it be possible to add a |
To have a generic You can test with the examples in the PR description:
I am also thinking about adding a test for a two step flashing but would currently require specific handling for |
I've tested it successfully with your instructions, thanks! However, I find that it would be useful to warn while flashing that openocd is writing with an offset, something like The file name is also different from what is today on master. It gives the full path while flashbin gives only the relative path. Can we normalise this into showing the full path? |
It is because I gave a relative file in the command line. This gives the full path:
I did not added the RIOT/dist/tools/openocd/openocd.sh Lines 90 to 95 in 2d27b32
I only fixed that the 'verify' was not using the offset. What I did, is that now if you provide a binary file, I add the ROM_BASE_ADDR. |
That's what I meant with adding a new target
That was not my question, sorry for not being clear. What I mean that I'd like to know if the flash script is flashing using an offset printing in the script something like
I think by printing the direct flashing address this is included. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the changes I'm asking I think it's better to wait for FLASHFILE
so everything would fit better.
ACK.
@cladmi ok to merge? |
There is not conflicts so I would say yes. |
The test for a I could replace it by testing the extension and an env variable to force it. Any preference on this ? After patching it, I tested in
|
I cannot block my own PR… |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot block my own PR…
UnACK.
I added debug output for I changed the test to check the file extension and also use IMAGE_TYPE:
The |
@kYc0o for your |
0355c24
to
1f32986
Compare
I redid the periph_flashpage test and the binfile detection:
@kYc0o can you retry with mac ? |
Tested with success on a nucleo-l152re on OSX. Squash and re-ACK. |
Update to bash to have `local` variables and `=~` regex matching. Will be used in upcoming commits.
When flashing with an IMAGE_OFFSET, it should also be passed to verify_image. It is handling the base address in the image too. This works with both elf files and binaries with the base address added.
Returns 0 if it is true. The test is based on the file extension, but also use the IMAGE_TYPE variable to force setting to binary.
This allows getting the ROM base address. It may not be available in the build system directly so better extract it from openocd. Also openocd is board specific and this address is cpu specific so would have definition order issue in the build system.
Add the rom base address to the flash address when flashing binaries. This allows flashing binaries with the default openocd configuration. It is an API change to IMAGE_OFFSET with binary files as it should now only be an offset to the base address. Force openocd type to '.bin' in case we want to flash hex/elf objects or files not automatically recognized as bin.
7272d8f
to
bc7e53f
Compare
Rebased with fix included to print as %08x to be coherent with flash_addr. diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh
index 04faaaa67..a4c72dd38 100755
--- a/dist/tools/openocd/openocd.sh
+++ b/dist/tools/openocd/openocd.sh
@@ -204,7 +204,7 @@ do_flash() {
FLASH_ADDR=$(_flash_address 1)
echo "Binfile detected, adding ROM base address: ${FLASH_ADDR}"
IMAGE_TYPE=bin
- IMAGE_OFFSET=$(printf "0x%x\n" "$((${IMAGE_OFFSET} + ${FLASH_ADDR}))")
+ IMAGE_OFFSET=$(printf "0x%08x\n" "$((${IMAGE_OFFSET} + ${FLASH_ADDR}))")
fi
if [ "${IMAGE_OFFSET}" != "0" ]; then |
That's ok, just a beautifier. Go! |
Contribution description
This adds support for flashing binary files using openocd and not configuring anything.
When flashing binaries, openocd needs the absolute address for flashing.
There was already
IMAGE_OFFSET
but it required configuration for flashing by default for boards that do not start at 0x0, likeiotlab-m3
.The rom base address is now queried from
openocd
andIMAGE_OFFSET
is added to that.IMAGE_OFFSET
with binary files as it should now be an offset to the base addressedbg
behavior too, which as an--offset
variable that takes into account the base address.IMAGE_OFFSET
when it shouldflash list
to extract the first bank addressAPI change
This is an API change but would still consider it minor as it only affects openocd when flashing binary files and was also not working as
IMAGE_OFFSET
was not set for verify_image. So changing an API of something that did not work.Testing
I tested with
iotlab-m3
but using any board usingopenocd
should do. Even better if the board start address is not zero, and if it has with multiple rom banks.For easier eye debugging, openocd can be run with
sh -xc
instead ofsh -c
here:RIOT/dist/tools/openocd/openocd.sh
Line 163 in 31aba49
Flash an elf with offset
Flash a simple binary without configuration
Flash a binary with offset
Issues/PRs references
This is part of the OTA implementation required features in #9342