Skip to content

Commit

Permalink
aarch64: re-introduce dtb relocation
Browse files Browse the repository at this point in the history
This allows us to use the global dtb pointer again after switching to the
runtime page tables.

Qemu reserves 1MB for the device tree, but only ~7KB of this is actually used.
Use fdt_pack() to shrink the size of the dtb to the minimum, then relocate it
into the 64KB reserved area, overwriting the preboot.S code as explained in the
following commit:

  3024ac3 aarch64: dtb: read amount of memory from device tree

This partially reverts the following commit:

  69a0ce3 arm: do not relocate DTB, instead read it ahead of time

Use fdt_open_into() to relocate the DTB, and reserve the whole 64KB area to
allow for some extra room in case any OSv driver would ever want to manipulate
or add properties to the device tree after relocation.

The 64KB reserved area should hopefully be large enough to describe any device
we'd see when running as a hypervisor guest. I have seen DTBs as large as 58KB,
but in that case there were a ton of extra peripherals that we'd be unlikely to
ever see when running as a hypervisor guest.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@dornerworks.com>
Message-Id: <20210219215249.25453-2-stewart.hildebrand@dornerworks.com>
  • Loading branch information
stewdk authored and wkozaczuk committed Feb 22, 2021
1 parent dd5f9c3 commit 84c6300
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arch/aarch64/arch-dtb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ bool dtb_get_vmm_is_xen()

void __attribute__((constructor(init_prio::dtb))) dtb_setup()
{
void *olddtb;
int node;
char *cmdline_override;
int len;
Expand Down Expand Up @@ -680,6 +681,17 @@ void __attribute__((constructor(init_prio::dtb))) dtb_setup()
abort("dtb_setup: command line too long.\n");
}

if (fdt_pack(dtb) != 0) {
abort("dtb_setup: failed to pack dtb\n");
}

olddtb = dtb;
dtb = (void *)OSV_KERNEL_BASE;

if (fdt_open_into(olddtb, dtb, 0x10000) != 0) {
abort("dtb_setup: failed to move dtb (dtb too large?)\n");
}

cmdline = (char *)fdt_getprop(dtb, node, "bootargs", NULL);
if (!cmdline) {
abort("dtb_setup: cannot find cmdline after dtb move.\n");
Expand Down

0 comments on commit 84c6300

Please sign in to comment.