Skip to contentSkip to conversation

RISC-V: rework for PBL, VIRT and 64-Bit support

PATCH Superseded Ahmad Fatoum 6 participants 36 messages Mar 14, 2021 – Mar 15, 2021

Subsystems (11)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover RISC-V: rework for PBL, VIRT and 64-Bit support

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.

Cheers,
Ahmad Fatoum (18):
partitions: don't allocate dma capable memory
images: make BOARD_ARM_GENERIC_DT available for other arches
ARM: rename CONFIG_ARM_USE_COMPRESSED_DTB to CONFIG_USE_COMPRESSED_DTB
ARM: aarch64: ommit unused label in assembly
serial: virtio-console: depend on, but don't select VIRTIO
filetype: detect RISC-V Linux kernel image
asm: unaligned: 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
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 CLINT timer
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                             |   9 +-
 arch/arm/cpu/start.c                         |   2 +-
 arch/arm/lib64/runtime-offset.S              |   2 +-
 arch/arm/mach-at91/Kconfig                   |   2 +-
 arch/arm/mach-imx/Kconfig                    |  26 +--
 arch/arm/mach-omap/Kconfig                   |   2 +-
 arch/riscv/Kconfig                           |  66 +++++--
 arch/riscv/Makefile                          |  34 ++--
 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-entry.S         |  26 +++
 arch/riscv/boot/board-dt-2nd.c               |  29 +++
 arch/riscv/boot/dtb.c                        |  25 ---
 arch/riscv/boot/entry.c                      |  33 ++++
 arch/riscv/boot/entry.h                      |  15 ++
 arch/riscv/boot/entry_ll.S                   |  15 ++
 arch/riscv/boot/main_entry.c                 |  35 ----
 arch/riscv/boot/start.S                      |  68 -------
 arch/riscv/boot/start.c                      | 197 +++++++++++++++++++
 arch/riscv/boot/uncompress.c                 |  74 +++++++
 arch/riscv/configs/erizo_generic_defconfig   |   5 -
 arch/riscv/configs/virt32_defconfig          | 117 +++++++++++
 arch/riscv/configs/virt64_defconfig          | 118 +++++++++++
 arch/riscv/dts/Makefile                      |   9 +-
 arch/riscv/include/asm/barebox-riscv.h       | 101 ++++++++++
 arch/riscv/include/asm/common.h              |  10 +-
 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/sections.h            |  15 ++
 arch/riscv/include/asm/string.h              |  21 +-
 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                         |  26 +++
 arch/riscv/lib/memcpy.S                      | 108 ++++++++++
 arch/riscv/lib/memmove.S                     |  64 ++++++
 arch/riscv/lib/memset.S                      | 113 +++++++++++
 arch/riscv/lib/pbl.lds.S                     |  88 +++++++++
 arch/riscv/lib/reloc.c                       |  64 ++++++
 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                            |   3 +
 common/partitions.c                          |   5 +-
 common/partitions/dos.c                      |   7 +-
 common/partitions/efi.c                      |   1 -
 drivers/clocksource/Kconfig                  |   7 +
 drivers/clocksource/Makefile                 |   1 +
 drivers/clocksource/timer-clint.c            |  98 +++++++++
 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/Makefile                              |   8 +-
 images/Makefile.erizo                        |  12 ++
 include/dma.h                                |   1 +
 include/filetype.h                           |   1 +
 pbl/Kconfig                                  |   6 +-
 scripts/.gitignore                           |   1 +
 scripts/Makefile                             |   1 +
 scripts/Makefile.lib                         |  11 ++
 scripts/prelink-riscv.c                      | 122 ++++++++++++
 scripts/prelink-riscv.inc                    | 123 ++++++++++++
 75 files changed, 2285 insertions(+), 263 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-entry.S
 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
 create mode 100644 arch/riscv/boot/entry_ll.S
 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/include/asm/barebox-riscv.h
 create mode 100644 arch/riscv/include/asm/dma.h
 create mode 100644 arch/riscv/include/asm/image.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/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
 create mode 100644 images/Makefile.erizo
 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 1/20 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 2/20 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 3/20 ARM: rename CONFIG_ARM_USE_COMPRESSED_DTB to CONFIG_USE_COMPRESSED_DTB

In reply to Ahmad Fatoum

Other PBL-enabled architecture can benefit from compressed dtbs as well. As the symbol doesn't have a prompt, it's safe to rename all of instances of it to drop the ARM qualifier.

---
 arch/arm/Kconfig           |  7 +------
 arch/arm/cpu/start.c       |  2 +-
 arch/arm/mach-at91/Kconfig |  2 +-
 arch/arm/mach-imx/Kconfig  | 26 +++++++++++++-------------
 arch/arm/mach-omap/Kconfig |  2 +-
 common/Kconfig             |  6 ++++++
 6 files changed, 23 insertions(+), 22 deletions(-)
arch/arm/Kconfig +1 -6
index 3b983c8b3d0a..0e444d17d5af 100644
@@ -17,11 +17,6 @@ config ARM_LINUX
 config HAVE_MACH_ARM_HEAD
 	bool
 
-config ARM_USE_COMPRESSED_DTB
-	bool
-	select UNCOMPRESS
-	select LZO_DECOMPRESS
-
 config TEXT_BASE
 	hex
 	default 0x0
@@ -208,7 +203,7 @@ config ARCH_STM32MP
 	select ARCH_HAS_RESET_CONTROLLER
 	select ARM_AMBA
 	select ARM_SMCCC
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config ARCH_VERSATILE
 	bool "ARM Versatile boards (ARM926EJ-S)"
arch/arm/cpu/start.c +1 -1
index f48f5beea807..5533466e01a7 100644
@@ -75,7 +75,7 @@ void *barebox_arm_boot_dtb(void)
 		return barebox_boarddata;
 	}
 
