Skip to contentSkip to conversation

Add support for CONFIG_API on RISC-V

PATCH New mhorne at FreeBSD.org 6 participants 22 messages Apr 20, 2020 – Jun 22, 2020 RISC-V

lore
Share & tools
lore
#0 lore raw

cover Add support for CONFIG_API on RISC-V

From: Mitchell Horne <[email protected]>

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Mitchell Horne (7):
examples: generate demo.bin
examples: rename __start to _start on MIPS
examples: add a linker script for the API demo
examples: fix the type of search_hint
examples: fix incompatible type casts
riscv: add CONFIG_API support
api: enumerate virtio-blk devices

 api/Makefile             |  1 +
 api/api_platform-riscv.c | 33 +++++++++++++++++++++++++++++++++
 api/api_storage.c        | 14 +++++++++++++-
 examples/api/Makefile    | 10 +++++++---
 examples/api/crt0.S      | 25 +++++++++++++++++++++----
 examples/api/demo.c      | 21 +++++++++++----------
 examples/api/demo.lds    | 14 ++++++++++++++
 examples/api/glue.c      |  6 +++---
 examples/api/glue.h      |  2 +-
 include/api_public.h     |  1 +
 10 files changed, 105 insertions(+), 22 deletions(-)
 create mode 100644 api/api_platform-riscv.c
 create mode 100644 examples/api/demo.lds
Signature · 1 line
2.26.1
#1 lore raw

PATCH 1/7 examples: generate demo.bin

From: Mitchell Horne <[email protected]>

The CONFIG_API option builds the example program, examples/api/demo, as an ELF file. The make logic exists to create a binary as well, so add the target to do so.

---
 examples/api/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
examples/api/Makefile +1 -2
index ca4eb1f71a..9ff793206f 100644
@@ -20,7 +20,7 @@ endif
 endif
 
 # Resulting ELF and binary exectuables will be named demo and demo.bin
-extra-y = demo
+extra-y = demo demo.bin
 
 # Source files located in the examples/api directory
 OBJ-y += crt0.o
@@ -56,7 +56,6 @@ cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -o $@ $(filter-out $(PHO
 $(obj)/demo: $(OBJS) FORCE
 	$(call if_changed,link_demo)
 
-# demo.bin is never genrated. Is this necessary?
 OBJCOPYFLAGS_demo.bin := -O binary
 $(obj)/demo.bin: $(obj)/demo FORCE
 	$(call if_changed,objcopy)
Signature · 1 line
2.26.1
#2 lore raw

PATCH 1/7 examples: generate demo.bin

Quoted 12 lines · On Tue, Apr 21, 2020 at 7:27 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

The CONFIG_API option builds the example program, examples/api/demo, as an ELF file. The make logic exists to create a binary as well, so add the target to do so.

---
 examples/api/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#3 lore raw

PATCH 2/7 examples: rename __start to _start on MIPS

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

On MIPS, __start marks the entry point to the CONFIG_API demo program. Change the name to _start, to be consistent with all other architectures.

---
 examples/api/crt0.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
examples/api/crt0.S +4 -4
index 57bba9d851..2f75f5a036 100644
@@ -42,12 +42,12 @@ syscall:
 #elif defined(CONFIG_MIPS)
 #include <asm/asm.h>
 	.text
-	.globl __start
-	.ent __start
-__start:
+	.globl _start
+	.ent _start
+_start:
 	PTR_S	$sp, search_hint
 	b	main
-	.end __start
+	.end _start
 
 	.globl syscall
 	.ent syscall
Signature · 1 line
2.26.1
#4 lore raw

PATCH 2/7 examples: rename __start to _start on MIPS

Quoted 12 lines · On Tue, Apr 21, 2020 at 7:28 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

On MIPS, __start marks the entry point to the CONFIG_API demo program. Change the name to _start, to be consistent with all other architectures.

---
 examples/api/crt0.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
#5 lore raw

PATCH 2/7 examples: rename __start to _start on MIPS

In reply to mhorne at FreeBSD.org

+cc Wolfgang, Tom

Am 21.04.20 um 00:34 schrieb mhorne at FreeBSD.org:

Quoted 23 lines

From: Mitchell Horne <[email protected]>

On MIPS, __start marks the entry point to the CONFIG_API demo program. Change the name to _start, to be consistent with all other architectures.

---
 examples/api/crt0.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
examples/api/crt0.S +0 -3
index 57bba9d851..2f75f5a036 100644
@@ -42,12 +42,12 @@ syscall:
 #elif defined(CONFIG_MIPS)
 #include <asm/asm.h>
 	.text
-	.globl __start
-	.ent __start
-__start:

examples/api/crt0.S syscall: · line 53

Quoted 10 lines
examples/api/crt0.S +4 -1
+	.globl _start
+	.ent _start
+_start:
 	PTR_S	$sp, search_hint
 	b	main
-	.end __start
+	.end _start
 
 	.globl syscall
 	.ent syscall

__start is used by the default binutils linker script for MIPS. For a test you could simply do a "make malta_defconfig", enable CONFIG_API via menuconfig and build. Without this patch you'll get:

$ /opt/gcc-9.2.0-nolibc/mips-linux/bin/mips-linux-readelf -s
examples/api/demo | grep __start
    64: 80200700    16 FUNC    GLOBAL DEFAULT    1 __start

But with this patch __start will now an unresolved symbol:

$ /opt/gcc-9.2.0-nolibc/mips-linux/bin/mips-linux-readelf -s
examples/api/demo | grep __start
    19: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __start

But I'm not sure if the original intention was to use the default linker script or the one provided by U-Boot and if examples/api/ should use the same compiler and linker flags as example/standalone/. Some archs have used a custom linker script. Maybe Wolfgang knows more?

Signature · 1 line
- Daniel
#6 lore raw

PATCH 2/7 examples: rename __start to _start on MIPS

Dear Daniel,

Quoted 5 lines · In message <[email protected]> you wrote:

But I'm not sure if the original intention was to use the default linker script or the one provided by U-Boot and if examples/api/ should use the same compiler and linker flags as example/standalone/. Some archs have used a custom linker script. Maybe Wolfgang knows more?

Sorry, I can't remember resp. I think I never knew.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Quantum particles: The dreams that stuff is made of.
#7 lore raw

PATCH 3/7 examples: add a linker script for the API demo

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

When compiling the API demo program, the first object file in the linker arguments is crt0.o, which contains the _start routine. This is done with the hope that it will appear first in the .text section, but the linker doesn't guarantee this behaviour.

Add a simple linker script that ensures this ordering. This fixes execution of the API demo binary for cases where _start was placed elsewhere in the .text section.

---
 examples/api/Makefile |  4 +++-
 examples/api/crt0.S   |  2 ++
 examples/api/demo.lds | 14 ++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 examples/api/demo.lds
examples/api/Makefile +3 -1
index 9ff793206f..8fa9c04118 100644
@@ -48,10 +48,12 @@ OBJS := $(OBJ-y) $(notdir $(EXT_COBJ-y) $(EXT_SOBJ-y))
 targets += $(OBJS)
 OBJS := $(addprefix $(obj)/,$(OBJS))
 
+LDS = $(obj)/demo.lds
 #########################################################################
 
 quiet_cmd_link_demo = LD      $@
-cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS)
+cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -T $(LDS) \
+	-o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS)
 
 $(obj)/demo: $(OBJS) FORCE
 	$(call if_changed,link_demo)
