Skip to content

Commit e868435

Browse files
mhiramatrostedt
authored andcommitted
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@devnote2 Reported-by: Steven Rostedt <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 24aed09 commit e868435

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/bootconfig/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <unistd.h>
1111
#include <string.h>
1212
#include <errno.h>
13+
#include <endian.h>
1314

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

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

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

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

408411
/* Add a footer */
409412
p = data + size;
410-
*(u32 *)p = size;
413+
*(u32 *)p = htole32(size);
411414
p += sizeof(u32);
412415

413-
*(u32 *)p = csum;
416+
*(u32 *)p = htole32(csum);
414417
p += sizeof(u32);
415418

416419
memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);

0 commit comments

Comments
 (0)