[U-Boot] One u-boot.bin for Raspberry PI 3 and 4 - possible?

Geoff Williams geoff at declarativesystems.com
Fri Sep 27 02:16:55 UTC 2019


Hi List,

TLDR: As subject

I've been following Alexander Graf's uEFI+grub2 presentation on Raspberry PI[1].
I have it working on PI 3 and 4 and its great but I need to re-compile u-boot
for each board which means lots of images.

I would like create a single image to boot grub on PI 3 and 4.

I did my own investigation but hit a wall. In board/raspberrypi/rpi/rpi.c there
is a #IFNDEF..#ELSE around the definition of bcm283x_mem_map which selects a
different memory layout to expose as extern struct mem_map for PI 4 vs anything
else.

I did some hacking to expose two mem_map extern structs and pick the right one
at runtime[2]. Of course this experiment is horrible and breaks all other
boards:

board/raspberrypi/rpi/rpi.c
    static uint32_t rev_type;// = 0x11;

    struct mm_region *mem_map_b = other_bcm283x_mem_map; /* other PIs */
    struct mm_region *mem_map_a = bcm2711_bcm283x_mem_map; /* PI 4 */

    uint32_t get_rpi_hw_ref(void) {
            /* doesn't work get_board_rev(); */
             return rev_type;
    }

arch/arm/cpu/armv8/cache_v8.c
    /* before every use of mem_map... */

      /* nasty hack */
      struct mm_region *mem_map;
      if (get_rpi_hw_ref() == 0x11) {
            mem_map = mem_map_a;
      } else {
            mem_map = mem_map_b;
      }

rev_type gets set by get_board_rev() but I don't believe this function has been
called before mem_map is used[3] so my hack always chooses the else branch.

I'm new to bootloader programming and waiting for a serial cable to arrive so am
working blind but I suspect I'm up against some kind of chicken and egg problem
where the memory map needs to be set before the board revision can be extracted
using the mailbox driver, is anyone able to confirm this or suggest another
approach?

My dream is to be able to compile a single u-boot.bin compiled as armv8-a and be
able to boot any Raspberry PI 3/4 to grub2 from it. Is this realistic?

Cheers,
Geoff


[1] https://www.youtube.com/watch?v=bNL1pd-rwCU
[2] https://github.com/GeoffWilliams/u-boot/tree/nasty
[3] If I initialise rev_type as 0x11 then it works on Raspberry PI 4 but if its
    commented boot fails with rainbow screen which tells me that rev_type wasn't
    assigned (or didn't contain 0x11...?) before mem_map was used.


More information about the U-Boot mailing list