examples/api/crt0.S +2 -0
index 2f75f5a036..658bc59a82 100644
@@ -62,12 +62,14 @@ syscall:
 	.end syscall
 
 return_addr:
+	.data
 	.align 8
 	.long 0
 #else
 #error No support for this arch!
 #endif
 
+	.data
 	.globl syscall_ptr
 syscall_ptr:
 	.align	8
examples/api/demo.lds new file +14 -0
new file mode 100644
index 0000000000..a6b88dedef
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Mitchell Horne <[email protected]>
+ */
+
+ENTRY(_start)
+SECTIONS
+{
+    .text :
+    {
+        *crt0.S(.text*)
+        *(.text*)
+    }
+}
Signature · 1 line
2.26.1
#8 lore raw

PATCH 3/7 examples: add a linker script for the API demo

Quoted 43 lines · On Tue, Apr 21, 2020 at 7:28 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

When compiling the API demo program, the first object file in the linker arguments is crt0.o, which contains the _start routine. This is done with the hope that it will appear first in the .text section, but the linker doesn't guarantee this behaviour.

Add a simple linker script that ensures this ordering. This fixes execution of the API demo binary for cases where _start was placed elsewhere in the .text section.

---
 examples/api/Makefile |  4 +++-
 examples/api/crt0.S   |  2 ++
 examples/api/demo.lds | 14 ++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 examples/api/demo.lds
examples/api/Makefile +3 -1
index 9ff793206f..8fa9c04118 100644
@@ -48,10 +48,12 @@ OBJS := $(OBJ-y) $(notdir $(EXT_COBJ-y) $(EXT_SOBJ-y))
 targets += $(OBJS)
 OBJS := $(addprefix $(obj)/,$(OBJS))
 
+LDS = $(obj)/demo.lds
 #########################################################################
 
 quiet_cmd_link_demo = LD      $@
-cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS)
+cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -T $(LDS) \
+       -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS)
 
 $(obj)/demo: $(OBJS) FORCE
        $(call if_changed,link_demo)
examples/api/crt0.S +0 -0
index 2f75f5a036..658bc59a82 100644

examples/api/crt0.S syscall: · line 65

Quoted 4 lines
examples/api/crt0.S +1 -0
@@ -62,12 +62,14 @@ syscall:
        .end syscall
 
 return_addr:
