Skip to contentSkip to conversation

kexec:arm: support zImage with appended device tree

PATCH Superseded Hoeun Ryu 4 participants 13 messages Jun 23, 2017 – Jul 4, 2017

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hoeun Ryu

author
#0 lore raw

PATCH 1/1 kexec:arm: support zImage with appended device tree

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

This patch is to support the concatednated zImage. This changes the priority of source of dtb file.

1. --dtb dtb_file
2. zImage_w_dtb <= newly added
3. /sys/firmware/fdt
4. /proc/device-tree

Users don't need to specify dtb file in the command line and don't have to have /sys/firmware/fdt or /proc/device-tree if dtb is available in zImage.

---
 kexec/arch/arm/kexec-arm.h        |  1 +
 kexec/arch/arm/kexec-zImage-arm.c | 47 ++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec-arm.h +1 -0
index a74cce2..94695b7 100644
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 
 #define SYSFS_FDT "/sys/firmware/fdt"
+#define APPENDED_FDT ((char *)-1) /* it doesn't mean to be opened. */
 #define BOOT_BLOCK_VERSION 17
 #define BOOT_BLOCK_LAST_COMP_VERSION 16
 
kexec/arch/arm/kexec-zImage-arm.c +36 -11

77 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 10 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

This patch is to support the concatednated zImage. This changes the priority of source of dtb file.

1. --dtb dtb_file
2. zImage_w_dtb <= newly added
3. /sys/firmware/fdt
4. /proc/device-tree

The original default fdt is /sys/firmware/fdt, after your changes it becomes zImage attached dtb, presumably one knows his zImage appended a dtb it is fine, but if one does not notice it, it changes the behavior he expects.

How about add a new option for zImage_dtb, like --zImage-dtb

Quoted 116 lines

Users don't need to specify dtb file in the command line and don't have to have /sys/firmware/fdt or /proc/device-tree if dtb is available in zImage.

---
 kexec/arch/arm/kexec-arm.h        |  1 +
 kexec/arch/arm/kexec-zImage-arm.c | 47 ++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec-arm.h +1 -0
index a74cce2..94695b7 100644
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 
 #define SYSFS_FDT "/sys/firmware/fdt"
+#define APPENDED_FDT ((char *)-1) /* it doesn't mean to be opened. */
 #define BOOT_BLOCK_VERSION 17
 #define BOOT_BLOCK_LAST_COMP_VERSION 16
 
kexec/arch/arm/kexec-zImage-arm.c +36 -11
index 7f02b93..59f0003 100644
@@ -390,6 +390,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	initrd_size = 0;
 	use_atags = 0;
 	dtb_file = NULL;
+	dtb_buf = NULL;
 	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch(opt) {
 		default:
@@ -424,14 +425,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		return -1;
 	}
 