-	if (!IS_ENABLED(CONFIG_ARM_USE_COMPRESSED_DTB) || !barebox_boarddata
+	if (!IS_ENABLED(CONFIG_USE_COMPRESSED_DTBS) || !barebox_boarddata
 			|| !blob_is_compressed_fdt(barebox_boarddata))
 		return NULL;
 
arch/arm/mach-at91/Kconfig +1 -1
index 52eefc736138..2d13b71ce3a1 100644
@@ -573,7 +573,7 @@ endif
 config AT91_MULTI_BOARDS
 	bool "Allow multiple boards to be selected"
 	select HAVE_PBL_MULTI_IMAGES
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 if AT91_MULTI_BOARDS
 
arch/arm/mach-imx/Kconfig +13 -13
index 3f8012c73211..55931058f6d7 100644
@@ -345,7 +345,7 @@ config MACH_PROTONIC_IMX6
 	bool "Protonic-Holland i.MX6 based boards"
 	select ARCH_IMX6
 	select ARCH_IMX6UL
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_KONTRON_SAMX6I
         bool "Kontron sAMX6i"
@@ -409,18 +409,18 @@ config MACH_TECHNEXION_PICO_HOBBIT
 	bool "Technexion Pico Hobbit"
 	select ARCH_IMX6
 	select ARCH_IMX6UL
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_TECHNEXION_WANDBOARD
 	bool "Technexion Wandboard"
 	select ARCH_IMX6
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 	select MCI_IMX_ESDHC_PBL
 
 config MACH_EMBEST_MARSBOARD
 	bool "Embest MarSboard"
 	select ARCH_IMX6
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_EMBEST_RIOTBOARD
 	bool "Embest RIoTboard"
@@ -454,7 +454,7 @@ config MACH_CM_FX6
 config MACH_ADVANTECH_ROM_742X
 	bool "Advantech ROM 742X"
 	select ARCH_IMX6
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_WARP7
 	bool "NXP i.MX7: element 14 WaRP7 Board"
@@ -464,7 +464,7 @@ config MACH_AC_SXB
 	bool "Atlas Copco: SXB board"
 	select ARCH_IMX7
 	select MCI_IMX_ESDHC_PBL
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_VF610_TWR
 	bool "Freescale VF610 Tower Board"
@@ -479,14 +479,14 @@ config MACH_ZII_RDU1
 	select MACH_FREESCALE_MX51_PDK_POWER
 	select CRC8
 	select MACH_ZII_COMMON
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_ZII_RDU2
 	bool "ZII i.MX6Q(+) RDU2"
 	select ARCH_IMX6
 	select MCI_IMX_ESDHC_PBL
 	select MACH_ZII_COMMON
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_ZII_IMX8MQ_DEV
 	bool "ZII i.MX8MQ based devices"
@@ -496,19 +496,19 @@ config MACH_ZII_IMX8MQ_DEV
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select MACH_ZII_COMMON
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_ZII_VF610_DEV
 	bool "ZII VF610 Dev Family"
 	select ARCH_VF610
 	select CLKDEV_LOOKUP
 	select MACH_ZII_COMMON
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_ZII_IMX7D_DEV
 	bool "ZII i.MX7D based devices"
 	select ARCH_IMX7
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_PHYTEC_PHYCORE_IMX7
 	bool "Phytec phyCORE i.MX7"
@@ -576,12 +576,12 @@ config MACH_DIGI_CCIMX6ULSBCPRO
 	bool "Digi Internal CC-IMX6UL SBC Pro"
 	select ARCH_IMX6
 	select ARCH_IMX6UL
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_WEBASTO_CCBV2
 	bool "Webasto Common Communication Board V2"
 	select ARCH_IMX6UL
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 
 config MACH_MNT_REFORM
 	bool "MNT Reform"
arch/arm/mach-omap/Kconfig +1 -1
index 220b6351679c..3347d277bbb0 100644
@@ -41,7 +41,7 @@ config ARCH_AM33XX
 	select GENERIC_GPIO
 	select OFTREE
 	select CLOCKSOURCE_TI_DM
-	select ARM_USE_COMPRESSED_DTB
+	select USE_COMPRESSED_DTB
 	help
 	  Say Y here if you are using Texas Instrument's AM33xx based platform
 
common/Kconfig +6 -0
index b1f4543e03cd..36207274f07f 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
 
Signature · 7 lines
2.29.2


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

PATCH 4/20 ARM: aarch64: ommit 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 5/20 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 6/20 filetype: detect RISC-V Linux kernel image

In reply to Ahmad Fatoum

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

---
 common/filetype.c  | 3 +++
 include/filetype.h | 1 +
 2 files changed, 4 insertions(+)
common/filetype.c +3 -0
index 539c96b74527..d89a5bcffea5 100644
@@ -61,6 +61,7 @@ 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_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 +304,8 @@ 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 ((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 +1 -0
index 3019dda6ed78..cc97f0a6ba9f 100644
@@ -43,6 +43,7 @@ enum filetype {
 	filetype_kwbimage_v1,
 	filetype_android_sparse,
 	filetype_arm64_linux_image,
+	filetype_riscv_linux_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
#7 lore raw

PATCH 7/20 asm: unaligned: 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
#8 lore raw

PATCH 8/20 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
#9 lore raw

PATCH 9/20 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
#10 lore raw

PATCH 10/20 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
#11 lore raw

PATCH 11/20 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
#12 lore raw

PATCH 12/20 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
#13 lore raw

PATCH 13/20 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.

Cc Masahiro Yamada <[email protected]>

---
Hello Masahiro,

Do you know if Kernel Kbuild has a similiar prelink stage somewhere, i.e. an optional architecture-specific rule that processes the ELF file before continuing normally? I'd like for arch/risc/Makefile to define PRELINK as a command that takes the ELF as an argument and for the Makefiles to have no knowledge about PRELINK's content or architecture, but I don't know how to best go about this.

Thanks

---
 arch/riscv/Makefile                    |   1 +
 arch/riscv/boot/Makefile               |   3 +
 arch/riscv/boot/entry.c                |  33 +++++
 arch/riscv/boot/entry.h                |  15 ++
 arch/riscv/boot/entry_ll.S             |  15 ++
 arch/riscv/boot/start.c                | 197 +++++++++++++++++++++++++
 arch/riscv/boot/uncompress.c           |  74 ++++++++++
 arch/riscv/include/asm/barebox-riscv.h | 101 +++++++++++++
 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               |  83 +++++++++++
 arch/riscv/lib/reloc.c                 |  64 ++++++++
 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 +++++++++++++++
 24 files changed, 969 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/entry_ll.S
 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..954e9b602287
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-y += start.o
+obj-pbl-y += entry.o entry_ll.o uncompress.o
arch/riscv/boot/entry.c new file +33 -0
new file mode 100644
index 000000000000..ec506acfa3b2
@@ -0,0 +1,33 @@
+/* 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 __barebox_riscv_entry(unsigned long membase,
+				      unsigned long memsize,
+				      void *boarddata,
+				      unsigned long sp);
+
+void __noreturn barebox_riscv_entry(unsigned long membase,
+				    unsigned long memsize, void *boarddata)
+{
+	__barebox_riscv_entry(membase, memsize, boarddata,
+			      riscv_mem_stack_top(membase, membase + memsize));
+}
+
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/entry_ll.S new file +15 -0
new file mode 100644
index 000000000000..7011fefad865
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/linkage.h>
+#include <asm/sections.h>
+
+/*
+ * a0: memory base
+ * a1: memory size
+ * a2: board data
+ * a3: new value for SP
+ */
+.section .text.__barebox_riscv_entry
+ENTRY(__barebox_riscv_entry)
+	move	sp, a3
+	j	barebox_pbl_start
+ENDPROC(__barebox_riscv_entry)
arch/riscv/boot/start.c new file +197 -0

197 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 +101 -0

101 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 +83 -0

83 lines not on this page · raw message

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

64 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
#14 lore raw

Re: [PATCH 13/20] RISC-V: implement PBL and relocation support

Quoted 892 lines · 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.

Cc Masahiro Yamada <[email protected]>

---
Hello Masahiro,

Do you know if Kernel Kbuild has a similiar prelink stage somewhere, i.e. an optional architecture-specific rule that processes the ELF file before continuing normally? I'd like for arch/risc/Makefile to define PRELINK as a command that takes the ELF as an argument and for the Makefiles to have no knowledge about PRELINK's content or architecture, but I don't know how to best go about this.

Thanks

---
 arch/riscv/Makefile                    |   1 +
 arch/riscv/boot/Makefile               |   3 +
 arch/riscv/boot/entry.c                |  33 +++++
 arch/riscv/boot/entry.h                |  15 ++
 arch/riscv/boot/entry_ll.S             |  15 ++
 arch/riscv/boot/start.c                | 197 +++++++++++++++++++++++++
 arch/riscv/boot/uncompress.c           |  74 ++++++++++
 arch/riscv/include/asm/barebox-riscv.h | 101 +++++++++++++
 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               |  83 +++++++++++
 arch/riscv/lib/reloc.c                 |  64 ++++++++
 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 +++++++++++++++
 24 files changed, 969 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/entry_ll.S
 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..954e9b602287
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-y += start.o
+obj-pbl-y += entry.o entry_ll.o uncompress.o
arch/riscv/boot/entry.c new file +33 -0
new file mode 100644
index 000000000000..ec506acfa3b2
@@ -0,0 +1,33 @@
+/* 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 __barebox_riscv_entry(unsigned long membase,
+				      unsigned long memsize,
+				      void *boarddata,
+				      unsigned long sp);
+
+void __noreturn barebox_riscv_entry(unsigned long membase,
+				    unsigned long memsize, void *boarddata)
+{
+	__barebox_riscv_entry(membase, memsize, boarddata,
+			      riscv_mem_stack_top(membase, membase + memsize));
+}
+
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/entry_ll.S new file +15 -0
new file mode 100644
index 000000000000..7011fefad865
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/linkage.h>
+#include <asm/sections.h>
+
+/*
+ * a0: memory base
+ * a1: memory size
+ * a2: board data
+ * a3: new value for SP
+ */
+.section .text.__barebox_riscv_entry
+ENTRY(__barebox_riscv_entry)
+	move	sp, a3
+	j	barebox_pbl_start
+ENDPROC(__barebox_riscv_entry)
arch/riscv/boot/start.c new file +197 -0
new file mode 100644
index 000000000000..7fcbafcc0758
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2010 Sascha Hauer <[email protected]>, Pengutronix
+
+#define pr_fmt(fmt) "start.c: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <linux/sizes.h>
+#include <of.h>
+#include <asm/barebox-riscv.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/sections.h>
+#include <asm/unaligned.h>
+#include <linux/kasan.h>
+#include <memory.h>
+#include <uncompress.h>
+#include <malloc.h>
+
+#include <debug_ll.h>
+
+#include "entry.h"
+
+unsigned long riscv_stack_top;
+static unsigned long riscv_barebox_size;
+static unsigned long riscv_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_riscv_boarddata_compressed_dtb *dtb = blob;
+
+	return dtb->magic == BAREBOX_RISCV_BOARDDATA_COMPRESSED_DTB_MAGIC;
+}
+
+void *barebox_riscv_boot_dtb(void)
+{
+	void *dtb;
+	void *data;
+	int ret;
+	struct barebox_riscv_boarddata_compressed_dtb *compressed_dtb;
+	static void *boot_dtb;
+
+	if (boot_dtb)
+		return boot_dtb;
+
+	if (barebox_boarddata && blob_is_fdt(barebox_boarddata)) {
+		pr_debug("%s: using barebox_boarddata\n", __func__);
+		return barebox_boarddata;
+	}
+
+	if (!IS_ENABLED(CONFIG_USE_COMPRESSED_DTB) || !barebox_boarddata
+	    || !blob_is_compressed_fdt(barebox_boarddata))
+		return NULL;
+
+	compressed_dtb = barebox_boarddata;
+
+	pr_debug("%s: using compressed_dtb\n", __func__);
+
+	dtb = malloc(compressed_dtb->datalen_uncompressed);
+	if (!dtb)
+		return NULL;
+
+	data = compressed_dtb + 1;
+
+	ret = uncompress(data, compressed_dtb->datalen, NULL, NULL, dtb, NULL, NULL);
+	if (ret) {
+		pr_err("uncompressing dtb failed\n");
+		free(dtb);
+		return NULL;
+	}
+
+	boot_dtb = dtb;
+
+	return boot_dtb;
+}
+
+static inline unsigned long riscv_mem_boarddata(unsigned long membase,
+						unsigned long endmem,
+						unsigned long size)
+{
+	unsigned long mem;
+
+	mem = riscv_mem_barebox_image(membase, endmem, riscv_barebox_size);
+	mem -= ALIGN(size, 64);
+
+	return mem;
+}
+
+unsigned long riscv_mem_ramoops_get(void)
+{
+	return riscv_mem_ramoops(0, riscv_stack_top);
+}
+EXPORT_SYMBOL_GPL(riscv_mem_ramoops_get);
+
+unsigned long riscv_mem_endmem_get(void)
+{
+	return riscv_endmem;
+}
+EXPORT_SYMBOL_GPL(riscv_mem_endmem_get);
+
+static int barebox_memory_areas_init(void)
+{
+	if(barebox_boarddata)
+		request_sdram_region("board data", (unsigned long)barebox_boarddata,
+				     barebox_boarddata_size);
+
+	return 0;
+}
+device_initcall(barebox_memory_areas_init);
+
+/*
+ * First function in the uncompressed image. We get here from
+ * the pbl. The stack already has been set up by the pbl.
+ */
+__noreturn __no_sanitize_address __section(.text_entry)
+void barebox_non_pbl_start(unsigned long membase, unsigned long memsize, void *boarddata)
+{
+	unsigned long endmem = membase + memsize;
+	unsigned long malloc_start, malloc_end;
+	unsigned long barebox_size = barebox_image_size + MAX_BSS_SIZE;
+	unsigned long barebox_base = riscv_mem_barebox_image(membase, endmem, barebox_size);
+
+	relocate_to_current_adr();
+
+	setup_c();
+
+	barrier();
+
+	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);
+
+	riscv_endmem = endmem;
+	riscv_stack_top = riscv_mem_stack_top(membase, endmem);
+	riscv_barebox_size = barebox_size;
+	malloc_end = barebox_base;
+
+	if (boarddata) {
+		uint32_t totalsize = 0;
+		const char *name;
+
+		if (blob_is_fdt(boarddata)) {
+			totalsize = get_unaligned_be32(boarddata + 4);
+			name = "DTB";
+		} else if (blob_is_compressed_fdt(boarddata)) {
+			struct barebox_riscv_boarddata_compressed_dtb *bd = boarddata;
+			totalsize = bd->datalen + sizeof(*bd);
+			name = "Compressed DTB";
+		}
+
+		if (totalsize) {
+			unsigned long mem = riscv_mem_boarddata(membase, endmem, totalsize);
+			pr_debug("found %s in boarddata, copying to 0x%08lx\n", name, mem);
+			barebox_boarddata = memcpy((void *)mem, boarddata, totalsize);
+			barebox_boarddata_size = totalsize;
+			malloc_end = mem;
+		}
+	}
+
+	/*
+	 * Maximum malloc space is the Kconfig value if given
+	 * or 1GB.
+	 */
+	if (MALLOC_SIZE > 0) {
+		malloc_start = malloc_end - MALLOC_SIZE;
+		if (malloc_start < membase)
+			malloc_start = membase;
+	} else {
+		malloc_start = malloc_end - (malloc_end - membase) / 2;
+		if (malloc_end - malloc_start > SZ_1G)
+			malloc_start = malloc_end - SZ_1G;
+	}
+
+	pr_debug("initializing malloc pool at 0x%08lx (size 0x%08lx)\n",
+			malloc_start, malloc_end - malloc_start);
+
+	mem_malloc_init((void *)malloc_start, (void *)malloc_end - 1);
+
+	pr_debug("starting barebox...\n");
+
+	start_barebox();
+}
+
+void start(unsigned long membase, unsigned long memsize, void *boarddata);
+/*
+ * First function in the uncompressed image. We get here from
+ * the pbl. The stack already has been set up by the pbl.
+ */
+void __no_sanitize_address __section(.text_entry) start(unsigned long membase,
+		unsigned long memsize, void *boarddata)
+{
+	barebox_non_pbl_start(membase, memsize, boarddata);
+}
arch/riscv/boot/uncompress.c new file +74 -0
new file mode 100644
index 000000000000..cf268bece1bf
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2010-2013 Sascha Hauer <[email protected]>, Pengutronix
+// SPDX-FileCopyrightText: 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+
+/* uncompress.c - uncompressor code for self extracing pbl image */
+
+#define pr_fmt(fmt) "uncompress.c: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <linux/sizes.h>
+#include <pbl.h>
+#include <asm/barebox-riscv.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/sections.h>
+#include <asm/unaligned.h>
+
+#include <debug_ll.h>
+
+#include "entry.h"
+
+unsigned long free_mem_ptr;
+unsigned long free_mem_end_ptr;
+
+extern unsigned char input_data[];
+extern unsigned char input_data_end[];
+
+void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
+				  void *fdt)
+{
+	uint32_t pg_len, uncompressed_len;
+	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
+	unsigned long endmem = membase + memsize;
+	unsigned long barebox_base;
+	void *pg_start, *pg_end;
+	unsigned long pc = get_pc();
+
+	pg_start = input_data + get_runtime_offset();
+	pg_end = input_data_end + get_runtime_offset();
+
+	/*
+	 * If we run from inside the memory just relocate the binary
+	 * to the current address. Otherwise it may be a readonly location.
+	 * Copy and relocate to the start of the memory in this case.
+	 */
+	if (pc > membase && pc - membase < memsize)
+		relocate_to_current_adr();
+	else
+		relocate_to_adr(membase);
+
+	pg_len = pg_end - pg_start;
+	uncompressed_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));
+
+	barebox_base = riscv_mem_barebox_image(membase, endmem,
+					       uncompressed_len + MAX_BSS_SIZE);
+
+	setup_c();
+
+	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);
+
+	free_mem_ptr = riscv_mem_early_malloc(membase, endmem);
+	free_mem_end_ptr = riscv_mem_early_malloc_end(membase, endmem);
+
+	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
+			pg_start, pg_len, barebox_base, uncompressed_len);
+
+	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
+
+	barebox = (void *)barebox_base;
+
+	pr_debug("jumping to uncompressed image at 0x%p. dtb=0x%p\n", barebox, fdt);
+
+	barebox(membase, memsize, fdt);
+}
arch/riscv/include/asm/barebox-riscv.h new file +101 -0
new file mode 100644
index 000000000000..05e076c4868b
@@ -0,0 +1,101 @@
+/* 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 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);
+
+struct barebox_riscv_boarddata_compressed_dtb {
+#define BAREBOX_RISCV_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
+	u32 magic;
+	u32 datalen;
+	u32 datalen_uncompressed;
+};
+
+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,
+						    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 a0, ulong a1, ulong a2);	\
+	void __section(.text_head_entry_##name) name (ulong a0, ulong a1, ulong a2)
+
+/*
+ * When using compressed images in conjunction with relocatable images
+ * the PBL code must pick a suitable place where to uncompress the barebox
+ * image. For doing this the PBL code must know the size of the final
+ * image including the BSS segment. The BSS size is unknown to the PBL
+ * code, so define a maximum BSS size here.
+ */
+#define MAX_BSS_SIZE SZ_1M
+
+#define barebox_image_size (__image_end - __image_start)
+
+#endif	/* _BAREBOX_RISCV_H_ */
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 +83 -0
new file mode 100644
index 000000000000..33caab7b1024
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: 2012 Sascha Hauer <[email protected]>, Pengutronix */
+
+#include <linux/sizes.h>
+#include <asm-generic/barebox.lds.h>
+#include <asm-generic/memory_layout.h>
+
+OUTPUT_ARCH(riscv)
+SECTIONS
+{
+	. = 0x0;
+
+	.image_start : { *(.__image_start) }
+
+	. = ALIGN(4);
+	._text : { *(._text) }
+	.text      :
+	{
+		_stext = .;
+		*(.text_head_entry*)
+		__bare_init_start = .;
+		*(.text_bare_init*)
+		__bare_init_end = .;
+		*(.text*)
+	}
+
+	/* Discard unwind if enable in barebox */
+	/DISCARD/ : { *(.ARM.ex*) }
+
+	BAREBOX_BARE_INIT_SIZE
+	BAREBOX_PBL_SIZE
+
+	. = ALIGN(4);
+	.rodata : { *(.rodata*) }
+
+	.barebox_imd : { BAREBOX_IMD }
+
+	_etext = .;			/* End of text and rodata section */
+
+	.data : { *(.data*) }
+
+	__shasum_start = .;
+	.shasum : {
+		KEEP(*(.shasum))
+	}
+	__shasum_end = .;
+
+	/DISCARD/ : { *(.rela.plt*) }
+	.rela.dyn : {
+		__rel_dyn_start = .;
+		*(.rela*)
+		__rel_dyn_end = .;
+	}
+
+	.dynsym : {
+		__dynsym_start = .;
+		*(.dynsym)
+		__dynsym_end = .;
+	}
+
+	pbl_code_size =  .;
+
+	.__bss_start :  { *(.__bss_start) }
+	.bss : { *(.bss*) }
+	.__bss_stop :  { *(.__bss_stop) }
+	_end = .;
+
+	pbl_memory_size =  .;
+
+	. = ALIGN(4);
+	__piggydata_start = .;
+	.piggydata : {
+		*(.piggydata)
+	}
+	__piggydata_end = .;
+
+	.image_end : { KEEP(*(.__image_end)) }
+
+	pbl_image_size =  .;
+
+	_barebox_image_size = __image_end;
+	_barebox_pbl_size = __bss_start;
+}
arch/riscv/lib/reloc.c new file +64 -0
new file mode 100644
index 000000000000..5e26c0be9c1c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+// SPDX-FileCopyrightText: Copyright (c) 2021 Ahmad Fatoum, Pengutronix
+
+#include <common.h>
+#include <linux/linkage.h>
+#include <asm/sections.h>
+#include <asm/barebox-riscv.h>
+#include <debug_ll.h>
+#include <asm-generic/module.h>
+
+#include <elf.h>
+
+#if __riscv_xlen == 64
+#define Elf_Rela			Elf64_Rela
+#define R_RISCV_ABSOLUTE		R_RISCV_64
+#define DYNSYM_ENTRY(dynsym, rela)	dynsym[ELF_R_SYM(rela->r_info) * 3 + 1]
+#elif __riscv_xlen == 32
+#define Elf_Rela			Elf32_Rela
+#define R_RISCV_ABSOLUTE		R_RISCV_32
+#define DYNSYM_ENTRY(dynsym, rela)	dynsym[ELF_R_SYM(rela->r_info) * 4 + 1]
+#else
+#error unknown riscv target
+#endif
+
+#define RISC_R_TYPE(x)	((x) & 0xFF)
+
+void relocate_to_current_adr(void)
+{
+	unsigned long offset;
+	unsigned long *dynsym;
+	void *dstart, *dend;
+	Elf_Rela *rela;
+
+	/* Get offset between linked address and runtime address */
+	offset = get_runtime_offset();
+
+	dstart = __rel_dyn_start + offset;
+	dend = __rel_dyn_end + offset;
+	dynsym = (void *)__dynsym_start + offset;
+
+	for (rela = dstart; (void *)rela < dend; rela++) {
+		unsigned long *fixup;
+
+		fixup = (unsigned long *)(rela->r_offset + offset);
+
+		switch (RISC_R_TYPE(rela->r_info)) {
+		case R_RISCV_RELATIVE:
+			*fixup = rela->r_addend + offset;
+			break;
+		case R_RISCV_ABSOLUTE:
+			*fixup = DYNSYM_ENTRY(dynsym, rela) + rela->r_addend + offset;
+			break;
+		default:
+			putc_ll('>');
+			puthex_ll(rela->r_info);
+			putc_ll(' ');
+			puthex_ll(rela->r_offset);
+			putc_ll(' ');
+			puthex_ll(rela->r_addend);
+			putc_ll('\n');
+			panic("");
+		}
+	}
+}
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 +22 -0
new file mode 100644
index 000000000000..6d824d00f7e0
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: Copyright (c) 2021 Ahmad Fatoum, Pengutronix */
+
+#include <linux/linkage.h>
+#include <asm/sections.h>
+#include <asm/asm.h>
+
+/*
+ * setup_c: clear bss
+ */
+.section .text.setup_c
+ENTRY(setup_c)
+	lla	a0, __bss_start
+	li	a1, 0
+	lla	a2, __bss_stop
+	sub	a2, a2, a0
+	j	__memset
+ENDPROC(setup_c)
+
+/*
+ * void relocate_to_adr(unsigned long targetadr)
+ *

arch/riscv/lib/setupc.S line 32

Quoted 10 lines
arch/riscv/lib/setupc.S new file +10 -0
+ * Copy binary to targetadr, relocate code and continue
+ * executing at new address.
+ */
+.section .text.relocate_to_adr
+ENTRY(relocate_to_adr)
+					/* a0: target address */
+	addi	sp, sp, -SZREG * 2
+	lla	a1, _text		/* a1: source address */
+
+	beq	a0, a1, copied		/* skip if already at new address */

This needs to be moved after spilling ra onto stack. Will fix in v2.

Quoted 324 lines
arch/riscv/lib/setupc.S new file +23 -0
+
+	lla	a2, copied
+	sub	a2, a2, a1
+	add	a2, a2, a0
+	REG_S	a2, (SZREG * 1)(sp)
+
+	/* adjust return address */
+	sub	ra, ra, a1		/* sub address where we are actually running */
+	add	ra, ra, a0		/* add address where we are going to run */
+	REG_S	ra, (SZREG * 2)(sp)
+
+	lla	a2, __bss_start
+	sub	a2, a2, a1		 /* a2: size */
+
+	jal	__memcpy
+
+	REG_L	a0, (SZREG * 1)(sp)
+	jr	a0 			/* jump to relocated address */
+copied:
+	REG_L	ra, (SZREG * 2)(sp)
+	addi	sp, sp, SZREG * 2
+	j	relocate_to_current_adr	/* relocate binary */
+ENDPROC(relocate_to_adr)
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
new file mode 100644
index 000000000000..c185d3981ca1
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Andes Technology
+ * Chih-Mao Chen <[email protected]>
+ *
+ * Statically process runtime relocations on RISC-V ELF images
+ * so that it can be directly executed when loaded at LMA
+ * without fixup. Both RV32 and RV64 are supported.
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <elf.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "compiler.h"
+
+#ifndef EM_RISCV
+#define EM_RISCV 243
+#endif
+
+#ifndef R_RISCV_32
+#define R_RISCV_32 1
+#endif
+
+#ifndef R_RISCV_64
+#define R_RISCV_64 2
+#endif
+
+#ifndef R_RISCV_RELATIVE
+#define R_RISCV_RELATIVE 3
+#endif
+
+const char *argv0;
+
+#define die(fmt, ...) \
+	do { \
+		fprintf(stderr, "%s: " fmt "\n", argv0, ## __VA_ARGS__); \
+		exit(EXIT_FAILURE); \
+	} while (0)
+
+#define PRELINK_BYTEORDER le
+#define PRELINK_INC_BITS 32
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+#define PRELINK_BYTEORDER le
+#define PRELINK_INC_BITS 64
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+#define PRELINK_BYTEORDER be
+#define PRELINK_INC_BITS 32
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+#define PRELINK_BYTEORDER be
+#define PRELINK_INC_BITS 64
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+int main(int argc, const char *const *argv)
+{
+	argv0 = argv[0];
+
+	if (argc < 2) {
+		fprintf(stderr, "Usage: %s <u-boot>\n", argv0);
+		exit(EXIT_FAILURE);
+	}
+
+	int fd = open(argv[1], O_RDWR, 0);
+
+	if (fd < 0)
+		die("Cannot open %s: %s", argv[1], strerror(errno));
+
+	struct stat st;
+
+	if (fstat(fd, &st) < 0)
+		die("Cannot stat %s: %s", argv[1], strerror(errno));
+
+	void *data =
+		mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+	if (data == MAP_FAILED)
+		die("Cannot mmap %s: %s", argv[1], strerror(errno));
+
+	close(fd);
+
+	unsigned char *e_ident = (unsigned char *)data;
+
+	if (memcmp(e_ident, ELFMAG, SELFMAG) != 0)
+		die("Invalid ELF file %s", argv[1]);
+
+	bool is64 = e_ident[EI_CLASS] == ELFCLASS64;
+	bool isbe = e_ident[EI_DATA] == ELFDATA2MSB;
+
+	if (is64) {
+		if (isbe)
+			prelink_be64(data);
+		else
+			prelink_le64(data);
+	} else {
+		if (isbe)
+			prelink_be32(data);
+		else
+			prelink_le32(data);
+	}
+
+	return 0;
+}
scripts/prelink-riscv.inc new file +123 -0
new file mode 100644
index 000000000000..f2b5467f5b3c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Andes Technology
+ * Chih-Mao Chen <[email protected]>
+ *
+ * Statically process runtime relocations on RISC-V ELF images
+ * so that it can be directly executed when loaded at LMA
+ * without fixup. Both RV32 and RV64 are supported.
+ */
+
+#define CONCAT_IMPL(x, y) x##y
+#define CONCAT(x, y) CONCAT_IMPL(x, y)
+#define CONCAT3(x, y, z) CONCAT(CONCAT(x, y), z)
+
+#define prelink_bonn    CONCAT3(prelink_, PRELINK_BYTEORDER, PRELINK_INC_BITS)
+#define uintnn_t        CONCAT3(uint, PRELINK_INC_BITS, _t)
+#define get_offset_bonn CONCAT3(get_offset_, PRELINK_BYTEORDER, PRELINK_INC_BITS)
+#define Elf_Ehdr        CONCAT3(Elf, PRELINK_INC_BITS, _Ehdr)
+#define Elf_Phdr        CONCAT3(Elf, PRELINK_INC_BITS, _Phdr)
+#define Elf_Rela        CONCAT3(Elf, PRELINK_INC_BITS, _Rela)
+#define Elf_Sym         CONCAT3(Elf, PRELINK_INC_BITS, _Sym)
+#define Elf_Dyn         CONCAT3(Elf, PRELINK_INC_BITS, _Dyn)
+#define Elf_Addr        CONCAT3(Elf, PRELINK_INC_BITS, _Addr)
+#define ELF_R_TYPE      CONCAT3(ELF, PRELINK_INC_BITS, _R_TYPE)
+#define ELF_R_SYM       CONCAT3(ELF, PRELINK_INC_BITS, _R_SYM)
+#define target16_to_cpu CONCAT(PRELINK_BYTEORDER, 16_to_cpu)
+#define target32_to_cpu CONCAT(PRELINK_BYTEORDER, 32_to_cpu)
+#define target64_to_cpu CONCAT(PRELINK_BYTEORDER, 64_to_cpu)
+#define targetnn_to_cpu CONCAT3(PRELINK_BYTEORDER, PRELINK_INC_BITS, _to_cpu)
+#define cpu_to_target32 CONCAT3(cpu_to_, PRELINK_BYTEORDER, 32)
+#define cpu_to_target64 CONCAT3(cpu_to_, PRELINK_BYTEORDER, 64)
+
+static void* get_offset_bonn (void* data, Elf_Phdr* phdrs, size_t phnum, Elf_Addr addr)
+{
+	Elf_Phdr *p;
+
+	for (p = phdrs; p < phdrs + phnum; ++p)
+		if (targetnn_to_cpu(p->p_vaddr) <= addr && targetnn_to_cpu(p->p_vaddr) + targetnn_to_cpu(p->p_memsz) > addr)
+			return data + targetnn_to_cpu(p->p_offset) + (addr - targetnn_to_cpu(p->p_vaddr));
+
+	return NULL;
+}
+
+static void prelink_bonn(void *data)
+{
+	Elf_Ehdr *ehdr = data;
+	Elf_Phdr *p;
+	Elf_Dyn *dyn;
+	Elf_Rela *r;
+
+	if (target16_to_cpu(ehdr->e_machine) != EM_RISCV)
+		die("Machine type is not RISC-V");
+
+	Elf_Phdr *phdrs = data + targetnn_to_cpu(ehdr->e_phoff);
+
+	Elf_Dyn *dyns = NULL;
+	for (p = phdrs; p < phdrs + target16_to_cpu(ehdr->e_phnum); ++p) {
+		if (target32_to_cpu(p->p_type) == PT_DYNAMIC) {
+			dyns = data + targetnn_to_cpu(p->p_offset);
+			break;
+		}
+	}
+
+	if (dyns == NULL)
+		die("No dynamic section found");
+
+	Elf_Rela *rela_dyn = NULL;
+	size_t rela_count = 0;
+	Elf_Sym *dynsym = NULL;
+	for (dyn = dyns;; ++dyn) {
+		if (targetnn_to_cpu(dyn->d_tag) == DT_NULL)
+			break;
+		else if (targetnn_to_cpu(dyn->d_tag) == DT_RELA)
+			rela_dyn = get_offset_bonn(data, phdrs, target16_to_cpu(ehdr->e_phnum), + targetnn_to_cpu(dyn->d_un.d_ptr));
+		else if (targetnn_to_cpu(dyn->d_tag) == DT_RELASZ)
+		  rela_count = targetnn_to_cpu(dyn->d_un.d_val) / sizeof(Elf_Rela);
+		else if (targetnn_to_cpu(dyn->d_tag) == DT_SYMTAB)
+			dynsym = get_offset_bonn(data, phdrs, target16_to_cpu(ehdr->e_phnum), + targetnn_to_cpu(dyn->d_un.d_ptr));
+
+	}
+
+	if (rela_dyn == NULL)
+		die("No .rela.dyn found");
+
+	if (dynsym == NULL)
+		die("No .dynsym found");
+
+	for (r = rela_dyn; r < rela_dyn + rela_count; ++r) {
+		void* buf = get_offset_bonn(data, phdrs, target16_to_cpu(ehdr->e_phnum), targetnn_to_cpu(r->r_offset));
+
+		if (buf == NULL)
+			continue;
+
+		if (ELF_R_TYPE(targetnn_to_cpu(r->r_info)) == R_RISCV_RELATIVE)
+			*((uintnn_t*) buf) = r->r_addend;
+		else if (ELF_R_TYPE(targetnn_to_cpu(r->r_info)) == R_RISCV_32)
+			*((uint32_t*) buf) = cpu_to_target32(targetnn_to_cpu(dynsym[ELF_R_SYM(targetnn_to_cpu(r->r_info))].st_value) + targetnn_to_cpu(r->r_addend));
+		else if (ELF_R_TYPE(targetnn_to_cpu(r->r_info)) == R_RISCV_64)
+			*((uint64_t*) buf) = cpu_to_target64(targetnn_to_cpu(dynsym[ELF_R_SYM(targetnn_to_cpu(r->r_info))].st_value) + targetnn_to_cpu(r->r_addend));
+	}
+}
+
+#undef prelink_bonn
+#undef uintnn_t
+#undef get_offset_bonn
+#undef Elf_Ehdr
+#undef Elf_Phdr
+#undef Elf_Rela
+#undef Elf_Sym
+#undef Elf_Dyn
+#undef Elf_Addr
+#undef ELF_R_TYPE
+#undef ELF_R_SYM
+#undef target16_to_cpu
+#undef target32_to_cpu
+#undef target64_to_cpu
+#undef targetnn_to_cpu
+#undef cpu_to_target32
+#undef cpu_to_target64
+
+#undef CONCAT_IMPL
+#undef CONCAT
+#undef CONCAT3
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
#15 lore raw

PATCH 14/20 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.

The board still throws TLSF errors on startup, but that was the case before the rework as well. Tested with qemu as described in the docs.

---
I assume some memory corruption is happening due to the minimal malloc area size? It doesn't happen with dlmalloc. It doesn't happen on riscv virt added later on, so I will likely not pursue this further.

---
 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/lib/Makefile                    |  2 +-
 arch/riscv/lib/barebox.lds.S               | 36 ++++++++----
 arch/riscv/lib/dtb.c                       | 26 +++++++++
 common/Kconfig                             |  4 +-
 images/Makefile                            |  4 ++
 images/Makefile.erizo                      | 12 ++++
 pbl/Kconfig                                |  2 +-
 17 files changed, 107 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.erizo
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..f59e8b39a572 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/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..3a906a4f9f78
@@ -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_debug("using boarddata provided DTB\n");
+
+	if (!fdt) {
+		pr_debug("No DTB found\n");
+		return 0;
+	}
+
+	barebox_register_fdt(fdt);
+
+	return 0;
+}
+core_initcall(of_riscv_init);
common/Kconfig +2 -2
index 36207274f07f..37204fb40a44 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
 
