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_PINS_WITH_NAMES 9
37#define BINARY_INFO_TYPE_NAMED_GROUP 10
38
39// note plan is to reserve c1 = 0->31 for "collision tags"; i.e.
40// for which you should always use random IDs with the binary_info,
41// giving you 4 + 8 + 32 = 44 bits to avoid collisions
42#define BINARY_INFO_MAKE_TAG(c1, c2) ((((uint)c2&0xffu)<<8u)|((uint)c1&0xffu))
43
44// Raspberry Pi defined. do not use
45#define BINARY_INFO_TAG_RASPBERRY_PI BINARY_INFO_MAKE_TAG('R','P')
46
47#define BINARY_INFO_ID_RP_PROGRAM_NAME 0x02031c86
48#define BINARY_INFO_ID_RP_PROGRAM_VERSION_STRING 0x11a9bc3a
49#define BINARY_INFO_ID_RP_PROGRAM_BUILD_DATE_STRING 0x9da22254
50#define BINARY_INFO_ID_RP_BINARY_END 0x68f465de
51#define BINARY_INFO_ID_RP_PROGRAM_URL 0x1856239a
52#define BINARY_INFO_ID_RP_PROGRAM_DESCRIPTION 0xb6a07c19
53#define BINARY_INFO_ID_RP_PROGRAM_FEATURE 0xa1f4b453
54#define BINARY_INFO_ID_RP_PROGRAM_BUILD_ATTRIBUTE 0x4275f0d3
55#define BINARY_INFO_ID_RP_SDK_VERSION 0x5360b3ab
56#define BINARY_INFO_ID_RP_PICO_BOARD 0xb63cffbb
57#define BINARY_INFO_ID_RP_BOOT2_NAME 0x7f8882e1
58
59#if PICO_ON_DEVICE
60#define bi_ptr_of(x) x *
61#else
62#define bi_ptr_of(x) uint32_t
63#endif
64typedef struct __packed _binary_info_core {
65 uint16_t type;
66 uint16_t tag;
68
69typedef struct __packed _binary_info_raw_data {
70 struct _binary_info_core core;
71 uint8_t bytes[1];
73
74typedef struct __packed _binary_info_sized_data {
75 struct _binary_info_core core;
76 uint32_t length;
77 uint8_t bytes[1];
79
80typedef struct __packed _binary_info_list_zero_terminated {
81 struct _binary_info_core core;
82 bi_ptr_of(binary_info_t) list;
84
85typedef struct __packed _binary_info_id_and_int {
86 struct _binary_info_core core;
87 uint32_t id;
88 int32_t value;
90
91typedef struct __packed _binary_info_id_and_string {
92 struct _binary_info_core core;
93 uint32_t id;
94 bi_ptr_of(const char) value;
96
97typedef struct __packed _binary_info_block_device {
98 struct _binary_info_core core;
99 bi_ptr_of(const char) name; // optional static name (independent of what is formatted)
100 uint32_t address;
101 uint32_t size;
102 bi_ptr_of(binary_info_t) extra; // additional info
103 uint16_t flags;
105
106#define BI_PINS_ENCODING_RANGE 1
107#define BI_PINS_ENCODING_MULTI 2
108
109typedef struct __packed _binary_info_pins_with_func {
110 struct _binary_info_core core;
111 // 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 p
112 // phi_5 : plo_5 : func_4 : 001_3 // pin range plo-phi inclusive
113 uint32_t pin_encoding;
115
116typedef struct __packed _binary_info_pins_with_name {
117 struct _binary_info_core core;
118 uint32_t pin_mask;
119 bi_ptr_of(const char) label;
121
122#define BI_NAMED_GROUP_SHOW_IF_EMPTY 0x0001 // default is to hide
123#define BI_NAMED_GROUP_SEPARATE_COMMAS 0x0002 // default is newlines
124#define BI_NAMED_GROUP_SORT_ALPHA 0x0004 // default is no sort
125#define BI_NAMED_GROUP_ADVANCED 0x0008 // if set, then only shown in say info -a
126
127typedef struct __packed _binary_info_named_group {
128 struct _binary_info_core core;
129 uint32_t parent_id;
130 uint16_t flags;
131 uint16_t group_tag;
132 uint32_t group_id;
133 bi_ptr_of(const char) label;
135
136enum {
137 BINARY_INFO_BLOCK_DEV_FLAG_READ =
138 1 << 0, // if not readable, then it is basically hidden, but tools may choose to avoid overwriting it
139 BINARY_INFO_BLOCK_DEV_FLAG_WRITE = 1 << 1,
140 BINARY_INFO_BLOCK_DEV_FLAG_REFORMAT = 1 << 2, // may be reformatted..
141
142 BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN = 0 << 4, // unknown free to look
143 BINARY_INFO_BLOCK_DEV_FLAG_PT_MBR = 1 << 4, // expect MBR
144 BINARY_INFO_BLOCK_DEV_FLAG_PT_GPT = 2 << 4, // expect GPT
145 BINARY_INFO_BLOCK_DEV_FLAG_PT_NONE = 3 << 4, // no partition table
146};
147
148#ifdef __cplusplus
149}
150#endif
151#endif
Definition: structure.h:97
Definition: structure.h:64
Definition: structure.h:85
Definition: structure.h:91
Definition: structure.h:80
Definition: structure.h:127
Definition: structure.h:109
Definition: structure.h:116
Definition: structure.h:69
Definition: structure.h:74