rp-rs / rp-hal

A Rust Embedded-HAL for the rp series microcontrollers
https://crates.io/crates/rp2040-hal
Apache License 2.0
1.44k stars 234 forks source link

rp-binary-info is not compatible with picotool for rp2350 #853

Closed romainreignier closed 1 month ago

romainreignier commented 1 month ago

With the latest version (2.0.0) of picotool, picotool info works with rp2040 binaries but not with rp2350.

$ picotool version
picotool v2.0.0 (Linux, GNU-11.4.0, Release)

Steps to reproduce

$ git clone https://github.com/rp-rs/rp-hal.git
$ cd rp2040-hal-examples
$ cargo build --bin binary_info_demo
$ picotool info -a -t elf target/thumbv6m-none-eabi/debug/binary_info_demo
File target/thumbv6m-none-eabi/debug/binary_info_demo:

Program Information
 name:          rp2040-hal Binary Info Example
 version:       0.1.0
 web site:      https://github.com/rp-rs/rp-hal
 description:   A GPIO blinky with extra metadata.
 binary start:  0x10000000

Fixed Pin Information
 none

Build Information
 pico_board:        pico
 build attributes:  debug

So it works with RP2040.

But doing the same RP2350 provides no info:

$ cd rp235x-hal-examples
$ cargo build --bin binary_info_demo
$ picotool info -a -t elf target/thumbv8m.main-none-eabihf/debug/binary_info_demo
File target/thumbv8m.main-none-eabihf/debug/binary_info_demo:

Program Information
 none

Fixed Pin Information
 none

Build Information
 none
jonathanpallant commented 1 month ago

That .... is unexpected (I wrote the support and the demos). I'll look into it.

jonathanpallant commented 1 month ago

Can you attach your two elf files, or can you run llvm-objdump -t | rustfilt | sort on them?

romainreignier commented 1 month ago

Sure.

Objdump results: rp2040.txt rp2350.txt

Elf files with a .txt extension to allow upload on Github: rp2040_binary_info_demo_bin.txt rp2350_binary_info_demo_bin.txt

jonathanpallant commented 1 month ago

RP2020:

100001c0 g     O .boot_info 00000014 rp_binary_info::PICOTOOL_HEADER
100085a4 l     O .bi_entries    0000001c binary_info_demo::PICOTOOL_ENTRIES
100089b8 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
100089cc l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
100089fc l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10008a48 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10008a5c l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10008a70 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10008a7c l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
100094c8 g     O .rodata    00000018 rp_binary_info::MAPPING_TABLE

RP2350:

10008ba4 l     O .bi_entries    0000001c binary_info_demo::PICOTOOL_ENTRIES
10009084 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10009098 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
100090c8 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10009114 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10009128 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
1000913c l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY
10009148 l     O .rodata    0000000c binary_info_demo::PICOTOOL_ENTRIES::ENTRY

Oops.

The .boot_info input section is missing from the RP2350 example linker script. It should be packed into the .start_block output section.

romainreignier commented 1 month ago

Indeed, it now works as expected:

$ cargo build --bin binary_info_demo
$ picotool info -a -t elf target/thumbv8m.main-none-eabihf/debug/binary_info_demo
File target/thumbv8m.main-none-eabihf/debug/binary_info_demo:

Program Information
 name:          binary_info_demo
 version:       0.1.0
 web site:      https://github.com/rp-rs/rp-hal
 description:   A GPIO blinky with extra metadata.
 binary start:  0x10000000
 target chip:   RP2350
 image type:    ARM Secure

Fixed Pin Information
 none

Build Information
 pico_board:        pico2
 build attributes:  debug