Skip to content

Commit

Permalink
tools/bootconfig: Store size and checksum in footer as le32
Browse files Browse the repository at this point in the history
Store the size and the checksum fields in the footer as le32
instead of u32. This will allow us to apply bootconfig to the
cross build initrd without caring the endianness.

Link: https://lkml.kernel.org/r/160583935332.547349.5897811300636587426.stgit@devnote2

Reported-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Masami Hiramatsu authored and Steven Rostedt (VMware) committed Dec 1, 2020
1 parent 24aed09 commit e868435
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/bootconfig/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <endian.h>

#include <linux/kernel.h>
#include <linux/bootconfig.h>
Expand Down Expand Up @@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf)

if (read(fd, &size, sizeof(u32)) < 0)
return pr_errno("Failed to read size", -errno);
size = le32toh(size);

if (read(fd, &csum, sizeof(u32)) < 0)
return pr_errno("Failed to read checksum", -errno);
csum = le32toh(csum);

/* Wrong size error */
if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) {
Expand Down Expand Up @@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path)

/* Add a footer */
p = data + size;
*(u32 *)p = size;
*(u32 *)p = htole32(size);
p += sizeof(u32);

*(u32 *)p = csum;
*(u32 *)p = htole32(csum);
p += sizeof(u32);

memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
Expand Down

0 comments on commit e868435

Please sign in to comment.