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

Fix: special elf program header with zero p_filesz #78

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

andelf
Copy link
Contributor

@andelf andelf commented Nov 15, 2024

Fix #77

This might also affect probe-rs.

The original defect is that the object crate returns an Error accessing data when p_filesz of a ProgramHeader is zero. (I belive it should return an empty slice).

In case #77: the second ProgramHeader's p_filesz is zero.

firmware.elf:     file format elf32-littleriscv

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .init         00000004  00000000  00000000  00001000  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .vector       00000004  00000004  00000004  00001004  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .text         000001e4  00000008  00000008  00001008  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .fini         00000000  000001ec  000001ec  000011ec  2**0
                  CONTENTS, ALLOC, LOAD, CODE

=> The above sections belong to the first ProgramHeader.
  p_vaddr: U32(0), p_paddr: U32(0), p_filesz: U32(1ec), p_memsz: U32(1ec)
=> The following sections belong to the second ProgramHeader.
  p_vaddr: U32(20000000), p_paddr: U32(1ec), p_filesz: U32(0), p_memsz: U32(4)

  4 .dalign       00000000  20000000  20000000  000011ec  2**0
                  CONTENTS
  5 .dlalign      00000000  000001ec  000001ec  000011ec  2**0
                  CONTENTS
  6 .data         00000000  20000000  20000000  000011ec  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  7 .bss          00000004  20000000  000001ec  00002000  2**2
                  ALLOC
  8 .comment      00000033  00000000  00000000  000011ec  2**0
                  CONTENTS, READONLY

CC @maxgerhardt

@andelf
Copy link
Contributor Author

andelf commented Nov 15, 2024

@maxgerhardt Once you confirm the fix works, I'll proceed with a new release.

@maxgerhardt
Copy link

maxgerhardt commented Nov 15, 2024

Confirmed, with the latest version from this CI I get this

C:\Users\Max>"C:\Users\Max\Downloads\wlink-win-x86(1)\wlink.exe" flash C:\Users\Max\Downloads\blink\firmware.elf
08:37:35 [INFO] Connected to WCH-Link v2.14(v34) (WCH-LinkE-CH32V305)
08:37:35 [INFO] Attached chip: CH32X035 [CH32X035F8U6] (ChipID: 0x035e0601)
08:37:35 [INFO] Chip ESIG: FlashSize(62KB) UID(cd-ab-28-c5-49-bc-3e-2d)
08:37:35 [INFO] Flash protected: false
08:37:35 [INFO] Read C:\Users\Max\Downloads\blink\firmware.elf as ELF format
08:37:35 [INFO] Flashing 492 bytes to 0x08000000
08:37:35 [INFO] Read protected: false
████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 492/492
08:37:35 [INFO] Flash done
08:37:35 [INFO] Now reset...

@andelf andelf merged commit 8db1544 into main Nov 15, 2024
12 checks passed
@andelf andelf deleted the fix/special-elf-program-header-with-zero-p_filesz branch November 15, 2024 12:20
@andelf
Copy link
Contributor Author

andelf commented Nov 16, 2024

Released as v0.1.1.

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.

Error: Failed to access data for an ELF segment
2 participants