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

Add feature to include FlashDevice device description #14

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

mbrossard
Copy link
Contributor

The scripts from FlashAlgo rely on the FlashDevice struct (see https://www.keil.com/pack/doc/CMSIS/Pack/html/flashAlgorithm.html) and the existence of a PrgData section.

@thejpster
Copy link
Member

Does #19 work for your use case?

@mbrossard
Copy link
Contributor Author

I found a few issues in your branch:

  • rust-toolchain should be renamed rust-toolchain.toml
  • link.x copies partially memory.x from flash-algorithm but is missing PrgData and DeviceData sections. https://github.com/probe-rs/flash-algorithm-template/blob/master/link.x suggests it should only contain ALGO_PLACEMENT_START_ADDRESS, and .cargo/config should add "-C", "link-arg=-Tmemory.x", to rustflags.
  • It would probably make sense to add --remove-section DeviceData for the rust-objcopy call in build.sh.

There are a couple of issues with flash-algorithm (pinging @Yatekii):

  • The comment about dev_type is wrong, 5 is external SPI and 1 is onboard flash (see https://github.com/pyocd/FlashAlgo/blob/main/source/FlashOS.h#L35).
  • A few remaining fields in FlashDevice are hard-coded that should be customizable (dev_type and dev_name, but also possibly program_time_out and erase_time_out). vers should probably be bumped to 1.
  • In memory.x, the data, sdata, and bss sections are duplicated and should be removed from PrgCode.

There is one quirky bit in the scripts that expect the PrgData to be marked RW, so I needed to a dummy global variable. I don't know if there is another way to force the section to be read-write.

Running arm-none-eabi-objdump -h target/thumbv6m-none-eabi/release/flash-algo without the dummy variable yields:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 PrgCode       000001c4  00000000  00000000  000000b4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 PrgData       00000018  000001c4  000001c4  00000278  2**2
                  ALLOC
  2 DeviceData    000000b0  000001dc  000001dc  00000278  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

And with the dummy variable:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 PrgCode       000001c4  00000000  00000000  000000b4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 PrgData       0000001c  000001c4  000001c4  00000278  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 DeviceData    000000b0  000001e0  000001e0  00000294  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

You can also reproduce with:

$ git clone https://github.com/pyocd/FlashAlgo.git
$ cd FlashAlgo
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python scripts/generate_blobs.py ~/git/flash-algo/target/thumbv6m-none-eabi/release/flash-algo

@mbrossard
Copy link
Contributor Author

@theanh2020: I have looked at rebasing this PR. Some of this have been pulled into flash-algorithm but not in a released version. I will ask them when a release will happen.

@Yatekii
Copy link

Yatekii commented Dec 10, 2024

I just released flash-algorithm :)

@mbrossard
Copy link
Contributor Author

Tested with target-gen, pyOCD's generate_blobs.py and DAPLink's generate_flash_algo.py.

@9names
Copy link
Member

9names commented Dec 20, 2024

@mbrossard it would make more sense to ask for a review from someone with authority to merge, that particular github account has not contributed to this project (or any other project) and looks like a bot to me.

@mbrossard
Copy link
Contributor Author

That account somehow approved a previous version. So I thought the polite thing was to re-request a review.

Copy link
Member

@9names 9names left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for following up on this PR

@9names 9names merged commit 65a59f9 into rp-rs:main Dec 20, 2024
1 check passed
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.

5 participants