diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-08-17 21:56:14 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-08-17 22:12:39 +0200 |
| commit | eab3a57263d52eed517ee0fb9ccb307196664ee6 (patch) | |
| tree | c0d9653f01d0f167d04a4e368023cb68665cbdb2 /embassy-rp/src | |
| parent | e30a888823ca96e4f9a2cbf82a0db6a5617228d6 (diff) | |
rp: use the rp-binary-info crate for binary info.
Diffstat (limited to 'embassy-rp/src')
| -rw-r--r-- | embassy-rp/src/binary_info/consts.rs | 34 | ||||
| -rw-r--r-- | embassy-rp/src/binary_info/macros.rs | 171 | ||||
| -rw-r--r-- | embassy-rp/src/binary_info/mod.rs | 175 | ||||
| -rw-r--r-- | embassy-rp/src/binary_info/types.rs | 195 | ||||
| -rw-r--r-- | embassy-rp/src/lib.rs | 5 |
5 files changed, 3 insertions, 577 deletions
diff --git a/embassy-rp/src/binary_info/consts.rs b/embassy-rp/src/binary_info/consts.rs deleted file mode 100644 index d5fcd0d75..000000000 --- a/embassy-rp/src/binary_info/consts.rs +++ /dev/null | |||
| @@ -1,34 +0,0 @@ | |||
| 1 | //! Constants for binary info | ||
| 2 | |||
| 3 | // Credit: Taken from https://github.com/thejpster/rp-hal-rp2350-public (also licensed Apache 2.0 + MIT). | ||
| 4 | // Copyright (c) rp-rs organization | ||
| 5 | |||
| 6 | /// All Raspberry Pi specified IDs have this tag. | ||
| 7 | /// | ||
| 8 | /// You can create your own for custom fields. | ||
| 9 | pub const TAG_RASPBERRY_PI: u16 = super::make_tag(b"RP"); | ||
| 10 | |||
| 11 | /// Used to note the program name - use with StringEntry | ||
| 12 | pub const ID_RP_PROGRAM_NAME: u32 = 0x02031c86; | ||
| 13 | /// Used to note the program version - use with StringEntry | ||
| 14 | pub const ID_RP_PROGRAM_VERSION_STRING: u32 = 0x11a9bc3a; | ||
| 15 | /// Used to note the program build date - use with StringEntry | ||
| 16 | pub const ID_RP_PROGRAM_BUILD_DATE_STRING: u32 = 0x9da22254; | ||
| 17 | /// Used to note the size of the binary - use with IntegerEntry | ||
| 18 | pub const ID_RP_BINARY_END: u32 = 0x68f465de; | ||
| 19 | /// Used to note a URL for the program - use with StringEntry | ||
| 20 | pub const ID_RP_PROGRAM_URL: u32 = 0x1856239a; | ||
| 21 | /// Used to note a description of the program - use with StringEntry | ||
| 22 | pub const ID_RP_PROGRAM_DESCRIPTION: u32 = 0xb6a07c19; | ||
| 23 | /// Used to note some feature of the program - use with StringEntry | ||
| 24 | pub const ID_RP_PROGRAM_FEATURE: u32 = 0xa1f4b453; | ||
| 25 | /// Used to note some whether this was a Debug or Release build - use with StringEntry | ||
| 26 | pub const ID_RP_PROGRAM_BUILD_ATTRIBUTE: u32 = 0x4275f0d3; | ||
| 27 | /// Used to note the Pico SDK version used - use with StringEntry | ||
| 28 | pub const ID_RP_SDK_VERSION: u32 = 0x5360b3ab; | ||
| 29 | /// Used to note which board this program targets - use with StringEntry | ||
| 30 | pub const ID_RP_PICO_BOARD: u32 = 0xb63cffbb; | ||
| 31 | /// Used to note which `boot2` image this program uses - use with StringEntry | ||
| 32 | pub const ID_RP_BOOT2_NAME: u32 = 0x7f8882e1; | ||
| 33 | |||
| 34 | // End of file | ||
diff --git a/embassy-rp/src/binary_info/macros.rs b/embassy-rp/src/binary_info/macros.rs deleted file mode 100644 index faf6148c8..000000000 --- a/embassy-rp/src/binary_info/macros.rs +++ /dev/null | |||
| @@ -1,171 +0,0 @@ | |||
| 1 | //! Handy macros for making Binary Info entries | ||
| 2 | |||
| 3 | // Credit: Taken from https://github.com/thejpster/rp-hal-rp2350-public (also licensed Apache 2.0 + MIT). | ||
| 4 | // Copyright (c) rp-rs organization | ||
| 5 | |||
| 6 | /// Generate a static item containing the given environment variable, | ||
| 7 | /// and return its [`EntryAddr`](super::EntryAddr). | ||
| 8 | #[macro_export] | ||
| 9 | macro_rules! binary_info_env { | ||
| 10 | ($tag:expr, $id:expr, $env_var_name:expr) => { | ||
| 11 | $crate::binary_info_str!($tag, $id, { | ||
| 12 | let value = concat!(env!($env_var_name), "\0"); | ||
| 13 | // # Safety | ||
| 14 | // | ||
| 15 | // We used `concat!` to null-terminate on the line above. | ||
| 16 | let value_cstr = unsafe { core::ffi::CStr::from_bytes_with_nul_unchecked(value.as_bytes()) }; | ||
| 17 | value_cstr | ||
| 18 | }) | ||
| 19 | }; | ||
| 20 | } | ||
| 21 | |||
| 22 | /// Generate a static item containing the given string, and return its | ||
| 23 | /// [`EntryAddr`](super::EntryAddr). | ||
| 24 | /// | ||
| 25 | /// You must pass a numeric tag, a numeric ID, and `&CStr` (which is always | ||
| 26 | /// null-terminated). | ||
| 27 | #[macro_export] | ||
| 28 | macro_rules! binary_info_str { | ||
| 29 | ($tag:expr, $id:expr, $str:expr) => {{ | ||
| 30 | static ENTRY: $crate::binary_info::StringEntry = $crate::binary_info::StringEntry::new($tag, $id, $str); | ||
| 31 | ENTRY.addr() | ||
| 32 | }}; | ||
| 33 | } | ||
| 34 | |||
| 35 | /// Generate a static item containing the given string, and return its | ||
| 36 | /// [`EntryAddr`](super::EntryAddr). | ||
| 37 | /// | ||
| 38 | /// You must pass a numeric tag, a numeric ID, and `&CStr` (which is always | ||
| 39 | /// null-terminated). | ||
| 40 | #[macro_export] | ||
| 41 | macro_rules! binary_info_int { | ||
| 42 | ($tag:expr, $id:expr, $int:expr) => {{ | ||
| 43 | static ENTRY: $crate::binary_info::IntegerEntry = $crate::binary_info::IntegerEntry::new($tag, $id, $int); | ||
| 44 | ENTRY.addr() | ||
| 45 | }}; | ||
| 46 | } | ||
| 47 | |||
| 48 | /// Generate a static item containing the program name, and return its | ||
| 49 | /// [`EntryAddr`](super::EntryAddr). | ||
| 50 | #[macro_export] | ||
| 51 | macro_rules! binary_info_rp_program_name { | ||
| 52 | ($name:expr) => { | ||
| 53 | $crate::binary_info_str!( | ||
| 54 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 55 | $crate::binary_info::consts::ID_RP_PROGRAM_NAME, | ||
| 56 | $name | ||
| 57 | ) | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | |||
| 61 | /// Generate a static item containing the `CARGO_BIN_NAME` as the program name, | ||
| 62 | /// and return its [`EntryAddr`](super::EntryAddr). | ||
| 63 | #[macro_export] | ||
| 64 | macro_rules! binary_info_rp_cargo_bin_name { | ||
| 65 | () => { | ||
| 66 | $crate::binary_info_env!( | ||
| 67 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 68 | $crate::binary_info::consts::ID_RP_PROGRAM_NAME, | ||
| 69 | "CARGO_BIN_NAME" | ||
| 70 | ) | ||
| 71 | }; | ||
| 72 | } | ||
| 73 | |||
| 74 | /// Generate a static item containing the program version, and return its | ||
| 75 | /// [`EntryAddr`](super::EntryAddr). | ||
| 76 | #[macro_export] | ||
| 77 | macro_rules! binary_info_rp_program_version { | ||
| 78 | ($version:expr) => {{ | ||
| 79 | $crate::binary_info_str!( | ||
| 80 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 81 | $crate::binary_info::consts::ID_RP_PROGRAM_VERSION, | ||
| 82 | $version | ||
| 83 | ) | ||
| 84 | }}; | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Generate a static item containing the `CARGO_PKG_VERSION` as the program | ||
| 88 | /// version, and return its [`EntryAddr`](super::EntryAddr). | ||
| 89 | #[macro_export] | ||
| 90 | macro_rules! binary_info_rp_cargo_version { | ||
| 91 | () => { | ||
| 92 | $crate::binary_info_env!( | ||
| 93 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 94 | $crate::binary_info::consts::ID_RP_PROGRAM_VERSION_STRING, | ||
| 95 | "CARGO_PKG_VERSION" | ||
| 96 | ) | ||
| 97 | }; | ||
| 98 | } | ||
| 99 | |||
| 100 | /// Generate a static item containing the program URL, and return its | ||
| 101 | /// [`EntryAddr`](super::EntryAddr). | ||
| 102 | #[macro_export] | ||
| 103 | macro_rules! binary_info_rp_program_url { | ||
| 104 | ($url:expr) => { | ||
| 105 | $crate::binary_info_str!( | ||
| 106 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 107 | $crate::binary_info::consts::ID_RP_PROGRAM_URL, | ||
| 108 | $url | ||
| 109 | ) | ||
| 110 | }; | ||
| 111 | } | ||
| 112 | |||
| 113 | /// Generate a static item containing the `CARGO_PKG_HOMEPAGE` as the program URL, | ||
| 114 | /// and return its [`EntryAddr`](super::EntryAddr). | ||
| 115 | #[macro_export] | ||
| 116 | macro_rules! binary_info_rp_cargo_homepage_url { | ||
| 117 | () => { | ||
| 118 | $crate::binary_info_env!( | ||
| 119 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 120 | $crate::binary_info::consts::ID_RP_PROGRAM_URL, | ||
| 121 | "CARGO_PKG_HOMEPAGE" | ||
| 122 | ) | ||
| 123 | }; | ||
| 124 | } | ||
| 125 | |||
| 126 | /// Generate a static item containing the program description, and return its | ||
| 127 | /// [`EntryAddr`](super::EntryAddr). | ||
| 128 | #[macro_export] | ||
| 129 | macro_rules! binary_info_rp_program_description { | ||
| 130 | ($description:expr) => { | ||
| 131 | $crate::binary_info_str!( | ||
| 132 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 133 | $crate::binary_info::consts::ID_RP_PROGRAM_DESCRIPTION, | ||
| 134 | $description | ||
| 135 | ) | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | /// Generate a static item containing whether this is a debug or a release | ||
| 140 | /// build, and return its [`EntryAddr`](super::EntryAddr). | ||
| 141 | #[macro_export] | ||
| 142 | macro_rules! binary_info_rp_program_build_attribute { | ||
| 143 | () => { | ||
| 144 | $crate::binary_info_str!( | ||
| 145 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 146 | $crate::binary_info::consts::ID_RP_PROGRAM_BUILD_ATTRIBUTE, | ||
| 147 | { | ||
| 148 | if cfg!(debug_assertions) { | ||
| 149 | c"debug" | ||
| 150 | } else { | ||
| 151 | c"release" | ||
| 152 | } | ||
| 153 | } | ||
| 154 | ) | ||
| 155 | }; | ||
| 156 | } | ||
| 157 | |||
| 158 | /// Generate a static item containing the specific board this program runs on, | ||
| 159 | /// and return its [`EntryAddr`](super::EntryAddr). | ||
| 160 | #[macro_export] | ||
| 161 | macro_rules! binary_info_rp_pico_board { | ||
| 162 | ($board:expr) => { | ||
| 163 | $crate::binary_info_str!( | ||
| 164 | $crate::binary_info::consts::TAG_RASPBERRY_PI, | ||
| 165 | $crate::binary_info::consts::ID_RP_PICO_BOARD, | ||
| 166 | $board | ||
| 167 | ) | ||
| 168 | }; | ||
| 169 | } | ||
| 170 | |||
| 171 | // End of file | ||
diff --git a/embassy-rp/src/binary_info/mod.rs b/embassy-rp/src/binary_info/mod.rs deleted file mode 100644 index ea475086b..000000000 --- a/embassy-rp/src/binary_info/mod.rs +++ /dev/null | |||
| @@ -1,175 +0,0 @@ | |||
| 1 | //! Code and types for creating Picotool compatible "Binary Info" metadata | ||
| 2 | //! | ||
| 3 | //! Add something like this to your program, and compile with the "binary-info" | ||
| 4 | //! and "rt" features: | ||
| 5 | //! | ||
| 6 | //! ``` | ||
| 7 | //! #[link_section = ".bi_entries"] | ||
| 8 | //! #[used] | ||
| 9 | //! pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 3] = [ | ||
| 10 | //! embassy_rp::binary_info_rp_program_name!(c"Program Name Here"), | ||
| 11 | //! embassy_rp::binary_info_rp_cargo_version!(), | ||
| 12 | //! embassy_rp::binary_info_int!(embassy_rp::binary_info::make_tag(b"JP"), 0x0000_0001, 0x12345678), | ||
| 13 | //! ]; | ||
| 14 | //! ``` | ||
| 15 | |||
| 16 | // Credit: Taken from https://github.com/thejpster/rp-hal-rp2350-public (also licensed Apache 2.0 + MIT). | ||
| 17 | // Copyright (c) rp-rs organization | ||
| 18 | |||
| 19 | pub mod consts; | ||
| 20 | |||
| 21 | mod types; | ||
| 22 | pub use types::*; | ||
| 23 | |||
| 24 | #[macro_use] | ||
| 25 | mod macros; | ||
| 26 | |||
| 27 | extern "C" { | ||
| 28 | /// The linker script sets this symbol to have the address of the first | ||
| 29 | /// entry in the `.bi_entries` section. | ||
| 30 | static __bi_entries_start: EntryAddr; | ||
| 31 | /// The linker script sets this symbol to have the address just past the | ||
| 32 | /// last entry in the `.bi_entries` section. | ||
| 33 | static __bi_entries_end: EntryAddr; | ||
| 34 | /// The linker script sets this symbol to have the address of the first | ||
| 35 | /// entry in the `.data` section. | ||
| 36 | static __sdata: u32; | ||
| 37 | /// The linker script sets this symbol to have the address just past the | ||
| 38 | /// first entry in the `.data` section. | ||
| 39 | static __edata: u32; | ||
| 40 | /// The linker script sets this symbol to have the address of the | ||
| 41 | /// initialisation data for the first entry in the `.data` section (i.e. a | ||
| 42 | /// flash address, not a RAM address). | ||
| 43 | static __sidata: u32; | ||
| 44 | } | ||
| 45 | |||
| 46 | /// Picotool can find this block in our ELF file and report interesting | ||
| 47 | /// metadata. | ||
| 48 | /// | ||
| 49 | /// The data here tells picotool the start and end flash addresses of our | ||
| 50 | /// metadata. | ||
| 51 | #[cfg(feature = "binary-info")] | ||
| 52 | #[link_section = ".start_block"] | ||
| 53 | #[used] | ||
| 54 | pub static PICOTOOL_HEADER: Header = unsafe { | ||
| 55 | Header::new( | ||
| 56 | core::ptr::addr_of!(__bi_entries_start), | ||
| 57 | core::ptr::addr_of!(__bi_entries_end), | ||
| 58 | &MAPPING_TABLE, | ||
| 59 | ) | ||
| 60 | }; | ||
| 61 | |||
| 62 | /// This tells picotool how to convert RAM addresses back into Flash addresses | ||
| 63 | #[cfg(feature = "binary-info")] | ||
| 64 | pub static MAPPING_TABLE: [MappingTableEntry; 2] = [ | ||
| 65 | // This is the entry for .data | ||
| 66 | MappingTableEntry { | ||
| 67 | source_addr_start: unsafe { core::ptr::addr_of!(__sidata) }, | ||
| 68 | dest_addr_start: unsafe { core::ptr::addr_of!(__sdata) }, | ||
| 69 | dest_addr_end: unsafe { core::ptr::addr_of!(__edata) }, | ||
| 70 | }, | ||
| 71 | // This is the terminating marker | ||
| 72 | MappingTableEntry::null(), | ||
| 73 | ]; | ||
| 74 | |||
| 75 | /// Create a 'Binary Info' entry containing the program name | ||
| 76 | /// | ||
| 77 | /// This is well-known to picotool, and will be displayed if you run `picotool info`. | ||
| 78 | /// | ||
| 79 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 80 | /// * ID: [`consts::ID_RP_PROGRAM_NAME`] | ||
| 81 | pub const fn rp_program_name(name: &'static core::ffi::CStr) -> StringEntry { | ||
| 82 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_NAME, name) | ||
| 83 | } | ||
| 84 | |||
| 85 | /// Create a 'Binary Info' entry containing the program version. | ||
| 86 | /// | ||
| 87 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 88 | /// * Id: [`consts::ID_RP_PROGRAM_VERSION_STRING`] | ||
| 89 | pub const fn rp_program_version(name: &'static core::ffi::CStr) -> StringEntry { | ||
| 90 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_VERSION_STRING, name) | ||
| 91 | } | ||
| 92 | |||
| 93 | /// Create a 'Binary Info' entry with a URL | ||
| 94 | /// | ||
| 95 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 96 | /// * Id: [`consts::ID_RP_PROGRAM_URL`] | ||
| 97 | pub const fn rp_program_url(url: &'static core::ffi::CStr) -> StringEntry { | ||
| 98 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_URL, url) | ||
| 99 | } | ||
| 100 | |||
| 101 | /// Create a 'Binary Info' with the program build date | ||
| 102 | /// | ||
| 103 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 104 | /// * Id: [`consts::ID_RP_PROGRAM_BUILD_DATE_STRING`] | ||
| 105 | pub const fn rp_program_build_date_string(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 106 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_BUILD_DATE_STRING, value) | ||
| 107 | } | ||
| 108 | |||
| 109 | /// Create a 'Binary Info' with the size of the binary | ||
| 110 | /// | ||
| 111 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 112 | /// * Id: [`consts::ID_RP_BINARY_END`] | ||
| 113 | pub const fn rp_binary_end(value: u32) -> IntegerEntry { | ||
| 114 | IntegerEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_BINARY_END, value) | ||
| 115 | } | ||
| 116 | |||
| 117 | /// Create a 'Binary Info' with a description of the program | ||
| 118 | /// | ||
| 119 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 120 | /// * Id: [`consts::ID_RP_PROGRAM_DESCRIPTION`] | ||
| 121 | pub const fn rp_program_description(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 122 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_DESCRIPTION, value) | ||
| 123 | } | ||
| 124 | |||
| 125 | /// Create a 'Binary Info' with some feature of the program | ||
| 126 | /// | ||
| 127 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 128 | /// * Id: [`consts::ID_RP_PROGRAM_FEATURE`] | ||
| 129 | pub const fn rp_program_feature(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 130 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_FEATURE, value) | ||
| 131 | } | ||
| 132 | |||
| 133 | /// Create a 'Binary Info' with some whether this was a Debug or Release build | ||
| 134 | /// | ||
| 135 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 136 | /// * Id: [`consts::ID_RP_PROGRAM_BUILD_ATTRIBUTE`] | ||
| 137 | pub const fn rp_program_build_attribute(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 138 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PROGRAM_BUILD_ATTRIBUTE, value) | ||
| 139 | } | ||
| 140 | |||
| 141 | /// Create a 'Binary Info' with the Pico SDK version used | ||
| 142 | /// | ||
| 143 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 144 | /// * Id: [`consts::ID_RP_SDK_VERSION`] | ||
| 145 | pub const fn rp_sdk_version(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 146 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_SDK_VERSION, value) | ||
| 147 | } | ||
| 148 | |||
| 149 | /// Create a 'Binary Info' with which board this program targets | ||
| 150 | /// | ||
| 151 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 152 | /// * Id: [`consts::ID_RP_PICO_BOARD`] | ||
| 153 | pub const fn rp_pico_board(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 154 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_PICO_BOARD, value) | ||
| 155 | } | ||
| 156 | |||
| 157 | /// Create a 'Binary Info' with which `boot2` image this program uses | ||
| 158 | /// | ||
| 159 | /// * Tag: [`consts::TAG_RASPBERRY_PI`] | ||
| 160 | /// * Id: [`consts::ID_RP_BOOT2_NAME`] | ||
| 161 | pub const fn rp_boot2_name(value: &'static core::ffi::CStr) -> StringEntry { | ||
| 162 | StringEntry::new(consts::TAG_RASPBERRY_PI, consts::ID_RP_BOOT2_NAME, value) | ||
| 163 | } | ||
| 164 | |||
| 165 | /// Create a tag from two ASCII letters. | ||
| 166 | /// | ||
| 167 | /// ``` | ||
| 168 | /// let tag = embassy_rp::binary_info::make_tag(b"RP"); | ||
| 169 | /// assert_eq!(tag, 0x5052); | ||
| 170 | /// ``` | ||
| 171 | pub const fn make_tag(c: &[u8; 2]) -> u16 { | ||
| 172 | u16::from_le_bytes(*c) | ||
| 173 | } | ||
| 174 | |||
| 175 | // End of file | ||
diff --git a/embassy-rp/src/binary_info/types.rs b/embassy-rp/src/binary_info/types.rs deleted file mode 100644 index 6aec1902e..000000000 --- a/embassy-rp/src/binary_info/types.rs +++ /dev/null | |||
| @@ -1,195 +0,0 @@ | |||
| 1 | //! Types for the Binary Info system | ||
| 2 | |||
| 3 | // Credit: Taken from https://github.com/thejpster/rp-hal-rp2350-public (also licensed Apache 2.0 + MIT). | ||
| 4 | // Copyright (c) rp-rs organization | ||
| 5 | |||
| 6 | /// This is the 'Binary Info' header block that `picotool` looks for in your UF2 | ||
| 7 | /// file/ELF file/Pico in Bootloader Mode to give you useful metadata about your | ||
| 8 | /// program. | ||
| 9 | /// | ||
| 10 | /// It should be placed in the first 4096 bytes of flash, so use your `memory.x` | ||
| 11 | /// to insert a section between `.text` and `.vector_table` and put a static | ||
| 12 | /// value of this type in that section. | ||
| 13 | #[repr(C)] | ||
| 14 | pub struct Header { | ||
| 15 | /// Must be equal to Picotool::MARKER_START | ||
| 16 | marker_start: u32, | ||
| 17 | /// The first in our table of pointers to Entries | ||
| 18 | entries_start: *const EntryAddr, | ||
| 19 | /// The last in our table of pointers to Entries | ||
| 20 | entries_end: *const EntryAddr, | ||
| 21 | /// The first entry in a null-terminated RAM/Flash mapping table | ||
| 22 | mapping_table: *const MappingTableEntry, | ||
| 23 | /// Must be equal to Picotool::MARKER_END | ||
| 24 | marker_end: u32, | ||
| 25 | } | ||
| 26 | |||
| 27 | impl Header { | ||
| 28 | /// This is the `BINARY_INFO_MARKER_START` magic value from `picotool` | ||
| 29 | const MARKER_START: u32 = 0x7188ebf2; | ||
| 30 | /// This is the `BINARY_INFO_MARKER_END` magic value from `picotool` | ||
| 31 | const MARKER_END: u32 = 0xe71aa390; | ||
| 32 | |||
| 33 | /// Create a new `picotool` compatible header. | ||
| 34 | /// | ||
| 35 | /// * `entries_start` - the first [`EntryAddr`] in the table | ||
| 36 | /// * `entries_end` - the last [`EntryAddr`] in the table | ||
| 37 | /// * `mapping_table` - the RAM/Flash address mapping table | ||
| 38 | pub const fn new( | ||
| 39 | entries_start: *const EntryAddr, | ||
| 40 | entries_end: *const EntryAddr, | ||
| 41 | mapping_table: &'static [MappingTableEntry], | ||
| 42 | ) -> Self { | ||
| 43 | let mapping_table = mapping_table.as_ptr(); | ||
| 44 | Self { | ||
| 45 | marker_start: Self::MARKER_START, | ||
| 46 | entries_start, | ||
| 47 | entries_end, | ||
| 48 | mapping_table, | ||
| 49 | marker_end: Self::MARKER_END, | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | // We need this as rustc complains that is is unsafe to share `*const u32` | ||
| 55 | // pointers between threads. We only allow these to be created with static | ||
| 56 | // data, so this is OK. | ||
| 57 | unsafe impl Sync for Header {} | ||
| 58 | |||
| 59 | /// This is a reference to an entry. It's like a `&dyn` ref to some type `T: | ||
| 60 | /// Entry`, except that the run-time type information is encoded into the | ||
| 61 | /// Entry itself in very specific way. | ||
| 62 | #[repr(transparent)] | ||
| 63 | pub struct EntryAddr(*const u32); | ||
| 64 | |||
| 65 | // We need this as rustc complains that is is unsafe to share `*const u32` | ||
| 66 | // pointers between threads. We only allow these to be created with static | ||
| 67 | // data, so this is OK. | ||
| 68 | unsafe impl Sync for EntryAddr {} | ||
| 69 | |||
| 70 | /// Allows us to tell picotool where values are in the UF2 given their run-time | ||
| 71 | /// address. | ||
| 72 | /// | ||
| 73 | /// The most obvious example is RAM variables, which must be found in the | ||
| 74 | /// `.data` section of the UF2. | ||
| 75 | #[repr(C)] | ||
| 76 | pub struct MappingTableEntry { | ||
| 77 | /// The start address in RAM (or wherever the address picotool finds will | ||
| 78 | /// point) | ||
| 79 | pub source_addr_start: *const u32, | ||
| 80 | /// The start address in flash (or whever the data actually lives in the | ||
| 81 | /// ELF) | ||
| 82 | pub dest_addr_start: *const u32, | ||
| 83 | /// The end address in flash | ||
| 84 | pub dest_addr_end: *const u32, | ||
| 85 | } | ||
| 86 | |||
| 87 | impl MappingTableEntry { | ||
| 88 | /// Generate a null entry to mark the end of the list | ||
| 89 | pub const fn null() -> MappingTableEntry { | ||
| 90 | MappingTableEntry { | ||
| 91 | source_addr_start: core::ptr::null(), | ||
| 92 | dest_addr_start: core::ptr::null(), | ||
| 93 | dest_addr_end: core::ptr::null(), | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | // We need this as rustc complains that is is unsafe to share `*const u32` | ||
| 99 | // pointers between threads. We only allow these to be created with static | ||
| 100 | // data, so this is OK. | ||
| 101 | unsafe impl Sync for MappingTableEntry {} | ||
| 102 | |||
| 103 | /// This is the set of data types that `picotool` supports. | ||
| 104 | #[repr(u16)] | ||
| 105 | pub enum DataType { | ||
| 106 | /// Raw data | ||
| 107 | Raw = 1, | ||
| 108 | /// Data with a size | ||
| 109 | SizedData = 2, | ||
| 110 | /// A list of binary data | ||
| 111 | BinaryInfoListZeroTerminated = 3, | ||
| 112 | /// A BSON encoded blob | ||
| 113 | Bson = 4, | ||
| 114 | /// An Integer with an ID | ||
| 115 | IdAndInt = 5, | ||
| 116 | /// A string with an Id | ||
| 117 | IdAndString = 6, | ||
| 118 | /// A block device | ||
| 119 | BlockDevice = 7, | ||
| 120 | /// GPIO pins, with their function | ||
| 121 | PinsWithFunction = 8, | ||
| 122 | /// GPIO pins, with their name | ||
| 123 | PinsWithName = 9, | ||
| 124 | /// GPIO pins, with multiple names? | ||
| 125 | PinsWithNames = 10, | ||
| 126 | } | ||
| 127 | |||
| 128 | /// All Entries start with this common header | ||
| 129 | #[repr(C)] | ||
| 130 | struct EntryCommon { | ||
| 131 | data_type: DataType, | ||
| 132 | tag: u16, | ||
| 133 | } | ||
| 134 | |||
| 135 | /// An entry which contains both an ID (e.g. `ID_RP_PROGRAM_NAME`) and a pointer | ||
| 136 | /// to a null-terminated string. | ||
| 137 | #[repr(C)] | ||
| 138 | pub struct StringEntry { | ||
| 139 | header: EntryCommon, | ||
| 140 | id: u32, | ||
| 141 | value: *const core::ffi::c_char, | ||
| 142 | } | ||
| 143 | |||
| 144 | impl StringEntry { | ||
| 145 | /// Create a new `StringEntry` | ||
| 146 | pub const fn new(tag: u16, id: u32, value: &'static core::ffi::CStr) -> StringEntry { | ||
| 147 | StringEntry { | ||
| 148 | header: EntryCommon { | ||
| 149 | data_type: DataType::IdAndString, | ||
| 150 | tag, | ||
| 151 | }, | ||
| 152 | id, | ||
| 153 | value: value.as_ptr(), | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | /// Get this entry's address | ||
| 158 | pub const fn addr(&self) -> EntryAddr { | ||
| 159 | EntryAddr(self as *const Self as *const u32) | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | // We need this as rustc complains that is is unsafe to share `*const | ||
| 164 | // core::ffi::c_char` pointers between threads. We only allow these to be | ||
| 165 | // created with static string slices, so it's OK. | ||
| 166 | unsafe impl Sync for StringEntry {} | ||
| 167 | |||
| 168 | /// An entry which contains both an ID (e.g. `ID_RP_BINARY_END`) and an integer. | ||
| 169 | #[repr(C)] | ||
| 170 | pub struct IntegerEntry { | ||
| 171 | header: EntryCommon, | ||
| 172 | id: u32, | ||
| 173 | value: u32, | ||
| 174 | } | ||
| 175 | |||
| 176 | impl IntegerEntry { | ||
| 177 | /// Create a new `StringEntry` | ||
| 178 | pub const fn new(tag: u16, id: u32, value: u32) -> IntegerEntry { | ||
| 179 | IntegerEntry { | ||
| 180 | header: EntryCommon { | ||
| 181 | data_type: DataType::IdAndInt, | ||
| 182 | tag, | ||
| 183 | }, | ||
| 184 | id, | ||
| 185 | value, | ||
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 189 | /// Get this entry's address | ||
| 190 | pub const fn addr(&self) -> EntryAddr { | ||
| 191 | EntryAddr(self as *const Self as *const u32) | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | // End of file | ||
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 1fc397107..21f0771de 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -9,6 +9,9 @@ | |||
| 9 | // This mod MUST go first, so that the others see its macros. | 9 | // This mod MUST go first, so that the others see its macros. |
| 10 | pub(crate) mod fmt; | 10 | pub(crate) mod fmt; |
| 11 | 11 | ||
| 12 | #[cfg(feature = "binary-info")] | ||
| 13 | pub use rp_binary_info as binary_info; | ||
| 14 | |||
| 12 | #[cfg(feature = "critical-section-impl")] | 15 | #[cfg(feature = "critical-section-impl")] |
| 13 | mod critical_section_impl; | 16 | mod critical_section_impl; |
| 14 | 17 | ||
| @@ -16,8 +19,6 @@ mod intrinsics; | |||
| 16 | 19 | ||
| 17 | pub mod adc; | 20 | pub mod adc; |
| 18 | #[cfg(feature = "_rp235x")] | 21 | #[cfg(feature = "_rp235x")] |
| 19 | pub mod binary_info; | ||
| 20 | #[cfg(feature = "_rp235x")] | ||
| 21 | pub mod block; | 22 | pub mod block; |
| 22 | #[cfg(feature = "rp2040")] | 23 | #[cfg(feature = "rp2040")] |
| 23 | pub mod bootsel; | 24 | pub mod bootsel; |
