From b134408d403c3029036eff7dba232de42a1358b4 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 19:30:45 +1000 Subject: [PATCH 1/6] Fix `make clean` and `make load`. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9a1511d9..5fc26b52 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,10 @@ firmware: cd firmware && make clean all load-firmware: - litex_term --kernel firmware/firmware.bin COM8 + cd firmware && make load clean: rm -rf build + cd firmware && make clean .PHONY: load firmware load-firmware From b619dfefb11dce9100fbf595d0f5bd02d3b3a059 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 20:35:29 +1000 Subject: [PATCH 2/6] Refactoring makefiles * Make each target build under build// * Make libuip/uip stuff build under build//software/libuip * Make the firmware build under build//software/firmware * Make the CSR csv generate under build//test/ **All** output is now only inside the build directory. Fixes #6 - Each target should have it's own build directory. --- .gitignore | 5 ----- Makefile | 27 +++++---------------------- firmware/Makefile | 37 +++++++++++++++++-------------------- firmware/libuip/Makefile | 26 ++++++++++++++------------ opsis_base.py | 7 +++++-- opsis_hdmi2usb.py | 6 ++++-- opsis_sim.py | 8 +++++--- opsis_video.py | 6 ++++-- 8 files changed, 54 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index bac3ecfd..a2b9c9f5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,5 @@ __pycache__ *.pyc *.egg-info *.vcd -*.o -*.bin -*.elf -*.a -test/csr.csv outgoing build diff --git a/Makefile b/Makefile index 5fc26b52..d8e47266 100644 --- a/Makefile +++ b/Makefile @@ -2,46 +2,29 @@ CPU ?= lm32 export CLANG=0 opsis_base: - rm -rf build - ./opsis_base.py --nocompile-gateware --cpu-type $(CPU) - cd firmware && make clean all + rm -rf build/opsis_base ./opsis_base.py --cpu-type $(CPU) opsis_minisoc: - rm -rf build - ./opsis_base.py --with-ethernet --nocompile-gateware --cpu-type $(CPU) - cd firmware && make clean all + rm -rf build/opsis_minisoc ./opsis_base.py --with-ethernet --cpu-type $(CPU) opsis_video: - rm -rf build - ./opsis_video.py --nocompile-gateware --cpu-type $(CPU) - cd firmware && make clean all + rm -rf build/opsis_video ./opsis_video.py --cpu-type $(CPU) opsis_hdmi2usb: - rm -rf build - ./opsis_hdmi2usb.py --nocompile-gateware --cpu-type $(CPU) - cd firmware && make clean all + rm -rf build/opsis_hdmi2usb ./opsis_hdmi2usb.py --cpu-type $(CPU) opsis_sim: - rm -rf build - ./opsis_sim.py --nocompile-gateware --with-ethernet --cpu-type $(CPU) - cd firmware && make clean all + rm -rf build/opsis_sim ./opsis_sim.py --with-ethernet --cpu-type $(CPU) load: ./load.py -firmware: - cd firmware && make clean all - -load-firmware: - cd firmware && make load - clean: rm -rf build - cd firmware && make clean .PHONY: load firmware load-firmware diff --git a/firmware/Makefile b/firmware/Makefile index 3709b134..39cb59c0 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,10 +1,7 @@ -OPSIS_DIR=../build - -include $(OPSIS_DIR)/software/include/generated/variables.mak +include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -UIPDIR=uip -LIBUIPDIR=libuip +BUILD_DIRECTORY=$(BUILDINC_DIRECTORY)/../../ OBJECTS=isr.o \ ethernet.o \ @@ -25,7 +22,10 @@ OBJECTS=isr.o \ i2c.o \ main.o -CFLAGS += -I. -I$(UIPDIR) -I$(LIBUIPDIR) +CFLAGS += \ + -I. \ + -I$(LIBUIP_DIRECTORY)/../uip \ + -I$(LIBUIP_DIRECTORY) all: firmware.bin @@ -35,37 +35,34 @@ all: firmware.bin %.bin: %.elf $(OBJCOPY) -O binary $< $@ chmod -x $@ - cp $@ boot.bin + cp $@ $(BUILD_DIRECTORY)/boot.bin firmware.elf: $(OBJECTS) libs $(LD) $(LDFLAGS) \ - -T linker.ld \ + -T $(FIRMWARE_DIRECTORY)/linker.ld \ -N -o $@ \ - $(OPSIS_DIR)/software/libbase/crt0-$(CPU).o \ - $(OBJECTS) \ - -L$(OPSIS_DIR)/software/libbase \ - -L$(OPSIS_DIR)/software/libcompiler_rt \ - -L$(LIBUIPDIR) \ + ../libbase/crt0-$(CPU).o \ + $(OBJECTS) \ + -L../libnet \ + -L../libbase \ + -L../libcompiler_rt \ + -L../libuip \ -lbase-nofloat -luip -lcompiler_rt chmod -x $@ -main.o: main.c +main.o: $(FIRMWARE_DIRECTORY)/main.c $(compile) -%.o: %.c +%.o: $(FIRMWARE_DIRECTORY)/%.c $(compile) -%.o: %.S +%.o: $(FIRMWARE_DIRECTORY)/%.S $(assemble) -libs: - $(MAKE) -C $(LIBUIPDIR) - load: firmware.bin litex_term --kernel firmware.bin COM8 clean: - cd libuip && make clean $(RM) $(OBJECTS) $(OBJECTS:.o=.d) firmware.elf firmware.bin .*~ *~ .PHONY: all main.o clean libs load diff --git a/firmware/libuip/Makefile b/firmware/libuip/Makefile index 00c054cf..0a0722c0 100644 --- a/firmware/libuip/Makefile +++ b/firmware/libuip/Makefile @@ -1,16 +1,15 @@ -OPSIS_DIR=../../build - -include $(OPSIS_DIR)/software/include/generated/variables.mak +include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak +VPATH=$(LIBUIP_DIRECTORY) + UIPDIR=../uip -LIBUIPDIR=../libuip +LIBUIPDIR=. -CFLAGS += $(CPPFLAGS) -I. \ - -I$(UIPDIR) \ - -I$(UIPDIR)/net \ - -I$(UIPDIR)/net\ip \ - -I$(UIPDIR)/net\ipv4 \ +CFLAGS += $(CPPFLAGS) \ + -I$(LIBUIP_DIRECTORY)/$(LIBUIPDIR) \ + -I$(LIBUIP_DIRECTORY)/$(UIPDIR) \ + -I$(LIBUIP_DIRECTORY)/$(UIPDIR)/net \ -Wno-char-subscripts \ -fno-strict-aliasing -fpack-struct @@ -50,9 +49,10 @@ UIPCOREOBJS=$(UIPDIR)/net/ip/dhcpc.o \ $(UIPDIR)/sys/timer.o \ $(UIPDIR)/lib/list.o -UIPARCHOBJS=clock-arch.o \ - rtimer-arch.o \ - liteethmac-drv.o +UIPARCHOBJS=\ + $(LIBUIPDIR)/clock-arch.o \ + $(LIBUIPDIR)/rtimer-arch.o \ + $(LIBUIPDIR)/liteethmac-drv.o UIPOBJS=$(UIPCOREOBJS) $(UIPARCHOBJS) OBJS_LIB+=$(UIPOBJS) @@ -64,9 +64,11 @@ all: $(UIPLIB) .PHONY: all compile clean %.o: %.c + @mkdir -p $(@D) $(compile) %.o: %.S + @mkdir -p $(@D) $(assemble) clean: diff --git a/opsis_base.py b/opsis_base.py index 643f7fe0..577feeb4 100755 --- a/opsis_base.py +++ b/opsis_base.py @@ -271,10 +271,13 @@ def main(): platform = opsis_platform.Platform() cls = MiniSoC if args.with_ethernet else BaseSoC + builddir = "opsis_base/" if not args.with_ethernet else "opsis_base/" soc = cls(platform, **soc_sdram_argdict(args)) - builder = Builder(soc, output_dir="build", + builder = Builder(soc, output_dir="build/{}".format(builddir), compile_gateware=not args.nocompile_gateware, - csr_csv="test/csr.csv") + csr_csv="build/{}/test/csr.csv".format(builddir)) + builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) + builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) vns = builder.build() if __name__ == "__main__": diff --git a/opsis_hdmi2usb.py b/opsis_hdmi2usb.py index 42eb244d..8e462122 100755 --- a/opsis_hdmi2usb.py +++ b/opsis_hdmi2usb.py @@ -49,9 +49,11 @@ def main(): platform = opsis_platform.Platform() soc = HDMI2USBSoC(platform, **soc_sdram_argdict(args)) - builder = Builder(soc, output_dir="build", + builder = Builder(soc, output_dir="build/opsis_hdmi2usb/", compile_gateware=not args.nocompile_gateware, - csr_csv="test/csr.csv") + csr_csv="build/opsis_hdmi2usb/test/csr.csv") + builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) + builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) vns = builder.build() if __name__ == "__main__": diff --git a/opsis_sim.py b/opsis_sim.py index 5ba09fec..b46b7c55 100755 --- a/opsis_sim.py +++ b/opsis_sim.py @@ -144,11 +144,13 @@ def main(): cls = MiniSoC if args.with_ethernet else BaseSoC soc = cls(**soc_sdram_argdict(args)) - builder = Builder(soc, output_dir="build", + builder = Builder(soc, output_dir="build/opsis_sim/", compile_gateware=not args.nocompile_gateware, - csr_csv="test/csr.csv") + csr_csv="build/opsis_sim/test/csr.csv") + builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) + builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) builder.build() if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/opsis_video.py b/opsis_video.py index 3641ba79..5cdad87b 100755 --- a/opsis_video.py +++ b/opsis_video.py @@ -78,9 +78,11 @@ def main(): platform = opsis_platform.Platform() soc = VideoMixerSoC(platform, **soc_sdram_argdict(args)) - builder = Builder(soc, output_dir="build", + builder = Builder(soc, output_dir="build/opsis_video/", compile_gateware=not args.nocompile_gateware, - csr_csv="test/csr.csv") + csr_csv="build/opsis_video/test/csr.csv") + builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) + builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) vns = builder.build() if __name__ == "__main__": From 4020e9244520fef9404df2d53e53412e7711d79d Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 20:41:59 +1000 Subject: [PATCH 3/6] Temp fix for test directory not existing. Revert this patch when the builder creates the test directory for the csr.csv file. --- opsis_base.py | 1 + opsis_hdmi2usb.py | 1 + opsis_sim.py | 1 + opsis_video.py | 1 + 4 files changed, 4 insertions(+) diff --git a/opsis_base.py b/opsis_base.py index 577feeb4..28921923 100755 --- a/opsis_base.py +++ b/opsis_base.py @@ -278,6 +278,7 @@ def main(): csr_csv="build/{}/test/csr.csv".format(builddir)) builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) + os.makedirs("build/{}/test".format(builddir)) # FIXME: Remove when builder does this. vns = builder.build() if __name__ == "__main__": diff --git a/opsis_hdmi2usb.py b/opsis_hdmi2usb.py index 8e462122..f6244143 100755 --- a/opsis_hdmi2usb.py +++ b/opsis_hdmi2usb.py @@ -54,6 +54,7 @@ def main(): csr_csv="build/opsis_hdmi2usb/test/csr.csv") builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) + os.makedirs("build/opsis_hdmi2usb/test") # FIXME: Remove when builder does this. vns = builder.build() if __name__ == "__main__": diff --git a/opsis_sim.py b/opsis_sim.py index b46b7c55..075cca18 100755 --- a/opsis_sim.py +++ b/opsis_sim.py @@ -149,6 +149,7 @@ def main(): csr_csv="build/opsis_sim/test/csr.csv") builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) + os.makedirs("build/opsis_sim/test") # FIXME: Remove when builder does this. builder.build() diff --git a/opsis_video.py b/opsis_video.py index 5cdad87b..f19d1f50 100755 --- a/opsis_video.py +++ b/opsis_video.py @@ -83,6 +83,7 @@ def main(): csr_csv="build/opsis_video/test/csr.csv") builder.add_software_package("libuip", "{}/firmware/libuip".format(os.getcwd())) builder.add_software_package("firmware", "{}/firmware".format(os.getcwd())) + os.makedirs("build/opsis_video/test") # FIXME: Remove when builder does this. vns = builder.build() if __name__ == "__main__": From 81fe822fb0ab131c0f04ce0cf05769345776d134 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 20:52:59 +1000 Subject: [PATCH 4/6] Put boot.bin in software/ --- firmware/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/Makefile b/firmware/Makefile index 39cb59c0..04681aa0 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -35,7 +35,7 @@ all: firmware.bin %.bin: %.elf $(OBJCOPY) -O binary $< $@ chmod -x $@ - cp $@ $(BUILD_DIRECTORY)/boot.bin + cp $@ $(BUILD_DIRECTORY)/software/boot.bin firmware.elf: $(OBJECTS) libs $(LD) $(LDFLAGS) \ From 5c85343721a420cc09345b32b30a580a403331f5 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 21:23:25 +1000 Subject: [PATCH 5/6] Add missing import in opsis_sim. --- opsis_sim.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opsis_sim.py b/opsis_sim.py index 075cca18..25dc855f 100755 --- a/opsis_sim.py +++ b/opsis_sim.py @@ -2,6 +2,7 @@ import argparse import importlib +import os from litex.gen import * from litex.gen.genlib.io import CRG From d927bd9856d5a9e40332bb75a5b1a2b645a399ed Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 20 Sep 2016 22:00:48 +1000 Subject: [PATCH 6/6] Adding setup/teardown for Ethernet on sim target on Ubuntu. --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Makefile b/Makefile index d8e47266..e8b54cc7 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,19 @@ opsis_hdmi2usb: rm -rf build/opsis_hdmi2usb ./opsis_hdmi2usb.py --cpu-type $(CPU) +opsis_sim_setup: + sudo openvpn --mktun --dev tap0 + sudo ifconfig tap0 192.168.1.100 up + sudo mknod /dev/net/tap0 c 10 200 + sudo chown $(shell whoami) /dev/net/tap0 + sudo atftpd --bind-address 192.168.1.100 --daemon --logfile /dev/stdout --no-fork --user $(shell whoami) build/opsis_sim/software/ & + +opsis_sim_teardown: + sudo killall atftpd || true # FIXME: This is dangerous... + sudo rm -f /dev/net/tap0 + sudo ifconfig tap0 down + sudo openvpn --rmtun --dev tap0 + opsis_sim: rm -rf build/opsis_sim ./opsis_sim.py --with-ethernet --cpu-type $(CPU)