pyocd / pyocd/pyOCD

Generating Flash Algorithm script has an unnecessary restriction

Open
#1,459 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
560
Avg merge
1h 41m
Merged PRs (30d)
3

Description

When generating a flash algo blob using the generate_flash_algo.py I hit upon an unnecessary restriction in the generator. The FLM I've flying around has the PrgCode section not starting at address 0 but instead has the following layout

$arm-none-eabi-readelf -S flash_algo.FLM
There are 17 section headers, starting at offset 0x300d9c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] PrgCode           PROGBITS        0000c000 000034 003f54 00  AX  0   0  4
  [ 2] PrgData           PROGBITS        0000ff54 003f88 000244 00  WA  0   0  4
  [ 3] PrgData           NOBITS          00010198 0041cc 000004 00  WA  0   0  4
  [ 4] DevDscr           PROGBITS        00010198 0041cc 0010a0 00   A  0   0  4
  [ 5] .debug_abbrev     PROGBITS        00000000 00526c 0005c4 00      0   0  1
  [ 6] .debug_frame      PROGBITS        00000000 005830 00115c 00      0   0  1
  [ 7] .debug_info       PROGBITS        00000000 00698c 0318bc 00      0   0  1
  [ 8] .debug_line       PROGBITS        00000000 038248 002fc8 00      0   0  1
  [ 9] .debug_loc        PROGBITS        00000000 03b210 0021c0 00      0   0  1
  [10] .debug_macinfo    PROGBITS        00000000 03d3d0 2bbe58 00      0   0  1
  [11] .debug_pubnames   PROGBITS        00000000 2f9228 000a7f 00      0   0  1
  [12] .symtab           SYMTAB          00000000 2f9ca8 001df0 10     13 286  4
  [13] .strtab           STRTAB          00000000 2fba98 00182c 00      0   0  1
  [14] .note             NOTE            00000000 2fd2c4 000020 00      0   0  4
  [15] .comment          PROGBITS        00000000 2fd2e4 0039d8 00      0   0  1
  [16] .shstrtab         STRTAB          00000000 300cbc 0000a0 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)

But this isn't compatible with the checks done in the following as the script threw a RO section does not start at address 0 error.
https://github.com/pyocd/pyOCD/blob/30427690c0f986689eed87b9102cf4a6a6950e5e/pyocd/target/pack/flash_algo.py#L274-L289

Removing the RO starts a 0 check there and adding a constant offset of 0x0000c000 here (and offsetting load_address) gave me a working flash algorithm
https://github.com/pyocd/pyOCD/blob/30427690c0f986689eed87b9102cf4a6a6950e5e/pyocd/target/pack/flash_algo.py#L297

I'm not fully fluent how FLM files are generated or how they should look like, but this feels like an unnecessary requirement to me that if removed would make the script more versatile.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with generate_flash_algo.py and the checks in pyocd/target/pack/flash_algo.py around the linked lines. Compare the current section and load-address assumptions with the supplied readelf output, then verify the generated blob using an FLM whose PrgCode starts at 0x0000c000. Done means valid nonzero-origin PrgCode layouts are accepted without breaking existing flash algorithms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.