On 10/09/2011 08:55 PM, Sascha Silbe wrote:
Excerpts from Simon Schampijer's message of 2011-10-09 18:01:35 +0200:

The serial number is often only readable by root on non-XO
hardware, that is why we do not read it. If the serial number
can not be found on an XO we display the entry as 'Not available'.
[...]

-def get_firmware_number():
-    firmware_no = None
-    if os.path.exists(os.path.join(_OFW_TREE, _MODEL)):
-        firmware_no = _read_file(os.path.join(_OFW_TREE, _MODEL))
-    elif os.path.exists(os.path.join(_PROC_TREE, _MODEL)):
-        firmware_no = _read_file(os.path.join(_PROC_TREE, _MODEL))
+def _parse_olpc_firmware_number(firmware_no):
      if firmware_no is None:
          firmware_no = _not_available
      else:
@@ -111,6 +107,21 @@ def get_firmware_number():
      return firmware_no


+def get_firmware_number():
+    firmware_no = None
+    if os.path.exists(os.path.join(_OFW_TREE, _MODEL)):
+        firmware_no = _read_file(os.path.join(_OFW_TREE, _MODEL))
+        firmware_no = _parse_olpc_firmware_number(firmware_no)
+    elif os.path.exists(os.path.join(_PROC_TREE, _MODEL)):
+        firmware_no = _read_file(os.path.join(_PROC_TREE, _MODEL))
+        firmware_no = _parse_olpc_firmware_number(firmware_no)
+    elif os.path.exists(os.path.join(_DMI_DIRECTORY, 'bios_version')):
+        firmware_no = _read_file(os.path.join(_DMI_DIRECTORY, 'bios_version'))
+        if firmware_no is None:
+            firmware_no = _not_available
+    return firmware_no

[...]

There still seems to be some confusion over what is available on
various systems (esp. "non-XOs"), so here are a few real-life examples:


== Apple eMac (powerpc) ==

{{{
sascha.silbe@emac:~$ uname -r
2.6.32-5-powerpc
sascha.silbe@emac:~$ tr '\0' '\n'<  /proc/device-tree/model
PowerMac4,4
sascha.silbe@emac:~$ tr '\0' '\n'<  /proc/device-tree/openprom/model
OpenFirmware 3
sascha.silbe@emac:~$ tr '\0' '\n'<  /proc/device-tree/banner-name
-bash: /proc/device-tree/banner-name: No such file or directory
sascha.silbe@emac:~$ tr '\0' '\n'<  /proc/device-tree/compatible
PowerMac4,4
MacRISC2
MacRISC
Power Macintosh
sascha.silbe@emac:~$ tr '\0' '\n'<  /proc/device-tree/serial-number |sed -e 
's/[A-Za-z]/A/g' -e 's/[0-9]/0/g' |grep -v '^$'
A0A
AAA0000A0
sascha.silbe@emac:~$ ls /sys/class/dmi/id
ls: cannot access /sys/class/dmi/id: No such file or directory
sascha.silbe@emac:~$ cat /proc/cpuinfo
processor       : 0
cpu             : 7455, altivec supported
clock           : 999.999997MHz
revision        : 3.3 (pvr 8001 0303)
bogomips        : 66.57
timebase        : 33289815
platform        : PowerMac
model           : PowerMac4,4
machine         : PowerMac4,4
motherboard     : PowerMac4,4 MacRISC2 MacRISC Power Macintosh
detected as     : 80 (eMac)
pmac flags      : 00000010
L2 cache        : 256K unified
pmac-generation : NewWorld
Memory          : 640 MB
}}}


== OpenRD Ultimate (armel) ==

{{{
sascha.silbe@flatty:~$ uname -r
2.6.32-5-kirkwood
sascha.silbe@flatty:~$ ls /proc/device-tree
ls: cannot access /proc/device-tree: No such file or directory
sascha.silbe@flatty:~$ ls /sys/class/dmi/id
ls: cannot access /sys/class/dmi/id: No such file or directory
sascha.silbe@flatty:~$ cat /proc/cpuinfo
Processor       : Feroceon 88FR131 rev 1 (v5l)
BogoMIPS        : 1199.30
Features        : swp half thumb fastmult edsp
CPU implementer : 0x56
CPU architecture: 5TE
CPU variant     : 0x2
CPU part        : 0x131
CPU revision    : 1

Hardware        : Marvell OpenRD Ultimate Board
Revision        : 0000
Serial          : 0000000000000000
}}}


== Athlon64 based PC (amd64) ==

