stlink
stlink copied to clipboard
[feature] reading and writing flash address with CLI
Hello, is there a way to read and write some flash addresses directly with the CLI without having to flash or read a whole binary file? I want to check few addresses on the flash and also overwrite few others, my application uses the binary directly (with CLI) as it is a javafx application. Thank you.
Please describe more precisely what you intend to do. What system and hardware do you use?
I use STLink V2-1, on STM32F1xx device in this case. What i want to do is to write and read few bytes at different addresses of the flash, without having to read the whole firmware and write it back. The purpose of this is to update some data in place, without having to read or write the whole thing.
Is there anybody who is able to contribute on this issue?
Some facts may need a stress.
- The internal flash is erased once a page(page size ranging from 1KB to at least 4KB). Any non-0xff bytes cannot be rewritten reliably. For F1XX, if I got it right, even 0xff bytes cannot be rewritten without an erase. That is, writing some random bytes causes the whole page to be erased.
- Considering this feature, a partial update may not reduce erase cycles without intentionally design that places all variable data inside a limited number of pages.
- For an intentional design, manually specifying the start address and using a partial binary file is as effective as stlink on erase cycles and would reduce a read cycle that is a must if the diff process is done by stlink.
What is the current state of this?
hello, Regarding this issue i did us a workaround, a base firmware is stored in the application, some chunks are copied and patched when the target is programmed, st-flash is then used to flash these small chunks on the target. This is not as elegant as it could be but it is fast since the chunks are small and there is no need to read the entire firmware from each target, so for this specific use case it is fine.
@Hoel This could be helpful indeed. Can you submit a PR so we can have a look at the implementation?
I think this could be very useful, at least on ST's command line tool for Windows I'm using this for a couple of years now. Example using this feature:
C:\> ST-LINK_CLI.EXE -c UR SWD freq=4000 -w32 0x080FF800 0x131D3FFC
For st-flash it could look as following:
$ st-flash write <variable-type> <variable> <address>
Example:
$ st-flash write -w32 0x131D3FFC 0x080FF800
Edit: to partially solve this problem, on linux I crafted a small binary file by hand and flashed that. Example:
$ echo -n $'\x5E' > secrets.bin
$ echo -n $'\x6F' >> secrets.bin
$ echo -n $'\xB8' >> secrets.bin
$ echo -n $'\x13' >> secrets.bin
$ st-flash write secrets.bin 0x080FF800
note: that you can't flash '0' value bytes this way
@geoffrey-vl Can you contribute on this topic regarding an implementation?
To be honest I have a couple of other project I'm also working on, so don't count on it. But for starters I'd like to discuss how the command would look like. Can it be as described in https://github.com/stlink-org/stlink/issues/875#issuecomment-808199643 ?
I'd consider this a useful feature. Who can help out on this topic? Does anybody have an idea how to implement this?
Closing this feature request due to inactivity.