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
Touch seeded packages, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1920837

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

Status in apport package in Ubuntu:
  Fix Released
Status in apport source package in Focal:
  In Progress
Status in apport source package in Groovy:
  In Progress

Bug description:
  It would be helpful if bugs reported from images for Raspberry Pi's or
  RISCV systems were tagged so that one could search for bugs from
  systems running those images e.g. 'raspi-image'.

  [Test Case]
  After installing a preinstalled image of Ubuntu for Raspberry Pi do the 
following:
  1) run 'ubuntu-bug apport'
  2) view the bug report and check the Tags field

  With the current version of apport you will not see the tag 'raspi-image'.
  With the version of apport in -proposed you will see the tag 'raspi-image'.

  [Where problems could occur]
  If the code being added is syntactically incorrect then we'd see a Traceback 
which would be bad as it could affect all bug / crash reports.

  [Other Info]
  Since there aren't any Groovy images for RISC-V there will be nothing to test 
there.

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

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to