Skip to contentSkip to conversation

of/fdt: add kernel command line option for dtb_compat string

PATCH In review [email protected] 3 participants 11 messages Dec 6, 2010 – Dec 30, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/fdt: add kernel command line option for dtb_compat string

From: Dirk Brandewie <[email protected]>

Adds a kernel command line option "dtb_compat=<string>". This string will be used to select the first compatible device tree blob linked into the kernel if a device tree blob is was *not* passed in by the bootloader.

---
 Documentation/kernel-parameters.txt |    8 ++++++
 drivers/of/fdt.c                    |   48 +++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
Documentation/kernel-parameters.txt +8 -0
index 92e83e5..64093e5 100644
@@ -655,6 +655,14 @@ and is between 256 and 4096 characters. It is defined in the file
 
 	dscc4.setup=	[NET]
 
+	dtb_compat=	[KNL]
+			Specify the "compatible" string for the device
+			tree blob present in the vmlinux image.  This
+			string will be used to select the first device
+			tree blob whose compatible property matches
+			the string if a dtb was NOT passed in by the
+			bootloader.
+
 	dynamic_printk	Enables pr_debug()/dev_dbg() calls if
 			CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
 			These can also be switched on/off via
drivers/of/fdt.c +48 -0

57 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 4 lines

-----Original Message-----
From:

devicetree-discuss-bounces+stephen.neuendorffer=xilinx.com@lists.ozlabs. org [mailto:devicetree-

Quoted 1 line

[email protected]] On

Behalf Of

Quoted 4 lines

[email protected]
Sent: Monday, December 06, 2010 9:54 AM
To: [email protected]
Cc: Randy Dunlap; [email protected];

[email protected]

Quoted 1 line

Subject: [PATCH] of/fdt: add kernel command line option for dtb_compat

string

Quoted 8 lines

From: Dirk Brandewie <[email protected]>

Adds a kernel command line option "dtb_compat=<string>". This string will be used to select the first compatible device tree blob linked into the kernel if a device tree blob is was *not* passed in by the bootloader.

Quoted 4 lines
---
 Documentation/kernel-parameters.txt |    8 ++++++
 drivers/of/fdt.c                    |   48

+++++++++++++++++++++++++++++++++++

Review

Quoted 3 lines
 2 files changed, 56 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt and is between 256 and 4096 characters. It is

Quoted 4 lines

index 92e83e5..64093e5 100644

Documentation/kernel-parameters.txt +0 -0
@@ -655,6 +655,14 @@ and is between 256 and 4096 characters. It is

defined in the file

Quoted 34 lines
Documentation/kernel-parameters.txt +8 -0
 	dscc4.setup=	[NET]
 
+	dtb_compat=	[KNL]
+			Specify the "compatible" string for the device
+			tree blob present in the vmlinux image.  This
+			string will be used to select the first device
+			tree blob whose compatible property matches
+			the string if a dtb was NOT passed in by the
+			bootloader.
+
 	dynamic_printk	Enables pr_debug()/dev_dbg() calls if
 			CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
 			These can also be switched on/off via
drivers/of/fdt.c +5 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include <linux/of_fdt.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include <asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 	pr_debug(" <- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 10 lines
drivers/of/fdt.c +10 -0
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+	void *rc = NULL;
+	unsigned long root, size;
+	struct boot_param_header  *orig_initial_boot_params;
+	uint8_t *blob;
+
+	orig_initial_boot_params = initial_boot_params;
+	blob = __dtb_start;
+	initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using of_fdt_is_compatible() from my recent set of patches?
It takes a blob argument. Then the loop below goes away.

Steve

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 4 lines
drivers/of/fdt.c +4 -0
+
+
+	while (blob < __dtb_end) {
+		if (be32_to_cpu(initial_boot_params->magic) !=

OF_DT_HEADER) {

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 626

Quoted 1 line
drivers/of/fdt.c +1 -0
+			WARN(1, "Invalid device tree blob in

vmlinux\n");

Quoted 14 lines
drivers/of/fdt.c +14 -0
+			break;
+		}
+
+		root = of_get_flat_dt_root();
+		if (of_flat_dt_is_compatible(root, name) > 0) {
+			rc = blob;
+			break;
+		}
+
+		size =  be32_to_cpu(initial_boot_params->totalsize);
+		blob =  PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+		initial_boot_params = (struct boot_param_header *)blob;
+	}
+

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 10 lines
drivers/of/fdt.c +10 -0
+	if (rc == NULL)
+		initial_boot_params = orig_initial_boot_params;
+	return rc;
+}
+
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
+	if (!initial_boot_params)
+		initial_boot_params =

of_flat_dt_find_compatible_dtb(line);

Quoted 8 lines
drivers/of/fdt.c +5 -1
+	return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+
--

1.7.2.3

Quoted 4 lines

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

#2 lore raw
Quoted 27 lines · Stephen Neuendorffer
Quoted 27 lines
drivers/of/fdt.c +10 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
  #include<linux/of_fdt.h>
  #include<linux/string.h>
  #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
  #ifdef CONFIG_PPC
  #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
  	pr_debug("<- unflatten_device_tree()\n");
  }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+	void *rc = NULL;
+	unsigned long root, size;
+	struct boot_param_header  *orig_initial_boot_params;
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 5 lines
drivers/of/fdt.c +5 -0
+	uint8_t *blob;
+
+	orig_initial_boot_params = initial_boot_params;
+	blob = __dtb_start;
+	initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using of_fdt_is_compatible() from my recent set of patches?

I would like to get rid of the pointer dance. Is your patch set going to make it into .37? I didn't see any acks.

Quoted 2 lines

It takes a blob argument. Then the loop below goes away.

The loop will still be needed since multiple DTBs may be linked into the image. using your of_fdt_is_compatible() will make the loop a lot more readable though.

--Dirk

Quoted 51 lines

Steve

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 4 lines
drivers/of/fdt.c +4 -0
+
+
+	while (blob<  __dtb_end) {
+		if (be32_to_cpu(initial_boot_params->magic) !=

OF_DT_HEADER) {

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 626

Quoted 1 line
drivers/of/fdt.c +1 -0
+			WARN(1, "Invalid device tree blob in

vmlinux\n");

Quoted 14 lines
drivers/of/fdt.c +14 -0
+			break;
+		}
+
+		root = of_get_flat_dt_root();
+		if (of_flat_dt_is_compatible(root, name)>  0) {
+			rc = blob;
+			break;
+		}
+
+		size =  be32_to_cpu(initial_boot_params->totalsize);
+		blob =  PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+		initial_boot_params = (struct boot_param_header *)blob;
+	}
+

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 10 lines
drivers/of/fdt.c +10 -0
+	if (rc == NULL)
+		initial_boot_params = orig_initial_boot_params;
+	return rc;
+}
+
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
+	if (!initial_boot_params)
+		initial_boot_params =

of_flat_dt_find_compatible_dtb(line);

Quoted 8 lines
drivers/of/fdt.c +5 -1
+	return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+
--

1.7.2.3

Quoted 4 lines

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

#3 lore raw
Quoted 37 lines · Dirk Brandewie
Quoted 27 lines · Stephen Neuendorffer
Quoted 27 lines
drivers/of/fdt.c +10 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+ void *rc = NULL;
+ unsigned long root, size;
+ struct boot_param_header *orig_initial_boot_params;
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 5 lines
drivers/of/fdt.c +5 -0
+ uint8_t *blob;
+
+ orig_initial_boot_params = initial_boot_params;
+ blob = __dtb_start;
+ initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using of_fdt_is_compatible() from my recent set of patches?

Quoted 3 lines

I would like to get rid of the pointer dance. Is your patch set going to make it into .37? I didn't see any acks.

Obviously I meant .38 :-)

Quoted 64 lines
Quoted 2 lines

It takes a blob argument. Then the loop below goes away.

The loop will still be needed since multiple DTBs may be linked into the image. using your of_fdt_is_compatible() will make the loop a lot more readable though.

--Dirk

Quoted 55 lines

Steve

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 4 lines
drivers/of/fdt.c +4 -0
+
+
+ while (blob< __dtb_end) {
+ if (be32_to_cpu(initial_boot_params->magic) !=

OF_DT_HEADER) {

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 626

Quoted 1 line
drivers/of/fdt.c +1 -0
+ WARN(1, "Invalid device tree blob in

vmlinux\n");

Quoted 14 lines
drivers/of/fdt.c +14 -0
+ break;
+ }
+
+ root = of_get_flat_dt_root();
+ if (of_flat_dt_is_compatible(root, name)> 0) {
+ rc = blob;
+ break;
+ }
+
+ size = be32_to_cpu(initial_boot_params->totalsize);
+ blob = PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+ initial_boot_params = (struct boot_param_header *)blob;
+ }
+

drivers/of/fdt.c void __init unflatten_device_tree(void)

Quoted 10 lines
drivers/of/fdt.c +10 -0
+ if (rc == NULL)
+ initial_boot_params = orig_initial_boot_params;
+ return rc;
+}
+
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
+ if (!initial_boot_params)
+ initial_boot_params =

of_flat_dt_find_compatible_dtb(line);

Quoted 8 lines
drivers/of/fdt.c +5 -1
+ return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+
--

1.7.2.3

Quoted 4 lines

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

#4 lore raw
Quoted 7 lines

-----Original Message-----
From: Dirk Brandewie [mailto:[email protected]]
Sent: Monday, December 06, 2010 11:03 AM
To: Stephen Neuendorffer
Cc: [email protected]; Randy Dunlap;

devicetree-discuss-uLR06cmDAlY/[email protected]; linux-

Quoted 2 lines

[email protected]; grant.likely-s3s/[email protected]
Subject: Re: [PATCH] of/fdt: add kernel command line option for

dtb_compat string

Quoted 29 lines · Dirk Brandewie
Quoted 27 lines · Stephen Neuendorffer
Quoted 26 lines
Quoted 26 lines
drivers/of/fdt.c +9 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+ void *rc = NULL;
+ unsigned long root, size;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 6 lines
drivers/of/fdt.c +6 -0
+ struct boot_param_header *orig_initial_boot_params;
+ uint8_t *blob;
+
+ orig_initial_boot_params = initial_boot_params;
+ blob = __dtb_start;
+ initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using

of_fdt_is_compatible()

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

from my recent set of patches?

I would like to get rid of the pointer dance. Is your patch set

going to make it

Quoted 3 lines
Quoted 2 lines

into .37? I didn't see any acks.

Obviously I meant .38 :-)

I'd like it too, but that's up to Grant. I imagine some of the bottleneck is that I don't have
an easy way to test on powerpc or microblaze at the moment, so it's not clear that the code doesn't
break anything.

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

It takes a blob argument. Then the loop below goes away.

The loop will still be needed since multiple DTBs may be linked into

the image.

Quoted 1 line
Quoted 1 line

using your of_fdt_is_compatible() will make the loop a lot more

readable though.

Yeah, right. Is the format just the binary concatenation of the device trees? part of why I ask
is the PTR_ALIGN code: It seems like different blob functions make different assumptions about the
location of the blob. In some cases, it is assumed to be the passed pointer, in others,
the pointer is scanned for OF_DT_BEGIN_NODE (using of_get_flat_dt_root). Is the concern about
STRUCT_ALIGNMENT necessary if you call of_get_flat_dt_root() afterwards? Would it make sense to
always call of_get_flat_dt_root in the 'generic' functions I added or not?

BTW, PTR_ALIGN should probably be ALIGN.

Steve

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

#5 lore raw
Quoted 66 lines · Stephen Neuendorffer
Quoted 7 lines

-----Original Message-----
From: Dirk Brandewie [mailto:[email protected]]
Sent: Monday, December 06, 2010 11:03 AM
To: Stephen Neuendorffer
Cc: [email protected]; Randy Dunlap;

[email protected]; linux-

Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH] of/fdt: add kernel command line option for

dtb_compat string

Quoted 29 lines · Dirk Brandewie
Quoted 27 lines · Stephen Neuendorffer
Quoted 26 lines
Quoted 26 lines
drivers/of/fdt.c +9 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+ void *rc = NULL;
+ unsigned long root, size;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 6 lines
drivers/of/fdt.c +6 -0
+ struct boot_param_header *orig_initial_boot_params;
+ uint8_t *blob;
+
+ orig_initial_boot_params = initial_boot_params;
+ blob = __dtb_start;
+ initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using

of_fdt_is_compatible()

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

from my recent set of patches?

I would like to get rid of the pointer dance. Is your patch set

going to make it

Quoted 3 lines
Quoted 2 lines

into .37? I didn't see any acks.

Obviously I meant .38 :-)

I'd like it too, but that's up to Grant. I imagine some of the bottleneck is that I don't have
an easy way to test on powerpc or microblaze at the moment, so it's not clear that the code doesn't
break anything.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

It takes a blob argument. Then the loop below goes away.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

The loop will still be needed since multiple DTBs may be linked into

the image.

Quoted 1 line
Quoted 1 line

using your of_fdt_is_compatible() will make the loop a lot more

readable though.

Yeah, right. Is the format just the binary concatenation of the device trees?

