pico-binary-info
Portable Pi Pico binary_info parser
Loading...
Searching...
No Matches
structure.h
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_BINARY_INFO_STRUCTURE_H
8#define _PICO_BINARY_INFO_STRUCTURE_H
9
10// NOTE: This file may be included by non SDK code, so does not use SDK includes
11
12// NOTE: ALL CHANGES MUST BE BACKWARDS COMPATIBLE
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stdint.h>
19
20#ifndef __packed
21#define __packed __attribute__((packed))
22#endif
23
24typedef struct _binary_info_core binary_info_t;
25
26#define BINARY_INFO_TYPE_RAW_DATA 1
27#define BINARY_INFO_TYPE_SIZED_DATA 2
28#define BINARY_INFO_TYPE_BINARY_INFO_LIST_ZERO_TERMINATED 3
29#define BINARY_INFO_TYPE_BSON 4
30#define BINARY_INFO_TYPE_ID_AND_INT 5
31#define BINARY_INFO_TYPE_ID_AND_STRING 6
32// traditional block device
33#define BINARY_INFO_TYPE_BLOCK_DEVICE 7
34#define BINARY_INFO_TYPE_PINS_WITH_FUNC 8
35#define BINARY_INFO_TYPE_PINS_WITH_NAME 9
36#define BINARY_INFO_TYPE_NAMED_GROUP 10
37#define BINARY_INFO_TYPE_PTR_INT32_WITH_NAME 11
38#define BINARY_INFO_TYPE_PTR_STRING_WITH_NAME 12
39#define BINARY_INFO_TYPE_PINS64_WITH_FUNC 13
40#define BINARY_INFO_TYPE_PINS64_WITH_NAME 14
41
42// note plan is to reserve c1 = 0->31 for "collision tags"; i.e.
43// for which you should always use random IDs with the binary_info,
44// giving you 4 + 8 + 32 = 44 bits to avoid collisions
45#define BINARY_INFO_MAKE_TAG(c1, c2) ((uint16_t)((((c2)&0xffu)<<8u)|((c1)&0xffu)))
46
47// Raspberry Pi defined. do not use
48#define BINARY_INFO_TAG_RASPBERRY_PI BINARY_INFO_MAKE_TAG('R','P')
49
50#define BINARY_INFO_ID_RP_PROGRAM_NAME 0x02031c86
51#define BINARY_INFO_ID_RP_PROGRAM_VERSION_STRING 0x11a9bc3a
52#define BINARY_INFO_ID_RP_PROGRAM_BUILD_DATE_STRING 0x9da22254
53#define BINARY_INFO_ID_RP_BINARY_END 0x68f465de
54#define BINARY_INFO_ID_RP_PROGRAM_URL 0x1856239a
55#define BINARY_INFO_ID_RP_PROGRAM_DESCRIPTION 0xb6a07c19
56#define BINARY_INFO_ID_RP_PROGRAM_FEATURE 0xa1f4b453
57#define BINARY_INFO_ID_RP_PROGRAM_BUILD_ATTRIBUTE 0x4275f0d3
58#define BINARY_INFO_ID_RP_SDK_VERSION 0x5360b3ab
59#define BINARY_INFO_ID_RP_PICO_BOARD 0xb63cffbb
60#define BINARY_INFO_ID_RP_BOOT2_NAME 0x7f8882e1
61
62#if PICO_ON_DEVICE
63#define bi_ptr_of(x) x *
64#else
65#define bi_ptr_of(x) uint32_t
66#endif
67
74typedef struct __packed _binary_info_core {
75 uint16_t type;
76 uint16_t tag;
77} binary_info_core_t;
78
82typedef struct __packed _binary_info_raw_data {
84 uint8_t bytes[1];
85} binary_info_raw_data_t;
86
90typedef struct __packed _binary_info_sized_data {
92 uint32_t length;
93 uint8_t bytes[1];
94} binary_info_sized_data_t;
95
99typedef struct __packed _binary_info_list_zero_terminated {
101 bi_ptr_of(binary_info_t) list;
102} binary_info_list_zero_terminated_t;
103
107typedef struct __packed _binary_info_id_and_int {
109 uint32_t id;
110 int32_t value;
111} binary_info_id_and_int_t;
112
116typedef struct __packed _binary_info_id_and_string {
118 uint32_t id;
119 bi_ptr_of(const char) value;
120} binary_info_id_and_string_t;
121
125typedef struct __packed _binary_info_ptr_int32_with_name {
127 int32_t id;
128 bi_ptr_of(const int) value;
129 bi_ptr_of(const char) label;
130} binary_info_ptr_int32_with_name_t;
131
135typedef struct __packed _binary_info_ptr_string_with_name {
137 int32_t id;
138 bi_ptr_of(const char) value;
139 bi_ptr_of(const char) label;
140 uint32_t len;
141} binary_info_ptr_string_with_name_t;
142
146typedef struct __packed _binary_info_block_device {
148 bi_ptr_of(const char) name;
149 uint32_t address;
150 uint32_t size;
151 bi_ptr_of(binary_info_t) extra;
152 uint16_t flags;
153} binary_info_block_device_t;
154
155#define BI_PINS_ENCODING_RANGE 1
156#define BI_PINS_ENCODING_MULTI 2
157
161typedef struct __packed _binary_info_pins_with_func {
163 // p4_5 : p3_5 : p2_5 : p1_5 : p0_5 : func_4 : 010_3 //individual pins p0,p1,p2,p3,p4 ... if fewer than 5 then duplicate last pin
164 // phi_5 : plo_5 : func_4 : 001_3 // pin range plo-phi inclusive
165 uint32_t pin_encoding;
166} binary_info_pins_with_func_t;
167
171typedef struct __packed _binary_info_pins64_with_func {
173 // p6_8 : p5_8 : p4_8 : p3_8 : p2_8 : p1_8 : p0_8 : func_5 : 010_3 //individual pins p0,p1,p2 ... if fewer than 7 then duplicate last pin
174 // phi_8 : plo_8 : func_5 : 001_3 // pin range plo-phi inclusive
175 uint64_t pin_encoding;
176} binary_info_pins64_with_func_t;
177
181typedef struct __packed _binary_info_pins_with_name {
183 uint32_t pin_mask;
184 bi_ptr_of(const char) label;
185} binary_info_pins_with_name_t;
186
190typedef struct __packed _binary_info_pins64_with_name {
192 uint64_t pin_mask;
193 bi_ptr_of(const char) label;
194} binary_info_pins64_with_name_t;
195
196#define BI_NAMED_GROUP_SHOW_IF_EMPTY 0x0001 // default is to hide
197#define BI_NAMED_GROUP_SEPARATE_COMMAS 0x0002 // default is newlines
198#define BI_NAMED_GROUP_SORT_ALPHA 0x0004 // default is no sort
199#define BI_NAMED_GROUP_ADVANCED 0x0008 // if set, then only shown in say info -a
200
207typedef struct __packed _binary_info_named_group {
209 uint32_t parent_id;
210 uint16_t flags;
211 uint16_t group_tag;
212 uint32_t group_id;
213 bi_ptr_of(const char) label;
214} binary_info_named_group_t;
215
216enum {
217 BINARY_INFO_BLOCK_DEV_FLAG_READ = 1 << 0, // if not readable, then it is basically hidden, but tools may choose to avoid overwriting it
218 BINARY_INFO_BLOCK_DEV_FLAG_WRITE = 1 << 1,
219 BINARY_INFO_BLOCK_DEV_FLAG_REFORMAT = 1 << 2, // may be reformatted..
220
221 BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN = 0 << 4, // unknown free to look
222 BINARY_INFO_BLOCK_DEV_FLAG_PT_MBR = 1 << 4, // expect MBR
223 BINARY_INFO_BLOCK_DEV_FLAG_PT_GPT = 2 << 4, // expect GPT
224 BINARY_INFO_BLOCK_DEV_FLAG_PT_NONE = 3 << 4, // no partition table
225};
226
227#ifdef __cplusplus
228}
229#endif
230#endif
Binary info entry describing a block device in the binary.
Definition structure.h:146
struct _binary_info_core core
Common binary info header.
Definition structure.h:147
uint32_t address
Start address of the block device in flash.
Definition structure.h:149
bi_ptr_of(const char) name
optional static name (independent of what is formatted)
bi_ptr_of(binary_info_t) extra
additional info
uint16_t flags
Block device capability flags (BINARY_INFO_BLOCK_DEV_FLAG_*)
Definition structure.h:152
uint32_t size
Size of the block device in bytes.
Definition structure.h:150
Common header fields shared by all binary info entries.
Definition structure.h:74
uint16_t tag
Namespace tag identifying the entry's owner.
Definition structure.h:76
uint16_t type
Binary info entry type (one of BINARY_INFO_TYPE_*)
Definition structure.h:75
Binary info entry associating a 32-bit integer value with an ID.
Definition structure.h:107
struct _binary_info_core core
Common binary info header.
Definition structure.h:108
uint32_t id
Identifier for the value (one of BINARY_INFO_ID_*)
Definition structure.h:109
int32_t value
The integer value associated with the ID.
Definition structure.h:110
Binary info entry associating a string value with an ID.
Definition structure.h:116
uint32_t id
Identifier for the value (one of BINARY_INFO_ID_*)
Definition structure.h:118
bi_ptr_of(const char) value
Pointer to the null-terminated string value.
struct _binary_info_core core
Common binary info header.
Definition structure.h:117
Binary info entry holding a null-terminated list of binary info pointers.
Definition structure.h:99
bi_ptr_of(binary_info_t) list
Pointer to the null-terminated list of binary info entries.
struct _binary_info_core core
Common binary info header.
Definition structure.h:100
Binary info entry defining a named group of related binary info entries.
Definition structure.h:207
uint32_t group_id
Unique identifier for this group.
Definition structure.h:212
uint16_t group_tag
Tag namespace used by entries within this group.
Definition structure.h:211
bi_ptr_of(const char) label
Pointer to the null-terminated group label.
uint16_t flags
Display flags for the group (BI_NAMED_GROUP_*)
Definition structure.h:210
uint32_t parent_id
ID of the parent group (0 for top-level)
Definition structure.h:209
struct _binary_info_core core
Common binary info header.
Definition structure.h:208
Binary info entry describing one or more GPIO pins and their assigned function, supporting pin number...
Definition structure.h:171
struct _binary_info_core core
Common binary info header.
Definition structure.h:172
uint64_t pin_encoding
Encoded pin numbers and function for more than 32 pins (see BI_PINS_ENCODING_* for format)
Definition structure.h:175
Binary info entry associating a human-readable label with a set of GPIO pins (up to 64)
Definition structure.h:190
bi_ptr_of(const char) label
Pointer to the null-terminated pin label.
struct _binary_info_core core
Common binary info header.
Definition structure.h:191
uint64_t pin_mask
Bitmask of GPIO pins covered by this entry (up to 64 pins)
Definition structure.h:192
Binary info entry describing one or more GPIO pins and their assigned function, supporting pin number...
Definition structure.h:161
struct _binary_info_core core
Common binary info header.
Definition structure.h:162
uint32_t pin_encoding
Encoded pin numbers and function (see BI_PINS_ENCODING_* for format)
Definition structure.h:165
Binary info entry associating a human-readable label with a set of GPIO pins.
Definition structure.h:181
struct _binary_info_core core
Common binary info header.
Definition structure.h:182
bi_ptr_of(const char) label
Pointer to the null-terminated pin label.
uint32_t pin_mask
Bitmask of GPIO pins covered by this entry.
Definition structure.h:183
Binary info entry holding a pointer to a named 32-bit integer variable.
Definition structure.h:125
bi_ptr_of(const int) value
Pointer to the integer variable.
bi_ptr_of(const char) label
Pointer to the null-terminated display label.
int32_t id
Identifier for the variable.
Definition structure.h:127
struct _binary_info_core core
Common binary info header.
Definition structure.h:126
Binary info entry holding a pointer to a named string variable.
Definition structure.h:135
bi_ptr_of(const char) value
Pointer to the string variable.
int32_t id
Identifier for the variable.
Definition structure.h:137
bi_ptr_of(const char) label
Pointer to the null-terminated display label.
struct _binary_info_core core
Common binary info header.
Definition structure.h:136
uint32_t len
Maximum length of the string buffer.
Definition structure.h:140
Binary info entry carrying raw, uninterpreted byte data.
Definition structure.h:82
uint8_t bytes[1]
Raw byte payload (variable length)
Definition structure.h:84
struct _binary_info_core core
Common binary info header.
Definition structure.h:83
Binary info entry carrying a length-prefixed byte buffer.
Definition structure.h:90
struct _binary_info_core core
Common binary info header.
Definition structure.h:91
uint32_t length
Number of bytes in the payload.
Definition structure.h:92
uint8_t bytes[1]
Byte payload (variable length)
Definition structure.h:93