[PATCH 2/2] um: Add devicetree support
Vincent Whitchurch
vincent.whitchurch at axis.com
Tue Jan 18 06:20:13 PST 2022
On Fri, Jan 14, 2022 at 02:49:09PM +0100, Rob Herring wrote:
> On Wed, Dec 08, 2021 at 04:11:23PM +0100, Vincent Whitchurch wrote:
> > --- /dev/null
> > +++ b/arch/um/kernel/dtb.c
> > @@ -0,0 +1,41 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +
> > +#include <linux/init.h>
> > +#include <linux/of_fdt.h>
> > +#include <linux/printk.h>
> > +#include <linux/memblock.h>
> > +#include <init.h>
> > +
> > +#include "um_arch.h"
> > +
> > +static char *dtb __initdata;
> > +
> > +void uml_dtb_init(void)
> > +{
> > + long long size;
> > + void *area;
> > +
> > + area = uml_load_file(dtb, &size);
> > + if (!area)
> > + return;
> > +
> > + if (!early_init_dt_scan(area)) {
> > + pr_err("invalid DTB %s\n", dtb);
> > + memblock_free(area, size);
> > + return;
> > + }
> > +
> > + unflatten_device_tree();
> > + early_init_fdt_scan_reserved_mem();
>
> These should be reversed. early_init_fdt_scan_reserved_mem() works on
> the flat tree. Reserved memory needs to be reserved before
> unflatten_device_tree() starts allocating memory. Though I imagine that
> doesn't really matter for UML.
I only tested dynamic allocation of reserved memory, and that,
unsuprisingly, works regardless of the order. But I'll send a patch to
change it.
> Also, does the dtb end up in permanently allocated memory (i.e. not
> init)? It needs to be if not.
The dtb is allocated with memblock_alloc() in arch/um/kernel/load_file.c
and is never freed (except on an error from early_init_dt_scan() as in
the above hunk), so I think this is already taken care of.
More information about the linux-um
mailing list