bootconfig: Updates for 5.10
Subsystems (2)
cover bootconfig: Updates for 5.10
Masami Hiramatsu (3):
bootconfig: Load size and checksum in the footer as le32 tools/bootconfig: Store size and checksum in footer as le32
docs: bootconfig: Add the endianness of fields
----
Documentation/admin-guide/bootconfig.rst | 4 +++- init/main.c | 4 ++-- tools/bootconfig/main.c | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-)
PATCH 1/3 bootconfig: Load size and checksum in the footer as le32
From: Masami Hiramatsu <[email protected]>
Load 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.
--- init/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
init/main.c +2 -2
@@ -288,8 +288,8 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) found: hdr = (u32 *)(data -8 ); - size = hdr[0 ]; - csum = hdr[1 ]; + size =le32_to_cpu (hdr[0 ]); + csum =le32_to_cpu (hdr[1 ]); data = ((void *)hdr) - size;if ((unsigned long )data < initrd_start) {
Signature · 1 line
2.28.0
PATCH 2/3 tools/bootconfig: Store size and checksum in footer as le32
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
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.
--- tools/bootconfig/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/bootconfig/main.c +5 -2
@@ -10,6 +10,7 @@#include <unistd.h> #include <string.h> #include <errno.h> +#include <endian.h> #include <linux/kernel.h> #include <linux/bootconfig.h>
@@ -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 ) {
@@ -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 );
Signature · 1 line
2.28.0
PATCH 3/3 docs: bootconfig: Add the endianness of fields
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add a description about the endianness of the size and the checksum fields. Those must be stored as le32 instead of u32. This will allow us to apply bootconfig to the cross build initrd without caring the endianness.
--- Documentation/admin-guide/bootconfig.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/admin-guide/bootconfig.rst +3 -1
@@ -140,7 +140,9 @@ Since the boot configuration file is loaded with initrd, it will be added to the end of the initrd (initramfs) image file with padding, size, checksum and 12-byte magic word as below. -[initrd][bootconfig][padding][size(u32)][checksum(u32)][#BOOTCONFIG\n] +[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n] + +The size and checksum fields are unsigned 32bit little endian value. When the boot configuration is added to the initrd image, the total file size is aligned to 4 bytes. To fill the gap, null characters
Signature · 1 line
2.28.0