-	if (!use_atags && !dtb_file) {
-		int f;
-
-		f = have_sysfs_fdt();
-		if (f)
-			dtb_file = SYSFS_FDT;
-	}
-
 	if (command_line) {
 		command_line_len = strlen(command_line) + 1;
 		if (command_line_len > COMMAND_LINE_SIZE)
@@ -440,9 +433,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	if (ramdisk)
 		ramdisk_buf = slurp_file(ramdisk, &initrd_size);
 
-	if (dtb_file)
-		dtb_buf = slurp_file(dtb_file, &dtb_length);
-
 	if (len > 0x34) {
 		const struct zimage_header *hdr;
 		off_t size;
@@ -459,6 +449,25 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 				  (unsigned long long)size,
 				  (unsigned long long)len);
 
+			/* check if zImage has an appended dtb */
+			if (!dtb_file) {
+				if (fdt_check_header(buf + size) == 0) {
+					/*
+					 * dtb_file won't be opened. It's set
+					 * just to pass NULL checking.
+					 */
+					dtb_file = APPENDED_FDT;
+					dtb_length = fdt_totalsize(buf + size);
+					dtb_buf = xmalloc(dtb_length);
+					memcpy(dtb_buf, buf+size, dtb_length);
+
+					dbgprintf("found appended dtb, size 0x%llx\n",
+						  (unsigned long long)dtb_length);
+
+
+				}
+			}
+
 			if (size > len) {
 				fprintf(stderr,
 					"zImage is truncated - file 0x%llx vs header 0x%llx\n",
@@ -575,6 +584,22 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		initrd_base = kernel_base + _ALIGN(len * 5, getpagesize());
 	}
 
+	if (!use_atags && !dtb_file) {
+		int f;
+
+		f = have_sysfs_fdt();
+		if (f)
+			dtb_file = SYSFS_FDT;
+	}
+
+	/*
+	 * dtb_buf can be allocated when checking zImage_with_dtb.
+	 * dtb_buf won't be allocated in the logic if dtb_file is handed over
+	 * in argv[].
+	 */
+	if (dtb_file && !dtb_buf)
+		dtb_buf = slurp_file(dtb_file, &dtb_length);
+
 	if (use_atags) {
 		/*
 		 * use ATAGs from /proc/atags
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#2 lore raw
Quoted 14 lines · Dave Young
Quoted 6 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and
the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

Quoted 7 lines

This patch is to support the concatednated zImage. This changes the priority of source of dtb file.

 1. --dtb dtb_file
 2. zImage_w_dtb <= newly added
 3. /sys/firmware/fdt
 4. /proc/device-tree

Quoted 9 lines

The original default fdt is /sys/firmware/fdt, after your changes it becomes zImage attached dtb, presumably one knows his zImage appended a
dtb it is fine, but if one does not notice it, it changes the behavior
he expects.

How about add a new option for zImage_dtb, like --zImage-dtb

It sounds good to me too.
I think I can accept your suggestion in the next version if the others agree.

Thank you for the review.

Quoted 124 lines
Quoted 124 lines

Users don't need to specify dtb file in the command line and don't have to
have /sys/firmware/fdt or /proc/device-tree if dtb is available in zImage.

---
 kexec/arch/arm/kexec-arm.h        |  1 +
 kexec/arch/arm/kexec-zImage-arm.c | 47
++++++++++++++++++++++++++++++---------

 2 files changed, 37 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec- renamed from kexec/arch/arm/kexec-arm.h +0 -0

arm.h
index a74cce2..94695b7 100644

kexec/arch/arm/kexec-arm.h +0 -0
@@ -4,6 +4,7 @@
  #include <sys/types.h>


 #define SYSFS_FDT "/sys/firmware/fdt"
+#define APPENDED_FDT ((char *)-1) /* it doesn't mean to be opened. */
 #define BOOT_BLOCK_VERSION 17
 #define BOOT_BLOCK_LAST_COMP_VERSION 16

kexec/arch/arm/kexec-zImage-arm.c +1 -0
index 7f02b93..59f0003 100644
@@ -390,6 +390,7 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  	initrd_size = 0;
  	use_atags = 0;
  	dtb_file = NULL;
+	dtb_buf = NULL;
  	while((opt = getopt_long(argc, argv, short_options,
 options, 0)) != -1) {

  switch(opt) {
  default:

kexec/arch/arm/kexec-zImage-arm.c +0 -0
@@ -424,14 +425,6 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  		return -1;
  	}

kexec/arch/arm/kexec-zImage-arm.c +0 -8
-	if (!use_atags && !dtb_file) {
-		int f;
-
-		f = have_sysfs_fdt();
-		if (f)
-			dtb_file = SYSFS_FDT;
-	}
-

  if (command_line) {
  command_line_len = strlen(command_line) + 1; if (command_line_len > COMMAND_LINE_SIZE)

kexec/arch/arm/kexec-zImage-arm.c +0 -0
@@ -440,9 +433,6 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  	if (ramdisk)
  		ramdisk_buf = slurp_file(ramdisk, &initrd_size);

kexec/arch/arm/kexec-zImage-arm.c +0 -3
-	if (dtb_file)
-		dtb_buf = slurp_file(dtb_file, &dtb_length);
-

  if (len > 0x34) {
  const struct zimage_header *hdr;
  off_t size;

kexec/arch/arm/kexec-zImage-arm.c +0 -0
@@ -459,6 +449,25 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  				  (unsigned long long)size,
  				  (unsigned long long)len);

kexec/arch/arm/kexec-zImage-arm.c +3 -0
+			/* check if zImage has an appended dtb */
+			if (!dtb_file) {
+				if (fdt_check_header(buf + size)

== 0) {

kexec/arch/arm/kexec-zImage-arm.c +2 -0
+					/*
+					 * dtb_file won't be

opened. It's set

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					 * just to pass NULL

checking.

kexec/arch/arm/kexec-zImage-arm.c +3 -0
+					 */
+					dtb_file = APPENDED_FDT;
+					dtb_length =

fdt_totalsize(buf + size);

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					dtb_buf =

xmalloc(dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					memcpy(dtb_buf, buf+size,

dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +2 -0
+
+					dbgprintf("found appended

dtb, size 0x%llx\n",

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+						  (unsigned long

long)dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +5 -0
+
+
+				}
+			}
+

  if (size > len) { fprintf(stderr, "zImage is truncated - file 0x%llx vs header 0x%llx\n",

kexec/arch/arm/kexec-zImage-arm.c +0 -0
@@ -575,6 +584,22 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  		initrd_base = kernel_base + _ALIGN(len * 5,
 getpagesize());
  	}

kexec/arch/arm/kexec-zImage-arm.c +11 -0
+	if (!use_atags && !dtb_file) {
+		int f;
+
+		f = have_sysfs_fdt();
+		if (f)
+			dtb_file = SYSFS_FDT;
+	}
+
+	/*
+	 * dtb_buf can be allocated when checking zImage_with_dtb.
+	 * dtb_buf won't be allocated in the logic if dtb_file is

handed over

Quoted 8 lines
Quoted 8 lines
kexec/arch/arm/kexec-zImage-arm.c +5 -0
+	 * in argv[].
+	 */
+	if (dtb_file && !dtb_buf)
+		dtb_buf = slurp_file(dtb_file, &dtb_length);
+

  if (use_atags) {
  /*
   * use ATAGs from /proc/atags

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
In reply to Hoeun Ryu
Quoted 2 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

We support that only for the purpose of allowing old boot loaders that are not DT aware to load kernels that require DT. If it weren't for that, we wouldn't have it.

I don't see why we should propagate this hack to other systems such as kexec, especially when they have native DT support.

Signature · 6 lines
Russell King

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
author
#4 lore raw
Quoted 6 lines · Russell King
Quoted 5 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and
the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

Quoted 9 lines

We support that only for the purpose of allowing old boot loaders that
are not DT aware to load kernels that require DT.  If it weren't for that, we wouldn't have it.

I don't see why we should propagate this hack to other systems such as
kexec, especially when they have native DT support.

We have some cases when we would like to use different dtb from the running system when using kexec and I think that's why kexec-tools supports --dtb command line option.

For example, I have the second kernel for the crash dump with different kernel configuration and the different dtb from the running system. I'd like to exclude some nodes/properties from dtb like memory reservations or unnecessary devices to keep the second kernel/dtb minimal.

The concatenated zImage for arm has a benefit (whether it's intended or not) to make it possible for users to merge multiple boot images into a simple single file.
What I'd like to do is just to support the concatenated zImage so that users can use --load(-panic) zImage_with_dtb_from_the_running_system instead of --load(-panic) zImage --dtb different_dtb_from_the_running_system.

Thank you for the review.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw
Quoted 9 lines · Hoeun Ryu

We have some cases when we would like to use different dtb from the running system when using kexec and I think that's why kexec-tools supports --dtb command line option.

For example, I have the second kernel for the crash dump with different kernel configuration and the different dtb from the running system. I'd like to exclude some nodes/properties from dtb like memory reservations or unnecessary devices to keep the second kernel/dtb minimal.

Quoted 7 lines

The concatenated zImage for arm has a benefit (whether it's intended or not) to make it possible for users to merge multiple boot images into a simple single file.
What I'd like to do is just to support the concatenated zImage so that users can use --load(-panic) zImage_with_dtb_from_the_running_system instead of --load(-panic) zImage --dtb different_dtb_from_the_running_system.

Don't you mean --load(-panic) zImage_with_different_dtb_from_the_running_system ?

So, what you seem to be saying is that you think it's easier for the user to do this:

# cat zImage some-other-dtb > zImage.dtb
# kexec --load-panic zImage.dtb

rather than:

# kexec --load-panic zImage --dtb some-other-dtb

?

What about the initrd? Do you want to append that as well?

Signature · 6 lines
Russell King

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
author
#6 lore raw
Quoted 21 lines · Russell King
Quoted 11 lines · Hoeun Ryu

We have some cases when we would like to use different dtb from the running system when using kexec and I think that's why kexec-tools supports --dtb command line option.

For example, I have the second kernel for the crash dump with different kernel configuration and the different dtb from the running system. I'd like to exclude some nodes/properties from dtb like memory reservations or unnecessary devices to keep the second kernel/dtb minimal.

Quoted 7 lines

The concatenated zImage for arm has a benefit (whether it's intended or not) to make it possible for users to merge multiple boot images into a simple single file.
What I'd like to do is just to support the concatenated zImage so that users can use --load(-panic) zImage_with_dtb_from_the_running_system instead of --load(-panic) zImage --dtb different_dtb_from_the_running_system.

Quoted 3 lines

Don't you mean --load(-panic) zImage_with_different_dtb_from_the_running_system ?

I'm sorry. This is what I mean.

Quoted 11 lines

So, what you seem to be saying is that you think it's easier for the user to do this:

# cat zImage some-other-dtb > zImage.dtb
# kexec --load-panic zImage.dtb

rather than:

# kexec --load-panic zImage --dtb some-other-dtb

?

Right.

Quoted 1 line

What about the initrd? Do you want to append that as well?

I have thought of it.
I think It would be better to have it.
But I think this is the first step to do so.

Quoted 3 lines
Signature · 2 lines
-- 
Russell King

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw
Quoted 5 lines · Hoeun Ryu
Quoted 1 line

What about the initrd? Do you want to append that as well?

I have thought of it.
I think It would be better to have it.
But I think this is the first step to do so.

That is something we don't support with the kernel, and would be insane to do so - it would mean that the very dumb decompressor would have to relocate not only the dtb image, but also the initrd image to some other part of memory. It moves the appended dtb image along with the rest of the zImage as one complete blob, but that doesn't work so well for an appended initrd. It will also be rather slow.

So I'd like to continue my discouragement of this entire approach and say that kexec-tools should *not* add support for an appended DTB nor an appended initrd.

The kernel build process gives you the kernel image and dtb file. The appended-dtb image support that we have in the kernel is for backwards compatibility with non-DT aware boot loaders that only know how to deal with one or two images at boot time.

Signature · 6 lines
Russell King

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#8 lore raw
Quoted 14 lines · Russell King
Quoted 5 lines · Hoeun Ryu
Quoted 1 line

What about the initrd? Do you want to append that as well?

I have thought of it.
I think It would be better to have it.
But I think this is the first step to do so.

That is something we don't support with the kernel, and would be insane to do so - it would mean that the very dumb decompressor would have to relocate not only the dtb image, but also the initrd image to some other part of memory. It moves the appended dtb image along with the rest of the zImage as one complete blob, but that doesn't work so well for an appended initrd. It will also be rather slow.

Quoted 3 lines

So I'd like to continue my discouragement of this entire approach and say that kexec-tools should *not* add support for an appended DTB nor an appended initrd.

I also agree that we'd better not adding this in kexec-tools, --dtb works well, the appended dtb does not gain much but it introduces more code to maintain.

Quoted 8 lines

The kernel build process gives you the kernel image and dtb file. The appended-dtb image support that we have in the kernel is for backwards compatibility with non-DT aware boot loaders that only know how to deal with one or two images at boot time.

Signature · 1 line
Russell King

Thanks
Dave

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#9 lore raw
Quoted 23 lines · Dave Young
Quoted 17 lines · Russell King
Quoted 6 lines · Hoeun Ryu
Quoted 3 lines

What about the initrd?  Do you want to append that as well?

I have thought of it.
I think It would be better to have it.
But I think this is the first step to do so.

That is something we don't support with the kernel, and would be insane
to do so - it would mean that the very dumb decompressor would have to relocate not only the dtb image, but also the initrd image to some other part of memory.  It moves the appended dtb image along with
the rest of the zImage as one complete blob, but that doesn't work so well for an appended initrd.  It will also be rather slow.

Quoted 5 lines

So I'd like to continue my discouragement of this entire approach and
say that kexec-tools should *not* add support for an appended DTB nor
an appended initrd.

Quoted 5 lines

I also agree that we'd better not adding this in kexec-tools, --dtb works well, the appended dtb does not gain much but it introduces more
code to maintain.

I understand and respect your opinion.
Thank you for the review.

Quoted 7 lines
Quoted 7 lines

The kernel build process gives you the kernel image and dtb file. The appended-dtb image support that we have in the kernel is for backwards compatibility with non-DT aware boot loaders that only know how to deal with one or two images at boot time.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#10 lore raw
In reply to Russell King
Quoted 16 lines · Russell King
Quoted 6 lines · Hoeun Ryu
Quoted 3 lines

What about the initrd?  Do you want to append that as well?

I have thought of it.
I think It would be better to have it.
But I think this is the first step to do so.

That is something we don't support with the kernel, and would be insane
to do so - it would mean that the very dumb decompressor would have to relocate not only the dtb image, but also the initrd image to some other part of memory.  It moves the appended dtb image along with
the rest of the zImage as one complete blob, but that doesn't work so well for an appended initrd.  It will also be rather slow.

Quoted 9 lines

So I'd like to continue my discouragement of this entire approach and say that kexec-tools should *not* add support for an appended DTB nor an appended initrd.

The kernel build process gives you the kernel image and dtb file. The appended-dtb image support that we have in the kernel is for backwards compatibility with non-DT aware boot loaders that only know how to deal with one or two images at boot time.

I understand and respect your opinion.
Thank you for the review.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#11 lore raw
In reply to Hoeun Ryu
Quoted 6 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

This patch is to support the concatednated zImage. This changes the priority of source of dtb file.

Quoted 7 lines

1. --dtb dtb_file
2. zImage_w_dtb <= newly added
3. /sys/firmware/fdt
4. /proc/device-tree

Users don't need to specify dtb file in the command line and don't have to have /sys/firmware/fdt or /proc/device-tree if dtb is available in zImage.

any specific reason to not to add the new method as last preferred option? Does it not work if there exist a /sys/firmware/fdt in case of a kernel booted with "dtb appended zImage"?

Quoted 57 lines
---
 kexec/arch/arm/kexec-arm.h        |  1 +
 kexec/arch/arm/kexec-zImage-arm.c | 47 ++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec-arm.h +1 -0
index a74cce2..94695b7 100644
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 
 #define SYSFS_FDT "/sys/firmware/fdt"
+#define APPENDED_FDT ((char *)-1) /* it doesn't mean to be opened. */
 #define BOOT_BLOCK_VERSION 17
 #define BOOT_BLOCK_LAST_COMP_VERSION 16
 
kexec/arch/arm/kexec-zImage-arm.c +1 -11
index 7f02b93..59f0003 100644
@@ -390,6 +390,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	initrd_size = 0;
 	use_atags = 0;
 	dtb_file = NULL;
+	dtb_buf = NULL;
 	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch(opt) {
 		default:
@@ -424,14 +425,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		return -1;
 	}
 
-	if (!use_atags && !dtb_file) {
-		int f;
-
-		f = have_sysfs_fdt();
-		if (f)
-			dtb_file = SYSFS_FDT;
-	}
-
 	if (command_line) {
 		command_line_len = strlen(command_line) + 1;
 		if (command_line_len > COMMAND_LINE_SIZE)
@@ -440,9 +433,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	if (ramdisk)
 		ramdisk_buf = slurp_file(ramdisk, &initrd_size);
 
-	if (dtb_file)
-		dtb_buf = slurp_file(dtb_file, &dtb_length);
-
 	if (len > 0x34) {
 		const struct zimage_header *hdr;
 		off_t size;

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, · line 454

Quoted 6 lines
kexec/arch/arm/kexec-zImage-arm.c +3 -0
@@ -459,6 +449,25 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 				  (unsigned long long)size,
 				  (unsigned long long)len);
 
+			/* check if zImage has an appended dtb */
+			if (!dtb_file) {
+				if (fdt_check_header(buf + size) == 0) {

What if size >= len? I think, in that case there might not be a valid address at buf+size and reading those area would lead in segmentation fault.

Quoted 33 lines
kexec/arch/arm/kexec-zImage-arm.c +25 -0
+					/*
+					 * dtb_file won't be opened. It's set
+					 * just to pass NULL checking.
+					 */
+					dtb_file = APPENDED_FDT;
+					dtb_length = fdt_totalsize(buf + size);
+					dtb_buf = xmalloc(dtb_length);
+					memcpy(dtb_buf, buf+size, dtb_length);
+
+					dbgprintf("found appended dtb, size 0x%llx\n",
+						  (unsigned long long)dtb_length);
+
+
+				}
+			}
+
 			if (size > len) {
 				fprintf(stderr,
 					"zImage is truncated - file 0x%llx vs header 0x%llx\n",
@@ -575,6 +584,22 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		initrd_base = kernel_base + _ALIGN(len * 5, getpagesize());
 	}
 
+	if (!use_atags && !dtb_file) {
+		int f;
+
+		f = have_sysfs_fdt();
+		if (f)
+			dtb_file = SYSFS_FDT;
+	}
+
+	/*

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, · line 605

Quoted 10 lines
kexec/arch/arm/kexec-zImage-arm.c +7 -0
+	 * dtb_buf can be allocated when checking zImage_with_dtb.
+	 * dtb_buf won't be allocated in the logic if dtb_file is handed over
+	 * in argv[].
+	 */
+	if (dtb_file && !dtb_buf)
+		dtb_buf = slurp_file(dtb_file, &dtb_length);
+
 	if (use_atags) {
 		/*
 		 * use ATAGs from /proc/atags

--
Pratyush

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#12 lore raw
Quoted 20 lines · Pratyush Anand
Quoted 14 lines · Hoeun Ryu

Arm linux supports zImage with appended dtb (CONFIG_ARM_APPENDED_DTB) and
the concatenated image is generated like cat zImage dtb > zImage_w_dtb.

This patch is to support the concatednated zImage. This changes the priority of source of dtb file.

 1. --dtb dtb_file
 2. zImage_w_dtb <= newly added
 3. /sys/firmware/fdt
 4. /proc/device-tree

Quoted 4 lines

Users don't need to specify dtb file in the command line and don't have to
have /sys/firmware/fdt or /proc/device-tree if dtb is available in zImage.

Quoted 6 lines

any specific reason to not to add the new method as last preferred option?
Does it not work if there exist a /sys/firmware/fdt in case of a kernel booted
with "dtb appended zImage"?

I thought that DTBs from command line should be priotized over /sys or /proc.
What I intended is to use command line --load(-panic) zImage_with_dtb instead of --load(-panic) zImage --dtb dtb_file.
So I thought they should have the identical priority in both cases.

Quoted 69 lines
Quoted 69 lines

---
 kexec/arch/arm/kexec-arm.h        |  1 +
 kexec/arch/arm/kexec-zImage-arm.c | 47
++++++++++++++++++++++++++++++---------

 2 files changed, 37 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec- renamed from kexec/arch/arm/kexec-arm.h +0 -0

arm.h
index a74cce2..94695b7 100644

kexec/arch/arm/kexec-arm.h +1 -0
@@ -4,6 +4,7 @@
  #include <sys/types.h>
 
  #define SYSFS_FDT "/sys/firmware/fdt"
+#define APPENDED_FDT ((char *)-1) /* it doesn't mean to be opened.
 */
  #define BOOT_BLOCK_VERSION 17
  #define BOOT_BLOCK_LAST_COMP_VERSION 16
kexec/arch/arm/kexec-zImage-arm.c +1 -0
index 7f02b93..59f0003 100644
@@ -390,6 +390,7 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  	initrd_size = 0;
  	use_atags = 0;
  	dtb_file = NULL;
+	dtb_buf = NULL;
  	while((opt = getopt_long(argc, argv, short_options,
 options, 0)) != -1) {

  switch(opt) {
  default:

kexec/arch/arm/kexec-zImage-arm.c +0 -8
@@ -424,14 +425,6 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  		return -1;
  	}
 
-	if (!use_atags && !dtb_file) {
-		int f;
-
-		f = have_sysfs_fdt();
-		if (f)
-			dtb_file = SYSFS_FDT;
-	}
-
  	if (command_line) {
  		command_line_len = strlen(command_line) + 1;

  if (command_line_len > COMMAND_LINE_SIZE)

kexec/arch/arm/kexec-zImage-arm.c +0 -3
@@ -440,9 +433,6 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  	if (ramdisk)
  		ramdisk_buf = slurp_file(ramdisk, &initrd_size);
 
-	if (dtb_file)
-		dtb_buf = slurp_file(dtb_file, &dtb_length);
-
  	if (len > 0x34) {
  		const struct zimage_header *hdr;

  off_t size;

kexec/arch/arm/kexec-zImage-arm.c +0 -0
@@ -459,6 +449,25 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  				  (unsigned long long)size,
  				  (unsigned long long)len);
 
Quoted 8 lines

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,

Quoted 4 lines
kexec/arch/arm/kexec-zImage-arm.c +3 -0
+			/* check if zImage has an appended dtb */
+			if (!dtb_file) {
+				if (fdt_check_header(buf + size)
 == 0) {

What if size >= len? I think, in that case there might not be a valid address
at buf+size and reading those area would lead in segmentation fault.

Oh. I'll fix the bug in the next version.

Thank you for the review.

Quoted 49 lines
Quoted 49 lines
kexec/arch/arm/kexec-zImage-arm.c +2 -0
+					/*
+					 * dtb_file won't be

opened. It's set

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					 * just to pass NULL

checking.

kexec/arch/arm/kexec-zImage-arm.c +3 -0
+					 */
+					dtb_file = APPENDED_FDT;
+					dtb_length =

fdt_totalsize(buf + size);

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					dtb_buf =

xmalloc(dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+					memcpy(dtb_buf, buf+size,

dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +2 -0
+
+					dbgprintf("found appended

dtb, size 0x%llx\n",

kexec/arch/arm/kexec-zImage-arm.c +1 -0
+						  (unsigned long

long)dtb_length);

kexec/arch/arm/kexec-zImage-arm.c +5 -0
+
+
+				}
+			}
+

  if (size > len) { fprintf(stderr, "zImage is truncated - file 0x%llx vs header 0x%llx\n",

kexec/arch/arm/kexec-zImage-arm.c +11 -0
@@ -575,6 +584,22 @@ int zImage_arm_load(int argc, char **argv,
 const char *buf, off_t len,
  		initrd_base = kernel_base + _ALIGN(len * 5,
 getpagesize());
  	}
 
+	if (!use_atags && !dtb_file) {
+		int f;
+
+		f = have_sysfs_fdt();
+		if (f)
+			dtb_file = SYSFS_FDT;
+	}
+
+	/*
+	 * dtb_buf can be allocated when checking zImage_with_dtb.
+	 * dtb_buf won't be allocated in the logic if dtb_file is

handed over

kexec/arch/arm/kexec-zImage-arm.c +3 -0
+	 * in argv[].
+	 */
+	if (dtb_file && !dtb_buf)
Quoted 8 lines
Quoted 6 lines
kexec/arch/arm/kexec-zImage-arm.c +2 -0
+		dtb_buf = slurp_file(dtb_file, &dtb_length);
+

  if (use_atags) {
  /*
   * use ATAGs from /proc/atags

--
Pratyush

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec