0001
0002 #ifndef _LINUX_XBC_H
0003 #define _LINUX_XBC_H
0004
0005
0006
0007
0008
0009
0010 #ifdef __KERNEL__
0011 #include <linux/kernel.h>
0012 #include <linux/types.h>
0013 #else
0014
0015
0016
0017
0018
0019
0020
0021 #endif
0022
0023 #define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
0024 #define BOOTCONFIG_MAGIC_LEN 12
0025 #define BOOTCONFIG_ALIGN_SHIFT 2
0026 #define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT)
0027 #define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1)
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 static inline __init uint32_t xbc_calc_checksum(void *data, uint32_t size)
0039 {
0040 unsigned char *p = data;
0041 uint32_t ret = 0;
0042
0043 while (size--)
0044 ret += *p++;
0045
0046 return ret;
0047 }
0048
0049
0050 struct xbc_node {
0051 uint16_t next;
0052 uint16_t child;
0053 uint16_t parent;
0054 uint16_t data;
0055 } __attribute__ ((__packed__));
0056
0057 #define XBC_KEY 0
0058 #define XBC_VALUE (1 << 15)
0059
0060 #define XBC_DATA_MAX (XBC_VALUE - 1)
0061
0062 #define XBC_NODE_MAX 1024
0063 #define XBC_KEYLEN_MAX 256
0064 #define XBC_DEPTH_MAX 16
0065
0066
0067 struct xbc_node * __init xbc_root_node(void);
0068 int __init xbc_node_index(struct xbc_node *node);
0069 struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node);
0070 struct xbc_node * __init xbc_node_get_child(struct xbc_node *node);
0071 struct xbc_node * __init xbc_node_get_next(struct xbc_node *node);
0072 const char * __init xbc_node_get_data(struct xbc_node *node);
0073
0074
0075
0076
0077
0078
0079
0080 static inline __init bool xbc_node_is_value(struct xbc_node *node)
0081 {
0082 return node->data & XBC_VALUE;
0083 }
0084
0085
0086
0087
0088
0089
0090
0091 static inline __init bool xbc_node_is_key(struct xbc_node *node)
0092 {
0093 return !xbc_node_is_value(node);
0094 }
0095
0096
0097
0098
0099
0100
0101
0102 static inline __init bool xbc_node_is_array(struct xbc_node *node)
0103 {
0104 return xbc_node_is_value(node) && node->child != 0;
0105 }
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 static inline __init bool xbc_node_is_leaf(struct xbc_node *node)
0117 {
0118 return xbc_node_is_key(node) &&
0119 (!node->child || xbc_node_is_value(xbc_node_get_child(node)));
0120 }
0121
0122
0123 struct xbc_node * __init xbc_node_find_subkey(struct xbc_node *parent,
0124 const char *key);
0125
0126 const char * __init xbc_node_find_value(struct xbc_node *parent,
0127 const char *key,
0128 struct xbc_node **vnode);
0129
0130 struct xbc_node * __init xbc_node_find_next_leaf(struct xbc_node *root,
0131 struct xbc_node *leaf);
0132
0133 const char * __init xbc_node_find_next_key_value(struct xbc_node *root,
0134 struct xbc_node **leaf);
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 static inline const char * __init
0147 xbc_find_value(const char *key, struct xbc_node **vnode)
0148 {
0149 return xbc_node_find_value(NULL, key, vnode);
0150 }
0151
0152
0153
0154
0155
0156
0157
0158
0159 static inline struct xbc_node * __init xbc_find_node(const char *key)
0160 {
0161 return xbc_node_find_subkey(NULL, key);
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171 static inline struct xbc_node * __init xbc_node_get_subkey(struct xbc_node *node)
0172 {
0173 struct xbc_node *child = xbc_node_get_child(node);
0174
0175 if (child && xbc_node_is_value(child))
0176 return xbc_node_get_next(child);
0177 else
0178 return child;
0179 }
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 #define xbc_array_for_each_value(anode, value) \
0191 for (value = xbc_node_get_data(anode); anode != NULL ; \
0192 anode = xbc_node_get_child(anode), \
0193 value = anode ? xbc_node_get_data(anode) : NULL)
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203 #define xbc_node_for_each_child(parent, child) \
0204 for (child = xbc_node_get_child(parent); child != NULL ; \
0205 child = xbc_node_get_next(child))
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215 #define xbc_node_for_each_subkey(parent, child) \
0216 for (child = xbc_node_get_subkey(parent); child != NULL ; \
0217 child = xbc_node_get_next(child))
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234 #define xbc_node_for_each_array_value(node, key, anode, value) \
0235 for (value = xbc_node_find_value(node, key, &anode); value != NULL; \
0236 anode = xbc_node_get_child(anode), \
0237 value = anode ? xbc_node_get_data(anode) : NULL)
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248 #define xbc_node_for_each_key_value(node, knode, value) \
0249 for (knode = NULL, value = xbc_node_find_next_key_value(node, &knode);\
0250 knode != NULL; value = xbc_node_find_next_key_value(node, &knode))
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 #define xbc_for_each_key_value(knode, value) \
0261 xbc_node_for_each_key_value(NULL, knode, value)
0262
0263
0264 int __init xbc_node_compose_key_after(struct xbc_node *root,
0265 struct xbc_node *node, char *buf, size_t size);
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277 static inline int __init xbc_node_compose_key(struct xbc_node *node,
0278 char *buf, size_t size)
0279 {
0280 return xbc_node_compose_key_after(NULL, node, buf, size);
0281 }
0282
0283
0284 int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos);
0285
0286
0287 int __init xbc_get_info(int *node_size, size_t *data_size);
0288
0289
0290 void __init xbc_exit(void);
0291
0292
0293 #ifdef CONFIG_BOOT_CONFIG_EMBED
0294 const char * __init xbc_get_embedded_bootconfig(size_t *size);
0295 #else
0296 static inline const char *xbc_get_embedded_bootconfig(size_t *size)
0297 {
0298 return NULL;
0299 }
0300 #endif
0301
0302 #endif