From a0658421ccdc63dff6182ff5cf8c66f25c5774d0 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Sat, 11 Apr 2020 18:23:40 -0700 Subject: [PATCH 1/3] litex_sim: Better error messages on failure to load module. --- litex/build/sim/core/modules.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litex/build/sim/core/modules.c b/litex/build/sim/core/modules.c index f8d66da7a..2d12a771f 100644 --- a/litex/build/sim/core/modules.c +++ b/litex/build/sim/core/modules.c @@ -118,11 +118,11 @@ int litex_sim_find_ext_module(struct ext_module_list_s *first, char *name , stru { struct ext_module_list_s *list = NULL; int ret=RC_OK; - + if(!first || !name || !found) { ret = RC_INVARG; - eprintf("Invalid arg\n"); + eprintf("Invalid first:%s arg:%s found:%p\n", first, name, found); goto out; } @@ -140,11 +140,11 @@ int litex_sim_find_module(struct module_s *first, char *name , struct module_s * { struct module_s *list = NULL; int ret=RC_OK; - + if(!first || !name || !found) { ret = RC_INVARG; - eprintf("Invalid arg\n"); + eprintf("Invalid first:%s arg:%s found:%p\n", first, name, found); goto out; } From 5a0bb6ee017f78a38a314747d55a95dbe10622c3 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Sat, 11 Apr 2020 18:26:15 -0700 Subject: [PATCH 2/3] litex_sim: Rework Makefiles to put output files in gateware directory. --- litex/build/sim/core/Makefile | 9 ++++---- litex/build/sim/core/modules/Makefile | 6 +++-- litex/build/sim/core/modules/clocker/Makefile | 7 ++---- .../build/sim/core/modules/ethernet/Makefile | 16 ++++++-------- .../sim/core/modules/jtagremote/Makefile | 7 ++---- litex/build/sim/core/modules/rules.mak | 22 +++++++++++++++---- .../sim/core/modules/serial2console/Makefile | 7 ++---- .../sim/core/modules/serial2tcp/Makefile | 7 ++---- litex/build/sim/core/modules/variables.mak | 13 ----------- .../sim/core/modules/xgmii_ethernet/Makefile | 16 ++++++-------- litex/build/sim/verilator.py | 3 +-- 11 files changed, 50 insertions(+), 63 deletions(-) delete mode 100644 litex/build/sim/core/modules/variables.mak diff --git a/litex/build/sim/core/Makefile b/litex/build/sim/core/Makefile index 422baacdd..047423cac 100644 --- a/litex/build/sim/core/Makefile +++ b/litex/build/sim/core/Makefile @@ -29,11 +29,11 @@ all: modules sim mkdir: mkdir -p $(OBJ_DIR) -$(OBJS_SIM): %.o: $(SRC_DIR)/%.c +$(OBJS_SIM): %.o: $(SRC_DIR)/%.c | mkdir $(CC) -c $(CFLAGS) -o $(OBJ_DIR)/$@ $< .PHONY: sim -sim: mkdir $(OBJS_SIM) +sim: $(OBJS_SIM) | mkdir verilator -Wno-fatal -O3 $(CC_SRCS) --top-module dut --exe \ -DPRINTF_COND=0 \ $(SRCS_SIM_CPP) $(OBJS_SIM) \ @@ -51,8 +51,9 @@ sim: mkdir $(OBJS_SIM) make -j -C $(OBJ_DIR) -f Vdut.mk Vdut .PHONY: modules -modules: mkdir - $(MAKE) -C $(MOD_DIR) +modules: + mkdir modules + $(MAKE) -C modules -f $(MOD_DIR)/Makefile .PHONY: clean clean: diff --git a/litex/build/sim/core/modules/Makefile b/litex/build/sim/core/modules/Makefile index a0b721c51..c7a35784a 100644 --- a/litex/build/sim/core/modules/Makefile +++ b/litex/build/sim/core/modules/Makefile @@ -1,11 +1,13 @@ +include ../variables.mak MODULES = xgmii_ethernet ethernet serial2console serial2tcp clocker -SHROBJS = $(MODULES:=.so) .PHONY: $(MODULES) all: $(MODULES) $(MODULES): %: - $(MAKE) -C $@ + mkdir -p $@ + $(MAKE) MOD=$@ -C $@ -f $(SRC_DIR)/modules/$@/Makefile + cp $@/$@.so $@.so .PHONY: clean clean: diff --git a/litex/build/sim/core/modules/clocker/Makefile b/litex/build/sim/core/modules/clocker/Makefile index 3fd45b454..0c69b5b9e 100644 --- a/litex/build/sim/core/modules/clocker/Makefile +++ b/litex/build/sim/core/modules/clocker/Makefile @@ -1,5 +1,2 @@ -include ../variables.mak - -all: $(OBJ_DIR)/clocker.so - -include ../rules.mak +include ../../variables.mak +include $(SRC_DIR)/modules/rules.mak diff --git a/litex/build/sim/core/modules/ethernet/Makefile b/litex/build/sim/core/modules/ethernet/Makefile index d29bf1c24..461ed86be 100644 --- a/litex/build/sim/core/modules/ethernet/Makefile +++ b/litex/build/sim/core/modules/ethernet/Makefile @@ -1,22 +1,20 @@ -include ../variables.mak -CFLAGS += -Itapcfg/src/include +include ../../variables.mak UNAME_S := $(shell uname -s) -all: $(OBJ_DIR)/ethernet.so +include $(SRC_DIR)/modules/rules.mak -include ../rules.mak +CFLAGS += -I$(MOD_SRC_DIR)/tapcfg/src/include +OBJS = $(MOD).o tapcfg.o taplog.o -OBJS = $(addprefix $(OBJ_DIR)/, ethernet.o tapcfg.o taplog.o) - -$(OBJ_DIR)/ethernet.so: $(OBJS) +$(MOD).so: $(OBJS) ifeq ($(UNAME_S),Darwin) $(CC) $(LDFLAGS) -o $@ $^ else $(CC) $(LDFLAGS) -Wl,-soname,$@ -o $@ $^ endif -$(OBJ_DIR)/tapcfg.o: tapcfg/src/lib/tapcfg.c +tapcfg.o: $(MOD_SRC_DIR)/tapcfg/src/lib/tapcfg.c $(CC) $(CFLAGS) -c -o $@ $< -$(OBJ_DIR)/taplog.o: tapcfg/src/lib/taplog.c +taplog.o: $(MOD_SRC_DIR)/tapcfg/src/lib/taplog.c $(CC) $(CFLAGS) -c -o $@ $< diff --git a/litex/build/sim/core/modules/jtagremote/Makefile b/litex/build/sim/core/modules/jtagremote/Makefile index 950d49145..0c69b5b9e 100644 --- a/litex/build/sim/core/modules/jtagremote/Makefile +++ b/litex/build/sim/core/modules/jtagremote/Makefile @@ -1,5 +1,2 @@ -include ../variables.mak - -all: $(OBJ_DIR)/jtagremote.so - -include ../rules.mak +include ../../variables.mak +include $(SRC_DIR)/modules/rules.mak diff --git a/litex/build/sim/core/modules/rules.mak b/litex/build/sim/core/modules/rules.mak index 62ff24288..0c1867270 100644 --- a/litex/build/sim/core/modules/rules.mak +++ b/litex/build/sim/core/modules/rules.mak @@ -1,9 +1,23 @@ +CC ?= gcc UNAME_S := $(shell uname -s) -$(OBJ_DIR)/%.o: %.c - $(CC) -c $(CFLAGS) -I../.. -o $@ $< +ifeq ($(UNAME_S),Darwin) + CFLAGS += -I/usr/local/include/ + LDFLAGS += -L/usr/local/lib -ljson-c + CFLAGS += -Wall -O3 -ggdb -fPIC +else + CFLAGS += -Wall -O3 -ggdb -fPIC -Werror +endif +LDFLAGS += -levent -shared -fPIC -$(OBJ_DIR)/%.so: $(OBJ_DIR)/%.o +MOD_SRC_DIR=$(SRC_DIR)/modules/$(MOD) + +all: $(MOD).so + +%.o: $(MOD_SRC_DIR)/%.c + $(CC) -c $(CFLAGS) -I$(MOD_SRC_DIR)/../.. -o $@ $< + +%.so: %.o ifeq ($(UNAME_S),Darwin) $(CC) $(LDFLAGS) -o $@ $^ else @@ -12,4 +26,4 @@ endif .PHONY: clean clean: - rm -f $(OBJ_DIR)/*.o $(OBJ_DIR)/*.so + rm -f *.o *.so diff --git a/litex/build/sim/core/modules/serial2console/Makefile b/litex/build/sim/core/modules/serial2console/Makefile index 7d752baa5..0c69b5b9e 100644 --- a/litex/build/sim/core/modules/serial2console/Makefile +++ b/litex/build/sim/core/modules/serial2console/Makefile @@ -1,5 +1,2 @@ -include ../variables.mak - -all: $(OBJ_DIR)/serial2console.so - -include ../rules.mak +include ../../variables.mak +include $(SRC_DIR)/modules/rules.mak diff --git a/litex/build/sim/core/modules/serial2tcp/Makefile b/litex/build/sim/core/modules/serial2tcp/Makefile index 403644496..0c69b5b9e 100644 --- a/litex/build/sim/core/modules/serial2tcp/Makefile +++ b/litex/build/sim/core/modules/serial2tcp/Makefile @@ -1,5 +1,2 @@ -include ../variables.mak - -all: $(OBJ_DIR)/serial2tcp.so - -include ../rules.mak +include ../../variables.mak +include $(SRC_DIR)/modules/rules.mak diff --git a/litex/build/sim/core/modules/variables.mak b/litex/build/sim/core/modules/variables.mak deleted file mode 100644 index dee2a9832..000000000 --- a/litex/build/sim/core/modules/variables.mak +++ /dev/null @@ -1,13 +0,0 @@ -CC ?= gcc -UNAME_S := $(shell uname -s) - -ifeq ($(UNAME_S),Darwin) - CFLAGS += -I/usr/local/include/ - LDFLAGS += -L/usr/local/lib -ljson-c - CFLAGS += -Wall -O3 -ggdb -fPIC -else - CFLAGS += -Wall -O3 -ggdb -fPIC -Werror -endif -LDFLAGS += -levent -shared -fPIC - -OBJ_DIR ?= . diff --git a/litex/build/sim/core/modules/xgmii_ethernet/Makefile b/litex/build/sim/core/modules/xgmii_ethernet/Makefile index ece1f013c..461ed86be 100644 --- a/litex/build/sim/core/modules/xgmii_ethernet/Makefile +++ b/litex/build/sim/core/modules/xgmii_ethernet/Makefile @@ -1,22 +1,20 @@ -include ../variables.mak -CFLAGS += -Itapcfg/src/include +include ../../variables.mak UNAME_S := $(shell uname -s) -all: $(OBJ_DIR)/xgmii_ethernet.so +include $(SRC_DIR)/modules/rules.mak -include ../rules.mak +CFLAGS += -I$(MOD_SRC_DIR)/tapcfg/src/include +OBJS = $(MOD).o tapcfg.o taplog.o -OBJS = $(addprefix $(OBJ_DIR)/, xgmii_ethernet.o tapcfg.o taplog.o) - -$(OBJ_DIR)/xgmii_ethernet.so: $(OBJS) +$(MOD).so: $(OBJS) ifeq ($(UNAME_S),Darwin) $(CC) $(LDFLAGS) -o $@ $^ else $(CC) $(LDFLAGS) -Wl,-soname,$@ -o $@ $^ endif -$(OBJ_DIR)/tapcfg.o: tapcfg/src/lib/tapcfg.c +tapcfg.o: $(MOD_SRC_DIR)/tapcfg/src/lib/tapcfg.c $(CC) $(CFLAGS) -c -o $@ $< -$(OBJ_DIR)/taplog.o: tapcfg/src/lib/taplog.c +taplog.o: $(MOD_SRC_DIR)/tapcfg/src/lib/taplog.c $(CC) $(CFLAGS) -c -o $@ $< diff --git a/litex/build/sim/verilator.py b/litex/build/sim/verilator.py index 682192a29..f068d08d1 100644 --- a/litex/build/sim/verilator.py +++ b/litex/build/sim/verilator.py @@ -125,7 +125,6 @@ def _build_sim(build_name, sources, threads, coverage, opt_level="O3", trace_fst build_script_contents = """\ rm -rf obj_dir/ make -C . -f {} {} {} {} {} {} -mkdir -p modules && cp obj_dir/*.so modules """.format(makefile, "CC_SRCS=\"{}\"".format("".join(cc_srcs)), "THREADS={}".format(threads) if int(threads) > 1 else "", @@ -217,4 +216,4 @@ class SimVerilatorToolchain: os.chdir("../../") if build: - return top_output.ns \ No newline at end of file + return top_output.ns From 97d0c525ee239be435a0a19be4155405595b3b7d Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Sun, 12 Apr 2020 10:29:13 -0700 Subject: [PATCH 3/3] Remove trailing whitespace. --- litex/build/sim/core/modules.c | 4 ++-- .../build/sim/core/modules/clocker/clocker.c | 4 ++-- .../sim/core/modules/serial2tcp/serial2tcp.c | 24 +++++++++---------- litex/build/sim/core/pads.c | 6 ++--- litex/build/sim/core/parse.c | 10 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/litex/build/sim/core/modules.c b/litex/build/sim/core/modules.c index 2d12a771f..60bec4c69 100644 --- a/litex/build/sim/core/modules.c +++ b/litex/build/sim/core/modules.c @@ -20,7 +20,7 @@ int litex_sim_register_ext_module(struct ext_module_s *mod) { int ret=RC_OK; struct ext_module_list_s *ml=NULL; - + if(!mod) { eprintf("Invalid arguments\n"); @@ -81,7 +81,7 @@ int litex_sim_load_ext_modules(struct ext_module_list_s **mlist) eprintf("Can't load library %s\n", libdylib_last_error()); goto out; } - + if(!libdylib_find(lib, "litex_sim_ext_module_init")) { ret = RC_ERROR; diff --git a/litex/build/sim/core/modules/clocker/clocker.c b/litex/build/sim/core/modules/clocker/clocker.c index 13d047892..1b2b9db04 100644 --- a/litex/build/sim/core/modules/clocker/clocker.c +++ b/litex/build/sim/core/modules/clocker/clocker.c @@ -60,7 +60,7 @@ static int clocker_new(void **sess, char *args) out: *sess=(void*)s; - return ret; + return ret; } static int clocker_add_pads(void *sess, struct pad_list_s *plist) @@ -74,7 +74,7 @@ static int clocker_add_pads(void *sess, struct pad_list_s *plist) goto out; } pads = plist->pads; - + if(!strcmp(plist->name, "sys_clk")) { litex_sim_module_pads_get(pads, "sys_clk", (void**)&s->sys_clk); } diff --git a/litex/build/sim/core/modules/serial2tcp/serial2tcp.c b/litex/build/sim/core/modules/serial2tcp/serial2tcp.c index 347c92eb8..82fe4fbab 100644 --- a/litex/build/sim/core/modules/serial2tcp/serial2tcp.c +++ b/litex/build/sim/core/modules/serial2tcp/serial2tcp.c @@ -97,9 +97,9 @@ void read_handler(int fd, short event, void *arg) struct session_s *s = (struct session_s*)arg; char buffer[1024]; ssize_t read_len; - + int i; - + read_len = read(fd, buffer, 1024); for(i = 0; i < read_len; i++) { @@ -118,10 +118,10 @@ static void accept_conn_cb(struct evconnlistener *listener, evutil_socket_t fd, { struct session_s *s = (struct session_s*)ctx; struct timeval tv = {1, 0}; - + s->fd = fd; s->ev = event_new(base, fd, EV_READ | EV_PERSIST , event_handler, s); - event_add(s->ev, &tv); + event_add(s->ev, &tv); } static void @@ -159,7 +159,7 @@ static int serial2tcp_new(void **sess, char *args) fprintf(stderr, "Invalid port selected!\n"); goto out; } - + s=(struct session_s*)malloc(sizeof(struct session_s)); if(!s) { ret = RC_NOENMEM; @@ -177,8 +177,8 @@ static int serial2tcp_new(void **sess, char *args) eprintf("Can't bind port %d\n!\n", port); goto out; } - evconnlistener_set_error_cb(listener, accept_error_cb); - + evconnlistener_set_error_cb(listener, accept_error_cb); + out: *sess=(void*)s; return ret; @@ -202,19 +202,19 @@ static int serial2tcp_add_pads(void *sess, struct pad_list_s *plist) litex_sim_module_pads_get(pads, "source_valid", (void**)&s->tx_valid); litex_sim_module_pads_get(pads, "source_ready", (void**)&s->tx_ready); } - + if(!strcmp(plist->name, "sys_clk")) litex_sim_module_pads_get(pads, "sys_clk", (void**)&s->sys_clk); out: return ret; - + } static int serial2tcp_tick(void *sess) { char c; int ret = RC_OK; - + struct session_s *s = (struct session_s*)sess; if(*s->sys_clk == 0) return RC_OK; @@ -228,7 +228,7 @@ static int serial2tcp_tick(void *sess) goto out; } } - + *s->rx_valid=0; if(s->datalen) { *s->rx=s->databuf[s->data_start]; @@ -236,7 +236,7 @@ static int serial2tcp_tick(void *sess) s->datalen--; *s->rx_valid=1; } - + out: return ret; } diff --git a/litex/build/sim/core/pads.c b/litex/build/sim/core/pads.c index 225a34c3b..c40c3b119 100644 --- a/litex/build/sim/core/pads.c +++ b/litex/build/sim/core/pads.c @@ -17,7 +17,7 @@ int litex_sim_register_pads(struct pad_s *pads, char *interface_name, int index) { ret = RC_INVARG; eprintf("Invalid argument\n"); - goto out; + goto out; } pl = (struct pad_list_s *)malloc(sizeof(struct pad_list_s)); @@ -36,7 +36,7 @@ int litex_sim_register_pads(struct pad_s *pads, char *interface_name, int index) pl->next = padlist; padlist = pl; - + out: return ret; } @@ -45,7 +45,7 @@ int litex_sim_pads_get_list(struct pad_list_s **plist) { int ret=RC_OK; - + if(!plist) { ret = RC_INVARG; diff --git a/litex/build/sim/core/parse.c b/litex/build/sim/core/parse.c index 29d483d0d..6af8a198b 100644 --- a/litex/build/sim/core/parse.c +++ b/litex/build/sim/core/parse.c @@ -99,7 +99,7 @@ static int json_to_interface_list(json_object *interface, struct interface_s **i json_object *obj; json_object *name; json_object *index; - + struct interface_s *t_iface=NULL; if(!interface || !iface) @@ -108,7 +108,7 @@ static int json_to_interface_list(json_object *interface, struct interface_s **i eprintf("Invalid argument\n"); goto out; } - + if(!json_object_is_type(interface, json_type_array)) { ret=RC_JSERROR; @@ -166,7 +166,7 @@ out: static int module_list_free(struct module_s *mod) { - int ret=RC_OK; + int ret=RC_OK; struct module_s *mnext; int i; while(mod) @@ -247,7 +247,7 @@ static int json_to_module_list(json_object *obj, struct module_s **mod) tickfirst=NULL; json_object_object_get_ex(tobj, "tickfirst", &tickfirst); - + if(m) { @@ -275,7 +275,7 @@ static int json_to_module_list(json_object *obj, struct module_s **mod) goto out; } len = 0; - + while(m->iface[len++].name); m->niface= len-1; m->name = strdup(json_object_get_string(name));