No each blob starts on a STRUCT_ALIGNMENT boundary. If the blob does not have the correct alignment the code that GCC generates to reference into the structure breaks.

part of why I ask

Quoted 10 lines

is the PTR_ALIGN code: It seems like different blob functions make different assumptions about the
location of the blob. In some cases, it is assumed to be the passed pointer, in others,
the pointer is scanned for OF_DT_BEGIN_NODE (using of_get_flat_dt_root). Is the concern about
STRUCT_ALIGNMENT necessary if you call of_get_flat_dt_root() afterwards? Would it make sense to
always call of_get_flat_dt_root in the 'generic' functions I added or not?

The padding between blobs is added in the assembly wrapper (zero fill) of_get_flat_dt_root() assumes the blob pointer (initial_boot_params) is the head of the blob and only skips OF_DT_NOP (0x4). If we always hand in the pointer to the head of the blob the rest of fdt.c should be happy with it.

Quoted 2 lines

BTW, PTR_ALIGN should probably be ALIGN.

Originally I used ALIGN but needed to cast the result of ALIGN blob to get rid of a compiler warning Grant suggested PTR_ALIGN which does the cast for you.

Quoted 6 lines

Steve

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

#6 lore raw
In reply to Stephen Neuendorffer
Quoted 51 lines · Stephen Neuendorffer
Quoted 7 lines

-----Original Message-----
From: Dirk Brandewie [mailto:[email protected]]
Sent: Monday, December 06, 2010 11:03 AM
To: Stephen Neuendorffer
Cc: [email protected]; Randy Dunlap;

[email protected]; linux-

Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH] of/fdt: add kernel command line option for

dtb_compat string

Quoted 29 lines · Dirk Brandewie
Quoted 27 lines · Stephen Neuendorffer
Quoted 26 lines
Quoted 26 lines
drivers/of/fdt.c +9 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+ void *rc = NULL;
+ unsigned long root, size;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 6 lines
drivers/of/fdt.c +6 -0
+ struct boot_param_header *orig_initial_boot_params;
+ uint8_t *blob;
+
+ orig_initial_boot_params = initial_boot_params;
+ blob = __dtb_start;
+ initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using

of_fdt_is_compatible()

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

from my recent set of patches?

Quoted 7 lines
Quoted 1 line
Quoted 1 line

I would like to get rid of the pointer dance. Is your patch set

going to make it

Quoted 3 lines
Quoted 2 lines

into .37? I didn't see any acks.

Obviously I meant .38 :-)

I'd like it too, but that's up to Grant.

Grant any guidance here?

I imagine some of the

Quoted 5 lines

bottleneck is that I don't have
an easy way to test on powerpc or microblaze at the moment, so it's not clear that the code doesn't
break anything.

#7 lore raw
In reply to Stephen Neuendorffer
Quoted 55 lines · Stephen Neuendorffer
Quoted 7 lines

-----Original Message-----
From: Dirk Brandewie [mailto:[email protected]]
Sent: Monday, December 06, 2010 11:03 AM
To: Stephen Neuendorffer
Cc: [email protected]; Randy Dunlap;

devicetree-discuss-uLR06cmDAlY/[email protected]; linux-

Quoted 2 lines

[email protected]; grant.likely-s3s/[email protected]
Subject: Re: [PATCH] of/fdt: add kernel command line option for

dtb_compat string

Quoted 29 lines · Dirk Brandewie
Quoted 27 lines · Stephen Neuendorffer
Quoted 26 lines
Quoted 26 lines
drivers/of/fdt.c +9 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+ void *rc = NULL;
+ unsigned long root, size;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 621

Quoted 6 lines
drivers/of/fdt.c +6 -0
+ struct boot_param_header *orig_initial_boot_params;
+ uint8_t *blob;
+
+ orig_initial_boot_params = initial_boot_params;
+ blob = __dtb_start;
+ initial_boot_params = (struct boot_param_header *)blob;

Oy... can you avoid the pointer dance by using

of_fdt_is_compatible()

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

from my recent set of patches?

I would like to get rid of the pointer dance. Is your patch set

going to make it

Quoted 2 lines
Quoted 2 lines

into .37? I didn't see any acks.

Quoted 7 lines
Quoted 1 line

Obviously I meant .38 :-)

I'd like it too, but that's up to Grant. I imagine some of the bottleneck is that I don't have
an easy way to test on powerpc or microblaze at the moment, so it's not clear that the code doesn't
break anything.

