* [PATCH 0/7] bootconfig: Clean up bootconfig
@ 2021-09-17 10:02 Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 1/7] tools/bootconfig: Run test script when build all Masami Hiramatsu
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:02 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Hi,
Here is a bootconfig cleanup series which includes a previous
xbc_destroy_all() renaming patch. Basically this tries to remove
all dummy patched in tools/bootconfig, except include/linux/bootconfig.
This series can be applied on top of 1-3rd patch of this series.
https://lore.kernel.org/all/163177338366.682366.5998343833719057348.stgit@devnote2/T/#u
As I added a NOTE in the bootconfig files, those are not intended to
be used from user application, except for tools/bootconfig. Because
tools/bootconfig runs parser tests, it must use the same code of
lib/bootconfig.
However, I don't want to keep the dummy headers for that. This series
minimize the differences and consolidate it to the one wrapper header.
I hope this eases the current situation so that the future change will
not (or hard to) break tools/bootconfig build.
Thank you,
---
Masami Hiramatsu (7):
tools/bootconfig: Run test script when build all
bootconfig: Rename xbc_destroy_all() to xbc_exit()
bootconfig: Split parse-tree part from xbc_init
bootconfig: Remove unused debug function
tools/bootconfig: Print all error message in stderr
bootconfig: Replace u16 and u32 with uint16_t and uint32_t
bootconfig: Cleanup dummy headers in tools/bootconfig
include/linux/bootconfig.h | 27 ++--
init/main.c | 2
lib/bootconfig.c | 187 +++++++++++++++------------
tools/bootconfig/Makefile | 4 -
tools/bootconfig/include/linux/bootconfig.h | 45 ++++++
tools/bootconfig/include/linux/bug.h | 12 --
tools/bootconfig/include/linux/ctype.h | 7 -
tools/bootconfig/include/linux/errno.h | 7 -
tools/bootconfig/include/linux/kernel.h | 18 ---
tools/bootconfig/include/linux/memblock.h | 11 --
tools/bootconfig/include/linux/printk.h | 14 --
tools/bootconfig/include/linux/string.h | 32 -----
tools/bootconfig/main.c | 25 ++--
13 files changed, 181 insertions(+), 210 deletions(-)
delete mode 100644 tools/bootconfig/include/linux/bug.h
delete mode 100644 tools/bootconfig/include/linux/ctype.h
delete mode 100644 tools/bootconfig/include/linux/errno.h
delete mode 100644 tools/bootconfig/include/linux/kernel.h
delete mode 100644 tools/bootconfig/include/linux/memblock.h
delete mode 100644 tools/bootconfig/include/linux/printk.h
delete mode 100644 tools/bootconfig/include/linux/string.h
--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/7] tools/bootconfig: Run test script when build all
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
@ 2021-09-17 10:02 ` Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 2/7] bootconfig: Rename xbc_destroy_all() to xbc_exit() Masami Hiramatsu
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:02 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Run the bootconfig test script when build all target
so that user can notice any issue when build it.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
tools/bootconfig/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/bootconfig/Makefile b/tools/bootconfig/Makefile
index da5975775337..f1eec3ccbe18 100644
--- a/tools/bootconfig/Makefile
+++ b/tools/bootconfig/Makefile
@@ -15,7 +15,7 @@ CFLAGS = -Wall -g -I$(CURDIR)/include
ALL_TARGETS := bootconfig
ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
-all: $(ALL_PROGRAMS)
+all: $(ALL_PROGRAMS) test
$(OUTPUT)bootconfig: main.c $(LIBSRC)
$(CC) $(filter %.c,$^) $(CFLAGS) -o $@
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/7] bootconfig: Rename xbc_destroy_all() to xbc_exit()
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 1/7] tools/bootconfig: Run test script when build all Masami Hiramatsu
@ 2021-09-17 10:02 ` Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 3/7] bootconfig: Split parse-tree part from xbc_init Masami Hiramatsu
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:02 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Avoid using this noisy name and use more calm one.
This is just a name change. No functional change.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Changes in v5:
- Use _exit suffix instead of _fini.
---
include/linux/bootconfig.h | 2 +-
init/main.c | 2 +-
lib/bootconfig.c | 8 ++++----
tools/bootconfig/main.c | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index f955bb7eabbb..7eb7a7f8ade7 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -277,7 +277,7 @@ int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos);
int __init xbc_get_info(int *node_size, size_t *data_size);
/* XBC cleanup data structures */
-void __init xbc_destroy_all(void);
+void __init xbc_exit(void);
/* Debug dump functions */
void __init xbc_debug_dump(void);
diff --git a/init/main.c b/init/main.c
index 747b4fd38a1a..e5464067ca7a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -463,7 +463,7 @@ static void __init setup_boot_config(void)
static void __init exit_boot_config(void)
{
- xbc_destroy_all();
+ xbc_exit();
}
#else /* !CONFIG_BOOT_CONFIG */
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index b088fe5c0001..a3ce5a0c3ca4 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -802,13 +802,13 @@ static int __init xbc_verify_tree(void)
}
/**
- * xbc_destroy_all() - Clean up all parsed bootconfig
+ * xbc_exit() - Clean up all parsed bootconfig
*
* This clears all data structures of parsed bootconfig on memory.
* If you need to reuse xbc_init() with new boot config, you can
* use this.
*/
-void __init xbc_destroy_all(void)
+void __init xbc_exit(void)
{
memblock_free_ptr(xbc_data, xbc_data_size);
xbc_data = NULL;
@@ -869,7 +869,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
if (!xbc_nodes) {
if (emsg)
*emsg = "Failed to allocate bootconfig nodes";
- xbc_destroy_all();
+ xbc_exit();
return -ENOMEM;
}
memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);
@@ -925,7 +925,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
*epos = xbc_err_pos;
if (emsg)
*emsg = xbc_err_msg;
- xbc_destroy_all();
+ xbc_exit();
} else
ret = xbc_node_num;
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 4f2a8d884745..4252c23bd35d 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -397,7 +397,7 @@ static int apply_xbc(const char *path, const char *xbc_path)
printf("\tChecksum: %d\n", (unsigned int)csum);
/* TODO: Check the options by schema */
- xbc_destroy_all();
+ xbc_exit();
free(buf);
/* Remove old boot config if exists */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/7] bootconfig: Split parse-tree part from xbc_init
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 1/7] tools/bootconfig: Run test script when build all Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 2/7] bootconfig: Rename xbc_destroy_all() to xbc_exit() Masami Hiramatsu
@ 2021-09-17 10:02 ` Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 4/7] bootconfig: Remove unused debug function Masami Hiramatsu
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:02 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Split bootconfig data parser to build tree code from
xbc_init(). This is an internal cosmetic change.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
lib/bootconfig.c | 99 +++++++++++++++++++++++++++++-------------------------
1 file changed, 54 insertions(+), 45 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index a3ce5a0c3ca4..b7e5a32b30d3 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -801,6 +801,58 @@ static int __init xbc_verify_tree(void)
return 0;
}
+/* Need to setup xbc_data and xbc_nodes before call this. */
+static int __init xbc_parse_tree(void)
+{
+ char *p, *q;
+ int ret, c;
+
+ last_parent = NULL;
+ p = xbc_data;
+ do {
+ q = strpbrk(p, "{}=+;:\n#");
+ if (!q) {
+ p = skip_spaces(p);
+ if (*p != '\0')
+ ret = xbc_parse_error("No delimiter", p);
+ break;
+ }
+
+ c = *q;
+ *q++ = '\0';
+ switch (c) {
+ case ':':
+ case '+':
+ if (*q++ != '=') {
+ ret = xbc_parse_error(c == '+' ?
+ "Wrong '+' operator" :
+ "Wrong ':' operator",
+ q - 2);
+ break;
+ }
+ fallthrough;
+ case '=':
+ ret = xbc_parse_kv(&p, q, c);
+ break;
+ case '{':
+ ret = xbc_open_brace(&p, q);
+ break;
+ case '#':
+ q = skip_comment(q);
+ fallthrough;
+ case ';':
+ case '\n':
+ ret = xbc_parse_key(&p, q);
+ break;
+ case '}':
+ ret = xbc_close_brace(&p, q);
+ break;
+ }
+ } while (!ret);
+
+ return ret;
+}
+
/**
* xbc_exit() - Clean up all parsed bootconfig
*
@@ -836,8 +888,7 @@ void __init xbc_exit(void)
*/
int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
{
- char *p, *q;
- int ret, c;
+ int ret;
if (epos)
*epos = -1;
@@ -874,49 +925,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
}
memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);
- last_parent = NULL;
- p = xbc_data;
- do {
- q = strpbrk(p, "{}=+;:\n#");
- if (!q) {
- p = skip_spaces(p);
- if (*p != '\0')
- ret = xbc_parse_error("No delimiter", p);
- break;
- }
-
- c = *q;
- *q++ = '\0';
- switch (c) {
- case ':':
- case '+':
- if (*q++ != '=') {
- ret = xbc_parse_error(c == '+' ?
- "Wrong '+' operator" :
- "Wrong ':' operator",
- q - 2);
- break;
- }
- fallthrough;
- case '=':
- ret = xbc_parse_kv(&p, q, c);
- break;
- case '{':
- ret = xbc_open_brace(&p, q);
- break;
- case '#':
- q = skip_comment(q);
- fallthrough;
- case ';':
- case '\n':
- ret = xbc_parse_key(&p, q);
- break;
- case '}':
- ret = xbc_close_brace(&p, q);
- break;
- }
- } while (!ret);
-
+ ret = xbc_parse_tree();
if (!ret)
ret = xbc_verify_tree();
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/7] bootconfig: Remove unused debug function
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
` (2 preceding siblings ...)
2021-09-17 10:02 ` [PATCH 3/7] bootconfig: Split parse-tree part from xbc_init Masami Hiramatsu
@ 2021-09-17 10:02 ` Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 5/7] tools/bootconfig: Print all error message in stderr Masami Hiramatsu
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:02 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Remove unused xbc_debug_dump() from bootconfig for clean up
the code.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
include/linux/bootconfig.h | 3 ---
lib/bootconfig.c | 21 ---------------------
2 files changed, 24 deletions(-)
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index 7eb7a7f8ade7..85cdfd381877 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -279,7 +279,4 @@ int __init xbc_get_info(int *node_size, size_t *data_size);
/* XBC cleanup data structures */
void __init xbc_exit(void);
-/* Debug dump functions */
-void __init xbc_debug_dump(void);
-
#endif
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index b7e5a32b30d3..953789171858 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -4,15 +4,12 @@
* Masami Hiramatsu <mhiramat@kernel.org>
*/
-#define pr_fmt(fmt) "bootconfig: " fmt
-
#include <linux/bootconfig.h>
#include <linux/bug.h>
#include <linux/ctype.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/memblock.h>
-#include <linux/printk.h>
#include <linux/string.h>
/*
@@ -940,21 +937,3 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
return ret;
}
-
-/**
- * xbc_debug_dump() - Dump current XBC node list
- *
- * Dump the current XBC node list on printk buffer for debug.
- */
-void __init xbc_debug_dump(void)
-{
- int i;
-
- for (i = 0; i < xbc_node_num; i++) {
- pr_debug("[%d] %s (%s) .next=%d, .child=%d .parent=%d\n", i,
- xbc_node_get_data(xbc_nodes + i),
- xbc_node_is_value(xbc_nodes + i) ? "value" : "key",
- xbc_nodes[i].next, xbc_nodes[i].child,
- xbc_nodes[i].parent);
- }
-}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/7] tools/bootconfig: Print all error message in stderr
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
` (3 preceding siblings ...)
2021-09-17 10:02 ` [PATCH 4/7] bootconfig: Remove unused debug function Masami Hiramatsu
@ 2021-09-17 10:03 ` Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 6/7] bootconfig: Replace u16 and u32 with uint16_t and uint32_t Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 7/7] bootconfig: Cleanup dummy headers in tools/bootconfig Masami Hiramatsu
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:03 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Print all error message in stderr. This also removes
unneeded tools/bootconfig/include/linux/printk.h.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
tools/bootconfig/include/linux/kernel.h | 2 --
tools/bootconfig/include/linux/printk.h | 14 --------------
tools/bootconfig/main.c | 2 ++
3 files changed, 2 insertions(+), 16 deletions(-)
delete mode 100644 tools/bootconfig/include/linux/printk.h
diff --git a/tools/bootconfig/include/linux/kernel.h b/tools/bootconfig/include/linux/kernel.h
index 2d93320aa374..c4854b8e7023 100644
--- a/tools/bootconfig/include/linux/kernel.h
+++ b/tools/bootconfig/include/linux/kernel.h
@@ -5,8 +5,6 @@
#include <stdlib.h>
#include <stdbool.h>
-#include <linux/printk.h>
-
typedef unsigned short u16;
typedef unsigned int u32;
diff --git a/tools/bootconfig/include/linux/printk.h b/tools/bootconfig/include/linux/printk.h
deleted file mode 100644
index 036e667596eb..000000000000
--- a/tools/bootconfig/include/linux/printk.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_PRINTK_H
-#define _SKC_LINUX_PRINTK_H
-
-#include <stdio.h>
-
-#define printk(fmt, ...) printf(fmt, ##__VA_ARGS__)
-
-#define pr_err printk
-#define pr_warn printk
-#define pr_info printk
-#define pr_debug printk
-
-#endif
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 4252c23bd35d..adc6c6e73fa9 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -15,6 +15,8 @@
#include <linux/kernel.h>
#include <linux/bootconfig.h>
+#define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
+
static int xbc_show_value(struct xbc_node *node, bool semicolon)
{
const char *val, *eol;
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/7] bootconfig: Replace u16 and u32 with uint16_t and uint32_t
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
` (4 preceding siblings ...)
2021-09-17 10:03 ` [PATCH 5/7] tools/bootconfig: Print all error message in stderr Masami Hiramatsu
@ 2021-09-17 10:03 ` Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 7/7] bootconfig: Cleanup dummy headers in tools/bootconfig Masami Hiramatsu
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:03 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Replace u16 and u32 with uint16_t and uint32_t so
that the tools/bootconfig only needs <stdint.h>.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
include/linux/bootconfig.h | 12 ++++++------
lib/bootconfig.c | 16 ++++++++--------
tools/bootconfig/include/linux/kernel.h | 4 +---
tools/bootconfig/main.c | 20 ++++++++++----------
4 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index 85cdfd381877..a6f8dc51f168 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -25,10 +25,10 @@
* The checksum will be used with the BOOTCONFIG_MAGIC and the size for
* embedding the bootconfig in the initrd image.
*/
-static inline __init u32 xbc_calc_checksum(void *data, u32 size)
+static inline __init uint32_t xbc_calc_checksum(void *data, uint32_t size)
{
unsigned char *p = data;
- u32 ret = 0;
+ uint32_t ret = 0;
while (size--)
ret += *p++;
@@ -38,10 +38,10 @@ static inline __init u32 xbc_calc_checksum(void *data, u32 size)
/* XBC tree node */
struct xbc_node {
- u16 next;
- u16 child;
- u16 parent;
- u16 data;
+ uint16_t next;
+ uint16_t child;
+ uint16_t parent;
+ uint16_t data;
} __attribute__ ((__packed__));
#define XBC_KEY 0
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 953789171858..a2f5f582181d 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -244,7 +244,7 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,
struct xbc_node *node,
char *buf, size_t size)
{
- u16 keys[XBC_DEPTH_MAX];
+ uint16_t keys[XBC_DEPTH_MAX];
int depth = 0, ret = 0, total = 0;
if (!node || node == root)
@@ -359,21 +359,21 @@ const char * __init xbc_node_find_next_key_value(struct xbc_node *root,
/* XBC parse and tree build */
-static int __init xbc_init_node(struct xbc_node *node, char *data, u32 flag)
+static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag)
{
unsigned long offset = data - xbc_data;
if (WARN_ON(offset >= XBC_DATA_MAX))
return -EINVAL;
- node->data = (u16)offset | flag;
+ node->data = (uint16_t)offset | flag;
node->child = 0;
node->next = 0;
return 0;
}
-static struct xbc_node * __init xbc_add_node(char *data, u32 flag)
+static struct xbc_node * __init xbc_add_node(char *data, uint32_t flag)
{
struct xbc_node *node;
@@ -403,7 +403,7 @@ static inline __init struct xbc_node *xbc_last_child(struct xbc_node *node)
return node;
}
-static struct xbc_node * __init __xbc_add_sibling(char *data, u32 flag, bool head)
+static struct xbc_node * __init __xbc_add_sibling(char *data, uint32_t flag, bool head)
{
struct xbc_node *sib, *node = xbc_add_node(data, flag);
@@ -430,17 +430,17 @@ static struct xbc_node * __init __xbc_add_sibling(char *data, u32 flag, bool hea
return node;
}
-static inline struct xbc_node * __init xbc_add_sibling(char *data, u32 flag)
+static inline struct xbc_node * __init xbc_add_sibling(char *data, uint32_t flag)
{
return __xbc_add_sibling(data, flag, false);
}
-static inline struct xbc_node * __init xbc_add_head_sibling(char *data, u32 flag)
+static inline struct xbc_node * __init xbc_add_head_sibling(char *data, uint32_t flag)
{
return __xbc_add_sibling(data, flag, true);
}
-static inline __init struct xbc_node *xbc_add_child(char *data, u32 flag)
+static inline __init struct xbc_node *xbc_add_child(char *data, uint32_t flag)
{
struct xbc_node *node = xbc_add_sibling(data, flag);
diff --git a/tools/bootconfig/include/linux/kernel.h b/tools/bootconfig/include/linux/kernel.h
index c4854b8e7023..39f306c18dd0 100644
--- a/tools/bootconfig/include/linux/kernel.h
+++ b/tools/bootconfig/include/linux/kernel.h
@@ -3,11 +3,9 @@
#define _SKC_LINUX_KERNEL_H
#include <stdlib.h>
+#include <stdint.h>
#include <stdbool.h>
-typedef unsigned short u16;
-typedef unsigned int u32;
-
#define unlikely(cond) (cond)
#define __init
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index adc6c6e73fa9..fb7c9fb953d7 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -178,7 +178,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
{
struct stat stat;
int ret;
- u32 size = 0, csum = 0, rcsum;
+ uint32_t size = 0, csum = 0, rcsum;
char magic[BOOTCONFIG_MAGIC_LEN];
const char *msg;
@@ -202,11 +202,11 @@ static int load_xbc_from_initrd(int fd, char **buf)
if (lseek(fd, -(8 + BOOTCONFIG_MAGIC_LEN), SEEK_END) < 0)
return pr_errno("Failed to lseek for size", -errno);
- if (read(fd, &size, sizeof(u32)) < 0)
+ if (read(fd, &size, sizeof(uint32_t)) < 0)
return pr_errno("Failed to read size", -errno);
size = le32toh(size);
- if (read(fd, &csum, sizeof(u32)) < 0)
+ if (read(fd, &csum, sizeof(uint32_t)) < 0)
return pr_errno("Failed to read checksum", -errno);
csum = le32toh(csum);
@@ -364,7 +364,7 @@ static int apply_xbc(const char *path, const char *xbc_path)
size_t total_size;
struct stat stat;
const char *msg;
- u32 size, csum;
+ uint32_t size, csum;
int pos, pad;
int ret, fd;
@@ -378,7 +378,7 @@ static int apply_xbc(const char *path, const char *xbc_path)
/* Backup the bootconfig data */
data = calloc(size + BOOTCONFIG_ALIGN +
- sizeof(u32) + sizeof(u32) + BOOTCONFIG_MAGIC_LEN, 1);
+ sizeof(uint32_t) + sizeof(uint32_t) + BOOTCONFIG_MAGIC_LEN, 1);
if (!data)
return -ENOMEM;
memcpy(data, buf, size);
@@ -426,17 +426,17 @@ static int apply_xbc(const char *path, const char *xbc_path)
}
/* To align up the total size to BOOTCONFIG_ALIGN, get padding size */
- total_size = stat.st_size + size + sizeof(u32) * 2 + BOOTCONFIG_MAGIC_LEN;
+ total_size = stat.st_size + size + sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN;
pad = ((total_size + BOOTCONFIG_ALIGN - 1) & (~BOOTCONFIG_ALIGN_MASK)) - total_size;
size += pad;
/* Add a footer */
p = data + size;
- *(u32 *)p = htole32(size);
- p += sizeof(u32);
+ *(uint32_t *)p = htole32(size);
+ p += sizeof(uint32_t);
- *(u32 *)p = htole32(csum);
- p += sizeof(u32);
+ *(uint32_t *)p = htole32(csum);
+ p += sizeof(uint32_t);
memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
p += BOOTCONFIG_MAGIC_LEN;
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 7/7] bootconfig: Cleanup dummy headers in tools/bootconfig
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
` (5 preceding siblings ...)
2021-09-17 10:03 ` [PATCH 6/7] bootconfig: Replace u16 and u32 with uint16_t and uint32_t Masami Hiramatsu
@ 2021-09-17 10:03 ` Masami Hiramatsu
6 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2021-09-17 10:03 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linus Torvalds, LKML, Masami Hiramatsu
Cleanup dummy headers in tools/bootconfig/include except
for tools/bootconfig/include/linux/bootconfig.h.
For this change, I uses __KERNEL__ macro to split kernel
header #include and introduce xbc_alloc_mem() and
xbc_free_mem().
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
include/linux/bootconfig.h | 10 ++++++
lib/bootconfig.c | 43 +++++++++++++++++++++++---
tools/bootconfig/Makefile | 2 +
tools/bootconfig/include/linux/bootconfig.h | 45 ++++++++++++++++++++++++++-
tools/bootconfig/include/linux/bug.h | 12 -------
tools/bootconfig/include/linux/ctype.h | 7 ----
tools/bootconfig/include/linux/errno.h | 7 ----
tools/bootconfig/include/linux/kernel.h | 14 --------
tools/bootconfig/include/linux/memblock.h | 11 -------
tools/bootconfig/include/linux/string.h | 32 -------------------
tools/bootconfig/main.c | 1 -
11 files changed, 93 insertions(+), 91 deletions(-)
delete mode 100644 tools/bootconfig/include/linux/bug.h
delete mode 100644 tools/bootconfig/include/linux/ctype.h
delete mode 100644 tools/bootconfig/include/linux/errno.h
delete mode 100644 tools/bootconfig/include/linux/kernel.h
delete mode 100644 tools/bootconfig/include/linux/memblock.h
delete mode 100644 tools/bootconfig/include/linux/string.h
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index a6f8dc51f168..a4665c7ab07c 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -7,8 +7,18 @@
* Author: Masami Hiramatsu <mhiramat@kernel.org>
*/
+#ifdef __KERNEL__
#include <linux/kernel.h>
#include <linux/types.h>
+#else /* !__KERNEL__ */
+/*
+ * NOTE: This is only for tools/bootconfig, because tools/bootconfig will
+ * run the parser sanity test.
+ * This does NOT mean linux/bootconfig.h is available in the user space.
+ * However, if you change this file, please make sure the tools/bootconfig
+ * has no issue on building and running.
+ */
+#endif
#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
#define BOOTCONFIG_MAGIC_LEN 12
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index a2f5f582181d..a056ae137750 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -4,6 +4,7 @@
* Masami Hiramatsu <mhiramat@kernel.org>
*/
+#ifdef __KERNEL__
#include <linux/bootconfig.h>
#include <linux/bug.h>
#include <linux/ctype.h>
@@ -11,6 +12,16 @@
#include <linux/kernel.h>
#include <linux/memblock.h>
#include <linux/string.h>
+#else /* !__KERNEL__ */
+/*
+ * NOTE: This is only for tools/bootconfig, because tools/bootconfig will
+ * run the parser sanity test.
+ * This does NOT mean lib/bootconfig.c is available in the user space.
+ * However, if you change this file, please make sure the tools/bootconfig
+ * has no issue on building and running.
+ */
+#include <linux/bootconfig.h>
+#endif
/*
* Extra Boot Config (XBC) is given as tree-structured ascii text of
@@ -31,6 +42,29 @@ static int xbc_err_pos __initdata;
static int open_brace[XBC_DEPTH_MAX] __initdata;
static int brace_index __initdata;
+#ifdef __KERNEL__
+static inline void *xbc_alloc_mem(size_t size)
+{
+ return memblock_alloc(size, SMP_CACHE_BYTES);
+}
+
+static inline void xbc_free_mem(void *addr, size_t size)
+{
+ memblock_free_ptr(addr, size);
+}
+
+#else /* !__KERNEL__ */
+
+static inline void *xbc_alloc_mem(size_t size)
+{
+ return malloc(size);
+}
+
+static inline void xbc_free_mem(void *addr, size_t size)
+{
+ free(addr);
+}
+#endif
/**
* xbc_get_info() - Get the information of loaded boot config
* node_size: A pointer to store the number of nodes.
@@ -859,11 +893,11 @@ static int __init xbc_parse_tree(void)
*/
void __init xbc_exit(void)
{
- memblock_free_ptr(xbc_data, xbc_data_size);
+ xbc_free_mem(xbc_data, xbc_data_size);
xbc_data = NULL;
xbc_data_size = 0;
xbc_node_num = 0;
- memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
+ xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
xbc_nodes = NULL;
brace_index = 0;
}
@@ -902,7 +936,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
return -ERANGE;
}
- xbc_data = memblock_alloc(size + 1, SMP_CACHE_BYTES);
+ xbc_data = xbc_alloc_mem(size + 1);
if (!xbc_data) {
if (emsg)
*emsg = "Failed to allocate bootconfig data";
@@ -912,8 +946,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
xbc_data[size] = '\0';
xbc_data_size = size + 1;
- xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX,
- SMP_CACHE_BYTES);
+ xbc_nodes = xbc_alloc_mem(sizeof(struct xbc_node) * XBC_NODE_MAX);
if (!xbc_nodes) {
if (emsg)
*emsg = "Failed to allocate bootconfig nodes";
diff --git a/tools/bootconfig/Makefile b/tools/bootconfig/Makefile
index f1eec3ccbe18..566c3e0ee561 100644
--- a/tools/bootconfig/Makefile
+++ b/tools/bootconfig/Makefile
@@ -17,7 +17,7 @@ ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
all: $(ALL_PROGRAMS) test
-$(OUTPUT)bootconfig: main.c $(LIBSRC)
+$(OUTPUT)bootconfig: main.c include/linux/bootconfig.h $(LIBSRC)
$(CC) $(filter %.c,$^) $(CFLAGS) -o $@
test: $(ALL_PROGRAMS) test-bootconfig.sh
diff --git a/tools/bootconfig/include/linux/bootconfig.h b/tools/bootconfig/include/linux/bootconfig.h
index de7f30f99af3..6784296a0692 100644
--- a/tools/bootconfig/include/linux/bootconfig.h
+++ b/tools/bootconfig/include/linux/bootconfig.h
@@ -2,10 +2,53 @@
#ifndef _BOOTCONFIG_LINUX_BOOTCONFIG_H
#define _BOOTCONFIG_LINUX_BOOTCONFIG_H
-#include "../../../../include/linux/bootconfig.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+
#ifndef fallthrough
# define fallthrough
#endif
+#define WARN_ON(cond) \
+ ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \
+ __FILE__, __LINE__, __func__, #cond) : 0)
+
+#define unlikely(cond) (cond)
+
+/* Copied from lib/string.c */
+static inline char *skip_spaces(const char *str)
+{
+ while (isspace(*str))
+ ++str;
+ return (char *)str;
+}
+
+static inline char *strim(char *s)
+{
+ size_t size;
+ char *end;
+
+ size = strlen(s);
+ if (!size)
+ return s;
+
+ end = s + size - 1;
+ while (end >= s && isspace(*end))
+ end--;
+ *(end + 1) = '\0';
+
+ return skip_spaces(s);
+}
+
+#define __init
+#define __initdata
+
+#include "../../../../include/linux/bootconfig.h"
+
#endif
diff --git a/tools/bootconfig/include/linux/bug.h b/tools/bootconfig/include/linux/bug.h
deleted file mode 100644
index 7b65a389c0dd..000000000000
--- a/tools/bootconfig/include/linux/bug.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_BUG_H
-#define _SKC_LINUX_BUG_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define WARN_ON(cond) \
- ((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \
- __FILE__, __LINE__, __func__, #cond) : 0)
-
-#endif
diff --git a/tools/bootconfig/include/linux/ctype.h b/tools/bootconfig/include/linux/ctype.h
deleted file mode 100644
index c56ecc136448..000000000000
--- a/tools/bootconfig/include/linux/ctype.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_CTYPE_H
-#define _SKC_LINUX_CTYPE_H
-
-#include <ctype.h>
-
-#endif
diff --git a/tools/bootconfig/include/linux/errno.h b/tools/bootconfig/include/linux/errno.h
deleted file mode 100644
index 5d9f91ec2fda..000000000000
--- a/tools/bootconfig/include/linux/errno.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_ERRNO_H
-#define _SKC_LINUX_ERRNO_H
-
-#include <asm/errno.h>
-
-#endif
diff --git a/tools/bootconfig/include/linux/kernel.h b/tools/bootconfig/include/linux/kernel.h
deleted file mode 100644
index 39f306c18dd0..000000000000
--- a/tools/bootconfig/include/linux/kernel.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_KERNEL_H
-#define _SKC_LINUX_KERNEL_H
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#define unlikely(cond) (cond)
-
-#define __init
-#define __initdata
-
-#endif
diff --git a/tools/bootconfig/include/linux/memblock.h b/tools/bootconfig/include/linux/memblock.h
deleted file mode 100644
index f2e506f7d57f..000000000000
--- a/tools/bootconfig/include/linux/memblock.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _XBC_LINUX_MEMBLOCK_H
-#define _XBC_LINUX_MEMBLOCK_H
-
-#include <stdlib.h>
-
-#define SMP_CACHE_BYTES 0
-#define memblock_alloc(size, align) malloc(size)
-#define memblock_free_ptr(paddr, size) free(paddr)
-
-#endif
diff --git a/tools/bootconfig/include/linux/string.h b/tools/bootconfig/include/linux/string.h
deleted file mode 100644
index 8267af75153a..000000000000
--- a/tools/bootconfig/include/linux/string.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _SKC_LINUX_STRING_H
-#define _SKC_LINUX_STRING_H
-
-#include <string.h>
-
-/* Copied from lib/string.c */
-static inline char *skip_spaces(const char *str)
-{
- while (isspace(*str))
- ++str;
- return (char *)str;
-}
-
-static inline char *strim(char *s)
-{
- size_t size;
- char *end;
-
- size = strlen(s);
- if (!size)
- return s;
-
- end = s + size - 1;
- while (end >= s && isspace(*end))
- end--;
- *(end + 1) = '\0';
-
- return skip_spaces(s);
-}
-
-#endif
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index fb7c9fb953d7..156b62a163c5 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -12,7 +12,6 @@
#include <errno.h>
#include <endian.h>
-#include <linux/kernel.h>
#include <linux/bootconfig.h>
#define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-09-17 10:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-17 10:02 [PATCH 0/7] bootconfig: Clean up bootconfig Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 1/7] tools/bootconfig: Run test script when build all Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 2/7] bootconfig: Rename xbc_destroy_all() to xbc_exit() Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 3/7] bootconfig: Split parse-tree part from xbc_init Masami Hiramatsu
2021-09-17 10:02 ` [PATCH 4/7] bootconfig: Remove unused debug function Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 5/7] tools/bootconfig: Print all error message in stderr Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 6/7] bootconfig: Replace u16 and u32 with uint16_t and uint32_t Masami Hiramatsu
2021-09-17 10:03 ` [PATCH 7/7] bootconfig: Cleanup dummy headers in tools/bootconfig Masami Hiramatsu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.