{{{
sascha.silbe@twin:~$ uname -r
2.6.32-5-amd64
sascha.silbe@twin:~$ ls /proc/device-tree
ls: cannot access /proc/device-tree: No such file or directory
sascha.silbe@twin:~$ cat /sys/class/dmi/id/product_name
GA-MA78G-DS3H
sascha.silbe@twin:~$ cat /sys/class/dmi/id/product_version

sascha.silbe@twin:~$ cat /sys/class/dmi/id/bios_vendor
Award Software International, Inc.
sascha.silbe@twin:~$ cat /sys/class/dmi/id/bios_version
F3
}}}


== XO-1.5 (i386) ==

{{{
sascha.silbe@xo15-sascha:~$ uname -r
2.6.35.13-xo1.5-2-00905-g483bf23
sascha.silbe@xo15-sascha:~$ ls /proc/device-tree
ls: cannot access /proc/device-tree: No such file or directory
sascha.silbe@xo15-sascha:~$ tr '\0' '\n'<  /ofw/model
D4
sascha.silbe@xo15-sascha:~$ tr '\0' '\n'<  /ofw/compatible
-bash: /ofw/compatible: No such file or directory
sascha.silbe@xo15-sascha:~$ tr '\0' '\n'<  /ofw/openprom/model
CL1   Q3A64  Q3A
sascha.silbe@xo15-sascha:~$ cat /sys/class/dmi/id/product_name
XO
sascha.silbe@xo15-sascha:~$ cat /sys/class/dmi/id/product_version
1.5
sascha.silbe@xo15-sascha:~$ cat /sys/class/dmi/id/bios_vendor
  IE8y2D ScD%g4r2bAIFA.
sascha.silbe@xo15-sascha:~$ cat /sys/class/dmi/id/bios_version
OLPC Ver 1.00.15
}}}


== XO-1.75 (armel) ==

{{{
sascha.silbe@mimosa:~$ uname -r
3.0.0-mimosa-1-00159-g1abf0b6
sascha.silbe@mimosa:~$ tr '\0' '\n'<  /proc/device-tree/model
1B1
sascha.silbe@mimosa:~$ tr '\0' '\n'<  /proc/device-tree/compatible
olpc,xo-1.75
sascha.silbe@mimosa:~$ tr '\0' '\n'<  /proc/device-tree/openprom/model
CL2   Q4B11  Q4B
sascha.silbe@mimosa:~$ tr '\0' '\n'<  /proc/device-tree/banner-name
OLPC 1B1
sascha.silbe@mimosa:~$ tr '\0' '\n'<  /proc/device-tree/serial-number |sed -e 
's/[A-Za-z]/A/g' -e 's/[0-9]/0/g'
AAA0000000A
sascha.silbe@mimosa:~$ ls /sys/class/dmi/id
ls: cannot access /sys/class/dmi/id: No such file or directory
sascha.silbe@mimosa:~$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp iwmmxt thumbee vfpv3
vfpv3d16
CPU implementer : 0x56
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0x581
CPU revision    : 5

Hardware        : OLPC XO-1.75
Revision        : 0000
Serial          : 0000000000000000
}}}

All of the above are running Debian Squeeze, except for the XO-1.75
which is running Debian Wheezy. The XOs are running custom kernels
(based on OLPC git), all others stock Debian kernels.


Based on the limited sample given above, I can say:

1. On systems with device tree support, the information from device tree
    is more useful than what's available via DMI (if anything).
2. There's no standard format for the openprom/model and serial-number
    entries.
3. For the serial-number entry we can come up with a simple transformation
    that can handle both formats given above: replace \0 with ' ' and
    trim spaces.
4. For openprom/model OTOH we might want to special-case XOs as they
    contain more than just the firmware version in that entry.


Your patch is almost fine - it should just make clear that what we get
from .../openprom/model is not always an OLPC style firmware version and
make sure not to choke on other formats. E.g.:


def _parse_firmware_number(firmware_no):
     if firmware_no is None:
         return _not_available

     firmware_no = firmware_no.replace('\0', ' ').strip()

     # try to extract Open Firmware version from OLPC style version
     # string, e.g. "CL2   Q4B11  Q4B"
     if len(firmware_no) != 16:
         return firmware_no

     fields = re.split(' +', firmware_no)
     if len(fields) != 3 or not fields[1].startswith(fields[2]):
         return firmware_no

     return fields[1]

def _parse_firmware_number(firmware_no):
    if firmware_no is None:
        firmware_no = _not_available
    else:
        # try to extract Open Firmware version from OLPC style
        # version string, e.g. "CL2   Q4B11 Q4B"
        fields = re.split(' +', firmware_no)
        if len(fields) == 3:
            firmware_no = fields[1]
    return firmware_no

Thanks for the input. I would suggest the method above. It contains the old check which works fine on the XO and in the case of the powerpc it will return "OpenFirmware 3".

Btw, today is the tarballs due day for the bug fix release, would be great to include this one. In any case already the original patch I would be happy to push as powerpc is a real edge case and the original patch has been tested.

Regards,
   Simon
_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to