Skip to contentSkip to conversation

Documentation: devicetree: root node serial-number property documentation

PATCH Superseded Paul Kocialkowski 3 participants 11 messages Apr 18, 2015 – May 6, 2015

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 Documentation: devicetree: root node serial-number property documentation

Open firmware is already using the serial-number property for passing the device's serial number from the bootloader to the kernel. In addition, lshw already has support for scanning this property.

The serial number is a string that somewhat represents the device's serial number. It might come from some form of storage (e.g. an eeprom) and be programmed at factory-time by the manufacturer or come from identification bits available in e.g. the SoC (note that the soc_id property in the SoC bus should hold a full account of those bits).

The serial number is taken as-is from the bootloader, so it is up to the bootloader to define where the serial number comes from and what length it should be. Some use cases for the serial number require it to have a maximum length (e.g. for USB serial number) and some other cases imply more restrictions on what the serial number should look like (e.g. in Android, the ro.serialno property is usually a 16-bytes (plus one null byte) representation of a 64 bit number).

---
 Documentation/devicetree/booting-without-of.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/booting-without-of.txt +4 -0
index 7768518..95fc385 100644
@@ -828,6 +828,10 @@ address which can extend beyond that limit.
   name may clash with standard defined ones, you prefix them with your
   vendor name and a comma.
 
+  Additional properties for the root node:
+
+    - serial-number : a string representing the device's serial number
+
   b) The /cpus node
 
   This node is the parent of all individual CPU nodes. It doesn't
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +25 -2
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)
 {
+#ifdef CONFIG_OF
+	struct device_node *root;
+	int ret;
+#endif
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
+
+#ifdef CONFIG_OF
+	root = of_find_node_by_path("/");
+	if (root) {
+		ret = of_property_read_string(root, "serial-number",
+					      &system_serial);
+		if (ret)
+			system_serial = NULL;
+	}
+#endif
+
+	if (!system_serial)
+		system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
+					  system_serial_high,
+					  system_serial_low);
+
 	return 0;
 }
 late_initcall(init_machine_late);
@@ -1091,8 +1115,7 @@ static int c_show(struct seq_file *m, void *v)
 
 	seq_printf(m, "Hardware\t: %s\n", machine_name);
 	seq_printf(m, "Revision\t: %04x\n", system_rev);
-	seq_printf(m, "Serial\t\t: %08x%08x\n",
-		   system_serial_high, system_serial_low);
+	seq_printf(m, "Serial\t\t: %s\n", system_serial);
 
 	return 0;
 }
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Le samedi 18 avril 2015 ? 11:58 +0200, Paul Kocialkowski a ?crit :

Quoted 3 lines

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

Any further comment on this?

Quoted 63 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +24 -0
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)
 {
+#ifdef CONFIG_OF
+	struct device_node *root;
+	int ret;
+#endif
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
+
+#ifdef CONFIG_OF
+	root = of_find_node_by_path("/");
+	if (root) {
+		ret = of_property_read_string(root, "serial-number",
+					      &system_serial);
+		if (ret)
+			system_serial = NULL;
+	}
+#endif
+
+	if (!system_serial)
+		system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
+					  system_serial_high,
+					  system_serial_low);
+
 	return 0;
 }
 late_initcall(init_machine_late);

arch/arm/kernel/setup.c static int c_show(struct seq_file *m, void *v) · line 1121

Quoted 9 lines
arch/arm/kernel/setup.c +1 -2
@@ -1091,8 +1115,7 @@ static int c_show(struct seq_file *m, void *v)
 
 	seq_printf(m, "Hardware\t: %s\n", machine_name);
 	seq_printf(m, "Revision\t: %04x\n", system_rev);
-	seq_printf(m, "Serial\t\t: %08x%08x\n",
-		   system_serial_high, system_serial_low);
+	seq_printf(m, "Serial\t\t: %s\n", system_serial);
 
 	return 0;
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150427/9c4abe91/attachment.sig>

#3 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

In reply to Paul Kocialkowski
Quoted 5 lines · Paul Kocialkowski

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

One comment below, otherwise:

Quoted 34 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +3 -0
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)

arch/arm/kernel/setup.c arch_initcall(customize_machine); · line 835

