Skip to contentSkip to conversation

add riscv support

RFC In review Antony Pavlov 2 participants 2 messages Oct 13, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 add riscv support

This patch adds initial RISC-V architecture support for barebox.

At the moment only spike emulator is supported (see https://github.com/riscv/riscv-isa-sim
for details). Moreover barebox does not works with spike's emulated
serial port directly. Barebox runs on top of riscv proxy kernel
(pk, see https://github.com/riscv/riscv-pk). In many ways
RISC-V barebox modus operandi is very similar to sandbox barebox.

Current spike and qemu-riscv (https://github.com/riscv/riscv-isa-sim)
emulators support only HTIF (Host-Target InterFace) for serial console, though adding 8250 UART port support for spike pull request is exists (see https://github.com/riscv/riscv-isa-sim/pull/53).

Running RISC-V barebox mini-HOWTO
=================================

Obtain RISC-V GCC/Newlib Toolchain and pk (proxy kernel); see https://github.com/riscv/riscv-tools/blob/master/README.md
for details, the build.sh script from riscv-tools should create toolchain, pk ELF image and the spike emulator.

Next compile barebox:

    $ git clone -b 20161013.riscv https://github.com/frantony/barebox
    $ cd barebox
    $ make pk_defconfig ARCH=riscv
    ...
    $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-elf-

Run barebox:

    $ spike pk barebox

Board: riscv proxy kernel
Warning: Using dummy clocksource
malloc space: 0x00067640 -> 0x0046763f (size 4 MiB) running /env/bin/init...
/env/bin/init not found
barebox:/

TIP: riscv-tools buils.sh script installs pk ELF image into ${TOOLCHAIN_INSTALL_PATH}/riscv64-unknown-elf/bin directory.

---
 arch/riscv/Kconfig                      |  17 +++++
 arch/riscv/Makefile                     |  84 +++++++++++++++++++++++
 arch/riscv/boards/pk/.gitignore         |   1 +
 arch/riscv/boards/pk/Makefile           |   5 ++
 arch/riscv/boards/pk/barebox.lds.S      |  40 +++++++++++
 arch/riscv/boards/pk/console.c          |  43 ++++++++++++
 arch/riscv/boards/pk/devices.c          |  36 ++++++++++
 arch/riscv/boards/pk/dtb.c              |  67 ++++++++++++++++++
 arch/riscv/configs/pk_defconfig         |  70 +++++++++++++++++++
 arch/riscv/dts/.gitignore               |   1 +
 arch/riscv/dts/Makefile                 |  11 +++
 arch/riscv/dts/pk.dts                   |   7 ++
 arch/riscv/dts/skeleton.dtsi            |  13 ++++
 arch/riscv/include/asm/barebox.h        |   1 +
 arch/riscv/include/asm/bitops.h         |  35 ++++++++++
 arch/riscv/include/asm/bitsperlong.h    |  10 +++
 arch/riscv/include/asm/byteorder.h      |  12 ++++
 arch/riscv/include/asm/common.h         |   6 ++
 arch/riscv/include/asm/elf.h            |  11 +++
 arch/riscv/include/asm/io.h             |   8 +++
 arch/riscv/include/asm/posix_types.h    |   1 +
 arch/riscv/include/asm/sections.h       |   1 +
 arch/riscv/include/asm/string.h         |   1 +
 arch/riscv/include/asm/swab.h           |   6 ++
 arch/riscv/include/asm/types.h          |  60 +++++++++++++++++
 arch/riscv/include/asm/unaligned.h      |  19 ++++++
 arch/riscv/lib/asm-offsets.c            |  12 ++++
 arch/riscv/mach-pk/Makefile             |  12 ++++
 arch/riscv/mach-pk/common.c             | 116 ++++++++++++++++++++++++++++++++
 arch/riscv/mach-pk/include/mach/linux.h |  22 ++++++
 drivers/of/Kconfig                      |   2 +-
 drivers/serial/Kconfig                  |   2 +-
 32 files changed, 730 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/boards/pk/.gitignore
 create mode 100644 arch/riscv/boards/pk/Makefile
 create mode 100644 arch/riscv/boards/pk/barebox.lds.S
 create mode 100644 arch/riscv/boards/pk/console.c
 create mode 100644 arch/riscv/boards/pk/devices.c
 create mode 100644 arch/riscv/boards/pk/dtb.c
 create mode 100644 arch/riscv/configs/pk_defconfig
 create mode 100644 arch/riscv/dts/.gitignore
 create mode 100644 arch/riscv/dts/Makefile
 create mode 100644 arch/riscv/dts/pk.dts
 create mode 100644 arch/riscv/dts/skeleton.dtsi
 create mode 100644 arch/riscv/include/asm/barebox.h
 create mode 100644 arch/riscv/include/asm/bitops.h
 create mode 100644 arch/riscv/include/asm/bitsperlong.h
 create mode 100644 arch/riscv/include/asm/byteorder.h
 create mode 100644 arch/riscv/include/asm/common.h
 create mode 100644 arch/riscv/include/asm/elf.h
 create mode 100644 arch/riscv/include/asm/io.h
 create mode 100644 arch/riscv/include/asm/posix_types.h
 create mode 100644 arch/riscv/include/asm/sections.h
 create mode 100644 arch/riscv/include/asm/string.h
 create mode 100644 arch/riscv/include/asm/swab.h
 create mode 100644 arch/riscv/include/asm/types.h
 create mode 100644 arch/riscv/include/asm/unaligned.h
 create mode 100644 arch/riscv/lib/asm-offsets.c
 create mode 100644 arch/riscv/mach-pk/Makefile
 create mode 100644 arch/riscv/mach-pk/common.c
 create mode 100644 arch/riscv/mach-pk/include/mach/linux.h
arch/riscv/Kconfig new file +17 -0
new file mode 100644
index 0000000..2bc49b9
@@ -0,0 +1,17 @@
+config RISCV
+	bool
+	select OFTREE
+	select GENERIC_FIND_NEXT_BIT
+	default y
+
+config ARCH_TEXT_BASE
+	hex
+	default 0x00000000
+
+source common/Kconfig
+source commands/Kconfig
+source net/Kconfig
+source drivers/Kconfig
+source fs/Kconfig
+source lib/Kconfig
+source crypto/Kconfig
arch/riscv/Makefile new file +84 -0

84 lines not on this page · raw message

arch/riscv/boards/pk/.gitignore new file +1 -0
new file mode 100644
index 0000000..d116578
@@ -0,0 +1 @@
+barebox.lds
arch/riscv/boards/pk/Makefile new file +5 -0
new file mode 100644
index 0000000..2f921e6
@@ -0,0 +1,5 @@
+obj-y += console.o
+obj-y += devices.o
+obj-y += dtb.o
+
+extra-y += barebox.lds
arch/riscv/boards/pk/barebox.lds.S new file +40 -0
new file mode 100644
index 0000000..6ba2814
@@ -0,0 +1,40 @@
+#include <asm-generic/barebox.lds.h>
+
+SECTIONS
+{
+	_stext = .;
+	_etext = .;			/* End of text and rodata section */
+	_sdata = .;
+
+	. = ALIGN(4);
+	.data : { *(.data*) }
+
+	. = ALIGN(64);
+	__barebox_initcalls_start = .;
+	__barebox_initcalls : { INITCALLS }
+	__barebox_initcalls_end = .;
+
+	. = ALIGN(64);
+	__barebox_exitcalls_start = .;
+	__barebox_exitcalls : { EXITCALLS }
+	__barebox_exitcalls_end = .;
+
+	. = ALIGN(64);
+	__barebox_magicvar_start = .;
+	.barebox_magicvar : { BAREBOX_MAGICVARS }
+	__barebox_magicvar_end = .;
+
+	. = ALIGN(64);
+	__barebox_cmd_start = .;
+	__barebox_cmd : { BAREBOX_CMDS }
+	__barebox_cmd_end = .;
+
+	_edata = .;
+	. = ALIGN(8);
+	__bss_start = .;
+	.bss : { *(.bss*) }
+	__bss_stop = .;
+	_end = .;
+}
+
+INSERT BEFORE .rodata;
arch/riscv/boards/pk/console.c new file +43 -0

43 lines not on this page · raw message

arch/riscv/boards/pk/devices.c new file +36 -0
new file mode 100644
index 0000000..301446a
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+
+static LIST_HEAD(sandbox_device_list);
+
+int sandbox_add_device(struct device_d *dev)
+{
+	list_add(&dev->list, &sandbox_device_list);
+
+	return 0;
+}
+
+static int sandbox_device_init(void)
+{
+	struct device_d *dev, *tmp;
+
+	barebox_set_model("riscv proxy kernel");
+	barebox_set_hostname("barebox");
+
+	list_for_each_entry_safe(dev, tmp, &sandbox_device_list, list) {
+		/* reset the list_head before registering for real */
+		dev->list.prev = NULL;
+		dev->list.next = NULL;
+		platform_device_register(dev);
+	}
+
+	return 0;
+}
+postcore_initcall(sandbox_device_init);
arch/riscv/boards/pk/dtb.c new file +67 -0

67 lines not on this page · raw message

arch/riscv/configs/pk_defconfig new file +70 -0

70 lines not on this page · raw message

arch/riscv/dts/.gitignore new file +1 -0
new file mode 100644
index 0000000..077903c
@@ -0,0 +1 @@
+*dtb*
arch/riscv/dts/Makefile new file +11 -0
new file mode 100644
index 0000000..898c3c3
@@ -0,0 +1,11 @@
+ifeq ($(CONFIG_OFTREE),y)
+dtb-y += \
+	pk.dtb
+endif
+
+# just to build a built-in.o. Otherwise compilation fails when no devicetree is
+# created.
+obj- += dummy.o
+
+always := $(dtb-y)
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts
arch/riscv/dts/pk.dts new file +7 -0
new file mode 100644
index 0000000..2595aa1
@@ -0,0 +1,7 @@
+/dts-v1/;
+
+#include "skeleton.dtsi"
+
+/ {
+
+};
arch/riscv/dts/skeleton.dtsi new file +13 -0
new file mode 100644
index 0000000..38ead82
@@ -0,0 +1,13 @@
+/*
+ * Skeleton device tree; the bare minimum needed to boot; just include and
+ * add a compatible value.  The bootloader will typically populate the memory
+ * node.
+ */
+
+/ {
+	#address-cells = <2>;
+	#size-cells = <1>;
+	chosen { };
+	aliases { };
+	memory { device_type = "memory"; reg = <0 0 0>; };
+};
arch/riscv/include/asm/barebox.h new file +1 -0
new file mode 100644
index 0000000..2997587
@@ -0,0 +1 @@
+/* dummy */
arch/riscv/include/asm/bitops.h new file +35 -0
new file mode 100644
index 0000000..e77ab83
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+
+#ifndef _ASM_BITOPS_H_
+#define _ASM_BITOPS_H_
+
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/__fls.h>
+#include <asm-generic/bitops/ffs.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+#include <asm-generic/bitops/ops.h>
+
+#define set_bit(x, y)			__set_bit(x, y)
+#define clear_bit(x, y)			__clear_bit(x, y)
+#define change_bit(x, y)		__change_bit(x, y)
+#define test_and_set_bit(x, y)		__test_and_set_bit(x, y)
+#define test_and_clear_bit(x, y)	__test_and_clear_bit(x, y)
+#define test_and_change_bit(x, y)	__test_and_change_bit(x, y)
+
+#endif /* _ASM_BITOPS_H_ */
arch/riscv/include/asm/bitsperlong.h new file +10 -0
new file mode 100644
index 0000000..4641e7e
@@ -0,0 +1,10 @@
+#ifndef __ASM_BITSPERLONG_H
+#define __ASM_BITSPERLONG_H
+
+#ifdef __riscv64
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+
+#endif /* __ASM_BITSPERLONG_H */
arch/riscv/include/asm/byteorder.h new file +12 -0
new file mode 100644
index 0000000..994a61a
@@ -0,0 +1,12 @@
+#ifndef _ASM_RISCV_BYTEORDER_H
+#define _ASM_RISCV_BYTEORDER_H
+
+#if defined(__RISCVEL__)
+#include <linux/byteorder/little_endian.h>
+#elif defined(__RISCVEB__)
+#include <linux/byteorder/big_endian.h>
+#else
+#error "Unknown endianness"
+#endif
+
+#endif /* _ASM_RISCV_BYTEORDER_H */
arch/riscv/include/asm/common.h new file +6 -0
new file mode 100644
index 0000000..9b8bd2d
@@ -0,0 +1,6 @@
+#ifndef ASM_COMMON_H
+#define ASM_COMMON_H
+
+#define ARCH_HAS_CTRLC
+
+#endif /* ASM_COMMON_H */
arch/riscv/include/asm/elf.h new file +11 -0
new file mode 100644
index 0000000..3939336
@@ -0,0 +1,11 @@
+#ifndef __ASM_SANDBOX_ELF_H__
+#define __ASM_SANDBOX_ELF_H__
+
+#if __SIZEOF_POINTER__ == 8
+#define ELF_CLASS	ELFCLASS64
+#define CONFIG_PHYS_ADDR_T_64BIT
+#else
+#define ELF_CLASS	ELFCLASS32
+#endif
+
+#endif /* __ASM_SANDBOX_ELF_H__ */
arch/riscv/include/asm/io.h new file +8 -0
new file mode 100644
index 0000000..d9aca42
@@ -0,0 +1,8 @@
+#ifndef __ASM_RISCV_IO_H
+#define __ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>
+
+#define IO_SPACE_LIMIT 0
+
+#endif /* __ASM_RISCV_IO_H */
arch/riscv/include/asm/posix_types.h new file +1 -0
new file mode 100644
index 0000000..22cae62
@@ -0,0 +1 @@
+#include <asm-generic/posix_types.h>
arch/riscv/include/asm/sections.h new file +1 -0
new file mode 100644
index 0000000..2b8c516
@@ -0,0 +1 @@
+#include <asm-generic/sections.h>
arch/riscv/include/asm/string.h new file +1 -0
new file mode 100644
index 0000000..2997587
@@ -0,0 +1 @@
+/* dummy */
arch/riscv/include/asm/swab.h new file +6 -0
new file mode 100644
index 0000000..60a9012
@@ -0,0 +1,6 @@
+#ifndef _ASM_SWAB_H
+#define _ASM_SWAB_H
+
+/* nothing. use generic functions */
+
+#endif /* _ASM_SWAB_H */
arch/riscv/include/asm/types.h new file +60 -0

60 lines not on this page · raw message

arch/riscv/include/asm/unaligned.h new file +19 -0
new file mode 100644
index 0000000..d02da6e
@@ -0,0 +1,19 @@
+#ifndef _ASM_SANDBOX_UNALIGNED_H
+#define _ASM_SANDBOX_UNALIGNED_H
+
+/*
+ * The architecture sandbox is compiled on can do unaligned accesses itself.
+ */
+
+#include <linux/unaligned/access_ok.h>
+#include <linux/unaligned/generic.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define get_unaligned __get_unaligned_le
+#define put_unaligned __put_unaligned_le
+#else
+#define get_unaligned __get_unaligned_be
+#define put_unaligned __put_unaligned_be
+#endif
+
+#endif /* _ASM_SANDBOX_UNALIGNED_H */
arch/riscv/lib/asm-offsets.c new file +12 -0
new file mode 100644
index 0000000..22f382b
@@ -0,0 +1,12 @@
+/*
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed to extract
+ * and format the required data.
+ */
+
+#include <linux/kbuild.h>
+
+int main(void)
+{
+	return 0;
+}
arch/riscv/mach-pk/Makefile new file +12 -0
new file mode 100644
index 0000000..5f4c97b
@@ -0,0 +1,12 @@
+machdirs := arch/riscv/mach-pk/
+
+ifeq ($(KBUILD_SRC),)
+CPPFLAGS := $(patsubst %,-I%include,$(machdirs))
+else
+CPPFLAGS := $(patsubst %,-I$(srctree)/%include,$(machdirs))
+endif
+
+CFLAGS := -W -Wall -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE)
+NOSTDINC_FLAGS :=
+
+obj-y = common.o
arch/riscv/mach-pk/common.c new file +116 -0

116 lines not on this page · raw message

arch/riscv/mach-pk/include/mach/linux.h new file +22 -0
new file mode 100644
index 0000000..627ee17
@@ -0,0 +1,22 @@
+#ifndef __ASM_ARCH_LINUX_H
+#define __ASM_ARCH_LINUX_H
+
+struct device_d;
+
+int sandbox_add_device(struct device_d *dev);
+
+int linux_register_device(const char *name, void *start, void *end);
+int linux_read(int fd, void *buf, size_t count);
+ssize_t linux_write(int fd, const void *buf, size_t count);
+int linux_tstc(int fd);
+
+int barebox_register_console(char *name_template, int stdinfd, int stdoutfd);
+
+int barebox_register_dtb(const void *dtb);
+
+struct linux_console_data {
+	int stdinfd;
+	int stdoutfd;
+};
+
+#endif /* __ASM_ARCH_LINUX_H */
drivers/of/Kconfig +1 -1
index d0a62bd..0824b04 100644
@@ -4,7 +4,7 @@ config OFTREE
 
 config OFTREE_MEM_GENERIC
 	depends on OFTREE
-	depends on PPC || ARM || ARCH_EFI || OPENRISC || SANDBOX
+	depends on PPC || ARM || ARCH_EFI || OPENRISC || SANDBOX || RISCV
 	def_bool y
 
 config DTC
drivers/serial/Kconfig +1 -1
index b112d7e..85751a2 100644
@@ -41,7 +41,7 @@ config DRIVER_SERIAL_NETX
 	bool "Netx serial driver"
 
 config DRIVER_SERIAL_LINUX_CONSOLE
-	depends on LINUX
+	depends on LINUX || RISCV
 	default y
 	bool "linux console driver"
 
Signature · 7 lines
2.9.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 1 line · Antony Pavlov

This patch adds initial RISC-V architecture support for barebox.

Great to see this; could you add some documentation? We have a nice documentation framework in the meantime. Most of your cover letter could for example go into the docs.

rsc

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox