Skip to content

Commit a2de2f8

Browse files
mhiramatrostedt
authored andcommitted
lib/bootconfig: Add override operator support
Add the value override operator (":=") support to the bootconfig. This value override operator will be useful for the bootloaders which will only update the existing bootconfig according to the bootloader boot options. Without this override operator, the bootloader needs to parse the existing bootconfig and update it. However, with this assignment, it can just append the updated (partial) bootconfig text at the tail of existing one without parsing it. (Of course, it must update the size, checksum and magic, but that will be done easily) Link: https://lkml.kernel.org/r/159482882954.126704.16209517125614438640.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 80a6e70 commit a2de2f8

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lib/bootconfig.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,30 @@ const char * __init xbc_node_find_next_key_value(struct xbc_node *root,
329329

330330
/* XBC parse and tree build */
331331

332+
static int __init xbc_init_node(struct xbc_node *node, char *data, u32 flag)
333+
{
334+
unsigned long offset = data - xbc_data;
335+
336+
if (WARN_ON(offset >= XBC_DATA_MAX))
337+
return -EINVAL;
338+
339+
node->data = (u16)offset | flag;
340+
node->child = 0;
341+
node->next = 0;
342+
343+
return 0;
344+
}
345+
332346
static struct xbc_node * __init xbc_add_node(char *data, u32 flag)
333347
{
334348
struct xbc_node *node;
335-
unsigned long offset;
336349

337350
if (xbc_node_num == XBC_NODE_MAX)
338351
return NULL;
339352

340353
node = &xbc_nodes[xbc_node_num++];
341-
offset = data - xbc_data;
342-
node->data = (u16)offset;
343-
if (WARN_ON(offset >= XBC_DATA_MAX))
354+
if (xbc_init_node(node, data, flag) < 0)
344355
return NULL;
345-
node->data |= flag;
346-
node->child = 0;
347-
node->next = 0;
348356

349357
return node;
350358
}
@@ -603,7 +611,9 @@ static int __init xbc_parse_kv(char **k, char *v, int op)
603611
if (c < 0)
604612
return c;
605613

606-
if (!xbc_add_sibling(v, XBC_VALUE))
614+
if (op == ':' && child) {
615+
xbc_init_node(child, v, XBC_VALUE);
616+
} else if (!xbc_add_sibling(v, XBC_VALUE))
607617
return -ENOMEM;
608618

609619
if (c == ',') { /* Array */
@@ -787,7 +797,7 @@ int __init xbc_init(char *buf, const char **emsg, int *epos)
787797

788798
p = buf;
789799
do {
790-
q = strpbrk(p, "{}=+;\n#");
800+
q = strpbrk(p, "{}=+;:\n#");
791801
if (!q) {
792802
p = skip_spaces(p);
793803
if (*p != '\0')
@@ -798,9 +808,12 @@ int __init xbc_init(char *buf, const char **emsg, int *epos)
798808
c = *q;
799809
*q++ = '\0';
800810
switch (c) {
811+
case ':':
801812
case '+':
802813
if (*q++ != '=') {
803-
ret = xbc_parse_error("Wrong '+' operator",
814+
ret = xbc_parse_error(c == '+' ?
815+
"Wrong '+' operator" :
816+
"Wrong ':' operator",
804817
q - 2);
805818
break;
806819
}

0 commit comments

Comments
 (0)