Documentation: devicetree: root node serial-number property documentation
Subsystems (2)
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
@@ -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
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
@@ -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
@@ -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
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.
Signed-off-by Paul Kocialkowski <[email protected]>
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@@ -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
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
-0unsigned 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.
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
Signed-off-by Paul Kocialkowski <[email protected]>One comment below, but otherwise:
Acked-by Grant Likely <[email protected]>
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@@ -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@@ -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
-0unsigned 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
-0static 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. Ifsystem_serialis 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 theof_rootpointer directly. It is safe to callof_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>
PATCH v4 1/2 Documentation: devicetree: root node serial-number property documentation
In reply to Paul KocialkowskiQuoted 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_idproperty 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
Signed-off-by Paul Kocialkowski <[email protected]>
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@@ -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
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_idproperty 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
Signed-off-by Paul Kocialkowski <[email protected]>Acked-by Rob Herring <[email protected]>What Russell was referring to for submitting is his patch tracker:
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@@ -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
-1This 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>