Skip to contentSkip to conversation

Documentation: devicetree: root node serial-number property documentation

PATCH Superseded Paul Kocialkowski 2 participants 6 messages Apr 17, 2015 – Apr 18, 2015

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 v2 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            | 21 +++++++++++++++++++--
 2 files changed, 20 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 +19 -2
index 1d60beb..d1833ce 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,6 +824,21 @@ arch_initcall(customize_machine);
 
 static int __init init_machine_late(void)
 {
+#ifdef CONFIG_OF
+	unsigned long dt_root;
+	int size;
+
+	dt_root = of_get_flat_dt_root();
+
+	/* Scan for serial number */
+	system_serial = of_get_flat_dt_prop(dt_root, "serial-number", &size);
+#endif
+
+	if (!system_serial)
+		system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
+					  system_serial_high,
+					  system_serial_low);
+
 	if (machine_desc->init_late)
 		machine_desc->init_late();
 	return 0;
@@ -1091,8 +1109,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 v2 2/2 arch: arm: Show the serial number from devicetree in cpuinfo

Hi,

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

Quoted 10 lines · Paul Kocialkowski

static int __init init_machine_late(void)
{

arch/arm/kernel/setup.c +8 -0
+#ifdef CONFIG_OF
+	unsigned long dt_root;
+	int size;
+
+	dt_root = of_get_flat_dt_root();
+
+	/* Scan for serial number */
+	system_serial = of_get_flat_dt_prop(dt_root, "serial-number", &size);

I was really hoping for:

	if (of_property_read_string(of_root, "serial-number", &system_serial))
		system_serial = NULL;

here. I can't see a reason to use the flattened DT at this point as we've already parsed it.

I'd also put this after the call to machine_desc->init_late().

Thanks.

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

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

Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a ?crit :

Quoted 16 lines

Hi,

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

Quoted 10 lines · Paul Kocialkowski

static int __init init_machine_late(void)
{

arch/arm/kernel/setup.c +8 -0
+#ifdef CONFIG_OF
+	unsigned long dt_root;
+	int size;
+
+	dt_root = of_get_flat_dt_root();
+
+	/* Scan for serial number */
+	system_serial = of_get_flat_dt_prop(dt_root, "serial-number", &size);

I was really hoping for:

Quoted 5 lines
	if (of_property_read_string(of_root, "serial-number", &system_serial))
		system_serial = NULL;

here. I can't see a reason to use the flattened DT at this point as we've already parsed it.

Good point -- I'm not very used to using device-tree so I didn't think of it, thanks for mentioning it.

At this point, I guess I can also add your Signed-Off-By to the patch.

Quoted 1 line

I'd also put this after the call to machine_desc->init_late().

Will do.

-------------- 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/20150418/ab0efeae/attachment.sig>

#4 lore raw

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

Quoted 21 lines · Paul Kocialkowski

Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a ?crit :

Quoted 19 lines

Hi,

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

Quoted 10 lines · Paul Kocialkowski

static int __init init_machine_late(void)
{

arch/arm/kernel/setup.c +8 -0
+#ifdef CONFIG_OF
+	unsigned long dt_root;
+	int size;
+
+	dt_root = of_get_flat_dt_root();
+
+	/* Scan for serial number */
+	system_serial = of_get_flat_dt_prop(dt_root, "serial-number", &size);

I was really hoping for:

	if (of_property_read_string(of_root, "serial-number", &system_serial))
		system_serial = NULL;
Quoted 7 lines
Quoted 2 lines

here. I can't see a reason to use the flattened DT at this point as we've already parsed it.

Good point -- I'm not very used to using device-tree so I didn't think of it, thanks for mentioning it.

At this point, I guess I can also add your Signed-Off-By to the patch.

No - Signed-off-by is to indicate the path by which it was committed into the git tree, not for review, etc.

I'm assuming you'll be submitting this to my patch system eventually, which means when I apply the patch, it'll have my S-o-b automatically added.

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

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

Le samedi 18 avril 2015 ? 13:27 +0100, Russell King - ARM Linux a ?crit :

Quoted 25 lines · Paul Kocialkowski
Quoted 24 lines

Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a ?crit :

Quoted 21 lines

Hi,

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

Quoted 10 lines · Paul Kocialkowski

static int __init init_machine_late(void)
{

arch/arm/kernel/setup.c +8 -0
+#ifdef CONFIG_OF
+	unsigned long dt_root;
+	int size;
+
+	dt_root = of_get_flat_dt_root();
+
+	/* Scan for serial number */
+	system_serial = of_get_flat_dt_prop(dt_root, "serial-number", &size);

I was really hoping for:

	if (of_property_read_string(of_root, "serial-number", &system_serial))
		system_serial = NULL;

here. I can't see a reason to use the flattened DT at this point as we've already parsed it.

Quoted 7 lines
Quoted 4 lines

Good point -- I'm not very used to using device-tree so I didn't think of it, thanks for mentioning it.

At this point, I guess I can also add your Signed-Off-By to the patch.

No - Signed-off-by is to indicate the path by which it was committed into the git tree, not for review, etc.

Right, but since you've provided me with code samples, you might as well hold part of the authorship of the patch.

Quoted 3 lines

I'm assuming you'll be submitting this to my patch system eventually, which means when I apply the patch, it'll have my S-o-b automatically added.

V3 (that includes your suggestion) was sent already.

Thanks for the review and comprehensive help!
-------------- 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/20150418/0197a35a/attachment.sig>