@@ -358,7 +358,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/Makefile +4 -0
index 84492a154d16..8070531c54e3 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.erizo
 
 
 pblb-$(CONFIG_BOARD_GENERIC_DT) += start_dt_2nd
images/Makefile.erizo 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
#16 lore raw

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

On Sun, 14 Mar 2021 13:27:58 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 14 lines
common/Kconfig +1 -1
index 36207274f07f..37204fb40a44 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
 

common/Kconfig config KALLSYMS · line 364

Quoted 8 lines
common/Kconfig +1 -1
@@ -358,7 +358,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

Hmmm. AFAIR MIPS barebox is relocatable. Why CONFIG_RELOCATABLE does not depend on MIPS?

Signature · 7 lines
Best regards,
  Antony Pavlov

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

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

Quoted 21 lines · Antony Pavlov

On Sun, 14 Mar 2021 13:27:58 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 16 lines
common/Kconfig +1 -1
index 36207274f07f..37204fb40a44 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
 
@@ -358,7 +358,7 @@ config KALLSYMS
 	  This is useful to print a nice backtrace when an exception occurs.
 
Quoted 9 lines

common/Kconfig config KALLSYMS · line 364

Quoted 6 lines
common/Kconfig +1 -1
 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

Hmmm. AFAIR MIPS barebox is relocatable. Why CONFIG_RELOCATABLE does not depend on MIPS?

good point, I'll need to test it

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
#18 lore raw

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

Quoted 31 lines · On Mon, 15 Mar 2021 12:45:15 +0100 Oleksij Rempel <[email protected]>…
Quoted 21 lines · Antony Pavlov

On Sun, 14 Mar 2021 13:27:58 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 16 lines
common/Kconfig +1 -1
index 36207274f07f..37204fb40a44 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
 
@@ -358,7 +358,7 @@ config KALLSYMS
 	  This is useful to print a nice backtrace when an exception occurs.
 
Quoted 9 lines

common/Kconfig config KALLSYMS · line 364

Quoted 6 lines
common/Kconfig +1 -1
 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

Hmmm. AFAIR MIPS barebox is relocatable. Why CONFIG_RELOCATABLE does not depend on MIPS?

Quoted 1 line

good point, I'll need to test it

At the first glance the only point to enable CONFIG_RELOCATABLE is to enable FS_PSTORE.

Signature · 7 lines
Best regards,
  Antony Pavlov

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

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

Hello,

Quoted 34 lines · Antony Pavlov
Quoted 31 lines · On Mon, 15 Mar 2021 12:45:15 +0100 Oleksij Rempel <[email protected]>…
Quoted 30 lines · Antony Pavlov

On Sun, 14 Mar 2021 13:27:58 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 14 lines
common/Kconfig +1 -1
index 36207274f07f..37204fb40a44 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
 

