Commit e8684358 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

tools/bootconfig: Store size and checksum in footer as le32

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@devnote2Reported-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 24aed094
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <endian.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/bootconfig.h> #include <linux/bootconfig.h>
...@@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf) ...@@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf)
if (read(fd, &size, sizeof(u32)) < 0) if (read(fd, &size, sizeof(u32)) < 0)
return pr_errno("Failed to read size", -errno); return pr_errno("Failed to read size", -errno);
size = le32toh(size);
if (read(fd, &csum, sizeof(u32)) < 0) if (read(fd, &csum, sizeof(u32)) < 0)
return pr_errno("Failed to read checksum", -errno); return pr_errno("Failed to read checksum", -errno);
csum = le32toh(csum);
/* Wrong size error */ /* Wrong size error */
if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) { if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) {
...@@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path) ...@@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path)
/* Add a footer */ /* Add a footer */
p = data + size; p = data + size;
*(u32 *)p = size; *(u32 *)p = htole32(size);
p += sizeof(u32); p += sizeof(u32);
*(u32 *)p = csum; *(u32 *)p = htole32(csum);
p += sizeof(u32); p += sizeof(u32);
memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment