Skip to contentSkip to conversation

RISC-V: erizo: migrate to PBL

PATCH In review Ahmad Fatoum 3 participants 28 messages Mar 21, 2021 – Mar 24, 2021

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

v3 cover RISC-V: erizo: migrate to PBL

With these changes applied, barebox can now generate images that can be booted on qemu/tinyemu virt32 and virt64 machines.

The boards have clocksource, virtio, cfi-flash, reboot and poweroff support.

This can also be pulled from Github:
https://github.com/a3f/barebox/tree/multi-image-riscv-v3

v2 -> v3:
- reworded some commit titles
- added new header format for barebox images
- added filetype detection for new barebox image format
- fixed use of uninitialized sp in Erizo ENTRY_POINT (Antony)
- Replaced assembly entry point of generic DT image with customized version of new header format macro
- early exit relocation if runtime offset == 0
- remove note about TLSF error that's now fixed after Antony's bisection
- replace 2 line assembly function in entry_ll.S with inline code

v1 -> v2:
- moved compressed dtb helpers into common header for both ARM and RISC-V to use
- relocate_to_adr(fixed_base) can now be called multiple times in a row
- removed some extra spaces (Antony)
- as arch is DT only, bumped pr_debug to pr_err if dt is not found. no panic, because with debug_ll you might still be able to boot to shell for further debugging
- rename Makefile.erizo to Makefile.riscv. Let's just build all board images out of the same Makefile now
- HAS_ARCH_SJLJ selected for 64-bit as well
- don't require compiler to support atomics or floating point on rv64 (Rouven)
- added RISCV timer for SBI and rdcycle mode. This is used on tinyemu virt. rdcycle mode could be used on erizo as well if suitable timerbase chosen.
- activate first console because Tinyemu only describes virtio mmio region for console and no stdout-path

Cheers,
Ahmad Fatoum (19):
partitions: don't allocate dma capable memory
images: make BOARD_ARM_GENERIC_DT available for other arches
ARM: make ARM_USE_COMPRESSED_DTB available for other arches
ARM: aarch64: omit unused label in assembly
serial: virtio-console: depend on, but don't select VIRTIO
RISC-V: <asm/unaligned.h>: don't do unaligned accesses
RISC-V: debug_ll: ns16550: align C access size with assembly's
RISC-V: drop duplicate or unneeded cflags
RISC-V: add cacheless HAS_DMA support
RISC-V: erizo: move to arch/riscv/boards/erizo
RISC-V: import Linux' optimized string functions
filetype: detect RISC-V images
RISC-V: implement PBL image header
RISC-V: implement PBL and relocation support
RISC-V: erizo: migrate to PBL
RISC-V: support symbol names in barebox image
RISC-V: add generic DT image
clocksource: add driver for RISC-V and CLINT timers
power: reset: add drivers for generic syscon reset and poweroff

Rouven Czerwinski (2):
RISC-V: add 64-bit support
RISC-V: add Qemu virt support

 Documentation/boards/riscv.rst               |  72 ++++++-
 Makefile                                     |   1 +
 arch/arm/Kconfig                             |   7 +-
 arch/arm/cpu/start.c                         |  20 +-
 arch/arm/include/asm/barebox-arm.h           |   7 -
 arch/arm/lib64/runtime-offset.S              |   2 +-
 arch/riscv/Kconfig                           |  81 +++++--
 arch/riscv/Makefile                          |  35 ++-
 arch/riscv/boards/Makefile                   |   2 +
 arch/riscv/boards/erizo/Makefile             |   3 +
 arch/riscv/boards/erizo/lowlevel.c           |  18 ++
 arch/riscv/boot/Makefile                     |   5 +-
 arch/riscv/boot/board-dt-2nd.c               |  36 ++++
 arch/riscv/boot/dtb.c                        |  25 ---
 arch/riscv/boot/entry.c                      |  29 +++
 arch/riscv/boot/entry.h                      |  15 ++
 arch/riscv/boot/main_entry.c                 |  35 ---
 arch/riscv/boot/start.S                      |  68 ------
 arch/riscv/boot/start.c                      | 185 ++++++++++++++++
 arch/riscv/boot/uncompress.c                 |  74 +++++++
 arch/riscv/configs/erizo_generic_defconfig   |   5 -
 arch/riscv/configs/virt32_defconfig          | 116 ++++++++++
 arch/riscv/configs/virt64_defconfig          | 117 ++++++++++
 arch/riscv/cpu/Makefile                      |   3 +
 arch/riscv/cpu/core.c                        |  50 +++++
 arch/riscv/cpu/time.c                        |  38 ++++
 arch/riscv/dts/Makefile                      |   9 +-
 arch/riscv/dts/erizo.dtsi                    |   2 +-
 arch/riscv/include/asm/barebox-riscv-head.h  |  36 ++++
 arch/riscv/include/asm/barebox-riscv.h       | 105 +++++++++
 arch/riscv/include/asm/common.h              |  10 +-
 arch/riscv/include/asm/csr.h                 | 211 +++++++++++++++++++
 arch/riscv/include/asm/debug_ll_ns16550.h    |  16 +-
 arch/riscv/include/asm/dma.h                 |  44 ++++
 arch/riscv/include/asm/elf.h                 |   8 +-
 arch/riscv/include/asm/image.h               |  65 ++++++
 arch/riscv/include/asm/linkage.h             |   4 +
 arch/riscv/include/asm/sbi.h                 | 153 ++++++++++++++
 arch/riscv/include/asm/sections.h            |  15 ++
 arch/riscv/include/asm/string.h              |  21 +-
 arch/riscv/include/asm/timer.h               |   9 +
 arch/riscv/include/asm/types.h               |   8 +-
 arch/riscv/include/asm/unaligned.h           |  16 +-
 arch/riscv/lib/Makefile                      |   6 +-
 arch/riscv/lib/barebox.lds.S                 |  55 +++--
 arch/riscv/lib/dtb.c                         |  30 +++
 arch/riscv/lib/memcpy.S                      | 108 ++++++++++
 arch/riscv/lib/memmove.S                     |  64 ++++++
 arch/riscv/lib/memset.S                      | 113 ++++++++++
 arch/riscv/lib/pbl.lds.S                     |  85 ++++++++
 arch/riscv/lib/reloc.c                       |  66 ++++++
 arch/riscv/lib/runtime-offset.S              |  12 ++
 arch/riscv/lib/sections.c                    |   9 +
 arch/riscv/lib/setupc.S                      |  55 +++++
 arch/riscv/mach-virt/Makefile                |   3 +
 arch/riscv/mach-virt/include/mach/debug_ll.h |  25 +++
 common/Kconfig                               |   8 +-
 common/filetype.c                            |   6 +
 common/partitions.c                          |   5 +-
 common/partitions/dos.c                      |   7 +-
 common/partitions/efi.c                      |   1 -
 drivers/clocksource/Kconfig                  |  15 ++
 drivers/clocksource/Makefile                 |   2 +
 drivers/clocksource/timer-clint.c            |  93 ++++++++
 drivers/clocksource/timer-riscv.c            |  66 ++++++
 drivers/power/reset/Kconfig                  |  14 ++
 drivers/power/reset/Makefile                 |   2 +
 drivers/power/reset/syscon-poweroff.c        |  76 +++++++
 drivers/power/reset/syscon-reboot.c          |  92 ++++++++
 drivers/serial/Kconfig                       |   2 +-
 images/.gitignore                            |   1 +
 images/Makefile                              |   8 +-
 images/Makefile.riscv                        |  12 ++
 include/compressed-dtb.h                     |  33 +++
 include/dma.h                                |   1 +
 include/filetype.h                           |   2 +
 pbl/Kconfig                                  |   6 +-
 scripts/.gitignore                           |   1 +
 scripts/Makefile                             |   1 +
 scripts/Makefile.lib                         |  11 +
 scripts/prelink-riscv.c                      | 122 +++++++++++
 scripts/prelink-riscv.inc                    | 123 +++++++++++
 82 files changed, 2853 insertions(+), 269 deletions(-)
 create mode 100644 arch/riscv/boards/Makefile
 create mode 100644 arch/riscv/boards/erizo/Makefile
 create mode 100644 arch/riscv/boards/erizo/lowlevel.c
 create mode 100644 arch/riscv/boot/board-dt-2nd.c
 delete mode 100644 arch/riscv/boot/dtb.c
 create mode 100644 arch/riscv/boot/entry.c
 create mode 100644 arch/riscv/boot/entry.h
 delete mode 100644 arch/riscv/boot/main_entry.c
 delete mode 100644 arch/riscv/boot/start.S
 create mode 100644 arch/riscv/boot/start.c
 create mode 100644 arch/riscv/boot/uncompress.c
 create mode 100644 arch/riscv/configs/virt32_defconfig
 create mode 100644 arch/riscv/configs/virt64_defconfig
 create mode 100644 arch/riscv/cpu/Makefile
 create mode 100644 arch/riscv/cpu/core.c
 create mode 100644 arch/riscv/cpu/time.c
 create mode 100644 arch/riscv/include/asm/barebox-riscv-head.h
 create mode 100644 arch/riscv/include/asm/barebox-riscv.h
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/dma.h
 create mode 100644 arch/riscv/include/asm/image.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/timer.h
 create mode 100644 arch/riscv/lib/dtb.c
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memmove.S
 create mode 100644 arch/riscv/lib/memset.S
 create mode 100644 arch/riscv/lib/pbl.lds.S
 create mode 100644 arch/riscv/lib/reloc.c
 create mode 100644 arch/riscv/lib/runtime-offset.S
 create mode 100644 arch/riscv/lib/sections.c
 create mode 100644 arch/riscv/lib/setupc.S
 create mode 100644 arch/riscv/mach-virt/Makefile
 create mode 100644 arch/riscv/mach-virt/include/mach/debug_ll.h
 create mode 100644 drivers/clocksource/timer-clint.c
 create mode 100644 drivers/clocksource/timer-riscv.c
 create mode 100644 drivers/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
 create mode 100644 images/Makefile.riscv
 create mode 100644 include/compressed-dtb.h
 create mode 100644 scripts/prelink-riscv.c
 create mode 100644 scripts/prelink-riscv.inc
Signature · 7 lines
2.29.2


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

PATCH v3 1/21 partitions: don't allocate dma capable memory

While block drivers may do DMA, they always use block caching chunks as bounce buffer. No dma is every done directly to the block_read data argument, so it doesn't need to be allocated with dma_alloc. The buffer also need not be zeroed, as block_read will either overwrite it completely or fail.

---
 common/partitions.c     | 5 ++---
 common/partitions/dos.c | 7 +++----
 common/partitions/efi.c | 1 -
 3 files changed, 5 insertions(+), 8 deletions(-)
common/partitions.c +2 -3
index 1f0c544c6067..deb931f3290f 100644
@@ -17,7 +17,6 @@
 #include <asm/unaligned.h>
 #include <disks.h>
 #include <filetype.h>
-#include <dma.h>
 #include <linux/err.h>
 
 #include "partitions/parser.h"
@@ -120,7 +119,7 @@ int parse_partition_table(struct block_device *blk)
 	uint8_t *buf;
 
 	pdesc = xzalloc(sizeof(*pdesc));
-	buf = dma_alloc(SECTOR_SIZE * 2);
+	buf = malloc(2 * SECTOR_SIZE);
 
 	rc = block_read(blk, buf, 0, 2);
 	if (rc != 0) {
@@ -149,7 +148,7 @@ int parse_partition_table(struct block_device *blk)
 	}
 
 on_error:
-	dma_free(buf);
+	free(buf);
 	free(pdesc);
 	return rc;
 }
common/partitions/dos.c +3 -4
index 488c2936f715..0012c4875658 100644
@@ -16,7 +16,6 @@
 #include <disks.h>
 #include <init.h>
 #include <asm/unaligned.h>
-#include <dma.h>
 #include <linux/err.h>
 
 #include "parser.h"
@@ -64,7 +63,7 @@ static uint64_t disk_guess_size(struct device_d *dev,
 
 static void *read_mbr(struct block_device *blk)
 {
-	void *buf = dma_alloc(SECTOR_SIZE);
+	void *buf = malloc(SECTOR_SIZE);
 	int ret;
 
 	ret = block_read(blk, buf, 0, 1);
@@ -135,7 +134,7 @@ static int dos_get_disk_signature(struct param_d *p, void *_priv)
 static void dos_extended_partition(struct block_device *blk, struct partition_desc *pd,
 		struct partition *partition, uint32_t signature)
 {
-	uint8_t *buf = dma_alloc(SECTOR_SIZE);
+	uint8_t *buf = malloc(SECTOR_SIZE);
 	uint32_t ebr_sector = partition->first_sec;
 	struct partition_entry *table = (struct partition_entry *)&buf[0x1be];
 	unsigned partno = 5;
@@ -185,7 +184,7 @@ static void dos_extended_partition(struct block_device *blk, struct partition_de
 	}
 
 out:
-	dma_free(buf);
+	free(buf);
 	return;
 }
 
common/partitions/efi.c +0 -1
index f20fd0d9b9e8..437c3d64f889 100644
@@ -16,7 +16,6 @@
 #include <disks.h>
 #include <init.h>
 #include <asm/unaligned.h>
-#include <dma.h>
 #include <crc.h>
 #include <linux/ctype.h>
 
Signature · 7 lines
2.29.2


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

PATCH v3 2/21 images: make BOARD_ARM_GENERIC_DT available for other arches

In reply to Ahmad Fatoum

Other architectures would benefit from the generic DT image too. Add a new arch-agnostic symbol that arches besides ARM can select.

The new symbol itself should not have a prompt as the help text for each architecture likely differs (e.g. device tree handoff register).

---
 arch/arm/Kconfig | 2 +-
 images/Makefile  | 4 ++--
 pbl/Kconfig      | 4 ++++
 3 files changed, 7 insertions(+), 3 deletions(-)
arch/arm/Kconfig +1 -1
index a1f781b60f95..3b983c8b3d0a 100644
@@ -323,7 +323,7 @@ config BOARD_ARM_VIRT
 	select OF_OVERLAY
 
 config BOARD_ARM_GENERIC_DT
-	select LIBFDT
+	select BOARD_GENERIC_DT
 	select ARM_AMBA
 	depends on HAVE_PBL_MULTI_IMAGES
 	depends on OFDEVICE
images/Makefile +2 -2
index b8899dcd2a81..84492a154d16 100644
@@ -166,9 +166,9 @@ include $(srctree)/images/Makefile.zynqmp
 include $(srctree)/images/Makefile.layerscape
 
 
-pblb-$(CONFIG_BOARD_ARM_GENERIC_DT) += start_dt_2nd
+pblb-$(CONFIG_BOARD_GENERIC_DT) += start_dt_2nd
 FILE_barebox-dt-2nd.img = start_dt_2nd.pblb
-image-$(CONFIG_BOARD_ARM_GENERIC_DT) += barebox-dt-2nd.img
+image-$(CONFIG_BOARD_GENERIC_DT) += barebox-dt-2nd.img
 
 ifdef CONFIG_ARM
 pblb-$(CONFIG_PBL_SINGLE_IMAGE) += start_pbl
pbl/Kconfig +4 -0
index 6e8cc3ac04ae..2eea5aef7a30 100644
@@ -40,6 +40,10 @@ config PBL_VERIFY_PIGGY
 	depends on ARM
 	bool
 
+config BOARD_GENERIC_DT
+	bool
+	select LIBFDT
+
 config IMAGE_COMPRESSION
 	bool
 	depends on HAVE_IMAGE_COMPRESSION
Signature · 7 lines
2.29.2


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

PATCH v3 3/21 ARM: make ARM_USE_COMPRESSED_DTB available for other arches

In reply to Ahmad Fatoum

Other PBL-enabled architecture can benefit from compressed dtbs as well. Move symbol and code to a comm place to be able to use it from RISC-V in a later commit. In order not to break out of tree boards at runtime, the old symbol name is maintained for ARM.

---
 arch/arm/Kconfig                   |  5 ++---
 arch/arm/cpu/start.c               | 20 ++++--------------
 arch/arm/include/asm/barebox-arm.h |  7 -------
 common/Kconfig                     |  6 ++++++
 include/compressed-dtb.h           | 33 ++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 26 deletions(-)
 create mode 100644 include/compressed-dtb.h
arch/arm/Kconfig +2 -3
index 3b983c8b3d0a..faf5050eaf23 100644
@@ -18,9 +18,8 @@ config HAVE_MACH_ARM_HEAD
 	bool
 
 config ARM_USE_COMPRESSED_DTB
-	bool
-	select UNCOMPRESS
-	select LZO_DECOMPRESS
+       bool
+       select USE_COMPRESSED_DTB
 
 config TEXT_BASE
 	hex
arch/arm/cpu/start.c +4 -16
index f48f5beea807..c61db668658b 100644
@@ -18,6 +18,7 @@
 #include <linux/kasan.h>
 #include <memory.h>
 #include <uncompress.h>
+#include <compressed-dtb.h>
 #include <malloc.h>
 
 #include <debug_ll.h>
@@ -30,18 +31,6 @@ static unsigned long arm_endmem;
 static void *barebox_boarddata;
 static unsigned long barebox_boarddata_size;
 
-static bool blob_is_fdt(const void *blob)
-{
-	return get_unaligned_be32(blob) == FDT_MAGIC;
-}
-
-static bool blob_is_compressed_fdt(const void *blob)
-{
-	const struct barebox_arm_boarddata_compressed_dtb *dtb = blob;
-
-	return dtb->magic == BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC;
-}
-
 static bool blob_is_arm_boarddata(const void *blob)
 {
 	const struct barebox_arm_boarddata *bd = blob;
@@ -64,7 +53,7 @@ void *barebox_arm_boot_dtb(void)
 	void *dtb;
 	void *data;
 	int ret;
-	struct barebox_arm_boarddata_compressed_dtb *compressed_dtb;
+	struct barebox_boarddata_compressed_dtb *compressed_dtb;
 	static void *boot_dtb;
 
 	if (boot_dtb)
@@ -75,8 +64,7 @@ void *barebox_arm_boot_dtb(void)
 		return barebox_boarddata;
 	}
 
-	if (!IS_ENABLED(CONFIG_ARM_USE_COMPRESSED_DTB) || !barebox_boarddata
-			|| !blob_is_compressed_fdt(barebox_boarddata))
+	if (!fdt_blob_can_be_decompressed(barebox_boarddata))
 		return NULL;
 
 	compressed_dtb = barebox_boarddata;
@@ -185,7 +173,7 @@ __noreturn __no_sanitize_address void barebox_non_pbl_start(unsigned long membas
 			totalsize = get_unaligned_be32(boarddata + 4);
 			name = "DTB";
 		} else if (blob_is_compressed_fdt(boarddata)) {
-			struct barebox_arm_boarddata_compressed_dtb *bd = boarddata;
+			struct barebox_boarddata_compressed_dtb *bd = boarddata;
 			totalsize = bd->datalen + sizeof(*bd);
 			name = "Compressed DTB";
 		} else if (blob_is_arm_boarddata(boarddata)) {
arch/arm/include/asm/barebox-arm.h +0 -7
index f81257f896a9..348a55e8040f 100644
@@ -84,13 +84,6 @@ u32 barebox_arm_machine(void);
 unsigned long arm_mem_ramoops_get(void);
 unsigned long arm_mem_endmem_get(void);
 
-struct barebox_arm_boarddata_compressed_dtb {
-#define BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
-	u32 magic;
-	u32 datalen;
-	u32 datalen_uncompressed;
-};
-
 struct barebox_arm_boarddata *barebox_arm_get_boarddata(void);
 
 #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_ARM_EXCEPTIONS)
common/Kconfig +6 -0
index 56064d12c5f3..ede26cec081a 100644
@@ -42,6 +42,12 @@ config BLOCK
 config BLOCK_WRITE
 	bool
 
+config USE_COMPRESSED_DTB
+	bool
+	depends on ARM
+	select UNCOMPRESS
+	select LZO_DECOMPRESS
+
 config ELF
 	bool "ELF Support" if COMPILE_TEST
 
include/compressed-dtb.h new file +33 -0
new file mode 100644
index 000000000000..1ba98a7e2b92
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef COMPRESSED_DTB_H_
+#define COMPRESSED_DTB_H_
+
+#include <linux/types.h>
+#include <asm/unaligned.h>
+
+struct barebox_boarddata_compressed_dtb {
+#define BAREBOX_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
+	u32 magic;
+	u32 datalen;
+	u32 datalen_uncompressed;
+};
+
+static inline bool blob_is_compressed_fdt(const void *blob)
+{
+	const struct barebox_boarddata_compressed_dtb *dtb = blob;
+
+	return dtb->magic == BAREBOX_BOARDDATA_COMPRESSED_DTB_MAGIC;
+}
+
+static inline bool fdt_blob_can_be_decompressed(const void *blob)
+{
+	return IS_ENABLED(CONFIG_USE_COMPRESSED_DTB) && blob
+			&& blob_is_compressed_fdt(blob);
+}
+
+static inline bool blob_is_fdt(const void *blob)
+{
+	return get_unaligned_be32(blob) == FDT_MAGIC;
+}
+
+#endif
Signature · 7 lines
2.29.2


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

PATCH v3 4/21 ARM: aarch64: omit unused label in assembly

In reply to Ahmad Fatoum

The 1: is a left-over from before 5f04e5e03e94 ("ARM: aarch64: Fix get_runtime_offset after relocation"). It's unused now, so drop it.

---
 arch/arm/lib64/runtime-offset.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/lib64/runtime-offset.S +1 -1
index 5e5ab9a8d136..e2ff5d21036d 100644
@@ -8,7 +8,7 @@
  * we are currently running at.
  */
 ENTRY(get_runtime_offset)
-1:	adr x0, _text
+	adr x0, _text
 	ldr x1, linkadr
 	subs x0, x0, x1
 	ret
Signature · 7 lines
2.29.2


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

PATCH v3 5/21 serial: virtio-console: depend on, but don't select VIRTIO

In reply to Ahmad Fatoum

VIRTIO has multiple backends, each with is its own dependencies. It's thus wrong to select it from drivers. Fix this.

---
 drivers/serial/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/serial/Kconfig +1 -1
index 09434c1ba86c..db924efa02a6 100644
@@ -158,7 +158,7 @@ config DRIVER_SERIAL_LPUART
 
 config VIRTIO_CONSOLE
 	tristate "Virtio console"
-	select VIRTIO
+	depends on VIRTIO
 	help
 	  Virtio console for use with hypervisors.
 
Signature · 7 lines
2.29.2


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

PATCH v3 6/21 RISC-V: <asm/unaligned.h>: don't do unaligned accesses

In reply to Ahmad Fatoum

While HW can emulate unaligned accesses at a performance penalty, it's probably best to just not generate them.

---
 arch/riscv/include/asm/unaligned.h | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
arch/riscv/include/asm/unaligned.h +4 -12
index aaebc064114e..c37b71c21ee5 100644
@@ -1,19 +1,11 @@
 #ifndef _ASM_RISCV_UNALIGNED_H
 #define _ASM_RISCV_UNALIGNED_H
 
-/*
- * FIXME: this file is copy-n-pasted from sandbox's unaligned.h
- */
-
-#include <linux/unaligned/access_ok.h>
+#include <linux/unaligned/le_byteshift.h>
+#include <linux/unaligned/be_byteshift.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
+#define get_unaligned	__get_unaligned_le
+#define put_unaligned	__put_unaligned_le
 
 #endif /* _ASM_RISCV_UNALIGNED_H */
Signature · 7 lines
2.29.2


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

PATCH v3 7/21 RISC-V: debug_ll: ns16550: align C access size with assembly's

In reply to Ahmad Fatoum

The assembly putc routines do accesses the same size of the register stride. Do likewise for the C implementation.

---
 arch/riscv/include/asm/debug_ll_ns16550.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
arch/riscv/include/asm/debug_ll_ns16550.h +10 -6
index f1c2ccbd0afb..7d6d12df74fe 100644
@@ -51,9 +51,13 @@
 #if defined(DEBUG_LL_UART_IOSIZE32)
 #define UART_REG_L	lw
 #define UART_REG_S	sw
+#define __uart_read	readl
+#define __uart_write	writel
 #elif defined(DEBUG_LL_UART_IOSIZE8)
 #define UART_REG_L	lbu
 #define UART_REG_S	sb
+#define __uart_read	readb
+#define __uart_write	writeb
 #else
 #error "Please define DEBUG_LL_UART_IOSIZE{8,32}"
 #endif
@@ -68,19 +72,19 @@
 static inline void PUTC_LL(char ch)
 {
 #ifdef CONFIG_DEBUG_LL
-	while (!(__raw_readl((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
+	while (!(__uart_read((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
 		;
-	__raw_writel(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
+	__uart_write(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
 #endif /* CONFIG_DEBUG_LL */
 }
 
 static inline void debug_ll_ns16550_init(void)
 {
 #ifdef CONFIG_DEBUG_LL
-	__raw_writel(UART_LCR_DLAB, (u8 *)DEBUG_LL_UART_ADDR + UART_LCR);
-	__raw_writel(DEBUG_LL_UART_DIVISOR & 0xff, (u8 *)DEBUG_LL_UART_ADDR + UART_DLL);
-	__raw_writel((DEBUG_LL_UART_DIVISOR >> 8) & 0xff, (u8 *)DEBUG_LL_UART_ADDR + UART_DLM);
-	__raw_writel(UART_LCR_W, (u8 *)DEBUG_LL_UART_ADDR + UART_LCR);
+	__uart_write(UART_LCR_DLAB, (u8 *)DEBUG_LL_UART_ADDR + UART_LCR);
+	__uart_write(DEBUG_LL_UART_DIVISOR & 0xff, (u8 *)DEBUG_LL_UART_ADDR + UART_DLL);
+	__uart_write((DEBUG_LL_UART_DIVISOR >> 8) & 0xff, (u8 *)DEBUG_LL_UART_ADDR + UART_DLM);
+	__uart_write(UART_LCR_W, (u8 *)DEBUG_LL_UART_ADDR + UART_LCR);
 #endif /* CONFIG_DEBUG_LL */
 }
 #else /* __ASSEMBLY__ */
Signature · 7 lines
2.29.2


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

PATCH v3 8/21 RISC-V: drop duplicate or unneeded cflags

In reply to Ahmad Fatoum

-pipe -Wall is specified in top-level Makefile. Disabling warnings is unneeded on the arch and is a left-over from MIPS port probably.

---
 arch/riscv/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/riscv/Makefile +1 -3
index 8cd5f51e3052..edf3a971e615 100644
@@ -7,9 +7,7 @@ ifeq ($(CONFIG_ARCH_RV32I),y)
 	riscv-ldflags-y += -melf32lriscv
 endif
 
-cflags-y += -fno-pic -pipe
-cflags-y += -Wall -Wstrict-prototypes \
-	-Wno-uninitialized -Wno-format -Wno-main -mcmodel=medany
+cflags-y += -fno-pic -Wstrict-prototypes -mcmodel=medany
 
 LDFLAGS_barebox += -nostdlib
 
Signature · 7 lines
2.29.2


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

PATCH v3 9/21 RISC-V: add cacheless HAS_DMA support

In reply to Ahmad Fatoum

Define some stubs, so we can get virtio MMIO working on RISC-V in QEMU. As we don't yet have MMU support, this is sufficient.

---
 arch/riscv/Kconfig           |  1 +
 arch/riscv/include/asm/dma.h | 44 ++++++++++++++++++++++++++++++++++++
 include/dma.h                |  1 +
 3 files changed, 46 insertions(+)
 create mode 100644 arch/riscv/include/asm/dma.h
arch/riscv/Kconfig +1 -0
index c8d63f99bb28..a7f362d8e80c 100644
@@ -8,6 +8,7 @@ config RISCV
 	select COMMON_CLK
 	select COMMON_CLK_OF_PROVIDER
 	select CLKDEV_LOOKUP
+	select HAS_DMA
 
 config ARCH_TEXT_BASE
 	hex
arch/riscv/include/asm/dma.h new file +44 -0

44 lines not on this page · raw message

include/dma.h +1 -0
index 07b79cd91893..1b1cb3a40796 100644
@@ -11,6 +11,7 @@
 
 #include <dma-dir.h>
 #include <asm/dma.h>
+#include <driver.h>
 
 #define DMA_ADDRESS_BROKEN	NULL
 
Signature · 7 lines
2.29.2


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

PATCH v3 10/21 RISC-V: erizo: move to arch/riscv/boards/erizo

In reply to Ahmad Fatoum

In preparation for migrating to PBL for RISC-V platforms, move the only existing board support to a new arch/riscv/boards/ directory.

---
 arch/riscv/Makefile                                       | 2 +-
 arch/riscv/boards/Makefile                                | 2 ++
 arch/riscv/boards/erizo/Makefile                          | 5 +++++
 arch/riscv/{boot/dtb.c => boards/erizo/board.c}           | 0
 arch/riscv/{boot/main_entry.c => boards/erizo/lowlevel.c} | 0
 arch/riscv/{boot => boards/erizo}/start.S                 | 0
 arch/riscv/boot/Makefile                                  | 3 ---
 7 files changed, 8 insertions(+), 4 deletions(-)
 create mode 100644 arch/riscv/boards/Makefile
 create mode 100644 arch/riscv/boards/erizo/Makefile
 rename arch/riscv/{boot/dtb.c => boards/erizo/board.c} (100%)
 rename arch/riscv/{boot/main_entry.c => boards/erizo/lowlevel.c} (100%)
 rename arch/riscv/{boot => boards/erizo}/start.S (100%)
 delete mode 100644 arch/riscv/boot/Makefile
arch/riscv/Makefile +1 -1
index edf3a971e615..d9cefe32c057 100644
@@ -41,7 +41,7 @@ MACH  :=
 endif
 
 common-y += $(MACH)
-common-y += arch/riscv/boot/
+common-y += arch/riscv/boards/
 common-y += arch/riscv/lib/
 
 common-$(CONFIG_OFTREE) += arch/riscv/dts/
arch/riscv/boards/Makefile new file +2 -0
new file mode 100644
index 000000000000..2ce9af41e03b
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_BOARD_ERIZO_GENERIC)	+= erizo/
arch/riscv/boards/erizo/Makefile new file +5 -0
new file mode 100644
index 000000000000..72b9a13ba73f
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += lowlevel.o
+obj-y += start.o
+obj-y += board.o
arch/riscv/boards/erizo/board.c renamed from arch/riscv/boot/dtb.c +0 -0
similarity index 100%
rename from arch/riscv/boot/dtb.c
rename to arch/riscv/boards/erizo/board.c
arch/riscv/boards/erizo/lowlevel.c renamed from arch/riscv/boot/main_entry.c +0 -0
similarity index 100%
rename from arch/riscv/boot/main_entry.c
rename to arch/riscv/boards/erizo/lowlevel.c
arch/riscv/boards/erizo/start.S renamed from arch/riscv/boot/start.S +0 -0
similarity index 100%
rename from arch/riscv/boot/start.S
rename to arch/riscv/boards/erizo/start.S
arch/riscv/boot/Makefile deleted +0 -3
deleted file mode 100644
index fd62cab8c127..000000000000
@@ -1,3 +0,0 @@
-obj-y += start.o
-obj-y += main_entry.o
-obj-$(CONFIG_OFDEVICE) += dtb.o
Signature · 7 lines
2.29.2


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

PATCH v3 11/21 RISC-V: import Linux' optimized string functions

In reply to Ahmad Fatoum

For non-NMON enabled board the RISC-V specific settings menu will be empty. Improve UI/UX by adding something there.

---
 arch/riscv/Kconfig              |   7 ++
 arch/riscv/include/asm/string.h |  21 +++++-
 arch/riscv/lib/Makefile         |   1 +
 arch/riscv/lib/memcpy.S         | 108 ++++++++++++++++++++++++++++++
 arch/riscv/lib/memmove.S        |  64 ++++++++++++++++++
 arch/riscv/lib/memset.S         | 113 ++++++++++++++++++++++++++++++++
 6 files changed, 313 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memmove.S
 create mode 100644 arch/riscv/lib/memset.S
arch/riscv/Kconfig +7 -0
index a7f362d8e80c..b1b24f2e5764 100644
@@ -70,6 +70,13 @@ endmenu
 
 menu "RISC-V specific settings"
 
+config RISCV_OPTIMZED_STRING_FUNCTIONS
+	bool "use assembler optimized string functions"
+	help
+	  Say yes here to use assembler optimized memcpy / memset functions.
+	  These functions work faster than the normal versions but increase
+	  your binary size.
+
 config HAS_NMON
 	bool
 
arch/riscv/include/asm/string.h +20 -1
index 2997587d820c..1e920c8688ce 100644
@@ -1 +1,20 @@
-/* dummy */
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_RISCV_STRING_H
+#define __ASM_RISCV_STRING_H
+
+#ifdef CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *, const void *, __kernel_size_t);
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *, int, __kernel_size_t);
+#define __HAVE_ARCH_MEMMOVE
+extern void *memmove(void *, const void *, __kernel_size_t);
+
+#endif
+
+extern void *__memcpy(void *, const void *, __kernel_size_t);
+extern void *__memset(void *, int, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t);
+
+#endif
arch/riscv/lib/Makefile +1 -0
index 7fe57b0b554c..b983ca8cdca0 100644
@@ -2,3 +2,4 @@ extra-y += barebox.lds
 
 obj-y += riscv_timer.o
 obj-$(CONFIG_HAS_ARCH_SJLJ) += setjmp.o longjmp.o
+obj-$(CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS) += memcpy.o memset.o memmove.o
arch/riscv/lib/memcpy.S new file +108 -0

108 lines not on this page · raw message

arch/riscv/lib/memmove.S new file +64 -0

64 lines not on this page · raw message

arch/riscv/lib/memset.S new file +113 -0

113 lines not on this page · raw message

Signature · 7 lines
2.29.2


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

PATCH v3 12/21 filetype: detect RISC-V images

In reply to Ahmad Fatoum

We still have no boot support for RISC-V, take the first step by enabling barebox to detect both a RISC-V Linux kernel and barebox image. The header format is aligned with that of arm64, but they differ in the signature magic.

---
 common/filetype.c  | 6 ++++++
 include/filetype.h | 2 ++
 2 files changed, 8 insertions(+)
common/filetype.c +6 -0
index 539c96b74527..0cae00abaaa5 100644
@@ -61,6 +61,8 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb1" },
 	[filetype_android_sparse] = { "Android sparse image", "sparse" },
 	[filetype_arm64_linux_image] = { "ARM aarch64 Linux image", "aarch64-linux" },
+	[filetype_riscv_linux_image] = { "RISC-V Linux image", "riscv-linux" },
+	[filetype_riscv_barebox_image] = { "RISC-V barebox image", "riscv-barebox" },
 	[filetype_elf] = { "ELF", "elf" },
 	[filetype_imx_image_v1] = { "i.MX image (v1)", "imx-image-v1" },
 	[filetype_imx_image_v2] = { "i.MX image (v2)", "imx-image-v2" },
@@ -303,6 +305,10 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_bpk;
 	if (le32_to_cpu(buf[14]) == 0x644d5241)
 		return filetype_arm64_linux_image;
+	if (le32_to_cpu(buf[14]) == 0x05435352)
+		return filetype_riscv_linux_image;
+	if (le32_to_cpu(buf[14]) == 0x56435352 && !memcmp(&buf[12], "barebox", 8))
+		return filetype_riscv_barebox_image;
 	if ((buf8[0] == 0x5a || buf8[0] == 0x69 || buf8[0] == 0x78 ||
 	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
 	    buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
include/filetype.h +2 -0
index 3019dda6ed78..fd339f9564ef 100644
@@ -43,6 +43,8 @@ enum filetype {
 	filetype_kwbimage_v1,
 	filetype_android_sparse,
 	filetype_arm64_linux_image,
+	filetype_riscv_linux_image,
+	filetype_riscv_barebox_image,
 	filetype_elf,
 	filetype_imx_image_v1,
 	filetype_imx_image_v2,
Signature · 7 lines
2.29.2


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

PATCH v3 13/21 RISC-V: implement PBL image header

In reply to Ahmad Fatoum

We'll adopt the RISC-V Linux kernel image header structure for the barebox images as well. The __barebox_riscv_header() macro implementing it can customize some fields to allow differentiating between barebox and kernel images. It will be used in follow-up commits to implement the entry points of both the erizo image and the generic DT image.

---
 arch/riscv/include/asm/barebox-riscv-head.h | 36 ++++++++++++
 arch/riscv/include/asm/image.h              | 65 +++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 arch/riscv/include/asm/barebox-riscv-head.h
 create mode 100644 arch/riscv/include/asm/image.h
arch/riscv/include/asm/barebox-riscv-head.h new file +36 -0
new file mode 100644
index 000000000000..f681ec8bcee6
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (c) 2021 Ahmad Fatoum, Pengutronix */
+
+#ifndef __ASM_RISCV_HEAD_H
+#define __ASM_RISCV_HEAD_H
+
+#include <linux/kernel.h>
+#include <asm/image.h>
+
+#define ____barebox_riscv_header(instr, load_offset, version, magic1, magic2)         \
+	__asm__ __volatile__ (                                                        \
+		instr "\n"                     /* code0 */                            \
+		"j 1f\n"                       /* code1 */                            \
+		".balign 8\n"                                                         \
+		".dword " #load_offset "\n"    /* Image load offset from RAM start */ \
+		".dword _barebox_image_size\n" /* Effective Image size */             \
+		".dword 0\n"                   /* Kernel flags */                     \
+		".word " #version "\n"         /* version */                          \
+		".word 0\n"                    /* reserved */                         \
+		".dword 0\n"                   /* reserved */                         \
+		".asciz \"" magic1 "\"\n"      /* magic 1 */                          \
+		".balign 8\n"                                                         \
+		".ascii \"" magic2 "\"\n"      /* magic 2 */                          \
+		".word 0\n"                    /* reserved (PE-COFF offset) */        \
+		"1:\n"                                                                \
+	)
+
+#define __barebox_riscv_header(instr, load_offset, version, magic1, magic2) \
+        ____barebox_riscv_header(instr, load_offset, version, magic1, magic2)
+
+#ifndef __barebox_riscv_head
+#define __barebox_riscv_head() \
+	__barebox_riscv_header("nop", 0x55555555FFFFFFFF, 0x0, "barebox", "RSCV")
+#endif
+
+#endif /* __ASM_RISCV_HEAD_H */
arch/riscv/include/asm/image.h new file +65 -0

65 lines not on this page · raw message

Signature · 7 lines
2.29.2


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

PATCH v3 14/21 RISC-V: implement PBL and relocation support

In reply to Ahmad Fatoum

Given that we only support a single RISC-V board, this puts us in a good position to make this a multi-image-only architecture.

This commit adds the necessary bits. It's highly inspired by the ARM PBL support. Notable difference is that for relocations to be generated, it was necessary to compile with -fpic. The relocation code assumes the relocation entries to preprocessed. This is done at build-time by means of the prelink-riscv script imported from U-Boot.

Actual migration to -fpic and prelinking is done along with porting erizo in a follow-up commit.

---
 arch/riscv/Makefile                    |   1 +
 arch/riscv/boot/Makefile               |   3 +
 arch/riscv/boot/entry.c                |  29 ++++
 arch/riscv/boot/entry.h                |  15 ++
 arch/riscv/boot/start.c                | 185 +++++++++++++++++++++++++
 arch/riscv/boot/uncompress.c           |  74 ++++++++++
 arch/riscv/include/asm/barebox-riscv.h | 104 ++++++++++++++
 arch/riscv/include/asm/common.h        |  10 +-
 arch/riscv/include/asm/elf.h           |   7 +
 arch/riscv/include/asm/linkage.h       |   4 +
 arch/riscv/include/asm/sections.h      |  15 ++
 arch/riscv/lib/Makefile                |   3 +
 arch/riscv/lib/barebox.lds.S           |  14 +-
 arch/riscv/lib/pbl.lds.S               |  80 +++++++++++
 arch/riscv/lib/reloc.c                 |  66 +++++++++
 arch/riscv/lib/runtime-offset.S        |  12 ++
 arch/riscv/lib/sections.c              |   9 ++
 arch/riscv/lib/setupc.S                |  55 ++++++++
 scripts/.gitignore                     |   1 +
 scripts/Makefile                       |   1 +
 scripts/Makefile.lib                   |  11 ++
 scripts/prelink-riscv.c                | 122 ++++++++++++++++
 scripts/prelink-riscv.inc              | 123 ++++++++++++++++
 23 files changed, 940 insertions(+), 4 deletions(-)
 create mode 100644 arch/riscv/boot/Makefile
 create mode 100644 arch/riscv/boot/entry.c
 create mode 100644 arch/riscv/boot/entry.h
 create mode 100644 arch/riscv/boot/start.c
 create mode 100644 arch/riscv/boot/uncompress.c
 create mode 100644 arch/riscv/include/asm/barebox-riscv.h
 create mode 100644 arch/riscv/lib/pbl.lds.S
 create mode 100644 arch/riscv/lib/reloc.c
 create mode 100644 arch/riscv/lib/runtime-offset.S
 create mode 100644 arch/riscv/lib/sections.c
 create mode 100644 arch/riscv/lib/setupc.S
 create mode 100644 scripts/prelink-riscv.c
 create mode 100644 scripts/prelink-riscv.inc
arch/riscv/Makefile +1 -0
index d9cefe32c057..df2b5bb681a4 100644
@@ -43,6 +43,7 @@ endif
 common-y += $(MACH)
 common-y += arch/riscv/boards/
 common-y += arch/riscv/lib/
+common-y += arch/riscv/boot/
 
 common-$(CONFIG_OFTREE) += arch/riscv/dts/
 
arch/riscv/boot/Makefile new file +3 -0
new file mode 100644
index 000000000000..70e5b11bebb8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-y += start.o
+pbl-y += entry.o uncompress.o
arch/riscv/boot/entry.c new file +29 -0
new file mode 100644
index 000000000000..eb286423d875
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <types.h>
+
+#include <asm/barebox-riscv.h>
+
+#include "entry.h"
+#include <debug_ll.h>
+
+/*
+ * Main RISC-V entry point. Call this with the memory region you can
+ * spare for barebox. This doesn't necessarily have to be the full
+ * SDRAM. The currently running binary can be inside or outside of
+ * this region. The PBL can be running inside or outside of this
+ * region.
+ *
+ * -> membase + memsize
+ *   STACK_SIZE              - stack
+ *   128KiB                  - early memory space
+ * -> maximum end of barebox binary
+ */
+
+void __noreturn __naked barebox_riscv_entry(unsigned long membase,
+					    unsigned long memsize, void *boarddata)
+{
+	unsigned long stack_top = riscv_mem_stack_top(membase, membase + memsize);
+	asm volatile ("move sp, %0" : : "r"(stack_top));
+	barebox_pbl_start(membase, memsize, boarddata);
+}
+
arch/riscv/boot/entry.h new file +15 -0
new file mode 100644
index 000000000000..b3a24d2783f7
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ENTRY_H__
+#define __ENTRY_H__
+
+#include <common.h>
+
+void __noreturn barebox_non_pbl_start(unsigned long membase,
+				      unsigned long memsize,
+				      void *boarddata);
+
+void __noreturn barebox_pbl_start(unsigned long membase,
+				  unsigned long memsize,
+				  void *boarddata);
+
+#endif
arch/riscv/boot/start.c new file +185 -0

185 lines not on this page · raw message

arch/riscv/boot/uncompress.c new file +74 -0

74 lines not on this page · raw message

arch/riscv/include/asm/barebox-riscv.h new file +104 -0

104 lines not on this page · raw message

arch/riscv/include/asm/common.h +9 -1
index bc8a17e30bc5..a0982c548fe1 100644
@@ -1,6 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: Copyright (c) 2021 Ahmad Fatoum, Pengutronix */
 #ifndef ASM_RISCV_COMMON_H
 #define ASM_RISCV_COMMON_H
 
-/* nothing special yet */
+#include <linux/compiler.h>
+
+static __always_inline unsigned long get_pc(void)
+{
+label:
+	return (unsigned long)&&label;
+}
 
 #endif /* ASM_RISCV_COMMON_H */
arch/riscv/include/asm/elf.h +7 -0
index 7134fa05820a..adb8ec8f6ece 100644
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __ASM_RISCV_ELF_H__
 #define __ASM_RISCV_ELF_H__
 
@@ -8,4 +9,10 @@
 #define ELF_CLASS	ELFCLASS32
 #endif
 
+/* Relocation types used by the dynamic linker */
+#define R_RISCV_NONE		0
+#define R_RISCV_32		1
+#define R_RISCV_64		2
+#define R_RISCV_RELATIVE	3
+
 #endif /* __ASM_RISCV_ELF_H__ */
arch/riscv/include/asm/linkage.h +4 -0
index 9e88ba23cd2b..c6801294f388 100644
@@ -9,4 +9,8 @@
 #define __ALIGN		.balign 4
 #define __ALIGN_STR	".balign 4"
 
+#define ENDPROC(name) \
+  .type name, %function; \
+  END(name)
+
 #endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/sections.h +15 -0
index 2b8c5160388f..b5fbba8f165a 100644
@@ -1 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __ASM_SECTIONS_H
+#define __ASM_SECTIONS_H
+
+#ifndef __ASSEMBLY__
 #include <asm-generic/sections.h>
+#include <linux/types.h>
+
+extern char __rel_dyn_start[];
+extern char __rel_dyn_end[];
+extern char __dynsym_start[];
+extern char __dynsym_end[];
+
+#endif
+
+#endif /* __ASM_SECTIONS_H */
arch/riscv/lib/Makefile +3 -0
index b983ca8cdca0..5f57d9fcd2e2 100644
@@ -1,5 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
 extra-y += barebox.lds
 
 obj-y += riscv_timer.o
+obj-pbl-y += sections.o setupc.o reloc.o sections.o runtime-offset.o
 obj-$(CONFIG_HAS_ARCH_SJLJ) += setjmp.o longjmp.o
 obj-$(CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS) += memcpy.o memset.o memmove.o
arch/riscv/lib/barebox.lds.S +11 -3
index 342769890bb0..c8a331c577cf 100644
@@ -43,10 +43,18 @@ SECTIONS
 
 	.barebox_imd : { BAREBOX_IMD }
 
-	. = ALIGN(8);
-	.got : { *(.got*) }
+	/DISCARD/ : { *(.rela.plt*) }
+	.rela.dyn : {
+		__rel_dyn_start = .;
+		*(.rel*)
+		__rel_dyn_end = .;
+	}
 
-	.rela.dyn : { *(.rela*) }
+	.dynsym : {
+		__dynsym_start = .;
+		*(.dynsym)
+		__dynsym_end = .;
+	}
 
 	_edata = .;
 	. = ALIGN(8);
arch/riscv/lib/pbl.lds.S new file +80 -0

80 lines not on this page · raw message

arch/riscv/lib/reloc.c new file +66 -0

66 lines not on this page · raw message

arch/riscv/lib/runtime-offset.S new file +12 -0
new file mode 100644
index 000000000000..f6a040628963
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: Copyright (c) 2021 Ahmad Fatoum, Pengutronix */
+#include <linux/linkage.h>
+#include <asm/sections.h>
+
+.section ".text_bare_init","ax"
+ENTRY(get_runtime_offset)
+	lla	a0, _text	/* load addr */
+	la	a1, _text	/* link addr */
+	sub	a0, a0, a1
+	ret
+ENDPROC(get_runtime_offset)
arch/riscv/lib/sections.c new file +9 -0
new file mode 100644
index 000000000000..e23a41dcf5d4
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <asm/sections.h>
+#include <linux/types.h>
+
+char _text[0] __attribute__((section("._text")));
+char __bss_start[0] __attribute__((section(".__bss_start")));
+char __bss_stop[0] __attribute__((section(".__bss_stop")));
+char __image_start[0] __attribute__((section(".__image_start")));
+char __image_end[0] __attribute__((section(".__image_end")));
arch/riscv/lib/setupc.S new file +55 -0

55 lines not on this page · raw message

scripts/.gitignore +1 -0
index 7c9a3f55715f..9577d568edd0 100644
@@ -32,3 +32,4 @@ mips-relocs
 rsatoc
 stm32image
 mvebuimg
+prelink-riscv
scripts/Makefile +1 -0
index 744f4dd0e7e6..4dc70815b7e6 100644
@@ -24,6 +24,7 @@ hostprogs-always-$(CONFIG_ARCH_SOCFPGA)			+= socfpga_mkimage
 hostprogs-always-$(CONFIG_ARCH_MXS)			+= mxsimage mxsboot
 hostprogs-always-$(CONFIG_ARCH_LAYERSCAPE)		+= pblimage
 hostprogs-always-$(CONFIG_ARCH_STM32MP)			+= stm32image
+hostprogs-always-$(CONFIG_RISCV)			+= prelink-riscv
 KBUILD_HOSTCFLAGS += -I$(srctree)/scripts/include/
 HOSTLDLIBS_mxsimage  = `pkg-config --libs openssl`
 HOSTCFLAGS_omap3-usb-loader.o = `pkg-config --cflags libusb-1.0`
scripts/Makefile.lib +11 -0
index 2844d29be600..319ac19975ed 100644
@@ -247,6 +247,17 @@ $(obj)/%:: $(src)/%_shipped
 #	and add target to extra-y so that we know we have to
 #	read in the saved command line
 
+# Prelinking
+# ---------------------------------------------------------------------------
+
+ifneq ($(CONFIG_RISCV),)
+quiet_cmd_prelink__ = PRELINK $@
+      cmd_prelink__ = $(objtree)/scripts/prelink-riscv $@
+endif
+
+quiet_cmd_prelink__ ?=
+      cmd_prelink__ ?=
+
 # Linking
 # ---------------------------------------------------------------------------
 
scripts/prelink-riscv.c new file +122 -0

122 lines not on this page · raw message

scripts/prelink-riscv.inc new file +123 -0

123 lines not on this page · raw message

Signature · 7 lines
2.29.2


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

Re: [PATCH v3 14/21] RISC-V: implement PBL and relocation support

On Sun, 21 Mar 2021 16:13:37 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 75 lines
arch/riscv/include/asm/barebox-riscv.h new file +72 -0
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * (C) Copyright 2002
+ * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Marius Groeger <[email protected]>
+ *
+ * (C) Copyright 2002
+ * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Alex Zuepke <[email protected]>
+ */
+
+#ifndef _BAREBOX_RISCV_H_
+#define _BAREBOX_RISCV_H_
+
+#include <linux/sizes.h>
+#include <asm-generic/memory_layout.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <asm/sections.h>
+
+unsigned long get_runtime_offset(void);
+
+void setup_c(void);
+void relocate_to_current_adr(void);
+void relocate_to_adr(unsigned long target);
+void __noreturn __naked barebox_riscv_entry(unsigned long membase, unsigned long memsize,
+					    void *boarddata);
+
+unsigned long riscv_mem_ramoops_get(void);
+unsigned long riscv_mem_endmem_get(void);
+
+void *barebox_riscv_boot_dtb(void);
+
+static inline unsigned long riscv_mem_stack_top(unsigned long membase,
+						unsigned long endmem)
+{
+	return endmem - SZ_2M;
+}
+
+static inline unsigned long riscv_mem_stack(unsigned long membase,
+					  unsigned long endmem)
+{
+	return riscv_mem_stack_top(membase, endmem) - STACK_SIZE;
+}
+
+static inline unsigned long riscv_mem_early_malloc(unsigned long membase,
+						   unsigned long endmem)
+{
+	return riscv_mem_stack(membase, endmem) - SZ_128K;
+}
+
+static inline unsigned long riscv_mem_early_malloc_end(unsigned long membase,
+						       unsigned long endmem)
+{
+	return riscv_mem_stack(membase, endmem);
+}
+
+static inline unsigned long riscv_mem_ramoops(unsigned long membase,
+					      unsigned long endmem)
+{
+	endmem = riscv_mem_stack(membase, endmem);
+#ifdef CONFIG_FS_PSTORE_RAMOOPS
+	endmem -= CONFIG_FS_PSTORE_RAMOOPS_SIZE;
+	endmem = ALIGN_DOWN(endmem, SZ_4K);
+#endif
+
+	return endmem;
+}
+
+static inline unsigned long riscv_mem_barebox_image(unsigned long membase,
+						    unsigned long endmem,

arch/riscv/include/asm/barebox-riscv.h line 82

Quoted 10 lines
arch/riscv/include/asm/barebox-riscv.h new file +10 -0
+						    unsigned long size)
+{
+	endmem = riscv_mem_ramoops(membase, endmem);
+
+	return ALIGN_DOWN(endmem - size, SZ_1M);
+}
+
+#define ENTRY_FUNCTION(name, arg0, arg1, arg2)                          \
+	void name (ulong r0, ulong r1, ulong r2);                       \
+ 	static void __##name(ulong, ulong, ulong);                      \

^^
Please fix whitespace here.

Signature · 7 lines
Best regards,
  Antony Pavlov

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

PATCH 1/1 fixup! RISC-V: implement PBL and relocation support

In reply to Ahmad Fatoum

fix stray space in tab indented block.

---
 arch/riscv/include/asm/barebox-riscv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/barebox-riscv.h +1 -1
index 84344c842547..948a562c5c1f 100644
@@ -80,7 +80,7 @@ static inline unsigned long riscv_mem_barebox_image(unsigned long membase,
 
 #define ENTRY_FUNCTION(name, arg0, arg1, arg2)                          \
 	void name (ulong r0, ulong r1, ulong r2);                       \
- 	static void __##name(ulong, ulong, ulong);                      \
+	static void __##name(ulong, ulong, ulong);                      \
 	void __naked __noreturn __section(.text_head_entry_##name) name \
 		(ulong a0, ulong a1, ulong a2)                          \
 	{                                                               \
Signature · 7 lines
2.30.0


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

PATCH v3 15/21 RISC-V: erizo: migrate to PBL

In reply to Ahmad Fatoum

We now have everything in place to migrate erizo to PBL. As currently, this is the only board, we can drop all non-PBL support in the same go.

---
 Documentation/boards/riscv.rst             | 13 +++--
 Makefile                                   |  1 +
 arch/riscv/Kconfig                         | 15 ++---
 arch/riscv/Makefile                        | 25 +++-----
 arch/riscv/boards/erizo/Makefile           |  4 +-
 arch/riscv/boards/erizo/board.c            | 25 --------
 arch/riscv/boards/erizo/lowlevel.c         | 37 ++++--------
 arch/riscv/boards/erizo/start.S            | 68 ----------------------
 arch/riscv/configs/erizo_generic_defconfig |  5 --
 arch/riscv/dts/Makefile                    |  9 +--
 arch/riscv/include/asm/barebox-riscv.h     |  1 +
 arch/riscv/lib/Makefile                    |  2 +-
 arch/riscv/lib/barebox.lds.S               | 36 ++++++++----
 arch/riscv/lib/dtb.c                       | 26 +++++++++
 common/Kconfig                             |  4 +-
 images/.gitignore                          |  1 +
 images/Makefile                            |  4 ++
 images/Makefile.riscv                      | 12 ++++
 pbl/Kconfig                                |  2 +-
 19 files changed, 109 insertions(+), 181 deletions(-)
 delete mode 100644 arch/riscv/boards/erizo/board.c
 delete mode 100644 arch/riscv/boards/erizo/start.S
 create mode 100644 arch/riscv/lib/dtb.c
 create mode 100644 images/Makefile.riscv
Documentation/boards/riscv.rst +8 -5
index c7fa52aadbee..a1f7e30531ee 100644
@@ -1,8 +1,11 @@
 RISC-V
 ======
 
-Running RISC-V barebox on qemu
-------------------------------
+Erizo
+-----
+
+Running on qemu
+~~~~~~~~~~~~~~~
 
 Obtain RISC-V GCC/Newlib Toolchain,
 see https://github.com/riscv/riscv-tools/blob/master/README.md
@@ -44,7 +47,7 @@ Next compile barebox::
 Run barebox::
 
   $ <path to riscv-qemu source>/riscv32-softmmu/qemu-system-riscv32 \
-      -nographic -M erizo -bios <path to barebox sources >/barebox.bin \
+      -nographic -M erizo -bios ./images/barebox-erizo-generic.img \
       -serial stdio -monitor none -trace file=/dev/null
   Switch to console [cs0]
   
@@ -59,8 +62,8 @@ Run barebox::
   barebox:/
 
 
-Running RISC-V barebox on DE0-Nano FPGA board
----------------------------------------------
+Running on DE0-Nano FPGA board
+------------------------------
 
 See https://github.com/open-design/riscv-soc-cores/ for instructions
 on DE0-Nano bitstream generation and loading.
Makefile +1 -0
index 6d44314f0a7e..4cc7bef2bd42 100644
@@ -776,6 +776,7 @@ define rule_barebox__
 	$(if $(CONFIG_KALLSYMS),,+$(call cmd,barebox_version))
 	$(call cmd,barebox__)
 	$(Q)echo 'cmd_$@ := $(cmd_barebox__)' > $(@D)/.$(@F).cmd
+	$(call cmd,prelink__)
 	$(call cmd,sysmap)
 endef
 
arch/riscv/Kconfig +5 -10
index b1b24f2e5764..4a2a547a7b35 100644
@@ -1,14 +1,16 @@
 config RISCV
 	def_bool y
 	select GENERIC_FIND_NEXT_BIT
-	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
-	select HAVE_CONFIGURABLE_TEXT_BASE
 	select GPIOLIB
 	select OFTREE
+	select OFDEVICE
 	select COMMON_CLK
 	select COMMON_CLK_OF_PROVIDER
 	select CLKDEV_LOOKUP
 	select HAS_DMA
+	select HAVE_PBL_IMAGE
+	select HAVE_PBL_MULTI_IMAGES
+	select HAVE_IMAGE_COMPRESSION
 
 config ARCH_TEXT_BASE
 	hex
@@ -24,6 +26,7 @@ config MACH_ERIZO
 	bool "erizo family"
 	select HAS_DEBUG_LL
 	select HAS_NMON
+	select USE_COMPRESSED_DTB
 
 endchoice
 
@@ -56,14 +59,6 @@ config 32BIT
 
 endchoice
 
-config BUILTIN_DTB
-	bool "link a DTB into the barebox image"
-	depends on OFTREE
-
-config BUILTIN_DTB_NAME
-	string "DTB to build into the barebox image"
-	depends on BUILTIN_DTB
-
 source "arch/riscv/mach-erizo/Kconfig"
 
 endmenu
arch/riscv/Makefile +9 -16
index df2b5bb681a4..00456ed02ce1 100644
@@ -3,21 +3,23 @@ KBUILD_DEFCONFIG := erizo_generic_defconfig
 KBUILD_CPPFLAGS += -fno-strict-aliasing
 
 ifeq ($(CONFIG_ARCH_RV32I),y)
-	cflags-y += -march=rv32im -mabi=ilp32
-	riscv-ldflags-y += -melf32lriscv
+	riscv-cflags-y := -march=rv32im -mabi=ilp32
+	riscv-ldflags-y := -melf32lriscv
 endif
 
-cflags-y += -fno-pic -Wstrict-prototypes -mcmodel=medany
+riscv-cflags-y += -Wstrict-prototypes -mcmodel=medany -fpic
+riscv-ldflags-y += -pie -static
 
+PBL_CPPFLAGS += $(riscv-cflags-y)
+LDFLAGS_pbl += $(riscv-ldflags-y)
+
+cflags-y += $(riscv-cflags-y)
 LDFLAGS_barebox += -nostdlib
 
 machine-$(CONFIG_MACH_ERIZO)	:= erizo
 
 LDFLAGS_barebox += $(riscv-ldflags-y)
 
-TEXT_BASE = $(CONFIG_TEXT_BASE)
-KBUILD_CPPFLAGS += -DTEXT_BASE=$(CONFIG_TEXT_BASE)
-
 ifndef CONFIG_MODULES
 # Add cleanup flags
 KBUILD_CPPFLAGS += -fdata-sections -ffunction-sections
@@ -54,13 +56,4 @@ lds-y	:= arch/riscv/lib/barebox.lds
 
 CLEAN_FILES += arch/riscv/lib/barebox.lds
 
-ifeq ($(CONFIG_MACH_ERIZO),y)
-KBUILD_IMAGE := barebox.erizo.nmon
-endif
-
-quiet_cmd_erizo_nmon_image = MKIMAGE $@
-      cmd_erizo_nmon_image = $(srctree)/scripts/erizo-nmon-image $< $@ || \
-	echo "WARNING: Couldn't create erizo nmon image due to previous errors."
-
-barebox.erizo.nmon: $(KBUILD_BINARY) FORCE
-	$(call if_changed,erizo_nmon_image)
+KBUILD_IMAGE := $(KBUILD_BINARY)
arch/riscv/boards/erizo/Makefile +1 -3
index 72b9a13ba73f..3d217ffe0b93 100644
@@ -1,5 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y += lowlevel.o
-obj-y += start.o
-obj-y += board.o
+pbl-y += lowlevel.o
arch/riscv/boards/erizo/board.c deleted +0 -25
deleted file mode 100644
index b9b68fc7f254..000000000000
@@ -1,25 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2016, 2018 Antony Pavlov <[email protected]>
- *
- * This file is part of barebox.
- *
- * 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.
- *
- */
-#include <common.h>
-#include <init.h>
-#include <of.h>
-
-extern char __dtb_start[];
-
-static int of_riscv_init(void)
-{
-	barebox_register_fdt(__dtb_start);
-
-	return 0;
-}
-core_initcall(of_riscv_init);
arch/riscv/boards/erizo/lowlevel.c +10 -27
index f9c640c1123f..d9edb530b746 100644
@@ -1,35 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2016 Antony Pavlov <[email protected]>
- *
- * This file is part of barebox.
- *
- * 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.
- *
- */
 
 #include <common.h>
-#include <memory.h>
-#include <asm-generic/memory_layout.h>
-#include <asm/sections.h>
+#include <asm/barebox-riscv.h>
+#include <debug_ll.h>
 
-void main_entry(void);
-
-/**
- * Called plainly from assembler code
- *
- * @note The C environment isn't initialized yet
- */
-void main_entry(void)
+ENTRY_FUNCTION(start_erizo_generic, a0, a1, a2)
 {
-	/* clear the BSS first */
-	memset(__bss_start, 0x00, __bss_stop - __bss_start);
+	extern char __dtb_z_erizo_generic_start[];
+
+	debug_ll_ns16550_init();
+	putc_ll('>');
 
-	mem_malloc_init((void *)MALLOC_BASE,
-			(void *)(MALLOC_BASE + MALLOC_SIZE - 1));
+	/* On POR, we are running from read-only memory here. */
 
-	start_barebox();
+	barebox_riscv_entry(0x80000000, SZ_8M,
+			    __dtb_z_erizo_generic_start + get_runtime_offset());
 }
arch/riscv/boards/erizo/start.S deleted +0 -68

68 lines not on this page · raw message

arch/riscv/configs/erizo_generic_defconfig +0 -5
index 2ea1e46cc960..839b652ab53d 100644
@@ -1,9 +1,5 @@
 # CONFIG_GLOBALVAR is not set
-CONFIG_TEXT_BASE=0x80000000
-CONFIG_MEMORY_LAYOUT_FIXED=y
-CONFIG_STACK_BASE=0x800e0000
 CONFIG_STACK_SIZE=0x20000
-CONFIG_MALLOC_BASE=0x80100000
 CONFIG_MALLOC_SIZE=0x100000
 CONFIG_MALLOC_TLSF=y
 CONFIG_PANIC_HANG=y
@@ -36,7 +32,6 @@ CONFIG_CMD_SPI=y
 CONFIG_CMD_OF_DUMP=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_DHRYSTONE=y
-CONFIG_OFDEVICE=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SPI_GPIO=y
 CONFIG_I2C=y
arch/riscv/dts/Makefile +3 -6
index 6bd4e5a9250c..4041c34e0c45 100644
@@ -1,12 +1,9 @@
-BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
-ifneq ($(BUILTIN_DTB),)
-obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
-endif
-
-obj-$(CONFIG_BOARD_ERIZO_GENERIC) += erizo-generic.dtb.o
+# SPDX-License-Identifier: GPL-2.0
 
 # just to build a built-in.o. Otherwise compilation fails when no devicetree is
 # created.
 obj- += dummy.o
 
+pbl-$(CONFIG_BOARD_ERIZO_GENERIC) += erizo-generic.dtb.o
+
 clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts
arch/riscv/include/asm/barebox-riscv.h +1 -0
index 3655e3b87535..84344c842547 100644
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 #include <asm/sections.h>
+#include <asm/barebox-riscv-head.h>
 
 unsigned long get_runtime_offset(void);
 
arch/riscv/lib/Makefile +1 -1
index 5f57d9fcd2e2..a9bf68bca597 100644
@@ -2,7 +2,7 @@
 
 extra-y += barebox.lds
 
-obj-y += riscv_timer.o
+obj-y += riscv_timer.o dtb.o
 obj-pbl-y += sections.o setupc.o reloc.o sections.o runtime-offset.o
 obj-$(CONFIG_HAS_ARCH_SJLJ) += setjmp.o longjmp.o
 obj-$(CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS) += memcpy.o memset.o memmove.o
arch/riscv/lib/barebox.lds.S +24 -12
index c8a331c577cf..562ad5dc6662 100644
@@ -14,22 +14,30 @@
 #include <asm-generic/barebox.lds.h>
 
 OUTPUT_ARCH(riscv)
-ENTRY(_start)
+ENTRY(start)
 SECTIONS
 {
-	. = TEXT_BASE;
+	. = 0x0;
 
-	. = ALIGN(8);
+	.image_start : { *(.__image_start) }
+
+	. = ALIGN(4);
+	._text : { *(._text) }
 	.text      :
 	{
 		_stext = .;
-		_start = .;
-		KEEP(*(.text_entry*))
-		_text = .;
+		*(.text_entry*)
+		__bare_init_start = .;
+		*(.text_bare_init*)
+		__bare_init_end = .;
+		__exceptions_start = .;
+		KEEP(*(.text_exceptions*))
+		__exceptions_stop = .;
 		*(.text*)
 	}
+	BAREBOX_BARE_INIT_SIZE
 
-	. = ALIGN(8);
+	. = ALIGN(4);
 	.rodata : {
 		*(.rodata*)
 		RO_DATA_SECTION
@@ -38,7 +46,7 @@ SECTIONS
 	_etext = .;			/* End of text and rodata section */
 	_sdata = .;
 
-	. = ALIGN(8);
+	. = ALIGN(4);
 	.data : { *(.data*) }
 
 	.barebox_imd : { BAREBOX_IMD }
@@ -57,9 +65,13 @@ SECTIONS
 	}
 
 	_edata = .;
-	. = ALIGN(8);
-	__bss_start = .;
-	.bss : { *(.bss*) *(.sbss*) }
-	__bss_stop = .;
+
+	.image_end : { *(.__image_end) }
+
+	. = ALIGN(4);
+	.__bss_start :  { *(.__bss_start) }
+	.bss : { *(.bss*) }
+	.__bss_stop :  { *(.__bss_stop) }
 	_end = .;
+	_barebox_image_size = __bss_start;
 }
arch/riscv/lib/dtb.c new file +26 -0
new file mode 100644
index 000000000000..c7fa6b0c31ca
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2013 Sascha Hauer <[email protected]>, Pengutronix
+#include <common.h>
+#include <init.h>
+#include <of.h>
+#include <asm/barebox-riscv.h>
+
+static int of_riscv_init(void)
+{
+	void *fdt;
+
+	/* See if we are provided a dtb in boarddata */
+	fdt = barebox_riscv_boot_dtb();
+	if (!fdt) {
+		pr_err("No DTB found\n");
+		return -ENODATA;
+	}
+
+	pr_debug("using boarddata provided DTB\n");
+
+
+	barebox_register_fdt(fdt);
+
+	return 0;
+}
+core_initcall(of_riscv_init);
common/Kconfig +2 -2
index ede26cec081a..342817bbcbb4 100644
@@ -44,7 +44,7 @@ config BLOCK_WRITE
 
 config USE_COMPRESSED_DTB
 	bool
-	depends on ARM
+	depends on ARM || RISCV
 	select UNCOMPRESS
 	select LZO_DECOMPRESS
 
@@ -359,7 +359,7 @@ config KALLSYMS
 	  This is useful to print a nice backtrace when an exception occurs.
 
 config RELOCATABLE
-	depends on PPC || ARM
+	depends on PPC || ARM || RISCV
 	bool "generate relocatable barebox binary"
 	help
 	  A non relocatable barebox binary will run at it's compiled in
images/.gitignore +1 -0
index 377c14ceb384..eafdb44b5bdd 100644
@@ -31,3 +31,4 @@ barebox.sum
 *.image
 *.mvebu1img
 *.stm32
+*.nmon
images/Makefile +4 -0
index 84492a154d16..ee1347f6b6bd 100644
@@ -42,6 +42,8 @@
 # both as entrypoint and as filename
 #
 
+include scripts/Makefile.lib
+
 quiet_cmd_objcopy_bin = OBJCOPYB $@
       cmd_objcopy_bin = \
 		$(OBJCOPY) -O binary $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ && \
@@ -64,6 +66,7 @@ PBL_CPPFLAGS	+= -fdata-sections -ffunction-sections
 
 $(obj)/%.pbl: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(obj)/piggy.o $(obj)/sha_sum.o FORCE
 	$(call if_changed,elf__,$(*F))
+	$(call cmd,prelink__)
 
 $(obj)/%.pblb: $(obj)/%.pbl FORCE
 	$(call if_changed,objcopy_bin,$(*F))
@@ -164,6 +167,7 @@ include $(srctree)/images/Makefile.at91
 include $(srctree)/images/Makefile.zynq
 include $(srctree)/images/Makefile.zynqmp
 include $(srctree)/images/Makefile.layerscape
+include $(srctree)/images/Makefile.riscv
 
 
 pblb-$(CONFIG_BOARD_GENERIC_DT) += start_dt_2nd
images/Makefile.riscv new file +12 -0
new file mode 100644
index 000000000000..463c6ce4400d
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+quiet_cmd_erizo_nmon_image = MKIMAGE $@
+      cmd_erizo_nmon_image = $(srctree)/scripts/erizo-nmon-image $< $@ || \
+	echo "WARNING: Couldn't create erizo nmon image due to previous errors."
+
+$(obj)/%.nmon: $(obj)/%.img FORCE
+	$(call if_changed,erizo_nmon_image)
+
+pblb-$(CONFIG_BOARD_ERIZO_GENERIC) += start_erizo_generic
+FILE_barebox-erizo-generic.img = start_erizo_generic.pblb
+image-$(CONFIG_BOARD_ERIZO_GENERIC) += barebox-erizo-generic.img barebox-erizo-generic.nmon
pbl/Kconfig +1 -1
index 2eea5aef7a30..451a278c4088 100644
@@ -27,7 +27,7 @@ config PBL_SINGLE_IMAGE
 if PBL_IMAGE
 
 config PBL_RELOCATABLE
-	depends on ARM || MIPS
+	depends on ARM || MIPS || RISCV
 	bool "relocatable pbl image"
 	help
 	  Generate a pbl binary which can relocate itself during startup to run
Signature · 7 lines
2.29.2


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

On Sun, 21 Mar 2021 16:13:38 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

I have good news and bad news.

The good news is that erizo barebox successfully runs on real FPGA hardware.

The bad news is that there is no "stack" region in erizo iomem output; also barebox relocated to te middle of RAM not to the top of RAM:

barebox:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x80000000 - 0x807fffff (size 0x00800000) ram0

    0x802ffd80 - 0x803ffd7f (size 0x00100000) malloc space
    0x803ffd80 - 0x803fffc3 (size 0x00000244) board data
    0x80400000 - 0x80436cff (size 0x00036d00) barebox
    0x80436d00 - 0x8043eec7 (size 0x000081c8) barebox data
    0x8043eec8 - 0x8044336f (size 0x000044a8) bss

0x90000000 - 0x9000001f (size 0x00000020) [email protected] 0x91000000 - 0x91000003 (size 0x00000004) [email protected] 0x91000004 - 0x91000007 (size 0x00000004) [email protected]
barebox:/

Please compare with mips malta and arm vexpress-a9 iomem output:

barebox@qemu malta:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x180003f8 - 0x180003ff (size 0x00000008) [email protected] 0x1e000000 - 0x1e3fffff (size 0x00400000) [email protected] 0x1f000900 - 0x1f00093f (size 0x00000040) [email protected] 0x1f000b00 - 0x1f000b1f (size 0x00000020) [email protected] 0xa0000000 - 0xafffffff (size 0x10000000) kseg1_ram0

    0xafb39000 - 0xafb3ffff (size 0x00007000) stack
    0xafb40000 - 0xaff3ffff (size 0x00400000) malloc space
    0xaff40000 - 0xaffa3fdf (size 0x00063fe0) barebox
    0xaffa3fe0 - 0xafff249f (size 0x0004e4c0) barebox data
    0xafffa4a0 - 0xafffe60b (size 0x0000416c) bss

barebox@qemu malta:/

barebox@V2P-CA9:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x10004000 - 0x10004fff (size 0x00001000) amba
0x10005000 - 0x10005fff (size 0x00001000) amba
0x10006000 - 0x10006fff (size 0x00001000) amba
0x10007000 - 0x10007fff (size 0x00001000) amba
0x10009000 - 0x10009fff (size 0x00001000) amba
0x1000a000 - 0x1000afff (size 0x00001000) amba
0x1000b000 - 0x1000bfff (size 0x00001000) amba
0x1000c000 - 0x1000cfff (size 0x00001000) amba
0x10011000 - 0x10011fff (size 0x00001000) amba
0x10012000 - 0x10012fff (size 0x00001000) amba
0x10017000 - 0x10017fff (size 0x00001000) amba
0x1001f000 - 0x1001ffff (size 0x00001000) amba
0x10020000 - 0x10020fff (size 0x00001000) amba
0x40000000 - 0x43ffffff (size 0x04000000) 40000000.flash@0,00000000.of 0x44000000 - 0x47ffffff (size 0x04000000) 40000000.flash@0,00000000.of 0x60000000 - 0x9fffffff (size 0x40000000) ram0

    0x6fefe1c0 - 0x7fdfc37f (size 0x0fefe1c0) malloc space
    0x7fdfc380 - 0x7fdfffe3 (size 0x00003c64) board data
    0x7fe00000 - 0x7fe5749f (size 0x000574a0) barebox
    0x7fe574a0 - 0x7feabb9f (size 0x00054700) barebox data
    0x7feabba0 - 0x7feae90f (size 0x00002d70) bss
    0x7ffe8000 - 0x7ffeffff (size 0x00008000) stack

barebox@V2P-CA9:/

Signature · 7 lines
Best regards,
  Antony Pavlov

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

Hello Antony,

Quoted 10 lines · Antony Pavlov

On Sun, 21 Mar 2021 16:13:38 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

I have good news and bad news.

The good news is that erizo barebox successfully runs on real FPGA hardware.

The bad news is that there is no "stack" region in erizo iomem output;

Just sent out a fix. I missed that common code can no longer request the stack memory region as we have a dynamic STACK_BASE now.

Quoted 10 lines

also barebox relocated to te middle of RAM not to the top of RAM:

barebox:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x80000000 - 0x807fffff (size 0x00800000) ram0

    0x802ffd80 - 0x803ffd7f (size 0x00100000) malloc space
    0x803ffd80 - 0x803fffc3 (size 0x00000244) board data
    0x80400000 - 0x80436cff (size 0x00036d00) barebox
    0x80436d00 - 0x8043eec7 (size 0x000081c8) barebox data
    0x8043eec8 - 0x8044336f (size 0x000044a8) bss
Quoted 4 lines

0x90000000 - 0x9000001f (size 0x00000020) [email protected] 0x91000000 - 0x91000003 (size 0x00000004) [email protected] 0x91000004 - 0x91000007 (size 0x00000004) [email protected]
barebox:/

Stack is:

	0x805e0000 - 0x805fffff (size 0x00020000) stack

ARM placed the top most memory region 1M from the end of memory. I chose 2M for RISC-V, because Qemu for Virt places the FDT into the last 2M.

I've adjust the virt entry point to take care of this and removed the 2M. My memory map is now:

0x00000000 - 0xffffffff (size 0x00000000) iomem
0x80000000 - 0x807fffff (size 0x00800000) ram0

    0x804ffd80 - 0x805ffd7f (size 0x00100000) malloc space
    0x805ffd80 - 0x805fffc3 (size 0x00000244) board data
    0x80600000 - 0x80636c7f (size 0x00036c80) barebox
    0x80636c80 - 0x8063ee53 (size 0x000081d4) barebox data
    0x8063ee54 - 0x806432ff (size 0x000044ac) bss
    0x807e0000 - 0x807fffff (size 0x00020000) stack

0x90000000 - 0x9000001f (size 0x00000020) [email protected] 0x91000000 - 0x91000003 (size 0x00000004) [email protected] 0x91000004 - 0x91000007 (size 0x00000004) [email protected]

barebox is now 2M from the end of RAM. This is because barebox PBL doesn't have information on how big barebox proper BSS is. I am doing it like ARM and assume 1M.

Thanks for testing and let me know if this works for you, Ahmad

Quoted 46 lines

Please compare with mips malta and arm vexpress-a9 iomem output:

barebox@qemu malta:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x180003f8 - 0x180003ff (size 0x00000008) [email protected] 0x1e000000 - 0x1e3fffff (size 0x00400000) [email protected] 0x1f000900 - 0x1f00093f (size 0x00000040) [email protected] 0x1f000b00 - 0x1f000b1f (size 0x00000020) [email protected] 0xa0000000 - 0xafffffff (size 0x10000000) kseg1_ram0

    0xafb39000 - 0xafb3ffff (size 0x00007000) stack
    0xafb40000 - 0xaff3ffff (size 0x00400000) malloc space
    0xaff40000 - 0xaffa3fdf (size 0x00063fe0) barebox
    0xaffa3fe0 - 0xafff249f (size 0x0004e4c0) barebox data
    0xafffa4a0 - 0xafffe60b (size 0x0000416c) bss

barebox@qemu malta:/

barebox@V2P-CA9:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x10004000 - 0x10004fff (size 0x00001000) amba
0x10005000 - 0x10005fff (size 0x00001000) amba
0x10006000 - 0x10006fff (size 0x00001000) amba
0x10007000 - 0x10007fff (size 0x00001000) amba
0x10009000 - 0x10009fff (size 0x00001000) amba
0x1000a000 - 0x1000afff (size 0x00001000) amba
0x1000b000 - 0x1000bfff (size 0x00001000) amba
0x1000c000 - 0x1000cfff (size 0x00001000) amba
0x10011000 - 0x10011fff (size 0x00001000) amba
0x10012000 - 0x10012fff (size 0x00001000) amba
0x10017000 - 0x10017fff (size 0x00001000) amba
0x1001f000 - 0x1001ffff (size 0x00001000) amba
0x10020000 - 0x10020fff (size 0x00001000) amba
0x40000000 - 0x43ffffff (size 0x04000000) 40000000.flash@0,00000000.of 0x44000000 - 0x47ffffff (size 0x04000000) 40000000.flash@0,00000000.of 0x60000000 - 0x9fffffff (size 0x40000000) ram0

    0x6fefe1c0 - 0x7fdfc37f (size 0x0fefe1c0) malloc space
    0x7fdfc380 - 0x7fdfffe3 (size 0x00003c64) board data
    0x7fe00000 - 0x7fe5749f (size 0x000574a0) barebox
    0x7fe574a0 - 0x7feabb9f (size 0x00054700) barebox data
    0x7feabba0 - 0x7feae90f (size 0x00002d70) bss
    0x7ffe8000 - 0x7ffeffff (size 0x00008000) stack

barebox@V2P-CA9:/

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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
#20 lore raw

PATCH v3 16/21 RISC-V: support symbol names in barebox image

In reply to Ahmad Fatoum

Make debugging a bit more convenient by providing users the option to include symbol names.

---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index 4a2a547a7b35..91e8546f9624 100644
@@ -11,6 +11,7 @@ config RISCV
 	select HAVE_PBL_IMAGE
 	select HAVE_PBL_MULTI_IMAGES
 	select HAVE_IMAGE_COMPRESSION
+	select HAS_KALLSYMS
 
 config ARCH_TEXT_BASE
 	hex
Signature · 7 lines
2.29.2


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

PATCH v3 17/21 RISC-V: add 64-bit support

In reply to Ahmad Fatoum

From: Rouven Czerwinski <[email protected]>

As our assembly routines are now written to work correctly on 32-bit as well as 64-bit, nothing is holding us back from adding 64-bit support.

---
 arch/riscv/Kconfig             | 27 +++++++++++++++++++--------
 arch/riscv/Makefile            |  7 +++++--
 arch/riscv/include/asm/elf.h   |  1 -
 arch/riscv/include/asm/types.h |  8 +-------
 arch/riscv/lib/barebox.lds.S   |  5 +++++
 arch/riscv/lib/pbl.lds.S       |  5 +++++
 6 files changed, 35 insertions(+), 18 deletions(-)
arch/riscv/Kconfig +19 -8
index 91e8546f9624..08a0e7cef48d 100644
@@ -11,6 +11,7 @@ config RISCV
 	select HAVE_PBL_IMAGE
 	select HAVE_PBL_MULTI_IMAGES
 	select HAVE_IMAGE_COMPRESSION
+	select HAS_ARCH_SJLJ
 	select HAS_KALLSYMS
 
 config ARCH_TEXT_BASE
@@ -25,6 +26,7 @@ choice
 
 config MACH_ERIZO
 	bool "erizo family"
+	select ARCH_RV32I
 	select HAS_DEBUG_LL
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
@@ -41,24 +43,33 @@ config ARCH_RV32I
 	select GENERIC_LIB_ASHLDI3
 	select GENERIC_LIB_ASHRDI3
 	select GENERIC_LIB_LSHRDI3
-	select HAS_ARCH_SJLJ
+	select 32BIT
+
+config ARCH_RV64I
+	bool "RV64I"
+	select CPU_SUPPORTS_64BIT_KERNEL
+	select 64BIT
 
 endchoice
 
 config CPU_SUPPORTS_32BIT_KERNEL
 	bool
 
-choice
-	prompt "barebox code model"
-	default 32BIT
+config CPU_SUPPORTS_64BIT_KERNEL
+	bool
+
+config PHYS_ADDR_T_64BIT
+	bool
 
 config 32BIT
-	bool "32-bit barebox"
+	bool
 	depends on CPU_SUPPORTS_32BIT_KERNEL
-	help
-	  Select this option to build a 32-bit barebox.
 
-endchoice
+config 64BIT
+	bool
+	depends on CPU_SUPPORTS_64BIT_KERNEL
+	select ARCH_DMA_ADDR_T_64BIT
+	select PHYS_ADDR_T_64BIT
 
 source "arch/riscv/mach-erizo/Kconfig"
 
arch/riscv/Makefile +5 -2
index 00456ed02ce1..c49c1b09ec8e 100644
@@ -3,8 +3,11 @@ KBUILD_DEFCONFIG := erizo_generic_defconfig
 KBUILD_CPPFLAGS += -fno-strict-aliasing
 
 ifeq ($(CONFIG_ARCH_RV32I),y)
-	riscv-cflags-y := -march=rv32im -mabi=ilp32
-	riscv-ldflags-y := -melf32lriscv
+	riscv-cflags-y += -march=rv32im -mabi=ilp32
+	riscv-ldflags-y += -melf32lriscv
+else
+	riscv-cflags-y += -march=rv64im -mabi=lp64
+	riscv-ldflags-y += -melf64lriscv
 endif
 
 riscv-cflags-y += -Wstrict-prototypes -mcmodel=medany -fpic
arch/riscv/include/asm/elf.h +0 -1
index adb8ec8f6ece..0cd27724da60 100644
@@ -4,7 +4,6 @@
 
 #if __SIZEOF_POINTER__ == 8
 #define ELF_CLASS	ELFCLASS64
-#define CONFIG_PHYS_ADDR_T_64BIT
 #else
 #define ELF_CLASS	ELFCLASS32
 #endif
arch/riscv/include/asm/types.h +1 -7
index af37d7738c65..1ad5904f9178 100644
@@ -3,18 +3,12 @@
 
 #include <asm-generic/int-ll64.h>
 
-#ifdef __riscv64
+#if __riscv_xlen == 64
 /*
  * This is used in dlmalloc. On RISCV64 we need it to be 64 bit
  */
 #define INTERNAL_SIZE_T unsigned long
 
-/*
- * This is a Kconfig variable in the Kernel, but we want to detect
- * this during compile time, so we set it here.
- */
-#define CONFIG_PHYS_ADDR_T_64BIT
-
 #endif
 
 #endif /* __ASM_RISCV_TYPES_H */
arch/riscv/lib/barebox.lds.S +5 -0
index 562ad5dc6662..7856b57a5220 100644
@@ -15,6 +15,11 @@
 
 OUTPUT_ARCH(riscv)
 ENTRY(start)
+#ifdef CONFIG_64BIT
+OUTPUT_FORMAT("elf64-littleriscv")
+#else
+OUTPUT_FORMAT("elf32-littleriscv")
+#endif
 SECTIONS
 {
 	. = 0x0;
arch/riscv/lib/pbl.lds.S +5 -0
index 881faac34064..e238b2bfd34e 100644
@@ -6,6 +6,11 @@
 #include <asm-generic/memory_layout.h>
 
 OUTPUT_ARCH(riscv)
+#ifdef CONFIG_64BIT
+OUTPUT_FORMAT("elf64-littleriscv")
+#else
+OUTPUT_FORMAT("elf32-littleriscv")
+#endif
 SECTIONS
 {
 	. = 0x0;
Signature · 7 lines
2.29.2


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

PATCH v3 18/21 RISC-V: add generic DT image

In reply to Ahmad Fatoum

This barebox image implements the same header as Linux and receives the device tree in the same register. It can be booted from barebox or loaded by Qemu -kernel option.

---
 arch/riscv/Kconfig             |  9 +++++++++
 arch/riscv/boot/Makefile       |  1 +
 arch/riscv/boot/board-dt-2nd.c | 36 ++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 arch/riscv/boot/board-dt-2nd.c
arch/riscv/Kconfig +9 -0
index 08a0e7cef48d..e630ad4ceb98 100644
@@ -73,6 +73,15 @@ config 64BIT
 
 source "arch/riscv/mach-erizo/Kconfig"
 
+config BOARD_RISCV_GENERIC_DT
+	select BOARD_GENERIC_DT
+	bool "Build generic RISC-V device tree 2nd stage image"
+	help
+	  This enables compilation of a generic image that can be started 2nd
+	  stage from barebox or from qemu. It picks up a device tree passed
+	  in a1 like the Kernel does, so it could be used anywhere where a Kernel
+	  image could be used. The image will be called images/barebox-dt-2nd.img
+
 endmenu
 
 menu "RISC-V specific settings"
arch/riscv/boot/Makefile +1 -0
index 70e5b11bebb8..968a826d1620 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-y += start.o
 pbl-y += entry.o uncompress.o
+pbl-$(CONFIG_BOARD_GENERIC_DT) += board-dt-2nd.o
arch/riscv/boot/board-dt-2nd.c new file +36 -0
new file mode 100644
index 000000000000..25fa7d4f2bef
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <common.h>
+#include <debug_ll.h>
+#include <pbl.h>
+
+#if __riscv_xlen == 64
+#define IMAGE_LOAD_OFFSET 0x200000 /* Image load offset(2MB) from start of RAM */
+#else
+#define IMAGE_LOAD_OFFSET 0x400000 /* Image load offset(4MB) from start of RAM */
+#endif
+
+/* because we can depend on being loaded at an offset, we can just use
+ * our load address as stack top
+ */
+#define __barebox_riscv_head() \
+	__barebox_riscv_header("auipc sp, 0", IMAGE_LOAD_OFFSET, \
+			       RISCV_HEADER_VERSION, "RISCV", RISCV_IMAGE_MAGIC2)
+
+#include <asm/barebox-riscv.h>
+
+ENTRY_FUNCTION(start_dt_2nd, a0, _fdt, a2)
+{
+	unsigned long membase, memsize;
+	void *fdt = (void *)_fdt;
+
+	if (!fdt)
+		hang();
+
+	relocate_to_current_adr();
+	setup_c();
+
+	fdt_find_mem(fdt, &membase, &memsize);
+
+	barebox_riscv_entry(membase, memsize, fdt);
+}
Signature · 7 lines
2.29.2


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

PATCH v3 19/21 clocksource: add driver for RISC-V and CLINT timers

In reply to Ahmad Fatoum

CLINT is selected by Linux on nommu RISC-V machines, while the RISC-V timer with SBI is selected on MMU enabled ones.
Both are also available on the Qemu Virt machine, but only SBI is available on TinyEmu. As we'll add Virt support in a follow-up commit, import both drivers now. Erizo could in theory make use of the RISC-V timer, but even a 2GHz timer base is too slow for it to be accurate.

---
 arch/riscv/Kconfig                |  12 ++
 arch/riscv/Makefile               |   1 +
 arch/riscv/cpu/Makefile           |   3 +
 arch/riscv/cpu/core.c             |  50 +++++++
 arch/riscv/cpu/time.c             |  38 ++++++
 arch/riscv/include/asm/csr.h      | 211 ++++++++++++++++++++++++++++++
 arch/riscv/include/asm/sbi.h      | 153 ++++++++++++++++++++++
 arch/riscv/include/asm/timer.h    |   9 ++
 arch/riscv/lib/dtb.c              |   4 +
 drivers/clocksource/Kconfig       |  15 +++
 drivers/clocksource/Makefile      |   2 +
 drivers/clocksource/timer-clint.c |  93 +++++++++++++
 drivers/clocksource/timer-riscv.c |  50 +++++++
 13 files changed, 641 insertions(+)
 create mode 100644 arch/riscv/cpu/Makefile
 create mode 100644 arch/riscv/cpu/core.c
 create mode 100644 arch/riscv/cpu/time.c
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/timer.h
 create mode 100644 drivers/clocksource/timer-clint.c
 create mode 100644 drivers/clocksource/timer-riscv.c
arch/riscv/Kconfig +12 -0
index e630ad4ceb98..50c4d145cf54 100644
@@ -13,6 +13,7 @@ config RISCV
 	select HAVE_IMAGE_COMPRESSION
 	select HAS_ARCH_SJLJ
 	select HAS_KALLSYMS
+	select RISCV_TIMER if RISCV_SBI
 
 config ARCH_TEXT_BASE
 	hex
@@ -30,6 +31,7 @@ config MACH_ERIZO
 	select HAS_DEBUG_LL
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
+	select RISCV_M_MODE
 
 endchoice
 
@@ -113,4 +115,14 @@ config NMON_HELP
 	  Say yes here to get the nmon commands message on
 	  every nmon start.
 
+# set if we run in machine mode, cleared if we run in supervisor mode
+config RISCV_M_MODE
+	bool
+
+# set if we are running in S-mode and can use SBI calls
+config RISCV_SBI
+	bool
+	depends on !RISCV_M_MODE
+	default y
+
 endmenu
arch/riscv/Makefile +1 -0
index c49c1b09ec8e..c0dadead42ad 100644
@@ -47,6 +47,7 @@ endif
 
 common-y += $(MACH)
 common-y += arch/riscv/boards/
+common-y += arch/riscv/cpu/
 common-y += arch/riscv/lib/
 common-y += arch/riscv/boot/
 
arch/riscv/cpu/Makefile new file +3 -0
new file mode 100644
index 000000000000..f1312be699a1
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += core.o time.o
arch/riscv/cpu/core.c new file +50 -0

50 lines not on this page · raw message

arch/riscv/cpu/time.c new file +38 -0
new file mode 100644
index 000000000000..39bb6a5112f7
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ * All RISC-V systems have a timer attached to every hart.  These timers can
+ * either be read from the "time" and "timeh" CSRs, and can use the SBI to
+ * setup events, or directly accessed using MMIO registers.
+ */
+#include <common.h>
+#include <init.h>
+#include <clock.h>
+#include <errno.h>
+#include <of.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <io.h>
+#include <asm/timer.h>
+
+unsigned long riscv_timebase;
+
+int timer_init(void)
+{
+	struct device_node *cpu;
+	u32 prop;
+
+	cpu = of_find_node_by_path("/cpus");
+	if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop)) {
+		pr_err("RISC-V system with no 'timebase-frequency' in DTS\n");
+		return -ENOENT;
+	}
+
+	riscv_timebase = prop;
+
+	of_platform_populate(cpu, NULL, NULL);
+
+	return 0;
+}
arch/riscv/include/asm/csr.h new file +211 -0

211 lines not on this page · raw message

arch/riscv/include/asm/sbi.h new file +153 -0

153 lines not on this page · raw message

arch/riscv/include/asm/timer.h new file +9 -0
new file mode 100644
index 000000000000..1f78ef4c0099
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_RISCV_DELAY_H
+#define _ASM_RISCV_DELAY_H
+
+int timer_init(void);
+extern unsigned long riscv_timebase;
+
+#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/lib/dtb.c +4 -0
index c7fa6b0c31ca..8c2f5b251883 100644
@@ -4,6 +4,7 @@
 #include <init.h>
 #include <of.h>
 #include <asm/barebox-riscv.h>
+#include <asm/timer.h>
 
 static int of_riscv_init(void)
 {
@@ -21,6 +22,9 @@ static int of_riscv_init(void)
 
 	barebox_register_fdt(fdt);
 
+	/* do it now, before clocksource drivers run postcore */
+	timer_init();
+
 	return 0;
 }
 core_initcall(of_riscv_init);
drivers/clocksource/Kconfig +15 -0
index 6dfe6151ac98..2d8f5113ad8d 100644
@@ -99,4 +99,19 @@ config CLOCKSOURCE_TI_DM
 config CLOCKSOURCE_TI_32K
 	bool
 
+config RISCV_TIMER
+	bool "Timer for the RISC-V platform" if COMPILE_TEST
+	depends on RISCV && RISCV_SBI
+	help
+	  This enables the per-hart timer built into all RISC-V systems, which
+	  is accessed via both the SBI and the rdcycle instruction.  This is
+	  required for all RISC-V systems.
+
+config CLINT_TIMER
+	bool "CLINT Timer for the RISC-V platform" if COMPILE_TEST
+	depends on OFDEVICE
+	help
+	  This option enables the CLINT timer for RISC-V systems.  The CLINT
+	  driver is usually used for NoMMU RISC-V systems.
+
 endmenu
drivers/clocksource/Makefile +2 -0
index b4607f787fcf..e3d243eb9423 100644
@@ -21,3 +21,5 @@ obj-$(CONFIG_CLOCKSOURCE_IMX_GPT) += timer-imx-gpt.o
 obj-$(CONFIG_CLOCKSOURCE_DW_APB_TIMER) += dw_apb_timer.o
 obj-$(CONFIG_CLOCKSOURCE_TI_DM) += timer-ti-dm.o
 obj-$(CONFIG_CLOCKSOURCE_TI_32K) += timer-ti-32k.o
+obj-$(CONFIG_CLINT_TIMER) += timer-clint.o
+obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o
drivers/clocksource/timer-clint.c new file +93 -0

93 lines not on this page · raw message

drivers/clocksource/timer-riscv.c new file +50 -0

50 lines not on this page · raw message

Signature · 7 lines
2.29.2


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

PATCH v3 20/21 power: reset: add drivers for generic syscon reset and poweroff

In reply to Ahmad Fatoum

Many SoC reset/poweroff mechanisms can be represented using this generic binding. Of the boards we support, at least the virt machines can be rebooted and powered off by it. Import the Linux v5.11 state of the driver to support this.

---
 arch/riscv/Kconfig                    |  1 +
 arch/riscv/dts/erizo.dtsi             |  2 +-
 drivers/clocksource/Kconfig           |  2 +-
 drivers/clocksource/timer-riscv.c     | 18 +++++-
 drivers/power/reset/Kconfig           | 14 ++++
 drivers/power/reset/Makefile          |  2 +
 drivers/power/reset/syscon-poweroff.c | 76 ++++++++++++++++++++++
 drivers/power/reset/syscon-reboot.c   | 92 +++++++++++++++++++++++++++
 8 files changed, 204 insertions(+), 3 deletions(-)
 create mode 100644 drivers/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
arch/riscv/Kconfig +1 -0
index 50c4d145cf54..6e8bfdef14db 100644
@@ -32,6 +32,7 @@ config MACH_ERIZO
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
 	select RISCV_M_MODE
+	select RISCV_TIMER
 
 endchoice
 
arch/riscv/dts/erizo.dtsi +1 -1
index 07534798ac75..e854a48ae55c 100644
@@ -22,7 +22,7 @@
 
 		cpu@0 {
 			device_type = "cpu";
-			compatible = "cliffordwolf,picorv32";
+			compatible = "cliffordwolf,picorv32", "riscv";
 			clocks = <&ref_clk>;
 			reg = <0>;
 		};
drivers/clocksource/Kconfig +1 -1
index 2d8f5113ad8d..7bc69afd7820 100644
@@ -101,7 +101,7 @@ config CLOCKSOURCE_TI_32K
 
 config RISCV_TIMER
 	bool "Timer for the RISC-V platform" if COMPILE_TEST
-	depends on RISCV && RISCV_SBI
+	depends on RISCV
 	help
 	  This enables the per-hart timer built into all RISC-V systems, which
 	  is accessed via both the SBI and the rdcycle instruction.  This is
drivers/clocksource/timer-riscv.c +17 -1
index 637285fd78a7..eb5ba2d8c226 100644
@@ -13,7 +13,7 @@
 #include <asm/timer.h>
 #include <asm/csr.h>
 
-static u64 notrace riscv_timer_get_count(void)
+static u64 notrace riscv_timer_get_count_sbi(void)
 {
 	__maybe_unused u32 hi, lo;
 
@@ -28,6 +28,22 @@ static u64 notrace riscv_timer_get_count(void)
 	return ((u64)hi << 32) | lo;
 }
 
+static u64 notrace riscv_timer_get_count_rdcycle(void)
+{
+	u64 ticks;
+	asm volatile("rdcycle %0" : "=r" (ticks));
+
+	return ticks;
+}
+
+static u64 notrace riscv_timer_get_count(void)
+{
+	if (IS_ENABLED(CONFIG_RISCV_SBI))
+		return riscv_timer_get_count_sbi();
+	else
+		return riscv_timer_get_count_rdcycle();
+}
+
 static struct clocksource riscv_clocksource = {
 	.read		= riscv_timer_get_count,
 	.mask		= CLOCKSOURCE_MASK(64),
drivers/power/reset/Kconfig +14 -0
index f65e1f67fd59..e60037a6e637 100644
@@ -14,3 +14,17 @@ config SYSCON_REBOOT_MODE
 	  get reboot mode arguments and store it in SYSCON mapped
 	  register, then the bootloader can read it to take different
 	  action according to the mode.
+
+config POWER_RESET_SYSCON
+	bool "Generic SYSCON regmap reset driver"
+	depends on OFDEVICE
+	select MFD_SYSCON
+	help
+	  Reboot support for generic SYSCON mapped register reset.
+
+config POWER_RESET_SYSCON_POWEROFF
+	bool "Generic SYSCON regmap poweroff driver"
+	depends on OFDEVICE
+	select MFD_SYSCON
+	help
+	  Poweroff support for generic SYSCON mapped register poweroff.
drivers/power/reset/Makefile +2 -0
index 56feec78cf26..a490dce87333 100644
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
 obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
+obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o
+obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o
drivers/power/reset/syscon-poweroff.c new file +76 -0

76 lines not on this page · raw message

drivers/power/reset/syscon-reboot.c new file +92 -0

92 lines not on this page · raw message

Signature · 7 lines
2.29.2


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

PATCH 1/1 fixup! clocksource: add driver for RISC-V and CLINT timers

This were wrongly squashed into the commit after.

---
 arch/riscv/Kconfig                |  1 +
 arch/riscv/dts/erizo.dtsi         |  2 +-
 drivers/clocksource/Kconfig       |  2 +-
 drivers/clocksource/timer-riscv.c | 18 +++++++++++++++++-
 4 files changed, 20 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +1 -0
index ce338e3f1f95..c0583f31536b 100644
@@ -32,6 +32,7 @@ config MACH_ERIZO
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
 	select RISCV_M_MODE
+	select RISCV_TIMER
 
 config MACH_VIRT
 	bool "virt family"
arch/riscv/dts/erizo.dtsi +1 -1
index 07534798ac75..e854a48ae55c 100644
@@ -22,7 +22,7 @@ fixed-clock
 
 		cpu@0 {
 			device_type = "cpu";
-			compatible = "cliffordwolf,picorv32";
+			compatible = "cliffordwolf,picorv32", "riscv";
 			clocks = <&ref_clk>;
 			reg = <0>;
 		};
drivers/clocksource/Kconfig +1 -1
index 2d8f5113ad8d..7bc69afd7820 100644
@@ -101,7 +101,7 @@ config CLOCKSOURCE_TI_32K
 
 config RISCV_TIMER
 	bool "Timer for the RISC-V platform" if COMPILE_TEST
-	depends on RISCV && RISCV_SBI
+	depends on RISCV
 	help
 	  This enables the per-hart timer built into all RISC-V systems, which
 	  is accessed via both the SBI and the rdcycle instruction.  This is
drivers/clocksource/timer-riscv.c +17 -1
index 637285fd78a7..eb5ba2d8c226 100644
@@ -13,7 +13,7 @@
 #include <asm/timer.h>
 #include <asm/csr.h>
 
-static u64 notrace riscv_timer_get_count(void)
+static u64 notrace riscv_timer_get_count_sbi(void)
 {
 	__maybe_unused u32 hi, lo;
 
@@ -28,6 +28,22 @@ static u64 notrace riscv_timer_get_count(void)
 	return ((u64)hi << 32) | lo;
 }
 
+static u64 notrace riscv_timer_get_count_rdcycle(void)
+{
+	u64 ticks;
+	asm volatile("rdcycle %0" : "=r" (ticks));
+
+	return ticks;
+}
+
+static u64 notrace riscv_timer_get_count(void)
+{
+	if (IS_ENABLED(CONFIG_RISCV_SBI))
+		return riscv_timer_get_count_sbi();
+	else
+		return riscv_timer_get_count_rdcycle();
+}
+
 static struct clocksource riscv_clocksource = {
 	.read		= riscv_timer_get_count,
 	.mask		= CLOCKSOURCE_MASK(64),
Signature · 7 lines
2.30.0


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

Re: [PATCH] fixup! clocksource: add driver for RISC-V and CLINT timers

Quoted 1 line · Ahmad Fatoum

This were wrongly squashed into the commit after.

And this one was supposed to be a reply to the commit before.. Sascha, let me know if you want me to resend.

Quoted 84 lines
---
 arch/riscv/Kconfig                |  1 +
 arch/riscv/dts/erizo.dtsi         |  2 +-
 drivers/clocksource/Kconfig       |  2 +-
 drivers/clocksource/timer-riscv.c | 18 +++++++++++++++++-
 4 files changed, 20 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +1 -0
index ce338e3f1f95..c0583f31536b 100644
@@ -32,6 +32,7 @@ config MACH_ERIZO
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
 	select RISCV_M_MODE
+	select RISCV_TIMER
 
 config MACH_VIRT
 	bool "virt family"
arch/riscv/dts/erizo.dtsi +1 -1
index 07534798ac75..e854a48ae55c 100644
@@ -22,7 +22,7 @@ fixed-clock
 
 		cpu@0 {
 			device_type = "cpu";
-			compatible = "cliffordwolf,picorv32";
+			compatible = "cliffordwolf,picorv32", "riscv";
 			clocks = <&ref_clk>;
 			reg = <0>;
 		};
drivers/clocksource/Kconfig +1 -1
index 2d8f5113ad8d..7bc69afd7820 100644
@@ -101,7 +101,7 @@ config CLOCKSOURCE_TI_32K
 
 config RISCV_TIMER
 	bool "Timer for the RISC-V platform" if COMPILE_TEST
-	depends on RISCV && RISCV_SBI
+	depends on RISCV
 	help
 	  This enables the per-hart timer built into all RISC-V systems, which
 	  is accessed via both the SBI and the rdcycle instruction.  This is
drivers/clocksource/timer-riscv.c +17 -1
index 637285fd78a7..eb5ba2d8c226 100644
@@ -13,7 +13,7 @@
 #include <asm/timer.h>
 #include <asm/csr.h>
 
-static u64 notrace riscv_timer_get_count(void)
+static u64 notrace riscv_timer_get_count_sbi(void)
 {
 	__maybe_unused u32 hi, lo;
 
@@ -28,6 +28,22 @@ static u64 notrace riscv_timer_get_count(void)
 	return ((u64)hi << 32) | lo;
 }
 
+static u64 notrace riscv_timer_get_count_rdcycle(void)
+{
+	u64 ticks;
+	asm volatile("rdcycle %0" : "=r" (ticks));
+
+	return ticks;
+}
+
+static u64 notrace riscv_timer_get_count(void)
+{
+	if (IS_ENABLED(CONFIG_RISCV_SBI))
+		return riscv_timer_get_count_sbi();
+	else
+		return riscv_timer_get_count_rdcycle();
+}
+
 static struct clocksource riscv_clocksource = {
 	.read		= riscv_timer_get_count,
 	.mask		= CLOCKSOURCE_MASK(64),
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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
#27 lore raw

PATCH v3 21/21 RISC-V: add Qemu virt support

In reply to Ahmad Fatoum

From: Rouven Czerwinski <[email protected]>

The generic dt board added in a previous commit can be booted on RISC-V qemu -M virt. Add defconfigs for both 32- and 64-bit machines.

We could in theory drop the mach directory altogether like it's done on arm64, but for now it's left in as it provides <mach/debug_ll.h>.

It's expected that we can drop it in future in favor of generic earlycon support (which also wouldn't require manual adjustment of the shared entry point like with debug_ll).

---
 Documentation/boards/riscv.rst               |  59 ++++++++++
 arch/riscv/Kconfig                           |   8 ++
 arch/riscv/Makefile                          |   3 +-
 arch/riscv/configs/virt32_defconfig          | 116 ++++++++++++++++++
 arch/riscv/configs/virt64_defconfig          | 117 +++++++++++++++++++
 arch/riscv/mach-virt/Makefile                |   3 +
 arch/riscv/mach-virt/include/mach/debug_ll.h |  25 ++++
 7 files changed, 330 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/configs/virt32_defconfig
 create mode 100644 arch/riscv/configs/virt64_defconfig
 create mode 100644 arch/riscv/mach-virt/Makefile
 create mode 100644 arch/riscv/mach-virt/include/mach/debug_ll.h
Documentation/boards/riscv.rst +59 -0
index a1f7e30531ee..049029b4f23d 100644
@@ -1,6 +1,65 @@
 RISC-V
 ======
 
+QEMU Virt
+---------
+
+barebox supports both the qemu riscv32 and riscv64 ``-M virt`` boards::
+
+  make ARCH=riscv virt64_defconfig
+  qemu-system-riscv64 -M virt -serial stdio -kernel build/images/barebox-dt-2nd.img
+
+Replace ``64`` by ``32`` for 32-bit build. :ref:`virtio` over MMIO is supported and
+can be used for e.g. an extra console or to pass in a virtio-blk device::
+
+  qemu-system-riscv64 -M virt -serial stdio                                \
+  	-kernel ./images/barebox-dt-2nd.img                                \
+  	-device virtio-rng-device                                          \
+  	-drive if=none,file=./images/barebox-dt-2nd.img,format=raw,id=hd0  \
+  	-device virtio-blk-device,drive=hd0                                \
+  	-device virtio-serial-device                                       \
+  	-chardev socket,path=/tmp/foo,server,nowait,id=foo           	   \
+  	-device virtconsole,chardev=foo,name=console.foo
+
+  barebox 2021.02.0 #27 Sun Mar 14 10:08:09 CET 2021
+  
+  
+  Board: riscv-virtio,qemu
+  malloc space: 0x83dff820 -> 0x87bff03f (size 62 MiB)
+  
+  barebox@riscv-virtio,qemu:/ filetype /dev/virtioblk0
+  /dev/virtioblk0: RISC-V Linux image (riscv-linux)
+
+Note that the ``board-dt-2nd.img`` uses the Linux RISC-V kernel image
+format and boot protocol. It thus requires the device tree to be passed
+from outside in ``a1`` and must be loaded at an offset as indicated in
+the header for the initial stack to work. Using the ``-kernel`` option
+in Qemu or booting from bootloaders that can properly boot Linux will
+take care of this.
+
+TinyEMU
+-------
+
+TinyEMU can emulate a qemu-virt like machine with a RISC-V 32-, 64-
+and 128-bit CPU. It can run barebox with this sample configuration::
+
+  /* temu barebox-virt64.cfg */
+  {
+      version: 1,
+      machine: "riscv64",
+      memory_size: 256,
+      bios: "bbl64.bin",
+      kernel: "./images/barebox-dt-2nd.img",
+  }
+
+``barebox-dt-2nd.img`` can be generated like with Qemu. Graphical
+output is also supported, but virtio input support is still missing.
+To activate add::
+
+    display0: { device: "simplefb", width: 800, height: 600 },
+
+into the config file.
+
 Erizo
 -----
 
arch/riscv/Kconfig +8 -0
index 6e8bfdef14db..c0583f31536b 100644
@@ -34,6 +34,14 @@ config MACH_ERIZO
 	select RISCV_M_MODE
 	select RISCV_TIMER
 
+config MACH_VIRT
+	bool "virt family"
+	select BOARD_RISCV_GENERIC_DT
+	select CLINT_TIMER
+	help
+	  Generates an image tht can be be booted by QEMU. The image is called
+	  barebox-dt-2nd.img
+
 endchoice
 
 choice
arch/riscv/Makefile +2 -1
index c0dadead42ad..aba4526bba5a 100644
@@ -1,4 +1,4 @@
-KBUILD_DEFCONFIG := erizo_generic_defconfig
+KBUILD_DEFCONFIG := virt64_defconfig
 
 KBUILD_CPPFLAGS += -fno-strict-aliasing
 
@@ -20,6 +20,7 @@ cflags-y += $(riscv-cflags-y)
 LDFLAGS_barebox += -nostdlib
 
 machine-$(CONFIG_MACH_ERIZO)	:= erizo
+machine-$(CONFIG_MACH_VIRT)	:= virt
 
 LDFLAGS_barebox += $(riscv-ldflags-y)
 
arch/riscv/configs/virt32_defconfig new file +116 -0

116 lines not on this page · raw message

arch/riscv/configs/virt64_defconfig new file +117 -0

117 lines not on this page · raw message

arch/riscv/mach-virt/Makefile new file +3 -0
new file mode 100644
index 000000000000..d9c51e74c379
@@ -0,0 +1,3 @@
+# just to build a built-in.o. Otherwise compilation fails when no o-files is
+# created.
+obj- += dummy.o
arch/riscv/mach-virt/include/mach/debug_ll.h new file +25 -0
new file mode 100644
index 000000000000..056b7a330bdd
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2017 Antony Pavlov <[email protected]>
+ */
+
+#ifndef __MACH_VIRT_DEBUG_LL__
+#define __MACH_VIRT_DEBUG_LL__
+
+/** @file
+ *  This File contains declaration for early output support
+ */
+
+#include <linux/kconfig.h>
+
+#define DEBUG_LL_UART_ADDR	0x10000000
+#define DEBUG_LL_UART_SHIFT	0
+#define DEBUG_LL_UART_IOSIZE8
+
+#define DEBUG_LL_UART_CLK       0x00384000
+#define DEBUG_LL_UART_BPS       CONFIG_BAUDRATE
+#define DEBUG_LL_UART_DIVISOR   (DEBUG_LL_UART_CLK / DEBUG_LL_UART_BPS)
+
+#include <asm/debug_ll_ns16550.h>
+
+#endif /* __MACH_VIRT_DEBUG_LL__ */
Signature · 7 lines
2.29.2


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