It's in my -next branch now.

g.

#8 lore raw
In reply to [email protected]
Quoted 85 lines · On 12/06/2010 09:54 AM, [email protected] wrote:

From: Dirk Brandewie<[email protected]>

Adds a kernel command line option "dtb_compat=<string>". This string will be used to select the first compatible device tree blob linked into the kernel if a device tree blob is was *not* passed in by the bootloader.

---
  Documentation/kernel-parameters.txt |    8 ++++++
  drivers/of/fdt.c                    |   48 +++++++++++++++++++++++++++++++++++
  2 files changed, 56 insertions(+), 0 deletions(-)
Documentation/kernel-parameters.txt +8 -0
index 92e83e5..64093e5 100644
@@ -655,6 +655,14 @@ and is between 256 and 4096 characters. It is defined in the file
 
  	dscc4.setup=	[NET]
 
+	dtb_compat=	[KNL]
+			Specify the "compatible" string for the device
+			tree blob present in the vmlinux image.  This
+			string will be used to select the first device
+			tree blob whose compatible property matches
+			the string if a dtb was NOT passed in by the
+			bootloader.
+
  	dynamic_printk	Enables pr_debug()/dev_dbg() calls if
  			CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
  			These can also be switched on/off via
drivers/of/fdt.c +38 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
  #include<linux/of_fdt.h>
  #include<linux/string.h>
  #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
  #ifdef CONFIG_PPC
  #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
  	pr_debug("<- unflatten_device_tree()\n");
  }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+	void *rc = NULL;
+	unsigned long root, size;
+	struct boot_param_header  *orig_initial_boot_params;
+	uint8_t *blob;
+
+	orig_initial_boot_params = initial_boot_params;
+	blob = __dtb_start;
+	initial_boot_params = (struct boot_param_header *)blob;
+
+	while (blob<  __dtb_end) {
+		if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
+			WARN(1, "Invalid device tree blob in vmlinux\n");
+			break;
+		}
+
+		root = of_get_flat_dt_root();
+		if (of_flat_dt_is_compatible(root, name)>  0) {
+			rc = blob;
+			break;
+		}
+
+		size =  be32_to_cpu(initial_boot_params->totalsize);
+		blob =  PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+		initial_boot_params = (struct boot_param_header *)blob;
+	}
+
+	if (rc == NULL)
+		initial_boot_params = orig_initial_boot_params;
+	return rc;
+}
+

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 654

Quoted 10 lines
drivers/of/fdt.c +10 -0
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
+	if (!initial_boot_params)
+		initial_boot_params = of_flat_dt_find_compatible_dtb(line);
+	return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+

Any other comments on this patch? Do I need to port it to use Stephens patch set to allow passing in blobs to fdt.c?

--Dirk

#9 lore raw
In reply to [email protected]
Quoted 85 lines · On 12/06/2010 09:54 AM, [email protected] wrote:

From: Dirk Brandewie<[email protected]>

Adds a kernel command line option "dtb_compat=<string>". This string will be used to select the first compatible device tree blob linked into the kernel if a device tree blob is was *not* passed in by the bootloader.

---
  Documentation/kernel-parameters.txt |    8 ++++++
  drivers/of/fdt.c                    |   48 +++++++++++++++++++++++++++++++++++
  2 files changed, 56 insertions(+), 0 deletions(-)
Documentation/kernel-parameters.txt +8 -0
index 92e83e5..64093e5 100644
@@ -655,6 +655,14 @@ and is between 256 and 4096 characters. It is defined in the file
 
  	dscc4.setup=	[NET]
 
+	dtb_compat=	[KNL]
+			Specify the "compatible" string for the device
+			tree blob present in the vmlinux image.  This
+			string will be used to select the first device
+			tree blob whose compatible property matches
+			the string if a dtb was NOT passed in by the
+			bootloader.
+
  	dynamic_printk	Enables pr_debug()/dev_dbg() calls if
  			CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
  			These can also be switched on/off via
drivers/of/fdt.c +38 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
  #include<linux/of_fdt.h>
  #include<linux/string.h>
  #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
  #ifdef CONFIG_PPC
  #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
  	pr_debug("<- unflatten_device_tree()\n");
  }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+	void *rc = NULL;
