Skip to contentSkip to conversation

bootconfig: Show more error information

PATCH New Masami Hiramatsu 1 participant 5 messages Feb 5, 2020

Subsystems (2)
lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover bootconfig: Show more error information

Hello,

Here are some patches to show more error information and the number of nodes on boot message and bootconfig tool.

Since the max number of the nodes are limited and it is hard to count the number of nodes while writing the config file, it is better that the bootconfig command informs user the current number of the node.

Thank you,

---

Masami Hiramatsu (4):
bootconfig: Use bootconfig instead of boot config
bootconfig: Add more parse error messages tools/bootconfig: Show the number of bootconfig nodes
bootconfig: Show the number of nodes on boot message

 init/main.c             |   10 ++++++----
 lib/bootconfig.c        |   21 ++++++++++++++++-----
 tools/bootconfig/main.c |    1 +
 3 files changed, 23 insertions(+), 9 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/4 bootconfig: Use bootconfig instead of boot config

Use "bootconfig" (1 word) instead of "boot config" (2 words) in the boot message.

---
 init/main.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
init/main.c +3 -3
index f174a59d3903..2de2f9f7aab9 100644
@@ -372,7 +372,7 @@ static void __init setup_boot_config(const char *cmdline)
 
 	copy = memblock_alloc(size + 1, SMP_CACHE_BYTES);
 	if (!copy) {
-		pr_err("Failed to allocate memory for boot config\n");
+		pr_err("Failed to allocate memory for bootconfig\n");
 		return;
 	}
 
@@ -380,9 +380,9 @@ static void __init setup_boot_config(const char *cmdline)
 	copy[size] = '\0';
 
 	if (xbc_init(copy) < 0)
-		pr_err("Failed to parse boot config\n");
+		pr_err("Failed to parse bootconfig\n");
 	else {
-		pr_info("Load boot config: %d bytes\n", size);
+		pr_info("Load bootconfig: %d bytes\n", size);
 		/* keys starting with "kernel." are passed via cmdline */
 		extra_command_line = xbc_make_cmdline("kernel");
 		/* Also, "init." keys are init arguments */
author maintainer
#2 lore raw

PATCH 2/4 bootconfig: Add more parse error messages

In reply to Masami Hiramatsu

Add more error messages for following cases.
- Exceeding max number of nodes
- Config tree data is empty (e.g. comment only)
- Config data is empty or exceeding max size
- bootconfig is already initialized

---
 lib/bootconfig.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
lib/bootconfig.c +12 -4
index 055014e233a5..a98ae136529c 100644
@@ -373,7 +373,8 @@ static struct xbc_node * __init xbc_add_sibling(char *data, u32 flag)
 				sib->next = xbc_node_index(node);
 			}
 		}
-	}
+	} else
+		xbc_parse_error("Too many nodes", data);
 
 	return node;
 }
@@ -657,8 +658,10 @@ static int __init xbc_verify_tree(void)
 	struct xbc_node *n, *m;
 
 	/* Empty tree */
-	if (xbc_node_num == 0)
+	if (xbc_node_num == 0) {
+		xbc_parse_error("Empty config", xbc_data);
 		return -ENOENT;
+	}
 
 	for (i = 0; i < xbc_node_num; i++) {
 		if (xbc_nodes[i].next > xbc_node_num) {
@@ -732,12 +735,17 @@ int __init xbc_init(char *buf)
 	char *p, *q;
 	int ret, c;
 
-	if (xbc_data)
+	if (xbc_data) {
+		pr_err("Error: bootconfig is already initialized.\n");
 		return -EBUSY;
+	}
 
 	ret = strlen(buf);
-	if (ret > XBC_DATA_MAX - 1 || ret == 0)
+	if (ret > XBC_DATA_MAX - 1 || ret == 0) {
+		pr_err("Error: Config data is %s.\n",
+			ret ? "too big" : "empty");
 		return -ERANGE;
+	}
 
 	xbc_data = buf;
 	xbc_data_size = ret + 1;
author maintainer
#3 lore raw

PATCH 3/4 tools/bootconfig: Show the number of bootconfig nodes

In reply to Masami Hiramatsu

Show the number of bootconfig nodes when applying new bootconfig to initrd.

Since there are limitations of bootconfig not only in its filesize, but also the number of nodes, the number should be shown when applying so that user can get the feeling of scale of current bootconfig.

---
 lib/bootconfig.c        |    5 ++++-
 tools/bootconfig/main.c |    1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
lib/bootconfig.c +4 -1
index a98ae136529c..afb2e767e6fe 100644
@@ -728,7 +728,8 @@ void __init xbc_destroy_all(void)
  *
  * This parses the boot config text in @buf. @buf must be a
  * null terminated string and smaller than XBC_DATA_MAX.
- * Return 0 if succeeded, or -errno if there is any error.
+ * Return the number of stored nodes (>0) if succeeded, or -errno
+ * if there is any error.
  */
 int __init xbc_init(char *buf)
 {
@@ -788,6 +789,8 @@ int __init xbc_init(char *buf)
 
 	if (ret < 0)
 		xbc_destroy_all();
+	else
+		ret = xbc_node_num;
 
 	return ret;
 }
tools/bootconfig/main.c +1 -0
index 91c9a5c0c499..47f488458328 100644
@@ -268,6 +268,7 @@ int apply_xbc(const char *path, const char *xbc_path)
 		return ret;
 	}
 	printf("Apply %s to %s\n", xbc_path, path);
+	printf("\tNumber of nodes: %d\n", ret);
 	printf("\tSize: %u bytes\n", (unsigned int)size);
 	printf("\tChecksum: %d\n", (unsigned int)csum);
 
author maintainer
#4 lore raw

PATCH 4/4 bootconfig: Show the number of nodes on boot message

In reply to Masami Hiramatsu

Show the number of bootconfig nodes on boot message.

---
 init/main.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
init/main.c +4 -2
index 2de2f9f7aab9..491f1cdb3105 100644
@@ -342,6 +342,7 @@ static void __init setup_boot_config(const char *cmdline)
 	char *data, *copy;
 	const char *p;
 	u32 *hdr;
+	int ret;
 
 	p = strstr(cmdline, "bootconfig");
 	if (!p || (p != cmdline && !isspace(*(p-1))) ||
@@ -379,10 +380,11 @@ static void __init setup_boot_config(const char *cmdline)
 	memcpy(copy, data, size);
 	copy[size] = '\0';
 
-	if (xbc_init(copy) < 0)
+	ret = xbc_init(copy);
+	if (ret < 0)
 		pr_err("Failed to parse bootconfig\n");
 	else {
-		pr_info("Load bootconfig: %d bytes\n", size);
+		pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret);
 		/* keys starting with "kernel." are passed via cmdline */
 		extra_command_line = xbc_make_cmdline("kernel");
 		/* Also, "init." keys are init arguments */