+       .data

I think we need put .data before return_addr: to make it clearer.

examples/api/crt0.S syscall: · line 72

Quoted 7 lines
examples/api/crt0.S +1 -0
        .align 8
        .long 0
 #else
 #error No support for this arch!
 #endif
 
+       .data

And changing these symbols should be a separate patch.

examples/api/crt0.S syscall: · line 75

Quoted 3 lines
examples/api/crt0.S +0 -0
        .globl syscall_ptr
 syscall_ptr:
        .align  8

Regards,
Bin

#9 lore raw

PATCH 4/7 examples: fix the type of search_hint

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

search_hint is defined in assembly as a .long, and is intended to hold the initial stack pointer as a hint to the api_search_sig() routine. Convert this to a uintptr_t, to avoid possible truncation on 64-bit systems.

---
 examples/api/glue.c | 6 +++---
 examples/api/glue.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
examples/api/glue.c +3 -3
index 91d13157a1..c223306319 100644
@@ -42,8 +42,8 @@ static int valid_sig(struct api_signature *sig)
 int api_search_sig(struct api_signature **sig)
 {
 	unsigned char *sp;
-	uint32_t search_start = 0;
-	uint32_t search_end = 0;
+	uintptr_t search_start = 0;
+	uintptr_t search_end = 0;
 
 	if (sig == NULL)
 		return 0;
@@ -51,7 +51,7 @@ int api_search_sig(struct api_signature **sig)
 	if (search_hint == 0)
 		search_hint = 255 * 1024 * 1024;
 
-	search_start = search_hint & ~0x000fffff;
+	search_start = search_hint & ~0xffffful;
 	search_end = search_start + API_SEARCH_LEN - API_SIG_MAGLEN;
 
 	sp = (unsigned char *)search_start;
examples/api/glue.h +1 -1
index f9745604b6..dd662fc872 100644
@@ -18,7 +18,7 @@
 #define UB_MAX_DEV	6	/* max devices number */
 
 extern void *syscall_ptr;
-extern uint32_t search_hint;
+extern unsigned long search_hint;
 
 int	syscall(int, int *, ...);
 int	api_search_sig(struct api_signature **sig);
Signature · 1 line
2.26.1
#10 lore raw

PATCH 4/7 examples: fix the type of search_hint

Quoted 8 lines · On Tue, Apr 21, 2020 at 7:28 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

search_hint is defined in assembly as a .long, and is intended to hold the initial stack pointer as a hint to the api_search_sig() routine. Convert this to a uintptr_t, to avoid possible truncation on 64-bit systems.

Quoted 6 lines
---
 examples/api/glue.c | 6 +++---
 examples/api/glue.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
#11 lore raw

PATCH 5/7 examples: fix incompatible type casts

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Some printf statements in the API demo assume pointers to be 32-bits long, presumably since it was originally developed for 32-bit arm. This generates a number of warnings when compiling for 64-bit architectures, and may result in truncation of these values. Fix this by avoiding casts where possible or casting to a more appropriate type.

---
 examples/api/demo.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
examples/api/demo.c +11 -10
index e7523786b4..f81466c5cf 100644
@@ -43,12 +43,12 @@ int main(int argc, char * const argv[])
 	if (sig->version > API_SIG_VERSION)
 		return -3;
 
-	printf("API signature found @%x\n", (unsigned int)sig);
+	printf("API signature found @%lx\n", (uintptr_t)sig);
 	test_dump_sig(sig);
 
 	printf("\n*** Consumer API test ***\n");
-	printf("syscall ptr 0x%08x@%08x\n", (unsigned int)syscall_ptr,
-		(unsigned int)&syscall_ptr);
+	printf("syscall ptr 0x%08lx@%08lx\n", (uintptr_t)syscall_ptr,
+	       (uintptr_t)&syscall_ptr);
 
 	/* console activities */
 	ub_putc('B');
@@ -203,7 +203,7 @@ void test_dump_sig(struct api_signature *sig)
 	printf("signature:\n");
 	printf("  version\t= %d\n", sig->version);
 	printf("  checksum\t= 0x%08x\n", sig->checksum);
-	printf("  sc entry\t= 0x%08x\n", (unsigned int)sig->syscall);
+	printf("  sc entry\t= 0x%08lx\n", (uintptr_t)sig->syscall);
 }
 
 void test_dump_si(struct sys_info *si)
@@ -211,9 +211,9 @@ void test_dump_si(struct sys_info *si)
 	int i;
 
 	printf("sys info:\n");