Quoted 10 lines
arch/arm/kernel/setup.c +7 -0
 {
+#ifdef CONFIG_OF
+       struct device_node *root;
+       int ret;
+#endif
+
        if (machine_desc->init_late)
                machine_desc->init_late();
+
+#ifdef CONFIG_OF

These ifdefs should not be necessary, but please double check.

Rob

Quoted 30 lines
arch/arm/kernel/setup.c +15 -3
+       root = of_find_node_by_path("/");
+       if (root) {
+               ret = of_property_read_string(root, "serial-number",
+                                             &system_serial);
+               if (ret)
+                       system_serial = NULL;
+       }
+#endif
+
+       if (!system_serial)
+               system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
+                                         system_serial_high,
+                                         system_serial_low);
+
        return 0;
 }
 late_initcall(init_machine_late);
@@ -1091,8 +1115,7 @@ static int c_show(struct seq_file *m, void *v)
 
        seq_printf(m, "Hardware\t: %s\n", machine_name);
        seq_printf(m, "Revision\t: %04x\n", system_rev);
-       seq_printf(m, "Serial\t\t: %08x%08x\n",
-                  system_serial_high, system_serial_low);
+       seq_printf(m, "Serial\t\t: %s\n", system_serial);
 
        return 0;
 }
--

1.9.1

#4 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Le lundi 27 avril 2015 ? 08:48 -0500, Rob Herring a ?crit :

Quoted 44 lines · Paul Kocialkowski
Quoted 5 lines

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

One comment below, otherwise:

Quoted 33 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +3 -0
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
Quoted 13 lines

arch/arm/kernel/setup.c arch_initcall(customize_machine); · line 835

Quoted 11 lines
arch/arm/kernel/setup.c +7 -0
 static int __init init_machine_late(void)
 {
+#ifdef CONFIG_OF
+       struct device_node *root;
+       int ret;
+#endif
+
        if (machine_desc->init_late)
                machine_desc->init_late();
+
+#ifdef CONFIG_OF

These ifdefs should not be necessary, but please double check.

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

This is also being done a few lines above in customize_machine.

Quoted 25 lines
Quoted 25 lines
arch/arm/kernel/setup.c +15 -2
+       root = of_find_node_by_path("/");
+       if (root) {
+               ret = of_property_read_string(root, "serial-number",
+                                             &system_serial);
+               if (ret)
+                       system_serial = NULL;
+       }
+#endif
+
+       if (!system_serial)
+               system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
+                                         system_serial_high,
+                                         system_serial_low);
+
        return 0;
 }
 late_initcall(init_machine_late);
@@ -1091,8 +1115,7 @@ static int c_show(struct seq_file *m, void *v)
 
        seq_printf(m, "Hardware\t: %s\n", machine_name);
        seq_printf(m, "Revision\t: %04x\n", system_rev);
-       seq_printf(m, "Serial\t\t: %08x%08x\n",
-                  system_serial_high, system_serial_low);
+       seq_printf(m, "Serial\t\t: %s\n", system_serial);
 
Quoted 5 lines
Quoted 5 lines
arch/arm/kernel/setup.c +0 -1
        return 0;
 }
--

1.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150427/5dfe6591/attachment.sig>

#5 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Quoted 59 lines · Paul Kocialkowski

Le lundi 27 avril 2015 ? 08:48 -0500, Rob Herring a ?crit :

Quoted 44 lines · Paul Kocialkowski
Quoted 5 lines

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

One comment below, otherwise:

Quoted 33 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +3 -0
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
Quoted 13 lines

arch/arm/kernel/setup.c arch_initcall(customize_machine); · line 835

