From: Jean THOMAS Date: Tue, 16 Jun 2020 07:55:49 +0000 (+0200) Subject: Allow libgram to run outside a SoC X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5b48ef750af6c392342d010e2d4d5932894c42ac;p=gram.git Allow libgram to run outside a SoC --- diff --git a/libgram/Makefile b/libgram/Makefile index ff51a9a..de67554 100644 --- a/libgram/Makefile +++ b/libgram/Makefile @@ -8,8 +8,13 @@ OBJCOPY := $(TRIPLE)objcopy AR := $(TRIPLE)ar LD := $(TRIPLE)ld -CFLAGS := -fvisibility=hidden -march=rv32i -mabi=ilp32 -nostdlib -Os -Iinclude -LDFLAGS := -melf32lriscv -nostdlib +CFLAGS += -fvisibility=hidden -nostdlib -Os -Iinclude +LDFLAGS += -nostdlib + +ifeq ($(TRIPLE),riscv64-unknown-elf-) +CFLAGS += -march=rv32i -mabi=ilp32 +LDFLAGS += -melf32lriscv +endif all: libgram.a diff --git a/libgram/README.md b/libgram/README.md index 965c663..b7b3f81 100644 --- a/libgram/README.md +++ b/libgram/README.md @@ -1,6 +1,6 @@ # libgram, the C companion for gram -libgram is the C library for gram core initialization. +libgram is the C library for gram core initialization and memory testing. ## HowTo @@ -25,3 +25,14 @@ Link it to this library and you should be good to go! GRAM_ERR_NONE: No error happened (hardcoded to zero) GRAM_ERR_UNDOCUMENTED: Undocumented error, shame on us lazy coders (take a look at the code) ``` + +## Using libgram when you can't directly access the bus + +Compile libgram with `CFLAGS="-DGRAM_RW_FUNC"` (run `make clean` beforehand) then define the following functions: + +```c +uint32_t gram_read(struct gramCtx *ctx, void *addr); +int gram_write(struct gramCtx *ctx, void *addr, uint32_t value); +``` + +If you want to use the default compiler on your computer, use `CFLAGS="-DGRAM_RW_FUNC" make TRIPLE=""`. diff --git a/libgram/include/gram.h b/libgram/include/gram.h index de50a54..438c68c 100644 --- a/libgram/include/gram.h +++ b/libgram/include/gram.h @@ -1,6 +1,8 @@ #ifndef GRAM_H #define GRAM_H +#include + enum GramError { GRAM_ERR_NONE = 0, GRAM_ERR_UNDOCUMENTED, @@ -13,9 +15,15 @@ struct gramCtx { volatile void *ddr_base; volatile struct gramCoreRegs *core; volatile struct gramPHYRegs *phy; + void *user_data; }; extern __attribute__((visibility ("default"))) int gram_init(struct gramCtx *ctx, void *ddr_base, void *core_base, void *phy_base); extern __attribute__((visibility ("default"))) int gram_memtest(struct gramCtx *ctx); +#ifdef GRAM_RW_FUNC +extern uint32_t gram_read(struct gramCtx *ctx, void *addr); +extern int gram_write(struct gramCtx *ctx, void *addr, uint32_t value); +#endif /* GRAM_RW_FUNC */ + #endif /* GRAM_H */ diff --git a/libgram/src/dfii.c b/libgram/src/dfii.c index b9367ba..d2b7334 100644 --- a/libgram/src/dfii.c +++ b/libgram/src/dfii.c @@ -6,7 +6,11 @@ #include "helpers.h" static void dfii_setcontrol(struct gramCtx *ctx, uint8_t val) { +#ifdef GRAM_RW_FUNC + gram_write(ctx, &(ctx->core->control), val); +#else ctx->core->control = val; +#endif } void dfii_setsw(struct gramCtx *ctx, bool software_control) { @@ -18,16 +22,29 @@ void dfii_setsw(struct gramCtx *ctx, bool software_control) { } static void dfii_set_p0_address(struct gramCtx *ctx, uint32_t val) { +#ifdef GRAM_RW_FUNC + gram_write(ctx, &(ctx->core->phases[0].address), val); +#else ctx->core->phases[0].address = val; +#endif } static void dfii_set_p0_baddress(struct gramCtx *ctx, uint32_t val) { +#ifdef GRAM_RW_FUNC + gram_write(ctx, &(ctx->core->phases[0].baddress), val); +#else ctx->core->phases[0].baddress = val; +#endif } static void dfii_p0_command(struct gramCtx *ctx, uint32_t cmd) { +#ifdef GRAM_RW_FUNC + gram_write(ctx, &(ctx->core->phases[0].command), cmd); + gram_write(ctx, &(ctx->core->phases[0].command_issue), 1); +#else ctx->core->phases[0].command = cmd; ctx->core->phases[0].command_issue = 1; +#endif } /* TODO: those values are hardcoded for ECPIX-5's RAM */ diff --git a/libgram/src/memtest.c b/libgram/src/memtest.c index 55a5fc0..c5e0bee 100644 --- a/libgram/src/memtest.c +++ b/libgram/src/memtest.c @@ -1,5 +1,5 @@ #include int gram_memtest(struct gramCtx *ctx) { - return 0; + return GRAM_ERR_NONE; }