Bare metal programming on the Pi

Found a somewhat readable (for a non-programmer) account of how to load and run "bare metal" programs on a Pi4. It's at:

formatting link

The author still uses u-boot to load and run his code, leaving the question of how much code he _didn't_ write remains resident and active.

I'm getting the impression that u-boot starts a considerable amount of activity on the GPU. Does it simply go away once an introduced kernel is started? Later on in the tutorial it's clear that bluetooth requires its own software, which doesn't appear to be open source.

So, just how "bare" is bare metal on the Pi?

Thanks for reading,

bob prohaska

Reply to
bob prohaska
Loading thread data ...

AIUI the GPU is really in control of the hardware, all the code that runs on the GPU is closed source binary blobs and there's quite a lot of it.

--
Steve O'Hara-Smith                          |   Directable Mirror Arrays 
C:\>WIN                                     | A better way to focus the sun 
 Click to see the full signature
Reply to
Ahem A Rivet's Shot

The GPU runs its own OS and provides services to the ARM cores via the 'mailbox' interface. Other components (eg wifi and bluetooth) contain their own processors running their own software stacks. In general you don't get sources to software running on 'peripherals'.

On Pis 1-3 the GPU boots *first* and then loads the kernel ready for the ARM. On Pi4 it's a more 'normal' system with the ARM in charge.

You can get the ARM cores to yourself if you want. It is possible to keep u-boot in memory to provide 'firmware' services that your operating system doesn't provide, and there's also TrustZone, although I don't think the Pi environment uses that out of the box (I'm less familiar with Pi4).

If you want to do bare-metal things without U-boot, there's BakingPi:

formatting link
although that's written for the Pi1 and will need small changes for Pis

0/2/3. I'm not sure it'll work on Pi4. There are some PRs for supporting other Pis (Alex hasn't been able to work on it for a while):
formatting link

Theo

Reply to
Theo

Can the firmware services alluded to be called by a user logged in through a "normal" connection? I.e., bypassing normal security and authentication mechanisms? That's not an issue if the firmware is removed/overwritten by the loaded operating system, but if u-boot remains I understand much better the objections raised by open source advocates.

Thank you for a highly informative reply. I'm not competent to do much with BakingPi, certainly nothing remotely useful, but it gives insights which I didn't have before.

bob prohaska

Reply to
bob prohaska

If you're running regular Linux, generally not from userland. If you're running bare-metal, you have kernel privilege so it's up to you how you set things up. You could choose to overwrite u-boot if you don't want it present.

If you have TrustZone, your code running outside TrustZone is protected from trampling over the TZ firmware. If you want to get rid of that firmware you need your bootloader to run things inside the TrustZone. (I don't believe the Pi does anything with TZ by default and may not have TZ support in the hardware)

Theo

Reply to
Theo

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.