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
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 <[email protected]>
---
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
Vincent,
----- Ursprüngliche Mail -----
> Von: "Vincent Whitchurch" <[email protected]>
> An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov" <[email protected]>
> CC: [email protected], "linux-kernel" <[email protected]>, "linux-um" <[email protected]>,
> "devicetree" <[email protected]>, "Vincent Whitchurch" <[email protected]>
> 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
On Tue, 2021-12-21 at 21:55 +0100, Richard Weinberger wrote:
> Vincent,
>
> ----- Ursprüngliche Mail -----
> > Von: "Vincent Whitchurch" <[email protected]>
> > An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov" <[email protected]>
> > CC: [email protected], "linux-kernel" <[email protected]>, "linux-um" <[email protected]>,
> > "devicetree" <[email protected]>, "Vincent Whitchurch" <[email protected]>
> > 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
----- Ursprüngliche Mail -----
> Von: "Johannes Berg" <[email protected]>
> An: "richard" <[email protected]>, "Vincent Whitchurch" <[email protected]>
> CC: "Jeff Dike" <[email protected]>, "anton ivanov" <[email protected]>, "kernel" <[email protected]>,
> "linux-kernel" <[email protected]>, "linux-um" <[email protected]>, "devicetree"
> <[email protected]>
> 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" <[email protected]>
>> > An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov"
>> > <[email protected]>
>> > CC: [email protected], "linux-kernel" <[email protected]>, "linux-um"
>> > <[email protected]>,
>> > "devicetree" <[email protected]>, "Vincent Whitchurch"
>> > <[email protected]>
>> > 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
On Tue, Dec 21, 2021 at 10:13:03PM +0100, Richard Weinberger wrote:
> ----- Urspr?ngliche Mail -----
> > Von: "Johannes Berg" <[email protected]>
> > 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?
Vincent,
----- Ursprüngliche Mail -----
> Von: "Vincent Whitchurch" <[email protected]>
> An: "richard" <[email protected]>
> CC: "Johannes Berg" <[email protected]>, "Jeff Dike" <[email protected]>, "anton ivanov"
> <[email protected]>, "kernel" <[email protected]>, "linux-kernel" <[email protected]>,
> "linux-um" <[email protected]>, "devicetree" <[email protected]>
> 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" <[email protected]>
>> > 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