-	printf("  clkbus\t= 0x%08x\n", (unsigned int)si->clk_bus);
-	printf("  clkcpu\t= 0x%08x\n", (unsigned int)si->clk_cpu);
-	printf("  bar\t\t= 0x%08x\n", (unsigned int)si->bar);
+	printf("  clkbus\t= 0x%08lx\n", si->clk_bus);
+	printf("  clkcpu\t= 0x%08lx\n", si->clk_cpu);
+	printf("  bar\t\t= 0x%08lx\n", si->bar);
 
 	printf("---\n");
 	for (i = 0; i < si->mr_no; i++) {
@@ -296,7 +296,7 @@ void test_dump_di(int handle)
 	struct device_info *di = ub_dev_get(handle);
 
 	printf("device info (%d):\n", handle);
-	printf("  cookie\t= 0x%08x\n", (uint32_t)di->cookie);
+	printf("  cookie\t= 0x%08lx\n", (uintptr_t)di->cookie);
 	printf("  type\t\t= 0x%08x\n", di->type);
 
 	if (di->type == DEV_TYP_NET) {
@@ -308,7 +308,8 @@ void test_dump_di(int handle)
 
 	} else if (di->type & DEV_TYP_STOR) {
 		printf("  type\t\t= %s\n", test_stor_typ(di->type));
-		printf("  blk size\t\t= %d\n", (unsigned int)di->di_stor.block_size);
-		printf("  blk count\t\t= %d\n", (unsigned int)di->di_stor.block_count);
+		printf("  blk size\t\t= %lu\n", di->di_stor.block_size);
+		printf("  blk count\t\t= %llu\n",
+		       (uint64_t)di->di_stor.block_count);
 	}
 }
Signature · 1 line
2.26.1
#12 lore raw

PATCH 5/7 examples: fix incompatible type casts

Quoted 66 lines · On Tue, Apr 21, 2020 at 7:28 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

Some printf statements in the API demo assume pointers to be 32-bits long, presumably since it was originally developed for 32-bit arm. This generates a number of warnings when compiling for 64-bit architectures, and may result in truncation of these values. Fix this by avoiding casts where possible or casting to a more appropriate type.

---
 examples/api/demo.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
examples/api/demo.c +8 -8
index e7523786b4..f81466c5cf 100644
@@ -43,12 +43,12 @@ int main(int argc, char * const argv[])
        if (sig->version > API_SIG_VERSION)
                return -3;
 
-       printf("API signature found @%x\n", (unsigned int)sig);
+       printf("API signature found @%lx\n", (uintptr_t)sig);
        test_dump_sig(sig);
 
        printf("\n*** Consumer API test ***\n");
-       printf("syscall ptr 0x%08x@%08x\n", (unsigned int)syscall_ptr,
-               (unsigned int)&syscall_ptr);
+       printf("syscall ptr 0x%08lx@%08lx\n", (uintptr_t)syscall_ptr,
+              (uintptr_t)&syscall_ptr);
 
        /* console activities */
        ub_putc('B');
@@ -203,7 +203,7 @@ void test_dump_sig(struct api_signature *sig)
        printf("signature:\n");
        printf("  version\t= %d\n", sig->version);
        printf("  checksum\t= 0x%08x\n", sig->checksum);
-       printf("  sc entry\t= 0x%08x\n", (unsigned int)sig->syscall);
+       printf("  sc entry\t= 0x%08lx\n", (uintptr_t)sig->syscall);
 }
 
 void test_dump_si(struct sys_info *si)
@@ -211,9 +211,9 @@ void test_dump_si(struct sys_info *si)
        int i;
 
        printf("sys info:\n");
-       printf("  clkbus\t= 0x%08x\n", (unsigned int)si->clk_bus);
-       printf("  clkcpu\t= 0x%08x\n", (unsigned int)si->clk_cpu);
-       printf("  bar\t\t= 0x%08x\n", (unsigned int)si->bar);
+       printf("  clkbus\t= 0x%08lx\n", si->clk_bus);
+       printf("  clkcpu\t= 0x%08lx\n", si->clk_cpu);
+       printf("  bar\t\t= 0x%08lx\n", si->bar);
 
        printf("---\n");
        for (i = 0; i < si->mr_no; i++) {
@@ -296,7 +296,7 @@ void test_dump_di(int handle)
        struct device_info *di = ub_dev_get(handle);
 
        printf("device info (%d):\n", handle);
-       printf("  cookie\t= 0x%08x\n", (uint32_t)di->cookie);
+       printf("  cookie\t= 0x%08lx\n", (uintptr_t)di->cookie);
        printf("  type\t\t= 0x%08x\n", di->type);
 
        if (di->type == DEV_TYP_NET) {

examples/api/demo.c void test_dump_di(int handle) · line 312

Quoted 7 lines
examples/api/demo.c +2 -2
@@ -308,7 +308,8 @@ void test_dump_di(int handle)
 
        } else if (di->type & DEV_TYP_STOR) {
                printf("  type\t\t= %s\n", test_stor_typ(di->type));
-               printf("  blk size\t\t= %d\n", (unsigned int)di->di_stor.block_size);
-               printf("  blk count\t\t= %d\n", (unsigned int)di->di_stor.block_count);
+               printf("  blk size\t\t= %lu\n", di->di_stor.block_size);
+               printf("  blk count\t\t= %llu\n",

Use LBAF from include/blk.h ?

Also I am not sure why CONFIG_SYS_64BIT_LBA is undefined in include/api_public.h ?

examples/api/demo.c void test_dump_di(int handle) · line 315

Quoted 3 lines
examples/api/demo.c +1 -0
+                      (uint64_t)di->di_stor.block_count);
        }
 }

Regards,
Bin

#13 lore raw

PATCH 6/7 riscv: add CONFIG_API support

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Add the necessary changes to allow building the CONFIG_API option on the RISC-V architecture. The downstream consumer of this API is the u-boot version of FreeBSD's loader(8). This enables the loader to be ported to RISC-V.

Cc rick at andestech.com
Cc bmeng.cn at gmail.com
Cc atish.patra at wdc.com
---
 api/Makefile             |  1 +
 api/api_platform-riscv.c | 33 +++++++++++++++++++++++++++++++++
 examples/api/Makefile    |  3 +++
 examples/api/crt0.S      | 15 +++++++++++++++
 4 files changed, 52 insertions(+)
 create mode 100644 api/api_platform-riscv.c
api/Makefile +1 -0
index bd2d035fcd..737854e2c6 100644
@@ -6,3 +6,4 @@ obj-y += api.o api_display.o api_net.o api_storage.o
 obj-$(CONFIG_ARM) += api_platform-arm.o
 obj-$(CONFIG_PPC) += api_platform-powerpc.o
 obj-$(CONFIG_MIPS) += api_platform-mips.o
+obj-$(CONFIG_RISCV) += api_platform-riscv.o
api/api_platform-riscv.c new file +33 -0
new file mode 100644
index 0000000000..33a56535f3
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2007 Stanislav Galabov <[email protected]>
+ *
+ * This file contains routines that fetch data from bd_info sources
+ */
+
+#include <config.h>
+#include <linux/types.h>
+#include <api_public.h>
+
+#include <asm/u-boot.h>
+#include <asm/global_data.h>
+
+#include "api_private.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Important notice: handling of individual fields MUST be kept in sync with
+ * include/asm-generic/u-boot.h, so any changes
+ * need to reflect their current state and layout of structures involved!
+ */
+int platform_sys_info(struct sys_info *si)
+{
+	int i;
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
+		platform_set_mr(si, gd->bd->bi_dram[i].start,
+				gd->bd->bi_dram[i].size, MR_ATTR_DRAM);
+
+	return 1;
+}
examples/api/Makefile +3 -0
index 8fa9c04118..0f9d0e013f 100644
@@ -18,6 +18,9 @@ else
 LOAD_ADDR = 0x80200000
 endif
 endif
+ifeq ($(ARCH),riscv)
+LOAD_ADDR = 0x84000000
+endif
 
 # Resulting ELF and binary exectuables will be named demo and demo.bin
 extra-y = demo demo.bin
examples/api/crt0.S +15 -0
index 658bc59a82..2ba23331df 100644
@@ -65,6 +65,21 @@ return_addr:
 	.data
 	.align 8
 	.long 0
+
+#elif defined(CONFIG_RISCV)
+#include <asm/asm.h>
+	.text
+	.globl _start
+_start:
+	lla	t0, search_hint
+	REG_S	sp, 0(t0)
+	tail	main
+
+	.globl syscall
+syscall:
+	lla	t0, syscall_ptr
+	REG_L	t2, 0(t0)
+	jr	t2
 #else
 #error No support for this arch!
 #endif
Signature · 1 line
2.26.1
#14 lore raw

PATCH 6/7 riscv: add CONFIG_API support

Quoted 6 lines · On Tue, Apr 21, 2020 at 6:35 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

Add the necessary changes to allow building the CONFIG_API option on the RISC-V architecture. The downstream consumer of this API is the u-boot version of FreeBSD's loader(8). This enables the loader to be ported to

Could you please include a URL for FreeBSD's loader(8)?

Quoted 81 lines

RISC-V.

Cc rick at andestech.com
Cc bmeng.cn at gmail.com
Cc atish.patra at wdc.com
---
 api/Makefile             |  1 +
 api/api_platform-riscv.c | 33 +++++++++++++++++++++++++++++++++
 examples/api/Makefile    |  3 +++
 examples/api/crt0.S      | 15 +++++++++++++++
 4 files changed, 52 insertions(+)
 create mode 100644 api/api_platform-riscv.c
api/Makefile +1 -0
index bd2d035fcd..737854e2c6 100644
@@ -6,3 +6,4 @@ obj-y += api.o api_display.o api_net.o api_storage.o
 obj-$(CONFIG_ARM) += api_platform-arm.o
 obj-$(CONFIG_PPC) += api_platform-powerpc.o
 obj-$(CONFIG_MIPS) += api_platform-mips.o
+obj-$(CONFIG_RISCV) += api_platform-riscv.o
api/api_platform-riscv.c new file +33 -0
new file mode 100644
index 0000000000..33a56535f3
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2007 Stanislav Galabov <[email protected]>
+ *
+ * This file contains routines that fetch data from bd_info sources
+ */
+
+#include <config.h>
+#include <linux/types.h>
+#include <api_public.h>
+
+#include <asm/u-boot.h>
+#include <asm/global_data.h>
+
+#include "api_private.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Important notice: handling of individual fields MUST be kept in sync with
+ * include/asm-generic/u-boot.h, so any changes
+ * need to reflect their current state and layout of structures involved!
+ */
+int platform_sys_info(struct sys_info *si)
+{
+       int i;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
+               platform_set_mr(si, gd->bd->bi_dram[i].start,
+                               gd->bd->bi_dram[i].size, MR_ATTR_DRAM);
+
+       return 1;
+}
examples/api/Makefile +3 -0
index 8fa9c04118..0f9d0e013f 100644
@@ -18,6 +18,9 @@ else
 LOAD_ADDR = 0x80200000
 endif
 endif
+ifeq ($(ARCH),riscv)
+LOAD_ADDR = 0x84000000
+endif
 
 # Resulting ELF and binary exectuables will be named demo and demo.bin
 extra-y = demo demo.bin
examples/api/crt0.S +0 -0
index 658bc59a82..2ba23331df 100644

examples/api/crt0.S return_addr: · line 74

Quoted 10 lines
examples/api/crt0.S +7 -0
@@ -65,6 +65,21 @@ return_addr:
        .data
        .align 8
        .long 0
+
+#elif defined(CONFIG_RISCV)
+#include <asm/asm.h>
+       .text
+       .globl _start
+_start:
+       lla     t0, search_hint

Looks lla is only supported in newer assemblers?

examples/api/crt0.S return_addr:

Quoted 12 lines
examples/api/crt0.S +8 -1
+       REG_S   sp, 0(t0)
+       tail    main
+
+       .globl syscall
+syscall:
+       lla     t0, syscall_ptr
+       REG_L   t2, 0(t0)
+       jr      t2
 #else
 #error No support for this arch!
 #endif
--

Regards,
Bin

#15 lore raw

PATCH 7/7 api: enumerate virtio-blk devices

In reply to mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

API clients can make a syscall requesting the enumeration of network and storage devices. However, this does not check for virtio-blk storage devices, which API consumers may wish to use. Add the support to enumerate these devices as well.

---
 api/api_storage.c    | 14 +++++++++++++-
 include/api_public.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)
api/api_storage.c +13 -1
index 7ae03ac230..866c82d7ec 100644
@@ -30,7 +30,8 @@
 #define ENUM_SCSI	2
 #define ENUM_MMC	3
 #define ENUM_SATA	4
-#define ENUM_MAX	5
+#define ENUM_VIRTIO	5
+#define ENUM_MAX	6
 
 struct stor_spec {
 	int		max_dev;
@@ -46,6 +47,10 @@ static struct stor_spec specs[ENUM_MAX] = { { 0, 0, 0, 0, NULL }, };
 #define CONFIG_SYS_MMC_MAX_DEVICE	1
 #endif
 
+#ifndef CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE
+#define CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE	1
+#endif
+
 void dev_stor_init(void)
 {
 #if defined(CONFIG_IDE)
@@ -83,6 +88,13 @@ void dev_stor_init(void)
 	specs[ENUM_USB].type = DEV_TYP_STOR | DT_STOR_USB;
 	specs[ENUM_USB].name = "usb";
 #endif
+#if defined(CONFIG_VIRTIO_BLK)
+	specs[ENUM_VIRTIO].max_dev = CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE;
+	specs[ENUM_VIRTIO].enum_started = 0;
+	specs[ENUM_VIRTIO].enum_ended = 0;
+	specs[ENUM_VIRTIO].type = DEV_TYP_STOR | DT_STOR_VIRTIO;
+	specs[ENUM_VIRTIO].name = "virtio";
+#endif
 }
 
 /*
include/api_public.h +1 -0
index def103ce22..1f9ff49b0b 100644
@@ -87,6 +87,7 @@ typedef unsigned long lbastart_t;
 #define DT_STOR_USB	0x0040
 #define DT_STOR_MMC	0x0080
 #define DT_STOR_SATA	0x0100
+#define DT_STOR_VIRTIO	0x0200
 
 #define DEV_STA_CLOSED	0x0000		/* invalid, closed */
 #define DEV_STA_OPEN	0x0001		/* open i.e. active */
Signature · 1 line
2.26.1
#16 lore raw

PATCH 7/7 api: enumerate virtio-blk devices

Quoted 29 lines · On Tue, Apr 21, 2020 at 7:29 AM <[email protected]> wrote:

From: Mitchell Horne <[email protected]>

API clients can make a syscall requesting the enumeration of network and storage devices. However, this does not check for virtio-blk storage devices, which API consumers may wish to use. Add the support to enumerate these devices as well.

---
 api/api_storage.c    | 14 +++++++++++++-
 include/api_public.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)
api/api_storage.c +2 -1
index 7ae03ac230..866c82d7ec 100644
@@ -30,7 +30,8 @@
 #define ENUM_SCSI      2
 #define ENUM_MMC       3
 #define ENUM_SATA      4
-#define ENUM_MAX       5
+#define ENUM_VIRTIO    5
+#define ENUM_MAX       6
 
 struct stor_spec {
        int             max_dev;

api/api_storage.c static struct stor_spec specs[ENUM_MAX] = { { 0, 0, 0, 0, NULL }, }; · line 51

Quoted 5 lines
api/api_storage.c +2 -0
@@ -46,6 +47,10 @@ static struct stor_spec specs[ENUM_MAX] = { { 0, 0, 0, 0, NULL }, };
 #define CONFIG_SYS_MMC_MAX_DEVICE      1
 #endif
 
+#ifndef CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE
+#define CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE       1

At some time we need turn all these macros to Kconfig options in this file.

Quoted 24 lines
api/api_storage.c +9 -0
+#endif
+
 void dev_stor_init(void)
 {
 #if defined(CONFIG_IDE)
@@ -83,6 +88,13 @@ void dev_stor_init(void)
        specs[ENUM_USB].type = DEV_TYP_STOR | DT_STOR_USB;
        specs[ENUM_USB].name = "usb";
 #endif
+#if defined(CONFIG_VIRTIO_BLK)
+       specs[ENUM_VIRTIO].max_dev = CONFIG_SYS_VIRTIO_BLK_MAX_DEVICE;
+       specs[ENUM_VIRTIO].enum_started = 0;
+       specs[ENUM_VIRTIO].enum_ended = 0;
+       specs[ENUM_VIRTIO].type = DEV_TYP_STOR | DT_STOR_VIRTIO;
+       specs[ENUM_VIRTIO].name = "virtio";
+#endif
 }
 
 /*
include/api_public.h +0 -0
index def103ce22..1f9ff49b0b 100644

include/api_public.h typedef unsigned long lbastart_t; · line 93

Quoted 7 lines
include/api_public.h +1 -0
@@ -87,6 +87,7 @@ typedef unsigned long lbastart_t;
 #define DT_STOR_USB    0x0040
 #define DT_STOR_MMC    0x0080
 #define DT_STOR_SATA   0x0100
+#define DT_STOR_VIRTIO 0x0200
 
 #define DEV_STA_CLOSED 0x0000          /* invalid, closed */
 #define DEV_STA_OPEN   0x0001          /* open i.e. active */
#17 lore raw

cover Add support for CONFIG_API on RISC-V

In reply to mhorne at FreeBSD.org
Quoted 6 lines · mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Adding in the RISC-V maintainer and EFI maintainer. I thought the intention was for OSes to use the EFI loader here, even for "embedded" ? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200424/ec50a47c/attachment.sig>
#18 lore raw

cover Add support for CONFIG_API on RISC-V

Quoted 5 lines · Tom Rini
Quoted 2 lines · mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Quoted 9 lines
Quoted 4 lines

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Adding in the RISC-V maintainer and EFI maintainer. I thought the intention was for OSes to use the EFI loader here, even for "embedded" ? Thanks!

Hi Tom,

You are right, EFI is preferred. FreeBSD's loader has two implementations on arm: one that is an EFI application, and one based on this u-boot API (known as "ubldr"). ubldr precedes the EFI implementation by a few years.

For RISC-V my intention is also to implement both versions, and ubldr was simpler on FreeBSD's side, so I chose to do that first. Do you think this series is still worth pursuing if u-boot is going the way of EFI?

Cheers,
Mitchell

Quoted 2 lines

--
Tom

#19 lore raw

cover Add support for CONFIG_API on RISC-V

Quoted 23 lines · Mitchell Horne
Quoted 5 lines · Tom Rini
Quoted 2 lines · mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Quoted 9 lines
Quoted 4 lines

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Adding in the RISC-V maintainer and EFI maintainer. I thought the intention was for OSes to use the EFI loader here, even for "embedded" ? Thanks!

Hi Tom,

You are right, EFI is preferred. FreeBSD's loader has two implementations on arm: one that is an EFI application, and one based on this u-boot API (known as "ubldr"). ubldr precedes the EFI implementation by a few years.

Quoted 4 lines

For RISC-V my intention is also to implement both versions, and ubldr was simpler on FreeBSD's side, so I chose to do that first. Do you think this series is still worth pursuing if u-boot is going the way of EFI?

In my mind at least, the EFI interface is preferred as it's a defined external standard interface. If the architecture maintainers want to support both the U-Boot API and EFI on RISC-V, I don't object. But one of the intentions is to have there be less work for OS folks to have to do for example. So that you found this a good first step for your use case means perhaps we need to continue to have the U-Boot API method be around (not that we had planned any sort of removal). Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200424/67c8a3bf/attachment.sig>
#20 lore raw

cover Add support for CONFIG_API on RISC-V

Quoted 29 lines · Tom Rini
Quoted 23 lines · Mitchell Horne
Quoted 5 lines · Tom Rini
Quoted 2 lines · mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Quoted 9 lines
Quoted 4 lines

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Adding in the RISC-V maintainer and EFI maintainer. I thought the intention was for OSes to use the EFI loader here, even for "embedded" ? Thanks!

Hi Tom,

You are right, EFI is preferred. FreeBSD's loader has two implementations on arm: one that is an EFI application, and one based on this u-boot API (known as "ubldr"). ubldr precedes the EFI implementation by a few years.

Quoted 4 lines

For RISC-V my intention is also to implement both versions, and ubldr was simpler on FreeBSD's side, so I chose to do that first. Do you think this series is still worth pursuing if u-boot is going the way of EFI?

Quoted 8 lines

In my mind at least, the EFI interface is preferred as it's a defined external standard interface. If the architecture maintainers want to support both the U-Boot API and EFI on RISC-V, I don't object. But one of the intentions is to have there be less work for OS folks to have to do for example. So that you found this a good first step for your use case means perhaps we need to continue to have the U-Boot API method be around (not that we had planned any sort of removal). Thanks!

Hello Mitchell,

let me just give me an overview of where we currently are with UEFI support for RISC-V:

U-Boot supports UEFI to the point that we can start GRUB as EFI binary.

In Linux the UEFI support for RISC-V is being set up, cf.
https://lkml.org/lkml/2020/4/20/1800

In EDK2 RISC-V support is under active development
(https://edk2.groups.io/g/devel/search?q=RISC-V). In EDK2's staging repository (https://github.com/tianocore/edk2-staging.git) you can find a branch RISC-V-V2-CI-log-all-archs.

One challenge is the transfer of the HART id which is used for booting. In U-Boot this has been addressed by the patch 5370478d1c7a ("riscv: Add boot hartid to device tree").

@Atish:
Is there a corresponding patch for EDK2?

Best regards

Heinrich

#21 lore raw

cover Add support for CONFIG_API on RISC-V

Quoted 50 lines · Heinrich Schuchardt
Quoted 29 lines · Tom Rini
Quoted 23 lines · Mitchell Horne
Quoted 5 lines · Tom Rini
Quoted 2 lines · mhorne at FreeBSD.org

From: Mitchell Horne <[email protected]>

Quoted 9 lines
Quoted 4 lines

FreeBSD makes use of u-boot's CONFIG_API to provide a version of its standard bootloader for embedded architectures. This series adds the necessary support for the RISC-V architecture, along with some small fixes to the API demo program for 64-bit systems.

Adding in the RISC-V maintainer and EFI maintainer. I thought the intention was for OSes to use the EFI loader here, even for "embedded" ? Thanks!

Hi Tom,

You are right, EFI is preferred. FreeBSD's loader has two implementations on arm: one that is an EFI application, and one based on this u-boot API (known as "ubldr"). ubldr precedes the EFI implementation by a few years.

Quoted 4 lines

For RISC-V my intention is also to implement both versions, and ubldr was simpler on FreeBSD's side, so I chose to do that first. Do you think this series is still worth pursuing if u-boot is going the way of EFI?

Quoted 8 lines

In my mind at least, the EFI interface is preferred as it's a defined external standard interface. If the architecture maintainers want to support both the U-Boot API and EFI on RISC-V, I don't object. But one of the intentions is to have there be less work for OS folks to have to do for example. So that you found this a good first step for your use case means perhaps we need to continue to have the U-Boot API method be around (not that we had planned any sort of removal). Thanks!

Hello Mitchell,

let me just give me an overview of where we currently are with UEFI support for RISC-V:

U-Boot supports UEFI to the point that we can start GRUB as EFI binary.

In Linux the UEFI support for RISC-V is being set up, cf.
https://lkml.org/lkml/2020/4/20/1800

Quoted 8 lines

In EDK2 RISC-V support is under active development
(https://edk2.groups.io/g/devel/search?q=RISC-V). In EDK2's staging repository (https://github.com/tianocore/edk2-staging.git) you can find a branch RISC-V-V2-CI-log-all-archs.

One challenge is the transfer of the HART id which is used for booting. In U-Boot this has been addressed by the patch 5370478d1c7a ("riscv: Add boot hartid to device tree").

Hi, just so this thread isn't left dangling, I eventually went the EFI route. I found this to be easier because the hart-id fixups aren't applied when executing plain binaries via the "go" command. I don't think this patchset will be needed. Thanks!

Mitchell

Quoted 7 lines

@Atish:
Is there a corresponding patch for EDK2?

Best regards

Heinrich