From patchwork Mon Apr 20 22:34:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238132 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:12 -0400 Subject: [PATCH 1/7] examples: generate demo.bin In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-2-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne Reviewed-by: Bin Meng --- examples/api/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/api/Makefile b/examples/api/Makefile index ca4eb1f71a..9ff793206f 100644 --- a/examples/api/Makefile +++ b/examples/api/Makefile @@ -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) From patchwork Mon Apr 20 22:34:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238133 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:13 -0400 Subject: [PATCH 2/7] examples: rename __start to _start on MIPS In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-3-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne Reviewed-by: Bin Meng --- examples/api/crt0.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/api/crt0.S b/examples/api/crt0.S index 57bba9d851..2f75f5a036 100644 --- a/examples/api/crt0.S +++ b/examples/api/crt0.S @@ -42,12 +42,12 @@ syscall: #elif defined(CONFIG_MIPS) #include .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 From patchwork Mon Apr 20 22:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238136 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:14 -0400 Subject: [PATCH 3/7] examples: add a linker script for the API demo In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-4-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne --- 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 diff --git a/examples/api/Makefile b/examples/api/Makefile index 9ff793206f..8fa9c04118 100644 --- a/examples/api/Makefile +++ b/examples/api/Makefile @@ -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) diff --git a/examples/api/crt0.S b/examples/api/crt0.S index 2f75f5a036..658bc59a82 100644 --- a/examples/api/crt0.S +++ b/examples/api/crt0.S @@ -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 diff --git a/examples/api/demo.lds b/examples/api/demo.lds new file mode 100644 index 0000000000..a6b88dedef --- /dev/null +++ b/examples/api/demo.lds @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2020 Mitchell Horne + */ + +ENTRY(_start) +SECTIONS +{ + .text : + { + *crt0.S(.text*) + *(.text*) + } +} From patchwork Mon Apr 20 22:34:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238134 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:15 -0400 Subject: [PATCH 4/7] examples: fix the type of search_hint In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-5-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne Reviewed-by: Bin Meng --- examples/api/glue.c | 6 +++--- examples/api/glue.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/api/glue.c b/examples/api/glue.c index 91d13157a1..c223306319 100644 --- a/examples/api/glue.c +++ b/examples/api/glue.c @@ -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; diff --git a/examples/api/glue.h b/examples/api/glue.h index f9745604b6..dd662fc872 100644 --- a/examples/api/glue.h +++ b/examples/api/glue.h @@ -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); From patchwork Mon Apr 20 22:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238135 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:16 -0400 Subject: [PATCH 5/7] examples: fix incompatible type casts In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-6-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne --- examples/api/demo.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/api/demo.c b/examples/api/demo.c index e7523786b4..f81466c5cf 100644 --- a/examples/api/demo.c +++ b/examples/api/demo.c @@ -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); } } From patchwork Mon Apr 20 22:34:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238138 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:17 -0400 Subject: [PATCH 6/7] riscv: add CONFIG_API support In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-7-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne 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 diff --git a/api/Makefile b/api/Makefile index bd2d035fcd..737854e2c6 100644 --- a/api/Makefile +++ b/api/Makefile @@ -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 diff --git a/api/api_platform-riscv.c b/api/api_platform-riscv.c new file mode 100644 index 0000000000..33a56535f3 --- /dev/null +++ b/api/api_platform-riscv.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2007 Stanislav Galabov + * + * This file contains routines that fetch data from bd_info sources + */ + +#include +#include +#include + +#include +#include + +#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; +} diff --git a/examples/api/Makefile b/examples/api/Makefile index 8fa9c04118..0f9d0e013f 100644 --- a/examples/api/Makefile +++ b/examples/api/Makefile @@ -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 diff --git a/examples/api/crt0.S b/examples/api/crt0.S index 658bc59a82..2ba23331df 100644 --- a/examples/api/crt0.S +++ b/examples/api/crt0.S @@ -65,6 +65,21 @@ return_addr: .data .align 8 .long 0 + +#elif defined(CONFIG_RISCV) +#include + .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 From patchwork Mon Apr 20 22:34:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238137 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:18 -0400 Subject: [PATCH 7/7] api: enumerate virtio-blk devices In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-8-mhorne@FreeBSD.org> From: Mitchell Horne 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. Signed-off-by: Mitchell Horne Reviewed-by: Bin Meng --- api/api_storage.c | 14 +++++++++++++- include/api_public.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/api_storage.c b/api/api_storage.c index 7ae03ac230..866c82d7ec 100644 --- a/api/api_storage.c +++ b/api/api_storage.c @@ -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 } /* diff --git a/include/api_public.h b/include/api_public.h index def103ce22..1f9ff49b0b 100644 --- a/include/api_public.h +++ b/include/api_public.h @@ -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 */