mach-snapdragon: parse memory ourselves

The generic memory parsing code in U-Boot lacks a few things that we
need on Qualcomm:

1. It sets gd->ram_size and gd->ram_base to represent a single memory
   block.
2. setup_dest_addr() later relocates U-Boot to ram_base + ram_size, the
   end of that first memory block.

This results in all memory beyond U-Boot being unusable in Linux when
booting with EFI.

Since the ranges in the memory node may be out of order, the only way
for us to correctly determine the relocation address for U-Boot is to
parse all memory regions and find the highest valid address.

We can't use fdtdec_setup_memory_banksize() since it stores the result
in gd->bd which is not yet allocated.

Hence, this commit, which implements an optimised parser to read the
memory blocks and store them in the .data section where they will
survive relocation.

We set ram_base and ram_size to describe the entire address space of
memory, with the assumption that the last memory region is big enough
for U-Boot, its DTB, and heap. On all boards tested so far this seems
to be a reasonable assumption.

As a nice side effect, our fdt parsing also winds up being faster since
we avoid the overhead of checking address/size-cells or populating
struct resource. We can safely make these optimisations since we only
support ARM64, and trust the reg property to be populated correctly.

After relocation, we then populate gd->bd->bi_dram with the data we
parsed earlier.

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
1 file changed