* [PATCH 0/2] Devicetree support for UML
@ 2021-12-08 15:11 Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 1/2] um: Extract load file helper from initrd.c Vincent Whitchurch
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Vincent Whitchurch @ 2021-12-08 15:11 UTC (permalink / raw)
To: jdike, richard, anton.ivanov
Cc: kernel, linux-kernel, linux-um, devicetree, Vincent Whitchurch
This series add support for passing a devicetree blob to UML. It can be used
for testing device drivers.
Vincent Whitchurch (2):
um: Extract load file helper from initrd.c
um: Add devicetree support
arch/um/Kconfig | 1 +
arch/um/kernel/Makefile | 2 ++
arch/um/kernel/dtb.c | 41 +++++++++++++++++++++++++
arch/um/kernel/initrd.c | 48 ++++--------------------------
arch/um/kernel/load_file.c | 61 ++++++++++++++++++++++++++++++++++++++
arch/um/kernel/um_arch.c | 3 ++
arch/um/kernel/um_arch.h | 14 +++++++++
7 files changed, 127 insertions(+), 43 deletions(-)
create mode 100644 arch/um/kernel/dtb.c
create mode 100644 arch/um/kernel/load_file.c
create mode 100644 arch/um/kernel/um_arch.h
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] um: Extract load file helper from initrd.c
2021-12-08 15:11 [PATCH 0/2] Devicetree support for UML Vincent Whitchurch
@ 2021-12-08 15:11 ` Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 2/2] um: Add devicetree support Vincent Whitchurch
2021-12-21 20:55 ` [PATCH 0/2] Devicetree support for UML Richard Weinberger
2 siblings, 0 replies; 10+ messages in thread
From: Vincent Whitchurch @ 2021-12-08 15:11 UTC (permalink / raw)
To: jdike, richard, anton.ivanov
Cc: kernel, linux-kernel, linux-um, devicetree, Vincent Whitchurch
The file loading support in initrd.c can be re-used for
loading devicetrees. Move it out of initrd.c.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
arch/um/kernel/Makefile | 1 +
arch/um/kernel/initrd.c | 48 ++++--------------------------
arch/um/kernel/load_file.c | 61 ++++++++++++++++++++++++++++++++++++++
arch/um/kernel/um_arch.h | 8 +++++
4 files changed, 75 insertions(+), 43 deletions(-)
create mode 100644 arch/um/kernel/load_file.c
create mode 100644 arch/um/kernel/um_arch.h
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index 1d18e4e46989..92692bfef7ae 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -18,6 +18,7 @@ obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
physmem.o process.o ptrace.o reboot.o sigio.o \
signal.o syscall.o sysrq.o time.o tlb.o trap.o \
um_arch.o umid.o maccess.o kmsg_dump.o capflags.o skas/
+obj-y += load_file.o
obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
obj-$(CONFIG_GPROF) += gprof_syms.o
diff --git a/arch/um/kernel/initrd.c b/arch/um/kernel/initrd.c
index c1981ffb7179..47b8cb1a1156 100644
--- a/arch/um/kernel/initrd.c
+++ b/arch/um/kernel/initrd.c
@@ -10,37 +10,21 @@
#include <init.h>
#include <os.h>
+#include "um_arch.h"
+
/* Changed by uml_initrd_setup, which is a setup */
static char *initrd __initdata = NULL;
-static int load_initrd(char *filename, void *buf, int size);
int __init read_initrd(void)
{
+ unsigned long long size;
void *area;
- long long size;
- int err;
-
- if (initrd == NULL)
- return 0;
- err = os_file_size(initrd, &size);
- if (err)
+ if (!initrd)
return 0;
- /*
- * This is necessary because alloc_bootmem craps out if you
- * ask for no memory.
- */
- if (size == 0) {
- printk(KERN_ERR "\"%s\" is a zero-size initrd\n", initrd);
- return 0;
- }
-
- area = memblock_alloc(size, SMP_CACHE_BYTES);
+ area = uml_load_file(initrd, &size);
if (!area)
- panic("%s: Failed to allocate %llu bytes\n", __func__, size);
-
- if (load_initrd(initrd, area, size) == -1)
return 0;
initrd_start = (unsigned long) area;
@@ -59,25 +43,3 @@ __uml_setup("initrd=", uml_initrd_setup,
" This is used to boot UML from an initrd image. The argument is the\n"
" name of the file containing the image.\n\n"
);
-
-static int load_initrd(char *filename, void *buf, int size)
-{
- int fd, n;
-
- fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
- if (fd < 0) {
- printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
- -fd);
- return -1;
- }
- n = os_read_file(fd, buf, size);
- if (n != size) {
- printk(KERN_ERR "Read of %d bytes from '%s' failed, "
- "err = %d\n", size,
- filename, -n);
- return -1;
- }
-
- os_close_file(fd);
- return 0;
-}
diff --git a/arch/um/kernel/load_file.c b/arch/um/kernel/load_file.c
new file mode 100644
index 000000000000..5cecd0e291fb
--- /dev/null
+++ b/arch/um/kernel/load_file.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ */
+#include <linux/memblock.h>
+#include <os.h>
+
+#include "um_arch.h"
+
+static int __init __uml_load_file(const char *filename, void *buf, int size)
+{
+ int fd, n;
+
+ fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
+ if (fd < 0) {
+ printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
+ -fd);
+ return -1;
+ }
+ n = os_read_file(fd, buf, size);
+ if (n != size) {
+ printk(KERN_ERR "Read of %d bytes from '%s' failed, "
+ "err = %d\n", size,
+ filename, -n);
+ return -1;
+ }
+
+ os_close_file(fd);
+ return 0;
+}
+
+void *uml_load_file(const char *filename, unsigned long long *size)
+{
+ void *area;
+ int err;
+
+ *size = 0;
+
+ if (!filename)
+ return NULL;
+
+ err = os_file_size(filename, size);
+ if (err)
+ return NULL;
+
+ if (*size == 0) {
+ printk(KERN_ERR "\"%s\" is empty\n", filename);
+ return NULL;
+ }
+
+ area = memblock_alloc(*size, SMP_CACHE_BYTES);
+ if (!area)
+ panic("%s: Failed to allocate %llu bytes\n", __func__, *size);
+
+ if (__uml_load_file(filename, area, *size)) {
+ memblock_free(area, *size);
+ return NULL;
+ }
+
+ return area;
+}
diff --git a/arch/um/kernel/um_arch.h b/arch/um/kernel/um_arch.h
new file mode 100644
index 000000000000..b195df3a09a0
--- /dev/null
+++ b/arch/um/kernel/um_arch.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __UML_ARCH_H__
+#define __UML_ARCH_H__
+
+extern void * __init uml_load_file(const char *filename, unsigned long long *size);
+
+#endif
--
2.33.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] um: Add devicetree support
2021-12-08 15:11 [PATCH 0/2] Devicetree support for UML Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 1/2] um: Extract load file helper from initrd.c Vincent Whitchurch
@ 2021-12-08 15:11 ` Vincent Whitchurch
2022-01-14 13:49 ` Rob Herring
2021-12-21 20:55 ` [PATCH 0/2] Devicetree support for UML Richard Weinberger
2 siblings, 1 reply; 10+ messages in thread
From: Vincent Whitchurch @ 2021-12-08 15:11 UTC (permalink / raw)
To: jdike, richard, anton.ivanov
Cc: kernel, linux-kernel, linux-um, devicetree, Vincent Whitchurch
Add a dtb=<filename> option to boot UML with a devicetree blob. This
can be used for testing driver code using UML.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
arch/um/Kconfig | 1 +
arch/um/kernel/Makefile | 1 +
arch/um/kernel/dtb.c | 41 ++++++++++++++++++++++++++++++++++++++++
arch/um/kernel/um_arch.c | 3 +++
arch/um/kernel/um_arch.h | 6 ++++++
5 files changed, 52 insertions(+)
create mode 100644 arch/um/kernel/dtb.c
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index c18b45f75d41..1cf7ef3a2b81 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -18,6 +18,7 @@ config UML
select HAVE_DEBUG_KMEMLEAK
select HAVE_DEBUG_BUGVERBOSE
select NO_DMA if !UML_DMA_EMULATION
+ select OF_EARLY_FLATTREE
select GENERIC_IRQ_SHOW
select GENERIC_CPU_DEVICES
select HAVE_GCC_PLUGINS
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index 92692bfef7ae..ebd0cca3ff26 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -22,6 +22,7 @@ obj-y += load_file.o
obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
obj-$(CONFIG_GPROF) += gprof_syms.o
+obj-$(CONFIG_OF) += dtb.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
obj-$(CONFIG_GENERIC_PCI_IOMAP) += ioport.o
diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c
new file mode 100644
index 000000000000..ca69d72025f3
--- /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();
+}
+
+static int __init uml_dtb_setup(char *line, int *add)
+{
+ dtb = line;
+ return 0;
+}
+
+__uml_setup("dtb=", uml_dtb_setup,
+"dtb=<file>\n"
+" Boot the kernel with the devicetree blob from the specified file.\n"
+);
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 54447690de11..abceeabe29b9 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -29,6 +29,8 @@
#include <mem_user.h>
#include <os.h>
+#include "um_arch.h"
+
#define DEFAULT_COMMAND_LINE_ROOT "root=98:0"
#define DEFAULT_COMMAND_LINE_CONSOLE "console=tty"
@@ -407,6 +409,7 @@ void __init setup_arch(char **cmdline_p)
stack_protections((unsigned long) &init_thread_info);
setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
mem_total_pages(physmem_size, iomem_size, highmem);
+ uml_dtb_init();
read_initrd();
paging_init();
diff --git a/arch/um/kernel/um_arch.h b/arch/um/kernel/um_arch.h
index b195df3a09a0..1e07fb7ee35e 100644
--- a/arch/um/kernel/um_arch.h
+++ b/arch/um/kernel/um_arch.h
@@ -5,4 +5,10 @@
extern void * __init uml_load_file(const char *filename, unsigned long long *size);
+#ifdef CONFIG_OF
+extern void __init uml_dtb_init(void);
+#else
+static inline void uml_dtb_init(void) { }
+#endif
+
#endif
--
2.33.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] Devicetree support for UML
2021-12-08 15:11 [PATCH 0/2] Devicetree support for UML Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 1/2] um: Extract load file helper from initrd.c Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 2/2] um: Add devicetree support Vincent Whitchurch
@ 2021-12-21 20:55 ` Richard Weinberger
2021-12-21 20:56 ` Johannes Berg
2 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2021-12-21 20:55 UTC (permalink / raw)
To: Vincent Whitchurch
Cc: Jeff Dike, anton ivanov, kernel, linux-kernel, linux-um, devicetree
Vincent,
----- Ursprüngliche Mail -----
> Von: "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> An: "Jeff Dike" <jdike@addtoit.com>, "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>
> CC: kernel@axis.com, "linux-kernel" <linux-kernel@vger.kernel.org>, "linux-um" <linux-um@lists.infradead.org>,
> "devicetree" <devicetree@vger.kernel.org>, "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> Gesendet: Mittwoch, 8. Dezember 2021 16:11:21
> Betreff: [PATCH 0/2] Devicetree support for UML
> This series add support for passing a devicetree blob to UML. It can be used
> for testing device drivers.
Nice feature.
Code looks good so far. But while building I'm facing this warning:
WARNING: unmet direct dependencies detected for OF_EARLY_FLATTREE
Depends on [n]: OF [=n]
Selected by [y]:
- UML [=y]
Please note that my UML config has CONFIG_OF=n.
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] Devicetree support for UML
2021-12-21 20:55 ` [PATCH 0/2] Devicetree support for UML Richard Weinberger
@ 2021-12-21 20:56 ` Johannes Berg
2021-12-21 21:13 ` Richard Weinberger
0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2021-12-21 20:56 UTC (permalink / raw)
To: Richard Weinberger, Vincent Whitchurch
Cc: Jeff Dike, anton ivanov, kernel, linux-kernel, linux-um, devicetree
On Tue, 2021-12-21 at 21:55 +0100, Richard Weinberger wrote:
> Vincent,
>
> ----- Ursprüngliche Mail -----
> > Von: "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> > An: "Jeff Dike" <jdike@addtoit.com>, "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>
> > CC: kernel@axis.com, "linux-kernel" <linux-kernel@vger.kernel.org>, "linux-um" <linux-um@lists.infradead.org>,
> > "devicetree" <devicetree@vger.kernel.org>, "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> > Gesendet: Mittwoch, 8. Dezember 2021 16:11:21
> > Betreff: [PATCH 0/2] Devicetree support for UML
>
> > This series add support for passing a devicetree blob to UML. It can be used
> > for testing device drivers.
>
> Nice feature.
> Code looks good so far. But while building I'm facing this warning:
>
> WARNING: unmet direct dependencies detected for OF_EARLY_FLATTREE
> Depends on [n]: OF [=n]
> Selected by [y]:
> - UML [=y]
>
>
> Please note that my UML config has CONFIG_OF=n.
>
Hm. So maybe that needs to be
select OF_EARLY_FLATTREE if OF
or so?
johannes
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] Devicetree support for UML
2021-12-21 20:56 ` Johannes Berg
@ 2021-12-21 21:13 ` Richard Weinberger
2021-12-22 10:23 ` Vincent Whitchurch
0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2021-12-21 21:13 UTC (permalink / raw)
To: Johannes Berg
Cc: Vincent Whitchurch, Jeff Dike, anton ivanov, kernel,
linux-kernel, linux-um, devicetree
----- Ursprüngliche Mail -----
> Von: "Johannes Berg" <johannes@sipsolutions.net>
> An: "richard" <richard@nod.at>, "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> CC: "Jeff Dike" <jdike@addtoit.com>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "kernel" <kernel@axis.com>,
> "linux-kernel" <linux-kernel@vger.kernel.org>, "linux-um" <linux-um@lists.infradead.org>, "devicetree"
> <devicetree@vger.kernel.org>
> Gesendet: Dienstag, 21. Dezember 2021 21:56:50
> Betreff: Re: [PATCH 0/2] Devicetree support for UML
> On Tue, 2021-12-21 at 21:55 +0100, Richard Weinberger wrote:
>> Vincent,
>>
>> ----- Ursprüngliche Mail -----
>> > Von: "Vincent Whitchurch" <vincent.whitchurch@axis.com>
>> > An: "Jeff Dike" <jdike@addtoit.com>, "richard" <richard@nod.at>, "anton ivanov"
>> > <anton.ivanov@cambridgegreys.com>
>> > CC: kernel@axis.com, "linux-kernel" <linux-kernel@vger.kernel.org>, "linux-um"
>> > <linux-um@lists.infradead.org>,
>> > "devicetree" <devicetree@vger.kernel.org>, "Vincent Whitchurch"
>> > <vincent.whitchurch@axis.com>
>> > Gesendet: Mittwoch, 8. Dezember 2021 16:11:21
>> > Betreff: [PATCH 0/2] Devicetree support for UML
>>
>> > This series add support for passing a devicetree blob to UML. It can be used
>> > for testing device drivers.
>>
>> Nice feature.
>> Code looks good so far. But while building I'm facing this warning:
>>
>> WARNING: unmet direct dependencies detected for OF_EARLY_FLATTREE
>> Depends on [n]: OF [=n]
>> Selected by [y]:
>> - UML [=y]
>>
>>
>> Please note that my UML config has CONFIG_OF=n.
>>
>
> Hm. So maybe that needs to be
>
> select OF_EARLY_FLATTREE if OF
Yeah, IIRC arm and mips use such a pattern too.
Vincent, what do you think?
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] Devicetree support for UML
2021-12-21 21:13 ` Richard Weinberger
@ 2021-12-22 10:23 ` Vincent Whitchurch
2021-12-22 19:31 ` Richard Weinberger
0 siblings, 1 reply; 10+ messages in thread
From: Vincent Whitchurch @ 2021-12-22 10:23 UTC (permalink / raw)
To: Richard Weinberger
Cc: Johannes Berg, Jeff Dike, anton ivanov, kernel, linux-kernel,
linux-um, devicetree
On Tue, Dec 21, 2021 at 10:13:03PM +0100, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
> > Von: "Johannes Berg" <johannes@sipsolutions.net>
> > Gesendet: Dienstag, 21. Dezember 2021 21:56:50
> > On Tue, 2021-12-21 at 21:55 +0100, Richard Weinberger wrote:
> >> WARNING: unmet direct dependencies detected for OF_EARLY_FLATTREE
> >> Depends on [n]: OF [=n]
> >> Selected by [y]:
> >> - UML [=y]
> >>
> >> Please note that my UML config has CONFIG_OF=n.
> >>
> > Hm. So maybe that needs to be
> >
> > select OF_EARLY_FLATTREE if OF
>
> Yeah, IIRC arm and mips use such a pattern too. Vincent, what do you
> think?
Yes, that looks like the correct fix. I've tested it and it works. Do
you prefer to fix it up locally or should I repost?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] Devicetree support for UML
2021-12-22 10:23 ` Vincent Whitchurch
@ 2021-12-22 19:31 ` Richard Weinberger
0 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2021-12-22 19:31 UTC (permalink / raw)
To: Vincent Whitchurch
Cc: Johannes Berg, Jeff Dike, anton ivanov, kernel, linux-kernel,
linux-um, devicetree
Vincent,
----- Ursprüngliche Mail -----
> Von: "Vincent Whitchurch" <vincent.whitchurch@axis.com>
> An: "richard" <richard@nod.at>
> CC: "Johannes Berg" <johannes@sipsolutions.net>, "Jeff Dike" <jdike@addtoit.com>, "anton ivanov"
> <anton.ivanov@cambridgegreys.com>, "kernel" <kernel@axis.com>, "linux-kernel" <linux-kernel@vger.kernel.org>,
> "linux-um" <linux-um@lists.infradead.org>, "devicetree" <devicetree@vger.kernel.org>
> Gesendet: Mittwoch, 22. Dezember 2021 11:23:57
> Betreff: Re: [PATCH 0/2] Devicetree support for UML
> On Tue, Dec 21, 2021 at 10:13:03PM +0100, Richard Weinberger wrote:
>> ----- Ursprüngliche Mail -----
>> > Von: "Johannes Berg" <johannes@sipsolutions.net>
>> > Gesendet: Dienstag, 21. Dezember 2021 21:56:50
>> > On Tue, 2021-12-21 at 21:55 +0100, Richard Weinberger wrote:
>> >> WARNING: unmet direct dependencies detected for OF_EARLY_FLATTREE
>> >> Depends on [n]: OF [=n]
>> >> Selected by [y]:
>> >> - UML [=y]
>> >>
>> >> Please note that my UML config has CONFIG_OF=n.
>> >>
>> > Hm. So maybe that needs to be
>> >
>> > select OF_EARLY_FLATTREE if OF
>>
>> Yeah, IIRC arm and mips use such a pattern too. Vincent, what do you
>> think?
>
> Yes, that looks like the correct fix. I've tested it and it works. Do
> you prefer to fix it up locally or should I repost?
I'll fix it myself. :-)
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] um: Add devicetree support
2021-12-08 15:11 ` [PATCH 2/2] um: Add devicetree support Vincent Whitchurch
@ 2022-01-14 13:49 ` Rob Herring
2022-01-18 14:20 ` Vincent Whitchurch
0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2022-01-14 13:49 UTC (permalink / raw)
To: Vincent Whitchurch
Cc: jdike, richard, anton.ivanov, kernel, linux-kernel, linux-um, devicetree
On Wed, Dec 08, 2021 at 04:11:23PM +0100, Vincent Whitchurch wrote:
> Add a dtb=<filename> option to boot UML with a devicetree blob. This
> can be used for testing driver code using UML.
Neat!
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
> arch/um/Kconfig | 1 +
> arch/um/kernel/Makefile | 1 +
> arch/um/kernel/dtb.c | 41 ++++++++++++++++++++++++++++++++++++++++
> arch/um/kernel/um_arch.c | 3 +++
> arch/um/kernel/um_arch.h | 6 ++++++
> 5 files changed, 52 insertions(+)
> create mode 100644 arch/um/kernel/dtb.c
>
> diff --git a/arch/um/Kconfig b/arch/um/Kconfig
> index c18b45f75d41..1cf7ef3a2b81 100644
> --- a/arch/um/Kconfig
> +++ b/arch/um/Kconfig
> @@ -18,6 +18,7 @@ config UML
> select HAVE_DEBUG_KMEMLEAK
> select HAVE_DEBUG_BUGVERBOSE
> select NO_DMA if !UML_DMA_EMULATION
> + select OF_EARLY_FLATTREE
> select GENERIC_IRQ_SHOW
> select GENERIC_CPU_DEVICES
> select HAVE_GCC_PLUGINS
> diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
> index 92692bfef7ae..ebd0cca3ff26 100644
> --- a/arch/um/kernel/Makefile
> +++ b/arch/um/kernel/Makefile
> @@ -22,6 +22,7 @@ obj-y += load_file.o
>
> obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
> obj-$(CONFIG_GPROF) += gprof_syms.o
> +obj-$(CONFIG_OF) += dtb.o
> obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
> obj-$(CONFIG_STACKTRACE) += stacktrace.o
> obj-$(CONFIG_GENERIC_PCI_IOMAP) += ioport.o
> diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c
> new file mode 100644
> index 000000000000..ca69d72025f3
> --- /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.
Also, does the dtb end up in permanently allocated memory (i.e. not
init)? It needs to be if not.
Rob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] um: Add devicetree support
2022-01-14 13:49 ` Rob Herring
@ 2022-01-18 14:20 ` Vincent Whitchurch
0 siblings, 0 replies; 10+ messages in thread
From: Vincent Whitchurch @ 2022-01-18 14:20 UTC (permalink / raw)
To: Rob Herring
Cc: jdike, richard, anton.ivanov, kernel, linux-kernel, linux-um, devicetree
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-01-18 14:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 15:11 [PATCH 0/2] Devicetree support for UML Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 1/2] um: Extract load file helper from initrd.c Vincent Whitchurch
2021-12-08 15:11 ` [PATCH 2/2] um: Add devicetree support Vincent Whitchurch
2022-01-14 13:49 ` Rob Herring
2022-01-18 14:20 ` Vincent Whitchurch
2021-12-21 20:55 ` [PATCH 0/2] Devicetree support for UML Richard Weinberger
2021-12-21 20:56 ` Johannes Berg
2021-12-21 21:13 ` Richard Weinberger
2021-12-22 10:23 ` Vincent Whitchurch
2021-12-22 19:31 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).