+	unsigned long root, size;
+	struct boot_param_header  *orig_initial_boot_params;
+	uint8_t *blob;
+
+	orig_initial_boot_params = initial_boot_params;
+	blob = __dtb_start;
+	initial_boot_params = (struct boot_param_header *)blob;
+
+	while (blob<  __dtb_end) {
+		if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
+			WARN(1, "Invalid device tree blob in vmlinux\n");
+			break;
+		}
+
+		root = of_get_flat_dt_root();
+		if (of_flat_dt_is_compatible(root, name)>  0) {
+			rc = blob;
+			break;
+		}
+
+		size =  be32_to_cpu(initial_boot_params->totalsize);
+		blob =  PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+		initial_boot_params = (struct boot_param_header *)blob;
+	}
+
+	if (rc == NULL)
+		initial_boot_params = orig_initial_boot_params;
+	return rc;
+}
+

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 654

Quoted 10 lines
drivers/of/fdt.c +10 -0
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
+	if (!initial_boot_params)
+		initial_boot_params = of_flat_dt_find_compatible_dtb(line);
+	return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+

Any more comments on this patch? Is it good to go or DOA?

Thanks
--Dirk

#10 lore raw
Quoted 89 lines · Dirk Brandewie
Quoted 88 lines · On 12/06/2010 09:54 AM, [email protected] wrote:

From: Dirk Brandewie<[email protected]>

Adds a kernel command line option "dtb_compat=<string>". This string will be used to select the first compatible device tree blob linked into the kernel if a device tree blob is was *not* passed in by the bootloader.

---
 Documentation/kernel-parameters.txt |    8 ++++++
 drivers/of/fdt.c                    |   48 +++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
Documentation/kernel-parameters.txt +8 -0
index 92e83e5..64093e5 100644
@@ -655,6 +655,14 @@ and is between 256 and 4096 characters. It is defined in the file
 
 	dscc4.setup=	[NET]
 
+	dtb_compat=	[KNL]
+			Specify the "compatible" string for the device
+			tree blob present in the vmlinux image.  This
+			string will be used to select the first device
+			tree blob whose compatible property matches
+			the string if a dtb was NOT passed in by the
+			bootloader.
+
 	dynamic_printk	Enables pr_debug()/dev_dbg() calls if
 			CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
 			These can also be switched on/off via
drivers/of/fdt.c +41 -0
index c1360e0..ca1318c 100644
@@ -15,6 +15,8 @@
 #include<linux/of_fdt.h>
 #include<linux/string.h>
 #include<linux/errno.h>
+#include<asm-generic/vmlinux.lds.h>
+
 
 #ifdef CONFIG_PPC
 #include<asm/machdep.h>
@@ -604,3 +606,49 @@ void __init unflatten_device_tree(void)
 
 	pr_debug("<- unflatten_device_tree()\n");
 }
+
+extern uint8_t __dtb_start[];
+extern uint8_t __dtb_end[];
+static void __init *of_flat_dt_find_compatible_dtb(char *name)
+{
+	void *rc = NULL;
+	unsigned long root, size;
+	struct boot_param_header  *orig_initial_boot_params;
+	uint8_t *blob;
+
+	orig_initial_boot_params = initial_boot_params;
+	blob = __dtb_start;
+	initial_boot_params = (struct boot_param_header *)blob;
+
+	while (blob<  __dtb_end) {
+		if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
+			WARN(1, "Invalid device tree blob in vmlinux\n");
+			break;
+		}
+
+		root = of_get_flat_dt_root();
+		if (of_flat_dt_is_compatible(root, name)>  0) {
+			rc = blob;
+			break;
+		}
+
+		size =  be32_to_cpu(initial_boot_params->totalsize);
+		blob =  PTR_ALIGN(blob + size, STRUCT_ALIGNMENT);
+		initial_boot_params = (struct boot_param_header *)blob;
+	}
+
+	if (rc == NULL)
+		initial_boot_params = orig_initial_boot_params;
+	return rc;
+}
+
+
+static int __init of_flat_dtb_compat_setup(char *line)
+{
Quoted 8 lines

drivers/of/fdt.c void __init unflatten_device_tree(void) · line 654

Quoted 7 lines
drivers/of/fdt.c +7 -0
+	if (!initial_boot_params)
+		initial_boot_params = of_flat_dt_find_compatible_dtb(line);
+	return 1;
+}
+
+early_param("dtb_compat", of_flat_dtb_compat_setup);
+

Any more comments on this patch? Is it good to go or DOA?

Not DOA, but I want to discuss the linking vs. wrapper issue again before I commit to merging it. BTW, sorry for being MIA on this stuff for pretty much all December. I got over committed, but things should be better now.

g.