1 |
From e86843580d1bb1ce12544bca3115cf11d51603ff Mon Sep 17 00:00:00 2001 |
2 |
From: Masami Hiramatsu <mhiramat@kernel.org> |
3 |
Date: Fri, 20 Nov 2020 11:29:13 +0900 |
4 |
Subject: [PATCH 147/150] tools/bootconfig: Store size and checksum in footer |
5 |
as le32 |
6 |
|
7 |
Store the size and the checksum fields in the footer as le32 |
8 |
instead of u32. This will allow us to apply bootconfig to the |
9 |
cross build initrd without caring the endianness. |
10 |
|
11 |
Link: https://lkml.kernel.org/r/160583935332.547349.5897811300636587426.stgit@devnote2 |
12 |
|
13 |
Reported-by: Steven Rostedt <rostedt@goodmis.org> |
14 |
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> |
15 |
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> |
16 |
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> |
17 |
--- |
18 |
tools/bootconfig/main.c | 7 +++++-- |
19 |
1 file changed, 5 insertions(+), 2 deletions(-) |
20 |
|
21 |
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c |
22 |
index 4a445b6304bb..7362bef1a368 100644 |
23 |
--- a/tools/bootconfig/main.c |
24 |
+++ b/tools/bootconfig/main.c |
25 |
@@ -10,6 +10,7 @@ |
26 |
#include <unistd.h> |
27 |
#include <string.h> |
28 |
#include <errno.h> |
29 |
+#include <endian.h> |
30 |
|
31 |
#include <linux/kernel.h> |
32 |
#include <linux/bootconfig.h> |
33 |
@@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf) |
34 |
|
35 |
if (read(fd, &size, sizeof(u32)) < 0) |
36 |
return pr_errno("Failed to read size", -errno); |
37 |
+ size = le32toh(size); |
38 |
|
39 |
if (read(fd, &csum, sizeof(u32)) < 0) |
40 |
return pr_errno("Failed to read checksum", -errno); |
41 |
+ csum = le32toh(csum); |
42 |
|
43 |
/* Wrong size error */ |
44 |
if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) { |
45 |
@@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path) |
46 |
|
47 |
/* Add a footer */ |
48 |
p = data + size; |
49 |
- *(u32 *)p = size; |
50 |
+ *(u32 *)p = htole32(size); |
51 |
p += sizeof(u32); |
52 |
|
53 |
- *(u32 *)p = csum; |
54 |
+ *(u32 *)p = htole32(csum); |
55 |
p += sizeof(u32); |
56 |
|
57 |
memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); |
58 |
-- |
59 |
2.29.2 |
60 |
|