Re: [PATCH v19 05/13] of: Add a common kexec FDT setup function
From: Rob Herring
Date: Tue Jun 15 2021 - 10:02:07 EST
On Tue, Jun 15, 2021 at 6:18 AM Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:
>
> Hi Lakshmi and Rob,
>
> On Sun, Feb 21, 2021 at 6:52 PM Lakshmi Ramasubramanian
> <nramas@xxxxxxxxxxxxxxxxxxx> wrote:
> > From: Rob Herring <robh@xxxxxxxxxx>
> >
> > Both arm64 and powerpc do essentially the same FDT /chosen setup for
> > kexec. The differences are either omissions that arm64 should have
> > or additional properties that will be ignored. The setup code can be
> > combined and shared by both powerpc and arm64.
> >
> > The differences relative to the arm64 version:
> > - If /chosen doesn't exist, it will be created (should never happen).
> > - Any old dtb and initrd reserved memory will be released.
> > - The new initrd and elfcorehdr are marked reserved.
> > - "linux,booted-from-kexec" is set.
> >
> > The differences relative to the powerpc version:
> > - "kaslr-seed" and "rng-seed" may be set.
> > - "linux,elfcorehdr" is set.
> > - Any existing "linux,usable-memory-range" is removed.
> >
> > Combine the code for setting up the /chosen node in the FDT and updating
> > the memory reservation for kexec, for powerpc and arm64, in
> > of_kexec_alloc_and_setup_fdt() and move it to "drivers/of/kexec.c".
> >
> > Signed-off-by: Rob Herring <robh@xxxxxxxxxx>
> > Signed-off-by: Lakshmi Ramasubramanian <nramas@xxxxxxxxxxxxxxxxxxx>
>
> > --- /dev/null
> > +++ b/drivers/of/kexec.c
>
> > +/*
> > + * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree
> > + *
> > + * @image: kexec image being loaded.
> > + * @initrd_load_addr: Address where the next initrd will be loaded.
> > + * @initrd_len: Size of the next initrd, or 0 if there will be none.
> > + * @cmdline: Command line for the next kernel, or NULL if there will
> > + * be none.
> > + * @extra_fdt_size: Additional size for the new FDT buffer.
> > + *
> > + * Return: fdt on success, or NULL errno on error.
> > + */
> > +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
> > + unsigned long initrd_load_addr,
> > + unsigned long initrd_len,
> > + const char *cmdline, size_t extra_fdt_size)
> > +{
>
> > + /* Did we boot using an initrd? */
> > + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL);
> > + if (prop) {
> > + u64 tmp_start, tmp_end, tmp_size;
> > +
> > + tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop));
> > +
> > + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL);
> > + if (!prop) {
> > + ret = -EINVAL;
> > + goto out;
> > + }
> > +
> > + tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop));
>
> Some kernel code assumes "linux,initrd-{start,end}" are 64-bit,
> other code assumes 32-bit.
It can be either. The above code was a merge of arm64 and powerpc both
of which use 64-bit and still only runs on those arches. It looks like
some powerpc platforms may use 32-bit, but this would have been broken
before.
The code in drivers/of/fdt.c handles either case. We should probably
refactor early_init_dt_check_for_initrd() and this function to use a
common routine.
> linux/Documentation/arm/uefi.rst says 64-bit,
> dt-schema/schemas/chosen.yaml says 32-bit.
We should fix that.
Rob