Discussion:
[ORLinux] Running openrisc linux images in qemu
Stefan Kristiansson
2014-09-08 08:02:48 UTC
Permalink
Hi folks,
I have been trying to get openrisc images to run in qemu for some time now,
with not much success. The basic idea is to run an openrisc Linux kernel
with embedded initrd.
- Kernels compiled with the openrisc toolchain from kernel.org can be loaded
in the upstream version of qemu-system-or32.
- If there is no embedded initrd, the kernel crashes with "no working init found".
So far so good.
Yup ;)
- I then built an initrd using busybox. I could not use the toolchain
from kernel.org, so I had to build my own.
I tried various variants. Ultimately, I was able to build a toolchain
from git://openrisc.net/jonas/toolchain. It did not build cleanly,
so I had to
- disable Werror for gcc and binutils
- disable MAKEINFO for binutils
- disable makeinfo enforcement in binutils
- declare libc_hidden_def(strverscmp) to make strverscmp public in uClibc.
- Build busybox with -D__linux__ as the toolchain doesn't define it.
There has been improvements made to the toolchains and at the same time
some things have shifted places, the most recent toolchains are now
hosted on github under the openrisc organization (https://github.com/openrisc).
Instructions on how to build a uclibc based toolchain from these repositories
can be found here:
http://opencores.org/or1k/OpenRISC_GNU_tool_chain#Linux_.28uClibc.29_toolchain_.28or1k-linux-uclibc.29
(binutils has since these instructions were written been upstreamed,
so you could replace or1k-src with a binutils-gdb snapshot,
but or1k-src should work as well).

(For instance, the old uclibc that you used didn't support archs that doesn't
have the "legacy" syscalls, so upstream openrisc kernels wouldn't work
without an additional patch. https://github.com/openrisc/uClibc-or1k doesn't
have this problem).

You can compile the kernel with this toolchain, but also building the kernel
with the old toolchain should work fine.

As an additional sidenote, some of us have started to shift away from
uclibc in favour of musl-libc, but there are a couple of patches needed
to make that work.
After embedding the toolchain into the kernel (essentially based on the
openrisc defconfig), I tried the resulting kernels all the way back to 3.1.
In 3.1 and 3.2, the kernels hang after "Freeing unused kernel memory: 1456k freed".
Hang means I don't get any further output until I kill the qemu session.
With later kernels, I get a number of warning tracebacks. Here is an example
with the latest upstream kernel (3.17-rc2).
WARNING: CPU: 0 PID: 0 at kernel/rcu/tiny.c:90 0xc00460d0()
WARNING: CPU: 0 PID: 0 at kernel/rcu/tiny.c:111 0xc0045fe0()
WARNING: CPU: 0 PID: 0 at kernel/rcu/tiny.c:148 0xc0045d80()
I haven't seen these warnings, and I have tried running 3.17-rc2, but I have
some local patches applied with stuff I'm working on, so our mileage might vary.
I'll try a "clean" upstream 3.17-rc2 kernel and see if they'll appear here too.
Any idea what I might be doing wrong ? I see messages from others suggesting that
there is a way to run the openrisc kernel, I just seem to be unable to find out
what it is.
Yes, and this is a problem we are aware of, that finding the right way
into OpenRISC isn't always straight forward :(

If the newer toolchain doesn't solve the problems, please ping us back.

Stefan
Stefan Kristiansson
2014-09-08 19:15:28 UTC
Permalink
Ok, the or1k toolchain now builds, and it works (possibly because there have
been some updates to it since last week ;-),
Yes, I noticed that there was a couple of patches from upstream that
I hadn't picked back into or1k-src. Those shouldn't have made any
difference in whether the toolchain build or not, but that's not
so important now since things seems to work for you.
though it needs the following
kernel patch to be able to build the kernel with it.
Any chance to get this cleaned up in the kernel source, if possible one which
works with both the old and new toolchain ? Alternatively, is there some
command line trick I can use instead when building the kernel and/or the
toolchain ?
Yes, I've been slightly looking into this before, and so far the only
solution I have came up with that'd work for both toolchains are to
remove the OUTPUT_FORMAT line all together.
But, I'm not sure of the full implications of such a change...

Stefan
Thanks,
Guenter
---
diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S
index 2d69a85..8c4e492 100644
--- a/arch/openrisc/kernel/vmlinux.lds.S
+++ b/arch/openrisc/kernel/vmlinux.lds.S
@@ -30,7 +30,7 @@
#include <asm/cache.h>
#include <asm-generic/vmlinux.lds.h>
-OUTPUT_FORMAT("elf32-or32", "elf32-or32", "elf32-or32")
+OUTPUT_FORMAT("elf32-or1k", "elf32-or1k", "elf32-or1k")
jiffies = jiffies_64 + 4;
SECTIONS
Stefan Kristiansson
2014-09-08 20:30:49 UTC
Permalink
How about this ? Seems to work for me.
That looks good to me at least.
Thanks,
Guenter
---
From: Guenter Roeck <linux at roeck-us.net>
Date: Mon, 8 Sep 2014 13:03:44 -0700
Subject: [PATCH] openrisc: Support both old (or32) and new (or1k) toolchain
The output file format for or1k has changed from "elf32-or32"
to "elf32-or1k". Select the correct output format automatically
to be able to compile the kernel with both toolchain variants.
Signed-off-by: Guenter Roeck <linux at roeck-us.net>
---
arch/openrisc/kernel/vmlinux.lds.S | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S
index 2d69a85..1c5d21a 100644
--- a/arch/openrisc/kernel/vmlinux.lds.S
+++ b/arch/openrisc/kernel/vmlinux.lds.S
@@ -30,7 +30,13 @@
#include <asm/cache.h>
#include <asm-generic/vmlinux.lds.h>
-OUTPUT_FORMAT("elf32-or32", "elf32-or32", "elf32-or32")
+#ifdef __OR1K__
+#define __OUTPUT_FORMAT "elf32-or1k"
+#else
+#define __OUTPUT_FORMAT "elf32-or32"
+#endif
+
+OUTPUT_FORMAT(__OUTPUT_FORMAT, __OUTPUT_FORMAT, __OUTPUT_FORMAT)
jiffies = jiffies_64 + 4;
SECTIONS
--
1.9.1
Stefan Kristiansson
2014-09-08 19:26:24 UTC
Permalink
I see the following runtime warning with 3.10 and 3.12 kernels.
------------[ cut here ]------------
WARNING: at kernel/softirq.c:160 0xc0014ab4()
CPU: 0 PID: 19 Comm: init Not tainted 3.10.53-00055-g7474be8-dirty #1
Is there a (simple) patch available to fix this problem, or do we have
to live with it ?
This was fixed in 3.14 by
10f67dbf6add97751050f294d4c8e0cc1e5c2c23
openrisc: Rework signal handling

(If you want a more lightweight patch that solves the problem,
I proposed this back then
http://marc.info/?l=linux-kernel&m=136723205302070&w=2)
Also, 3.2 and 3.4 kernels fail to compile with the following error when using
the new toolchain.
arch/openrisc/kernel/head.S:1572: Error: unresolved expression that must be resolved
arch/openrisc/kernel/head.S:1574: Error: unresolved expression that must be resolved
make[1]: *** [arch/openrisc/kernel/head.o] Error 1
make[1]: *** Waiting for unfinished jobs....
Applying commit 160d837 ('openrisc: add missing header inclusion') to those
releases fixes the problem. Are there any concerns if I request that this patch
is added to the 3.2 and 3.4 stable releases ?
No, I think that should be fine.

Stefan
Loading...