From 0bf96e98646e980a8c34394fb21bd7785a29232d Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Wed, 8 Mar 2023 16:38:38 -0300 Subject: [PATCH] standardize Zephyr examples --- examples/zephyr/README.md | 25 +++----- examples/zephyr/device-dashboard/Makefile | 75 +++++++++-------------- examples/zephyr/http-client/Makefile | 9 ++- examples/zephyr/http-server/Makefile | 71 +++++++++------------ examples/zephyr/mqtt-aws-client/Makefile | 71 +++++++++------------ examples/zephyr/websocket-server/Makefile | 71 +++++++++------------ 6 files changed, 128 insertions(+), 194 deletions(-) diff --git a/examples/zephyr/README.md b/examples/zephyr/README.md index 674a7a41..7d2078c5 100644 --- a/examples/zephyr/README.md +++ b/examples/zephyr/README.md @@ -1,24 +1,15 @@ # Zephyr Project examples -## Building +- See detailed tutorial at https://mongoose.ws/tutorials/zephyr/device-dashboard/ -- Run `make zephyr`, this will clone the Zephyr Project repo or update it if you've already done it before -- Now you can build the project, follow one of this options: +The tutorial is specific for the Device Dashboard example but [build instructions](https://mongoose.ws/tutorials/zephyr/device-dashboard/#build-and-run) are generic -### Trying on a simulated board -The default board is an x86 machine that can be simulated with QEMU, and runs inside a _Docker_ container, you only need to have _Docker_ installed. Its Ethernet is also simulated and uses the TUN/TAP interface. -You'll need a TUN/TAP interface (default name is _tap0_) on your host machine; follow the instructions [here](https://github.com/cesanta/mongoose/tree/master/examples/mip-tap#linux-setup) to configure your network to provide a suitable networking environment. -- Run `make build`. The interface configuration on the simulated machine side is in the file _overlay-e1000.conf_, and defaults to _tap0_. You can change this overlay file adding an `OVERLAY` argument (e.g.: *make build OVERLAY="-DOVERLAY_CONFIG=something"*). -- Once the build succeeds, run `make run` to run the target. The default _Docker_ configuration is to share _/dev/net/tun_; if this does not work for you, pass the necessary _Docker_ parameters inside `SHARETUN` (e.g.: *make run SHARETUN=something*). +## Optional: Using a simulated board -### Using a real board +For testing purposes, we build for an x86 target that can be simulated with QEMU, and runs inside a _Docker_ container. Its Ethernet interface is also simulated, and uses the TUN/TAP interface. You can use this to try the examples or for your own development with Zephyr, without the need to have an actual board connected; you only need to have _Docker_ installed as the Zephyr Docker image handles the emulation for you. -- Run `make build BOARD=yourboardname` (e.g.: *make build BOARD=nucleo_f746zg*) -- Once the build succeeds, run `make flash`. The Makefile shares the USB bus with the _Docker_ container, this works well with ST-Link and J-Link devices. If this does not work for you, pass the necessary _Docker_ parameters inside `SHAREUSB` (e.g.: *make flash SHAREUSB=something*) -- The generated ELF file is at _build/zephyr_ - -## Cleaning up - -- You can run `make clean` to clean up the build files but keep the configuration files, which speeds the next build -- If you do major changes (like compiling for a different board...), run `make pristine` to clean up everything under the _build_ directory. +- You'll need a TUN/TAP interface (default name is _tap0_) on your host machine; follow the instructions [here](https://github.com/cesanta/mongoose/tree/master/examples/mip-tap#linux-setup) to configure your network to provide a suitable networking environment. +- Run `make build BUILD_ARGS="-b qemu_x86" OVERLAY="-DOVERLAY_CONFIG=overlay-e1000.conf"`. + - The interface configuration on the simulated machine side is in the file _overlay-e1000.conf_, and defaults to _tap0_. You can change this file or specify a different one by changing the `OVERLAY_CONFIG` argument above. +- Once the build succeeds, run `make run` to run the target. The default _Docker_ configuration is to share _/dev/net/tun_; if this does not work for you, pass the necessary _Docker_ parameters to _make_ with a `DOCKER_ARGS=` argument. diff --git a/examples/zephyr/device-dashboard/Makefile b/examples/zephyr/device-dashboard/Makefile index 59d4f872..c198e649 100644 --- a/examples/zephyr/device-dashboard/Makefile +++ b/examples/zephyr/device-dashboard/Makefile @@ -1,61 +1,46 @@ -MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..) -DOCKER_PROJECT_DIR ?= /workdir -ZEPHYR_DIR ?= zephyrproject -PROJECT_NAME = $(notdir $(CURDIR)) -PROJECT_PATH = $(realpath $(CURDIR)) -ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR) -DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME) -DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR) - -BOARD ?= qemu_x86 -ifeq "$(BOARD)" "qemu_x86" -OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf -else -OVERLAY ?= -endif - -SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH) -REPO ?= zephyrprojectrtos/ci - +TOP_DIR ?= $(realpath $(CURDIR)/../../..) +ZEPHYR_DIR ?= $(realpath $(CURDIR)/..)/zephyrproject +DOCKER ?= docker run --rm \ + -v $(TOP_DIR):$(TOP_DIR) \ + -w $(realpath $(CURDIR)) \ + -e ZEPHYR_BASE=$(ZEPHYR_DIR)/zephyr \ + $(DOCKER_ARGS) zephyrprojectrtos/ci +BUILD_ARGS ?= -b nucleo_f746zg +.PHONY: build example: true -build: - cp $(MONGOOSE_ROOT)/mongoose.[ch] src/ - cp $(MONGOOSE_ROOT)/examples/device-dashboard/net.c src/ - cp $(MONGOOSE_ROOT)/examples/device-dashboard/packed_fs.c src/ - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \ - west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build' +zephyr: + test -d $(ZEPHYR_DIR) || ( mkdir -p $(ZEPHYR_DIR) ; $(DOCKER) west init $(ZEPHYR_DIR)) + $(DOCKER) sh -c 'cd $(ZEPHYR_DIR) && west update' +build: + cp $(TOP_DIR)/mongoose.[ch] src/ + cp $(TOP_DIR)/examples/device-dashboard/net.c src/ + cp $(TOP_DIR)/examples/device-dashboard/packed_fs.c src/ + $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) $(OVERLAY) + +run: DOCKER_ARGS ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -it run: - $(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west build -t run clean: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t clean pristine: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t pristine +purge: clean pristine + rm -rf $(TOP_DIR)/.west $(ZEPHYR_DIR) build +flash debug: DOCKER_ARGS ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -it flash: - $(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west flash --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west flash --build-dir $(realpath $(CURDIR))/build debug: - $(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west debug --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west debug --build-dir $(realpath $(CURDIR))/build -.PHONY: build flash zephyr clean pristine run - -zephyr: -ifeq ($(wildcard $(ZEPHYR_PATH)/.*),) - mkdir $(ZEPHYR_PATH) - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)' -endif - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update' +test: BUILD_ARGS = -b qemu_x86 +test: OVERLAY = -DOVERLAY_CONFIG=overlay-e1000.conf +test: build run diff --git a/examples/zephyr/http-client/Makefile b/examples/zephyr/http-client/Makefile index 2b0fa519..e5aa7fff 100644 --- a/examples/zephyr/http-client/Makefile +++ b/examples/zephyr/http-client/Makefile @@ -5,8 +5,7 @@ DOCKER ?= docker run --rm \ -w $(realpath $(CURDIR)) \ -e ZEPHYR_BASE=$(ZEPHYR_DIR)/zephyr \ $(DOCKER_ARGS) zephyrprojectrtos/ci -#BUILD_ARGS ?= -b qemu_x86 -DOVERLAY_CONFIG=overlay-e1000.conf -BUILD_ARGS ?= -b nucleo_f429zi +BUILD_ARGS ?= -b nucleo_f746zg .PHONY: build example: @@ -18,7 +17,7 @@ zephyr: build: cp $(TOP_DIR)/mongoose.[ch] src/ - $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) + $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) $(OVERLAY) run: DOCKER_ARGS ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -it run: @@ -39,3 +38,7 @@ flash: debug: $(DOCKER) west debug --build-dir $(realpath $(CURDIR))/build + +test: BUILD_ARGS = -b qemu_x86 +test: OVERLAY = -DOVERLAY_CONFIG=overlay-e1000.conf +test: build run diff --git a/examples/zephyr/http-server/Makefile b/examples/zephyr/http-server/Makefile index be7a4cb9..e5aa7fff 100644 --- a/examples/zephyr/http-server/Makefile +++ b/examples/zephyr/http-server/Makefile @@ -1,59 +1,44 @@ -MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..) -DOCKER_PROJECT_DIR ?= /workdir -ZEPHYR_DIR ?= zephyrproject -PROJECT_NAME = $(notdir $(CURDIR)) -PROJECT_PATH = $(realpath $(CURDIR)) -ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR) -DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME) -DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR) - -BOARD ?= qemu_x86 -ifeq "$(BOARD)" "qemu_x86" -OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf -else -OVERLAY ?= -endif - -SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH) -REPO ?= zephyrprojectrtos/ci - +TOP_DIR ?= $(realpath $(CURDIR)/../../..) +ZEPHYR_DIR ?= $(realpath $(CURDIR)/..)/zephyrproject +DOCKER ?= docker run --rm \ + -v $(TOP_DIR):$(TOP_DIR) \ + -w $(realpath $(CURDIR)) \ + -e ZEPHYR_BASE=$(ZEPHYR_DIR)/zephyr \ + $(DOCKER_ARGS) zephyrprojectrtos/ci +BUILD_ARGS ?= -b nucleo_f746zg +.PHONY: build example: true -build: - cp $(MONGOOSE_ROOT)/mongoose.[ch] src/ - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \ - west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build' +zephyr: + test -d $(ZEPHYR_DIR) || ( mkdir -p $(ZEPHYR_DIR) ; $(DOCKER) west init $(ZEPHYR_DIR)) + $(DOCKER) sh -c 'cd $(ZEPHYR_DIR) && west update' +build: + cp $(TOP_DIR)/mongoose.[ch] src/ + $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) $(OVERLAY) + +run: DOCKER_ARGS ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -it run: - $(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west build -t run clean: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t clean pristine: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t pristine +purge: clean pristine + rm -rf $(TOP_DIR)/.west $(ZEPHYR_DIR) build +flash debug: DOCKER_ARGS ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -it flash: - $(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west flash --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west flash --build-dir $(realpath $(CURDIR))/build debug: - $(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west debug --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west debug --build-dir $(realpath $(CURDIR))/build -.PHONY: build flash zephyr clean pristine run - -zephyr: -ifeq ($(wildcard $(ZEPHYR_PATH)/.*),) - mkdir $(ZEPHYR_PATH) - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)' -endif - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update' +test: BUILD_ARGS = -b qemu_x86 +test: OVERLAY = -DOVERLAY_CONFIG=overlay-e1000.conf +test: build run diff --git a/examples/zephyr/mqtt-aws-client/Makefile b/examples/zephyr/mqtt-aws-client/Makefile index be7a4cb9..e5aa7fff 100644 --- a/examples/zephyr/mqtt-aws-client/Makefile +++ b/examples/zephyr/mqtt-aws-client/Makefile @@ -1,59 +1,44 @@ -MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..) -DOCKER_PROJECT_DIR ?= /workdir -ZEPHYR_DIR ?= zephyrproject -PROJECT_NAME = $(notdir $(CURDIR)) -PROJECT_PATH = $(realpath $(CURDIR)) -ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR) -DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME) -DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR) - -BOARD ?= qemu_x86 -ifeq "$(BOARD)" "qemu_x86" -OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf -else -OVERLAY ?= -endif - -SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH) -REPO ?= zephyrprojectrtos/ci - +TOP_DIR ?= $(realpath $(CURDIR)/../../..) +ZEPHYR_DIR ?= $(realpath $(CURDIR)/..)/zephyrproject +DOCKER ?= docker run --rm \ + -v $(TOP_DIR):$(TOP_DIR) \ + -w $(realpath $(CURDIR)) \ + -e ZEPHYR_BASE=$(ZEPHYR_DIR)/zephyr \ + $(DOCKER_ARGS) zephyrprojectrtos/ci +BUILD_ARGS ?= -b nucleo_f746zg +.PHONY: build example: true -build: - cp $(MONGOOSE_ROOT)/mongoose.[ch] src/ - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \ - west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build' +zephyr: + test -d $(ZEPHYR_DIR) || ( mkdir -p $(ZEPHYR_DIR) ; $(DOCKER) west init $(ZEPHYR_DIR)) + $(DOCKER) sh -c 'cd $(ZEPHYR_DIR) && west update' +build: + cp $(TOP_DIR)/mongoose.[ch] src/ + $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) $(OVERLAY) + +run: DOCKER_ARGS ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -it run: - $(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west build -t run clean: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t clean pristine: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t pristine +purge: clean pristine + rm -rf $(TOP_DIR)/.west $(ZEPHYR_DIR) build +flash debug: DOCKER_ARGS ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -it flash: - $(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west flash --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west flash --build-dir $(realpath $(CURDIR))/build debug: - $(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west debug --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west debug --build-dir $(realpath $(CURDIR))/build -.PHONY: build flash zephyr clean pristine run - -zephyr: -ifeq ($(wildcard $(ZEPHYR_PATH)/.*),) - mkdir $(ZEPHYR_PATH) - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)' -endif - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update' +test: BUILD_ARGS = -b qemu_x86 +test: OVERLAY = -DOVERLAY_CONFIG=overlay-e1000.conf +test: build run diff --git a/examples/zephyr/websocket-server/Makefile b/examples/zephyr/websocket-server/Makefile index be7a4cb9..e5aa7fff 100644 --- a/examples/zephyr/websocket-server/Makefile +++ b/examples/zephyr/websocket-server/Makefile @@ -1,59 +1,44 @@ -MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..) -DOCKER_PROJECT_DIR ?= /workdir -ZEPHYR_DIR ?= zephyrproject -PROJECT_NAME = $(notdir $(CURDIR)) -PROJECT_PATH = $(realpath $(CURDIR)) -ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR) -DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME) -DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR) - -BOARD ?= qemu_x86 -ifeq "$(BOARD)" "qemu_x86" -OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf -else -OVERLAY ?= -endif - -SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH) -REPO ?= zephyrprojectrtos/ci - +TOP_DIR ?= $(realpath $(CURDIR)/../../..) +ZEPHYR_DIR ?= $(realpath $(CURDIR)/..)/zephyrproject +DOCKER ?= docker run --rm \ + -v $(TOP_DIR):$(TOP_DIR) \ + -w $(realpath $(CURDIR)) \ + -e ZEPHYR_BASE=$(ZEPHYR_DIR)/zephyr \ + $(DOCKER_ARGS) zephyrprojectrtos/ci +BUILD_ARGS ?= -b nucleo_f746zg +.PHONY: build example: true -build: - cp $(MONGOOSE_ROOT)/mongoose.[ch] src/ - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \ - west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build' +zephyr: + test -d $(ZEPHYR_DIR) || ( mkdir -p $(ZEPHYR_DIR) ; $(DOCKER) west init $(ZEPHYR_DIR)) + $(DOCKER) sh -c 'cd $(ZEPHYR_DIR) && west update' +build: + cp $(TOP_DIR)/mongoose.[ch] src/ + $(DOCKER) west build $(BUILD_ARGS) -p auto $(realpath $(CURDIR)) $(OVERLAY) + +run: DOCKER_ARGS ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host -it run: - $(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west build -t run clean: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t clean pristine: - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build' + -$(DOCKER) west build -t pristine +purge: clean pristine + rm -rf $(TOP_DIR)/.west $(ZEPHYR_DIR) build +flash debug: DOCKER_ARGS ?= --privileged -v /dev/bus/usb/:/dev/bus/usb -it flash: - $(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west flash --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west flash --build-dir $(realpath $(CURDIR))/build debug: - $(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \ - west debug --build-dir $(DOCKER_PROJECT_PATH)/build' + $(DOCKER) west debug --build-dir $(realpath $(CURDIR))/build -.PHONY: build flash zephyr clean pristine run - -zephyr: -ifeq ($(wildcard $(ZEPHYR_PATH)/.*),) - mkdir $(ZEPHYR_PATH) - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)' -endif - $(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update' +test: BUILD_ARGS = -b qemu_x86 +test: OVERLAY = -DOVERLAY_CONFIG=overlay-e1000.conf +test: build run