linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] Documentation: devicetree: root node serial-number property documentation
@ 2015-04-17 18:43 Paul Kocialkowski
  2015-04-17 18:43 ` [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo Paul Kocialkowski
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Kocialkowski @ 2015-04-17 18:43 UTC (permalink / raw)
  To: linux-arm-kernel

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

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 Documentation/devicetree/booting-without-of.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/booting-without-of.txt b/Documentation/devicetree/booting-without-of.txt
index 7768518..95fc385 100644
--- a/Documentation/devicetree/booting-without-of.txt
+++ b/Documentation/devicetree/booting-without-of.txt
@@ -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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo
  2015-04-17 18:43 [PATCH v2 1/2] Documentation: devicetree: root node serial-number property documentation Paul Kocialkowski
@ 2015-04-17 18:43 ` Paul Kocialkowski
  2015-04-18  9:13   ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Kocialkowski @ 2015-04-17 18:43 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 arch/arm/include/asm/system_info.h |  1 +
 arch/arm/kernel/setup.c            | 21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/system_info.h b/arch/arm/include/asm/system_info.h
index 720ea03..3860cbd40 100644
--- a/arch/arm/include/asm/system_info.h
+++ b/arch/arm/include/asm/system_info.h
@@ -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;
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 1d60beb..d1833ce 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -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;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo
  2015-04-17 18:43 ` [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo Paul Kocialkowski
@ 2015-04-18  9:13   ` Russell King - ARM Linux
  2015-04-18  9:45     ` Paul Kocialkowski
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2015-04-18  9:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Fri, Apr 17, 2015 at 08:43:55PM +0200, Paul Kocialkowski wrote:
>  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);

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.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo
  2015-04-18  9:13   ` Russell King - ARM Linux
@ 2015-04-18  9:45     ` Paul Kocialkowski
  2015-04-18 12:27       ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Kocialkowski @ 2015-04-18  9:45 UTC (permalink / raw)
  To: linux-arm-kernel

Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a
?crit :
> Hi,
> 
> On Fri, Apr 17, 2015 at 08:43:55PM +0200, Paul Kocialkowski wrote:
> >  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);
> 
> 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.

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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo
  2015-04-18  9:45     ` Paul Kocialkowski
@ 2015-04-18 12:27       ` Russell King - ARM Linux
  2015-04-18 12:37         ` Paul Kocialkowski
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2015-04-18 12:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Apr 18, 2015 at 11:45:13AM +0200, Paul Kocialkowski wrote:
> Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a
> ?crit :
> > Hi,
> > 
> > On Fri, Apr 17, 2015 at 08:43:55PM +0200, Paul Kocialkowski wrote:
> > >  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);
> > 
> > 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.
> 
> 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.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo
  2015-04-18 12:27       ` Russell King - ARM Linux
@ 2015-04-18 12:37         ` Paul Kocialkowski
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Kocialkowski @ 2015-04-18 12:37 UTC (permalink / raw)
  To: linux-arm-kernel

Le samedi 18 avril 2015 ? 13:27 +0100, Russell King - ARM Linux a
?crit :
> On Sat, Apr 18, 2015 at 11:45:13AM +0200, Paul Kocialkowski wrote:
> > Le samedi 18 avril 2015 ? 10:13 +0100, Russell King - ARM Linux a
> > ?crit :
> > > Hi,
> > > 
> > > On Fri, Apr 17, 2015 at 08:43:55PM +0200, Paul Kocialkowski wrote:
> > > >  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);
> > > 
> > > 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.
> > 
> > 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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-18 12:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-17 18:43 [PATCH v2 1/2] Documentation: devicetree: root node serial-number property documentation Paul Kocialkowski
2015-04-17 18:43 ` [PATCH v2 2/2] arch: arm: Show the serial number from devicetree in cpuinfo Paul Kocialkowski
2015-04-18  9:13   ` Russell King - ARM Linux
2015-04-18  9:45     ` Paul Kocialkowski
2015-04-18 12:27       ` Russell King - ARM Linux
2015-04-18 12:37         ` Paul Kocialkowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).