common/Kconfig config KALLSYMS · line 364

Quoted 8 lines
common/Kconfig +1 -1
@@ -358,7 +358,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

Hmmm. AFAIR MIPS barebox is relocatable. Why CONFIG_RELOCATABLE does not depend on MIPS?

Quoted 3 lines
Quoted 1 line

good point, I'll need to test it

At the first glance the only point to enable CONFIG_RELOCATABLE is to enable FS_PSTORE.

Without having dug into the MIPS code, the main point of CONFIG_RELOCATABLE is that PBL can check for it to decide where to copy barebox proper to.

This is very relevant if there's no TEXT_BASE that works for all boards that you need to support with your multi-image barebox.

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

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

On Mon, 15 Mar 2021 13:40:10 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 39 lines

Hello,

Quoted 36 lines · Antony Pavlov
Quoted 32 lines · On Mon, 15 Mar 2021 12:45:15 +0100 Oleksij Rempel <[email protected]>…
Quoted 21 lines · Antony Pavlov

On Sun, 14 Mar 2021 13:27:58 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 16 lines
common/Kconfig +1 -1
index 36207274f07f..37204fb40a44 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
 
@@ -358,7 +358,7 @@ config KALLSYMS
 	  This is useful to print a nice backtrace when an exception occurs.
 
Quoted 9 lines

common/Kconfig config KALLSYMS · line 364

Quoted 6 lines
common/Kconfig +1 -1
 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

Hmmm. AFAIR MIPS barebox is relocatable. Why CONFIG_RELOCATABLE does not depend on MIPS?

good point, I'll need to test it

Quoted 7 lines
Quoted 1 line

At the first glance the only point to enable CONFIG_RELOCATABLE is to enable FS_PSTORE.

Without having dug into the MIPS code, the main point of CONFIG_RELOCATABLE is that PBL can check for it to decide where to copy barebox proper to.

This is very relevant if there's no TEXT_BASE that works for all boards that you need to support with your multi-image barebox.

So CONFIG_RELOCATABLE can be very helpful.

At the moment MIPS barebox is always relocatable.
Sometimes it's useful to run barebox from fixed TEXT_BASE (e.g. during gdb debug session), so this fixed TEXT_BASE behaviour can be introduced for CONFIG_RELOCATABLE=n case.

Signature · 7 lines
Best regards,
  Antony Pavlov

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

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

Hi,

Quoted 5 lines · Antony Pavlov
Quoted 3 lines · On Mon, 15 Mar 2021 13:40:10 +0100 Ahmad Fatoum <[email protected]> wrote:

Without having dug into the MIPS code, the main point of CONFIG_RELOCATABLE is that PBL can check for it to decide where to copy barebox proper to.

Quoted 8 lines
Quoted 2 lines

This is very relevant if there's no TEXT_BASE that works for all boards that you need to support with your multi-image barebox.

So CONFIG_RELOCATABLE can be very helpful.

At the moment MIPS barebox is always relocatable.
Sometimes it's useful to run barebox from fixed TEXT_BASE (e.g. during gdb debug session), so this fixed TEXT_BASE behaviour can be introduced for CONFIG_RELOCATABLE=n case.

With the pbl break stuff, you could in theory already flip a config option and have a gdb script that computes your load address from the address of your breakpoint. That would be nice to have as a ready-to-use script.

I recall Oleksij and Michael did something in that regard.

Benefit is that the break is an actual machine code nop when inactive, so binary size/layout shouldn't change, unlike with flipping CONFIG_RELOCATABLE. For RISC-V, I see no good reason to allow CONFIG_RELOCATABLE=n right now.

Cheers,
Ahmad

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
#22 lore raw

Re: MIPS RELOCATABLE: [PATCH 14/20] RISC-V: erizo: migrate to PBL

Am 15.03.21 um 16:46 schrieb Ahmad Fatoum:

Quoted 21 lines

Hi,

Quoted 5 lines · Antony Pavlov
Quoted 3 lines · On Mon, 15 Mar 2021 13:40:10 +0100 Ahmad Fatoum <[email protected]> wrote:

Without having dug into the MIPS code, the main point of CONFIG_RELOCATABLE is that PBL can check for it to decide where to copy barebox proper to.

Quoted 8 lines
Quoted 2 lines

This is very relevant if there's no TEXT_BASE that works for all boards that you need to support with your multi-image barebox.

So CONFIG_RELOCATABLE can be very helpful.

At the moment MIPS barebox is always relocatable.
Sometimes it's useful to run barebox from fixed TEXT_BASE (e.g. during gdb debug session), so this fixed TEXT_BASE behaviour can be introduced for CONFIG_RELOCATABLE=n case.

With the pbl break stuff, you could in theory already flip a config option and have a gdb script that computes your load address from the address of your breakpoint. That would be nice to have as a ready-to-use script.

Quoted 9 lines

I recall Oleksij and Michael did something in that regard.

Benefit is that the break is an actual machine code nop when inactive, so binary size/layout shouldn't change, unlike with flipping CONFIG_RELOCATABLE. For RISC-V, I see no good reason to allow CONFIG_RELOCATABLE=n right now.

Cheers,
Ahmad

If i remember it correctly, this two patches are needed, to make relocatable barebox debugable with openocd and gdb

https://git.pengutronix.de/cgit/barebox/commit/?id=c37cc2d725a496551113f4ebb1d116823eb0dbd1

https://git.pengutronix.de/cgit/barebox/commit/?id=d71573a006a2fc2b83c076c556b88166f4e3dec3

For the MIPS and RISC-V we would need similar helpers.

Regards,
Oleksij

--
Regards,
Oleksij

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

#23 lore raw

PATCH 15/20 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
#24 lore raw

PATCH 16/20 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             | 25 ++++++++++++++++++-------
 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, 34 insertions(+), 17 deletions(-)
arch/riscv/Kconfig +18 -7
index 91e8546f9624..29ac95aa0f4d 100644
@@ -25,6 +25,7 @@ choice
 
 config MACH_ERIZO
 	bool "erizo family"
+	select ARCH_RV32I
 	select HAS_DEBUG_LL
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
@@ -42,23 +43,33 @@ config ARCH_RV32I
 	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 f59e8b39a572..f60239fd253b 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=rv64imafd  -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 33caab7b1024..f1dd9aeabacc 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
#25 lore raw

Re: [PATCH 16/20] RISC-V: add 64-bit support

Hi Ahmad,

arch/riscv/Makefile KBUILD_DEFCONFIG := erizo_generic_defconfig · line 9

Quoted 9 lines · Ahmad Fatoum

From: Rouven Czerwinski <[email protected]> […]
 ifeq ($(CONFIG_ARCH_RV32I),y)

arch/riscv/Makefile +4 -2
-	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=rv64imafd  -mabi=lp64

This should also work with -march=rv64im, we are not using atomics or floating ops anywhere and should not require this until needed.

Quoted 3 lines
arch/riscv/Makefile +1 -0
+	riscv-ldflags-y += -melf64lriscv

 endif

Regards,
Rouven

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

#26 lore raw

PATCH 1/2 fixup! RISC-V: add 64-bit support

In reply to Ahmad Fatoum

The sjlj implementation is actually written so that it works fine on both 32- and 64- bit RISC-V. We can thus select it from CONFIG_RISCV directly.

---
 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
index a53ac4d12031..788bf36cfe42 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
@@ -50,7 +51,6 @@ config ARCH_RV32I
 	select GENERIC_LIB_ASHLDI3
 	select GENERIC_LIB_ASHRDI3
 	select GENERIC_LIB_LSHRDI3
-	select HAS_ARCH_SJLJ
 	select 32BIT
 
 config ARCH_RV64I
Signature · 7 lines
2.30.0


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

PATCH 2/2 fixup! RISC-V: add 64-bit support

We don't yet require support for float and atomic ops, so remove their letter.

---
 arch/riscv/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Makefile +1 -1
index 133e43af41bf..6df7d9d9eeac 100644
@@ -6,7 +6,7 @@ ifeq ($(CONFIG_ARCH_RV32I),y)
 	riscv-cflags-y += -march=rv32im -mabi=ilp32
 	riscv-ldflags-y += -melf32lriscv
 else
