Building the ZynqMP PMU firmware, the simple way

The PMU firmware

The Zynq UltraScale+ MPSoC, or simply ZynqMP for brevity, is a powerful and complex chip by Xilinx based on ARM cores and an FPGA. Within that chip, the PMU (Platform Management Unit) is a Microblaze processor that handles power states, clock and power domains and other very low-level tasks. It obviously has a crucial role for the chip.

There is no “standard” PMU firmware image: every user is supposed to build a custom one. Luckily its code is open source, and publicly available on the Xilinx Embeddedsw repository.

Building it

Unfortunately building a PMU firmware can be a bit annoying. One of the reasons is that it’s the only programmable Microblaze core in a chip that otherwise has only ARM cores. As such it needs an appropriate toolchain.

One of the solutions is to built it using the Xilinx XSDK, a firmware IDE by Xilinx. But it is a heavyweight tool just to build a 128 kB firmware, and it’s non-trivial to automate in a build process.

The other mainstream option is to let Yocto build it, which is a natural choice if you are using it to build the rest of your system. Some obscure rules are available in the meta-xilinx layer to build a Microblaze toolchain in an otherwise ARM64 configuration, and then use it to build the PMU firmware and its dependencies. This is a powerful method, but it makes it hard to understand how the firmware gets built. It also requires to build a toolchain and several packages at every build from scratch.

Booting with U-Boot SPL

Things get even more complex if you want to boot using U-Boot and its SPL, and here’s why.

To know how the chip resources are to be managed, the PMU firmware needs a “configuration object” to be passed from the outside even before U-Boot proper can start. The Xilinx First Stage Bootloader (FSBL) is able to load the configuration object. But using FSBL has drawbacks, including a poor boot speed.

The obvious alternative is U-Boot SPL, which is fast and the de facto standard in the embedded Linux ecosystem. Except it is currently unable to pass the configuration object to the PMU.

The current best hack to boot with U-Boot SPL is to modify the PMU firmware source code to load a¬†configuration object hard-coded in its own image. This removes the need for the SPL to load it. Implementing this hack requires additional build-time operations, and is implemented for example in the meta-topic Yocto layer. This hack works, although it forces to build a different PMU firmware for every different configuration (e.g. every board), but at the moment there’s not much that can be done. Moreover it adds to the complexity of the build process, since these hacks are not implemented in the meta-xilinx Yocto layer.

Keep it simple, stupid!

Does building a PMU firmware really need to be that complex? Of course not!

So in order to document and simplify the whole process, including the above mentioned hack to boot with U-Boot SPL, I wrote a shell script that does it in the simplest possible way. The design goals for this script are being simple, have minimal dependencies and to be easy to understand and modify.

The resulting script is even simpler than I expected! It also works without the need to setup a Yocto environment or any Xilinx IDE: actually it only needs crosstool-NG to build the Microblaze toolchain and the PMU firmware source code. It also allows to build a toolchain once and reuse it for every build, meaning a different PMU firmware image can be rebuilt in less than 10 seconds.

I published this script on the zynqmp-pmufw-builder GitHub repository. Feel free to use it for your projects, or simply to understand what’s going on when you use other tools!

10 thoughts on “Building the ZynqMP PMU firmware, the simple way”

  1. This script has been a life-saver. I struggled for weeks to sort out the complexity of Xilinx Yocto layers and building PMU firmware. It’s amazing how much simpler it can be. Thanks for your effort to solve this problem.

  2. Hi Luca,
    I followed the steps in After step 2 I have pmu_cfg_obj.c in two different directories (./embeddedsw/lib/sw_apps/zynqmp_fsbl/misc/pm_cfg_obj.c and ./embeddedsw/lib/sw_apps/zynqmp_pmufw/src/pm_cfg_obj.c).

    I tried to ran anyway the step 4 but it returns:

    patching file lib/sw_apps/zynqmp_pmufw/src/pm_binding.c
    Hunk #1 succeeded at 23 (offset -25 lines).
    Hunk #2 succeeded at 65 (offset -25 lines).
    sed: impossibile leggere pm_cfg_obj.c: File o directory non esistente

    Should I copy one of the two files mentioned above in current dir? And then, should I rerun ./ pmufw-patch?

    Thanks. I need to find a way to fix pmu-firmuware issue to create a yocto build for zcu102.

    • Hi Raffaele,

      patching the PMUFW sources to use an hard-coded configuration object is not supported anymore. There is a better way, see for more info. Apologies, I should have updated, I’ll do it now.

      BTW you probably can still use the old, unsupported way by copying your pm_cfg_obj.c in the root of your zynqmp-pmufw-builder clone.

      What matters it that you must use the pm_cfg_obj.c for _your_ hardware and configuration. If you are using a supported development board _and_ you are using it with the same configuration as the vendor, then you can use a pm_cfg_obj.c provided by the vendor or found in the U-Boot sources, but to be generic you should produce that file for your board and configuration. i.e. from your Vivado project.

      I know only one way to produce it: take the XSA (or HDF) file generated by Vivado and open it with Vitis (or XSDK), then follow the wizard to create a FSBL project. You can find your pm_cfg_obj.c somewhere in the generated files: take that file and throw away the rest.

      Hope it helps.

      • Hi Luca,

        I tried again following your updated, after I pulled your git.
        When I ran “$ ./ pmufw-build” I encountered an error:

        microblaze_selftest.S: Assembler messages:
        microblaze_selftest.S:554: Error: unknown opcode “bsifi”
        microblaze_selftest.S:555: Error: unknown opcode “bsefi”
        make: *** [Makefile:61: ../../../lib/microblaze_selftest.o] Error 1
        make: Leaving directory ‘/home/raffaele/yocto/ultra-scale/zynqmp-pmufw-builder/embeddedsw/lib/sw_apps/zynqmp_pmufw/misc/zynqmp_pmufw_bsp/psu_pmu_0/libsrc/standalone/src’

        • Hi Raffaele,

          I think an issue or bug report is more effectively reported as a github issue.

          However, to reply your question: I just tested building and it succeeds. However I tried more recent PMUFW versions (2020.2) instead of 2020.1 that is currently supported by zynqmp-pmufw-builder, and that failed with the same error message. Are you trying to build PMUFW >= 2020.2?

          I will try to look at these versions, but that won’t be very soon I’m afraid. If you solve it before I do, please send a patch or pull request!

  3. Thank you for this. Going to see how hard it’ll be to weld this into Yocto as a build step because there is ABSOLUTELY no reasons for AMD tying you up so when they provide the bulk of the core as FOSS stuff in bitbake metadata layers.

    • Hello Frank,

      a Yocto integration that is simple (unlike the meta-xilinx one, the last time I looked at it at least) would be great indeed!

      However using a script like the one I wrote is probably not the best way to go, especially the step building a toolchain using crosstool-NG does not make much sense in the context of a build system, that has building toolchains in its DNA by its very nature.

      There is work in progress in the Buildroot community to be able to build the PMU firmware along with the Microblaze toolchain within an otherwise ARM64 build. The idea is to add the necessary packages (equivalent to recipes in Yocto terminology) to build the necessary components of a bare metal toolchain: binutils, gcc and newlib. Here is the latest iteration of the patch series. This looks like the most correct approach, and I think it would be for Yocto/OE as well.

      With a proper toolchain in place, building the PMU firmware is really simple, as you can see in patch 5 of the series mentioned above.



Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.