Crate rp_binary_info

source ·
Expand description

Code and types for creating Picotool compatible “Binary Info” metadata

§Example usage

Enable the Cargo feature binary-info.

Add this to your linker script (usually named memory.x):

SECTIONS {
    /* ### Boot ROM info
     *
     * Goes after .vector_table, to keep it in the first 512 bytes of flash,
     * where picotool can find it
     */
    .boot_info : ALIGN(4)
    {
        KEEP(*(.boot_info));
    } > FLASH

} INSERT AFTER .vector_table;

/* move .text to start /after/ the boot info */
_stext = ADDR(.boot_info) + SIZEOF(.boot_info);

SECTIONS {
    /* ### Picotool 'Binary Info' Entries
     *
     * Picotool looks through this block (as we have pointers to it in our
     * header) to find interesting information.
     */
    .bi_entries : ALIGN(4)
    {
        /* We put this in the header */
        __bi_entries_start = .;
        /* Here are the entries */
        KEEP(*(.bi_entries));
        /* Keep this block a nice round size */
        . = ALIGN(4);
        /* We put this in the header */
        __bi_entries_end = .;
    } > FLASH
} INSERT AFTER .text;

Then, add this to your Rust code:

#[link_section = ".bi_entries"]
#[used]
pub static PICOTOOL_ENTRIES: [rp_binary_info::EntryAddr; 3] = [
    rp_binary_info::rp_program_name!(c"Program Name Here"),
    rp_binary_info::rp_cargo_version!(),
    rp_binary_info::int!(
        rp_binary_info::make_tag(b"JP"),
        0x0000_0001,
        0x12345678
    ),
];

§Cargo features

The binary-info Cargo feature enables emitting the main PICOTOOL_HEADER static, which is what Picotool looks for to discover the binary info.

It is optional to allow you to emit the static yourself differently, for e.g. compatibility with different linker scripts, while still allowing using the rest of the utilities in the crate to format the info.

Modules§

  • Constants for binary info

Macros§

Structs§

  • This is a reference to an entry. It’s like a &dyn ref to some type T: Entry, except that the run-time type information is encoded into the Entry itself in very specific way.
  • This is the ‘Binary Info’ header block that picotool looks for in your UF2 file/ELF file/Pico in Bootloader Mode to give you useful metadata about your program.
  • An entry which contains both an ID (e.g. ID_RP_BINARY_END) and an integer.
  • Allows us to tell picotool where values are in the UF2 given their run-time address.
  • An entry which contains both an ID (e.g. ID_RP_PROGRAM_NAME) and a pointer to a null-terminated string.

Enums§

  • This is the set of data types that picotool supports.

Statics§

  • This tells picotool how to convert RAM addresses back into Flash addresses

Functions§