The most reliable means I know of at the moment for detecting Raspberry
Pi hardware at runtime  is to query the device-tree.

For example, flash-kernel determines the type of board it is running on,
by matching the content of /proc/device-tree/model (e.g. "Raspberry Pi
400 Rev 1.0") against a pre-determined list of strings in its database.
Personally I don't much like matching fixed strings -- new board
revisions frequently come out and then f-k needs patching to add them,
but last cycle I did add the ability to match the "Raspberry Pi *" glob
as an attempt to support new boards even if they come out mid-cycle.
Something similar could be accomplished with some Python like so:

try:
    with open('/proc/device-tree/model', 'r', encoding='ascii') as f:
        is_a_pi = f.read().startswith('Raspberry Pi ')
except FileNotFoundError:
    is_a_pi = False

That seems to work reliably (even on compute modules where the model is
"Raspberry Pi Compute Module 4 Rev 1.0"), but I've no idea if the /proc
/device-tree/model file *always* exists or whether other boards publish
useful information in there.

Another possibility is to look at /proc/device-tree/compatible which I
*think* should always exist assuming a device-tree is in use on the
system. This is a binary file containing a sequence of NUL-terminated
strings, each of which is of the form "vendor,model" and is intended for
kernel driver matching. For example, on the Pi 400 it contains:

raspberrypi,400\0brcm,bcm2711\0

(where \0 is the NUL character). And on a 3B+ contains:

raspberrypi,3-model-b-plus\0brcm,bcm2837\0

My understanding is there's no strict requirement that these strings
appear in any particular order so simple prefix matching is potentially
unreliable. However, it's trivial enough to parse and extract the
"raspberrypi" vendor from this with some Python like:

try:
    with open('/proc/device-tree/compatible', 'rb') as f:
        is_a_pi = any(vendor == 'raspberrypi'
                      for s in f.read().split(b'\0') if s
                      for vendor, model in (s.decode('ascii').split(',', 1),))
except FileNotFoundError:
    is_a_pi = False

Something similar *should* be reasonably useful with just about any
board that uses a device tree (but obviously PCs don't have device-trees
so we still need the file-not-found check).

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1920837

Title:
  apport bugs from official raspi or riscv images are not identified

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1920837/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to