-	riscv-cflags-y += -march=rv64imafd  -mabi=lp64
+	riscv-cflags-y += -march=rv64im  -mabi=lp64
 	riscv-ldflags-y += -melf64lriscv
 endif
 
Signature · 7 lines
2.30.0


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

Re: [PATCH 2/2] fixup! RISC-V: add 64-bit support

On Sun, 14 Mar 2021 14:03:01 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

Quoted 14 lines

We don't yet require support for float and atomic ops, so remove their letter.

---
 arch/riscv/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Makefile +0 -0
index 133e43af41bf..6df7d9d9eeac 100644

arch/riscv/Makefile ifeq ($(CONFIG_ARCH_RV32I),y) · line 9

Quoted 5 lines
arch/riscv/Makefile +1 -1
@@ -6,7 +6,7 @@ ifeq ($(CONFIG_ARCH_RV32I),y)
 	riscv-cflags-y += -march=rv32im -mabi=ilp32
 	riscv-ldflags-y += -melf32lriscv
 else
-	riscv-cflags-y += -march=rv64imafd  -mabi=lp64
+	riscv-cflags-y += -march=rv64im  -mabi=lp64
                                      ^^^^^

Can you drop extra whitespace here, please?

Quoted 11 lines
arch/riscv/Makefile +0 -0
 	riscv-ldflags-y += -melf64lriscv
 endif
 
Signature · 7 lines
2.30.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 7 lines
Best regards,
  Antony Pavlov

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

PATCH 17/20 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-entry.S | 26 +++++++++++
 arch/riscv/boot/board-dt-2nd.c       | 29 +++++++++++++
 arch/riscv/include/asm/image.h       | 65 ++++++++++++++++++++++++++++
 5 files changed, 130 insertions(+)
 create mode 100644 arch/riscv/boot/board-dt-2nd-entry.S
 create mode 100644 arch/riscv/boot/board-dt-2nd.c
 create mode 100644 arch/riscv/include/asm/image.h
arch/riscv/Kconfig +9 -0
index 29ac95aa0f4d..7a47bd90135a 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 954e9b602287..d32322875979 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-y += start.o
 obj-pbl-y += entry.o entry_ll.o uncompress.o
+pbl-$(CONFIG_BOARD_GENERIC_DT) += board-dt-2nd.o board-dt-2nd-entry.o
arch/riscv/boot/board-dt-2nd-entry.S new file +26 -0
new file mode 100644
index 000000000000..520c40589356
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: Copyright (c) 2021 Ahmad Fatoum, Pengutronix */
+#include <linux/linkage.h>
+#include <asm/image.h>
+
+.section .text_head_entry_start_dt_2nd
+ENTRY(start_dt_2nd)
+	auipc sp, 0                /* code0 */
+	j dt_2nd_riscv
+	.balign 8
+#if __riscv_xlen == 64
+	.dword 0x200000            /* Image load offset(2MB) from start of RAM */
+#else
+	.dword 0x400000            /* Image load offset(4MB) from start of RAM */
+#endif
+	.dword _barebox_image_size /* Effective Image size */
+	.dword 0                   /* Kernel flags */
+	.word RISCV_HEADER_VERSION /* version */
+	.word 0                    /* reserved */
+	.dword 0                   /* reserved */
+	.ascii RISCV_IMAGE_MAGIC   /* magic1 */
+	.balign 4
+	.ascii RISCV_IMAGE_MAGIC2  /* magic2 */
+	.word   0                  /* reserved (PE-COFF offset) */
+	.asciz "barebox"           /* unused for now */
+END(start_dt_2nd)
arch/riscv/boot/board-dt-2nd.c new file +29 -0
new file mode 100644
index 000000000000..8eaddd80b1f3
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <common.h>
+#include <asm/barebox-riscv.h>
+#include <debug_ll.h>
+#include <pbl.h>
+
+static noinline void dt_2nd_continue(void *fdt)
+{
+	unsigned long membase, memsize;
+
+	if (!fdt)
+		hang();
+
+	fdt_find_mem(fdt, &membase, &memsize);
+
+	barebox_riscv_entry(membase, memsize, fdt);
+}
+
+/* called from assembly */
+void dt_2nd_riscv(unsigned long a0, void *fdt);
+
+void dt_2nd_riscv(unsigned long a0, void *fdt)
+{
+	relocate_to_current_adr();
+	setup_c();
+
+	dt_2nd_continue(fdt);
+}
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
#30 lore raw

PATCH 18/20 clocksource: add driver for RISC-V CLINT timer

In reply to Ahmad Fatoum

Linux selects this on nommu RISC-V machines. It's also used on the Virt machine added in a follow-up commit.

---
 drivers/clocksource/Kconfig       |  7 +++
 drivers/clocksource/Makefile      |  1 +
 drivers/clocksource/timer-clint.c | 98 +++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/clocksource/timer-clint.c
drivers/clocksource/Kconfig +7 -0
index 6dfe6151ac98..7f829490e108 100644
@@ -99,4 +99,11 @@ config CLOCKSOURCE_TI_DM
 config CLOCKSOURCE_TI_32K
 	bool
 
+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 +1 -0
index b4607f787fcf..268ce16800a7 100644
@@ -21,3 +21,4 @@ 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
drivers/clocksource/timer-clint.c new file +98 -0

98 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
#31 lore raw

PATCH 19/20 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.

---
 drivers/power/reset/Kconfig           | 14 ++++
 drivers/power/reset/Makefile          |  2 +
 drivers/power/reset/syscon-poweroff.c | 76 ++++++++++++++++++++++
 drivers/power/reset/syscon-reboot.c   | 92 +++++++++++++++++++++++++++
 4 files changed, 184 insertions(+)
 create mode 100644 drivers/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
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
#32 lore raw

PATCH 20/20 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          | 117 ++++++++++++++++++
 arch/riscv/configs/virt64_defconfig          | 118 +++++++++++++++++++
 arch/riscv/mach-virt/Makefile                |   3 +
 arch/riscv/mach-virt/include/mach/debug_ll.h |  25 ++++
 7 files changed, 332 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 7a47bd90135a..a53ac4d12031 100644
@@ -30,6 +30,14 @@ config MACH_ERIZO
 	select HAS_NMON
 	select USE_COMPRESSED_DTB
 
+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 f60239fd253b..133e43af41bf 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 +117 -0

117 lines not on this page · raw message

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

118 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
#33 lore raw

PATCH 1/1 fixup! RISC-V: add Qemu virt support

Activate first console in order to support machines where the virtio console is the only console as there is no way there to specify what the default console should be.

---
 arch/riscv/configs/virt32_defconfig | 1 -
 arch/riscv/configs/virt64_defconfig | 1 -
 2 files changed, 2 deletions(-)
arch/riscv/configs/virt32_defconfig +0 -1
index 2c6ecd7005c4..83e3ca1bade8 100644
@@ -11,7 +11,6 @@ CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
 CONFIG_IMD_TARGET=y
-CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_PBL_CONSOLE=y
 CONFIG_PARTITION_DISK_EFI=y
arch/riscv/configs/virt64_defconfig +0 -1
index adfa6c3613b8..17ce16637d96 100644
@@ -12,7 +12,6 @@ CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
 CONFIG_IMD_TARGET=y
-CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_PBL_CONSOLE=y
 CONFIG_PARTITION_DISK_EFI=y
Signature · 7 lines
2.30.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#34 lore raw
In reply to Ahmad Fatoum

On Sun, 14 Mar 2021 13:27:44 +0100
Ahmad Fatoum <[email protected]> wrote:

Hi!

I'm very glad to see RISC-V support improvement!

Can you please push your RISC-V working branch to github (or other public git repo), so I can test it too?

At the moment I have at least two out-of tree RISC-V branches that which I want to rebase on latest barebox with your patches:

* https://github.com/frantony/barebox/tree/20200222.riscv-sifive
contains hacky 64-bit support and add Sifive U500 qemu support.

* https://github.com/litex-hub/barebox/tree/20200727.litex-vexriscv-linux
contains litex SoC with RISC-V 32-bit CPU core support.
It can run linux on Arty, please see
https://github.com/enjoy-digital/litex/issues/413#issuecomment-609047340

It seems, that ethernet driver needs update: https://github.com/litex-hub/barebox/issues/1

I suppose that you can add 'bootm: add RISC-V image type' patch to your series (I'll send you the patch in a few minutes). The patch used in the litex series.

Quoted 146 lines

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.

Cheers,
Ahmad Fatoum (18):
partitions: don't allocate dma capable memory
images: make BOARD_ARM_GENERIC_DT available for other arches
ARM: rename CONFIG_ARM_USE_COMPRESSED_DTB to CONFIG_USE_COMPRESSED_DTB
ARM: aarch64: ommit unused label in assembly
serial: virtio-console: depend on, but don't select VIRTIO
filetype: detect RISC-V Linux kernel image
asm: unaligned: 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
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 CLINT timer
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                             |   9 +-
 arch/arm/cpu/start.c                         |   2 +-
 arch/arm/lib64/runtime-offset.S              |   2 +-
 arch/arm/mach-at91/Kconfig                   |   2 +-
 arch/arm/mach-imx/Kconfig                    |  26 +--
 arch/arm/mach-omap/Kconfig                   |   2 +-
 arch/riscv/Kconfig                           |  66 +++++--
 arch/riscv/Makefile                          |  34 ++--
 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-entry.S         |  26 +++
 arch/riscv/boot/board-dt-2nd.c               |  29 +++
 arch/riscv/boot/dtb.c                        |  25 ---
 arch/riscv/boot/entry.c                      |  33 ++++
 arch/riscv/boot/entry.h                      |  15 ++
 arch/riscv/boot/entry_ll.S                   |  15 ++
 arch/riscv/boot/main_entry.c                 |  35 ----
 arch/riscv/boot/start.S                      |  68 -------
 arch/riscv/boot/start.c                      | 197 +++++++++++++++++++
 arch/riscv/boot/uncompress.c                 |  74 +++++++
 arch/riscv/configs/erizo_generic_defconfig   |   5 -
 arch/riscv/configs/virt32_defconfig          | 117 +++++++++++
 arch/riscv/configs/virt64_defconfig          | 118 +++++++++++
 arch/riscv/dts/Makefile                      |   9 +-
 arch/riscv/include/asm/barebox-riscv.h       | 101 ++++++++++
 arch/riscv/include/asm/common.h              |  10 +-
 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/sections.h            |  15 ++
 arch/riscv/include/asm/string.h              |  21 +-
 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                         |  26 +++
 arch/riscv/lib/memcpy.S                      | 108 ++++++++++
 arch/riscv/lib/memmove.S                     |  64 ++++++
 arch/riscv/lib/memset.S                      | 113 +++++++++++
 arch/riscv/lib/pbl.lds.S                     |  88 +++++++++
 arch/riscv/lib/reloc.c                       |  64 ++++++
 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                            |   3 +
 common/partitions.c                          |   5 +-
 common/partitions/dos.c                      |   7 +-
 common/partitions/efi.c                      |   1 -
 drivers/clocksource/Kconfig                  |   7 +
 drivers/clocksource/Makefile                 |   1 +
 drivers/clocksource/timer-clint.c            |  98 +++++++++
 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/Makefile                              |   8 +-
 images/Makefile.erizo                        |  12 ++
 include/dma.h                                |   1 +
 include/filetype.h                           |   1 +
 pbl/Kconfig                                  |   6 +-
 scripts/.gitignore                           |   1 +
 scripts/Makefile                             |   1 +
 scripts/Makefile.lib                         |  11 ++
 scripts/prelink-riscv.c                      | 122 ++++++++++++
 scripts/prelink-riscv.inc                    | 123 ++++++++++++
 75 files changed, 2285 insertions(+), 263 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-entry.S
 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
 create mode 100644 arch/riscv/boot/entry_ll.S
 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/include/asm/barebox-riscv.h
 create mode 100644 arch/riscv/include/asm/dma.h
 create mode 100644 arch/riscv/include/asm/image.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/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
 create mode 100644 images/Makefile.erizo
 create mode 100644 scripts/prelink-riscv.c
 create mode 100644 scripts/prelink-riscv.inc
Signature · 1 line
2.29.2
Signature · 7 lines
Best regards,
  Antony Pavlov

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

Hello Antony,

Quoted 3 lines · Antony Pavlov

On Sun, 14 Mar 2021 13:27:44 +0100
Ahmad Fatoum <[email protected]> wrote:
I'm very glad to see RISC-V support improvement!

Your erizo barebox/qemu work made the initial iterations much quicker, so thanks for that!

Quoted 2 lines

Can you please push your RISC-V working branch to github (or other public git repo), so I can test it too?

Sure. I'll send out a v2 and send you a github link later today or early tomorrow.

Quoted 5 lines

At the moment I have at least two out-of tree RISC-V branches that which I want to rebase on latest barebox with your patches:

* https://github.com/frantony/barebox/tree/20200222.riscv-sifive
contains hacky 64-bit support and add Sifive U500 qemu support.

This is becoming relevant for us as well as we'' port barebox to the BeagleV. Our intention is to get the other Qemu platforms running as well in preparation for actual hardware support.

Quoted 7 lines

* https://github.com/litex-hub/barebox/tree/20200727.litex-vexriscv-linux
contains litex SoC with RISC-V 32-bit CPU core support.
It can run linux on Arty, please see
https://github.com/enjoy-digital/litex/issues/413#issuecomment-609047340

It seems, that ethernet driver needs update: https://github.com/litex-hub/barebox/issues/1

Thanks for the heads up. I will take a look at your rebased branches, once they are available.

Quoted 2 lines

I suppose that you can add 'bootm: add RISC-V image type' patch to your series (I'll send you the patch in a few minutes). The patch used in the litex series.

Sascha just picked it up.

Cheers,
Ahmad

Quoted 150 lines
Quoted 148 lines

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.

Cheers,
Ahmad Fatoum (18):
partitions: don't allocate dma capable memory
images: make BOARD_ARM_GENERIC_DT available for other arches
ARM: rename CONFIG_ARM_USE_COMPRESSED_DTB to CONFIG_USE_COMPRESSED_DTB
ARM: aarch64: ommit unused label in assembly
serial: virtio-console: depend on, but don't select VIRTIO
filetype: detect RISC-V Linux kernel image
asm: unaligned: 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
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 CLINT timer
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                             |   9 +-
 arch/arm/cpu/start.c                         |   2 +-
 arch/arm/lib64/runtime-offset.S              |   2 +-
 arch/arm/mach-at91/Kconfig                   |   2 +-
 arch/arm/mach-imx/Kconfig                    |  26 +--
 arch/arm/mach-omap/Kconfig                   |   2 +-
 arch/riscv/Kconfig                           |  66 +++++--
 arch/riscv/Makefile                          |  34 ++--
 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-entry.S         |  26 +++
 arch/riscv/boot/board-dt-2nd.c               |  29 +++
 arch/riscv/boot/dtb.c                        |  25 ---
 arch/riscv/boot/entry.c                      |  33 ++++
 arch/riscv/boot/entry.h                      |  15 ++
 arch/riscv/boot/entry_ll.S                   |  15 ++
 arch/riscv/boot/main_entry.c                 |  35 ----
 arch/riscv/boot/start.S                      |  68 -------
 arch/riscv/boot/start.c                      | 197 +++++++++++++++++++
 arch/riscv/boot/uncompress.c                 |  74 +++++++
 arch/riscv/configs/erizo_generic_defconfig   |   5 -
 arch/riscv/configs/virt32_defconfig          | 117 +++++++++++
 arch/riscv/configs/virt64_defconfig          | 118 +++++++++++
 arch/riscv/dts/Makefile                      |   9 +-
 arch/riscv/include/asm/barebox-riscv.h       | 101 ++++++++++
 arch/riscv/include/asm/common.h              |  10 +-
 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/sections.h            |  15 ++
 arch/riscv/include/asm/string.h              |  21 +-
 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                         |  26 +++
 arch/riscv/lib/memcpy.S                      | 108 ++++++++++
 arch/riscv/lib/memmove.S                     |  64 ++++++
 arch/riscv/lib/memset.S                      | 113 +++++++++++
 arch/riscv/lib/pbl.lds.S                     |  88 +++++++++
 arch/riscv/lib/reloc.c                       |  64 ++++++
 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                            |   3 +
 common/partitions.c                          |   5 +-
 common/partitions/dos.c                      |   7 +-
 common/partitions/efi.c                      |   1 -
 drivers/clocksource/Kconfig                  |   7 +
 drivers/clocksource/Makefile                 |   1 +
 drivers/clocksource/timer-clint.c            |  98 +++++++++
 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/Makefile                              |   8 +-
 images/Makefile.erizo                        |  12 ++
 include/dma.h                                |   1 +
 include/filetype.h                           |   1 +
 pbl/Kconfig                                  |   6 +-
 scripts/.gitignore                           |   1 +
 scripts/Makefile                             |   1 +
 scripts/Makefile.lib                         |  11 ++
 scripts/prelink-riscv.c                      | 122 ++++++++++++
 scripts/prelink-riscv.inc                    | 123 ++++++++++++
 75 files changed, 2285 insertions(+), 263 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-entry.S
 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
 create mode 100644 arch/riscv/boot/entry_ll.S
 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/include/asm/barebox-riscv.h
 create mode 100644 arch/riscv/include/asm/dma.h
 create mode 100644 arch/riscv/include/asm/image.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/power/reset/syscon-poweroff.c
 create mode 100644 drivers/power/reset/syscon-reboot.c
 create mode 100644 images/Makefile.erizo
 create mode 100644 scripts/prelink-riscv.c
 create mode 100644 scripts/prelink-riscv.inc
Signature · 1 line
2.29.2
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