Skip to content
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

Upload: NUVOTON: Change GDB load command to flash post-build processed image #341

Conversation

ccli8
Copy link

@ccli8 ccli8 commented Sep 9, 2024

Summary of changes

This PR includes two parts:

  1. Give chance to adjust GDB commands MBED_UPLOAD_LAUNCH_COMMANDS or MBED_UPLOAD_RESTART_COMMANDS for debug launch by implementing mbed_adjust_upload_debug_commands cmake function.
  2. Based on above, for Nuvoton targets, adjust gdb load command to flash post-build processed image

Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

@multiplemonomials
Copy link
Collaborator

Hmm... This is a really good catch, but it feels like this issue isn't actually specific to nuvoton devices at all. Maybe we should just change the load command to always use the hex file, and make the build system always generate the hex file. I will think about it.

@multiplemonomials
Copy link
Collaborator

I have now added #369 which introduces a new option for the upload address. That would probably be useful in this PR!

To clarify, I'd like to accept this, but I'd need it to be updated to (a) always build the bin and hex file, and (b) always make the GDB load command use the hex file.

@ccli8
Copy link
Author

ccli8 commented Oct 4, 2024

I will update to support above requirements.

Besides, one thing to clarify: #369 introduces upload address MBED_UPLOAD_BASE_ADDR. As I know, this will make sense to just *.bin file. *.hex file already encodes base address in it and needn't MBED_UPLOAD_BASE_ADDR?

@multiplemonomials
Copy link
Collaborator

Yeah, that's a fair point. Frankly I'm a bit confused, as every upload method except J-Link does let you specify an address with a hex file, so I wonder what offset they actually use

For pyocd debug, it appears the device under debug must be halted after
UPLOAD_LAUNCH_COMMANDS, or debugger will become abnormal.
This converts output to Intel HEX format unconditionally but to BIN
format just on demand for the following reasons:
1. Most flash programming tools support Intel HEX format, e.g. GDB
   load command.
2. Output can have large holes in addresses which BIN format cannot
   handle and can generate very large file.
This gives chance to adjust GDB commands MBED_UPLOAD_LAUNCH_COMMANDS
or MBED_UPLOAD_RESTART_COMMANDS for debug launch by implementing
mbed_adjust_upload_debug_commands cmake function.
With this adjustment, GDB load command changes to "load <app>.hex" from
just "load":
1. "Load" will load <app>.elf and is inappropriate for targets like
   bootloader or TF-M enabled which need to post-build process images.
2. "load <app>.bin" is not considered because GDB load command doesn't
   support binary format.
@ccli8 ccli8 force-pushed the nvt_upload_adjust_gdb_load_for_post_build branch from 1c60c4e to 176ebe6 Compare October 7, 2024 06:03
@ccli8
Copy link
Author

ccli8 commented Oct 7, 2024

Update as follows:

  1. Always generate hex file but generate bin file only on demand. This is because output image can have large holes in addresses and the converted bin file can become very large.
  2. Change GDB load command to load <app>.hex from just load. This change applies to all upload methods and all Mbed targets, not just specific to Nuvoton.

Copy link
Collaborator

@multiplemonomials multiplemonomials left a comment

Choose a reason for hiding this comment

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

Looks good, just need to resolve the issue with command line GDB usage, then will approve!

tools/cmake/mbed_target_functions.cmake Show resolved Hide resolved
This enables generating GDB command line gdbinit file for single project
multiple application scenario. The gdbinit file name would be <app>.gdbinit
for distinct among multiple applications.
@ccli8 ccli8 force-pushed the nvt_upload_adjust_gdb_load_for_post_build branch from 61e8b9d to 5d31030 Compare October 14, 2024 02:15
@multiplemonomials
Copy link
Collaborator

Looks good! Thanks for your work on this!

@multiplemonomials multiplemonomials merged commit 7d99fd1 into mbed-ce:master Oct 15, 2024
52 checks passed
@ccli8 ccli8 deleted the nvt_upload_adjust_gdb_load_for_post_build branch October 16, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants