Skip to contentSkip to conversation

Documentation: devicetree: root node serial-number property documentation

PATCH New Paul Kocialkowski 3 participants 6 messages Apr 28, 2015 – Jun 11, 2015

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

PATCH v4 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 v4 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            | 23 +++++++++++++++++++++--
 2 files changed, 22 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 +21 -2
index 1d60beb..b501754 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,25 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)
 {
+	struct device_node *root;
+	int ret;
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
+
+	root = of_find_node_by_path("/");
+	if (root) {
+		ret = of_property_read_string(root, "serial-number",
+					      &system_serial);
+		if (ret)
+			system_serial = NULL;
+	}
+
+	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 +1111,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 v4 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

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, but otherwise:

Quoted 22 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 23 +++++++++++++++++++++--
 2 files changed, 22 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 +0 -0
index 1d60beb..b501754 100644

arch/arm/kernel/setup.c unsigned int __atags_pointer __initdata; · line 98

Quoted 6 lines
arch/arm/kernel/setup.c +3 -0
@@ -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);
+

Is there any need to export this symbol? It's only used by built-in code. Not by modules.

Quoted 7 lines
arch/arm/kernel/setup.c +0 -0
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,25 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)
 {

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

Quoted 10 lines
arch/arm/kernel/setup.c +8 -0
+	struct device_node *root;
+	int ret;
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
+
+	root = of_find_node_by_path("/");
+	if (root) {
+		ret = of_property_read_string(root, "serial-number",
+					      &system_serial);

of_property_read_string() will not modify the argument on failure. If system_serial is initialized to NULL, then the failure path is unnecessary.

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

Quoted 3 lines
arch/arm/kernel/setup.c +3 -0
+		if (ret)
+			system_serial = NULL;
+	}

Calls to of_find_node* functions increment the refcount for the node. Need an of_node_put() here, or just use the of_root pointer directly. It is safe to call of_property_read_string() with a NULL node pointer too, it will fail gracefully.

So, the whole thing can safely boil down to:

	of_property_read_string(of_root, "serial-number", &system_serial);
	if (!system_serial)
		system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
					  system_serial_high, system_serial_low);

g.

#3 lore raw

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

Le dimanche 07 juin 2015 ? 18:03 +0100, Grant Likely a ?crit :

Quoted 7 lines
Quoted 4 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.

Quoted 5 lines
Quoted 1 line

One comment below, but otherwise:

I'm afraid this was merged in Russell's tree already:
http://ftp.arm.linux.org.uk/cgit/linux-arm.git/commit/?h=for-next&id=3f599875e5202986b350618a617527ab441bf206

Still, it might be useful to make another patch on top with your comments!

Quoted 25 lines
Quoted 25 lines
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 23 +++++++++++++++++++++--
 2 files changed, 22 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 +0 -0
index 1d60beb..b501754 100644
@@ -93,6 +93,9 @@ unsigned int __atags_pointer __initdata;
 unsigned int system_rev;
 EXPORT_SYMBOL(system_rev);
 
Quoted 6 lines

arch/arm/kernel/setup.c unsigned int __atags_pointer __initdata; · line 98

Quoted 3 lines
arch/arm/kernel/setup.c +3 -0
+const char *system_serial;
+EXPORT_SYMBOL(system_serial);
+

Is there any need to export this symbol? It's only used by built-in code. Not by modules.

I agree, but I thought it would be consistent with the way system_serial_high/low are exported. I'm not sure this was ever needed either, but generally, I guess it makes sense to export parameters that are passed to the kernel (it was through ATAGs before, now it's through device-tree, but the logic remains the same).

Quoted 5 lines
Quoted 5 lines
arch/arm/kernel/setup.c +0 -0
 unsigned int system_serial_low;
 EXPORT_SYMBOL(system_serial_low);
 
@@ -821,8 +824,25 @@ arch_initcall(customize_machine);
 
Quoted 16 lines

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

Quoted 12 lines
arch/arm/kernel/setup.c +8 -0
 static int __init init_machine_late(void)
 {
+	struct device_node *root;
+	int ret;
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
+
+	root = of_find_node_by_path("/");
+	if (root) {
+		ret = of_property_read_string(root, "serial-number",
+					      &system_serial);

of_property_read_string() will not modify the argument on failure. If system_serial is initialized to NULL, then the failure path is unnecessary.

Makes sense.

Quoted 9 lines

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

Quoted 3 lines
arch/arm/kernel/setup.c +3 -0
+		if (ret)
+			system_serial = NULL;
+	}

Calls to of_find_node* functions increment the refcount for the node. Need an of_node_put() here, or just use the of_root pointer directly. It is safe to call of_property_read_string() with a NULL node pointer too, it will fail gracefully.

Quoted 6 lines

So, the whole thing can safely boil down to:

	of_property_read_string(of_root, "serial-number", &system_serial);
	if (!system_serial)
		system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
					  system_serial_high, system_serial_low);

Looks good to me, feel free to commit this change, on top of:
http://ftp.arm.linux.org.uk/cgit/linux-arm.git/commit/?h=for-next&id=3f599875e5202986b350618a617527ab441bf206
-------------- 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/20150611/b66a37b3/attachment.sig>

#4 lore raw

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

In reply to Paul Kocialkowski
Quoted 18 lines · Paul Kocialkowski

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).

Quoted 1 line

What Russell was referring to for submitting is his patch tracker:

http://www.arm.linux.org.uk/developer/patches/

Rob

Quoted 22 lines
---
 Documentation/devicetree/booting-without-of.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/booting-without-of.txt +4 -1
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
--

1.9.1

#5 lore raw

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

Le mercredi 06 mai 2015 ? 08:26 -0500, Rob Herring a ?crit :

Quoted 19 lines · Paul Kocialkowski
Quoted 18 lines

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).

Quoted 7 lines
Quoted 1 line

What Russell was referring to for submitting is his patch tracker:

http://www.arm.linux.org.uk/developer/patches/

Thanks for the hint, that's done now.

Quoted 18 lines
Quoted 18 lines
---
 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
 
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/booting-without-of.txt +0 -1
   This node is the parent of all individual CPU nodes. It doesn't
--

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/20150506/fc3e1a07/attachment.sig>