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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mbrossard
Copy link

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
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

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