Quoted 11 lines
arch/arm/kernel/setup.c +7 -0
 static int __init init_machine_late(void)
 {
+#ifdef CONFIG_OF
+       struct device_node *root;
+       int ret;
+#endif
+
        if (machine_desc->init_late)
                machine_desc->init_late();
+
+#ifdef CONFIG_OF

These ifdefs should not be necessary, but please double check.

Quoted 3 lines

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Look at include/linux/of.h. There are an empty versions of both functions.

Quoted 2 lines

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

We still (and will continue to) have non-OF platforms.

Quoted 1 line

This is also being done a few lines above in customize_machine.

True, but that doesn't mean we want more.

Rob

#6 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Le lundi 27 avril 2015 ? 10:20 -0500, Rob Herring a ?crit :

Quoted 60 lines · Paul Kocialkowski
Quoted 59 lines

Le lundi 27 avril 2015 ? 08:48 -0500, Rob Herring a ?crit :

Quoted 57 lines · Paul Kocialkowski
Quoted 5 lines

This grabs the serial number shown in cpuinfo from the serial-number devicetree property in priority. When booting with ATAGs (and without device-tree), the provided number is still shown instead.

One comment below, otherwise:

Quoted 34 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
arch/arm/include/asm/system_info.h +1 -0
index 720ea03..3860cbd40 100644
@@ -17,6 +17,7 @@
 
 /* information about the system we're running on */
 extern unsigned int system_rev;
+extern const char *system_serial;
 extern unsigned int system_serial_low;
 extern unsigned int system_serial_high;
 extern unsigned int mem_fclk_21285;
arch/arm/kernel/setup.c +3 -0
index 1d60beb..349790f 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,29 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)

arch/arm/kernel/setup.c arch_initcall(customize_machine); · line 835

Quoted 10 lines
arch/arm/kernel/setup.c +7 -0
 {
+#ifdef CONFIG_OF
+       struct device_node *root;
+       int ret;
+#endif
+
        if (machine_desc->init_late)
                machine_desc->init_late();
+
+#ifdef CONFIG_OF

These ifdefs should not be necessary, but please double check.

Quoted 5 lines
Quoted 3 lines

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Look at include/linux/of.h. There are an empty versions of both functions.

Oh, you're right, I didn't know it was the case. I'll submit another version with those changes then!

Quoted 8 lines
Quoted 2 lines

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

We still (and will continue to) have non-OF platforms.

Quoted 1 line

This is also being done a few lines above in customize_machine.

True, but that doesn't mean we want more.

Ack.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150427/75f88604/attachment-0001.sig>

#7 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

In reply to Paul Kocialkowski
Quoted 6 lines · Paul Kocialkowski

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

That is _not_ "is the case" - there are a number of non-OF platforms... including some which will probably never be converted.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#8 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Le mardi 28 avril 2015 ? 17:09 +0100, Russell King - ARM Linux a ?crit :

Quoted 10 lines · Paul Kocialkowski
Quoted 6 lines

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

That is _not_ "is the case" - there are a number of non-OF platforms... including some which will probably never be converted.

Right, so I think v4 should be fine too, given the empty functions in
case CONFIG_OF is not set.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150502/487217c6/attachment.sig>

#9 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Quoted 6 lines · Paul Kocialkowski

Le mardi 28 avril 2015 ? 17:09 +0100, Russell King - ARM Linux a ?crit :

Quoted 5 lines · Paul Kocialkowski
Quoted 4 lines

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

That is _not_ "is the case" - there are a number of non-OF platforms... including some which will probably never be converted.

Right, so I think v4 should be fine too, given the empty functions in case CONFIG_OF is not set.

Yes, can you please put them in my patch system so we can get this applied?

Rob - does your ack apply to the v4 patch?

Thanks.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#10 lore raw

PATCH v3 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Le mercredi 06 mai 2015 ? 10:01 +0100, Russell King - ARM Linux a ?crit :

Quoted 10 lines · Paul Kocialkowski
Quoted 9 lines

Le mardi 28 avril 2015 ? 17:09 +0100, Russell King - ARM Linux a ?crit :

Quoted 8 lines · Paul Kocialkowski
Quoted 6 lines

Well, of_property_read_string is only defined when CONFIG_OF is set (base.c is always built in drivers/of but the directory is only included when CONFIG_OF is set).

Of course, on ARM, we now expect that it is the case, but it seems like good practice to check for it, since it could theoretically be disabled.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

That is _not_ "is the case" - there are a number of non-OF platforms... including some which will probably never be converted.

Right, so I think v4 should be fine too, given the empty functions in case CONFIG_OF is not set.

Yes, can you please put them in my patch system so we can get this applied?

What exactly do you mean?

I sent v4 to linux-arm-kernel at lists.infradead.org and devicetree at vger.kernel.org with you and Rob in the CC list, on the 28th of April.

Quoted 4 lines

Rob - does your ack apply to the v4 patch?

Thanks.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150506/d301340a/attachment-0001.sig>