0

A single Raspberry Pi OS instance seems able to boot on any board. Some other OSes don't. I'm under the impression that the various MCUs don't share instruction sets that are fully compatible with each other.

What does Raspberry Pi OS do to make this possible?

Does this compatibility come with any drawbacks worth mentioning e.g. in the form of size?

3
  • the CPU's are closely related - it's not unusual in the linux world - think about how a so called Live Linux CD can run on any x86 based CPU
    – Bravo
    Commented Nov 29, 2021 at 22:27
  • @Bravo The problem with thinking about that is that I only know they do — not how. And on the Pi I immediately ran into the opposite case, for e.g. OSMC, which makes me wonder whether the situation is different and warrants some special tricks.
    – Andreas
    Commented Nov 29, 2021 at 22:54
  • Probably something to do with the bcm27xx* device tree blobs in /boot - no idea what OSMC does,
    – Bravo
    Commented Nov 29, 2021 at 23:38

1 Answer 1

3

There are several approaches to this problem (which are not Pi specific actually).

One is "fat binaries" where a binary includes code segments for multiple cpus, and the start up execution environment activates the best one.

Another is to generate system binaries using compiler options that limit the executable to the lowest common denominator set of instructions that work on all cpus in the family. This may limit performance, as newer instructions might allow faster execution. This sometimes can be mitigated by isolating machine specific high performance code in a shared library, and activating the most appropriate version of the shared library at boot.

Another approach is if there are only a few specialized instructions not available on older cpus, install a trap for illegal instructions, and when it is triggered, emulate the missing instruction or back patch a subroutine call in its place.

Sometimes the differences between systems are more along the lines of different devices available, in which case the kernel can probe what is available at startup and either compensate for missing hardware or just not make it available.

The pi (and linux in general) uses several of these approaches at once.

2
  • Thank you. This turned out to be more interesting than expected. Especially instruction emulation. "Fat binaries" and lowest common denominator were the ones that came to mind while asking. Makes sense to cascade the various methods.
    – Andreas
    Commented Nov 30, 2021 at 16:56
  • I may have missed some methods, but I can't think of them right now. The pi kernel seems to use some variations of the above internally too.
    – user10489
    Commented Nov 30, 2021 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.